Task #0001535: TVA : réécriture du module CFGTVA

This commit is contained in:
Dany De Bontridder 2018-02-10 14:11:31 +01:00
parent a4c94b2f49
commit 7aadeb3d47
9 changed files with 465 additions and 425 deletions

View file

@ -236,7 +236,9 @@ $path = array(
// Attribute for category of card
'template_cat_category'=>'ajax_template_cat_category',
// From FollowUp , update a comment on a file
'update_comment_followUp'=>'ajax_follow_up'
'update_comment_followUp'=>'ajax_follow_up',
// TVA param
"tva_parameter"=>"ajax_tva_parameter"
) ;
if (array_key_exists($op, $path)) {

View file

@ -0,0 +1,278 @@
<?php
/*
* This file is part of NOALYSS.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Copyright (2018) Author Dany De Bontridder <dany@alchimerys.be>
/**
* @file
* @brief Configure the tva : code , rate, label ...
*/
require_once NOALYSS_INCLUDE."/lib/manage_table_sql.class.php";
require_once NOALYSS_INCLUDE."/lib/icon_action.class.php";
require_once NOALYSS_INCLUDE."/database/v_tva_rate_sql.class.php";
require_once NOALYSS_INCLUDE."/database/tva_rate_sql.class.php";
/**
* @class
* @brief Configure the tva : code , rate, label ...
* When using Manage_Table_SQL
*/
class Tva_Rate_MTable extends Manage_Table_SQL
{
/**
*
* @param V_Tva_rate_SQL $p_table
* @example tva_parameter.php
*/
function __construct(V_Tva_rate_SQL $p_table)
{
parent::__construct($p_table);
$this->set_col_label("tva_id", _("id"));
$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"=>_("Normal")],
["value"=>1, "label"=>_("Autoliquidation")]
));
$this->set_property_updatable("tva_id", FALSE);
$this->a_info=["tva_purchase"=>44,"tva_both_side"=>43,"tva_sale"=>45];
}
/**
* @brief display into a dialog box the datarow in order
* to be appended or modified. Can be override if you need
* a more complex form
*/
function input()
{
$nb_order=count($this->a_order);
echo "<table>";
for ($i=0; $i<$nb_order; $i++)
{
echo "<tr>";
$key=$this->a_order[$i];
$label=$this->a_label_displaid[$key];
$value=$this->table->get($key);
$error=$this->get_error($key);
$error=($error=="")?"":HtmlInput::errorbulle($error);
if ($this->get_property_visible($key)===TRUE)
{
$info="";
if ( isset($this->a_info[$key])) {
$info=Icon_Action::infobulle($this->a_info[$key]);
}
// Label
echo "<td> {$label} {$info} {$error}</td>";
if ($this->get_property_updatable($key)==TRUE)
{
echo "<td>";
if ($this->a_type[$key]=="select")
{
$select=new ISelect($key);
$select->value=$this->a_select[$key];
$select->selected=$value;
echo $select->input();
}
elseif ($key=="tva_rate")
{
$text=new INum($key);
$text->value=$value;
$text->prec=4;
$min_size=(strlen($value)<10)?10:strlen($value)+1;
$text->size=$min_size;
echo $text->input();
}
elseif ($key=='tva_purchase')
{
$text=new IPoste("tva_purchase");
$text->value=$value;
$min_size=10;
$text->size=$min_size;
$text->set_attribute('gDossier', Dossier::id());
$text->set_attribute('jrn', 0);
$text->set_attribute('account', 'tva_purchase');
echo $text->input();
//@todo ajout infobulle pour prévenir que compte doit exister
}
elseif ($key=='tva_sale')
{
$text=new IPoste("tva_sale");
$text->value=$value;
$min_size=10;
$text->set_attribute('gDossier', Dossier::id());
$text->set_attribute('jrn', 0);
$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;
echo $text->input();
}
echo "</td>";
}
else
{
printf('<td>%s %s</td>', h($value),
HtmlInput::hidden($key, $value)
);
}
}
echo "</tr>";
}
echo "</table>";
}
/**
* @brief save the data in TVA_RATE
* if tva_both_side is 1 and tva_purchase or tva_sale is empty then
it is equal to the other value
*
*/
function save()
{
$cn=Dossier::connect();
// if tva_both_side is 1 and tva_purchase or tva_sale is empty then
// it is equal to the other value
if ($this->table->tva_both_side==1)
{
if ($this->table->tva_purchase=="#"||trim($this->table->tva_purchase)
=="#")
{
$this->table->tva_purchase=$this->table->tva_sale;
}
if ($this->table->tva_sale=="#"||trim($this->table->tva_sale)=="#")
{
$this->table->tva_sale=$this->table->tva_purchase;
}
}
$tva_rate=new Tva_rate_SQL($cn, $this->table->tva_id);
$tva_rate->setp("tva_rate", $this->table->tva_rate);
$tva_rate->setp("tva_label", $this->table->tva_label);
$tva_rate->setp("tva_comment", $this->table->tva_comment);
$tva_rate->setp("tva_both_side", $this->table->tva_both_side);
// TVA accounting must be joined and separated with a comma
$tva_purchase=(trim($this->table->tva_purchase)=="")?"#":$this->table->tva_purchase;
$tva_sale=(trim($this->table->tva_sale)=="")?"#":$this->table->tva_sale;
$tva_rate->setp("tva_poste", $tva_purchase.",".$tva_sale);
$tva_rate->save();
// reload the row
$this->table->set_pk_value($tva_rate->tva_id);
$this->table->load();
}
/**
* Check data are valid
* 1. tva_rate between 0 & 1
* 2. label is uniq
* 3. accounting must exist
* @return boolean
*/
function check()
{
$cn=Dossier::connect();
// both accounting can not be empty
if (trim($this->table->tva_purchase)==""&&trim($this->table->tva_sale)=="")
{
$this->set_error("tva_purchase",
_("Les 2 postes comptables ne peuvent être nuls"));
$this->set_error("tva_sale",
_("Les 2 postes comptables ne peuvent être nuls"));
}
// Check the tva rate
if (trim($this->table->tva_rate)==""||isNumber($this->table->tva_rate)==0||$this->table->tva_rate>1)
{
$this->set_error("tva_rate", _("Taux de TVA invalide"));
}
//Check the label must be unique
$count=$cn->get_value("select count(*) from tva_rate where tva_id<>$1 and lower(tva_label)=lower($2)",
[$this->table->tva_id, $this->table->tva_label]);
if ($count>0)
{
$this->set_error("tva_label", _("Ce nom est déjà utilisé"));
}
// Check accounting exists for purchase
if (trim($this->table->tva_purchase)!=""&&$this->table->tva_purchase!="#")
{
$count=$cn->get_value("select count(*) from tmp_pcmn where pcm_val = $1",
[$this->table->tva_purchase]);
if ($count==0)
{
$this->set_error("tva_purchase", _("Poste comptable inexistant"));
}
}
// Check accounting exists for sale
if (trim($this->table->tva_sale)!=""&&$this->table->tva_sale!="#")
{
$count=$cn->get_value("select count(*) from tmp_pcmn where pcm_val = $1",
[$this->table->tva_sale]);
if ($count==0)
{
$this->set_error("tva_sale", _("Poste comptable inexistant"));
}
}
// check if tva_both_side is valid
if ($this->table->tva_both_side!=0&&$this->table->tva_both_side!=1)
{
$this->set_error("tva_both_side", _("Choix incorrect"));
}
if ($this->count_error()!=0)
return false;
return true;
}
/**
* delete if not used anywhere
*/
function delete()
{
$cn=Dossier::connect();
$count_purchase=$cn->get_value("select count(*) from quant_purchase where qp_vat_code = $1",[$this->table->tva_id]);
$count_sale=$cn->get_value("select count(*) from quant_sold where qs_vat_code = $1",[$this->table->tva_id]);
if ( $count_purchase > 0 || $count_sale > 0) {
throw new Exception(_("Effacement interdit : TVA utilisée"));
}
// Forbid to remove all tva
$count=$cn->get_value("select count(*) from tva_rate");
if ( $count < 2) {
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é"));
}
}
}

