noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 09/13: Task #2373: Détail TVA : ajout detail


From: dwm
Subject: [Noalyss-commit] [noalyss] 09/13: Task #2373: Détail TVA : ajout detail TVA appelable depuis menu par P0TVA (récapitulatif TVA)
Date: Tue, 30 Jul 2024 04:48:03 -0400 (EDT)

sparkyx pushed a commit to branch unstable
in repository noalyss.

commit 9fb7a3f061cafe589277d40578a18debcc13ae06
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Sat Jul 27 15:07:01 2024 +0200

    Task #2373: Détail TVA : ajout detail TVA appelable depuis menu
    par P0TVA (récapitulatif TVA)
---
 html/ajax_misc.php                                |   5 +-
 html/js/acc_ledger.js                             |  51 +++++-
 include/ajax/ajax_tax_detail.php                  |  60 +++++++
 include/class/acc_ledger_purchase.class.php       |   2 +-
 include/class/tax_detail.class.php                | 183 ++++++++++++++++++++++
 include/class/tax_summary.class.php               |  40 +++--
 include/export/export_p1tva_csv.php               |  40 +++++
 include/tax_detail.inc.php                        |  41 +++++
 include/template/tax_detail-button_export_csv.php |  41 +++++
 include/template/tax_detail-display_form.php      |  85 ++++++++++
 include/template/tax_detail-html.php              | 109 +++++++++++++
 include/template/tax_summary_display.php          |  14 +-
 sql/upgrade.sql                                   |  44 ++++++
 13 files changed, 701 insertions(+), 14 deletions(-)

diff --git a/html/ajax_misc.php b/html/ajax_misc.php
index 0dbf4b460..34daff0cb 100644
--- a/html/ajax_misc.php
+++ b/html/ajax_misc.php
@@ -346,7 +346,10 @@ $path = array(
     'list_filter_followup'=>"ajax_follow_up",
     //delete a filter for followup
     'delete_filter_followup'=>"ajax_follow_up",
-    "check_vatnumber"=>"ajax_check_vatnumber"
+    // Check VAT NUMBER with VIES European VAT
+    "check_vatnumber"=>"ajax_check_vatnumber",
+    // Tax Detail
+    "tax_detail"=>"ajax_tax_detail"
 ) ;
 
 if (array_key_exists($op, $path)) {
diff --git a/html/js/acc_ledger.js b/html/js/acc_ledger.js
index 7ca3b0422..e0055181b 100644
--- a/html/js/acc_ledger.js
+++ b/html/js/acc_ledger.js
@@ -1731,7 +1731,56 @@ function duplicate_operation(p_dossier, p_jr_id) {
         }
     );
 }
+/**
+ * Go to detail of Tax for a specific period , ledger id and tva_id
+ */
 
