noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
tax_detail.class.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19// Copyright Author Dany De Bontridder danydb@aevalys.eu 26/07/24
20/*!
21 * \file
22 * \brief detail of TVA_CODE for a specific ledger and periode
23 */
24
26{
27 protected $from; //!< Start date
28 protected $to; //!< end date
29 protected $tva_code; //!< tva_code
30 protected $ledger_id; //!< ledger_id (jrn_def.jrn_def_id) -1, means all ledger Sale + Purchase
31
33
34 $this->tva_code=$tva_code;
35 $this->from=$from;
36 $this->to=$to;
37 $this->ledger_id=$ledger_id;
38
39 }
40
41 /**
42 * @brief display a form for giving tva_code and dates
43 * @return void
44 */
45 static function display_form()
46 {
47 require_once NOALYSS_TEMPLATE."/tax_detail-display_form.php";
48 }
49
50 /**
51 * @brief get data
52 */
53 function get_data()
54 {
55 global $g_user,$cn;
56 $filter_ledger=" where ";
57
58
59 // Security
60 if ($g_user->get_status_security_ledger()==1 && $g_user->isAdmin()==0) {
61 $sSecurity=$g_user->get_ledger_sql('ALL')." and ";
62 $sSecurity=str_replace('jrn_def_id','v1.jr_def_id',$sSecurity);
63 $filter_ledger.=$sSecurity;
64 }
65
66 // filter on the date
67 $filter_ledger.=" jr_date >= to_date ($1,'DD.MM.YYYY') and jr_date <= to_date($2,'DD.MM.YYYY')";
68
69 // SQL index of array for array used in DatabaseCore::get_array
70 $param_idx=3;
71 $aParameter=array($this->from,$this->to);
72
73 // filter on vat_code
74 if ( !empty($this->tva_code ) )
75 {
76 $acc_tva=Acc_Tva::build($cn, $this->tva_code);
77 $filter_ledger.=" and tva_opid = \$$param_idx ";
78 $aParameter[]=$acc_tva->tva_id;
79 $param_idx++;
80 }
81 // filter on the ledger
82 if ( $this->ledger_id <> -1 ) {
83 $filter_ledger.= " and jr_def_id = \$$param_idx";
84 $param_idx++;
85 $aParameter[]=$this->ledger_id;
86
87 }
88 $sql="
89with v_amount_tva as (select
90 f_id
91 ,j_qcode
92 ,case when j_debit is true then 0-j_montant else j_montant end j_montant
93 , qp_vat_code tva_opid
94 , 0-qp_nd_tva qp_nd_tva
95 , 0-qp_nd_tva_recup qp_nd_tva_recup
96 , 0-qp_dep_priv qp_dep_priv
97 , qp_vat_sided
98 , j_poste
99 , j_debit
100 , j_text
101 , jr2.jr_id
102 , jr2.jr_pj_number
103 , jr2.jr_internal
104 ,jr2.jr_date
105 ,to_char(jr2.jr_date,'DD.MM.YY') str_date
106 ,jr_def_id
107 ,0-qp_vat vat_amount
108 from jrnx jr1
109 join jrn jr2 on (jr1.j_grpt = jr2.jr_grpt_id)
110 join quant_purchase q1 using (j_id)
111 union all
112 select f_id
113 ,j_qcode
114 ,case when j_debit is true then 0-j_montant else j_montant end
115 , qs_vat_code
116 , 0
117 , 0
118 , 0
119 , 0
120 , j_poste
121 , j_debit
122 , j_text
123 , jr4.jr_id
124 , jr4.jr_pj_number
125 , jr4.jr_internal
126 ,jr4.jr_date
127 ,to_char(jr4.jr_date,'DD.MM.YY')
128 ,jr_def_id
129 ,qs_vat
130 from jrnx jr3
131 join jrn jr4 on (jr3.j_grpt = jr4.jr_grpt_id)
132 join quant_sold qs using (j_id)
133 )
134select *, tva_label,format ('%s (%s)',t1.tva_code ,t1.tva_label) tva_code,tva_rate
135from v_amount_tva v1
136join tva_rate t1 on (v1.tva_opid=t1.tva_id)
137$filter_ledger
138order by jr_date,j_debit
139 ";
140 $data=$cn->get_array($sql,$aParameter);
141 return $data;
142 }
143 /**
144 * @brief display the result in HTML
145 * @return void
146 */
147 function html() {
148 global $data;
149 $data=$this->get_data();
150 require NOALYSS_TEMPLATE."/tax_detail-html.php";
151 }
153 {
154 require NOALYSS_TEMPLATE."/tax_detail-button_export_csv.php";
155 }
156
157 /**
158 * @brief export the result in a CSV file
159 */
160 function csv() {
161 $noalyss_csv=new Noalyss_Csv(sprintf("tax_detail-{$this->tva_code}-{$this->from}-{$this->to}"));
162 $data=$this->get_data();
163
164 $header=[_("date"),_('piece'),_("n° interne"),_("fiche"),_("poste"),_("base"),_("privé"),_("code tva"),_("taux"),_("montant tva"),_("non deductible"),_("recup")];
165 $noalyss_csv->send_header();
166 $noalyss_csv->write_header($header );
167 foreach ($data as $item) {
168
169 $noalyss_csv->add($item['str_date']);
170 $noalyss_csv->add($item['jr_pj_number']);
171 $noalyss_csv->add($item['jr_internal']);
172 $noalyss_csv->add($item['j_qcode']);
173 $noalyss_csv->add($item['j_poste']);
174 $noalyss_csv->add(nb($item['j_montant'],2),"number");
175 $noalyss_csv->add(nb($item['qp_dep_priv'],2),"number");
176 $noalyss_csv->add($item['tva_code']);
177 $noalyss_csv->add(nb($item['tva_rate'],2),"number");
178 $noalyss_csv->add(nb($item['vat_amount'],2),"number");
179 $noalyss_csv->add(nb($item['qp_nd_tva'],2),"number");
180 $noalyss_csv->add(nb($item['qp_nd_tva_recup'],2),"number");
181 $noalyss_csv->write();
182
183 }
184 }
185}
nb($p_number)
format the number for the CSV export
global $g_user
if no group available , then stop
$anc_grandlivre to
$anc_grandlivre from
_("actif, passif,charge,...")
static build($db, $p_code)
retrieve TVA rate thanks the code that could be the tva_id or tva_code.
Manage the CSV : manage files and write CSV record.
__construct($tva_code, $from, $to, $ledger_id)
html()
display the result in HTML
static display_form()
display a form for giving tva_code and dates
$ledger_id
ledger_id (jrn_def.jrn_def_id) -1, means all ledger Sale + Purchase
get_data()
get data
$from
Start date.
csv()
export the result in a CSV file
if(count($a_accounting)==0) $header
$filter_ledger
Definition preod.inc.php:39