View file

@ -108,7 +108,7 @@ if ( !defined("SITE_UPDATE_PLUGIN"))
if ( ! defined ("SYSINFO_DISPLAY")) {
define ("SYSINFO_DISPLAY",TRUE);
}
define ("DBVERSION",127);
define ("DBVERSION",128);
define ("MONO_DATABASE",25);
define ("DBVERSIONREPO",18);
define ('NOTFOUND','--not found--');

View file

@ -0,0 +1,70 @@
<?php
/**
* Autogenerated file
* This file is part of NOALYSS.
*
* NOALYSS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* NOALYSS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NOALYSS; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once NOALYSS_INCLUDE.'/lib/noalyss_sql.class.php';
require_once NOALYSS_INCLUDE.'/lib/database.class.php';
/**
* class_tva_rate_sql.php
*
* @file
* @brief abstract of the table public.tva_rate
*
*/
class Tva_rate_SQL extends Noalyss_SQL
{
function __construct(Database $p_cn, $p_id=-1)
{
$this->table="public.tva_rate";
$this->primary_key="tva_id";
/*
* List of columns
*/
$this->name=array(
"tva_id"=>"tva_id"
, "tva_label"=>"tva_label"
, "tva_rate"=>"tva_rate"
, "tva_comment"=>"tva_comment"
, "tva_poste"=>"tva_poste"
, "tva_both_side"=>"tva_both_side"
);
/*
* Type of columns
*/
$this->type=array(
"tva_id"=>"numeric"
, "tva_label"=>"text"
, "tva_rate"=>"numeric"
, "tva_comment"=>"text"
, "tva_poste"=>"text"
, "tva_both_side"=>"numeric"
);
$this->default=array(
"tva_id"=>"auto"
);
$this->date_format="DD.MM.YYYY";
parent::__construct($p_cn, $p_id);
}
}

