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);
55 $this->
set_col_label(
"tva_reverse_account",
_(
'Poste comptable autoliquidation'));
63 [
"value"=>0,
"label"=>
_(
"Non")],
64 [
"value"=>1,
"label"=>
_(
"Oui")]
71 array(
"value"=>
'O',
"label"=>
"Opération"),
72 array(
"value"=>
'P',
"label"=>
"Paiement")
78 array(
"value"=>
'O',
"label"=>
"Opération"),
79 array(
"value"=>
'P',
"label"=>
"Paiement")
83 "tva_purchase"=>44,
"tva_both_side"=>43,
"tva_sale"=>45
84 ,
"tva_payment_sale"=>74,
"tva_payment_purchase"=>74,
'tva_reverse_account'=>88];
85 $this->previous_id=
null;
86 $this->a_comment=array(
87 'tva_purchase'=>
_(
"Ne donnez pas ce poste comptable si ce code n'est pas utilisé à l'achat"),
88 'tva_both_side'=>
_(
"Autoliquidation : Utilisé en même temps au crédit et au débit"),
89 'tva_sale'=>
_(
"Ne donnez pas ce poste comptable si ce code n'est pas utilisé à la vente"),
90 'tva_payment_purchase'=>
_(
'TVA due ou récupérable quand l\'opération est payée ou exécutée'),
91 'tva_payment_sale'=>
_(
'TVA due ou récupérable quand l\'opération est payée ou exécutée'),
92 '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)")
121 $nb_order=count($this->a_order);
124 for (
$i=0;
$i<$nb_order;
$i++)
127 $key=$this->a_order[
$i];
128 $label=$this->a_label_displaid[$key];
136 if ( isset($this->a_info[$key])) {
140 echo
"<td> {$label} {$info} {$error}</td>";
145 if ($this->a_type[$key]==
"select")
148 $select->value=$this->a_select[$key];
158 $text->size=$min_size;
161 elseif ($key==
'tva_purchase')
166 $text->size=$min_size;
167 $text->set_attribute(
'gDossier', Dossier::id());
168 $text->set_attribute(
'jrn', 0);
169 $text->set_attribute(
'account',
'tva_purchase');
171 $url=
"do.php?".http_build_query(array(
"gDossier"=>Dossier::id(),
"ac"=>
'C0PCMN',
'p_start'=>4));
172 echo HtmlInput::anchor(
_(
"Configuration poste comptable"),
$url,
"",
'target="_blank"');
179 $text->set_attribute(
'gDossier', Dossier::id());
180 $text->set_attribute(
'jrn', 0);
181 $text->set_attribute(
'account',
'tva_sale');
182 $text->size=$min_size;
185 elseif ($this->a_type[$key]==
"text")
190 $text->size=$min_size;
192 }
elseif ($key ==
"tva_id") {
195 echo \HtmlInput::hidden(
"old_tva_id",
$value);
197 }
elseif ($key==
'tva_reverse_account')
202 $text->set_attribute(
'gDossier', Dossier::id());
203 $text->set_attribute(
'jrn', 0);
204 $text->set_attribute(
'account',
'tva_reverse_account');
205 $text->size=$min_size;
212 printf(
'<td>%s %s</td>',
h(
$value),
213 HtmlInput::hidden($key,
$value)
216 echo
'<td class="text-muted">';
217 if (isset ($this->a_comment[$key])) {
218 echo $this->a_comment[$key];
233 parent::from_request();
234 $http=new \HttpInput();
235 $this->
table->tva_reverse_account=
$http->request(
'tva_reverse_account');
246 if ( $this->previous_id ===
null ) {
247 throw new \Exception (
"TVA184: no previous TVA id");
249 $cn=Dossier::connect();
252 if ($this->
table->tva_both_side==1)
254 if ($this->
table->tva_purchase==
"#"||trim($this->
table->tva_purchase)
257 $this->
table->tva_purchase=$this->
table->tva_sale;
259 if ($this->
table->tva_sale==
"#"||trim($this->
table->tva_sale)==
"#")
261 $this->
table->tva_sale=$this->
table->tva_purchase;
264 $new_tva_id=$this->
table->tva_id;
272 $tva_rate->setp(
"tva_reverse_account", $this->
table->tva_reverse_account);
275 $tva_purchase=(trim($this->
table->tva_purchase)==
"")?
"#":$this->
table->tva_purchase;
276 $tva_sale=(trim($this->
table->tva_sale)==
"")?
"#":$this->
table->tva_sale;
277 $tva_rate->setp(
"tva_poste", $tva_purchase.
",".$tva_sale);
278 $tva_rate->setp(
"tva_payment_sale", $this->
table->tva_payment_sale);
279 $tva_rate->setp(
"tva_payment_purchase", $this->
table->tva_payment_purchase);
280 if ( $this->previous_id == -1 ) {
285 if ( $this->previous_id != - 1 && $this->previous_id != $new_tva_id) {
286 $cn->exec_sql(
"update tva_rate set tva_id = $1 where tva_id = $2",[$new_tva_id,$this->previous_id]);
287 $this->
table->setp(
"tva_id",$new_tva_id);
300 $cn=Dossier::connect();
301 if ( $this->previous_id ===
null ) {
302 throw new \Exception (
"TVA184: no previous TVA id");
305 if (trim($this->
table->tva_purchase??
"")==
""&&trim($this->
table->tva_sale??
"")==
"")
308 _(
"Les 2 postes comptables ne peuvent être nuls"));
310 _(
"Les 2 postes comptables ne peuvent être nuls"));
314 if (trim($this->
table->tva_rate??
"")==
""||
isNumber($this->
table->tva_rate)==0||$this->table->tva_rate>1)
316 $this->
set_error(
"tva_rate",
_(
"Taux de TVA invalide"));
320 $count=
$cn->get_value(
"select count(*) from tva_rate where tva_id<>$1 and lower(tva_label)=lower($2)",
324 $this->
set_error(
"tva_label",
_(
"Ce nom est déjà utilisé"));
328 if (trim($this->
table->tva_purchase??
"")!=
""&&$this->table->tva_purchase!=
"#")
330 $count=
$cn->get_value(
"select count(*) from tmp_pcmn where pcm_val = $1",
331 [$this->
table->tva_purchase]);
334 $this->
set_error(
"tva_purchase",
_(
"Poste comptable inexistant"));
338 if (trim($this->
table->tva_sale??
"")!=
""&&$this->table->tva_sale!=
"#")
340 $count=
$cn->get_value(
"select count(*) from tmp_pcmn where pcm_val = $1",
341 [$this->
table->tva_sale]);
344 $this->
set_error(
"tva_sale",
_(
"Poste comptable inexistant"));
349 if ($this->
table->tva_both_side!=0&&$this->table->tva_both_side!=1)
351 $this->
set_error(
"tva_both_side",
_(
"Choix incorrect"));
355 if (
isNumber($this->
table->tva_id) == 0 || $this->table->tva_id != round($this->
table->tva_id) )
357 $this->
set_error(
"tva_id",
_(
"Valeur invalide"));
361 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)
363 $this->
set_error(
"tva_id",
_(
"Code TVA déjà utilisé"));
366 $this->
table->tva_code=strtoupper(trim( $this->
table->tva_code));
367 $tva_code=$this->
table->tva_code;
369 $tva_code=strtoupper($tva_code);
370 $tva_code=preg_replace(
"/[A-Z]/",
"", $tva_code);
371 $tva_code=preg_replace(
"/[0-9]/",
"", $tva_code);
373 if (strlen($tva_code)>0){
374 $this->
set_error(
"tva_code",
_(
"code tva : Uniquement des chiffres et des lettres"));
377 if (strlen($this->
table->tva_code)>5){
378 $this->
set_error(
"tva_code",
_(
"code tva : Maximum 5 caractères"));
381 $this->
set_error(
"tva_code",
_(
"code tva : doit aussi contenir des lettres"));
386 if ( $this->
table->tva_both_side==0 && trim($this->
table->tva_reverse_account??
"") !=
"")
388 $this->
set_error(
"tva_reverse_account",
_(
"Pas d'autoliquidation demandé"));
390 if ( $this->
table->tva_both_side==1 && trim($this->
table->tva_reverse_account??
"") !=
"")
392 $count=
$cn->get_value(
"select count(*) from tmp_pcmn where pcm_val = $1",
393 [$this->
table->tva_reverse_account]);
396 $this->
set_error(
"tva_reverse_account",
_(
"Poste comptable inexistant"));
400 if ( trim($this->
table->tva_label??
"")==
"") {
401 $this->
set_error(
"tva_label",
_(
'Le label ne peut être vide'));
412 $cn=Dossier::connect();
413 $count_purchase=
$cn->get_value(
"select count(*) from quant_purchase where qp_vat_code = $1",[$this->
table->tva_id]);
414 $count_sale=
$cn->get_value(
"select count(*) from quant_sold where qs_vat_code = $1",[$this->
table->tva_id]);
415 if ( $count_purchase > 0 || $count_sale > 0) {
416 throw new Exception(
_(
"Effacement interdit : TVA utilisée"));
420 $count=
$cn->get_value(
"select count(*) from tva_rate");
422 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é"));
424 $cn->exec_sql(
"delete from tva_rate where tva_id=$1", [$this->
table->tva_id]);
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.
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
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)