1
|
|
|
<?php |
2
|
|
|
/* Copyright (C) 2004-2014 Laurent Destailleur <[email protected]> |
3
|
|
|
* Copyright (C) 2005-2012 Regis Houssin <[email protected]> |
4
|
|
|
* Copyright (C) 2008 Raphael Bertrand <[email protected]> |
5
|
|
|
* Copyright (C) 2010-2013 Juanjo Menent <[email protected]> |
6
|
|
|
* Copyright (C) 2012 Christophe Battarel <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This program 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 3 of the License, or |
11
|
|
|
* (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
* or see http://www.gnu.org/ |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* \file htdocs/core/modules/commande/doc/pdf_einstein.modules.php |
25
|
|
|
* \ingroup commande |
26
|
|
|
* \brief Fichier de la classe permettant de generer les commandes au modele Einstein |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
require_once DOL_DOCUMENT_ROOT .'/core/modules/commande/modules_commande.php'; |
30
|
|
|
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
31
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
32
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
33
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Classe permettant de generer les commandes au modele Einstein |
38
|
|
|
*/ |
39
|
|
|
class pdf_einstein_subtotal extends ModelePDFCommandes |
40
|
|
|
{ |
41
|
|
|
var $db; |
42
|
|
|
var $name; |
43
|
|
|
var $description; |
44
|
|
|
var $type; |
45
|
|
|
|
46
|
|
|
var $phpmin = array(4,3,0); // Minimum version of PHP required by module |
47
|
|
|
var $version = 'dolibarr'; |
48
|
|
|
|
49
|
|
|
var $page_largeur; |
50
|
|
|
var $page_hauteur; |
51
|
|
|
var $format; |
52
|
|
|
var $marge_gauche; |
53
|
|
|
var $marge_droite; |
54
|
|
|
var $marge_haute; |
55
|
|
|
var $marge_basse; |
56
|
|
|
|
57
|
|
|
var $emetteur; // Objet societe qui emet |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Constructor |
62
|
|
|
* |
63
|
|
|
* @param DoliDB $db Database handler |
64
|
|
|
*/ |
65
|
|
|
function __construct($db) |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
global $conf,$langs,$mysoc; |
68
|
|
|
|
69
|
|
|
$langs->load("main"); |
70
|
|
|
$langs->load("bills"); |
71
|
|
|
|
72
|
|
|
$this->db = $db; |
73
|
|
|
$this->name = "einstein_subtotal"; |
74
|
|
|
// J'ajoute l'annotation "déprécié" mais à garder... des fois qu'un client avec une vieille version utilise les modèles PDF custom |
75
|
|
|
$this->description = 'Modèle de commande incluant des spécificités du module sous-total. (déprécié)'; |
76
|
|
|
|
77
|
|
|
// Dimension page pour format A4 |
78
|
|
|
$this->type = 'pdf'; |
79
|
|
|
$formatarray=pdf_getFormat(); |
80
|
|
|
$this->page_largeur = $formatarray['width']; |
81
|
|
|
$this->page_hauteur = $formatarray['height']; |
82
|
|
|
$this->format = array($this->page_largeur,$this->page_hauteur); |
83
|
|
|
$this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10; |
84
|
|
|
$this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10; |
85
|
|
|
$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10; |
86
|
|
|
$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10; |
87
|
|
|
|
88
|
|
|
$this->option_logo = 1; // Affiche logo |
|
|
|
|
89
|
|
|
$this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION |
|
|
|
|
90
|
|
|
$this->option_modereg = 1; // Affiche mode reglement |
|
|
|
|
91
|
|
|
$this->option_condreg = 1; // Affiche conditions reglement |
|
|
|
|
92
|
|
|
$this->option_codeproduitservice = 1; // Affiche code produit-service |
|
|
|
|
93
|
|
|
$this->option_multilang = 1; // Dispo en plusieurs langues |
|
|
|
|
94
|
|
|
$this->option_escompte = 0; // Affiche si il y a eu escompte |
|
|
|
|
95
|
|
|
$this->option_credit_note = 0; // Support credit notes |
|
|
|
|
96
|
|
|
$this->option_freetext = 1; // Support add of a personalised text |
|
|
|
|
97
|
|
|
$this->option_draft_watermark = 1; // Support add of a watermark on drafts |
|
|
|
|
98
|
|
|
|
99
|
|
|
$this->franchise=!$mysoc->tva_assuj; |
|
|
|
|
100
|
|
|
|
101
|
|
|
// Get source company |
102
|
|
|
$this->emetteur=$mysoc; |
103
|
|
|
if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if was not defined |
104
|
|
|
|
105
|
|
|
// Define position of columns |
106
|
|
|
$this->posxdesc=$this->marge_gauche+1; |
|
|
|
|
107
|
|
|
$this->posxtva=112; |
|
|
|
|
108
|
|
|
$this->posxup=126; |
|
|
|
|
109
|
|
|
$this->posxqty=145; |
|
|
|
|
110
|
|
|
$this->posxdiscount=162; |
|
|
|
|
111
|
|
|
$this->postotalht=174; |
|
|
|
|
112
|
|
|
if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) $this->posxtva=$this->posxup; |
113
|
|
|
$this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images |
|
|
|
|
114
|
|
|
if ($this->page_largeur < 210) // To work with US executive format |
115
|
|
|
{ |
116
|
|
|
$this->posxpicture-=20; |
117
|
|
|
$this->posxtva-=20; |
118
|
|
|
$this->posxup-=20; |
119
|
|
|
$this->posxqty-=20; |
120
|
|
|
$this->posxdiscount-=20; |
121
|
|
|
$this->postotalht-=20; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
$this->tva=array(); |
|
|
|
|
125
|
|
|
$this->localtax1=array(); |
|
|
|
|
126
|
|
|
$this->localtax2=array(); |
|
|
|
|
127
|
|
|
$this->atleastoneratenotnull=0; |
|
|
|
|
128
|
|
|
$this->atleastonediscount=0; |
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Function to build pdf onto disk |
133
|
|
|
* |
134
|
|
|
* @param Object $object Object to generate |
135
|
|
|
* @param Translate $outputlangs Lang output object |
136
|
|
|
* @param string $srctemplatepath Full path of source filename for generator using a template file |
137
|
|
|
* @param int $hidedetails Do not show line details |
138
|
|
|
* @param int $hidedesc Do not show desc |
139
|
|
|
* @param int $hideref Do not show ref |
140
|
|
|
* @return int 1=OK, 0=KO |
141
|
|
|
*/ |
142
|
|
|
function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) |
|
|
|
|
143
|
|
|
{ |
144
|
|
|
global $user,$langs,$conf,$mysoc,$db,$hookmanager; |
145
|
|
|
|
146
|
|
|
if (! is_object($outputlangs)) $outputlangs=$langs; |
147
|
|
|
// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO |
148
|
|
|
if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; |
149
|
|
|
|
150
|
|
|
$outputlangs->load("main"); |
151
|
|
|
$outputlangs->load("dict"); |
152
|
|
|
$outputlangs->load("companies"); |
153
|
|
|
$outputlangs->load("bills"); |
154
|
|
|
$outputlangs->load("products"); |
155
|
|
|
$outputlangs->load("orders"); |
156
|
|
|
$outputlangs->load("deliveries"); |
157
|
|
|
|
158
|
|
|
$nblignes = count($object->lines); |
159
|
|
|
|
160
|
|
|
if ($conf->commande->dir_output) |
161
|
|
|
{ |
162
|
|
|
$object->fetch_thirdparty(); |
163
|
|
|
if(!empty($object->client) ){ |
164
|
|
|
$object->thirdparty = $object->client; |
165
|
|
|
} |
166
|
|
|
$deja_regle = ""; |
167
|
|
|
|
168
|
|
|
// Definition of $dir and $file |
169
|
|
|
if ($object->specimen) |
170
|
|
|
{ |
171
|
|
|
$dir = $conf->commande->dir_output; |
172
|
|
|
$file = $dir . "/SPECIMEN.pdf"; |
173
|
|
|
} |
174
|
|
|
else |
175
|
|
|
{ |
176
|
|
|
$objectref = dol_sanitizeFileName($object->ref); |
177
|
|
|
$dir = $conf->commande->dir_output . "/" . $objectref; |
178
|
|
|
$file = $dir . "/" . $objectref . ".pdf"; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
if (! file_exists($dir)) |
182
|
|
|
{ |
183
|
|
|
if (dol_mkdir($dir) < 0) |
184
|
|
|
{ |
185
|
|
|
$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
186
|
|
|
return 0; |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
if (file_exists($dir)) |
191
|
|
|
{ |
192
|
|
|
// Add pdfgeneration hook |
193
|
|
|
if (! is_object($hookmanager)) |
194
|
|
|
{ |
195
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
196
|
|
|
$hookmanager=new HookManager($this->db); |
197
|
|
|
} |
198
|
|
|
$hookmanager->initHooks(array('pdfgeneration')); |
199
|
|
|
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); |
200
|
|
|
global $action; |
201
|
|
|
$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
|
|
|
202
|
|
|
|
203
|
|
|
// Create pdf instance |
204
|
|
|
$pdf=pdf_getInstance($this->format); |
|
|
|
|
205
|
|
|
$default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance |
206
|
|
|
$heightforinfotot = 50; // Height reserved to output the info and total part |
207
|
|
|
$heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5); // Height reserved to output the free text on last page |
208
|
|
|
$heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) |
209
|
|
|
$pdf->SetAutoPageBreak(1,0); |
210
|
|
|
|
211
|
|
|
if (class_exists('TCPDF')) |
212
|
|
|
{ |
213
|
|
|
$pdf->setPrintHeader(false); |
214
|
|
|
$pdf->setPrintFooter(false); |
215
|
|
|
} |
216
|
|
|
$pdf->SetFont(pdf_getPDFFont($outputlangs)); |
217
|
|
|
// Set path to the background PDF File |
218
|
|
|
if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) |
219
|
|
|
{ |
220
|
|
|
$pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); |
|
|
|
|
221
|
|
|
$tplidx = $pdf->importPage(1); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
$pdf->Open(); |
225
|
|
|
$pagenb=0; |
226
|
|
|
$pdf->SetDrawColor(128,128,128); |
227
|
|
|
|
228
|
|
|
$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); |
229
|
|
|
$pdf->SetSubject($outputlangs->transnoentities("Order")); |
230
|
|
|
$pdf->SetCreator("Dolibarr ".DOL_VERSION); |
231
|
|
|
$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); |
232
|
|
|
$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order")); |
233
|
|
|
if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); |
234
|
|
|
|
235
|
|
|
$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right |
236
|
|
|
|
237
|
|
|
// Positionne $this->atleastonediscount si on a au moins une remise |
238
|
|
|
for ($i = 0 ; $i < $nblignes ; $i++) |
239
|
|
|
{ |
240
|
|
|
if ($object->lines[$i]->remise_percent) |
241
|
|
|
{ |
242
|
|
|
$this->atleastonediscount++; |
243
|
|
|
} |
244
|
|
|
} |
245
|
|
|
if (empty($this->atleastonediscount)) |
246
|
|
|
{ |
247
|
|
|
$this->posxpicture+=($this->postotalht - $this->posxdiscount); |
248
|
|
|
$this->posxtva+=($this->postotalht - $this->posxdiscount); |
249
|
|
|
$this->posxup+=($this->postotalht - $this->posxdiscount); |
250
|
|
|
$this->posxqty+=($this->postotalht - $this->posxdiscount); |
251
|
|
|
$this->posxdiscount+=($this->postotalht - $this->posxdiscount); |
252
|
|
|
//$this->postotalht; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
// New page |
256
|
|
|
$pdf->AddPage(); |
257
|
|
|
if (! empty($tplidx)) $pdf->useTemplate($tplidx); |
258
|
|
|
$pagenb++; |
259
|
|
|
$this->_pagehead($pdf, $object, 1, $outputlangs); |
260
|
|
|
$pdf->SetFont('','', $default_font_size - 1); |
261
|
|
|
$pdf->MultiCell(0, 3, ''); // Set interline to 3 |
262
|
|
|
$pdf->SetTextColor(0,0,0); |
263
|
|
|
|
264
|
|
|
|
265
|
|
|
$tab_top = 90; |
266
|
|
|
$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10); |
267
|
|
|
$tab_height = 130; |
268
|
|
|
$tab_height_newpage = 150; |
|
|
|
|
269
|
|
|
|
270
|
|
|
// Affiche notes |
271
|
|
|
$notetoshow=empty($object->note_public)?'':$object->note_public; |
272
|
|
|
if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) |
273
|
|
|
{ |
274
|
|
|
// Get first sale rep |
275
|
|
|
if (is_object($object->thirdparty)) |
276
|
|
|
{ |
277
|
|
|
$salereparray=$object->thirdparty->getSalesRepresentatives($user); |
278
|
|
|
$salerepobj=new User($this->db); |
279
|
|
|
$salerepobj->fetch($salereparray[0]['id']); |
280
|
|
|
if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature); |
281
|
|
|
} |
282
|
|
|
} |
283
|
|
|
if ($notetoshow) |
284
|
|
|
{ |
285
|
|
|
$tab_top = 88; |
286
|
|
|
|
287
|
|
|
$pdf->SetFont('','', $default_font_size - 1); |
288
|
|
|
$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1); |
289
|
|
|
$nexY = $pdf->GetY(); |
290
|
|
|
$height_note=$nexY-$tab_top; |
291
|
|
|
|
292
|
|
|
// Rect prend une longueur en 3eme param |
293
|
|
|
$pdf->SetDrawColor(192,192,192); |
294
|
|
|
$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1); |
295
|
|
|
|
296
|
|
|
$tab_height = $tab_height - $height_note; |
|
|
|
|
297
|
|
|
$tab_top = $nexY+6; |
298
|
|
|
} |
299
|
|
|
else |
300
|
|
|
{ |
301
|
|
|
$height_note=0; |
|
|
|
|
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
$iniY = $tab_top + 7; |
|
|
|
|
305
|
|
|
$curY = $tab_top + 7; |
|
|
|
|
306
|
|
|
$nexY = $tab_top + 7; |
307
|
|
|
|
308
|
|
|
$inPackage = false; |
|
|
|
|
309
|
|
|
$TPackageInfos = array(); |
|
|
|
|
310
|
|
|
$TChilds = array(); |
|
|
|
|
311
|
|
|
$package_qty = 0; |
|
|
|
|
312
|
|
|
$TStack = array(); |
313
|
|
|
|
314
|
|
|
// Loop on each lines |
315
|
|
|
for ($i = 0 ; $i < $nblignes ; $i++) |
316
|
|
|
{ |
317
|
|
|
$package_qty = $TStack[count($TStack) - 1]['package_qty']; |
318
|
|
|
$inPackage = count($TStack) > 0; |
319
|
|
|
|
320
|
|
|
// Ligne de titre |
321
|
|
|
if ($object->lines[$i]->product_type == 9 && $object->lines[$i]->qty < 97 && $object->lines[$i]->fk_product > 0) { |
322
|
|
|
$inPackage = true; |
323
|
|
|
|
324
|
|
|
if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES) { |
325
|
|
|
if (!empty($object->lines[$i]->fk_product)) { |
326
|
|
|
$product = new Product($db); |
327
|
|
|
$product->fetch($object->lines[$i]->fk_product); |
328
|
|
|
|
329
|
|
|
$TChilds = $product->getChildsArbo($product->id); |
330
|
|
|
|
331
|
|
|
$TStack[count($TStack)] = array( |
332
|
|
|
'childs' => $TChilds, |
333
|
|
|
'package' => array(), |
334
|
|
|
'package_qty' => 0 |
335
|
|
|
); |
336
|
|
|
|
337
|
|
|
// Si on se trouvait déjà dans un package, on rajoute ce produit à la liste des produits |
338
|
|
|
// du précédent package |
339
|
|
|
if (count($TStack) > 1) { |
340
|
|
|
$TStack[count($TStack) - 2]['package'][$object->lines[$i]->fk_product] += $object->lines[$i]->qty; |
341
|
|
|
} |
342
|
|
|
} |
343
|
|
|
} |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES) { |
347
|
|
|
if ($inPackage && $object->lines[$i]->product_type != 9 && $object->lines[$i]->fk_product > 0) { |
348
|
|
|
$TStack[count($TStack) - 1]['package'][$object->lines[$i]->fk_product] += $object->lines[$i]->qty; |
349
|
|
|
} |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
// Ligne de sous-total |
353
|
|
|
if ($inPackage && $object->lines[$i]->product_type == 9 && $object->lines[$i]->qty >= 97) { |
354
|
|
|
if (count($TStack) <= 1) { |
355
|
|
|
$inPackage = false; |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES) { |
359
|
|
|
// Comparaison pour déterminer la quantité de package |
360
|
|
|
$TProducts = array_keys($TStack[count($TStack) - 1]['package']); |
361
|
|
|
$TProductsChilds = array_keys($TStack[count($TStack) - 1]['childs']); |
362
|
|
|
|
363
|
|
|
if ($TProductsChilds == $TProducts) { |
364
|
|
|
// Il s'agit d'un package |
365
|
|
|
// On récupére la quantité |
366
|
|
|
$first_child_id = $TProducts[0]; |
367
|
|
|
$document_qty = $TStack[count($TStack) - 1]['package'][$first_child_id]; |
368
|
|
|
$base_qty = $TStack[count($TStack) - 1]['childs'][$first_child_id][1]; |
369
|
|
|
|
370
|
|
|
$TStack[count($TStack) - 1]['package_qty'] = $document_qty / $base_qty; |
371
|
|
|
$package_qty = $TStack[count($TStack) - 1]['package_qty']; |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
array_pop($TStack); |
375
|
|
|
} |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
$curY = $nexY; |
379
|
|
|
$pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage |
380
|
|
|
$pdf->SetTextColor(0,0,0); |
381
|
|
|
|
382
|
|
|
$pdf->setTopMargin($tab_top_newpage); |
383
|
|
|
$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. |
384
|
|
|
$pageposbefore=$pdf->getPage(); |
385
|
|
|
|
386
|
|
|
// Description of product line |
387
|
|
|
$curX = $this->posxdesc-1; |
388
|
|
|
|
389
|
|
|
$showpricebeforepagebreak=1; |
390
|
|
|
|
391
|
|
|
$pdf->startTransaction(); |
392
|
|
|
pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc); |
393
|
|
|
$pageposafter=$pdf->getPage(); |
394
|
|
|
if ($pageposafter > $pageposbefore) // There is a pagebreak |
395
|
|
|
{ |
396
|
|
|
$pdf->rollbackTransaction(true); |
397
|
|
|
$pageposafter=$pageposbefore; |
|
|
|
|
398
|
|
|
//print $pageposafter.'-'.$pageposbefore;exit; |
399
|
|
|
$pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. |
400
|
|
|
pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc); |
401
|
|
|
$pageposafter=$pdf->getPage(); |
402
|
|
|
$posyafter=$pdf->GetY(); |
403
|
|
|
if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text |
404
|
|
|
{ |
405
|
|
|
if ($i == ($nblignes-1)) // No more lines, and no space left to show total, so we create a new page |
406
|
|
|
{ |
407
|
|
|
$pdf->AddPage('','',true); |
408
|
|
|
if (! empty($tplidx)) $pdf->useTemplate($tplidx); |
409
|
|
|
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); |
410
|
|
|
$pdf->setPage($pageposafter+1); |
411
|
|
|
} |
412
|
|
|
} |
413
|
|
|
else |
414
|
|
|
{ |
415
|
|
|
// We found a page break |
416
|
|
|
$showpricebeforepagebreak=0; |
417
|
|
|
} |
418
|
|
|
} |
419
|
|
|
else // No pagebreak |
420
|
|
|
{ |
421
|
|
|
$pdf->commitTransaction(); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
$nexY = $pdf->GetY(); |
425
|
|
|
$pageposafter=$pdf->getPage(); |
426
|
|
|
$pdf->setPage($pageposbefore); |
427
|
|
|
$pdf->setTopMargin($this->marge_haute); |
428
|
|
|
$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. |
429
|
|
|
|
430
|
|
|
// We suppose that a too long description is moved completely on next page |
431
|
|
|
if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { |
432
|
|
|
$pdf->setPage($pageposafter); $curY = $tab_top_newpage; |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
$pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut |
436
|
|
|
|
437
|
|
|
// VAT Rate |
438
|
|
|
if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) |
439
|
|
|
{ |
440
|
|
|
// Si on ne doit masquer que les sous-produits |
441
|
|
|
if ($hidedetails && !$inPackage && $conf->global->SUBTOTAL_ONLY_HIDE_SUBPRODUCTS_PRICES) { |
442
|
|
|
$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, 0); |
443
|
|
|
} else { |
444
|
|
|
$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails); |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
$pdf->SetXY($this->posxtva, $curY); |
448
|
|
|
$pdf->MultiCell($this->posxup-$this->posxtva-0.8, 3, $vat_rate, 0, 'R'); |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
// Unit price before discount |
452
|
|
|
if ($hidedetails && !$inPackage && $conf->global->SUBTOTAL_ONLY_HIDE_SUBPRODUCTS_PRICES) { |
453
|
|
|
$up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, 0); |
454
|
|
|
} else { |
455
|
|
|
$up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails); |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
$pdf->SetXY($this->posxup, $curY); |
459
|
|
|
$pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0); |
460
|
|
|
|
461
|
|
|
// Booléen pour déterminer s'il s'agit d'une ligne de titre ou non |
462
|
|
|
$isTitle = false; |
|
|
|
|
463
|
|
|
|
464
|
|
|
// Quantity |
465
|
|
|
// Récupération de la quantité à afficher |
466
|
|
|
if ($conf->global->SUBTOTAL_IF_HIDE_PRICES_SHOW_QTY) { |
467
|
|
|
if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES && $package_qty > 0) { |
468
|
|
|
$qty = $package_qty; |
469
|
|
|
} else { |
470
|
|
|
$qty = pdf_getlineqty($object, $i, $outputlangs, 0); |
471
|
|
|
} |
472
|
|
|
} else { |
473
|
|
|
if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES && $package_qty > 0) { |
474
|
|
|
$qty = $package_qty; |
475
|
|
|
} else { |
476
|
|
|
$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails); |
477
|
|
|
} |
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
$pdf->SetXY($this->posxqty, $curY); |
481
|
|
|
$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 3, $qty, 0, 'R'); // Enough for 6 chars |
482
|
|
|
|
483
|
|
|
// Discount on line |
484
|
|
|
if ($object->lines[$i]->remise_percent) |
485
|
|
|
{ |
486
|
|
|
$pdf->SetXY($this->posxdiscount-2, $curY); |
487
|
|
|
$remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails); |
488
|
|
|
$pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R'); |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
// Total HT line |
492
|
|
|
if ($hidedetails && !$inPackage && $conf->global->SUBTOTAL_ONLY_HIDE_SUBPRODUCTS_PRICES) { |
493
|
|
|
$total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, 0); |
494
|
|
|
} else { |
495
|
|
|
$total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails); |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
$pdf->SetXY($this->postotalht, $curY); |
499
|
|
|
$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0); |
500
|
|
|
|
501
|
|
|
// Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva |
502
|
|
|
$tvaligne=doubleval($object->lines[$i]->total_tva); |
503
|
|
|
|
504
|
|
|
$localtax1ligne=$object->lines[$i]->total_localtax1; |
505
|
|
|
$localtax2ligne=$object->lines[$i]->total_localtax2; |
506
|
|
|
$localtax1_rate=$object->lines[$i]->localtax1_tx; |
507
|
|
|
$localtax2_rate=$object->lines[$i]->localtax2_tx; |
508
|
|
|
$localtax1_type=$object->lines[$i]->localtax1_type; |
509
|
|
|
$localtax2_type=$object->lines[$i]->localtax2_type; |
510
|
|
|
|
511
|
|
|
if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100; |
512
|
|
|
if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100; |
513
|
|
|
if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100; |
514
|
|
|
|
515
|
|
|
$vatrate=(string) $object->lines[$i]->tva_tx; |
516
|
|
|
|
517
|
|
|
// Retrieve type from database for backward compatibility with old records |
518
|
|
|
if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined |
519
|
|
|
&& (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax |
520
|
|
|
{ |
521
|
|
|
$localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc); |
522
|
|
|
$localtax1_type = $localtaxtmp_array[0]; |
523
|
|
|
$localtax2_type = $localtaxtmp_array[2]; |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
// retrieve global local tax |
527
|
|
|
if ($localtax1_type && $localtax1ligne != 0) |
528
|
|
|
$this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne; |
529
|
|
|
if ($localtax2_type && $localtax2ligne != 0) |
530
|
|
|
$this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne; |
531
|
|
|
|
532
|
|
|
if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*'; |
533
|
|
|
if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]=0; |
|
|
|
|
534
|
|
|
|
535
|
|
|
if (!empty($object->lines[$i]->TTotal_tva)) |
536
|
|
|
{ |
537
|
|
|
foreach ($object->lines[$i]->TTotal_tva as $vatrate => $tvaligne) |
538
|
|
|
{ |
539
|
|
|
$this->tva[$vatrate] += $tvaligne; |
540
|
|
|
} |
541
|
|
|
} |
542
|
|
|
else { |
543
|
|
|
// standard |
544
|
|
|
if(!empty($tvaligne)) $this->tva[$vatrate] += $tvaligne; |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
// Add line |
548
|
|
|
if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1)) |
549
|
|
|
{ |
550
|
|
|
$pdf->setPage($pageposafter); |
551
|
|
|
$pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(210,210,210))); |
552
|
|
|
//$pdf->SetDrawColor(190,190,200); |
553
|
|
|
$pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1); |
554
|
|
|
$pdf->SetLineStyle(array('dash'=>0)); |
555
|
|
|
} |
556
|
|
|
|
557
|
|
|
$nexY+=2; // Passe espace entre les lignes |
558
|
|
|
|
559
|
|
|
// Detect if some page were added automatically and output _tableau for past pages |
560
|
|
|
while ($pagenb < $pageposafter) |
561
|
|
|
{ |
562
|
|
|
$pdf->setPage($pagenb); |
563
|
|
|
if ($pagenb == 1) |
564
|
|
|
{ |
565
|
|
|
$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); |
566
|
|
|
} |
567
|
|
|
else |
568
|
|
|
{ |
569
|
|
|
$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); |
570
|
|
|
} |
571
|
|
|
$this->_pagefoot($pdf,$object,$outputlangs,1); |
572
|
|
|
$pagenb++; |
573
|
|
|
$pdf->setPage($pagenb); |
574
|
|
|
$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. |
575
|
|
|
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); |
576
|
|
|
} |
577
|
|
|
if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak) |
578
|
|
|
{ |
579
|
|
|
if ($pagenb == 1) |
580
|
|
|
{ |
581
|
|
|
$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); |
582
|
|
|
} |
583
|
|
|
else |
584
|
|
|
{ |
585
|
|
|
$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); |
586
|
|
|
} |
587
|
|
|
$this->_pagefoot($pdf,$object,$outputlangs,1); |
588
|
|
|
// New page |
589
|
|
|
$pdf->AddPage(); |
590
|
|
|
if (! empty($tplidx)) $pdf->useTemplate($tplidx); |
591
|
|
|
$pagenb++; |
592
|
|
|
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); |
593
|
|
|
} |
594
|
|
|
} |
595
|
|
|
|
596
|
|
|
// Show square |
597
|
|
|
if ($pagenb == 1) |
598
|
|
|
{ |
599
|
|
|
$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); |
600
|
|
|
$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; |
601
|
|
|
} |
602
|
|
|
else |
603
|
|
|
{ |
604
|
|
|
$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); |
605
|
|
|
$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
// Affiche zone infos |
609
|
|
|
$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs); |
|
|
|
|
610
|
|
|
|
611
|
|
|
if (!$conf->global->SUBTOTAL_HIDE_DOCUMENT_TOTAL) { |
612
|
|
|
// Affiche zone totaux |
613
|
|
|
$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs); |
|
|
|
|
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
// Affiche zone versements |
617
|
|
|
if ($deja_regle) |
618
|
|
|
{ |
619
|
|
|
$posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs); |
|
|
|
|
620
|
|
|
} |
621
|
|
|
|
622
|
|
|
// Pied de page |
623
|
|
|
$this->_pagefoot($pdf,$object,$outputlangs); |
624
|
|
|
if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages(); |
625
|
|
|
|
626
|
|
|
$pdf->Close(); |
627
|
|
|
|
628
|
|
|
$pdf->Output($file,'F'); |
629
|
|
|
|
630
|
|
|
// Add pdfgeneration hook |
631
|
|
|
$hookmanager->initHooks(array('pdfgeneration')); |
632
|
|
|
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); |
633
|
|
|
global $action; |
634
|
|
|
$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
635
|
|
|
|
636
|
|
|
if (! empty($conf->global->MAIN_UMASK)) |
637
|
|
|
@chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
|
|
|
638
|
|
|
|
639
|
|
|
return 1; // Pas d'erreur |
640
|
|
|
} |
641
|
|
|
else |
642
|
|
|
{ |
643
|
|
|
$this->error=$langs->trans("ErrorCanNotCreateDir",$dir); |
644
|
|
|
return 0; |
645
|
|
|
} |
646
|
|
|
} |
647
|
|
|
else |
648
|
|
|
{ |
649
|
|
|
$this->error=$langs->trans("ErrorConstantNotDefined","COMMANDE_OUTPUTDIR"); |
650
|
|
|
return 0; |
651
|
|
|
} |
652
|
|
|
$this->error=$langs->trans("ErrorUnknown"); |
|
|
|
|
653
|
|
|
return 0; // Erreur par defaut |
654
|
|
|
} |
655
|
|
|
|
656
|
|
|
/** |
657
|
|
|
* Show payments table |
658
|
|
|
* |
659
|
|
|
* @param PDF $pdf Object PDF |
660
|
|
|
* @param Object $object Object order |
661
|
|
|
* @param int $posy Position y in PDF |
662
|
|
|
* @param Translate $outputlangs Object langs for output |
663
|
|
|
* @return int <0 if KO, >0 if OK |
664
|
|
|
*/ |
665
|
|
|
function _tableau_versements(&$pdf, $object, $posy, $outputlangs) |
|
|
|
|
666
|
|
|
{ |
667
|
|
|
|
668
|
|
|
} |
669
|
|
|
|
670
|
|
|
|
671
|
|
|
/** |
672
|
|
|
* Show miscellaneous information (payment mode, payment term, ...) |
673
|
|
|
* |
674
|
|
|
* @param PDF $pdf Object PDF |
675
|
|
|
* @param Object $object Object to show |
676
|
|
|
* @param int $posy Y |
677
|
|
|
* @param Translate $outputlangs Langs object |
678
|
|
|
* @return void |
679
|
|
|
*/ |
680
|
|
|
function _tableau_info(&$pdf, $object, $posy, $outputlangs) |
|
|
|
|
681
|
|
|
{ |
682
|
|
|
global $conf; |
683
|
|
|
$default_font_size = pdf_getPDFFontSize($outputlangs); |
684
|
|
|
|
685
|
|
|
$pdf->SetFont('','', $default_font_size - 1); |
686
|
|
|
|
687
|
|
|
// If France, show VAT mention if not applicable |
688
|
|
|
if ($this->emetteur->country_code == 'FR' && $this->franchise == 1) |
689
|
|
|
{ |
690
|
|
|
$pdf->SetFont('','B', $default_font_size - 2); |
691
|
|
|
$pdf->SetXY($this->marge_gauche, $posy); |
692
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0); |
693
|
|
|
|
694
|
|
|
$posy=$pdf->GetY()+4; |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
$posxval=52; |
698
|
|
|
|
699
|
|
|
// Show payments conditions |
700
|
|
|
if ($object->cond_reglement_code || $object->cond_reglement) |
701
|
|
|
{ |
702
|
|
|
$pdf->SetFont('','B', $default_font_size - 2); |
703
|
|
|
$pdf->SetXY($this->marge_gauche, $posy); |
704
|
|
|
$titre = $outputlangs->transnoentities("PaymentConditions").':'; |
705
|
|
|
$pdf->MultiCell(80, 4, $titre, 0, 'L'); |
706
|
|
|
|
707
|
|
|
$pdf->SetFont('','', $default_font_size - 2); |
708
|
|
|
$pdf->SetXY($posxval, $posy); |
709
|
|
|
$lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc); |
710
|
|
|
$lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement); |
711
|
|
|
$pdf->MultiCell(80, 4, $lib_condition_paiement,0,'L'); |
712
|
|
|
|
713
|
|
|
$posy=$pdf->GetY()+3; |
714
|
|
|
} |
715
|
|
|
|
716
|
|
|
// Check a payment mode is defined |
717
|
|
|
/* Not used with orders |
718
|
|
|
if (empty($object->mode_reglement_code) |
719
|
|
|
&& ! $conf->global->FACTURE_CHQ_NUMBER |
720
|
|
|
&& ! $conf->global->FACTURE_RIB_NUMBER) |
721
|
|
|
{ |
722
|
|
|
$pdf->SetXY($this->marge_gauche, $posy); |
723
|
|
|
$pdf->SetTextColor(200,0,0); |
724
|
|
|
$pdf->SetFont('','B', $default_font_size - 2); |
725
|
|
|
$pdf->MultiCell(80, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0); |
726
|
|
|
$pdf->SetTextColor(0,0,0); |
727
|
|
|
|
728
|
|
|
$posy=$pdf->GetY()+1; |
729
|
|
|
} |
730
|
|
|
*/ |
731
|
|
|
/* TODO |
732
|
|
|
else if (! empty($object->availability_code)) |
733
|
|
|
{ |
734
|
|
|
$pdf->SetXY($this->marge_gauche, $posy); |
735
|
|
|
$pdf->SetTextColor(200,0,0); |
736
|
|
|
$pdf->SetFont('','B', $default_font_size - 2); |
737
|
|
|
$pdf->MultiCell(80, 3, $outputlangs->transnoentities("AvailabilityPeriod").': '.,0,'L',0); |
738
|
|
|
$pdf->SetTextColor(0,0,0); |
739
|
|
|
|
740
|
|
|
$posy=$pdf->GetY()+1; |
741
|
|
|
}*/ |
742
|
|
|
|
743
|
|
|
// Show planed date of delivery |
744
|
|
|
if (! empty($object->date_livraison)) |
745
|
|
|
{ |
746
|
|
|
$outputlangs->load("sendings"); |
747
|
|
|
$pdf->SetFont('','B', $default_font_size - 2); |
748
|
|
|
$pdf->SetXY($this->marge_gauche, $posy); |
749
|
|
|
$titre = $outputlangs->transnoentities("DateDeliveryPlanned").':'; |
750
|
|
|
$pdf->MultiCell(80, 4, $titre, 0, 'L'); |
751
|
|
|
$pdf->SetFont('','', $default_font_size - 2); |
752
|
|
|
$pdf->SetXY($posxval, $posy); |
753
|
|
|
$dlp=dol_print_date($object->date_livraison,"daytext",false,$outputlangs,true); |
|
|
|
|
754
|
|
|
$pdf->MultiCell(80, 4, $dlp, 0, 'L'); |
755
|
|
|
|
756
|
|
|
$posy=$pdf->GetY()+1; |
757
|
|
|
} |
758
|
|
|
elseif ($object->availability_code || $object->availability) // Show availability conditions |
759
|
|
|
{ |
760
|
|
|
$pdf->SetFont('','B', $default_font_size - 2); |
761
|
|
|
$pdf->SetXY($this->marge_gauche, $posy); |
762
|
|
|
$titre = $outputlangs->transnoentities("AvailabilityPeriod").':'; |
763
|
|
|
$pdf->MultiCell(80, 4, $titre, 0, 'L'); |
764
|
|
|
$pdf->SetTextColor(0,0,0); |
765
|
|
|
$pdf->SetFont('','', $default_font_size - 2); |
766
|
|
|
$pdf->SetXY($posxval, $posy); |
767
|
|
|
$lib_availability=$outputlangs->transnoentities("AvailabilityType".$object->availability_code)!=('AvailabilityType'.$object->availability_code)?$outputlangs->transnoentities("AvailabilityType".$object->availability_code):$outputlangs->convToOutputCharset(isset($object->availability)?$object->availability:''); |
768
|
|
|
$lib_availability=str_replace('\n',"\n",$lib_availability); |
769
|
|
|
$pdf->MultiCell(80, 4, $lib_availability, 0, 'L'); |
770
|
|
|
|
771
|
|
|
$posy=$pdf->GetY()+1; |
772
|
|
|
} |
773
|
|
|
|
774
|
|
|
// Show payment mode |
775
|
|
|
if ($object->mode_reglement_code |
776
|
|
|
&& $object->mode_reglement_code != 'CHQ' |
777
|
|
|
&& $object->mode_reglement_code != 'VIR') |
778
|
|
|
{ |
779
|
|
|
$pdf->SetFont('','B', $default_font_size - 2); |
780
|
|
|
$pdf->SetXY($this->marge_gauche, $posy); |
781
|
|
|
$titre = $outputlangs->transnoentities("PaymentMode").':'; |
782
|
|
|
$pdf->MultiCell(80, 5, $titre, 0, 'L'); |
783
|
|
|
|
784
|
|
|
$pdf->SetFont('','', $default_font_size - 2); |
785
|
|
|
$pdf->SetXY($posxval, $posy); |
786
|
|
|
$lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement); |
787
|
|
|
$pdf->MultiCell(80, 5, $lib_mode_reg,0,'L'); |
788
|
|
|
|
789
|
|
|
$posy=$pdf->GetY()+2; |
790
|
|
|
} |
791
|
|
|
|
792
|
|
|
// Show payment mode CHQ |
793
|
|
|
if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') |
794
|
|
|
{ |
795
|
|
|
// Si mode reglement non force ou si force a CHQ |
796
|
|
|
if (! empty($conf->global->FACTURE_CHQ_NUMBER)) |
797
|
|
|
{ |
798
|
|
|
if ($conf->global->FACTURE_CHQ_NUMBER > 0) |
799
|
|
|
{ |
800
|
|
|
$account = new Account($this->db); |
801
|
|
|
$account->fetch($conf->global->FACTURE_CHQ_NUMBER); |
802
|
|
|
|
803
|
|
|
$pdf->SetXY($this->marge_gauche, $posy); |
804
|
|
|
$pdf->SetFont('','B', $default_font_size - 3); |
805
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio),0,'L',0); |
806
|
|
|
$posy=$pdf->GetY()+1; |
807
|
|
|
|
808
|
|
|
if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) |
809
|
|
|
{ |
810
|
|
|
$pdf->SetXY($this->marge_gauche, $posy); |
811
|
|
|
$pdf->SetFont('','', $default_font_size - 3); |
812
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0); |
813
|
|
|
$posy=$pdf->GetY()+2; |
814
|
|
|
} |
815
|
|
|
} |
816
|
|
|
if ($conf->global->FACTURE_CHQ_NUMBER == -1) |
817
|
|
|
{ |
818
|
|
|
$pdf->SetXY($this->marge_gauche, $posy); |
819
|
|
|
$pdf->SetFont('','B', $default_font_size - 3); |
820
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$this->emetteur->name),0,'L',0); |
821
|
|
|
$posy=$pdf->GetY()+1; |
822
|
|
|
|
823
|
|
|
if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) |
824
|
|
|
{ |
825
|
|
|
$pdf->SetXY($this->marge_gauche, $posy); |
826
|
|
|
$pdf->SetFont('','', $default_font_size - 3); |
827
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0); |
828
|
|
|
$posy=$pdf->GetY()+2; |
829
|
|
|
} |
830
|
|
|
} |
831
|
|
|
} |
832
|
|
|
} |
833
|
|
|
|
834
|
|
|
// If payment mode not forced or forced to VIR, show payment with BAN |
835
|
|
|
if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') |
836
|
|
|
{ |
837
|
|
|
if (! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER)) |
838
|
|
|
{ |
839
|
|
|
$bankid=(empty($object->fk_bank)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_bank); |
840
|
|
|
$account = new Account($this->db); |
841
|
|
|
$account->fetch($bankid); |
842
|
|
|
|
843
|
|
|
$curx=$this->marge_gauche; |
844
|
|
|
$cury=$posy; |
845
|
|
|
|
846
|
|
|
$posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size); |
847
|
|
|
|
848
|
|
|
$posy+=2; |
849
|
|
|
} |
850
|
|
|
} |
851
|
|
|
|
852
|
|
|
return $posy; |
853
|
|
|
} |
854
|
|
|
|
855
|
|
|
|
856
|
|
|
/** |
857
|
|
|
* Show total to pay |
858
|
|
|
* |
859
|
|
|
* @param PDF $pdf Object PDF |
860
|
|
|
* @param Facture $object Object invoice |
861
|
|
|
* @param int $deja_regle Montant deja regle |
862
|
|
|
* @param int $posy Position depart |
863
|
|
|
* @param Translate $outputlangs Objet langs |
864
|
|
|
* @return int Position pour suite |
865
|
|
|
*/ |
866
|
|
|
function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs) |
|
|
|
|
867
|
|
|
{ |
868
|
|
|
global $conf,$mysoc; |
869
|
|
|
|
870
|
|
|
$default_font_size = pdf_getPDFFontSize($outputlangs); |
871
|
|
|
|
872
|
|
|
$tab2_top = $posy; |
873
|
|
|
$tab2_hl = 4; |
874
|
|
|
$pdf->SetFont('','', $default_font_size - 1); |
875
|
|
|
|
876
|
|
|
// Tableau total |
877
|
|
|
$col1x = 120; $col2x = 170; |
878
|
|
|
if ($this->page_largeur < 210) // To work with US executive format |
879
|
|
|
{ |
880
|
|
|
$col2x-=20; |
881
|
|
|
} |
882
|
|
|
$largcol2 = ($this->page_largeur - $this->marge_droite - $col2x); |
883
|
|
|
|
884
|
|
|
$useborder=0; |
885
|
|
|
$index = 0; |
886
|
|
|
|
887
|
|
|
// Total HT |
888
|
|
|
$pdf->SetFillColor(255,255,255); |
889
|
|
|
$pdf->SetXY($col1x, $tab2_top + 0); |
890
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1); |
891
|
|
|
|
892
|
|
|
$pdf->SetXY($col2x, $tab2_top + 0); |
893
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ht + (! empty($object->remise)?$object->remise:0), 0, $outputlangs), 0, 'R', 1); |
|
|
|
|
894
|
|
|
|
895
|
|
|
// Show VAT by rates and total |
896
|
|
|
$pdf->SetFillColor(248,248,248); |
897
|
|
|
|
898
|
|
|
$this->atleastoneratenotnull=0; |
|
|
|
|
899
|
|
|
if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) |
900
|
|
|
{ |
901
|
|
|
$tvaisnull=((! empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false); |
902
|
|
|
if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_ISNULL) && $tvaisnull) |
903
|
|
|
{ |
904
|
|
|
// Nothing to do |
905
|
|
|
} |
906
|
|
|
else |
907
|
|
|
{ |
908
|
|
|
//Local tax 1 before VAT |
909
|
|
|
//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on') |
910
|
|
|
//{ |
911
|
|
|
foreach( $this->localtax1 as $localtax_type => $localtax_rate ) |
912
|
|
|
{ |
913
|
|
|
if (in_array((string) $localtax_type, array('1','3','5'))) continue; |
914
|
|
|
foreach( $localtax_rate as $tvakey => $tvaval ) |
915
|
|
|
{ |
916
|
|
|
if ($tvakey!=0) // On affiche pas taux 0 |
917
|
|
|
{ |
918
|
|
|
//$this->atleastoneratenotnull++; |
919
|
|
|
|
920
|
|
|
$index++; |
921
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
922
|
|
|
|
923
|
|
|
$tvacompl=''; |
924
|
|
|
if (preg_match('/\*/',$tvakey)) |
925
|
|
|
{ |
926
|
|
|
$tvakey=str_replace('*','',$tvakey); |
927
|
|
|
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; |
928
|
|
|
} |
929
|
|
|
$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' '; |
930
|
|
|
$totalvat.=vatrate(abs($tvakey),1).$tvacompl; |
931
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1); |
932
|
|
|
|
933
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
934
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1); |
935
|
|
|
} |
936
|
|
|
} |
937
|
|
|
} |
938
|
|
|
//} |
939
|
|
|
//Local tax 2 before VAT |
940
|
|
|
//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on') |
941
|
|
|
//{ |
942
|
|
|
foreach( $this->localtax2 as $localtax_type => $localtax_rate ) |
943
|
|
|
{ |
944
|
|
|
if (in_array((string) $localtax_type, array('1','3','5'))) continue; |
945
|
|
|
foreach( $localtax_rate as $tvakey => $tvaval ) |
946
|
|
|
{ |
947
|
|
|
if ($tvakey!=0) // On affiche pas taux 0 |
948
|
|
|
{ |
949
|
|
|
//$this->atleastoneratenotnull++; |
950
|
|
|
|
951
|
|
|
|
952
|
|
|
|
953
|
|
|
$index++; |
954
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
955
|
|
|
|
956
|
|
|
$tvacompl=''; |
957
|
|
|
if (preg_match('/\*/',$tvakey)) |
958
|
|
|
{ |
959
|
|
|
$tvakey=str_replace('*','',$tvakey); |
960
|
|
|
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; |
961
|
|
|
} |
962
|
|
|
$totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' '; |
963
|
|
|
$totalvat.=vatrate(abs($tvakey),1).$tvacompl; |
964
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1); |
965
|
|
|
|
966
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
967
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1); |
968
|
|
|
|
969
|
|
|
} |
970
|
|
|
} |
971
|
|
|
} |
972
|
|
|
//} |
973
|
|
|
// VAT |
974
|
|
|
foreach($this->tva as $tvakey => $tvaval) |
975
|
|
|
{ |
976
|
|
|
if ($tvakey > 0) // On affiche pas taux 0 |
977
|
|
|
{ |
978
|
|
|
$this->atleastoneratenotnull++; |
979
|
|
|
|
980
|
|
|
$index++; |
981
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
982
|
|
|
|
983
|
|
|
$tvacompl=''; |
984
|
|
|
if (preg_match('/\*/',$tvakey)) |
985
|
|
|
{ |
986
|
|
|
$tvakey=str_replace('*','',$tvakey); |
987
|
|
|
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; |
988
|
|
|
} |
989
|
|
|
$totalvat =$outputlangs->transnoentities("TotalVAT").' '; |
990
|
|
|
$totalvat.=vatrate($tvakey,1).$tvacompl; |
991
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1); |
992
|
|
|
|
993
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
994
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1); |
995
|
|
|
} |
996
|
|
|
} |
997
|
|
|
|
998
|
|
|
//Local tax 1 after VAT |
999
|
|
|
//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on') |
1000
|
|
|
//{ |
1001
|
|
|
foreach( $this->localtax1 as $localtax_type => $localtax_rate ) |
1002
|
|
|
{ |
1003
|
|
|
if (in_array((string) $localtax_type, array('2','4','6'))) continue; |
1004
|
|
|
|
1005
|
|
|
foreach( $localtax_rate as $tvakey => $tvaval ) |
1006
|
|
|
{ |
1007
|
|
|
if ($tvakey != 0) // On affiche pas taux 0 |
1008
|
|
|
{ |
1009
|
|
|
//$this->atleastoneratenotnull++; |
1010
|
|
|
|
1011
|
|
|
$index++; |
1012
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
1013
|
|
|
|
1014
|
|
|
$tvacompl=''; |
1015
|
|
|
if (preg_match('/\*/',$tvakey)) |
1016
|
|
|
{ |
1017
|
|
|
$tvakey=str_replace('*','',$tvakey); |
1018
|
|
|
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; |
1019
|
|
|
} |
1020
|
|
|
$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' '; |
1021
|
|
|
|
1022
|
|
|
$totalvat.=vatrate(abs($tvakey),1).$tvacompl; |
1023
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1); |
1024
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
1025
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1); |
1026
|
|
|
} |
1027
|
|
|
} |
1028
|
|
|
} |
1029
|
|
|
//} |
1030
|
|
|
//Local tax 2 after VAT |
1031
|
|
|
//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on') |
1032
|
|
|
//{ |
1033
|
|
|
foreach( $this->localtax2 as $localtax_type => $localtax_rate ) |
1034
|
|
|
{ |
1035
|
|
|
if (in_array((string) $localtax_type, array('2','4','6'))) continue; |
1036
|
|
|
|
1037
|
|
|
foreach( $localtax_rate as $tvakey => $tvaval ) |
1038
|
|
|
{ |
1039
|
|
|
if ($tvakey != 0) // On affiche pas taux 0 |
1040
|
|
|
{ |
1041
|
|
|
//$this->atleastoneratenotnull++; |
1042
|
|
|
|
1043
|
|
|
$index++; |
1044
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
1045
|
|
|
|
1046
|
|
|
$tvacompl=''; |
1047
|
|
|
if (preg_match('/\*/',$tvakey)) |
1048
|
|
|
{ |
1049
|
|
|
$tvakey=str_replace('*','',$tvakey); |
1050
|
|
|
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; |
1051
|
|
|
} |
1052
|
|
|
$totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' '; |
1053
|
|
|
|
1054
|
|
|
$totalvat.=vatrate(abs($tvakey),1).$tvacompl; |
1055
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1); |
1056
|
|
|
|
1057
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
1058
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1); |
1059
|
|
|
} |
1060
|
|
|
} |
1061
|
|
|
} |
1062
|
|
|
//} |
1063
|
|
|
|
1064
|
|
|
// Total TTC |
1065
|
|
|
$index++; |
1066
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
1067
|
|
|
$pdf->SetTextColor(0,0,60); |
1068
|
|
|
$pdf->SetFillColor(224,224,224); |
1069
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1); |
1070
|
|
|
|
1071
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
1072
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc, 0, $outputlangs), $useborder, 'R', 1); |
1073
|
|
|
} |
1074
|
|
|
} |
1075
|
|
|
|
1076
|
|
|
$pdf->SetTextColor(0,0,0); |
1077
|
|
|
|
1078
|
|
|
$creditnoteamount=0; |
1079
|
|
|
$depositsamount=0; |
1080
|
|
|
//$creditnoteamount=$object->getSumCreditNotesUsed(); |
1081
|
|
|
//$depositsamount=$object->getSumDepositsUsed(); |
1082
|
|
|
//print "x".$creditnoteamount."-".$depositsamount;exit; |
1083
|
|
|
$resteapayer = price2num(doubleval($object->total_ttc) - doubleval($deja_regle) - $creditnoteamount - $depositsamount, 'MT'); |
1084
|
|
|
if (! empty($object->paye)) $resteapayer=0; |
1085
|
|
|
|
1086
|
|
|
if ($deja_regle > 0) |
1087
|
|
|
{ |
1088
|
|
|
// Already paid + Deposits |
1089
|
|
|
$index++; |
1090
|
|
|
|
1091
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
1092
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0); |
1093
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
1094
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0); |
1095
|
|
|
|
1096
|
|
|
$index++; |
1097
|
|
|
$pdf->SetTextColor(0,0,60); |
1098
|
|
|
$pdf->SetFillColor(224,224,224); |
1099
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
1100
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1); |
1101
|
|
|
|
1102
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
1103
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1); |
|
|
|
|
1104
|
|
|
|
1105
|
|
|
$pdf->SetFont('','', $default_font_size - 1); |
1106
|
|
|
$pdf->SetTextColor(0,0,0); |
1107
|
|
|
} |
1108
|
|
|
|
1109
|
|
|
$index++; |
1110
|
|
|
return ($tab2_top + ($tab2_hl * $index)); |
1111
|
|
|
} |
1112
|
|
|
|
1113
|
|
|
/** |
1114
|
|
|
* Show table for lines |
1115
|
|
|
* |
1116
|
|
|
* @param PDF $pdf Object PDF |
1117
|
|
|
* @param string $tab_top Top position of table |
1118
|
|
|
* @param string $tab_height Height of table (rectangle) |
1119
|
|
|
* @param int $nexY Y (not used) |
1120
|
|
|
* @param Translate $outputlangs Langs object |
1121
|
|
|
* @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title |
1122
|
|
|
* @param int $hidebottom Hide bottom bar of array |
1123
|
|
|
* @return void |
1124
|
|
|
*/ |
1125
|
|
|
function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0) |
|
|
|
|
1126
|
|
|
{ |
1127
|
|
|
global $conf; |
1128
|
|
|
|
1129
|
|
|
// Force to disable hidetop and hidebottom |
1130
|
|
|
$hidebottom=0; |
1131
|
|
|
if ($hidetop) $hidetop=-1; |
1132
|
|
|
|
1133
|
|
|
$default_font_size = pdf_getPDFFontSize($outputlangs); |
1134
|
|
|
|
1135
|
|
|
// Amount in (at tab_top - 1) |
1136
|
|
|
$pdf->SetTextColor(0,0,0); |
1137
|
|
|
$pdf->SetFont('','', $default_font_size - 2); |
1138
|
|
|
|
1139
|
|
|
if (empty($hidetop)) |
1140
|
|
|
{ |
1141
|
|
|
$titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$conf->currency)); |
1142
|
|
|
$pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4); |
1143
|
|
|
$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre); |
1144
|
|
|
|
1145
|
|
|
//$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230'; |
1146
|
|
|
if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)); |
1147
|
|
|
} |
1148
|
|
|
|
1149
|
|
|
$pdf->SetDrawColor(128,128,128); |
1150
|
|
|
$pdf->SetFont('','', $default_font_size - 1); |
1151
|
|
|
|
1152
|
|
|
// Output Rect |
1153
|
|
|
$this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect prend une longueur en 3eme param et 4eme param |
|
|
|
|
1154
|
|
|
|
1155
|
|
|
if (empty($hidetop)) |
1156
|
|
|
{ |
1157
|
|
|
$pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5); // line prend une position y en 2eme param et 4eme param |
1158
|
|
|
|
1159
|
|
|
$pdf->SetXY($this->posxdesc-1, $tab_top+1); |
1160
|
|
|
$pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L'); |
1161
|
|
|
} |
1162
|
|
|
|
1163
|
|
|
if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) |
1164
|
|
|
{ |
1165
|
|
|
$pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height); |
1166
|
|
|
if (empty($hidetop)) |
1167
|
|
|
{ |
1168
|
|
|
$pdf->SetXY($this->posxtva-3, $tab_top+1); |
1169
|
|
|
$pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C'); |
1170
|
|
|
} |
1171
|
|
|
} |
1172
|
|
|
|
1173
|
|
|
$pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height); |
1174
|
|
|
if (empty($hidetop)) |
1175
|
|
|
{ |
1176
|
|
|
$pdf->SetXY($this->posxup-1, $tab_top+1); |
1177
|
|
|
$pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C'); |
1178
|
|
|
} |
1179
|
|
|
|
1180
|
|
|
$pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height); |
1181
|
|
|
if (empty($hidetop)) |
1182
|
|
|
{ |
1183
|
|
|
$pdf->SetXY($this->posxqty-1, $tab_top+1); |
1184
|
|
|
$pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C'); |
1185
|
|
|
} |
1186
|
|
|
|
1187
|
|
|
$pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height); |
1188
|
|
|
if (empty($hidetop)) |
1189
|
|
|
{ |
1190
|
|
|
if ($this->atleastonediscount) |
1191
|
|
|
{ |
1192
|
|
|
$pdf->SetXY($this->posxdiscount-1, $tab_top+1); |
1193
|
|
|
$pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C'); |
1194
|
|
|
} |
1195
|
|
|
} |
1196
|
|
|
|
1197
|
|
|
if ($this->atleastonediscount) |
1198
|
|
|
{ |
1199
|
|
|
$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height); |
1200
|
|
|
} |
1201
|
|
|
if (empty($hidetop)) |
1202
|
|
|
{ |
1203
|
|
|
$pdf->SetXY($this->postotalht-1, $tab_top+1); |
1204
|
|
|
$pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHT"),'','C'); |
1205
|
|
|
} |
1206
|
|
|
} |
1207
|
|
|
|
1208
|
|
|
/** |
1209
|
|
|
* Show top header of page. |
1210
|
|
|
* |
1211
|
|
|
* @param PDF $pdf Object PDF |
1212
|
|
|
* @param Object $object Object to show |
1213
|
|
|
* @param int $showaddress 0=no, 1=yes |
1214
|
|
|
* @param Translate $outputlangs Object lang for output |
1215
|
|
|
* @return void |
1216
|
|
|
*/ |
1217
|
|
|
function _pagehead(&$pdf, $object, $showaddress, $outputlangs) |
|
|
|
|
1218
|
|
|
{ |
1219
|
|
|
global $conf,$langs,$hookmanager; |
1220
|
|
|
|
1221
|
|
|
$outputlangs->load("main"); |
1222
|
|
|
$outputlangs->load("bills"); |
1223
|
|
|
$outputlangs->load("propal"); |
1224
|
|
|
$outputlangs->load("companies"); |
1225
|
|
|
$outputlangs->load("orders"); |
1226
|
|
|
$default_font_size = pdf_getPDFFontSize($outputlangs); |
1227
|
|
|
|
1228
|
|
|
pdf_pagehead($pdf,$outputlangs,$this->page_hauteur); |
1229
|
|
|
|
1230
|
|
|
// Show Draft Watermark |
1231
|
|
|
if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) ) |
1232
|
|
|
{ |
1233
|
|
|
pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK); |
1234
|
|
|
} |
1235
|
|
|
|
1236
|
|
|
$pdf->SetTextColor(0,0,60); |
1237
|
|
|
$pdf->SetFont('','B', $default_font_size + 3); |
1238
|
|
|
|
1239
|
|
|
$posy=$this->marge_haute; |
1240
|
|
|
$posx=$this->page_largeur-$this->marge_droite-100; |
1241
|
|
|
|
1242
|
|
|
$pdf->SetXY($this->marge_gauche,$posy); |
1243
|
|
|
|
1244
|
|
|
// Logo |
1245
|
|
|
$logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo; |
1246
|
|
|
if ($this->emetteur->logo) |
1247
|
|
|
{ |
1248
|
|
|
if (is_readable($logo)) |
1249
|
|
|
{ |
1250
|
|
|
$height=pdf_getHeightForLogo($logo); |
1251
|
|
|
$pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) |
1252
|
|
|
} |
1253
|
|
|
else |
1254
|
|
|
{ |
1255
|
|
|
$pdf->SetTextColor(200,0,0); |
1256
|
|
|
$pdf->SetFont('','B', $default_font_size -2); |
1257
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L'); |
1258
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L'); |
1259
|
|
|
} |
1260
|
|
|
} |
1261
|
|
|
else |
1262
|
|
|
{ |
1263
|
|
|
$text=$this->emetteur->name; |
1264
|
|
|
$pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L'); |
1265
|
|
|
} |
1266
|
|
|
|
1267
|
|
|
$pdf->SetFont('','B', $default_font_size + 3); |
1268
|
|
|
$pdf->SetXY($posx,$posy); |
1269
|
|
|
$pdf->SetTextColor(0,0,60); |
1270
|
|
|
$title=$outputlangs->transnoentities("Order"); |
1271
|
|
|
$pdf->MultiCell(100, 3, $title, '', 'R'); |
1272
|
|
|
|
1273
|
|
|
$pdf->SetFont('','B',$default_font_size); |
1274
|
|
|
|
1275
|
|
|
$posy+=5; |
1276
|
|
|
$pdf->SetXY($posx,$posy); |
1277
|
|
|
$pdf->SetTextColor(0,0,60); |
1278
|
|
|
$pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R'); |
1279
|
|
|
|
1280
|
|
|
$posy+=1; |
1281
|
|
|
$pdf->SetFont('','', $default_font_size - 1); |
1282
|
|
|
|
1283
|
|
|
if ($object->ref_client) |
1284
|
|
|
{ |
1285
|
|
|
$posy+=5; |
1286
|
|
|
$pdf->SetXY($posx,$posy); |
1287
|
|
|
$pdf->SetTextColor(0,0,60); |
1288
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R'); |
1289
|
|
|
} |
1290
|
|
|
|
1291
|
|
|
$posy+=4; |
1292
|
|
|
$pdf->SetXY($posx,$posy); |
1293
|
|
|
$pdf->SetTextColor(0,0,60); |
1294
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderDate")." : " . dol_print_date($object->date,"%d %b %Y",false,$outputlangs,true), '', 'R'); |
|
|
|
|
1295
|
|
|
|
1296
|
|
|
$posy+=2; |
1297
|
|
|
|
1298
|
|
|
// Show list of linked objects |
1299
|
|
|
$posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size); |
|
|
|
|
1300
|
|
|
|
1301
|
|
|
if ($showaddress) |
1302
|
|
|
{ |
1303
|
|
|
// Sender properties |
1304
|
|
|
$carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty); |
1305
|
|
|
|
1306
|
|
|
// Show sender |
1307
|
|
|
$posy=42; |
1308
|
|
|
$posx=$this->marge_gauche; |
1309
|
|
|
if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80; |
1310
|
|
|
$hautcadre=40; |
1311
|
|
|
|
1312
|
|
|
// Show sender frame |
1313
|
|
|
$pdf->SetTextColor(0,0,0); |
1314
|
|
|
$pdf->SetFont('','', $default_font_size - 2); |
1315
|
|
|
$pdf->SetXY($posx,$posy-5); |
1316
|
|
|
$pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L'); |
1317
|
|
|
$pdf->SetXY($posx,$posy); |
1318
|
|
|
$pdf->SetFillColor(230,230,230); |
1319
|
|
|
$pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1); |
1320
|
|
|
$pdf->SetTextColor(0,0,60); |
1321
|
|
|
|
1322
|
|
|
// Show sender name |
1323
|
|
|
$pdf->SetXY($posx+2,$posy+3); |
1324
|
|
|
$pdf->SetFont('','B', $default_font_size); |
1325
|
|
|
$pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L'); |
1326
|
|
|
$posy=$pdf->getY(); |
1327
|
|
|
|
1328
|
|
|
// Show sender information |
1329
|
|
|
$pdf->SetXY($posx+2,$posy); |
1330
|
|
|
$pdf->SetFont('','', $default_font_size - 1); |
1331
|
|
|
$pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L'); |
1332
|
|
|
|
1333
|
|
|
|
1334
|
|
|
|
1335
|
|
|
// If CUSTOMER contact defined on order, we use it |
1336
|
|
|
$usecontact=false; |
1337
|
|
|
$arrayidcontact=$object->getIdContact('external','CUSTOMER'); |
1338
|
|
|
if (count($arrayidcontact) > 0) |
1339
|
|
|
{ |
1340
|
|
|
$usecontact=true; |
1341
|
|
|
$result=$object->fetch_contact($arrayidcontact[0]); |
|
|
|
|
1342
|
|
|
} |
1343
|
|
|
|
1344
|
|
|
// Recipient name |
1345
|
|
|
if (! empty($usecontact)) |
1346
|
|
|
{ |
1347
|
|
|
// On peut utiliser le nom de la societe du contact |
1348
|
|
|
if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socname = $object->contact->socname; |
1349
|
|
|
else $socname = $object->thirdparty->name; |
1350
|
|
|
$carac_client_name=$outputlangs->convToOutputCharset($socname); |
1351
|
|
|
} |
1352
|
|
|
else |
1353
|
|
|
{ |
1354
|
|
|
$carac_client_name=$outputlangs->convToOutputCharset($object->thirdparty->name); |
1355
|
|
|
} |
1356
|
|
|
|
1357
|
|
|
$carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target'); |
|
|
|
|
1358
|
|
|
|
1359
|
|
|
// Show recipient |
1360
|
|
|
$widthrecbox=100; |
1361
|
|
|
if ($this->page_largeur < 210) $widthrecbox=84; // To work with US executive format |
1362
|
|
|
$posy=42; |
1363
|
|
|
$posx=$this->page_largeur-$this->marge_droite-$widthrecbox; |
1364
|
|
|
if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche; |
1365
|
|
|
|
1366
|
|
|
// Show recipient frame |
1367
|
|
|
$pdf->SetTextColor(0,0,0); |
1368
|
|
|
$pdf->SetFont('','', $default_font_size - 2); |
1369
|
|
|
$pdf->SetXY($posx+2,$posy-5); |
1370
|
|
|
$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":",0,'L'); |
1371
|
|
|
$pdf->Rect($posx, $posy, $widthrecbox, $hautcadre); |
1372
|
|
|
|
1373
|
|
|
// Show recipient name |
1374
|
|
|
$pdf->SetXY($posx+2,$posy+3); |
1375
|
|
|
$pdf->SetFont('','B', $default_font_size); |
1376
|
|
|
$pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L'); |
1377
|
|
|
|
1378
|
|
|
// Show recipient information |
1379
|
|
|
$pdf->SetFont('','', $default_font_size - 1); |
1380
|
|
|
$pdf->SetXY($posx+2,$posy+4+(dol_nboflines_bis($carac_client_name,50)*4)); |
1381
|
|
|
$pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L'); |
1382
|
|
|
} |
1383
|
|
|
|
1384
|
|
|
$pdf->SetTextColor(0,0,0); |
1385
|
|
|
} |
1386
|
|
|
|
1387
|
|
|
/** |
1388
|
|
|
* Show footer of page. Need this->emetteur object |
1389
|
|
|
* |
1390
|
|
|
* @param PDF $pdf PDF |
1391
|
|
|
* @param Object $object Object to show |
1392
|
|
|
* @param Translate $outputlangs Object lang for output |
1393
|
|
|
* @param int $hidefreetext 1=Hide free text |
1394
|
|
|
* @return int Return height of bottom margin including footer text |
1395
|
|
|
*/ |
1396
|
|
|
function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0) |
|
|
|
|
1397
|
|
|
{ |
1398
|
|
|
$showdetails=0; |
1399
|
|
|
$free_text = (float)DOL_VERSION > 3.8 ? 'ORDER_FREE_TEXT' : 'COMMANDE_FREE_TEXT'; |
1400
|
|
|
return pdf_pagefoot($pdf,$outputlangs,$free_text,$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext); |
1401
|
|
|
} |
1402
|
|
|
|
1403
|
|
|
} |
1404
|
|
|
|
1405
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.