View file

@ -0,0 +1,72 @@
<?php
/**
* Autogenerated file
* This file is part of NOALYSS.
*
* NOALYSS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* NOALYSS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NOALYSS; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once NOALYSS_INCLUDE.'/lib/noalyss_sql.class.php';
require_once NOALYSS_INCLUDE.'/lib/database.class.php';
/**
* class_tva_rate_sql.php
*
* @file
* @brief abstract of the view public.v_tva_rate
*
*/
class V_Tva_Rate_SQL extends Noalyss_SQL
{
function __construct(Database $p_cn, $p_id=-1)
{
$this->table="public.v_tva_rate";
$this->primary_key="tva_id";
/*
* List of columns
*/
$this->name=array(
"tva_id"=>"tva_id"
, "tva_label"=>"tva_label"
, "tva_rate"=>"tva_rate"
, "tva_comment"=>"tva_comment"
, "tva_purchase"=>"tva_purchase"
, "tva_sale"=>"tva_sale"
, "tva_both_side"=>"tva_both_side"
);
/*
* Type of columns
*/
$this->type=array(
"tva_id"=>"numeric"
, "tva_label"=>"text"
, "tva_rate"=>"numeric"
, "tva_comment"=>"text"
, "tva_purchase"=>"text"
, "tva_sale"=>"text"
, "tva_both_side"=>"numeric"
);
$this->default=array(
"tva_id"=>"auto"
);
$this->date_format="DD.MM.YYYY";
parent::__construct($p_cn, $p_id);
}
}

View file

@ -71,5 +71,7 @@ content[39]="<?php echo _("Le préfixe des pièces doit être différent pour ch
content[40]="<?php echo _("Laissez à 0 pour ne pas changer le numéro")?>";
content[41]="<?php echo _("Mettez le pourcentage <br> à zéro pour effacer la ligne")?>";
content[42]="<?php echo _("Selectionnez le plan qui vous intéresse avant de cliquer sur Recherche")?>";
content[43]="<?php echo _("Autoliquidation : Utilisé en même temps au crédit et au débit")?>";
content[44]="<?php echo _("Ne donner pas ce poste comptable si ce code n'est pas utilisé à l'achat")?>";
content[45]="<?php echo _("Ne donner pas ce poste comptable si ce code n'est pas utilisé à la vente")?>";
</script>

View file