+function tax_detail_view (dossier_id,date_from,date_to,nLedger_id,nTva_id)
+{
+       try
+               {
+               var dgbox="detail_tax_box";
+               waiting_box();
+               removeDiv(dgbox);
+               // For form , most of the parameters are in the FORM
+               // method is then POST
+                //var queryString=$(p_form_id).serialize(true);
+
+              var queryString = {
+                       op: 'tax_detail',
+                       act: "tax_detail_view",
+                       gDossier: dossier_id,
+                    boxid: dgbox,
+                       date_from:date_from,
+                    date_to:date_to,
+                    ledger_id:nLedger_id,
+                    tva_id:nTva_id
+                   };
+               var action = new Ajax.Request(
+                                         "ajax_misc.php" ,
+                                         {
+                                             method:'GET',
+                                             parameters:queryString,
+                                             onFailure:ajax_misc_failure,
+                                             onSuccess:function(req){
+                                                       remove_waiting_box();
+                               if (req.responseText == 'NOCONX') {
+                                   reconnect();
+                                   return;
+                               }
+                                                       var y=calcy(15);
+                                                       var 
div_style="position:absolute;"+";top:"+y+"px";
+                                                       
add_div({id:dgbox,cssclass:'inner_box',html:loading(),style:div_style,drag:true});
+                                                       
$(dgbox).update(req.responseText);
+
+                                             }
+                                         }
+                     );
+               }catch( e)
+               {
+                       alert_box(e.message);
+               }
+}
 /**
  * For operation_exercice let update periode when changing folder
  * @type {{update_periode: operation_exercice.update_periode}}
@@ -1959,7 +2008,7 @@ var operation_exercice = {
                             return;
                         }
                         var answer=req.responseJSON;
-console.debug(answer['content']);
+
                         
$('operation_exercice_transfer_info').update(answer.content);
 
 
diff --git a/include/ajax/ajax_tax_detail.php b/include/ajax/ajax_tax_detail.php
new file mode 100644
index 000000000..a67f0884b
--- /dev/null
+++ b/include/ajax/ajax_tax_detail.php
@@ -0,0 +1,60 @@
+<?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 Author Dany De Bontridder danydb@noalyss.eu 28/07/24
+/*! 
+ * \file
+ * \brief manage Tax_Detail
+ */
+
+if (!defined('ALLOWED'))
+    die('Appel direct ne sont pas permis');
+$http=new HttpInput();
+try {
+    $tax_detail=new Tax_Detail(
+        $http->get('tva_id')
+        ,$http->get("date_from",'date')
+        ,$http->get("date_to",'date')
+        ,$http->get("ledger_id",'number')
+    );
+    $boxid=$http->get("boxid");
+
+} catch (\Exception $e) {
+    echo $e->getMessage();
+    return;
+}
+echo \HtmlInput::title_box("Détail TVA", $boxid);
+?>
+<div>
+    <p class="text-muted">
+        Il peut y avoir des différences entre la TVA calculée et à récupérer à 
cause de TVA Non Déductible, reprise
+        à charge du gérant ou d'arrondi.
+    </p>
+    <?php
+    $tax_detail->html();
+    ?>
+</div>
+<ul class="aligned-block">
+    <li>
+        <?=\HtmlInput::button_close($boxid)?>
+    </li>
+    <li>
+        <?=$tax_detail->button_export_csv()?>
+    </li>
+</ul>
+
diff --git a/include/class/acc_ledger_purchase.class.php 
b/include/class/acc_ledger_purchase.class.php
index d9a5ff7af..61a883561 100644
--- a/include/class/acc_ledger_purchase.class.php
+++ b/include/class/acc_ledger_purchase.class.php
@@ -323,7 +323,7 @@ class  Acc_Ledger_Purchase extends Acc_Ledger
     }
 
     /**
-     * Insert into JRNX the No Deductible amount and into Analytic Accountancy 
for the ND VAT
+     * @brief Insert into JRNX the No Deductible amount and into Analytic 
Accountancy for the ND VAT
      * @param Acc_Compute $p_nd_amount content ND amount
      * @param Fiche $p_fiche Card of the Service
      * @param type $p_tva_both  0 if TVA is normal or 1 if on both side
diff --git a/include/class/tax_detail.class.php 
b/include/class/tax_detail.class.php
new file mode 100644
index 000000000..98906b6c6
--- /dev/null
+++ b/include/class/tax_detail.class.php
@@ -0,0 +1,183 @@
+<?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 Author Dany De Bontridder danydb@aevalys.eu 26/07/24
+/*! 
+ * \file
+ * \brief detail of TVA_CODE for a specific ledger and periode
+ */
+
+class Tax_Detail
+{
+    protected $from; //!< Start date
+    protected $to; //!< end date
+    protected $tva_code; //!< tva_code
+    protected $ledger_id; //!< ledger_id (jrn_def.jrn_def_id) -1, means all 
ledger Sale + Purchase
+
+    function __construct($tva_code,$from,$to,$ledger_id) {
+
+        $this->tva_code=$tva_code;
+        $this->from=$from;
+        $this->to=$to;
+        $this->ledger_id=$ledger_id;
+
+    }
+
+    /**
+     * @brief display a form for giving tva_code and dates
+     * @return void
+     */
+    static function display_form()
+    {
+        require_once NOALYSS_TEMPLATE."/tax_detail-display_form.php";
+    }
+
+    /**
+     * @brief get data
+     */
+    function get_data()
+    {
+        global $g_user,$cn;
+        $filter_ledger=" where ";
+
+
+        // Security
+        if ($g_user->get_status_security_ledger()==1 && $g_user->isAdmin()==0) 
 {
+            $filter_ledger.=$g_user->get_ledger_sql('ALL')."   and ";
+        }
+
+        // filter on the date
+        $filter_ledger.="  jr_date >= to_date ($1,'DD.MM.YYYY') and jr_date <= 
to_date($2,'DD.MM.YYYY')";
+
+        // SQL index of array for  array used in DatabaseCore::get_array
+        $param_idx=3;
+        $aParameter=array($this->from,$this->to);
+
+        // filter on vat_code
+        if ( !empty($this->tva_code ) )
+        {
+            $acc_tva=Acc_Tva::build($cn, $this->tva_code);
+            $filter_ledger.=" and tva_opid = \$$param_idx ";
+            $aParameter[]=$acc_tva->tva_id;
+            $param_idx++;
+        }
+        // filter on the ledger
+        if ( $this->ledger_id <> -1 ) {
+            $filter_ledger.= " and jr_def_id = \$$param_idx";
+            $param_idx++;
+            $aParameter[]=$this->ledger_id;
+
+        }
+        $sql="
+with v_amount_tva as (select 
+                        f_id
+                        ,j_qcode
+                        ,case when j_debit is true then 0-j_montant else 
j_montant end j_montant
+                     , qp_vat_code tva_opid
+                     ,  0-qp_nd_tva  qp_nd_tva
+                     ,  0-qp_nd_tva_recup  qp_nd_tva_recup
+                     ,  0-qp_dep_priv  qp_dep_priv
+                     , qp_vat_sided
+                     , j_poste
+                     , j_debit
+                     , j_text
+                     , jr2.jr_id
+                     , jr2.jr_pj_number
+                     , jr2.jr_internal
+                    ,jr2.jr_date
+                    ,to_char(jr2.jr_date,'DD.MM.YY') str_date
+                    ,jr_def_id
+                    ,0-qp_vat vat_amount
+                from jrnx jr1
+                join jrn jr2 on (jr1.j_grpt = jr2.jr_grpt_id) 
+                 join  quant_purchase q1       using (j_id)
+                union all 
+                select f_id
+                        ,j_qcode
+                        ,case when j_debit is true then 0-j_montant else 
j_montant end
+                     , qs_vat_code
+                     , 0
+                     , 0
+                     , 0
+                     , 0
+                     , j_poste
+                     , j_debit
+                     , j_text
+                     , jr4.jr_id
+                     , jr4.jr_pj_number
+                     , jr4.jr_internal
+                    ,jr4.jr_date
+                    ,to_char(jr4.jr_date,'DD.MM.YY')
+                    ,jr_def_id
+                    ,qs_vat
+                from  jrnx jr3 
+                join jrn jr4 on (jr3.j_grpt = jr4.jr_grpt_id)
+                 join quant_sold qs using (j_id)
+                )
+select *, tva_label,format ('%s (%s)',t1.tva_code ,t1.tva_label) 
tva_code,tva_rate
+from v_amount_tva v1
+join tva_rate t1 on (v1.tva_opid=t1.tva_id)
+$filter_ledger      
+order by jr_date,j_debit
+        ";
+        $data=$cn->get_array($sql,$aParameter);
+        return $data;
+    }
+    /**
+     * @brief display the result in HTML
+     * @return void
+     */
+    function html() {
+        global $data;
+        $data=$this->get_data();
+        require NOALYSS_TEMPLATE."/tax_detail-html.php";
+    }
+    function button_export_csv()
+    {
+        require NOALYSS_TEMPLATE."/tax_detail-button_export_csv.php";
+    }
+
+    /**
+     * @brief export the result in a CSV file
+     */
+    function csv() {
+        $noalyss_csv=new 
Noalyss_Csv(sprintf("tax_detail-{$this->tva_code}-{$this->from}-{$this->to}"));
+        $data=$this->get_data();
+
+        $header=["date",'piece',"fiche","poste","base","privé","code 
tva","taux","montant tva","non deductible","recup"];
+        $noalyss_csv->send_header();
+        $noalyss_csv->write_header($header  );
+        foreach ($data as $item) {
+
+            $noalyss_csv->add($item['str_date']);
+            $noalyss_csv->add($item['jr_pj_number']);
+            $noalyss_csv->add($item['jr_internal']);
+            $noalyss_csv->add($item['j_qcode']);
+            $noalyss_csv->add($item['j_poste']);
+            $noalyss_csv->add(nb($item['j_montant'],2),"number");
+            $noalyss_csv->add(nb($item['qp_dep_priv'],2),"number");
+            $noalyss_csv->add($item['tva_code']);
+            $noalyss_csv->add(nb($item['tva_rate'],2),"number");
+            $noalyss_csv->add(nb($item['vat_amount'],2),"number");
+            $noalyss_csv->add(nb($item['qp_nd_tva'],2),"number");
+            $noalyss_csv->add(nb($item['qp_nd_tva_recup'],2),"number");
+            $noalyss_csv->write();
+
+        }
+    }
+}
\ No newline at end of file
diff --git a/include/class/tax_summary.class.php 
b/include/class/tax_summary.class.php
index ffb5e5037..7417034ff 100644
--- a/include/class/tax_summary.class.php
+++ b/include/class/tax_summary.class.php
@@ -67,7 +67,6 @@ class Tax_Summary
     public function get_db()
     {
         return $this->db;
-        return $this;
     }
 
     /**
@@ -85,7 +84,6 @@ class Tax_Summary
     public function get_date_start()
     {
         return $this->date_start;
-        return $this;
     }
 
     /**
@@ -105,7 +103,7 @@ class Tax_Summary
     public function get_date_end()
     {
         return $this->date_end;
-        return $this;
+
     }
 
     /**
@@ -240,9 +238,9 @@ class Tax_Summary
         return $sql;
     }
     /**
-     * Build the SQL for sale vat
+     * @brief Build the SQL for sale vat
      * 
-     * @param group by ledger
+     * @param $p_group_ledger bool true group by ledgers
      * 
      * @return string
      * 
@@ -329,12 +327,13 @@ class Tax_Summary
                         amount_vat,
                         amount_wovat,
                         amount_sided,
-                        tva_payment_sale as tva_type
+                        tva_payment_sale as tva_type,
+                        jrn_def.jrn_def_id
                     from
                         detail_tva 
                         join tva_rate on (tva_rate.tva_id=qs_vat_code)
                         join jrn_def on (jrn_def.jrn_def_id=j_jrn_def)
-                    order by jrn_def_name, tva_code ||' 
('||tva_rate.tva_label||')'";
+                    order by jrn_def.jrn_def_id,jrn_def_name, tva_code ||' 
('||tva_rate.tva_label||')'";
                 
         $array=$this->db->get_array($sql, [$this->date_start, 
$this->date_end]);
         return $array;
@@ -358,12 +357,13 @@ class Tax_Summary
                     amount_noded_amount,
                     amount_noded_tax,
                     amount_noded_return,
-                    amount_private
+                    amount_private,
+                   jrn_def.jrn_def_id
                 from
                     detail_tva 
                     join tva_rate on (tva_rate.tva_id=qp_vat_code)
                     join jrn_def on (jrn_def.jrn_def_id=j_jrn_def)
-                order by jrn_def_name, tva_code ||' 
('||tva_rate.tva_label||')'";
+                order by  jrn_def.jrn_def_id,jrn_def_name, tva_code ||' 
('||tva_rate.tva_label||')'";
         $array=$this->db->get_array($sql, [$this->date_start, 
$this->date_end]);
         return $array;
     }
@@ -392,7 +392,7 @@ class Tax_Summary
     }
 
     /**
-     * Summary for all purchase ledger
+     * @brief Summary for all purchase ledgers
      */
     function get_summary_purchase()
     {
@@ -464,4 +464,24 @@ class Tax_Summary
         echo '</form>';
     }
 
+    /**
+     * @brief Build a link to show the detail of a VAT ID
+     * @param $dateStart date from format 'DD.MM.YYYY'
+     * @param $DateeEd date to  format 'DD.MM.YYYY'
+     * @param $nLedger_id integer JRN_DEF.JRN_DEF_ID
+     * @param $nVAT_id integer TVA_RATE.TVA_ID
+     * @return javascript string
+     */
+    function 
build_link_detail($dossier_id,$dateStart,$DateeEd,$nLedger_id,$nVAT_id)
+    {
+
+
+        $js=sprintf("tax_detail_view('%s','%s','%s','%s','%s')",
+            
$dossier_id,$this->date_start,$this->date_end,$nLedger_id,$nVAT_id);
+
+        return $js;
+        
+
+    }
+
 }
