From c4645e68e1919e36b4f5a3026ba85e9f29e1cba5 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Tue, 17 May 2022 14:32:47 +0200 Subject: [PATCH] Supplemental TAX : manage parameter A ledger can have only 1 supplemental tax --- html/ajax_misc.php | 6 +- include/acc_other_tax.inc.php | 32 ++++ include/ajax/ajax_other_tax.php | 49 ++++++ include/class/acc_other_tax_mtable.class.php | 167 +++++++++++++++++++ include/constant.php | 4 +- include/database/acc_other_tax_sql.class.php | 67 ++++++++ include/lib/message_javascript.php | 2 + scenario/test_postgres_json_array.php | 0 sql/upgrade.sql | 15 ++ 9 files changed, 339 insertions(+), 3 deletions(-) create mode 100644 include/acc_other_tax.inc.php create mode 100644 include/ajax/ajax_other_tax.php create mode 100644 include/class/acc_other_tax_mtable.class.php create mode 100644 include/database/acc_other_tax_sql.class.php create mode 100644 scenario/test_postgres_json_array.php diff --git a/html/ajax_misc.php b/html/ajax_misc.php index e9be4d0d2..8a2fe06ff 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -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"; diff --git a/include/acc_other_tax.inc.php b/include/acc_other_tax.inc.php new file mode 100644 index 000000000..3e3a74e66 --- /dev/null +++ b/include/acc_other_tax.inc.php @@ -0,0 +1,32 @@ + +
+create_js_script(); +$acc_other_tax->display_table(); +?> + +
+ diff --git a/include/ajax/ajax_other_tax.php b/include/ajax/ajax_other_tax.php new file mode 100644 index 000000000..145f28829 --- /dev/null +++ b/include/ajax/ajax_other_tax.php @@ -0,0 +1,49 @@ + + */ +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"); +} \ No newline at end of file diff --git a/include/class/acc_other_tax_mtable.class.php b/include/class/acc_other_tax_mtable.class.php new file mode 100644 index 000000000..0b0054e1d --- /dev/null +++ b/include/class/acc_other_tax_mtable.class.php @@ -0,0 +1,167 @@ + + */ +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 ''; + 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 '', + h($p_value), + " ", + h($label), + ''; + 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()))."}"); + } +} diff --git a/include/constant.php b/include/constant.php index a453ed2ac..a2d1d766b 100644 --- a/include/constant.php +++ b/include/constant.php @@ -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]; diff --git a/include/database/acc_other_tax_sql.class.php b/include/database/acc_other_tax_sql.class.php new file mode 100644 index 000000000..0a11c91c9 --- /dev/null +++ b/include/database/acc_other_tax_sql.class.php @@ -0,0 +1,67 @@ +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); + } + +} diff --git a/include/lib/message_javascript.php b/include/lib/message_javascript.php index 792b7d777..5a29c3467 100644 --- a/include/lib/message_javascript.php +++ b/include/lib/message_javascript.php @@ -114,4 +114,6 @@ content[78]=""; content[79]=""; content[80]=""; +content[81]=""; +content[82]=""; diff --git a/scenario/test_postgres_json_array.php b/scenario/test_postgres_json_array.php new file mode 100644 index 000000000..e69de29bb diff --git a/sql/upgrade.sql b/sql/upgrade.sql index e69de29bb..fbb6dac2f 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -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)'; +