@ -0,0 +1,18 @@
begin;
create view v_tva_rate as select
tva_id,
tva_rate,
tva_label,
tva_comment,
split_part(tva_poste,',',1) as tva_purchase,
split_part(tva_poste,',',2) as tva_sale,
tva_both_side
from tva_rate;
comment on view v_tva_rate is 'Show this table to be easily used by Tva_Rate_MTable';
comment on column v_tva_rate.tva_purchase is ' VAT used for purchase';
comment on column v_tva_rate.tva_sale is ' VAT used for sale';
comment on column v_tva_rate.tva_both_side is 'if 1 , VAT avoided ';
insert into version (val,v_description) values (128,'Add a view to manage VAT');
commit;

View file

@ -25,317 +25,25 @@ require_once NOALYSS_INCLUDE.'/class/noalyss_parameter_folder.class.php';
require_once NOALYSS_INCLUDE.'/lib/html_input.class.php';
require_once NOALYSS_INCLUDE.'/lib/ihidden.class.php';
require_once NOALYSS_INCLUDE.'/lib/itextarea.class.php';
require_once NOALYSS_INCLUDE."/class/tva_rate_mtable.class.php";
$cn=Dossier::connect();
$own=new Noalyss_Parameter_Folder($cn);
echo '<div class="content">';
// Confirm remove
if (isset($_POST['confirm_rm']))
{
if ($cn->count_sql('select * from tva_rate') > 1)
$cn->exec_sql('select tva_delete($1)', array($_POST['tva_id']));
else
echo '<p class="notice">Vous ne pouvez pas effacer tous taux' .
' Si votre soci&eacute;t&eacute; n\'utilise pas la TVA, changer dans le menu soci&eacute;t&eacute</p>';
}
$both_side=(isset($_REQUEST['both']))?1:0;
//-----------------------------------------------------
// Record Change
if (isset($_POST['confirm_mod'])
|| isset($_POST['confirm_add']))
{
extract($_POST, EXTR_SKIP);
// remove space
$tva_poste = str_replace(" ", "", $tva_poste);
$err = 0; // Error code
if (isNumber($tva_rate) == 0)
{
$err = 2;
}
if ($err == 0)
{
if (isset($_POST['confirm_add']))
{
$sql = "select tva_insert($1,$2,$3,$4,$5)";
$res = $cn->exec_sql(
$sql, array($tva_label,
$tva_rate,
$tva_comment,
$tva_poste,
$both_side)
);
$err = Database::fetch_result($res);
}
if (isset($_POST['confirm_mod']))
{
$Res = $cn->exec_sql(
"select tva_modify($1,$2,$3,$4,$5,$6)", array($tva_id, $tva_label, $tva_rate, $tva_comment, $tva_poste,$both_side)
);
$err = Database::fetch_result($Res);
}
}
if ($err != 0)
{
$err_code = array(1 => "Tva id n\'est pas un nombre",
2 => "Taux tva invalide",
3 => "Label ne peut être vide",
4 => "Poste invalide",
5 => "Tva id doit être unique");
$str_err = $err_code[$err];
alert($str_err);
;
}
}
// If company not use VAT
$own = new Noalyss_Parameter_Folder($cn);
if ($own->MY_TVA_USE == 'N')
{
echo '<h2 class="error">'._("Vous n'êtes pas assujetti à la TVA").'</h2>';
return;
}
//-----------------------------------------------------
// Display
$sql = "select tva_id,tva_label,tva_rate,tva_comment,tva_poste,tva_both_side from tva_rate order by tva_label";
$Res = $cn->exec_sql($sql);
?>
<TABLE>
<TR>
<th>Id</th>
<th>Label</TH>
<th>Taux</th>
<th>Commentaire</th>
<th>Poste</th>
<th>Utilisé en même temps au crédit et au débit</th>
</tr>
<?php
$val = Database::fetch_all($Res);
foreach ($val as $row)
{
// load value into an array
$index = $row['tva_id'];
$tva_array[$index] = array(
'tva_label' => $row['tva_label'],
'tva_rate' => $row['tva_rate'],
'tva_comment' => $row['tva_comment'],
'tva_poste' => $row['tva_poste'],
'tva_both_side' => $row['tva_both_side']
);
echo "<TR>";
echo '<FORM METHOD="POST">';
$tva_rate=new V_Tva_Rate_SQL($cn);
echo '<td>';
echo $row['tva_id'];
echo '</td>';
$manage_table=new Tva_Rate_MTable($tva_rate);
echo "<TD>";
echo HtmlInput::hidden('tva_id', $row['tva_id']);
echo h($row['tva_label']);
echo "</TD>";
echo "<TD>";
echo $row['tva_rate'];
echo "</TD>";
echo "<TD>";
echo h($row['tva_comment']);
echo "</TD>";
echo "<TD>";
echo $row['tva_poste'];
echo "</TD>";
echo "<TD>";
$str_msg=( $row['tva_both_side']==1)?'Employé au crédit et débit':'normal' ;
echo $str_msg;
echo "</TD>";
echo "<TD>";
echo HtmlInput::submit("rm", "Efface");
echo HtmlInput::submit("mod", "Modifie");
$w = new IHidden();
$w->name = "tva_id";
$w->value = $row['tva_id'];
echo $w->input();
$w = new IHidden();
$w->name = "p_action";
$w->value = "divers";
echo $w->input();
$w = new IHidden();
$w->name = "sa";
$w->value = "tva";
echo $w->input();
echo "</TD>";
echo '</FORM>';
echo "</TR>";
}
?>
</TABLE>
<?php
// if we add / remove or modify a vat we don't show this button
if (!isset($_POST['add'])
&& !isset($_POST['mod'])
&& !isset($_POST['rm'])
)
{
?>
<form method="post">
<input type="submit" class="button" name="add" value="Ajouter un taux de tva">
<input type="hidden" name="p_action" value="divers">
<input type="hidden" name="sa" value="tva">
</form>
<?php
}
//-----------------------------------------------------
// remove
if (isset($_REQUEST['rm']))
{
echo "Voulez-vous vraiment effacer ce taux ? ";
$index = $_POST['tva_id'];
?>
<table>
<TR>
<th>Label</TH>
<th>Taux</th>
<th>Commentaire</th>
<th>Poste</th>
<th>Double côté</th>
</tr>
<tr>
<td> <?php echo $tva_array[$index]['tva_label'];?></td>
<td> <?php echo $tva_array[$index]['tva_rate'];?></td>
<td> <?php echo $tva_array[$index]['tva_comment'];?></td>
<td> <?php echo $tva_array[$index]['tva_poste'];?></td>
<td> <?php echo $tva_array[$index]['tva_both_side'];?></td>
</Tr>
</table>
<?php
echo '<FORM method="post">';
echo '<input type="hidden" name="tva_id" value="' . $index . '">';
echo HtmlInput::submit("confirm_rm", "Confirme");
echo HtmlInput::submit("Cancel", "no");
echo "</form>";
}
//-----------------------------------------------------
// add
if (isset($_REQUEST['add']))
{
echo "<fieldset><legend>Ajout d'un taux de tva </legend>";
echo '<FORM method="post">';
?>
<table >
<tr> <td align="right"> Label (ce que vous verrez dans les journaux)</td>
<td> <?php
$w = new IText();
$w->size = 20;
echo $w->input('tva_label', '')
?></td>
</tr>
<tr><td align="right"> Taux de tva </td>
<td> <?php
$w = new IText();
$w->size = 5;
echo $w->input('tva_rate', '')
?></td>
</tr>
<tr>
<td align="right"> Commentaire </td>
<td> <?php
$w = new ITextarea;
$w->heigh = 5;
$w->width = 50;
echo $w->input('tva_comment', '')
?></td>
</tr>
<tr>
<td align="right">Poste comptable utilisés format :debit,credit</td>
<td> <?php
$w = new IText();
$w->size = 20;
echo $w->input('tva_poste', '')
?></td>
</Tr>
<tr>
<td align="right">Utilisé au débit et au crédit afin d'annuler cette tva </td>
<td> <?php
$w = new ICheckBox("both", 1);
$w->size = 20;
echo $w->input('both', '')
?></td>
</Tr>
</table>
<input type="submit" class="button" value="Confirme" name="confirm_add">
<input type="submit" class="button" value="Cancel" name="no">
</FORM>
</fieldset>
<?php
}
//-----------------------------------------------------
// mod
if (isset($_REQUEST['mod']))
{
echo "Tva à modifier";
$index = $_POST['tva_id'];
echo "<fieldset><legend>Modification d'un taux de tva </legend>";
echo '<FORM method="post">';
echo '<input type="hidden" name="tva_id" value="' . $index . '">';
?>
<table>
<tr> <td align="right"> Label (ce que vous verrez dans les journaux)</td>
<td> <?php
$w = new Itext();
$w->size = 20;
echo $w->input('tva_label', $tva_array[$index]['tva_label'])
?></td>
</tr>
<tr><td align="right"> Taux de tva </td>
<td> <?php
$w = new Itext();
$w->size = 5;
echo $w->input('tva_rate', $tva_array[$index]['tva_rate'])
?></td>
</tr>
<tr>
<td align="right"> Commentaire </td>
<td> <?php
$w = new ITextarea();
$w->heigh = 5;
$w->width = 50;
echo $w->input('tva_comment', $tva_array[$index]['tva_comment'])
?></td>
</tr>
<tr>
<td align="right">Poste comptable utilisés format :debit,credit</td>
<td> <?php
$w = new IText();
$w->size = 20;
echo $w->input('tva_poste', $tva_array[$index]['tva_poste'])
?></td>
</Tr>
<tr>
<td align="right">Utilisé au débit et au crédit afin d'annuler cette tva </td>
<td> <?php
$w = new ICheckBox("both",$tva_array[$index]['tva_both_side'] );
$w->selected=$tva_array[$index]['tva_both_side'];
$w->size = 20;
echo $w->input('both', '')
?></td>
</Tr>
</table>
<input type="submit" class="button" value="Confirme" name="confirm_mod">
<input type="submit" class="button" value="Cancel" name="no">
</FORM>
</fieldset>
<?php
}
$manage_table->set_callback("ajax_misc.php");
$manage_table->add_json_param("op", "tva_parameter");
$manage_table->create_js_script();
$manage_table->display_table();
echo '</div>';
?>

