[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 10/24: New : 2178 Additional Tax : input in p
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 10/24: New : 2178 Additional Tax : input in purchase and sale ledger - tax with positive amount - tax with negative amount - tax in currency |
Date: |
Tue, 12 Jul 2022 07:05:30 -0400 (EDT) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit 7256f1464d06c80737e2eda7248b1cbeca85f9f5
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Sun May 22 12:02:12 2022 +0200
New : 2178 Additional Tax : input in purchase and sale ledger
- tax with positive amount
- tax with negative amount
- tax in currency
---
include/class/acc_ledger.class.php | 113 ++++++++++++++++++++++++++
include/class/acc_ledger_history.class.php | 52 ++++++++++++
include/class/acc_ledger_purchase.class.php | 77 ++++++++++++++++--
include/class/acc_ledger_sale.class.php | 68 ++++++++++++++--
include/class/acc_tax_purchase_sale.class.php | 84 +++++++++++++++++++
include/class/additional_tax.class.php | 99 ++++++++++++++++++++++
include/class/html_input_noalyss.class.php | 28 +++++++
include/constant.php | 4 +-
include/database/jrn_tax_sql.class.php | 68 ++++++++++++++++
include/template/ledger_detail_ach.php | 28 ++++++-
include/template/ledger_detail_ven.php | 33 ++++++--
sql/upgrade.sql | 31 ++++++-
12 files changed, 658 insertions(+), 27 deletions(-)
diff --git a/include/class/acc_ledger.class.php
b/include/class/acc_ledger.class.php
index 89c118618..4a52f2184 100644
--- a/include/class/acc_ledger.class.php
+++ b/include/class/acc_ledger.class.php
@@ -2231,6 +2231,56 @@ class Acc_Ledger extends jrn_def_sql
return $ret;
}
+ /**
+ * @brief retrieve the previous amount
+ * @param $p_to from the start of exercice until p_to
+ * @return array [other_tax_amount]
+ */
+ function previous_other_tax($p_to) {
+ $periode=new Periode($this->db, $p_to);
+ $exercise=$periode->get_exercice();
+ list ($min, $max)=$periode->get_limit($exercise);
+ // transform min into date
+ $min_date=$min->first_day();
+ // transform $p_to into date
+ $periode_max=new Periode($this->db, $p_to);
+ $max_date=$periode_max->first_day();
+ bcscale(2);
+ // min periode
+ if ($this->get_type()=='ACH')
+ {
+
+ $sql="
+ select j_montant
+ from quant_purchase
+ join jrnx using(j_id)
+ join jrn_tax using (j_id)
+ where j_date >= to_date($1,'DD.MM.YYYY') and j_date <
to_date($2,'DD.MM.YYYY')
+ and j_jrn_def = $3";
+ $amount=$this->db->get_value($sql,
+ array($min_date, $max_date, $this->id));
+
+ return array('other_tax_amount',$amount);
+
+ }
+ if ($this->get_type()=='VEN')
+ {
+
+ $sql="
+ select j_montant
+ from quant_sold
+ join jrnx using(j_id)
+ join jrn_tax using (j_id)
+ where j_date >= to_date($1,'DD.MM.YYYY') and j_date <
to_date($2,'DD.MM.YYYY')
+ and j_jrn_def = $3";
+ $amount=$this->db->get_value($sql,
+ array($min_date, $max_date, $this->id));
+
+ return array('other_tax_amount',$amount);
+
+ }
+ return array('other_tax_amount',0);
+ }
////////////////////////////////////////////////////////////////////////////////
// TEST MODULE
////////////////////////////////////////////////////////////////////////////////
@@ -3296,6 +3346,69 @@ class Acc_Ledger extends jrn_def_sql
$acc_operation->insert_related_action($s_related_action);
return true;
}
+
+ /**
+ * @brief form : display additional tax available for this ledger and
value, set 2 values : checkbox if tax applies
+ * and value
+ *
+ * @see template/form_ledger_detail.php
+ * @returns string
+ */
+ function input_additional_tax()
+ {
+
+ if ($this->has_other_tax() == false ) { return "";}
+ $amount=new INum("other_tax_amount",0);
+ $msg=_("Montant");
+ $row=$this->cn->get_row("select ac_id,ac_label,ac_rate from
acc_other_tax where $1 = any (ajrn_def_id)",
+ [$this->id]);
+ $checkbox=new ICheckBox("other_tax",$row['ac_id']);
+ $label=h($row['ac_label']);
+ $title=_("Autre taxe");
+ $out=<<<EOF
+<div id="additional_tax">
+ <h2 class="h3">{$title}</h2>
+ {$checkbox->input()} {$label} {$row['ac_rate']}%: {$msg} {$amount->input()}
+</div>
+
+EOF;
+ return $out;
+ }
+
+ /**
+ * @brief in confirm screen , display the compute value for additional tax
+ * @parameter $p_additional_tax acc_other_tax.ac_id
+ */
+ function display_additional_tax($p_additional_tax,$p_amount)
+ {
+ $row=$this->cn->get_row("select ac_id,ac_label,ac_rate from
acc_other_tax where ac_id=$1",
+ [$p_additional_tax]);
+ $label=h($row['ac_label']);
+ $title=_("Autre taxe");
+ $p_amount=h($p_amount);
+ $out=<<<EOF
+<div id="additional_tax">
+ <h2 class="h3">{$title}</h2>
+ {$label} {$row['ac_rate']}%: $p_amount
+</div>
+
+EOF;
+ return $out;
+ }
+
+
+ /**
+ * @brief returns true if the ledger has an additional tax
+ */
+ function has_other_tax()
+ {
+ $cnt=$this->db->get_value('select count(*)
+ from acc_other_tax
+ where array_position(ajrn_def_id,$1) is not null',[$this->id]);
+ if ($cnt == 0 ) return false;
+ return true;
+
+ }
}
?>
diff --git a/include/class/acc_ledger_history.class.php
b/include/class/acc_ledger_history.class.php
index 1a1c16e99..b36d28f6f 100644
--- a/include/class/acc_ledger_history.class.php
+++ b/include/class/acc_ledger_history.class.php
@@ -355,4 +355,56 @@ abstract class Acc_Ledger_History
}
throw new Exception(_("Filter invalide ".$filter_operation),5);
}
+
+ /**
+ * @brief count the number of addition tax for the ledger
+ * @return integer
+ */
+ public function has_other_tax()
+ {
+ $str_ledger=join(',',$this->ma_ledger);
+ $count=$this->db->get_value("select count(*)
+ from jrn_tax
+ join jrnx using (j_id)
+ join jrn on (jr_grpt_id=j_grpt)
+ where jr_tech_per>=$1 and jr_tech_per <=$2
+ and jr_def_id in ($str_ledger)
",[$this->m_from,$this->m_to]);
+ return $count;
+ }
+ /**
+ * @brief add additional info about additional tax. Add to $this->data an
array containing the
+ * info about a additional tax. Concerns only purchase and sales ledgers
+ * @verbatim
+ $this->data[$i]['supp_tax']['ac_id'] id in Acc_Other_Tax
+ $this->data[$i]['supp_tax']['j_montant'] Amount of this tax
+ $this->data[$i]['supp_tax']['ac_label'] Label of this tax
+ $this->data[$i]['supp_tax']['ac_rate'] Rate of this tax
+ $this->data[$i]['supp_tax']['j_poste'] Accounting
+ * @endverbatim
+ */
+ protected function add_additional_tax_info()
+ {
+ $prepare=$this->db->is_prepare("supp_tax_info");
+ if ( $prepare == false ){
+ $this->db->prepare("supp_tax_info","
+ select j_montant,jt1.ac_id,ac_label,ac_rate,j_poste
+ from
+ jrn_tax jt1
+ join acc_other_tax using (ac_id)
+ join jrnx using (j_id) where j_grpt=$1
+ ");
+
+ }
+ $data=$this->get_data();
+ $nb_row=count($data);
+
+ for ($i=0;$i<$nb_row;$i++)
+ {
+
$ret=$this->db->execute("supp_tax_info",array($data[$i]["jr_grpt_id"]));
+ $array=Database::fetch_all($ret);
+ $array=($array==false)?array():$array;
+ $data[$i]["supp_tax"]=$array;
+ }
+ $this->set_data($data);
+ }
}
diff --git a/include/class/acc_ledger_purchase.class.php
b/include/class/acc_ledger_purchase.class.php
index 17c7f9c31..1b6e12f61 100644
--- a/include/class/acc_ledger_purchase.class.php
+++ b/include/class/acc_ledger_purchase.class.php
@@ -542,6 +542,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
try
{
bcscale(4);
+ // total amount of the purchase
$tot_amount=0;
$tot_tva=0;
$tot_debit=0;
@@ -585,8 +586,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
$amount_4=bcmul(${'e_march'.$i.'_price'},${'e_quant'.$i});
/* We have to compute all the amount thanks Acc_Compute */
- $amount=round($amount_4,2);
-
+
$acc_amount=new Acc_Compute();
$acc_amount->check=false;
$acc_amount->set_parameter('amount',$amount_4);
@@ -770,7 +770,45 @@ class Acc_Ledger_Purchase extends Acc_Ledger
echo __LINE__." insert into operation currency
oc_amount:{$acc_amount->amount_currency} oc_vat_amount
{$acc_amount->amount_vat_currency} <br>";
}
} // end loop : save all items
- /* save total customer */
+
+
+ /*** save other tax ****/
+ if ( $this->has_other_tax() && isset($p_array['other_tax'])) {
+ $row=$this->db->get_row("select ac_id,ac_label,ac_accounting
+ from acc_other_tax
+ where ac_id=$1 ",
+ [$p_array['other_tax']]);
+ if ( ! empty ($row )) {
+
$other_tax_amount=bcmul($p_array['other_tax_amount'],$p_currency_rate);
+ $acc_operation=new Acc_Operation($this->db);
+ $acc_operation->date=$e_date;
+ $acc_operation->poste=$row['ac_accounting'];
+ $acc_operation->amount=$other_tax_amount;
+ $acc_operation->grpt=$seq;
+ $acc_operation->jrn=$p_jrn;
+ $acc_operation->type='d';
+ $acc_operation->periode=$tperiode;
+ $acc_operation->desc=$row['ac_label'];
+ $jrn_tax_sql=new Jrn_Tax_SQL($this->db);
+ $jrn_tax_sql->j_id=$acc_operation->insert_jrnx();
+ $jrn_tax_sql->ac_id=$row['ac_id'];
+ $jrn_tax_sql->pcm_val=$row['ac_accounting'];
+ $jrn_tax_sql->insert();
+ $operation_currency=new Operation_currency_SQL($this->db);
+
$operation_currency->oc_amount=$p_array['other_tax_amount'];
+ $operation_currency->oc_vat_amount=0;
+ $operation_currency->oc_price_unit=0;
+ $operation_currency->j_id=$jrn_tax_sql->j_id;
+ $operation_currency->insert();
+
+ $tot_debit=bcadd($tot_debit, abs($other_tax_amount));
+ $tot_amount=bcadd($tot_amount,$other_tax_amount);
+ }
+
+ }
+
+
+ /*** save total customer ***/
if ( DEBUGNOALYSS > 1 ) {
echo __LINE__." tot_amount $tot_amount<br>";
echo __LINE__." tot_tva $tot_tva<br>";
@@ -847,6 +885,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
}
}
+
/* insert into jrn */
$acc_operation=new Acc_Operation($this->db);
$acc_operation->date=$e_date;
@@ -1038,7 +1077,9 @@ class Acc_Ledger_Purchase extends Acc_Ledger
}
- }
+ }
+
+
}//end try
catch (Exception $e)
{
@@ -1458,6 +1499,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
}
// set focus on date
$r.= create_script("$('".$Date->id."').focus()");
+ $r.=$this->input_additional_tax();
return $r;
}
@@ -1721,7 +1763,8 @@ class Acc_Ledger_Purchase extends Acc_Ledger
// Format amount
$tot_amount=nbm($tot_amount);
$tot_tva=nbm($tot_tva);
- $tot=nbm($tot);
+ $tot_str=nbm($tot);
+
if ( $g_parameter->MY_TVA_USE == 'Y') {
$r.=<<<EOF
<tr class="highlight">
@@ -1736,7 +1779,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
{$tot_amount}
</td>
<td class="num">
- {$tot} {$str_code}
+ {$tot_str} {$str_code}
</td>
</tr>
EOF;
@@ -1774,7 +1817,7 @@ EOF;
</td>
<td class="num">
- {$tot} {$str_code}
+ {$tot_str} {$str_code}
</td>
</tr>
<tr class="highlight">
@@ -1786,7 +1829,7 @@ EOF;
<td>
</td>
<td class="num">
- {$tot} {$str_code}
+ {$tot_str} {$str_code}
</td>
</tr>
EOF;
@@ -1799,6 +1842,12 @@ EOF;
$r.=(! $p_summary )?'<div id="total_div_id" >':'<div>';
$r.='<h2>Totaux</h2>';
+ $other_tax_label="";
+ $other_tax_amount="";
+ if ( $this->has_other_tax() && isset($p_array['other_tax'])) {
+ $other_tax_label=_("Autre taxe");
+ $other_tax_amount=htmlspecialchars($p_array['other_tax_amount']);
+ }
/* use VAT */
if ($g_parameter->MY_TVA_USE == 'Y') {
$r.='<table>';
@@ -1812,9 +1861,17 @@ EOF;
$r.=td(hb(nbm($tva[$i])),'class="num"');
}
$r.='<tr>'.td(_('Total TVA')).td(hb($tot_tva),'class="num"');
+ if ( ! empty($other_tax_label) ) {
+
$r.='<tr>'.td($other_tax_label).td(hb($other_tax_amount),'class="num"');
+ }
+ if ( $other_tax_amount!="") {$tot=bcadd($tot,$other_tax_amount,2);}
$r.='<tr>'.td(_('Total TVAC')).td(hb($tot),'class="num"');
$r.='</table>';
} else {
+ if ( ! empty($other_tax_label) ) {
+
$r.='<tr>'.td($other_tax_label).td(hb($other_tax_amount),'class="num"');
+ }
+ if ( $other_tax_amount!="") {$tot=bcadd($tot,$other_tax_amount,2);}
$r.='<br>Total '.hb($tot);
}
$r.='</div>';
@@ -1831,6 +1888,10 @@ EOF;
$r.=HtmlInput::hidden('e_pj',$e_pj);
$r.=HtmlInput::hidden('e_pj_suggest',$e_pj_suggest);
$r.=HtmlInput::post_to_hidden(['p_currency_rate','p_currency_code']);
+ if ( $this->has_other_tax() && isset($p_array["other_tax"])) {
+ $r.=HtmlInput::hidden("other_tax",$p_array['other_tax']);
+
$r.=HtmlInput::hidden("other_tax_amount",$p_array['other_tax_amount']);
+ }
$mt=microtime(true);
$r.=HtmlInput::hidden('mt',$mt);
diff --git a/include/class/acc_ledger_sale.class.php
b/include/class/acc_ledger_sale.class.php
index 7f36a3699..b8a398c5b 100644
--- a/include/class/acc_ledger_sale.class.php
+++ b/include/class/acc_ledger_sale.class.php
@@ -285,9 +285,13 @@ class Acc_Ledger_Sale extends Acc_Ledger {
bcscale(4);
try {
+ // total amount of the sales (credit)
$tot_amount = 0;
+ // total amount of the VAT
$tot_tva = 0;
+ // tot debit if item's amount < 0
$tot_debit = 0;
+ // total amount in currency
$tot_amount_cur=0;
$this->db->start();
@@ -457,6 +461,43 @@ class Acc_Ledger_Sale extends Acc_Ledger {
$tot_amount_cur=round(bcadd($tot_amount_cur,$tva_item_currency,4),4);
}// end loop : save all items
+ /*** save other tax ****/
+ if ( $this->has_other_tax() && isset($p_array['other_tax'])) {
+ $row=$this->db->get_row("select ac_id,ac_label,ac_accounting
+ from acc_other_tax
+ where ac_id=$1 ",
+ [$p_array['other_tax']]);
+ if ( ! empty ($row )) {
+
$other_tax_amount=bcmul($p_array['other_tax_amount'],$p_currency_rate);
+ $acc_operation=new Acc_Operation($this->db);
+ $acc_operation->date=$e_date;
+ $acc_operation->poste=$row['ac_accounting'];
+ $acc_operation->amount=$other_tax_amount;
+ $acc_operation->grpt=$seq;
+ $acc_operation->jrn=$p_jrn;
+ $acc_operation->type='c';
+ $acc_operation->periode=$tperiode;
+ $acc_operation->desc=$row['ac_label'];
+ $jrn_tax_sql=new Jrn_Tax_SQL($this->db);
+ $jrn_tax_sql->j_id=$acc_operation->insert_jrnx();
+ $jrn_tax_sql->ac_id=$row['ac_id'];
+ $jrn_tax_sql->pcm_val=$row['ac_accounting'];
+ $jrn_tax_sql->insert();
+ $tot_amount=bcadd($tot_amount,$other_tax_amount);
+ if ( $p_array['other_tax_amount'] < 0 ) {
+ $tot_debit=bcadd($tot_debit,abs($other_tax_amount));
+ }
+ $operation_currency=new Operation_currency_SQL($this->db);
+
$operation_currency->oc_amount=$p_array['other_tax_amount'];
+ $operation_currency->oc_vat_amount=0;
+ $operation_currency->oc_price_unit=0;
+ $operation_currency->j_id=$jrn_tax_sql->j_id;
+ $operation_currency->insert();
+ }
+
+ }
+
+
/* save total customer */
$cust_amount = bcadd($tot_amount, $tot_tva);
$cust_amount = round($cust_amount,2);
@@ -965,7 +1006,7 @@ class Acc_Ledger_Sale extends Acc_Ledger {
$decalage=($g_parameter->MY_TVA_USE ==
'Y')?'<td></td><td></td><td></td><td></td>':'<td></td>';
$tot = bcadd($tot_amount, $tot_tva, 2);
$tot_eur=round(bcdiv($tot, $p_currency_rate),2);
- $tot=nbm($tot);
+ $tot_str=nbm($tot);
$str_tot=_('Totaux');
// Get currency code
@@ -994,7 +1035,7 @@ if ( $g_parameter->MY_TVA_USE=="Y") {
{$tot_amount}
</td>
<td class="num">
- {$tot} {$str_code}
+ {$tot_str} {$str_code}
</td>
</tr>
EOF;
@@ -1035,7 +1076,7 @@ EOF;
</td>
<td class="num">
- {$tot}
+ {$tot_str}
</td>
</tr>
<tr class="highlight">
@@ -1060,7 +1101,12 @@ EOF;
$r.='<input type="button" class="button" value="' . _('Vérifiez
Imputation Analytique') . '" onClick="verify_ca(\'\');">';
$r.=(! $p_summary )?'<div id="total_div_id" >':'<div>';
$r.='<h2>Totaux</h2>';
-
+ $other_tax_label="";
+ $other_tax_amount="";
+ if ( $this->has_other_tax() && isset($p_array['other_tax'])) {
+ $other_tax_label=_("Autre taxe");
+ $other_tax_amount=htmlspecialchars($p_array['other_tax_amount']);
+ }
/* use VAT */
if ($g_parameter->MY_TVA_USE == 'Y') {
$r.='<table>';
@@ -1074,9 +1120,17 @@ EOF;
$r.=td(hb(nbm($tva[$i])),'class="num"');
}
$r.='<tr>'.td(_('Total TVA')).td(hb($tot_tva),'class="num"');
+ if ( ! empty($other_tax_label) ) {
+
$r.='<tr>'.td($other_tax_label).td(hb($other_tax_amount),'class="num"');
+ }
+ if ( $other_tax_amount!="") {$tot=bcadd($tot,$other_tax_amount,2);}
$r.='<tr>'.td(_('Total TVAC')).td(hb($tot),'class="num"');
$r.='</table>';
} else {
+ if ( ! empty($other_tax_label) ) {
+
$r.='<tr>'.td($other_tax_label).td(hb($other_tax_amount),'class="num"');
+ }
+ if ( $other_tax_amount!="") {$tot=bcadd($tot,$other_tax_amount,2);}
$r.='<br>Total '.hb($tot);
}
$r.='</div>';
@@ -1100,7 +1154,10 @@ EOF;
$r.=HtmlInput::hidden('e_ech', $e_ech);
$r.=HtmlInput::hidden('e_pj', $e_pj);
$r.=HtmlInput::hidden('e_pj_suggest', $e_pj_suggest);
-
+ if ( $this->has_other_tax() && isset($p_array["other_tax"])) {
+ $r.=HtmlInput::hidden("other_tax",$p_array['other_tax']);
+
$r.=HtmlInput::hidden("other_tax_amount",$p_array['other_tax_amount']);
+ }
$e_mp = (isset($e_mp)) ? $e_mp : 0;
$r.=HtmlInput::hidden('e_mp', $e_mp);
@@ -1524,6 +1581,7 @@ EOF;
$r.=HtmlInput::hidden('jrn_type', 'VEN');
$r.= Html_Input_Noalyss::ledger_add_item("O");
$r.= create_script("$('" . $Date->id . "').focus()");
+ $r.=$this->input_additional_tax();
return $r;
}
/**
diff --git a/include/class/acc_tax_purchase_sale.class.php
b/include/class/acc_tax_purchase_sale.class.php
new file mode 100644
index 000000000..5fe9a1899
--- /dev/null
+++ b/include/class/acc_tax_purchase_sale.class.php
@@ -0,0 +1,84 @@
+<?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
+ * 1/03/20
+*/
+/**
+ * @file
+ * @brief Compute , display additional tax for Sale and Purchase,
+ *
+ */
+// Copyright Author Dany De Bontridder danydb@noalyss.eu 2022
+
+class Acc_Tax_Purchase_Sale
+{
+ private $jrn_tax_sql;
+
+ function __construct($p_cn, $p_id = -1)
+ {
+ $this->jrn_tax_sql = new Jrn_Tax_SQL($p_cn, $p_id);
+ }
+
+ /**
+ * @return Jrn_Tax_SQL
+ */
+ public function getJrnTaxSql(): Jrn_Tax_SQL
+ {
+ return $this->jrn_tax_sql;
+ }
+
+ /**
+ * @param Jrn_Tax_SQL $jrn_tax_sql
+ */
+ public function setJrnTaxSql(Jrn_Tax_SQL $jrn_tax_sql)
+ {
+ $this->jrn_tax_sql = $jrn_tax_sql;
+ return $this;
+ }
+
+ /**
+ * @brief retrieve Jrn_Tax_SQL thx its jr_id
+ * @param $p_jrid
+ */
+ public function get_by_operation_id($p_jrid)
+ {
+ $jt_id= $this->jrn_tax_sql->get_cn()->get_value(
+ "select jt_id from jrn_tax where jr_id=$1",
+ [$p_jrid]);
+ $jt_id=(empty($jt_id))?-1:$jt_id;
+ $this->jrn_tax_sql->set("jt_id",$jt_id);
+ if ($jt_id == -1 ) return;
+ $this->jrn_tax_sql->load();
+ }
+
+ /**
+ * @brief display in detail
+ */
+ public function display()
+ {
+ echo_warning(__FILE__.":".__LINE__.__CLASS__."::".__FUNCTION__."not
implemented");
+ }
+ public function save()
+ {
+ if ($this->jrn_tax_sql->get("jt_id") == -1 ) {
+ $this->jrn_tax_sql->insert();
+ return;
+ }
+ $this->jrn_tax_sql->update();
+ }
+
+}
\ No newline at end of file
diff --git a/include/class/additional_tax.class.php
b/include/class/additional_tax.class.php
new file mode 100644
index 000000000..da6788389
--- /dev/null
+++ b/include/class/additional_tax.class.php
@@ -0,0 +1,99 @@
+<?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
+*/
+
+// Copyright 2022 Author Dany De Bontridder dany@alchimerys.be
+
+
+class Additional_Tax
+{
+ private $tax_amount;
+ private $currency_amount;
+ private $currency_id;
+ private $ac_id;
+ private $ac_label;
+ private $ac_rate;
+ private $ac_accounting;
+
+ function
__construct($tax_amount,$currency_amount,$currency_id,$ac_id,$ac_label,$ac_rate,$ac_accounting)
+ {
+ $this->tax_amount=round($tax_amount,2);
+ $this->currency_amount=round($currency_amount,4);
+ $this->currency_id=$currency_id;
+ $this->ac_id=$ac_id;
+ $this->ac_label=$ac_label;
+ $this->ac_rate=$ac_rate;
+ $this->ac_accounting=$ac_accounting;
+ }
+
+ static function get_by_operation($p_jrn_id,&$sum_euro,&$sum_currency)
+ {
+ bcscale(4);
+ global $cn;
+ $array = $cn->get_array('select j_montant,currency_id,
+ oc.oc_amount,
+ jt.ac_id,
+ aot.ac_label,
+ aot.ac_rate,
+ aot.ac_accounting
+ from jrn_tax jt
+ join jrnx using (j_id)
+ join jrn on (jrnx.j_grpt=jrn.jr_grpt_id)
+ join acc_other_tax aot on (jt.ac_id=aot.ac_id)
+ left join operation_currency oc ON (oc.j_id=jt.j_id)
+ where
+ jr_id=$1', [$p_jrn_id]);
+ $sum_currency=0;$sum_euro=0;
+ if (empty($array)) { return array();}
+ $nb=count($array);
+ $a_additional_tax=array();
+ for ($i=0;$i<$nb;$i++) {
+ $a_additional_tax[]=new Additional_Tax($array[$i]['j_montant'],
+ $array[$i]['oc_amount'],
+ $array[$i]['currency_id'],
+ $array[$i]['ac_id'],
+ $array[$i]['ac_label'],
+ $array[$i]['ac_rate'],
+ $array[$i]['ac_accounting'],
+ );
+ $sum_euro=bcadd($sum_euro,$array[$i]['j_montant']);
+ $sum_currency=bcadd($sum_currency,$array[$i]['oc_amount']);
+ }
+ $sum_euro=round($sum_euro,2);
+ return $a_additional_tax;
+ }
+ static function
display_row($p_jrn_id,&$sum_euro,&$sum_currency,$decalage=0)
+ {
+
$a_additional_tax=Additional_Tax::get_by_operation($p_jrn_id,$sum_euro,$sum_currency);
+ $nb=count($a_additional_tax);
+ for ($i=0;$i<$nb;$i++) {
+ echo '<tr>';
+
+ echo td($a_additional_tax[$i]->ac_accounting);
+ echo td($a_additional_tax[$i]->ac_label." (
".$a_additional_tax[$i]->ac_rate." %)");
+ echo td(nbm($a_additional_tax[$i]->tax_amount),'class="num"');
+ echo td("").td("").td("").td("");
+ for ($e=0;$e<$decalage;$e++) { echo td("");}
+ echo td(nbm($a_additional_tax[$i]->tax_amount),'class="num"');
+ if ( $a_additional_tax[$i]->currency_id !=0 ) {
+ echo
td(nbm($a_additional_tax[$i]->currency_amount),'class="num"');
+ }
+ echo '</tr>';
+ }
+ }
+}
diff --git a/include/class/html_input_noalyss.class.php
b/include/class/html_input_noalyss.class.php
index ac1ea03d5..d46aaba1f 100644
--- a/include/class/html_input_noalyss.class.php
+++ b/include/class/html_input_noalyss.class.php
@@ -58,4 +58,32 @@ class Html_Input_Noalyss extends HtmlInput
return $r;
}
+
+ /**
+ * @brief display the supplementax if any
+ * @param $p_ledger_id jrn_def.jrn_def_id , id of the ledger
+ */
+ static function ledger_supplemental_tax($p_ledger_id)
+ {
+ $cn=Dossier::connect();
+ // if there is an additional tax for this ledger
+ $has_suppl_tax=$cn->get_value("select count(*) from acc_other_tax
where array_position(ajrn_def_id,$1)
+is not null",[$p_ledger_id]);
+ if ($has_suppl_tax ==0 ) {
+ return "";
+ }
+ if ( $has_suppl_tax>1) {
+ throw new Exception("HIN76:too many supplemental taxes");
+ }
+ $ac_id=$cn->get_value("select ac_id
+ from acc_other_tax
+ where
+ array_position(ajrn_def_id,$1) is not
null",[$p_ledger_id]);
+
+ $ac_other_tax=new Acc_Other_Tax_SQL($cn,$ac_id);
+ $msg=_("Autre taxe");
+ $checkbox=new ICheckBox("new_tax",$ac_id);
+
+
+ }
}
\ No newline at end of file
diff --git a/include/constant.php b/include/constant.php
index a2d1d766b..a1f93984c 100644
--- a/include/constant.php
+++ b/include/constant.php
@@ -601,7 +601,9 @@ function noalyss_class_autoloader($class) {
"pdf_anc_acc_list"=>"class/pdf_anc_acc_list.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'
+ 'acc_other_tax_sql'=>'database/acc_other_tax_sql.class.php',
+ 'jrn_tax_sql'=>'database/jrn_tax_sql.class.php',
+ 'additional_tax'=>'class/additional_tax.class.php'
);
if ( isset ($aClass[$class]) ) {
require_once NOALYSS_INCLUDE."/".$aClass[$class];
diff --git a/include/database/jrn_tax_sql.class.php
b/include/database/jrn_tax_sql.class.php
new file mode 100644
index 000000000..e1f006f98
--- /dev/null
+++ b/include/database/jrn_tax_sql.class.php
@@ -0,0 +1,68 @@
+<?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
+ */
+
+/**
+ * jrn_tax_sql.class.php
+ *
+ * @file
+ * @brief abstract of the table public.jrn_tax */
+
+/**
+ * @class Jrn_Tax_SQL
+ * @brief ORM of the table public.jrn_tax
+ */
+
+class Jrn_Tax_SQL extends Table_Data_SQL
+{
+
+ function __construct(DatabaseCore $p_cn, $p_id=-1)
+ {
+ $this->table="public.jrn_tax";
+ $this->primary_key="jt_id";
+ /*
+ * List of columns
+ */
+ $this->name=array(
+ "jt_id"=>"jt_id"
+ , "j_id"=>"j_id"
+ , "pcm_val"=>"pcm_val"
+ , "ac_id"=>"ac_id"
+ );
+ /*
+ * Type of columns
+ */
+ $this->type=array(
+ "jt_id"=>"number"
+ , "j_id"=>"number"
+ , "pcm_val"=>"text"
+ , "ac_id"=>"ac_id"
+ );
+
+
+ $this->default=array(
+ "jt_id"=>"auto"
+ );
+
+ $this->date_format="DD.MM.YYYY";
+ parent::__construct($p_cn, $p_id);
+ }
+
+}
\ No newline at end of file
diff --git a/include/template/ledger_detail_ach.php
b/include/template/ledger_detail_ach.php
index 764b37dab..d418526e4 100644
--- a/include/template/ledger_detail_ach.php
+++ b/include/template/ledger_detail_ach.php
@@ -2,6 +2,7 @@
//This file is part of NOALYSS and is under GPL
//see licence.txt
$str_anc="";
+global $div,$g_parameter,$cn,$access,$jr_id,$obj;
?><?php require_once NOALYSS_TEMPLATE.'/ledger_detail_top.php'; ?>
<div class="content" style="padding:0;">
<?php
@@ -115,6 +116,9 @@ $str_anc="";
$total_tvac = 0;
echo th(_('Quick Code'));
echo th(_('Description'));
+
+ echo th(_('Prix/Un.'), 'style="text-align:right"');
+ echo th(_('Quantité'), 'style="text-align:right"');
if ($owner->MY_TVA_USE == 'Y')
{
echo th(_('Taux TVA'), 'style="text-align:right"');
@@ -122,8 +126,6 @@ $str_anc="";
{
echo th('');
}
- echo th(_('Prix/Un.'), 'style="text-align:right"');
- echo th(_('Quantité'), 'style="text-align:right"');
echo th(_('Non ded'), 'style="text-align:right"');
if ($owner->MY_TVA_USE == 'Y')
@@ -194,10 +196,10 @@ $str_anc="";
$input->value = $fiche->strAttribut(ATTR_DEF_NAME);
}
$row.=td($input->input() . $hidden);
- $row.=td($sym_tva, 'style="text-align:center"');
$pu = $q['qp_unit'];
$row.=td(nbm($pu,4), 'class="num"');
$row.=td(nbm($q['qp_quantite'],4), 'class="num"');
+ $row.=td($sym_tva, 'style="text-align:center"');
$no_ded = bcadd($q['qp_dep_priv'], $q['qp_nd_amount']);
$row.=td(nbm($no_ded), ' style="text-align:right"');
@@ -257,14 +259,30 @@ $str_anc="";
}
echo tr($row,$class);
}
+
if ($owner->MY_TVA_USE == 'Y')
$row = td(_('Total'), '
style="font-style:italic;text-align:right;font-weight: bolder;width:auto"
colspan="6"');
else
$row = td(_('Total'), '
style="font-style:italic;text-align:right;font-weight: bolder;width:auto"
colspan="6"');
+ /**
+ * display additional tax if any + currency
+ */
+ $sum_add_tax=0;$sum_add_tax_cur=0;
+
Additional_Tax::display_row($jr_id,$sum_add_tax,$sum_add_tax_cur,2);
+ $sum_charge_euro=bcadd($sum_charge_euro,$sum_add_tax_cur);
+
+ $total_tvac=bcadd($sum_add_tax,$total_tvac);
+ if ($owner->MY_TVA_USE == 'N') {
+ $total_htva=bcadd($sum_add_tax,$total_htva);
+ }
$row.=td(nbm($total_htva), 'class="num"
style="font-style:italic;font-weight: bolder;"');
if ($owner->MY_TVA_USE == 'Y')
$row.=td("") . td("").td(nbm($total_tvac), 'class="num"
style="font-style:italic;font-weight: bolder;"');
-
+ /**
+ * display additional tax if any + currency
+ */
+
+
//Display total in currency
if ( $obj->det->currency_id != "" && $obj->det->currency_id >
0)
{
@@ -276,6 +294,8 @@ $str_anc="";
?>
</table>
<?php
+
+
/*
* Info about currency if not in euro
*/
diff --git a/include/template/ledger_detail_ven.php
b/include/template/ledger_detail_ven.php
index 90907c2b1..4de0cbc31 100644
--- a/include/template/ledger_detail_ven.php
+++ b/include/template/ledger_detail_ven.php
@@ -1,7 +1,10 @@
<?php
//This file is part of NOALYSS and is under GPL
//see licence.txt
-?><?php require_once NOALYSS_TEMPLATE.'/ledger_detail_top.php'; ?>
+global $div,$g_parameter,$cn,$access,$jr_id,$obj;
+?>
+
+<?php require_once NOALYSS_TEMPLATE.'/ledger_detail_top.php'; ?>
<?php
$tab_account=$div."account";
$tab_rapprochement=$div."rapproch";
@@ -9,7 +12,7 @@
$tab_document=$div."document";
$str_anc="";
?>
-<div class="content" style="padding:0;">
+<div class="content" style="padding:0px;">
<?php
$owner = new Noalyss_Parameter_Folder($cn);
?>
@@ -266,12 +269,24 @@ echo $ipaid->input();
$row = td(_('Total'), '
style="font-style:italic;text-align:right;font-weight: bolder;" colspan="5"');
else
$row = td(_('Total'), '
style="font-style:italic;text-align:right;font-weight: bolder;" colspan="5"');
+ /**
+ * display additional tax if any + currency
+ */
+ $sum_add_tax=0;$sum_add_tax_cur=0;
+
Additional_Tax::display_row($jr_id,$sum_add_tax,$sum_add_tax_cur);
+ $sum_prod_currency=bcadd($sum_prod_currency,$sum_add_tax_cur);
+
+ $total_tvac=bcadd($sum_add_tax,$total_tvac);
+ if ($owner->MY_TVA_USE == 'N') {
+ $total_htva=bcadd($sum_add_tax,$total_htva);
+ }
$row.=td(nbm($total_htva), 'class="num"
style="font-style:italic;font-weight: bolder;"');
- if ($owner->MY_TVA_USE == 'Y')
+ if ($owner->MY_TVA_USE == 'Y') {
$row.=td("") . td(nbm($total_tvac), 'class="num"
style="font-style:italic;font-weight: bolder;"');
-
-
- //Display total in currency
+
+ }
+
+ //Display total in currency
if ( $obj->det->currency_id != "" && $obj->det->currency_id >
0)
{
$row.= td(nbm($sum_prod_currency,4),' class="num"
style="font-style:italic;font-weight: bolder;"');
@@ -279,7 +294,7 @@ echo $ipaid->input();
echo tr($row);
?>
</table>
- </td>
+ </form>
</tr>
</table>
</td>
@@ -300,7 +315,9 @@ echo $ipaid->input();
echo _("Taux Réf"),
" ",nbm($obj->det->currency_rate_ref,4).$four_space;
echo _("Montant en devise"),
" ",nbm($sum_prod_currency,4).$four_space;
}
-?>
+
+?>
+
<?php
require_once NOALYSS_TEMPLATE.'/ledger_detail_bottom.php';
?>
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index fbb6dac2f..60c43838b 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -7,9 +7,38 @@ create table acc_other_tax
ajrn_def_id integer[],
ac_accounting account_type not null
);
-comment on table acc_other_tax is 'Other tax ';
+comment on table acc_other_tax is 'Additional tax for Sale or Purchase ';
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)';
+
+ALTER TABLE public.jrn drop CONSTRAINT jrn_pkey ;
+ALTER TABLE public.jrn ADD CONSTRAINT jrn_pkey PRIMARY KEY (jr_id);
+
+-- public.jrn_tax definition
+
+-- Drop table
+
+-- DROP TABLE public.jrn_tax;
+
+CREATE TABLE public.jrn_tax (
+ jt_id int4 NOT NULL GENERATED ALWAYS AS
IDENTITY,
+ j_id int8 NOT NULL, -- fk jrnx
+ pcm_val public."account_type" NOT NULL, -- FK
tmp_pcmn
+ ac_id int4 NOT NULL, -- FK to acc_other_tax
+ CONSTRAINT jrn_tax_pk PRIMARY KEY (jt_id)
+);
+
+-- Column comments
+
+COMMENT ON COLUMN public.jrn_tax.j_id IS 'fk jrnx';
+COMMENT ON COLUMN public.jrn_tax.pcm_val IS 'FK tmp_pcmn';
+COMMENT ON COLUMN public.jrn_tax.ac_id IS 'FK to acc_other_tax';
+
+
+-- public.jrn_tax foreign keys
+
+ALTER TABLE public.jrn_tax ADD CONSTRAINT jrn_tax_acc_other_tax_fk FOREIGN KEY
(ac_id) REFERENCES public.acc_other_tax(ac_id);
+ALTER TABLE public.jrn_tax ADD CONSTRAINT jrn_tax_fk FOREIGN KEY (j_id)
REFERENCES public.jrnx(j_id);
- [Noalyss-commit] [noalyss] branch master updated (f8d23563a -> cbc0d3fb7), Dany De Bontridder, 2022/07/12
- [Noalyss-commit] [noalyss] 01/24: Cosmetic : error message when user cannot add card, Dany De Bontridder, 2022/07/12
- [Noalyss-commit] [noalyss] 02/24: remove direct access to $_POST and extract, Dany De Bontridder, 2022/07/12
- [Noalyss-commit] [noalyss] 03/24: ISelect->display fails if this->value if null, Dany De Bontridder, 2022/07/12
- [Noalyss-commit] [noalyss] 06/24: Bug when ledger badly parametrized, Dany De Bontridder, 2022/07/12
- [Noalyss-commit] [noalyss] 08/24: Merge branch 'devel', Dany De Bontridder, 2022/07/12
- [Noalyss-commit] [noalyss] 05/24: Security : management , profile access, Dany De Bontridder, 2022/07/12
- [Noalyss-commit] [noalyss] 09/24: Supplemental TAX : manage parameter A ledger can have only 1 supplemental tax, Dany De Bontridder, 2022/07/12
- [Noalyss-commit] [noalyss] 13/24: code documentation, Dany De Bontridder, 2022/07/12
- [Noalyss-commit] [noalyss] 10/24: New : 2178 Additional Tax : input in purchase and sale ledger - tax with positive amount - tax with negative amount - tax in currency,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 11/24: Nouveau #0002178: Cotisation de solidarité Impression : Listing (HTML, CSV et PDF) Impression : Extended (HTML, CSV et PDF) Negatif amount and currency, Dany De Bontridder, 2022/07/12
- [Noalyss-commit] [noalyss] 14/24: Additional Tax : database changes, Dany De Bontridder, 2022/07/12
- [Noalyss-commit] [noalyss] 16/24: Additional Tax : export operation PDF, Dany De Bontridder, 2022/07/12
- [Noalyss-commit] [noalyss] 17/24: Additional Tax : automatic compute, Dany De Bontridder, 2022/07/12
- [Noalyss-commit] [noalyss] 23/24: Bug : supplemental tax cannot be deleted, Dany De Bontridder, 2022/07/12
- [Noalyss-commit] [noalyss] 19/24: Cosmetic : waiting box if confirmed, Dany De Bontridder, 2022/07/12
- [Noalyss-commit] [noalyss] 04/24: Remove unauthorized profile, Dany De Bontridder, 2022/07/12
- [Noalyss-commit] [noalyss] 07/24: cosmetic, Dany De Bontridder, 2022/07/12
- [Noalyss-commit] [noalyss] 12/24: Additional Tax : input in purchase and sale ledger - tax with positive amount - tax with negative amount - tax currency - Reverse operation - Correct in operation detail the amount of linked operation, Dany De Bontridder, 2022/07/12
- [Noalyss-commit] [noalyss] 18/24: Additional tax : remains when correct operation Cosmetic, Dany De Bontridder, 2022/07/12