Supplemental TAX : manage parameter

A ledger can have only 1 supplemental tax
This commit is contained in:
sparkyx 2022-05-17 14:32:47 +02:00
parent f8251c0f04
commit c4645e68e1
9 changed files with 339 additions and 3 deletions

View file

@ -311,8 +311,10 @@ $path = array(
// search all card , analytic or accounting
"search_account_card"=>"ajax_search_account_card",
// Mobile device menu from mobile_device_mtable
"mobile_device_menu"=>"ajax_mobile_device_menu"
) ;
"mobile_device_menu"=>"ajax_mobile_device_menu",
// other_tax
"other_tax"=>"ajax_other_tax"
) ;
if (array_key_exists($op, $path)) {
require NOALYSS_INCLUDE.'/ajax/'.$path[$op].".php";

View file

@ -0,0 +1,32 @@
<?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
*/
/**
* @file
* @brief manage the public.acc_other_tax
*/
?>
<div class="content">
<?php
$acc_other_tax=Acc_Other_Tax_MTable::build(-1);
$acc_other_tax->create_js_script();
$acc_other_tax->display_table();
?>
</div>

View file

@ -0,0 +1,49 @@
<?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 (2002-2022) Author Dany De Bontridder <danydb@noalyss.eu>
*/
global $g_user;
if ( $g_user->check_module("OTAX") == 0) die();
try {
$table=$http->request('table');
$action=$http->request('action');
$p_id=$http->request('p_id', "number");
$ctl_id=$http->request('ctl');
} catch(Exception $e) {
echo $e->getMessage();
return;
}
$acc_other_tax=Acc_Other_Tax_MTable::build($p_id);
if ($action == "input") {
$acc_other_tax->send_header();
echo $acc_other_tax->ajax_input()->saveXML();
} elseif ($action=="save") {
$acc_other_tax->send_header();
echo $acc_other_tax->ajax_save()->saveXML();
}elseif ($action=="delete") {
$acc_other_tax->send_header();
echo $acc_other_tax->ajax_delete()->saveXML();
}else {
die("error");
}

View file

@ -0,0 +1,167 @@
<?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 (2002-2022) Author Dany De Bontridder <danydb@noalyss.eu>
*/
class Acc_Other_Tax_MTable extends Manage_Table_SQL
{
/**
* @brief Build and returns an object
* @param int $p_id
*/
static public function build($p_id=-1)
{
$cn=Dossier::connect();
$object_sql=new Acc_Other_Tax_SQL($cn,$p_id);
$object=new Acc_Other_Tax_MTable($object_sql);
$object->set_object_name("other_tax_ctl");
$object->set_callback("ajax_misc.php");
$object->add_json_param("op","other_tax");
$object->set_order(["ac_label","ac_rate","ac_accounting","ajrn_def_id"]);
$object->set_col_label("ac_label",_("Nom"));
$object->set_col_label("ajrn_def_id",_("Journaux"));
$object->set_col_label("ac_rate",_("Taux"));
$object->set_col_tips("ac_rate",82);
$object->set_col_label("ac_accounting",_("Poste comptable"));
$object->set_col_tips("ac_accounting",81);
$object->set_col_type("ac_accounting","custom");
$object->set_col_type("ajrn_def_id","custom");
$object->set_property_visible("ajrn_def_id",false);
return $object;
}
function input_custom($p_key,$p_value) {
switch ($p_key) {
case "ac_accounting":
$accounting=new IPoste("ac_accounting",$p_value);
$accounting->set_attribute('gDossier',Dossier::id());
$accounting->set_attribute('jrn',0);
$accounting->set_attribute('account','ac_accounting');
echo $accounting->input();
break;
case "ajrn_def_id":
$cn=Dossier::connect();
$a_ledger=$cn->get_array("select
jrn_def_id,jrn_def_name ,
coalesce ( (select array_position(ajrn_def_id,jrn_def_id) from acc_other_tax
where ac_id=$1
),0) as in_array
from jrn_def
where
jrn_enable=1
and jrn_def_type in ('ACH','VEN')
order by jrn_def_name",[$this->get_table()->get("ac_id")]);
if (empty($a_ledger) ) {
echo _("Aucun journal disponible");
return;
}
$nb_ledger=count($a_ledger);
echo '<ul class="tab_row">';
for ($i=0;$i<$nb_ledger;$i++) {
$icheckbox=new ICheckBox("check[]",$a_ledger[$i]['jrn_def_id']);
if ( $a_ledger[$i]['in_array']!=0) {
$icheckbox->set_check($a_ledger[$i]['jrn_def_id']);
}
echo '<li>',
$icheckbox->input(),
h($a_ledger[$i]['jrn_def_name']),
'</li>';
}
echo '</ul>';
break;
}
}
function display_row_custom($p_key, $p_value, $p_id = 0)
{
$cn=Dossier::connect();
switch ($p_key)
{
case 'ac_accounting':
$label=$cn->get_value("select pcm_lib from tmp_pcmn where pcm_val=$1",
[$p_value]);
echo '<td>',
h($p_value),
" ",
h($label),
'</td>';
break;
}
}
function check()
{
$row=$this->get_table();
$cn=$row->get_cn();
if ( trim($row->getp("ac_rate")) == "") {
$row->setp("ac_rate",0);
}
if ( $row->getp("ac_rate")>100 || $row->getp("ac_rate")< 0 ) {
$this->set_error("ac_rate",_("Valeur invalide"));
}
$accounting=$row->getp("ac_accounting");
$nb_accounting=$cn->get_value("select count(*) from tmp_pcmn where pcm_val =format_account($1)",
[$accounting]);
if (empty($accounting)||$nb_accounting == 0) {
$this->set_error("ac_accounting",_("Poste comptable inexistant"));
}
$ledger=$row->get("ajrn_def_id");
if ( $ledger != "{}" && ! empty ($ledger))
{
$ledger=trim($ledger,'{');
$ledger=trim($ledger,'}');
$a_ledger=explode(",",$ledger);
$nb_ledger=count($a_ledger);
$pk=$row->get("ac_id");
for ($i=0;$i<$nb_ledger;$i++) {
if ($cn->get_value("select count(*) from acc_other_tax
where
array_position(ajrn_def_id,$1) is not null
and ac_id != $2
",[$a_ledger[$i],$pk]) > 0)
{
$this->set_error("ajrn_def_id",_("Journal déjà utilisé dans autre taxe"));
}
}
}
if ($this->count_error()>0) {
return false;
}
return true;
}
function input()
{
$this->set_property_visible("ajrn_def_id",true);
return parent::input();
}
function from_request()
{
parent::from_request(); // TODO: Change the autogenerated stub
$http=new HttpInput();
$this->table->set("ajrn_def_id","{".join(",",$http->post("check","array",array()))."}");
}
}

View file

@ -599,7 +599,9 @@ function noalyss_class_autoloader($class) {
"card_property"=>"class/card_property.class.php",
"pdfland"=>"class/pdf_land.class.php",
"pdf_anc_acc_list"=>"class/pdf_anc_acc_list.class.php",
'acc_reconciliation_lettering'=>'class/acc_reconciliation_lettering.class.php'
'acc_reconciliation_lettering'=>'class/acc_reconciliation_lettering.class.php',
"acc_other_tax_mtable"=>'class/acc_other_tax_mtable.class.php',
'acc_other_tax_sql'=>'database/acc_other_tax_sql.class.php'
);
if ( isset ($aClass[$class]) ) {
require_once NOALYSS_INCLUDE."/".$aClass[$class];

View file

@ -0,0 +1,67 @@
<?php
/*
* 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
*/
/**
* class_action_gestion_sql.php
*
* @file
* @brief abstract of the table public.action_gestion */
/**
* @class Acc_Other_Tax_SQL
* @brief ORM public.acc_other_tax
*/
class Acc_Other_Tax_SQL extends Table_Data_SQL
{
function __construct(DatabaseCore $p_cn, $p_id=-1)
{
$this->table="public.acc_other_tax";
$this->primary_key="ac_id";
/*
* List of columns
*/
$this->name=array(
"ac_id"=>"ac_id",
"ac_label"=>"ac_label",
"ac_rate"=>"ac_rate",
"ajrn_def_id"=>"ajrn_def_id",
"ac_accounting"=>"ac_accounting"
);
/*
* Type of columns
*/
$this->type=array(
"ac_id"=>"numeric",
"ac_label"=>"text",
"ac_rate"=>"numeric",
"ajrn_def_id"=>"array",
"ac_accounting"=>"text"
);
$this->default=array(
"ac_id"=>"auto"
);
parent::__construct($p_cn, $p_id);
}
}

View file

@ -114,4 +114,6 @@ content[78]="<?php echo htmlspecialchars($file_too_large,ENT_QUOTES)?>";
content[79]="<?php echo htmlspecialchars(_("Les postes comptables sont entre [] , les fiches entre {} et les postes analytiques entre {{ }}"))?>";
content[80]="<?php echo htmlspecialchars(_("Oui pour charger les fichiers javascripts et CSS standards"),ENT_QUOTES)?>";
content[81]="<?php echo htmlspecialchars(_("Recommendé d'avoir un poste propre"),ENT_QUOTES)?>";
content[82]="<?php echo htmlspecialchars(_("valeur en % "),ENT_QUOTES)?>";
</script>

View file

View file

@ -0,0 +1,15 @@
-- auto-generated definition
create table acc_other_tax
(
ac_id serial constraint acc_other_tax_pk primary key,
ac_label text not null,
ac_rate numeric (5,2) not null,
ajrn_def_id integer[],
ac_accounting account_type not null
);
comment on table acc_other_tax is 'Other tax ';
comment on column acc_other_tax.ac_label is 'Label of the tax';
comment on column acc_other_tax.ac_rate is 'rate of the tax in percent';
comment on column acc_other_tax.ajrn_def_id is 'array of to FK jrn_def (jrn_def_id)';
comment on column acc_other_tax.ac_accounting is 'FK tmp_pcmn (pcm_val)';