26require_once NOALYSS_INCLUDE.
"/database/v_tva_rate_sql.class.php";
27require_once NOALYSS_INCLUDE.
"/database/tva_rate_sql.class.php";
48 parent::__construct($p_table);
49 $this->icon_mod=
'left';
56 $this->
set_col_label(
"tva_reverse_account",
_(
'Poste comptable autoliquidation'));
59 $this->
set_col_label(
"tva_peppol_code",
_(
"Code Facture électronique UBL"));
67 [
"value"=>0,
"label"=>
_(
"Non")],
68 [
"value"=>1,
"label"=>
_(
"Oui")]
75 array(
"value"=>
'O',
"label"=>
"Opération"),
76 array(
"value"=>
'P',
"label"=>
"Paiement")
82 array(
"value"=>
'O',
"label"=>
"Opération"),
83 array(
"value"=>
'P',
"label"=>
"Paiement")
87 "tva_purchase"=>44,
"tva_both_side"=>43,
"tva_sale"=>45
88 ,
"tva_payment_sale"=>74,
"tva_payment_purchase"=>74,
'tva_reverse_account'=>88];
89 $this->previous_id=
null;
90 $this->a_comment=array(
91 'tva_purchase'=>
_(
"Ne donnez pas ce poste comptable si ce code n'est pas utilisé à l'achat"),
92 'tva_both_side'=>
_(
"Autoliquidation : Utilisé en même temps au crédit et au débit"),
93 'tva_sale'=>
_(
"Ne donnez pas ce poste comptable si ce code n'est pas utilisé à la vente"),
94 'tva_payment_purchase'=>
_(
'TVA due ou récupérable quand l\'opération est payée ou exécutée'),
95 'tva_payment_sale'=>
_(
'TVA due ou récupérable quand l\'opération est payée ou exécutée'),
96 '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)"),
97 'tva_peppol_code'=>
_(
"Code TVA est utilisé pour les factures électroniques, plus d'information dans le manuel"),
98 'vx_code'=>
_(
"Code exemption pour facture PEPPOL (ubl)")
128 $nb_order=count($this->a_order);
132 for (
$i=0;
$i<$nb_order;
$i++)
135 $key=$this->a_order[
$i];
136 $label=$this->a_label_displaid[$key];
144 if ( isset($this->a_info[$key])) {
148 echo
"<td> {$label} {$info} {$error}</td>";
153 if ($this->a_type[$key]==
"select")
156 $select->value=$this->a_select[$key];
166 $text->size=$min_size;
169 elseif ($key==
'tva_purchase')
174 $text->size=$min_size;
175 $text->set_attribute(
'gDossier', Dossier::id());
176 $text->set_attribute(
'jrn', 0);
177 $text->set_attribute(
'account',
'tva_purchase');
179 $url=
"do.php?".http_build_query(array(
"gDossier"=>Dossier::id(),
"ac"=>
'C0PCMN',
'p_start'=>4));
180 echo HtmlInput::anchor(
_(
"Configuration poste comptable"),
$url,
"",
'target="_blank"');
187 $text->set_attribute(
'gDossier', Dossier::id());
188 $text->set_attribute(
'jrn', 0);
189 $text->set_attribute(
'account',
'tva_sale');
190 $text->size=$min_size;
192 }
elseif ($key==
'tva_peppol_code') {
195 $text->transform(array(
197 ,
"S"=>
_(
'S Taux standard')
198 ,
'AE'=>
_(
'AE Autoliquidate mais pas INTRACOMM.')
199 ,
'Z'=>
_(
"Z TVA à 0%")
200 ,
'K'=>
_(
'K Autoliquidation INTRACOMM.')
201 ,
'G'=>
_(
'G TVA exempt pour export hors Europe')
202 ,
'O'=>
_(
'O TVA Hors périmètre application')
203 ,
'E'=>
_(
'E Exempté de TVA')
206 }
elseif ($key ==
'vx_code')
214 $js=sprintf(
"vat_code.list_vatex()");
215 echo \Icon_Action::icon_magnifier(uniqid(),
$js );
218 elseif ($key ==
"tva_id") {
221 echo \HtmlInput::hidden(
"old_tva_id",
$value);
223 }
elseif ($key==
'tva_reverse_account')
228 $text->set_attribute(
'gDossier', Dossier::id());
229 $text->set_attribute(
'jrn', 0);
230 $text->set_attribute(
'account',
'tva_reverse_account');
231 $text->size=$min_size;
233 }
elseif ($this->a_type[$key]==
"text")
238 $text->size=$min_size;
245 printf(
'<td>%s %s</td>',
h(
$value),
246 HtmlInput::hidden($key,
$value)
250 if (isset ($this->a_comment[$key])) {
251 print '<p class="text-muted">';
252 echo $this->a_comment[$key];
255 if( $key ==
'vx_code') {
256 echo
'<span id="vx_code_description">';
257 $row=$this->
table->cn->get_row(
"select vx_code,vx_code_name,vx_description,vx_remark from vatex_code where vx_code=$1",
259 if ( ! empty (
$row)) {
260 echo
$row[
'vx_description'].span(
$row[
'vx_remark'],
' class="text-muted" ');
278 parent::from_request();
279 $http=new \HttpInput();
280 $this->
table->tva_reverse_account=
$http->request(
'tva_reverse_account');
281 $this->
table->tva_peppol_code=
$http->request(
'tva_peppol_code');
282 $this->
table->vx_code=
$http->request(
'vx_code');
293 if ( $this->previous_id ===
null ) {
294 throw new \Exception (
"TVA184: no previous TVA id");
296 $cn=Dossier::connect();
299 if ($this->
table->tva_both_side==1)
301 if ($this->
table->tva_purchase==
"#"||trim($this->
table->tva_purchase)
304 $this->
table->tva_purchase=$this->
table->tva_sale;
306 if ($this->
table->tva_sale==
"#"||trim($this->
table->tva_sale)==
"#")
308 $this->
table->tva_sale=$this->
table->tva_purchase;
311 $new_tva_id=$this->
table->tva_id;
319 $tva_rate->setp(
"tva_reverse_account", $this->
table->tva_reverse_account);
320 $tva_rate->setp(
"tva_peppol_code", $this->
table->tva_peppol_code);
324 $tva_purchase=(trim($this->
table->tva_purchase)==
"")?
"#":$this->
table->tva_purchase;
325 $tva_sale=(trim($this->
table->tva_sale)==
"")?
"#":$this->
table->tva_sale;
326 $tva_rate->setp(
"tva_poste", $tva_purchase.
",".$tva_sale);
327 $tva_rate->setp(
"tva_payment_sale", $this->
table->tva_payment_sale);
328 $tva_rate->setp(
"tva_payment_purchase", $this->
table->tva_payment_purchase);
329 if ( $this->previous_id == -1 ) {
334 if ( $this->previous_id != - 1 && $this->previous_id != $new_tva_id) {
335 $cn->exec_sql(
"update tva_rate set tva_id = $1 where tva_id = $2",[$new_tva_id,$this->previous_id]);
336 $this->
table->setp(
"tva_id",$new_tva_id);
352 $cn=Dossier::connect();
353 if ( $this->previous_id ===
null ) {
354 throw new \Exception (
"TVA184: no previous TVA id");
357 if (trim($this->
table->tva_purchase??
"")==
""&&trim($this->
table->tva_sale??
"")==
"")
360 _(
"Les 2 postes comptables ne peuvent être nuls"));
362 _(
"Les 2 postes comptables ne peuvent être nuls"));
366 if (trim($this->
table->tva_rate??
"")==
""||
isNumber($this->
table->tva_rate)==0||$this->table->tva_rate>1)
368 $this->
set_error(
"tva_rate",
_(
"Taux de TVA invalide"));
372 $count=
$cn->get_value(
"select count(*) from tva_rate where tva_id<>$1 and lower(tva_label)=lower($2)",
376 $this->
set_error(
"tva_label",
_(
"Ce nom est déjà utilisé"));
380 if (trim($this->
table->tva_purchase??
"")!=
""&&$this->table->tva_purchase!=
"#")
382 $count=
$cn->get_value(
"select count(*) from tmp_pcmn where pcm_val = $1",
383 [$this->
table->tva_purchase]);
386 $this->
set_error(
"tva_purchase",
_(
"Poste comptable inexistant"));
390 if (trim($this->
table->tva_sale??
"")!=
""&&$this->table->tva_sale!=
"#")
392 $count=
$cn->get_value(
"select count(*) from tmp_pcmn where pcm_val = $1",
393 [$this->
table->tva_sale]);
396 $this->
set_error(
"tva_sale",
_(
"Poste comptable inexistant"));
401 if ($this->
table->tva_both_side!=0&&$this->table->tva_both_side!=1)
403 $this->
set_error(
"tva_both_side",
_(
"Choix incorrect"));
407 if (
isNumber($this->
table->tva_id) == 0 || $this->table->tva_id != round($this->
table->tva_id) )
409 $this->
set_error(
"tva_id",
_(
"Valeur invalide"));
413 if (
$flag && $this->previous_id != $this->
table->tva_id &&
$cn->get_value(
"select count(*) from tva_rate where tva_id=$1",[$this->table->tva_id]) > 0)
415 $this->
set_error(
"tva_id",
_(
"Code TVA déjà utilisé"));
418 $this->
table->tva_code=strtoupper(trim( $this->
table->tva_code));
419 $tva_code=$this->
table->tva_code;
421 $tva_code=strtoupper($tva_code);
422 $tva_code=preg_replace(
"/[A-Z]/",
"", $tva_code);
423 $tva_code=preg_replace(
"/[0-9]/",
"", $tva_code);
425 if (strlen($tva_code)>0){
426 $this->
set_error(
"tva_code",
_(
"code tva : Uniquement des chiffres et des lettres"));
429 if (strlen($this->
table->tva_code)>5){
430 $this->
set_error(
"tva_code",
_(
"code tva : Maximum 5 caractères"));
433 $this->
set_error(
"tva_code",
_(
"code tva : doit aussi contenir des lettres"));
438 if ( $this->
table->tva_both_side==0 && trim($this->
table->tva_reverse_account??
"") !=
"")
440 $this->
set_error(
"tva_reverse_account",
_(
"Pas d'autoliquidation demandé"));
442 if ( $this->
table->tva_both_side==1 && trim($this->
table->tva_reverse_account??
"") !=
"")
444 $count=
$cn->get_value(
"select count(*) from tmp_pcmn where pcm_val = $1",
445 [$this->
table->tva_reverse_account]);
448 $this->
set_error(
"tva_reverse_account",
_(
"Poste comptable inexistant"));
452 if ( trim($this->
table->tva_label??
"")==
"") {
453 $this->
set_error(
"tva_label",
_(
'Le label ne peut être vide'));
457 if ( $g_parameter->MY_INVOICE_FORMAT ==
'UBL21BE' && trim($this->
table->vx_code??
"") !=
"" && in_array($this->
table->tva_peppol_code,[
'S',
'Z'] ))
459 $this->
set_error(
"vx_code",
_(
"Le code d'exemption TVA ne peut être utilisé avec ce code Facture électronique UBL "));
462 if ( $g_parameter->MY_INVOICE_FORMAT ==
'UBL21BE' && trim($this->
table->vx_code??
"") !=
"" && $this->table->tva_peppol_code==
"")
464 $this->
set_error(
"vx_code",
_(
"Le code d'exemption TVA n' pas de sens sans code Facture électronique"));
467 if ( $g_parameter->MY_INVOICE_FORMAT ==
'UBL21BE'
468 && ! in_array($this->
table->tva_peppol_code??
"",[
"Z",
"S"])
469 && trim($this->
table->vx_code??
"" ) ==
"")
471 $this->
set_error(
"vx_code",
_(
"Un code d'exemption de TVA doit être fourni, voyez le manuel"));
483 $cn=Dossier::connect();
484 $count_purchase=
$cn->get_value(
"select count(*) from quant_purchase where qp_vat_code = $1",[$this->
table->tva_id]);
485 $count_sale=
$cn->get_value(
"select count(*) from quant_sold where qs_vat_code = $1",[$this->
table->tva_id]);
486 if ( $count_purchase > 0 || $count_sale > 0) {
487 throw new Exception(
_(
"Effacement interdit : TVA utilisée"));
491 $count=
$cn->get_value(
"select count(*) from tva_rate");
493 throw new Exception(
_(
"Vous ne pouvez pas effacer tous les taux. Si votre société n'utilise pas la TVA, changer dans le menu société"));
495 $cn->exec_sql(
"delete from tva_rate where tva_id=$1", [$this->
table->tva_id]);
span($p_string, $p_extra='')
h( $row[ 'oa_description'])
catch(Exception $e) $tva_rate
_("actif, passif,charge,...")
This class handles only the numeric input, the input will call a javascript to change comma to period...
show a button, for selecting a account and a input text for manually inserting an account the differe...
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
static infobulle($p_comment)
Display a info in a bubble, text is in message_javascript.
static trash($p_id, $p_javascript)
Display the icon of a trashbin.
Purpose is to propose a librairy to display a table content and allow to update and delete row ,...
count_error()
returns the nb of errors found
get_property_updatable($p_key)
return True if the column is updatable otherwise false
set_property_updatable($p_key, $p_value)
set a column of the data row updatable or not
set_col_type($p_key, $p_value, $p_array=NULL)
set the type of a column , it will change in the input db box , the select must supply an array of po...
get_property_visible($p_key)
return True if the column is visible otherwise false
get_error($p_col)
retrieve the error message
setTitle($p_title)
Set the title of the diabox , default is Donnée.
set_property_visible($p_key, $p_value)
set a column of the data row visible or not
set_error($p_col, $p_message)
set the error message for a wrong input
set_col_label($p_key, $p_display)
set the name to display for a column
Configure the tva : code , rate, label ... When using Manage_Table_SQL.
$previous_id
< previous tva_id, used to know if we update or insert,
__construct(V_Tva_rate_SQL $p_table)
input()
display into a dialog box the datarow in order to be appended or modified.
from_request()
add the TVA_REVERSE_ACCOUNT
save()
save the data in TVA_RATE if tva_both_side is 1 and tva_purchase or tva_sale is empty then it is equa...
check()
Check data are valid.
$a_comment
Supplemental explanation.
setPreviousId($previous_id)
abstract of the table public.tva_rate
if( $delta< 0) elseif( $delta==0)