diff --git a/include/export/export_p1tva_csv.php 
b/include/export/export_p1tva_csv.php
new file mode 100644
index 000000000..8688f4f6e
--- /dev/null
+++ b/include/export/export_p1tva_csv.php
@@ -0,0 +1,40 @@
+<?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 Author Dany De Bontridder danydb@aevalys.eu 27/07/24
+/*! 
+ * \file
+ * \brief  export in CSV detail of tax
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+
+$http=new \HttpInput();
+
+try {
+    $tax_detail=new Tax_Detail(
+        $http->get("vat_code"),
+        $http->get("from"),
+        $http->get("to"),
+        $http->get("p_jrn")
+    );
+} catch (\Exception $e) {
+    echo $e->getMessage();
+    return;
+}
+
+$tax_detail->csv();
\ No newline at end of file
diff --git a/include/tax_detail.inc.php b/include/tax_detail.inc.php
new file mode 100644
index 000000000..f6babd2cf
--- /dev/null
+++ b/include/tax_detail.inc.php
@@ -0,0 +1,41 @@
+<?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 Author Dany De Bontridder danydb@aevalys.eu 26/07/24
+/*! 
+ * \file
+ * \brief detail of VAT
+ */
+global $cn,$http;
+
+// display a form for periode + tva_code
+Tax_Detail::display_form();
+
+// if display
+if ( isset ($_GET['display'])) {
+
+    $tax_detail= new Tax_Detail (
+                            $http->get("vat_code"),
+                            $http->get("from","date"),
+                            $http->get("to","date"),
+                            $http->get("p_jrn","number"));
+    $tax_detail->button_export_csv();
+    $tax_detail->html();
+    $tax_detail->button_export_csv();
+
+}
diff --git a/include/template/tax_detail-button_export_csv.php 
b/include/template/tax_detail-button_export_csv.php
new file mode 100644
index 000000000..d5277b1cb
--- /dev/null
+++ b/include/template/tax_detail-button_export_csv.php
@@ -0,0 +1,41 @@
+<?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 Author Dany De Bontridder danydb@aevalys.eu 27/07/24
+/*! 
+ * \file
+ * \brief  button to export Tax_Detail in CSV
+ */
+$form_id=uniqid("export");
+?>
+<ul class="aligned-block">
+    <li>
+
+<form id="<?=$form_id?>" method="get" action="export.php" 
onsubmit="download_document_form('<?=$form_id?>')">
+    <?php
+    echo Dossier::hidden();
+    echo \HtmlInput::hidden("act", "CSV:p1tva");
+    echo \HtmlInput::hidden("from", $this->from);
+    echo \HtmlInput::hidden("to", $this->to);
+    echo \HtmlInput::hidden("vat_code", $this->tva_code);
+    echo \HtmlInput::hidden("p_jrn", $this->ledger_id);
+    echo \HtmlInput::submit("export_csv", _("Export CSV"));
+    ?>
+</form>
+    </li>
+</ul>
diff --git a/include/template/tax_detail-display_form.php 
b/include/template/tax_detail-display_form.php
new file mode 100644
index 000000000..31c5f2fac
--- /dev/null
+++ b/include/template/tax_detail-display_form.php
@@ -0,0 +1,85 @@
+<?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 Author Dany De Bontridder danydb@aevalys.eu 26/07/24
+/*! 
+ * \file
+ * \brief display a form for detail of tax
+ */
+global $cn;
+$http=new \HttpInput();
+$ivatnumber = new ITva_Popup("vat_code");
+$ivatnumber->value=$http->get("vat_code","string","");
+$idatestart = new IDate("from");
+$idateend = new IDate("to");
+
+global $g_user, $http;
+
+$a_limit = $g_user->get_limit_current_exercice();
+$idatestart->value = $http->get('from', 'date', $a_limit[0]);
+$idateend->value = $http->get('to', 'date', $a_limit[1]);
+
+
+?>
+<div class="content">
+<p class="text-muted">
+    Il peut y avoir des différences entre la TVA calculée et à récupérer à 
cause de TVA Non Déductible, reprise
+    à charge du gérant ou d'arrondi.
+</p>
+    <form method="GET">
+        <div class="form-inline">
+            <label for="from">Début</label>
+            <?= $idatestart->input(); ?>
+            <label for="to">Jusque</label>
+            <?= $idateend->input(); ?>
+
+            <label for="vat_code">Code TVA</label>
+            <?= $ivatnumber->input(); ?>
+            <label for="p_jrn">Journal</label>
+            <?php
+            $a_ledger_purchase=$g_user->get_ledger('ACH',3);
+            $a_ledger_sale=$g_user->get_ledger('VEN',3);
+            $a_ledger=array_merge($a_ledger_sale,$a_ledger_purchase);
+            if ( DEBUGNOALYSS > 1 ) echo 
\Noalyss\Dbg::hidden_info("a_ledger",$a_ledger);
+            $select_value=array();
+            $select_value[]=array('value'=>-1,"label"=>'Tous vente et Achat');
+            foreach($a_ledger as $i_ledger) :
+                
$select_value[]=array("value"=>$i_ledger["jrn_def_id"],"label"=>$i_ledger['jrn_def_name']);
+            endforeach;
+            $select=new \ISelect("p_jrn");
+            $select->value=$select_value;
+            $select->selected=$http->get("p_jrn","number",-1);
+            echo $select->input();
+            ?>
+        </div>
+
+
+        <ul class="aligned-block">
+            <li>
+
+            <?= HtmlInput::submit("display", _("Afficher")); ?>
+            </li>
+        </ul>
+        <?php
+        echo \HtmlInput::hidden("ac", $http->request("ac"));
+        echo \Dossier::hidden();
+        ?>
+    </form>
+
+</div>
+<hr>
\ No newline at end of file
diff --git a/include/template/tax_detail-html.php 
b/include/template/tax_detail-html.php
new file mode 100644
index 000000000..a235d5e17
--- /dev/null
+++ b/include/template/tax_detail-html.php
@@ -0,0 +1,109 @@
+<?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 Author Dany De Bontridder danydb@aevalys.eu 26/07/24
+/*! 
+ * \file
+ * \brief display result of tax detail
+ *
+ */
+
+global $data;
+echo HtmlInput::filter_table("detail_tva_id", "0,1,2,3,4,5,6,7,8,9,10,11", 1);
+$aTotaux=array();
+foreach 
(array('amount','vat_amount','amount_nd_tva','amount_nd_recup','autoreverse') 
as $i_tva) :
+    $aTotaux[$i_tva]=0;
+endforeach;
+?>
+<table class="result" id="detail_tva_id">
+    <tr>
+        <th>Date</th>
+        <th>Pièce</th>
+        <th>Fiche</th>
+        <th>Poste</th>
+        <th class="num">Base</th>
+        <th class="text-center">code TVA</th>
+        <th class="num">Taux</th>
+        <th class="num">Montant TVA</th>
+        <th class="num">Non déductible</th>
+        <th class="num">récupérable par impôt</th>
+
+        <th class="num">Autoliquidation</th>
+    </tr>
+<?php
+$idx=0; bcscale(4);
+foreach ($data as $item):
+    $idx++;
+    $class=($idx%2==0)?'even':'odd';
+    
$receipt_number=($item['jr_pj_number']=="")?$item['jr_internal']:$item['jr_pj_number'];
+    $control=bcmul($item['tva_rate'],$item['j_montant'],4);
+    $delta_control=bcsub($control,$item['vat_amount']);
+ //   $delta_control=bcsub($delta_control,$item['qp_nd_tva_recup']);
+  //  $delta_control=bcsub($delta_control,$item['qp_nd_tva']);
+  /*  $delta_control=bcsub($delta_control,$item['qp_dep_priv']);*/
+    $delta_control=round($delta_control,2);
+    $w_amount="";
+    if ( $delta_control != 0 ) {
+        $w_amount=sprintf('<span tabindex="-1" style="color:red" 
class="icon">&#xe80e; diff. TVA calculée %s</span>',$delta_control);
+    }
+?>
+<tr class="<?=$class?>">
+    <td><?=$item['str_date']?></td>
+    <td><?=HtmlInput::detail_op($item["jr_id"], $receipt_number)?></td>
+    <td><?=$item['j_qcode']?></td>
+    <td><?=$item['j_poste']?>
+        <?=$w_amount?>
+    </td>
+    <td class="num"><?=nbm($item['j_montant'],2)?></td>
+    <td class="text-center"><?=$item['tva_code']?></td>
+    <td class="num"><?=nbm($item['tva_rate'],2)?></td>
+    <td class="num"><?=nbm($item['vat_amount'],2)?></td>
+    <td class="num"><?=nbm($item['qp_nd_tva'],2)?></td>
+    <td class="num"><?=nbm($item['qp_nd_tva_recup'],2)?></td>
+    <td class="num"><?=nbm($item['qp_vat_sided'],2)?></td>
+    <?php
+    $aTotaux['amount']=bcadd($aTotaux['amount'],$item['j_montant'],2);
+    $aTotaux['vat_amount']=bcadd($aTotaux['vat_amount'],$item['vat_amount'],2);
+    
$aTotaux['amount_nd_tva']=bcadd($aTotaux['amount_nd_tva'],$item['qp_nd_tva'],2);
+    
$aTotaux['amount_nd_recup']=bcadd($aTotaux['amount_nd_recup'],$item['qp_nd_tva_recup'],2);
+
+    
$aTotaux['autoreverse']=bcadd($aTotaux['autoreverse'],$item['qp_vat_sided'],2);
+    ?>
+</tr>
+<?php
+endforeach;
+?>
+<tfoot>
+<tr class="highlight">
+    <td></td>
+    <td></td>
+    <td></td>
+    <td></td>
+    <td class="num"><?=nbm($aTotaux['amount'],2)?></td>
+    <td></td>
+    <td></td>
+    <td class="num"><?=nbm($aTotaux['vat_amount'],2)?></td>
+    <td class="num"><?=nbm($aTotaux['amount_nd_tva'],2)?></td>
+    <td class="num"><?=nbm($aTotaux['amount_nd_recup'],2)?></td>
+
+    <td class="num"><?=nbm($aTotaux['autoreverse'],2)?></td>
+
+</tr>
+</tfoot>
+
+</table>
diff --git a/include/template/tax_summary_display.php 
b/include/template/tax_summary_display.php
index 4f7bcdb79..11a6640b6 100644
--- a/include/template/tax_summary_display.php
+++ b/include/template/tax_summary_display.php
@@ -33,6 +33,7 @@
 bcscale(4);
 $array=$this->get_row_sale();
 $nb_array=count($array);
+$dossier_id=Dossier::id();
 $ledger="";
 $r=0;
 $tot_vat=0;$tot_wovat=0;$tot_sided=0;
@@ -71,8 +72,13 @@ for ($i=0;$i < $nb_array;$i++):
 <tr class="<?php echo $color;?>">
     <td>
         <?=$array[$i]['tva_label']?>
+        <?php
+        // add a link to see the detail in ajax : ajax_ledger.php
+        $js_detail = $this->build_link_detail($dossier_id, $this->date_start, 
$this->date_end,$array[$i]['jrn_def_id'], $array[$i]['qs_vat_code']);
+        ?>
+        <a href="javascript:void(0)" onclick="<?=$js_detail?>">Détails</a>
     </td>
-    <td>
+    <td class="num">
         <?=$array[$i]['tva_rate']*100?>%
     </td>
     <td class="num">
@@ -143,6 +149,7 @@ $a_sum=$this->get_summary_sale();
 
         <td>
             <?=$a_sum[$e]['tva_label']?>
+
         </td>
         <td  class="num">
             <?=$a_sum[$e]['tva_rate']*100?>%
@@ -224,6 +231,11 @@ for ($i=0;$i < $nb_array;$i++):
     <tr class="<?php echo $color;?>">
         <td>
             <?=$array[$i]['tva_label']?>
+            <?php
+            // add a link to see the detail in ajax : ajax_ledger.php
+            $js_detail = $this->build_link_detail($dossier_id, 
$this->date_start, $this->date_end,$array[$i]['jrn_def_id'], 
$array[$i]['qp_vat_code']);
+            ?>
+            <a href="javascript:void(0)" onclick="<?=$js_detail?>">Détails</a>
         </td>
         <td>
             <?=$array[$i]['tva_rate']*100?>%
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index e69de29bb..85ba072d6 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -0,0 +1,44 @@
+CREATE OR REPLACE FUNCTION  replace_menu_code( code_source text, 
code_destination text)
+    RETURNS void
+AS $function$
+begin
+    /*code */
+
+    update bookmark set b_action = 
replace(b_action,code_source,code_destination) where b_action ~ code_source;
+    update menu_ref set me_code =code_destination where me_code = code_source;
+    update profile_menu set me_code=code_destination where me_code = 
code_source;
+    update profile_menu set me_code_dep=code_destination where me_code_dep = 
code_source;
+end ;
+$function$
+LANGUAGE plpgsql;
+
+
+select replace_menu_code('PRINTGL','P0GRL');
+select replace_menu_code('PRINTBAL','P0BAL');
+select replace_menu_code('PRINTREC','P0RAP');
+select replace_menu_code('PRINTBILAN','P0BIL');
+select replace_menu_code('PRINTJRN','P0JRN');
+select replace_menu_code('PRINTTVA','P0TVA');
+select replace_menu_code('PRINTPOSTE','P0PST');
+select replace_menu_code('PRINTREPORT','P0RPO');
+select replace_menu_code('BALAGE','P0BLG');
+
+
+insert into menu_ref 
(me_code,me_menu,me_file,me_description,me_type,me_description_etendue)
+values('P1TVA','Détail TVA','tax_detail.inc.php','Détail TVA  par 
journal','ME','Détail des TVA ');
+
+insert into profile_menu 
(me_code,me_code_dep,p_id,p_order,p_type_display,pm_default,pm_id_dep)
+select me_code,'PRINT',1,250,'E',0,6 from menu_ref where me_code='P1TVA'
+union
+select me_code,'PRINT',1,250,'E',0,35 from menu_ref where me_code='P1TVA'
+union
+select me_code,'PRINT',2,250,'E',0,719 from menu_ref where me_code='P1TVA' and 
exists (select 1 from profile where p_id=2)
+union
+select me_code,'PRINT',2,250,'E',0,716 from menu_ref where me_code='P1TVA' and 
exists (select 1 from profile where p_id=2)
+;
+insert into menu_ref (me_code,me_menu,me_file,me_type)
+values ('CSV:p1tva','Export Détail TVA','export_p1tva_csv.php','PR')
+
+;
+
+insert into profile_menu(me_code,p_id,p_type_display) select 
'CSV:p1tva',p_id,'P' from profile where p_id in (1,2);
\ No newline at end of file



reply via email to

[Prev in Thread] Current Thread [Next in Thread]