noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
xml_reader.class.php
Go to the documentation of this file.
1<?php
2
3namespace Noalyss\XMLDocument;
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 * @file
26 * @brief answer to an inplace object
27 */
28abstract class XML_Reader
29{
30
31 protected \DOMDocument $domDocument;
32 protected readonly \DOMXPath $xpath;
33
34 public function __construct(\DOMDocument $domDocument)
35 {
36 $this->domDocument = $domDocument;
37 $this->xpath = new \DOMXPath($this->domDocument);
38 }
39 /**
40 * @brief before executing xpath->query the namespace must be registered
41 * the NS are different for each type of doc
42 * @param $xml (null , DOMXPath simpleXML)
43 */
44 public function registerNS($xml=null)
45 {
46 $a_namespace=$this->get_namespace();
47 if ($xml == null)
48 {
49 foreach ($a_namespace as $pf=>$ns) {
50 $this->xpath->registerNamespace($pf,$ns);
51 }
52 }
53 elseif ( get_class($xml) == "SimpleXMLElement" )
54 {
55 foreach ($a_namespace as $pf=>$ns) {
56 $xml->registerXPathNamespace($pf,$ns);
57 }
58 }
59 elseif (get_class($xml) == "DOMXPath" )
60 {
61 foreach ($a_namespace as $pf=>$ns) {
62 $xml->registerNamespace($pf,$ns);
63 }
64
65 }
66 else
67 {
68 throw new \Exception ("unknown object ".get_class($xml),57);
69 }
70 }
71 /**
72 *
73 * @return \DOMDocument
74 */
75 public function get_domDocument(): \DOMDocument
76 {
77 return $this->domDocument;
78 }
79
80 public function get_xpath(): \DOMXPath
81 {
82 return $this->xpath;
83 }
84
85 public function set_domDocument($domDocument)
86 {
87 $this->domDocument = $domDocument;
88 return $this;
89 }
90
91 /**
92 * @brief Build an XMLInvoice_Reader object from an XML file
93 * @param $filename (string) file and path to the file
94 * @return \Noalyss\XMLDocument\XMLInvoice_Reader
95 * @throws \Exception if xml not valid
96 */
97 static function build_from_file($filename)
98 {
99 if (!file_exists($filename))
100 {
101 throw new \Exception("XR101: file not found $filename", 101);
102 }
103 $dm = new \DOMDocument();
104 if ($dm->load($filename) == false)
105 {
106 throw new \Exception("XR106: cannot load file", 106);
107 }
108 if ( $dm->getElementsByTagName("CreditNote")->length == 1)
109 {
110 return new XMLCreditNote_Reader($dm);
111 }
112 if ( $dm->getElementsByTagName("Invoice")->length == 1)
113 {
114 return new XMLInvoice_Reader($dm);
115 }
116 throw new \Exception("XR116: unknown XML", 116);
117 }
118
119 /**
120 * @brief Build an XMLInvoice_Reader object from an XML string
121 * @param $string (string) XML
122 * @return \Noalyss\XMLDocument\XMLInvoice_Reader
123 * @throws \Exception if xml not valid
124 */
125 static function build_from_string($string)
126 {
127 $dm = new \DOMDocument();
128 if ($dm->loadXML($string) == false)
129 {
130 throw new \Exception("XR130: cannot load XML", 130);
131 }
132 if ( $dm->getElementsByTagName("CreditNote")->length == 1)
133 {
134 return new XMLCreditNote_Reader($dm);
135 }
136 if ( $dm->getElementsByTagName("Invoice")->length == 1)
137 {
138 return new XMLInvoice_Reader($dm);
139 }
140 throw new \Exception("XR120: unknown XML", 120);
141 }
142
143
144
145 /**
146 * @brief returns the embedded document in an array (keys : filecontent (BYTES),mimecode , filename)
147 * or false if there is no document
148 * @return bool|array of Document_Reference
149 * @throws \Exception if there are several documents
150 *
151 */
152 public function get_embedded_document()
153 {
154 $a_document_reference = array();
155 foreach (array(
156 "AdditionalDocumentReference",
157 "ReceiptDocumentReference",
158 "StatementDocumentReference",
159 "OriginatorDocumentReference",
160 "ContractDocumentReference"
161 )
162 as $document)
163 {
164 $document = $this->domDocument->getElementsByTagName($document);
165 if ($document->length == 0)
166 {
167 continue;
168 }
169 for ($e = 0; $e < $document->count(); $e++)
170 {
171 $item = $document->item($e);
172
173 if ($item->nodeType == XML_ELEMENT_NODE)
174 {
175 $id = $item->getElementsByTagName("ID")[0]?->nodeValue;
176 $description = $item->getElementsByTagName("DocumentDescription")[0]?->nodeValue;
177 $embedded_document = $item->getElementsByTagName("EmbeddedDocumentBinaryObject");
178 if ($embedded_document->length == 0)
179 {
180 continue;
181 }
182 $binary_object = new Binary_Object;
183 $binary_object->filecontent = base64_decode($embedded_document[0]->nodeValue);
184 $binary_object->mimecode = $embedded_document[0]->getAttribute("mimeCode");
185 $binary_object->filename = $embedded_document[0]->getAttribute("filename");
186 $document_reference = new Document_Reference();
187 $document_reference->setId($id)
188 ->setDescription($description)
189 ->setBinary_object($binary_object);
190 $a_document_reference[] = clone $document_reference;
191 }
192 }
193 }
194 return $a_document_reference;
195 }
196 /**
197 * @brief execute a XPATH query of the DOMDocument and return the result
198 * or null if nothing found
199 * @param $query (string) valid XPath Query
200 * @return null or DOMNodeList or DOMElement
201 */
202 public function get_node($query)
203 {
204
205 $this->registerNS();
206 if ($this->xpath->query($query)->length == 0)
207 {
208 return null;
209 }
210 return $this->xpath->query($query);
211 }
212 /**
213 * @brief get the node value
214 * @param $query (string) valid XPath query
215 * @param $ix (int) the item number
216 * @return string
217 */
218 function get_node_value($query, $ix = 0)
219 {
220 return $this->get_node($query)?->item($ix)?->nodeValue;
221 }
222
223 /**
224 * @brief get the customer info from XML
225 * @return array
226 */
227 function get_customer(): array
228 {
229 $result = [];
230 $result['ID'] = $this->get_node_value("//cac:AccountingCustomerParty[1]/cac:Party[1]/cbc:EndpointID[1]");
231 $result['name'] = $this->get_node_value('//cac:AccountingCustomerParty[1]/cac:Party[1]/cac:PartyName[1]/cbc:Name[1]');
232 if ($result['name'] == '') {
233 $result['name'] = $this->get_node_value("//cac:AccountingCustomerParty[1]/cac:Party[1]/cac:PartyLegalEntity[1]/cbc:RegistrationName[1]");
234 }
235 $result['street'] = $this->get_node_value('//cac:AccountingCustomerParty[1]/cac:Party[1]/cac:PostalAddress[1]/cbc:StreetName[1]');
236 $result['city'] = $this->get_node_value('//cac:AccountingCustomerParty[1]/cac:Party[1]/cac:PostalAddress[1]/cbc:CityName[1]');
237 $result['postcode'] = $this->get_node_value('//cac:AccountingCustomerParty[1]/cac:Party[1]/cac:PostalAddress[1]/cbc:PostalZone[1]');
238 $result['country_code'] = $this->get_node_value("//cac:AccountingCustomerParty[1]/cac:Party[1]/cac:PostalAddress[1]/cac:Country[1]/cbc:IdentificationCode[1]");
239 $result['company_id'] = $this->get_node_value("//cac:AccountingCustomerParty[1]/cac:Party[1]/cac:PartyTaxScheme[1]/cbc:CompanyID[1]");
240 $result['scheme'] = $this->get_node("//cac:AccountingCustomerParty[1]/cac:Party[1]/cbc:EndpointID[1]")[0]->getAttribute("schemeID");
241 return $result;
242 }
243
244 /**
245 * @brief get the supplier info from XML
246 * @return array
247 */
248 function get_supplier(): array
249 {
250 $result = [];
251 $result['ID'] = $this->get_node_value("//cac:AccountingSupplierParty[1]/cac:Party[1]/cbc:EndpointID[1]");
252 $result['name'] = $this->get_node_value("//cac:AccountingSupplierParty[1]/cac:Party[1]/cac:PartyName[1]/cbc:Name[1]");
253 if ($result['name'] == '') {
254 $result['name'] = $this->get_node_value("//cac:AccountingSupplierParty[1]/cac:Party[1]/cac:PartyLegalEntity[1]/cbc:RegistrationName[1]");
255 }
256 $result['street'] = $this->get_node_value("//cac:AccountingSupplierParty[1]/cac:Party[1]/cac:PostalAddress[1]/cbc:StreetName[1]");
257 $result['city'] = $this->get_node_value("//cac:AccountingSupplierParty[1]/cac:Party[1]/cac:PostalAddress[1]/cbc:CityName[1]");
258 $result['postcode'] = $this->get_node_value("//cac:AccountingSupplierParty[1]/cac:Party[1]/cac:PostalAddress[1]/cbc:PostalZone[1]");
259 $result['country_code'] = $this->get_node_value("//cac:AccountingSupplierParty[1]/cac:Party[1]/cac:PostalAddress[1]/cac:Country[1]/cbc:IdentificationCode[1]");
260 $result['company_id'] = $this->get_node_value("//cac:AccountingSupplierParty[1]/cac:Party[1]/cac:PartyTaxScheme[1]/cbc:CompanyID[1]");
261 $result['scheme'] = $this->get_node("//cac:AccountingSupplierParty[1]/cac:Party[1]/cbc:EndpointID[1]")[0]->getAttribute("schemeID");
262 return $result;
263 }
264
265
266
267 /**
268 * @brief get the Payment Means info from XML
269 * @return array
270 */
271 function get_payment_mean(): array
272 {
273 $result = [];
274 $result['payment_code'] = $this->get_node_value("//cac:PaymentMeans[1]/cbc:PaymentMeansCode[1]");
275 $result['label'] = $this->get_node_value("//cac:PaymentMeans[1]/cbc:PaymentID[1]");
276 $result['iban'] = $this->get_node_value("//cac:PaymentMeans[1]/cac:PayeeFinancialAccount[1]/cbc:ID[1]");
277 $result['bic'] = $this->get_node_value("//cac:PaymentMeans[1]/cac:PayeeFinancialAccount[1]/cac:FinancialInstitutionBranch[1]/cbc:ID[1]");
278 $result['note'] = [];
279 $note = $this->get_node("//cac:PaymentTerms/cbc:Note");
280 if ($note != null)
281 {
282 $a = $note->length;
283 for ($i = 0; $i < $a; $i++)
284 {
285 $result['note'][] = $note->item($i)->nodeValue;
286 }
287 }
288 /**
289 <cac:PaymentTerms>
290 <cbc:Note> In geval van betaling binnen 14 dagen is 2% (52.00€) betalingskorting van
291 toepassing en het te betalen bedrag = 3053.68€
292 En cas de paiement dans les 14 jours, l'escompte conditionnel de 2% (52.00€) est appliqué et le montant payable = 3053.68€
293 In case of payment within 14 days, 2% (52.00€) conditional cash/payment discount applies and the payable amount = 3053.68€
294 </cbc:Note>
295 </cac:PaymentTerms>
296 */
297 return $result;
298 }
299
300 /**
301 * @brief get the node value from simpleXML
302 * @param $xml (\SimpleXMLElement) fragment of XML dom
303 * @param $query (string) XPath query
304 * @return string
305 */
306 protected function get_simple_xml_value(\SimpleXMLElement $xml, $query): string
307 {
308 $this->registerNS($xml);
309
310 $x = $xml->xpath($query);
311 $result = (count($x) == 0) ? "" : $x[0];
312 return (string) $result;
313 }
314
315 /**
316 * @brief get the amount summary info from XML
317 * @return array
318 */
319 function get_amount_summary(): array
320 {
321 $result = [];
322 $node = $this->get_node("//cac:LegalMonetaryTotal");
323 $xml = simplexml_import_dom($node->item(0));
324 $result['LineExtensionAmount'] = $this->get_simple_xml_value($xml, "cbc:LineExtensionAmount");
325 $result['TaxExclusiveAmount'] = $this->get_simple_xml_value($xml, "cbc:TaxExclusiveAmount");
326 $result['TaxInclusiveAmount'] = $this->get_simple_xml_value($xml, "cbc:TaxInclusiveAmount");
327 $result['PayableAmount'] = $this->get_simple_xml_value($xml, "cbc:PayableAmount");
328 $result['AllowanceTotalAmount'] = $this->get_simple_xml_value($xml, "cbc:AllowanceTotalAmount");
329 $result['AllowanceTotalAmount'] = ($result['AllowanceTotalAmount'] == "") ? 0 : $result['AllowanceTotalAmount'];
330 $result['ChargeTotalAmount'] = $this->get_simple_xml_value($xml, "cbc:ChargeTotalAmount");
331 $result['ChargeTotalAmount'] = ($result['ChargeTotalAmount'] == "") ? 0 : $result['ChargeTotalAmount'];
332 return $result;
333 }
334
335 /**
336 * @brief get the customer info from XML
337 * @return array
338 */
339
340 /**
341 *
342 @code
343 <cac:AllowanceCharge>
344 <cbc:ChargeIndicator>false</cbc:ChargeIndicator>
345 <cbc:AllowanceChargeReasonCode>64</cbc:AllowanceChargeReasonCode>
346 <cbc:AllowanceChargeReason>Conditional cash/payment discount | Korting contant | Escompte Conditionnel 2%</cbc:AllowanceChargeReason>
347 <cbc:Amount currencyID="EUR">4.00</cbc:Amount>
348 <cac:TaxCategory>
349 <cbc:ID>S</cbc:ID>
350 <cbc:Percent>6.00</cbc:Percent>
351 <cac:TaxScheme>
352 <cbc:ID>VAT</cbc:ID>
353 </cac:TaxScheme>
354 </cac:TaxCategory>
355 </cac:AllowanceCharge>
356 @encode
357 */
358 function get_allowance(): array
359 {
360 $result = [];
361 $node=$this->get_node("//cac:AllowanceCharge");
362 if ( $node == null )
363 {
364 return $result;
365 }
366 for ($e = 0; $e < $node->length;$e++)
367 {
368 $row=[];
369 $row['ChargeIndicator'] = $this->get_node_value('//cac:AllowanceCharge/cbc:ChargeIndicator',$e);
370 $row['AllowanceChargeReasonCode'] = $this->get_node_value('//cac:AllowanceCharge/cbc:AllowanceChargeReasonCode',$e);
371 $row['AllowanceChargeReason'] = $this->get_node_value('//cac:AllowanceCharge/cbc:AllowanceChargeReason',$e);
372 $row['amount'] = $this->get_node_value('//cac:AllowanceCharge/cbc:Amount',$e);
373 $row['tva_id'] = $this->get_node_value('//cac:AllowanceCharge/cac:TaxCategory/cbc:ID',$e);
374 $row['tva_percent'] = $this->get_node_value('//cac:AllowanceCharge/cac:TaxCategory/cbc:Percent',$e);
375 $result[]=$row;
376 }
377 return $result;
378 }
379 /**
380 * @brief return the code of the document (cbc:"document"TypeCode)
381 * @return string "document string + cbc:"document"TypeCode"
382 */
383 abstract function get_document_type_code();
384 /**
385 *
386 * @return array
387 * @TODODNY
388 * Implémenter les allowances
389 */
390 function get_info(): array
391 {
392 $result = [];
393 $result['id'] = $this->get_node_value('cbc:ID');
394 $result['IssueDate'] = $this->get_node_value('cbc:IssueDate');
395 $result['DueDate'] = $this->get_node_value('cbc:DueDate');
396 $result['InvoiceTypeCode'] =$this->get_document_type_code();
397 $result['DocumentCurrencyCode'] = $this->get_node_value('cbc:DocumentCurrencyCode');
398 $result['BuyerReference'] = $this->get_node_value('cbc:BuyerReference');
399 $result['ActualDeliveryDate'] = $this->get_node_value('//cac:Delivery[1]/cbc:ActualDeliveryDate[1]');
400 $result['info']=array();
401
402 $result['info']['note']=$this->get_node_value("//cbc:Note");
403 /*
404 <cac:Delivery>
405 <cbc:ActualDeliveryDate>2018-07-01</cbc:ActualDeliveryDate>
406 </cac:Delivery>
407 */
408 return $result;
409 }
410
411 /**
412 * @brief make a PDF with the information from XMLInvoice
413 * @param \Database $cn
414 * @returns \PDF
415 */
416 public function to_pdf(): PDF
417 {
418 //$pdf = new PDF($cn);
419 $pdf = new PDF();
420 $result = $this->get_info();
421 $info=$result;
422 // $pdf->setDossierInfo(_(" id ") . " " . $result['id']);
423 $pdf->AliasNbPages();
424 $pdf->setAuthor("Noalyss");
425 $pdf->AddPage();
426 // 180 mm large
427 $pdf->setFont("DejaVu", "B", 16);
428 $pdf->write_cell(20, 10, "");
429 $pdf->write_cell(170, 10, _("Résumé facture"),1,0,'C');
430 $pdf->line_new(10);
431 $pdf->setFont("DejaVu", "", 7);
432 $pdf->write(4, sprintf(_("Document ID %s"), $result['id']));
433 $pdf->ln();
434 $pdf->write(4, sprintf(_("Date facture %s"), $result['IssueDate']));
435 $pdf->ln();
436 $pdf->write(4, sprintf(_("Date échéance %s"), $result['DueDate']));
437 $pdf->ln();
438 $pdf->write(4, sprintf(_("Type et code document %s"), $result['InvoiceTypeCode']));
439 $pdf->ln();
440 $pdf->write(4, sprintf(_("Devise document %s"), $result['DocumentCurrencyCode']));
441 $pdf->ln();
442 $pdf->write(4, sprintf(_("Référence client %s"), $result['BuyerReference']));
443 $pdf->ln();
444 $pdf->write(4, sprintf(_("Date Livraison %s"), $result['ActualDeliveryDate']));
445 $pdf->ln(10);
446
447 $pdf->setFont("DejaVu", "B", 12);
448 $pdf->write_cell(60, 4, _("Fournisseur"));
449 $pdf->line_new(12);
450 $supplier = $this->get_supplier();
451 $pdf->setFont("DejaVu", "", 7);
452 $pdf->write_cell(60, 4, $supplier['name']);
453 $pdf->write_cell(60, 4, $supplier['company_id']);
454 $pdf->write_cell(60, 4,$supplier['scheme'].":". $supplier['ID']);
455 $pdf->line_new();
456 $pdf->write_cell(60, 4, $supplier['street']);
457 $pdf->write_cell(30, 4, $supplier['postcode']);
458 $pdf->write_cell(60, 4, $supplier['city']);
459 $pdf->write_cell(20, 4, $supplier['country_code']);
460 $pdf->line_new(10);
461
462 $customer = $this->get_customer();
463 $pdf->setFont("DejaVu", "B", 12);
464 $pdf->write_cell(60, 4, _("Client"));
465 $pdf->line_new(10);
466 $pdf->setFont("DejaVu", "", 7);
467 $pdf->write_cell(60, 4, $customer['name']);
468 $pdf->write_cell(60, 4, $customer['company_id']);
469 $pdf->write_cell(60, 4, $customer['scheme'].":".$customer['ID']);
470 $pdf->line_new();
471 $pdf->write_cell(60, 4, $customer['street']);
472 $pdf->write_cell(40, 4, $customer['postcode']);
473 $pdf->write_cell(60, 4, $customer['city']);
474 $pdf->write_cell(20, 4, $customer['country_code']);
475 $pdf->line_new(10);
476 /**
477 * note invoice
478 */
479 if ( $info['info']['note'] != "")
480 {
481 $pdf->setFont("DejaVu", "B", 12);
482 $pdf->write_cell(60, 4, _("Notes"));
483 $pdf->line_new(10);
484 $pdf->setFont("DejaVu", "", 7);
485 $pdf->write_multi(50, 4,$info['info']['note']);
486 $pdf->line_new(10);
487 }
488 /**
489 * ITEM
490 */
491 $pdf->setFont("DejaVu", "B", 12);
492 $pdf->write_cell(60, 4, _("Articles"));
493 $pdf->line_new(10);
494 $pdf->setFont("DejaVu", "", 7);
495 $result = $this->get_invoiceLine();
496 $pdf->write_cell(50, 4, _("Code"), border: 'B');
497 $pdf->write_cell(50, 4, _("Description"), border: 'B');
498 $pdf->write_cell(30, 4, _("TVA"), border: 'B', align: 'R');
499 $pdf->write_cell(25, 4, _("Quantité"), border: 'B', align: 'R');
500 $pdf->write_cell(25, 4, _("Montant HT"), border: 'B', align: 'R');
501 $pdf->line_new();
502
503 $nb_inline = count($result);
504 for ($i = 0; $i < $nb_inline; $i++)
505 {
506 $pdf->write_multi(50, 4, $result[$i]['name']);
507 $pdf->write_multi(50, 4, $result[$i]['description']);
508 $pdf->write_cell(25, 4, $result[$i]['tva_percent'], align: 'R');
509 $pdf->write_cell(5, 4, $result[$i]['tva_id']);
510 $pdf->write_cell(25, 4, $result[$i]['quantity'], align: 'R');
511 $pdf->write_cell(25, 4, nbm($result[$i]['amount']), align: 'R');
512 $pdf->line_new();
513 }
514 $pdf->line_new(10);
515
516 $pdf->setFont("DejaVu", "B", 12);
517 $pdf->write_cell(60, 4, _("Totaux"));
518 $pdf->line_new(10);
519 $pdf->setFont("DejaVu", "", 7);
520 $result = $this->get_amount_summary();
521// @TODO DNY : Qu'est-ce que LineExtension Amount ??
522 $pdf->write_cell(50, 4, _("Base taxe"));
523 $pdf->write_cell(50, 4, nbm($result['LineExtensionAmount']),align:'R');
524 $pdf->line_new();
525 $pdf->write_cell(50, 4, _("Total Hors Taxe"));
526 $pdf->write_cell(50, 4, nbm($result['TaxExclusiveAmount']),align:'R');
527 $pdf->line_new();
528 $pdf->write_cell(50, 4, _("Total avec Taxe"));
529 $pdf->write_cell(50, 4, nbm($result['TaxInclusiveAmount']),align:'R');
530 $pdf->line_new();
531 $pdf->write_cell(50, 4, _("Total à payer"));
532 $pdf->write_cell(50, 4, nbm($result['PayableAmount']),align:'R');
533 $pdf->line_new();
534 $pdf->write_cell(50, 4, _("Total réduction"));
535 $pdf->write_cell(50, 4, nbm($result['AllowanceTotalAmount']),align:'R');
536 $pdf->line_new();
537 $pdf->write_cell(50, 4, _("Total charge"));
538 $pdf->write_cell(50, 4, nbm($result['ChargeTotalAmount']),align:'R');
539 $pdf->line_new(10);
540 $result=$this->get_allowance();
541 $nb_inline = count($result);
542 if ( !empty ($result ))
543 {
544 $pdf->setFont("DejaVu", "B", 12);
545 $pdf->write_cell(60, 4, _("Charge et déduction"));
546 $pdf->line_new(10);
547 $pdf->setFont("DejaVu", "", 7);
548 $pdf->write_cell(20, 4, _("code"), align: 'L', border: '1');
549 $pdf->write_cell(20, 4, _("Type"), border: '1');
550 $pdf->write_cell(55, 4, _("Raison"), align: 'L', border: '1');
551 $pdf->write_cell(30, 4, _("Montant"), align: 'R', border: '1');
552 $pdf->write_cell(30, 4, _("TVA"), align: 'L', border: '1');
553 $pdf->line_new();
554 for ($i = 0; $i < $nb_inline; $i++)
555 {
556 $pdf->write_cell(20, 4, $result[$i]['AllowanceChargeReasonCode'], align: 'L');
557 if ( $result[$i]['ChargeIndicator'] == 'false')
558 {
559 $pdf->write_cell(20, 4, _("Déduction"), align: 'L');
560
561 }else{
562 $pdf->write_cell(20, 4, _("Charge suppl."), align: 'L');
563
564 }
565 $pdf->write_cell(55, 4, $result[$i]['AllowanceChargeReason'], align: 'L');
566 $pdf->write_cell(30, 4,nbm( $result[$i]['amount']), align: 'R');
567 $pdf->write_cell(5, 4, $result[$i]['tva_id']);
568 $pdf->write_cell(25, 4, $result[$i]['tva_percent'], align: 'R');
569
570 $pdf->line_new();
571 }
572 }
573 $pdf->setFont("DejaVu", "B", 12);
574 $pdf->write_cell(60, 4, _("TVA"));
575 $pdf->line_new(10);
576 $pdf->setFont("DejaVu", "", 7);
577 $result = $this->get_taxes();
578 $pdf->write_cell(25, 4, _("% Taxe"), align: 'R', border: 'B');
579 $pdf->write_cell(5, 4, _("Code taxe"), border: 'B');
580 $pdf->write_cell(50, 4, _("Base"), align: 'R', border: 'B');
581 $pdf->write_cell(50, 4, _("Taxe"), align: 'R', border: 'B');
582 $pdf->line_new();
583 $nb_inline = count($result);
584 for ($i = 0; $i < $nb_inline; $i++)
585 {
586 $pdf->write_cell(25, 4, $result[$i]['tax_percent'], align: 'R');
587 $pdf->write_cell(5, 4, $result[$i]['tax_id']);
588 $pdf->write_cell(25, 4, $result[$i]['vatex']);
589 $pdf->write_cell(50, 4, nbm($result[$i]['taxable_amount']), align: 'R');
590 $pdf->write_cell(50, 4, nbm($result[$i]['tax']), align: 'R');
591
592 $pdf->line_new();
593 }
594 $pdf->line_new(10);
595
596
597 $pdf->setFont("DejaVu", "B", 12);
598 $pdf->write_cell(60, 4, _("Paiement"));
599 $pdf->line_new(10);
600 $pdf->setFont("DejaVu", "", 7);
601 $result = $this->get_payment_mean();
602 $pdf->write_cell(50, 4, _("Code"));
603 $pdf->write_cell(50, 4, $result['payment_code']);
604 $pdf->line_new();
605 $pdf->write_cell(50, 4, _("IBAN"));
606 $pdf->write_cell(50, 4, $result['iban']);
607 $pdf->line_new();
608 $pdf->write_cell(50, 4, _("BIC"));
609 $pdf->write_cell(50, 4, $result['bic']);
610 $pdf->line_new();
611 $pdf->write_cell(50, 4, _("Communication"));
612 $pdf->write_cell(50, 4, $result['label']);
613 $pdf->line_new();
614 $nb_note = count($result['note']);
615 for ($i = 0; $i < $nb_note; $i++)
616 {
617 $pdf->write_cell(40, 4, _("note") . " " . $i);
618 $pdf->write_multi(140, 4, str_replace(["\n", "\r", "\t"], " ", $result['note'][$i]));
619 $pdf->line_new();
620 }
621 /**
622 * display name of embedded from files
623 * @var $result(array of Document_Reference)
624 */
625 $result=$this->get_embedded_document();
626 if ( count($result) > 0)
627 {
628 $pdf->setFont("DejaVu", "B", 12);
629 $pdf->write_cell(60,4,_('Documents inclus'));
630 $pdf->line_new();
631 $pdf->setFont("DejaVu", "", 7);
632 $nb_result=count($result);
633 for ($i=0;$i< $nb_result;$i++)
634 {
635 $binary=$result[$i]->getBinary_object();
636 $pdf->write_multi(50,4,$result[$i]->getId());
637 $pdf->write_multi(50,4,$binary->filename);
638 $pdf->write_multi(50,4,$result[$i]->getDescription());
639 $pdf->line_new();
640
641 }
642
643 }
644 return $pdf;
645 }
646}
nbm($p_number, $p_dec=2)
format the number with a sep.
$note
display input textarea for operation note
switch($op2) $xml
for( $i=0;$i< $nb_match;$i++) if(empty($result)) $nb_result
_("actif, passif,charge,...")
if( $delta< 0) elseif( $delta==0)