View file

@ -1,119 +1,9 @@
set search_path=public,comptaproc;
alter table action_gestion drop ag_ref_ag_id;
/* --- repository
-- add style
insert into theme (the_name,the_filestyle) values ('Classic7','style-classic7.css');
delete from theme where the_filestyle in ('style-mandarine.css','style-mobile.css');
update user_global_pref set parameter_value='style-classic7.css' where parameter_value in ('style-mandarine.css','style-mobile.css');
-- add constraint
alter table jnt_use_dos add CONSTRAINT use_id_dos_id_uniq UNIQUE (use_id,dos_id);
-- create table to check progress
create table progress
(
p_id varchar(16) primary key,
p_value numeric (5,2) not null ,
p_created timestamp default now()
);
*/
create sequence tmp_pcmn_id_seq;
ALTER TABLE tmp_pcmn ADD COLUMN id bigint;
update tmp_pcmn set id=nextval('tmp_pcmn_id_seq');
ALTER TABLE tmp_pcmn ALTER COLUMN id SET NOT NULL;
ALTER TABLE tmp_pcmn ALTER COLUMN id SET DEFAULT nextval('tmp_pcmn_id_seq'::regclass);
ALTER TABLE tmp_pcmn ADD CONSTRAINT id_ux UNIQUE(id);
COMMENT ON COLUMN tmp_pcmn.id IS 'allow to identify the row, it is unique and not null (pseudo pk)';
update tmp_pcmn set id=nextval('tmp_pcmn_id_seq');
-- set search_path to public,comptaproc;
alter table tmp_pcmn add column pcm_direct_use varchar(1);
COMMENT ON COLUMN tmp_pcmn.pcm_direct_use IS 'Value are N or Y , N cannot be used directly , not even through a card';
ALTER TABLE tmp_pcmn ALTER COLUMN pcm_direct_use SET DEFAULT 'Y';
update tmp_pcmn set pcm_direct_use='Y';
update tmp_pcmn set pcm_direct_use='N' where length(pcm_val) < 3 and not exists (select j_poste from jrnx where j_poste=pcm_val);
ALTER TABLE tmp_pcmn ALTER COLUMN pcm_direct_use SET NOT NULL;
alter table tmp_pcmn add constraint pcm_direct_use_ck check (pcm_direct_use in ('Y','N'));
insert into bilan (b_name,b_file_template,b_file_form,b_type) values ('ASBL','document/fr_be/bnb-asbl.rtf','document/fr_be/bnb-asbl.form','RTF');
alter table jnt_letter drop jl_amount_deb;
ALTER TABLE operation_analytique ADD COLUMN f_id bigint;
ALTER TABLE operation_analytique ADD CONSTRAINT operation_analytique_fiche_id_fk FOREIGN KEY (f_id) REFERENCES fiche (f_id) MATCH SIMPLE ON UPDATE cascade ON cascade;
COMMENT ON COLUMN operation_analytique.f_id IS 'FK to fiche.f_id , used only with ODS';
drop FUNCTION comptaproc.table_analytic_account(text,text);
drop FUNCTION comptaproc.table_analytic_card(text,text);
CREATE TABLE public.user_filter (
id bigserial,
login text NULL,
nb_jrn int4 NULL,
date_start varchar(10) NULL,
date_end varchar(10) NULL,
description text NULL,
amount_min numeric(20,4) NULL,
amount_max numeric(20,4) NULL,
qcode text NULL,
accounting text NULL,
r_jrn text NULL,
date_paid_start varchar(10) NULL,
date_paid_end varchar(10) NULL,
ledger_type varchar(5) NULL,
all_ledger int4 NULL,
filter_name text NOT NULL,
unpaid varchar NULL,
PRIMARY KEY (id)
);
alter table jrn_periode drop constraint jrn_periode_pk;
create sequence jrn_periode_id_seq;
alter table jrn_periode add id bigint;
alter table jrn_periode alter column id set default nextval('jrn_periode_id_seq');
update jrn_periode set id=nextval('jrn_periode_id_seq');
alter table jrn_periode add constraint jrn_periode_pk primary key (id);
alter table jrn_periode add constraint jrn_periode_periode_ledger unique (jrn_def_id,p_id);
CREATE TABLE public.user_active_security (
id serial not NULL,
us_login text NOT NULL,
us_ledger varchar(1) not NULL,
us_action varchar(1) not NULL
);
COMMENT ON COLUMN public.user_active_security.us_login IS 'user''s login' ;
COMMENT ON COLUMN public.user_active_security.us_ledger IS 'Flag Security for ledger' ;
COMMENT ON COLUMN public.user_active_security.us_action IS 'Security for action' ;
ALTER TABLE public.user_active_security ADD CONSTRAINT user_active_security_pk PRIMARY KEY (id) ;
ALTER TABLE public.user_active_security ADD CONSTRAINT user_active_security_ledger_check CHECK (us_ledger in ('Y','N')) ;
ALTER TABLE public.user_active_security ADD CONSTRAINT user_active_security_action_check CHECK (us_action in ('Y','N')) ;
insert into user_active_security (us_login,us_ledger,us_action) select user_name,'Y','Y' from profile_user;
alter table jrn_def add jrn_enable int;
alter table jrn_def alter jrn_enable set default 1;
update jrn_def set jrn_enable=1;
comment on column jrn_def.jrn_enable is 'Set to 1 if the ledger is enable ';
alter table jrn add jr_optype varchar(3);
alter table jrn alter jr_optype set default 'NOR';
comment on column jrn.jr_optype is 'Type of operation , NOR = NORMAL , OPE opening , EXT extourne, CLO closing';
update jrn set jr_optype='NOR';
-- update quant_sold set qs_vat_sided=round(qs_vat_sided,2);
-- update quant_purchase set qp_vat_sided=round(qp_vat_sided,2);
alter table tags add column t_actif char(1);
update tags set t_actif='Y';
ALTER TABLE tags ADD CONSTRAINT tags_check CHECK (t_actif in ('N','Y')) ;
alter table tags alter t_actif set default 'Y';
COMMENT ON COLUMN tags.t_actif is 'Y if the tag is activate and can be used ';
-- in repo
create view v_tva_rate as select
tva_id,
tva_rate,
tva_label,
tva_comment,
split_part(tva_poste,',',1) as tva_purchase,
split_part(tva_poste,',',2) as tva_sale,
tva_both_side
from tva_rate;