noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
invoice_pdf.class.php
Go to the documentation of this file.
1<?php
2
3namespace Noalyss;
4
5/*
6 * This file is part of NOALYSS.
7 *
8 * NOALYSS is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * NOALYSS is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with NOALYSS; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22// Copyright Author Dany De Bontridder danydb@aevalys.eu 22/10/23
23
24
25/**
26 * @file invoice_pdf.class.php
27 * @brief create a standard invoice
28 */
29
30/**
31 * @class Invoice_PDF
32 * @brief create a standard invoice
33 */
34class Invoice_PDF extends \PDF
35{
36
37 private $data; //!< $data (array) see Acc_Ledger_Purchases
38
39 function __construct(
41 , private $dirname //!< folder where to save file
42 , private $filename //!< filename to use
43 )
44 {
45 parent::__construct($cn);
46 }
47
48 public function get_dirname()
49 {
50 return $this->dirname;
51 }
52
53 public function get_filename()
54 {
55 return $this->filename;
56 }
57
58 public function set_dirname($dirname)
59 {
60 $this->dirname = $dirname;
61 return $this;
62 }
63
64 public function set_filename($filename)
65 {
66 $this->filename = $filename;
67 return $this;
68 }
69
70 function set_data($array)
71 {
72 $this->data = $array;
73 return $this;
74 }
75
76 function get_data()
77 {
78 return $this->data;
79 }
80
81 function footer()
82 {
83 //Position at 1 cm from bottom
84 $this->SetY(-10);
85 //Arial italic 8
86 $this->SetFont('Arial', '', 8);
87 //Page number
88 parent::Cell(0, 8, " Page " . $this->PageNo() . '/{nb}', 0, 0, 'C');
89 parent::Ln(3);
90 }
91
92 function header()
93 {
94 global $g_parameter;
95 $this->setY(15);
96 $this->SetFont('DejaVu', '', 6);
97 $colsize = 90;
98 $this->write_multi($colsize, 3, $g_parameter->MY_NAME);
99 $this->write_multi($colsize, 3, $this->data['e_date'], border: '', align: 'R');
100 $this->line_new();
101 $this->write_multi($colsize, 3,
102 sprintf("%s %s "
103 , $g_parameter->MY_STREET
104 , $g_parameter->MY_NUMBER));
105 $this->line_new();
106 $this->write_multi($colsize, 3, $g_parameter->MY_POSTCODE
107 . " " . $g_parameter->MY_CITY
108 . " " . $g_parameter->MY_COUNTRY
109 );
110 $this->line_new();
111 $this->write_multi($colsize, 3, $g_parameter->MY_TVA);
112 $this->line_new();
113
114 $email_company = $this->cn->get_value("select pe_value from parameter_extra where pe_code=$1",
115 ['INVOICE_EMAIL_COMPANY']);
116 $site = $this->cn->get_value("select pe_value from parameter_extra where pe_code=$1",
117 ['WEB_COMPANY']);
118 // for FRANCE , the SIREN and SIRET must be given
119 $siren = $this->cn->get_value("select pe_value from parameter_extra where pe_code=$1",
120 ['SIREN']);
121 $siret = $this->cn->get_value("select pe_value from parameter_extra where pe_code=$1",
122 ['SIRET']);
123 $iban = $this->cn->get_value("select pe_value from parameter_extra where pe_code=$1",
124 ['COMPANY_BANK_IBAN']);
125 $bic = $this->cn->get_value("select pe_value from parameter_extra where pe_code=$1",
126 ['COMPANY_BANK_BIC']);
127
128 if ($siret != "")
129 {
130 $this->write_multi($colsize, 3, "SIRET $siret");
131 $this->line_new();
132 }
133 if ($siren != "")
134 {
135 $this->write_multi($colsize, 3, "SIREN $siren");
136 $this->line_new();
137 }
138 if ($iban != "")
139 {
140 $this->write_multi($colsize, 3, "IBAN $iban BIC $bic");
141 $this->line_new();
142 }
143 if ($g_parameter->MY_PHONE != "")
144 {
145 $this->write_multi($colsize, 3, sprintf(_("Tel %s "),
146 $g_parameter->MY_PHONE
147 ));
148 $this->line_new();
149 }
150 if ($email_company != "")
151 {
152 $this->write_multi($colsize, 3, sprintf(_("email %s "),
153 $email_company));
154 $this->line_new();
155 }
156 if ($site != "")
157 {
158 $this->write_multi($colsize, 3, sprintf(_("site %s"),
159 $site
160 ));
161 $this->line_new();
162 }
163 $this->setFont("DejaVu", 'B', 14);
164 $this->write_multi(40, 10, "");
165 $this->write_multi(100, 10, _("Facture") . " " . $this->data['e_pj'], border: 1, align: 'C');
166 $this->write_multi(40, 10, "");
167 $this->line_new(10);
168 $this->ln(5);
169 }
170
171 //!
172 //@brief make the invoice
173 function export()
174 {
175 $this->SetAuthor('NOALYSS');
176 $this->AliasNbPages();
177 $this->AddPage();
178 $this->SetAutoPageBreak(true, $this->bMargin*1);
179 $this->setTitle($this->filename, true);
180 // $customer (Fiche) retrieve card of the customer
181 $customer = new \Fiche($this->cn);
182 $customer->get_by_qcode(trim($this->data['e_client']));
183
184 $this->setFont("DejaVu", '', 7);
185 $this->write_cell(50, 4, "");
186 $this->write_cell(60, 4, sprintf(_("Echéance %s"), $this->data['e_ech']));
187 $this->line_new();
188 $this->write_cell(50, 4, "");
189 $this->write_cell(100, 4, _("Client"), 'B', 'R');
190 $this->line_new();
191 $this->write_cell(50, 4, "");
192 $this->write_cell(110, 4, $customer->get_attribute(ATTR_DEF_NAME)
193 . " " . $customer->get_attribute(ATTR_DEF_FIRST_NAME, 0));
194 $this->line_new();
195 $this->write_cell(50, 4, "");
196 $this->write_cell(110, 4, $customer->get_attribute(ATTR_DEF_ADRESS, 0));
197 $this->line_new();
198 $this->write_cell(50, 4, "");
199 $this->write_cell(110, 4, $customer->get_attribute(ATTR_DEF_POSTCODE, 0)
200 . " " . $customer->get_attribute(ATTR_DEF_CITY, 0)
201 );
202 $this->line_new();
203 $this->write_cell(50, 4, "");
204 $this->write_cell(110, 4, $customer->get_attribute(ATTR_DEF_COUNTRY, 0));
205 $this->line_new();
206 $this->write_cell(50, 4, "");
207 $this->write_cell(110, 4, $customer->get_attribute(ATTR_DEF_NUMTVA, 0));
208 $this->line_new();
209 $a_tva_amount = [];
210 $a_tva_code = [];
211 $col = array(
212 "quick_code" => 30,
213 "label" => 80,
214 "quantity" => 25,
215 "price" => 25,
216 "vat_code" => 20
217 );
218 $this->SetFont("DejaVu", "B", 12);
219 $this->write_multi(50, 20, "");
220 $this->write_multi(50, 20, _("Détails"));
221 $this->line_new();
222 $this->SetFont("DejaVu", "B", 7);
223 $currency = new \Acc_Currency($this->cn, $this->data['p_currency_code']);
224 $this->write_multi(100, 4, sprintf(_("Les montants sont en %s taux %s")
225 , $currency->get_code()
226 , $this->data['p_currency_rate']));
227 $this->line_new(4);
228 $this->SetFont("DejaVuCond", "", 7);
229 if ($this->data["bon_comm"] != "")
230 {
231 $this->write_multi(120, 4, sprintf(_("Bon de commande / référence %s")
232 , $this->data["bon_comm"]));
233 $this->line_new(4);
234 }
235 $this->line_new(4);
236 $this->SetFont("DejaVu", "", 7);
237 $this->write_multi($col['quick_code'], 4, _("Article"), 1);
238 $this->write_multi($col['label'], 4, _("Description"), 1);
239 $this->write_multi($col['quantity'], 4, _("Quantité"), 1, align: 'C');
240 $this->write_multi($col['price'], 4, _("Prix"), 1, align: 'C');
241 $this->write_multi($col['vat_code'], 4, _("TVA"), 1, align: 'C');
242 $this->line_new();
243 ///@var $tot_amount (float) total amount without VAT
244 ///@var $tot_vat (float) total VAT
245 ///@var $line (int) line printed
247 for ($i = 0; $i < $this->data['nb_item']; $i++)
248 {
249 $item = new \Fiche($this->cn);
250 if (!isset($this->data['e_march' . $i]) || $this->data['e_march' . $i] == "")
251 {
252 continue;
253 }
254 $line++;
255 $item->get_by_qcode(trim($this->data['e_march' . $i]));
256 $fill = $this->is_fill($line);
257 $this->write_multi($col['quick_code'], 4, $item->get_attribute(ATTR_DEF_QUICKCODE),'','',$fill);
258 if ( isset ($this->data['e_march' . $i . '_label']))
259 {
260 $this->write_multi($col['label'], 4, $this->data['e_march' . $i . '_label'],fill:$fill);
261 }else {
262 $this->write_multi($col['label'], 4,$item->get_attribute(ATTR_DEF_NAME),fill:$fill);
263 }
264 $this->write_multi($col['quantity'], 4, nbm($this->data['e_quant' . $i]), '', 'R',fill:$fill);
265 $this->write_multi($col['price'], 4, nbm($this->data['e_march' . $i . '_price']), '', 'R',fill:$fill);
266 $this->write_multi($col['vat_code'], 4, $this->data['e_march' . $i . '_tva_id'], '', 'C',fill:$fill);
267 $x = $this->data['e_march' . $i . '_tva_id'];
268 if (!isset($a_tva_amount[$x]))
269 {
270 $a_tva_amount[$x] = 0;
271 }
272 $a_tva_amount[$x] = bcadd($a_tva_amount[$x], $this->data["e_march" . $i . "_tva_amount"], 2);
274 , bcmul($this->data['e_march' . $i . '_price']
275 , $this->data['e_quant' . $i]
276 , 2
277 )
278 , 2);
279 $tot_vat = bcadd($tot_vat
280 , $this->data['e_march' . $i . '_tva_amount']
281 , 2);
282 $this->line_new(4);
283 if ($this->GetY()>250) {
284 $this->AddPage();
285 }
286 }
287 $this->line_new(10);
288 $this->SetFont("DejaVu", "B", 9);
289 $this->write_multi(30, 4, _("TVA"));
290 $this->line_new(5);
291 $this->SetFont("DejaVu", "", 7);
292 foreach ($a_tva_amount as $tva_id => $tva_amount)
293 {
294 $tva = \Acc_Tva::build($this->cn, $tva_id);
295 $this->write_multi(20, 4, "");
296 $this->write_multi(80, 4, $tva->tva_id
297 . " / " . $tva->tva_code
298 . " / " . $tva->tva_label
299 . " / " . $tva->tva_rate * 100
300 );
301
302 $this->write_multi(50, 4, $tva_amount,align:'R');
303 $this->line_new();
304 }
305 $this->ln(20);
306 $this->SetFont("DejaVu", "B", 9);
307 $this->write_multi(30, 4, _("TOTAUX"));
308 $this->line_new();
309 $this->SetFont("DejaVu", "", 7);
310 $this->write_multi(60, 4, _("Total Hors TVA "));
311 $this->write_multi(60, 4, nbm($tot_amount), '', 'R');
312 $this->line_new();
313 $this->write_multi(60, 4, _("Total TVA "));
314 $this->write_multi(60, 4, nbm($tot_vat), '', 'R');
315 $this->line_new();
316 $this->write_multi(60, 4, _("Total "));
317 $this->write_multi(60, 4, nbm(bcadd($tot_amount, $tot_vat, 2),2), '', 'R');
318 $this->line_new();
319 $iban = $this->cn->get_value("select pe_value from parameter_extra where pe_code=$1",
320 ['COMPANY_BANK_IBAN']);
321 if ($this->data['e_ech'] != "" && $iban != "")
322 {
323 $info = ($this->data["other_info"] == "") ? $this->data["e_pj"] : $this->data["other_info"];
324 $bic = $this->cn->get_value("select pe_value from parameter_extra where pe_code=$1",
325 ['COMPANY_BANK_IBAN']);
326 $this->write_multi(150, 4,
327 sprintf(_("Paiement avant le %s sur le compte %s (BIC %s) avec comme message %s"),
328 $this->data['e_ech']
329 , $iban
330 , $bic
331 , $this->data["other_info"]
332 )
333 );
334 $this->line_new();
335 }
336 $this->Output($this->dirname . DIRECTORY_SEPARATOR . $this->filename, "F");
337 }
338}
nbm($p_number, $p_dec=2)
format the number with a sep.
global $g_parameter
$input_from cn
_("actif, passif,charge,...")
contains the class for connecting to Noalyss
create a standard invoice
__construct(\Database $cn, private $dirname, private $filename)
$data
$data (array) see Acc_Ledger_Purchases
line_new($p_step=null)
Print all the cell stored and call Ln (new line)
write_multi($width, $interline, $txt, $border=0, $align='', $fill=false)
add a cell with automatic return to the line if the text is too long
API for creating PDF, unicode, based on tfpdf.
Definition pdf.class.php:34
const ATTR_DEF_ADRESS
Definition constant.php:230
const ATTR_DEF_NUMTVA
Definition constant.php:229
const ATTR_DEF_NAME
Definition constant.php:223
const ATTR_DEF_COUNTRY
Definition constant.php:232
const ATTR_DEF_POSTCODE
Definition constant.php:231
$dirname
Definition constant.php:42
const ATTR_DEF_CITY
Definition constant.php:236
const ATTR_DEF_FIRST_NAME
Definition constant.php:245
const ATTR_DEF_QUICKCODE
Definition constant.php:244