|
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-2014 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/facture/doc/pdf_crabe.modules.php |
|
25
|
|
|
* \ingroup facture |
|
26
|
|
|
* \brief File of class to generate customers invoices from crabe model |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.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
|
|
|
* Class to manage PDF invoice template Crabe |
|
38
|
|
|
*/ |
|
39
|
|
|
class pdf_crabe_subtotal extends ModelePDFFactures |
|
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 = "crabe_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 facture incluant des spécificités pour le 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 = 1; // Affiche si il y a eu escompte |
|
|
|
|
|
|
95
|
|
|
$this->option_credit_note = 1; // 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
|
|
|
/** |
|
133
|
|
|
* Function to build pdf onto disk |
|
134
|
|
|
* |
|
135
|
|
|
* @param Object $object Object to generate |
|
136
|
|
|
* @param Translate $outputlangs Lang output object |
|
137
|
|
|
* @param string $srctemplatepath Full path of source filename for generator using a template file |
|
138
|
|
|
* @param int $hidedetails Do not show line details |
|
139
|
|
|
* @param int $hidedesc Do not show desc |
|
140
|
|
|
* @param int $hideref Do not show ref |
|
141
|
|
|
* @return int 1=OK, 0=KO |
|
142
|
|
|
*/ |
|
143
|
|
|
function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) |
|
|
|
|
|
|
144
|
|
|
{ |
|
145
|
|
|
global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes; |
|
146
|
|
|
|
|
147
|
|
|
if (! is_object($outputlangs)) $outputlangs=$langs; |
|
148
|
|
|
// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO |
|
149
|
|
|
if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; |
|
150
|
|
|
|
|
151
|
|
|
$outputlangs->load("main"); |
|
152
|
|
|
$outputlangs->load("dict"); |
|
153
|
|
|
$outputlangs->load("companies"); |
|
154
|
|
|
$outputlangs->load("bills"); |
|
155
|
|
|
$outputlangs->load("products"); |
|
156
|
|
|
|
|
157
|
|
|
$nblignes = count($object->lines); |
|
158
|
|
|
|
|
159
|
|
|
// Loop on each lines to detect if there is at least one image to show |
|
160
|
|
|
$realpatharray=array(); |
|
161
|
|
|
if (! empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) |
|
162
|
|
|
{ |
|
163
|
|
|
for ($i = 0 ; $i < $nblignes ; $i++) |
|
164
|
|
|
{ |
|
165
|
|
|
if (empty($object->lines[$i]->fk_product)) continue; |
|
166
|
|
|
|
|
167
|
|
|
$objphoto = new Product($this->db); |
|
168
|
|
|
$objphoto->fetch($object->lines[$i]->fk_product); |
|
169
|
|
|
|
|
170
|
|
|
$pdir = get_exdir($object->lines[$i]->fk_product,2) . $object->lines[$i]->fk_product ."/photos/"; |
|
|
|
|
|
|
171
|
|
|
$dir = $conf->product->dir_output.'/'.$pdir; |
|
172
|
|
|
|
|
173
|
|
|
$realpath=''; |
|
174
|
|
|
foreach ($objphoto->liste_photos($dir,1) as $key => $obj) |
|
175
|
|
|
{ |
|
176
|
|
|
$filename=$obj['photo']; |
|
177
|
|
|
//if ($obj['photo_vignette']) $filename='thumbs/'.$obj['photo_vignette']; |
|
178
|
|
|
$realpath = $dir.$filename; |
|
179
|
|
|
break; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
if ($realpath) $realpatharray[$i]=$realpath; |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva; |
|
|
|
|
|
|
186
|
|
|
|
|
187
|
|
|
if ($conf->facture->dir_output) |
|
188
|
|
|
{ |
|
189
|
|
|
$object->fetch_thirdparty(); |
|
190
|
|
|
if(!empty($object->client) ){ |
|
191
|
|
|
$object->thirdparty = $object->client; |
|
192
|
|
|
} |
|
193
|
|
|
$deja_regle = $object->getSommePaiement(); |
|
194
|
|
|
$amount_credit_notes_included = $object->getSumCreditNotesUsed(); |
|
195
|
|
|
$amount_deposits_included = $object->getSumDepositsUsed(); |
|
196
|
|
|
|
|
197
|
|
|
// Definition of $dir and $file |
|
198
|
|
|
if ($object->specimen) |
|
199
|
|
|
{ |
|
200
|
|
|
$dir = $conf->facture->dir_output; |
|
201
|
|
|
$file = $dir . "/SPECIMEN.pdf"; |
|
202
|
|
|
} |
|
203
|
|
|
else |
|
204
|
|
|
{ |
|
205
|
|
|
$objectref = dol_sanitizeFileName($object->ref); |
|
206
|
|
|
$dir = $conf->facture->dir_output . "/" . $objectref; |
|
207
|
|
|
$file = $dir . "/" . $objectref . ".pdf"; |
|
208
|
|
|
} |
|
209
|
|
|
if (! file_exists($dir)) |
|
210
|
|
|
{ |
|
211
|
|
|
if (dol_mkdir($dir) < 0) |
|
212
|
|
|
{ |
|
213
|
|
|
$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
214
|
|
|
return 0; |
|
215
|
|
|
} |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
if (file_exists($dir)) |
|
219
|
|
|
{ |
|
220
|
|
|
// Add pdfgeneration hook |
|
221
|
|
|
if (! is_object($hookmanager)) |
|
222
|
|
|
{ |
|
223
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
|
224
|
|
|
$hookmanager=new HookManager($this->db); |
|
225
|
|
|
} |
|
226
|
|
|
$hookmanager->initHooks(array('pdfgeneration')); |
|
227
|
|
|
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); |
|
228
|
|
|
global $action; |
|
229
|
|
|
$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
|
|
|
|
|
230
|
|
|
|
|
231
|
|
|
// Create pdf instance |
|
232
|
|
|
$pdf=pdf_getInstance($this->format); |
|
|
|
|
|
|
233
|
|
|
$default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance |
|
234
|
|
|
$heightforinfotot = 50; // Height reserved to output the info and total part |
|
235
|
|
|
$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 |
|
236
|
|
|
$heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) |
|
237
|
|
|
$pdf->SetAutoPageBreak(1,0); |
|
238
|
|
|
|
|
239
|
|
|
if (class_exists('TCPDF')) |
|
240
|
|
|
{ |
|
241
|
|
|
$pdf->setPrintHeader(false); |
|
242
|
|
|
$pdf->setPrintFooter(false); |
|
243
|
|
|
} |
|
244
|
|
|
$pdf->SetFont(pdf_getPDFFont($outputlangs)); |
|
245
|
|
|
|
|
246
|
|
|
// Set path to the background PDF File |
|
247
|
|
|
if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) |
|
248
|
|
|
{ |
|
249
|
|
|
$pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); |
|
|
|
|
|
|
250
|
|
|
$tplidx = $pdf->importPage(1); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
$pdf->Open(); |
|
254
|
|
|
$pagenb=0; |
|
255
|
|
|
$pdf->SetDrawColor(128,128,128); |
|
256
|
|
|
|
|
257
|
|
|
$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); |
|
258
|
|
|
$pdf->SetSubject($outputlangs->transnoentities("Invoice")); |
|
259
|
|
|
$pdf->SetCreator("Dolibarr ".DOL_VERSION); |
|
260
|
|
|
$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); |
|
261
|
|
|
$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Invoice")); |
|
262
|
|
|
if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); |
|
263
|
|
|
|
|
264
|
|
|
$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right |
|
265
|
|
|
|
|
266
|
|
|
// Positionne $this->atleastonediscount si on a au moins une remise |
|
267
|
|
|
for ($i = 0 ; $i < $nblignes ; $i++) |
|
268
|
|
|
{ |
|
269
|
|
|
if ($object->lines[$i]->remise_percent) |
|
270
|
|
|
{ |
|
271
|
|
|
$this->atleastonediscount++; |
|
272
|
|
|
} |
|
273
|
|
|
} |
|
274
|
|
|
if (empty($this->atleastonediscount)) |
|
275
|
|
|
{ |
|
276
|
|
|
$this->posxpicture+=($this->postotalht - $this->posxdiscount); |
|
277
|
|
|
$this->posxtva+=($this->postotalht - $this->posxdiscount); |
|
278
|
|
|
$this->posxup+=($this->postotalht - $this->posxdiscount); |
|
279
|
|
|
$this->posxqty+=($this->postotalht - $this->posxdiscount); |
|
280
|
|
|
$this->posxdiscount+=($this->postotalht - $this->posxdiscount); |
|
281
|
|
|
//$this->postotalht; |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
// New page |
|
285
|
|
|
$pdf->AddPage(); |
|
286
|
|
|
if (! empty($tplidx)) $pdf->useTemplate($tplidx); |
|
287
|
|
|
$pagenb++; |
|
288
|
|
|
|
|
289
|
|
|
$this->_pagehead($pdf, $object, 1, $outputlangs); |
|
290
|
|
|
$pdf->SetFont('','', $default_font_size - 1); |
|
291
|
|
|
$pdf->MultiCell(0, 3, ''); // Set interline to 3 |
|
292
|
|
|
$pdf->SetTextColor(0,0,0); |
|
293
|
|
|
|
|
294
|
|
|
$tab_top = 90; |
|
295
|
|
|
$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10); |
|
296
|
|
|
$tab_height = 130; |
|
297
|
|
|
$tab_height_newpage = 150; |
|
|
|
|
|
|
298
|
|
|
|
|
299
|
|
|
// Affiche notes |
|
300
|
|
|
$notetoshow=empty($object->note_public)?'':$object->note_public; |
|
301
|
|
|
if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) |
|
302
|
|
|
{ |
|
303
|
|
|
// Get first sale rep |
|
304
|
|
|
if (is_object($object->thirdparty)) |
|
305
|
|
|
{ |
|
306
|
|
|
$salereparray=$object->thirdparty->getSalesRepresentatives($user); |
|
307
|
|
|
$salerepobj=new User($this->db); |
|
308
|
|
|
$salerepobj->fetch($salereparray[0]['id']); |
|
309
|
|
|
if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature); |
|
310
|
|
|
} |
|
311
|
|
|
} |
|
312
|
|
|
if ($notetoshow) |
|
313
|
|
|
{ |
|
314
|
|
|
$tab_top = 88; |
|
315
|
|
|
|
|
316
|
|
|
$pdf->SetFont('','', $default_font_size - 1); |
|
317
|
|
|
$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1); |
|
318
|
|
|
$nexY = $pdf->GetY(); |
|
319
|
|
|
$height_note=$nexY-$tab_top; |
|
320
|
|
|
|
|
321
|
|
|
// Rect prend une longueur en 3eme param |
|
322
|
|
|
$pdf->SetDrawColor(192,192,192); |
|
323
|
|
|
$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1); |
|
324
|
|
|
|
|
325
|
|
|
$tab_height = $tab_height - $height_note; |
|
|
|
|
|
|
326
|
|
|
$tab_top = $nexY+6; |
|
327
|
|
|
} |
|
328
|
|
|
else |
|
329
|
|
|
{ |
|
330
|
|
|
$height_note=0; |
|
|
|
|
|
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
$iniY = $tab_top + 7; |
|
|
|
|
|
|
334
|
|
|
$curY = $tab_top + 7; |
|
|
|
|
|
|
335
|
|
|
$nexY = $tab_top + 7; |
|
336
|
|
|
|
|
337
|
|
|
$inPackage = false; |
|
|
|
|
|
|
338
|
|
|
$TPackageInfos = array(); |
|
|
|
|
|
|
339
|
|
|
$TChilds = array(); |
|
|
|
|
|
|
340
|
|
|
$package_qty = 0; |
|
|
|
|
|
|
341
|
|
|
$TStack = array(); |
|
342
|
|
|
|
|
343
|
|
|
// Loop on each lines |
|
344
|
|
|
for ($i = 0; $i < $nblignes; $i++) |
|
345
|
|
|
{ |
|
346
|
|
|
$package_qty = $TStack[count($TStack) - 1]['package_qty']; |
|
347
|
|
|
$inPackage = count($TStack) > 0; |
|
348
|
|
|
|
|
349
|
|
|
// Ligne de titre |
|
350
|
|
|
if ($object->lines[$i]->product_type == 9 && $object->lines[$i]->qty < 97) { |
|
351
|
|
|
$inPackage = true; |
|
352
|
|
|
|
|
353
|
|
|
if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES) { |
|
354
|
|
|
if (!empty($object->lines[$i]->fk_product)) { |
|
355
|
|
|
$product = new Product($db); |
|
356
|
|
|
$product->fetch($object->lines[$i]->fk_product); |
|
357
|
|
|
|
|
358
|
|
|
$TChilds = $product->getChildsArbo($product->id); |
|
359
|
|
|
|
|
360
|
|
|
$TStack[count($TStack)] = array( |
|
361
|
|
|
'childs' => $TChilds, |
|
362
|
|
|
'package' => array(), |
|
363
|
|
|
'package_qty' => 0 |
|
364
|
|
|
); |
|
365
|
|
|
|
|
366
|
|
|
// Si on se trouvait déjà dans un package, on rajoute ce produit à la liste des produits |
|
367
|
|
|
// du précédent package |
|
368
|
|
|
if (count($TStack) > 1) { |
|
369
|
|
|
$TStack[count($TStack) - 2]['package'][$object->lines[$i]->fk_product] += $object->lines[$i]->qty; |
|
370
|
|
|
} |
|
371
|
|
|
} |
|
372
|
|
|
} |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES) { |
|
376
|
|
|
if ($inPackage && $object->lines[$i]->product_type != 9 && $object->lines[$i]->fk_product > 0) { |
|
377
|
|
|
$TStack[count($TStack) - 1]['package'][$object->lines[$i]->fk_product] += $object->lines[$i]->qty; |
|
378
|
|
|
} |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
if ($inPackage && $object->lines[$i]->product_type == 9 && $object->lines[$i]->qty >= 97) { |
|
382
|
|
|
if (count($TStack) <= 1) { |
|
383
|
|
|
$inPackage = false; |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES) { |
|
387
|
|
|
// Comparaison pour déterminer la quantité de package |
|
388
|
|
|
$TProducts = array_keys($TStack[count($TStack) - 1]['package']); |
|
389
|
|
|
$TProductsChilds = array_keys($TStack[count($TStack) - 1]['childs']); |
|
390
|
|
|
|
|
391
|
|
|
if ($TProductsChilds == $TProducts) { |
|
392
|
|
|
// Il s'agit d'un package |
|
393
|
|
|
// On récupére la quantité |
|
394
|
|
|
$first_child_id = $TProducts[0]; |
|
395
|
|
|
$document_qty = $TStack[count($TStack) - 1]['package'][$first_child_id]; |
|
396
|
|
|
$base_qty = $TStack[count($TStack) - 1]['childs'][$first_child_id][1]; |
|
397
|
|
|
|
|
398
|
|
|
$TStack[count($TStack) - 1]['package_qty'] = $document_qty / $base_qty; |
|
399
|
|
|
$package_qty = $TStack[count($TStack) - 1]['package_qty']; |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
|
|
array_pop($TStack); |
|
403
|
|
|
} |
|
404
|
|
|
} |
|
405
|
|
|
|
|
406
|
|
|
$curY = $nexY; |
|
407
|
|
|
$pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage |
|
408
|
|
|
$pdf->SetTextColor(0,0,0); |
|
409
|
|
|
|
|
410
|
|
|
// Define size of image if we need it |
|
411
|
|
|
$imglinesize=array(); |
|
412
|
|
|
if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]); |
|
413
|
|
|
|
|
414
|
|
|
$pdf->setTopMargin($tab_top_newpage); |
|
415
|
|
|
$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. |
|
416
|
|
|
$pageposbefore=$pdf->getPage(); |
|
417
|
|
|
|
|
418
|
|
|
$showpricebeforepagebreak=1; |
|
419
|
|
|
$posYAfterImage=0; |
|
420
|
|
|
$posYAfterDescription=0; |
|
|
|
|
|
|
421
|
|
|
|
|
422
|
|
|
// We start with Photo of product line |
|
423
|
|
|
if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot))) // If photo too high, we moved completely on new page |
|
424
|
|
|
{ |
|
425
|
|
|
$pdf->AddPage('','',true); |
|
426
|
|
|
if (! empty($tplidx)) $pdf->useTemplate($tplidx); |
|
427
|
|
|
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); |
|
428
|
|
|
$pdf->setPage($pageposbefore+1); |
|
429
|
|
|
|
|
430
|
|
|
$curY = $tab_top_newpage; |
|
431
|
|
|
$showpricebeforepagebreak=0; |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
if (isset($imglinesize['width']) && isset($imglinesize['height'])) |
|
435
|
|
|
{ |
|
436
|
|
|
$curX = $this->posxpicture-1; |
|
437
|
|
|
$pdf->Image($realpatharray[$i], $curX + (($this->posxtva-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi |
|
438
|
|
|
// $pdf->Image does not increase value return by getY, so we save it manually |
|
439
|
|
|
$posYAfterImage=$curY+$imglinesize['height']; |
|
440
|
|
|
} |
|
441
|
|
|
|
|
442
|
|
|
// Description of product line |
|
443
|
|
|
$curX = $this->posxdesc-1; |
|
444
|
|
|
|
|
445
|
|
|
$pdf->startTransaction(); |
|
446
|
|
|
pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc); |
|
447
|
|
|
$pageposafter=$pdf->getPage(); |
|
448
|
|
|
if ($pageposafter > $pageposbefore) // There is a pagebreak |
|
449
|
|
|
{ |
|
450
|
|
|
$pdf->rollbackTransaction(true); |
|
451
|
|
|
$pageposafter=$pageposbefore; |
|
|
|
|
|
|
452
|
|
|
//print $pageposafter.'-'.$pageposbefore;exit; |
|
453
|
|
|
$pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. |
|
454
|
|
|
pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc); |
|
455
|
|
|
$pageposafter=$pdf->getPage(); |
|
456
|
|
|
$posyafter=$pdf->GetY(); |
|
457
|
|
|
//var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit; |
|
458
|
|
|
if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text |
|
459
|
|
|
{ |
|
460
|
|
|
if ($i == ($nblignes-1)) // No more lines, and no space left to show total, so we create a new page |
|
461
|
|
|
{ |
|
462
|
|
|
$pdf->AddPage('','',true); |
|
463
|
|
|
if (! empty($tplidx)) $pdf->useTemplate($tplidx); |
|
464
|
|
|
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); |
|
465
|
|
|
$pdf->setPage($pageposafter+1); |
|
466
|
|
|
} |
|
467
|
|
|
} |
|
468
|
|
|
else |
|
469
|
|
|
{ |
|
470
|
|
|
// We found a page break |
|
471
|
|
|
$showpricebeforepagebreak=0; |
|
472
|
|
|
} |
|
473
|
|
|
} |
|
474
|
|
|
else // No pagebreak |
|
475
|
|
|
{ |
|
476
|
|
|
$pdf->commitTransaction(); |
|
477
|
|
|
} |
|
478
|
|
|
$posYAfterDescription=$pdf->GetY(); |
|
479
|
|
|
|
|
480
|
|
|
$nexY = $pdf->GetY(); |
|
481
|
|
|
$pageposafter=$pdf->getPage(); |
|
482
|
|
|
$pdf->setPage($pageposbefore); |
|
483
|
|
|
$pdf->setTopMargin($this->marge_haute); |
|
484
|
|
|
$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. |
|
485
|
|
|
|
|
486
|
|
|
// We suppose that a too long description or photo were moved completely on next page |
|
487
|
|
|
if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { |
|
488
|
|
|
$pdf->setPage($pageposafter); $curY = $tab_top_newpage; |
|
489
|
|
|
} |
|
490
|
|
|
|
|
491
|
|
|
$pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut |
|
492
|
|
|
|
|
493
|
|
|
// VAT Rate |
|
494
|
|
|
if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) |
|
495
|
|
|
{ |
|
496
|
|
|
// Si on ne doit masquer que les sous-produits |
|
497
|
|
|
if ($hidedetails && !$inPackage && $conf->global->SUBTOTAL_ONLY_HIDE_SUBPRODUCTS_PRICES) { |
|
498
|
|
|
$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, 0); |
|
499
|
|
|
} else { |
|
500
|
|
|
$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails); |
|
501
|
|
|
} |
|
502
|
|
|
|
|
503
|
|
|
$pdf->SetXY($this->posxtva, $curY); |
|
504
|
|
|
$pdf->MultiCell($this->posxup-$this->posxtva-0.8, 3, $vat_rate, 0, 'R'); |
|
505
|
|
|
} |
|
506
|
|
|
|
|
507
|
|
|
// Unit price before discount |
|
508
|
|
|
if ($hidedetails && !$inPackage && $conf->global->SUBTOTAL_ONLY_HIDE_SUBPRODUCTS_PRICES) { |
|
509
|
|
|
$up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, 0); |
|
510
|
|
|
} else { |
|
511
|
|
|
$up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails); |
|
512
|
|
|
} |
|
513
|
|
|
|
|
514
|
|
|
$pdf->SetXY($this->posxup, $curY); |
|
515
|
|
|
$pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0); |
|
516
|
|
|
|
|
517
|
|
|
// Quantity |
|
518
|
|
|
// Affichage de la quantité sur les lignes de total si la conf l'indique |
|
519
|
|
|
|
|
520
|
|
|
// Récupération de la quantité à afficher |
|
521
|
|
|
if ($conf->global->SUBTOTAL_IF_HIDE_PRICES_SHOW_QTY && $hidedetails) { |
|
522
|
|
|
if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES && $package_qty > 0) { |
|
523
|
|
|
$qty = $package_qty; |
|
524
|
|
|
} else { |
|
525
|
|
|
$qty = pdf_getlineqty($object, $i, $outputlangs, 0); |
|
526
|
|
|
} |
|
527
|
|
|
} else { |
|
528
|
|
|
if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES && $package_qty > 0) { |
|
529
|
|
|
$qty = $package_qty; |
|
530
|
|
|
} else { |
|
531
|
|
|
$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails); |
|
532
|
|
|
} |
|
533
|
|
|
} |
|
534
|
|
|
|
|
535
|
|
|
$pdf->SetXY($this->posxqty, $curY); |
|
536
|
|
|
$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 3, $qty, 0, 'R'); // Enough for 6 chars |
|
537
|
|
|
|
|
538
|
|
|
// Discount on line |
|
539
|
|
|
if ($object->lines[$i]->remise_percent) |
|
540
|
|
|
{ |
|
541
|
|
|
$pdf->SetXY($this->posxdiscount-2, $curY); |
|
542
|
|
|
$remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails); |
|
543
|
|
|
$pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R'); |
|
544
|
|
|
} |
|
545
|
|
|
|
|
546
|
|
|
// Total HT line |
|
547
|
|
|
if ($hidedetails && !$inPackage && $conf->global->SUBTOTAL_ONLY_HIDE_SUBPRODUCTS_PRICES) { |
|
548
|
|
|
$total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, 0); |
|
549
|
|
|
} else { |
|
550
|
|
|
$total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails); |
|
551
|
|
|
} |
|
552
|
|
|
|
|
553
|
|
|
$pdf->SetXY($this->postotalht, $curY); |
|
554
|
|
|
$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0); |
|
555
|
|
|
|
|
556
|
|
|
// Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva |
|
557
|
|
|
$tvaligne=doubleval($object->lines[$i]->total_tva); |
|
558
|
|
|
$localtax1ligne=$object->lines[$i]->total_localtax1; |
|
559
|
|
|
$localtax2ligne=$object->lines[$i]->total_localtax2; |
|
560
|
|
|
$localtax1_rate=$object->lines[$i]->localtax1_tx; |
|
561
|
|
|
$localtax2_rate=$object->lines[$i]->localtax2_tx; |
|
562
|
|
|
$localtax1_type=$object->lines[$i]->localtax1_type; |
|
563
|
|
|
$localtax2_type=$object->lines[$i]->localtax2_type; |
|
564
|
|
|
|
|
565
|
|
|
if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100; |
|
566
|
|
|
if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100; |
|
567
|
|
|
if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100; |
|
568
|
|
|
|
|
569
|
|
|
$vatrate=(string) $object->lines[$i]->tva_tx; |
|
570
|
|
|
|
|
571
|
|
|
// Retrieve type from database for backward compatibility with old records |
|
572
|
|
|
if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined |
|
573
|
|
|
&& (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax |
|
574
|
|
|
{ |
|
575
|
|
|
$localtaxtmp_array=getLocalTaxesFromRate($vatrate,0, $object->thirdparty, $mysoc); |
|
576
|
|
|
$localtax1_type = $localtaxtmp_array[0]; |
|
577
|
|
|
$localtax2_type = $localtaxtmp_array[2]; |
|
578
|
|
|
} |
|
579
|
|
|
|
|
580
|
|
|
// retrieve global local tax |
|
581
|
|
|
if ($localtax1_type && $localtax1ligne != 0) |
|
582
|
|
|
$this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne; |
|
583
|
|
|
if ($localtax2_type && $localtax2ligne != 0) |
|
584
|
|
|
$this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne; |
|
585
|
|
|
|
|
586
|
|
|
if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*'; |
|
587
|
|
|
if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]=''; |
|
588
|
|
|
|
|
589
|
|
|
if (!empty($object->lines[$i]->TTotal_tva)) |
|
590
|
|
|
{ |
|
591
|
|
|
foreach ($object->lines[$i]->TTotal_tva as $vatrate => $tvaligne) |
|
592
|
|
|
{ |
|
593
|
|
|
$this->tva[$vatrate] += $tvaligne; |
|
594
|
|
|
} |
|
595
|
|
|
} |
|
596
|
|
|
else { |
|
597
|
|
|
// standard |
|
598
|
|
|
if(!empty($tvaligne)) $this->tva[$vatrate] += $tvaligne; |
|
599
|
|
|
} |
|
600
|
|
|
|
|
601
|
|
|
if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage; |
|
602
|
|
|
|
|
603
|
|
|
// Add line |
|
604
|
|
|
if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1)) |
|
605
|
|
|
{ |
|
606
|
|
|
$pdf->setPage($pageposafter); |
|
607
|
|
|
$pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(210,210,210))); |
|
608
|
|
|
//$pdf->SetDrawColor(190,190,200); |
|
609
|
|
|
$pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1); |
|
610
|
|
|
$pdf->SetLineStyle(array('dash'=>0)); |
|
611
|
|
|
} |
|
612
|
|
|
|
|
613
|
|
|
$nexY+=2; // Passe espace entre les lignes |
|
614
|
|
|
|
|
615
|
|
|
// Detect if some page were added automatically and output _tableau for past pages |
|
616
|
|
|
while ($pagenb < $pageposafter) |
|
617
|
|
|
{ |
|
618
|
|
|
$pdf->setPage($pagenb); |
|
619
|
|
|
if ($pagenb == 1) |
|
620
|
|
|
{ |
|
621
|
|
|
$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); |
|
622
|
|
|
} |
|
623
|
|
|
else |
|
624
|
|
|
{ |
|
625
|
|
|
$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); |
|
626
|
|
|
} |
|
627
|
|
|
$this->_pagefoot($pdf,$object,$outputlangs,1); |
|
628
|
|
|
$pagenb++; |
|
629
|
|
|
$pdf->setPage($pagenb); |
|
630
|
|
|
$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. |
|
631
|
|
|
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); |
|
632
|
|
|
} |
|
633
|
|
|
if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak) |
|
634
|
|
|
{ |
|
635
|
|
|
if ($pagenb == 1) |
|
636
|
|
|
{ |
|
637
|
|
|
$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); |
|
638
|
|
|
} |
|
639
|
|
|
else |
|
640
|
|
|
{ |
|
641
|
|
|
$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); |
|
642
|
|
|
} |
|
643
|
|
|
$this->_pagefoot($pdf,$object,$outputlangs,1); |
|
644
|
|
|
// New page |
|
645
|
|
|
$pdf->AddPage(); |
|
646
|
|
|
if (! empty($tplidx)) $pdf->useTemplate($tplidx); |
|
647
|
|
|
$pagenb++; |
|
648
|
|
|
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); |
|
649
|
|
|
} |
|
650
|
|
|
} |
|
651
|
|
|
|
|
652
|
|
|
// Show square |
|
653
|
|
|
if ($pagenb == 1) |
|
654
|
|
|
{ |
|
655
|
|
|
$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); |
|
656
|
|
|
$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; |
|
657
|
|
|
} |
|
658
|
|
|
else |
|
659
|
|
|
{ |
|
660
|
|
|
$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); |
|
661
|
|
|
$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; |
|
662
|
|
|
} |
|
663
|
|
|
|
|
664
|
|
|
// Affiche zone infos |
|
665
|
|
|
$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs); |
|
|
|
|
|
|
666
|
|
|
|
|
667
|
|
|
if (!$conf->global->SUBTOTAL_HIDE_DOCUMENT_TOTAL) { |
|
668
|
|
|
// Affiche zone totaux |
|
669
|
|
|
$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs); |
|
670
|
|
|
} |
|
671
|
|
|
|
|
672
|
|
|
// Affiche zone versements |
|
673
|
|
|
if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) |
|
674
|
|
|
{ |
|
675
|
|
|
$posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs); |
|
|
|
|
|
|
676
|
|
|
} |
|
677
|
|
|
|
|
678
|
|
|
// Pied de page |
|
679
|
|
|
$this->_pagefoot($pdf,$object,$outputlangs); |
|
680
|
|
|
if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages(); |
|
681
|
|
|
|
|
682
|
|
|
$pdf->Close(); |
|
683
|
|
|
|
|
684
|
|
|
$pdf->Output($file,'F'); |
|
685
|
|
|
|
|
686
|
|
|
// Add pdfgeneration hook |
|
687
|
|
|
$hookmanager->initHooks(array('pdfgeneration')); |
|
688
|
|
|
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); |
|
689
|
|
|
global $action; |
|
690
|
|
|
$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
691
|
|
|
|
|
692
|
|
|
if (! empty($conf->global->MAIN_UMASK)) |
|
693
|
|
|
@chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
|
|
|
|
|
694
|
|
|
|
|
695
|
|
|
return 1; // Pas d'erreur |
|
696
|
|
|
} |
|
697
|
|
|
else |
|
698
|
|
|
{ |
|
699
|
|
|
$this->error=$langs->trans("ErrorCanNotCreateDir",$dir); |
|
700
|
|
|
return 0; |
|
701
|
|
|
} |
|
702
|
|
|
} |
|
703
|
|
|
else |
|
704
|
|
|
{ |
|
705
|
|
|
$this->error=$langs->trans("ErrorConstantNotDefined","FAC_OUTPUTDIR"); |
|
706
|
|
|
return 0; |
|
707
|
|
|
} |
|
708
|
|
|
$this->error=$langs->trans("ErrorUnknown"); |
|
|
|
|
|
|
709
|
|
|
return 0; // Erreur par defaut |
|
710
|
|
|
} |
|
711
|
|
|
|
|
712
|
|
|
|
|
713
|
|
|
/** |
|
714
|
|
|
* Show payments table |
|
715
|
|
|
* |
|
716
|
|
|
* @param PDF $pdf Object PDF |
|
717
|
|
|
* @param Object $object Object invoice |
|
718
|
|
|
* @param int $posy Position y in PDF |
|
719
|
|
|
* @param Translate $outputlangs Object langs for output |
|
720
|
|
|
* @return int <0 if KO, >0 if OK |
|
721
|
|
|
*/ |
|
722
|
|
|
function _tableau_versements(&$pdf, $object, $posy, $outputlangs) |
|
|
|
|
|
|
723
|
|
|
{ |
|
724
|
|
|
global $conf; |
|
725
|
|
|
|
|
726
|
|
|
$sign=1; |
|
727
|
|
|
if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1; |
|
728
|
|
|
|
|
729
|
|
|
$tab3_posx = 120; |
|
730
|
|
|
$tab3_top = $posy + 8; |
|
731
|
|
|
$tab3_width = 80; |
|
732
|
|
|
$tab3_height = 4; |
|
733
|
|
|
if ($this->page_largeur < 210) // To work with US executive format |
|
734
|
|
|
{ |
|
735
|
|
|
$tab3_posx -= 20; |
|
736
|
|
|
} |
|
737
|
|
|
|
|
738
|
|
|
$default_font_size = pdf_getPDFFontSize($outputlangs); |
|
739
|
|
|
|
|
740
|
|
|
$title=$outputlangs->transnoentities("PaymentsAlreadyDone"); |
|
741
|
|
|
if ($object->type == 2) $title=$outputlangs->transnoentities("PaymentsBackAlreadyDone"); |
|
742
|
|
|
|
|
743
|
|
|
$pdf->SetFont('','', $default_font_size - 3); |
|
744
|
|
|
$pdf->SetXY($tab3_posx, $tab3_top - 4); |
|
745
|
|
|
$pdf->MultiCell(60, 3, $title, 0, 'L', 0); |
|
746
|
|
|
|
|
747
|
|
|
$pdf->line($tab3_posx, $tab3_top, $tab3_posx+$tab3_width, $tab3_top); |
|
748
|
|
|
|
|
749
|
|
|
$pdf->SetFont('','', $default_font_size - 4); |
|
750
|
|
|
$pdf->SetXY($tab3_posx, $tab3_top); |
|
751
|
|
|
$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0); |
|
752
|
|
|
$pdf->SetXY($tab3_posx+21, $tab3_top); |
|
753
|
|
|
$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0); |
|
754
|
|
|
$pdf->SetXY($tab3_posx+40, $tab3_top); |
|
755
|
|
|
$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0); |
|
756
|
|
|
$pdf->SetXY($tab3_posx+58, $tab3_top); |
|
757
|
|
|
$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0); |
|
758
|
|
|
|
|
759
|
|
|
$pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height); |
|
760
|
|
|
|
|
761
|
|
|
$y=0; |
|
762
|
|
|
|
|
763
|
|
|
$pdf->SetFont('','', $default_font_size - 4); |
|
764
|
|
|
|
|
765
|
|
|
// Loop on each deposits and credit notes included |
|
766
|
|
|
$sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; |
|
767
|
|
|
$sql.= " re.description, re.fk_facture_source,"; |
|
768
|
|
|
$sql.= " f.type, f.datef"; |
|
769
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re, ".MAIN_DB_PREFIX ."facture as f"; |
|
770
|
|
|
$sql.= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".$object->id; |
|
771
|
|
|
$resql=$this->db->query($sql); |
|
772
|
|
|
if ($resql) |
|
773
|
|
|
{ |
|
774
|
|
|
$num = $this->db->num_rows($resql); |
|
|
|
|
|
|
775
|
|
|
$i=0; |
|
776
|
|
|
$invoice=new Facture($this->db); |
|
777
|
|
|
while ($i < $num) |
|
778
|
|
|
{ |
|
779
|
|
|
$y+=3; |
|
780
|
|
|
$obj = $this->db->fetch_object($resql); |
|
|
|
|
|
|
781
|
|
|
|
|
782
|
|
|
if ($obj->type == 2) $text=$outputlangs->trans("CreditNote"); |
|
783
|
|
|
elseif ($obj->type == 3) $text=$outputlangs->trans("Deposit"); |
|
784
|
|
|
else $text=$outputlangs->trans("UnknownType"); |
|
785
|
|
|
|
|
786
|
|
|
$invoice->fetch($obj->fk_facture_source); |
|
787
|
|
|
|
|
788
|
|
|
$pdf->SetXY($tab3_posx, $tab3_top+$y); |
|
789
|
|
|
$pdf->MultiCell(20, 3, dol_print_date($obj->datef,'day',false,$outputlangs,true), 0, 'L', 0); |
|
|
|
|
|
|
790
|
|
|
$pdf->SetXY($tab3_posx+21, $tab3_top+$y); |
|
791
|
|
|
$pdf->MultiCell(20, 3, price($obj->amount_ttc, 0, $outputlangs), 0, 'L', 0); |
|
792
|
|
|
$pdf->SetXY($tab3_posx+40, $tab3_top+$y); |
|
793
|
|
|
$pdf->MultiCell(20, 3, $text, 0, 'L', 0); |
|
794
|
|
|
$pdf->SetXY($tab3_posx+58, $tab3_top+$y); |
|
795
|
|
|
$pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0); |
|
796
|
|
|
|
|
797
|
|
|
$pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3); |
|
798
|
|
|
|
|
799
|
|
|
$i++; |
|
800
|
|
|
} |
|
801
|
|
|
} |
|
802
|
|
|
else |
|
803
|
|
|
{ |
|
804
|
|
|
$this->error=$this->db->lasterror(); |
|
805
|
|
|
return -1; |
|
806
|
|
|
} |
|
807
|
|
|
|
|
808
|
|
|
// Loop on each payment |
|
809
|
|
|
$sql = "SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num, pf.amount as amount,"; |
|
810
|
|
|
$sql.= " cp.code"; |
|
811
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; |
|
812
|
|
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id"; |
|
813
|
|
|
$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".$object->id; |
|
814
|
|
|
$sql.= " ORDER BY p.datep"; |
|
815
|
|
|
$resql=$this->db->query($sql); |
|
816
|
|
|
if ($resql) |
|
817
|
|
|
{ |
|
818
|
|
|
$num = $this->db->num_rows($resql); |
|
819
|
|
|
$i=0; |
|
820
|
|
|
while ($i < $num) { |
|
821
|
|
|
$y+=3; |
|
822
|
|
|
$row = $this->db->fetch_object($resql); |
|
823
|
|
|
|
|
824
|
|
|
$pdf->SetXY($tab3_posx, $tab3_top+$y); |
|
825
|
|
|
$pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date),'day',false,$outputlangs,true), 0, 'L', 0); |
|
|
|
|
|
|
826
|
|
|
$pdf->SetXY($tab3_posx+21, $tab3_top+$y); |
|
827
|
|
|
$pdf->MultiCell(20, 3, price($sign * $row->amount, 0, $outputlangs), 0, 'L', 0); |
|
828
|
|
|
$pdf->SetXY($tab3_posx+40, $tab3_top+$y); |
|
829
|
|
|
$oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort" . $row->code); |
|
830
|
|
|
|
|
831
|
|
|
$pdf->MultiCell(20, 3, $oper, 0, 'L', 0); |
|
832
|
|
|
$pdf->SetXY($tab3_posx+58, $tab3_top+$y); |
|
833
|
|
|
$pdf->MultiCell(30, 3, $row->num, 0, 'L', 0); |
|
834
|
|
|
|
|
835
|
|
|
$pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3); |
|
836
|
|
|
|
|
837
|
|
|
$i++; |
|
838
|
|
|
} |
|
839
|
|
|
} |
|
840
|
|
|
else |
|
841
|
|
|
{ |
|
842
|
|
|
$this->error=$this->db->lasterror(); |
|
843
|
|
|
return -1; |
|
844
|
|
|
} |
|
845
|
|
|
|
|
846
|
|
|
} |
|
847
|
|
|
|
|
848
|
|
|
|
|
849
|
|
|
/** |
|
850
|
|
|
* Show miscellaneous information (payment mode, payment term, ...) |
|
851
|
|
|
* |
|
852
|
|
|
* @param PDF $pdf Object PDF |
|
853
|
|
|
* @param Object $object Object to show |
|
854
|
|
|
* @param int $posy Y |
|
855
|
|
|
* @param Translate $outputlangs Langs object |
|
856
|
|
|
* @return void |
|
857
|
|
|
*/ |
|
858
|
|
|
function _tableau_info(&$pdf, $object, $posy, $outputlangs) |
|
|
|
|
|
|
859
|
|
|
{ |
|
860
|
|
|
global $conf; |
|
861
|
|
|
|
|
862
|
|
|
$default_font_size = pdf_getPDFFontSize($outputlangs); |
|
863
|
|
|
|
|
864
|
|
|
$pdf->SetFont('','', $default_font_size - 1); |
|
865
|
|
|
|
|
866
|
|
|
// If France, show VAT mention if not applicable |
|
867
|
|
|
if ($this->emetteur->country_code == 'FR' && $this->franchise == 1) |
|
868
|
|
|
{ |
|
869
|
|
|
$pdf->SetFont('','B', $default_font_size - 2); |
|
870
|
|
|
$pdf->SetXY($this->marge_gauche, $posy); |
|
871
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0); |
|
872
|
|
|
|
|
873
|
|
|
$posy=$pdf->GetY()+4; |
|
874
|
|
|
} |
|
875
|
|
|
|
|
876
|
|
|
$posxval=52; |
|
877
|
|
|
|
|
878
|
|
|
// Show payments conditions |
|
879
|
|
|
if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) |
|
880
|
|
|
{ |
|
881
|
|
|
$pdf->SetFont('','B', $default_font_size - 2); |
|
882
|
|
|
$pdf->SetXY($this->marge_gauche, $posy); |
|
883
|
|
|
$titre = $outputlangs->transnoentities("PaymentConditions").':'; |
|
884
|
|
|
$pdf->MultiCell(80, 4, $titre, 0, 'L'); |
|
885
|
|
|
|
|
886
|
|
|
$pdf->SetFont('','', $default_font_size - 2); |
|
887
|
|
|
$pdf->SetXY($posxval, $posy); |
|
888
|
|
|
$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); |
|
889
|
|
|
$lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement); |
|
890
|
|
|
$pdf->MultiCell(80, 4, $lib_condition_paiement,0,'L'); |
|
891
|
|
|
|
|
892
|
|
|
$posy=$pdf->GetY()+3; |
|
893
|
|
|
} |
|
894
|
|
|
|
|
895
|
|
|
if ($object->type != 2) |
|
896
|
|
|
{ |
|
897
|
|
|
// Check a payment mode is defined |
|
898
|
|
|
if (empty($object->mode_reglement_code) |
|
899
|
|
|
&& empty($conf->global->FACTURE_CHQ_NUMBER) |
|
900
|
|
|
&& empty($conf->global->FACTURE_RIB_NUMBER)) |
|
901
|
|
|
{ |
|
902
|
|
|
$this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"); |
|
903
|
|
|
} |
|
904
|
|
|
// Avoid having any valid PDF with setup that is not complete |
|
905
|
|
|
elseif (($object->mode_reglement_code == 'CHQ' && empty($conf->global->FACTURE_CHQ_NUMBER)) |
|
906
|
|
|
|| ($object->mode_reglement_code == 'VIR' && empty($conf->global->FACTURE_RIB_NUMBER))) |
|
907
|
|
|
{ |
|
908
|
|
|
$outputlangs->load("errors"); |
|
909
|
|
|
|
|
910
|
|
|
$pdf->SetXY($this->marge_gauche, $posy); |
|
911
|
|
|
$pdf->SetTextColor(200,0,0); |
|
912
|
|
|
$pdf->SetFont('','B', $default_font_size - 2); |
|
913
|
|
|
$this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup",$object->mode_reglement_code); |
|
914
|
|
|
$pdf->MultiCell(80, 3, $this->error,0,'L',0); |
|
915
|
|
|
$pdf->SetTextColor(0,0,0); |
|
916
|
|
|
|
|
917
|
|
|
$posy=$pdf->GetY()+1; |
|
918
|
|
|
} |
|
919
|
|
|
|
|
920
|
|
|
// Show payment mode |
|
921
|
|
|
if ($object->mode_reglement_code |
|
922
|
|
|
&& $object->mode_reglement_code != 'CHQ' |
|
923
|
|
|
&& $object->mode_reglement_code != 'VIR') |
|
924
|
|
|
{ |
|
925
|
|
|
$pdf->SetFont('','B', $default_font_size - 2); |
|
926
|
|
|
$pdf->SetXY($this->marge_gauche, $posy); |
|
927
|
|
|
$titre = $outputlangs->transnoentities("PaymentMode").':'; |
|
928
|
|
|
$pdf->MultiCell(80, 5, $titre, 0, 'L'); |
|
929
|
|
|
|
|
930
|
|
|
$pdf->SetFont('','', $default_font_size - 2); |
|
931
|
|
|
$pdf->SetXY($posxval, $posy); |
|
932
|
|
|
$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); |
|
933
|
|
|
$pdf->MultiCell(80, 5, $lib_mode_reg,0,'L'); |
|
934
|
|
|
|
|
935
|
|
|
$posy=$pdf->GetY()+2; |
|
936
|
|
|
} |
|
937
|
|
|
|
|
938
|
|
|
// Show payment mode CHQ |
|
939
|
|
|
if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') |
|
940
|
|
|
{ |
|
941
|
|
|
// Si mode reglement non force ou si force a CHQ |
|
942
|
|
|
if (! empty($conf->global->FACTURE_CHQ_NUMBER)) |
|
943
|
|
|
{ |
|
944
|
|
|
$diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE); |
|
945
|
|
|
|
|
946
|
|
|
if ($conf->global->FACTURE_CHQ_NUMBER > 0) |
|
947
|
|
|
{ |
|
948
|
|
|
$account = new Account($this->db); |
|
949
|
|
|
$account->fetch($conf->global->FACTURE_CHQ_NUMBER); |
|
950
|
|
|
|
|
951
|
|
|
$pdf->SetXY($this->marge_gauche, $posy); |
|
952
|
|
|
$pdf->SetFont('','B', $default_font_size - $diffsizetitle); |
|
953
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio),0,'L',0); |
|
954
|
|
|
$posy=$pdf->GetY()+1; |
|
955
|
|
|
|
|
956
|
|
|
if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) |
|
957
|
|
|
{ |
|
958
|
|
|
$pdf->SetXY($this->marge_gauche, $posy); |
|
959
|
|
|
$pdf->SetFont('','', $default_font_size - $diffsizetitle); |
|
960
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0); |
|
961
|
|
|
$posy=$pdf->GetY()+2; |
|
962
|
|
|
} |
|
963
|
|
|
} |
|
964
|
|
|
if ($conf->global->FACTURE_CHQ_NUMBER == -1) |
|
965
|
|
|
{ |
|
966
|
|
|
$pdf->SetXY($this->marge_gauche, $posy); |
|
967
|
|
|
$pdf->SetFont('','B', $default_font_size - $diffsizetitle); |
|
968
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$this->emetteur->name),0,'L',0); |
|
969
|
|
|
$posy=$pdf->GetY()+1; |
|
970
|
|
|
|
|
971
|
|
|
if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) |
|
972
|
|
|
{ |
|
973
|
|
|
$pdf->SetXY($this->marge_gauche, $posy); |
|
974
|
|
|
$pdf->SetFont('','', $default_font_size - $diffsizetitle); |
|
975
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0); |
|
976
|
|
|
$posy=$pdf->GetY()+2; |
|
977
|
|
|
} |
|
978
|
|
|
} |
|
979
|
|
|
} |
|
980
|
|
|
} |
|
981
|
|
|
|
|
982
|
|
|
// If payment mode not forced or forced to VIR, show payment with BAN |
|
983
|
|
|
if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') |
|
984
|
|
|
{ |
|
985
|
|
|
if (! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER)) |
|
986
|
|
|
{ |
|
987
|
|
|
$bankid=(empty($object->fk_bank)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_bank); |
|
988
|
|
|
$account = new Account($this->db); |
|
989
|
|
|
$account->fetch($bankid); |
|
990
|
|
|
|
|
991
|
|
|
$curx=$this->marge_gauche; |
|
992
|
|
|
$cury=$posy; |
|
993
|
|
|
|
|
994
|
|
|
$posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size); |
|
995
|
|
|
|
|
996
|
|
|
$posy+=2; |
|
997
|
|
|
} |
|
998
|
|
|
} |
|
999
|
|
|
} |
|
1000
|
|
|
|
|
1001
|
|
|
return $posy; |
|
1002
|
|
|
} |
|
1003
|
|
|
|
|
1004
|
|
|
|
|
1005
|
|
|
/** |
|
1006
|
|
|
* Show total to pay |
|
1007
|
|
|
* |
|
1008
|
|
|
* @param PDF $pdf Object PDF |
|
1009
|
|
|
* @param Facture $object Object invoice |
|
1010
|
|
|
* @param int $deja_regle Montant deja regle |
|
1011
|
|
|
* @param int $posy Position depart |
|
1012
|
|
|
* @param Translate $outputlangs Objet langs |
|
1013
|
|
|
* @return int Position pour suite |
|
1014
|
|
|
*/ |
|
1015
|
|
|
function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs) |
|
|
|
|
|
|
1016
|
|
|
{ |
|
1017
|
|
|
global $conf,$mysoc; |
|
1018
|
|
|
|
|
1019
|
|
|
$sign=1; |
|
1020
|
|
|
if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1; |
|
1021
|
|
|
|
|
1022
|
|
|
$default_font_size = pdf_getPDFFontSize($outputlangs); |
|
1023
|
|
|
|
|
1024
|
|
|
$tab2_top = $posy; |
|
1025
|
|
|
$tab2_hl = 4; |
|
1026
|
|
|
$pdf->SetFont('','', $default_font_size - 1); |
|
1027
|
|
|
|
|
1028
|
|
|
// Tableau total |
|
1029
|
|
|
$col1x = 120; $col2x = 170; |
|
1030
|
|
|
if ($this->page_largeur < 210) // To work with US executive format |
|
1031
|
|
|
{ |
|
1032
|
|
|
$col2x-=20; |
|
1033
|
|
|
} |
|
1034
|
|
|
$largcol2 = ($this->page_largeur - $this->marge_droite - $col2x); |
|
1035
|
|
|
|
|
1036
|
|
|
$useborder=0; |
|
1037
|
|
|
$index = 0; |
|
1038
|
|
|
|
|
1039
|
|
|
// Total HT |
|
1040
|
|
|
$pdf->SetFillColor(255,255,255); |
|
1041
|
|
|
$pdf->SetXY($col1x, $tab2_top + 0); |
|
1042
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1); |
|
1043
|
|
|
$pdf->SetXY($col2x, $tab2_top + 0); |
|
1044
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($object->total_ht + (! empty($object->remise)?$object->remise:0)), 0, $outputlangs), 0, 'R', 1); |
|
|
|
|
|
|
1045
|
|
|
|
|
1046
|
|
|
// Show VAT by rates and total |
|
1047
|
|
|
$pdf->SetFillColor(248,248,248); |
|
1048
|
|
|
|
|
1049
|
|
|
$this->atleastoneratenotnull=0; |
|
1050
|
|
|
if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) |
|
1051
|
|
|
{ |
|
1052
|
|
|
$tvaisnull=((! empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false); |
|
1053
|
|
|
if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_ISNULL) && $tvaisnull) |
|
1054
|
|
|
{ |
|
1055
|
|
|
// Nothing to do |
|
1056
|
|
|
} |
|
1057
|
|
|
else |
|
1058
|
|
|
{ |
|
1059
|
|
|
//Local tax 1 before VAT |
|
1060
|
|
|
//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on') |
|
1061
|
|
|
//{ |
|
1062
|
|
|
foreach( $this->localtax1 as $localtax_type => $localtax_rate ) |
|
1063
|
|
|
{ |
|
1064
|
|
|
if (in_array((string) $localtax_type, array('1','3','5'))) continue; |
|
1065
|
|
|
|
|
1066
|
|
|
foreach( $localtax_rate as $tvakey => $tvaval ) |
|
1067
|
|
|
{ |
|
1068
|
|
|
if ($tvakey!=0) // On affiche pas taux 0 |
|
1069
|
|
|
{ |
|
1070
|
|
|
//$this->atleastoneratenotnull++; |
|
1071
|
|
|
|
|
1072
|
|
|
$index++; |
|
1073
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
|
1074
|
|
|
|
|
1075
|
|
|
$tvacompl=''; |
|
1076
|
|
|
if (preg_match('/\*/',$tvakey)) |
|
1077
|
|
|
{ |
|
1078
|
|
|
$tvakey=str_replace('*','',$tvakey); |
|
1079
|
|
|
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; |
|
1080
|
|
|
} |
|
1081
|
|
|
|
|
1082
|
|
|
$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' '; |
|
1083
|
|
|
$totalvat.=vatrate(abs($tvakey),1).$tvacompl; |
|
1084
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1); |
|
1085
|
|
|
|
|
1086
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
|
1087
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1); |
|
1088
|
|
|
} |
|
1089
|
|
|
} |
|
1090
|
|
|
} |
|
1091
|
|
|
//} |
|
1092
|
|
|
//Local tax 2 before VAT |
|
1093
|
|
|
//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on') |
|
1094
|
|
|
//{ |
|
1095
|
|
|
foreach( $this->localtax2 as $localtax_type => $localtax_rate ) |
|
1096
|
|
|
{ |
|
1097
|
|
|
if (in_array((string) $localtax_type, array('1','3','5'))) continue; |
|
1098
|
|
|
|
|
1099
|
|
|
foreach( $localtax_rate as $tvakey => $tvaval ) |
|
1100
|
|
|
{ |
|
1101
|
|
|
if ($tvakey!=0) // On affiche pas taux 0 |
|
1102
|
|
|
{ |
|
1103
|
|
|
//$this->atleastoneratenotnull++; |
|
1104
|
|
|
|
|
1105
|
|
|
|
|
1106
|
|
|
|
|
1107
|
|
|
$index++; |
|
1108
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
|
1109
|
|
|
|
|
1110
|
|
|
$tvacompl=''; |
|
1111
|
|
|
if (preg_match('/\*/',$tvakey)) |
|
1112
|
|
|
{ |
|
1113
|
|
|
$tvakey=str_replace('*','',$tvakey); |
|
1114
|
|
|
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; |
|
1115
|
|
|
} |
|
1116
|
|
|
$totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' '; |
|
1117
|
|
|
$totalvat.=vatrate(abs($tvakey),1).$tvacompl; |
|
1118
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1); |
|
1119
|
|
|
|
|
1120
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
|
1121
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1); |
|
1122
|
|
|
|
|
1123
|
|
|
} |
|
1124
|
|
|
} |
|
1125
|
|
|
} |
|
1126
|
|
|
//} |
|
1127
|
|
|
// VAT |
|
1128
|
|
|
foreach($this->tva as $tvakey => $tvaval) |
|
1129
|
|
|
{ |
|
1130
|
|
|
if ($tvakey > 0) // On affiche pas taux 0 |
|
1131
|
|
|
{ |
|
1132
|
|
|
$this->atleastoneratenotnull++; |
|
1133
|
|
|
|
|
1134
|
|
|
$index++; |
|
1135
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
|
1136
|
|
|
|
|
1137
|
|
|
$tvacompl=''; |
|
1138
|
|
|
if (preg_match('/\*/',$tvakey)) |
|
1139
|
|
|
{ |
|
1140
|
|
|
$tvakey=str_replace('*','',$tvakey); |
|
1141
|
|
|
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; |
|
1142
|
|
|
} |
|
1143
|
|
|
$totalvat =$outputlangs->transnoentities("TotalVAT").' '; |
|
1144
|
|
|
$totalvat.=vatrate($tvakey,1).$tvacompl; |
|
1145
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1); |
|
1146
|
|
|
|
|
1147
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
|
1148
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1); |
|
1149
|
|
|
} |
|
1150
|
|
|
} |
|
1151
|
|
|
|
|
1152
|
|
|
//Local tax 1 after VAT |
|
1153
|
|
|
//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on') |
|
1154
|
|
|
//{ |
|
1155
|
|
|
foreach( $this->localtax1 as $localtax_type => $localtax_rate ) |
|
1156
|
|
|
{ |
|
1157
|
|
|
if (in_array((string) $localtax_type, array('2','4','6'))) continue; |
|
1158
|
|
|
|
|
1159
|
|
|
foreach( $localtax_rate as $tvakey => $tvaval ) |
|
1160
|
|
|
{ |
|
1161
|
|
|
if ($tvakey != 0) // On affiche pas taux 0 |
|
1162
|
|
|
{ |
|
1163
|
|
|
//$this->atleastoneratenotnull++; |
|
1164
|
|
|
|
|
1165
|
|
|
$index++; |
|
1166
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
|
1167
|
|
|
|
|
1168
|
|
|
$tvacompl=''; |
|
1169
|
|
|
if (preg_match('/\*/',$tvakey)) |
|
1170
|
|
|
{ |
|
1171
|
|
|
$tvakey=str_replace('*','',$tvakey); |
|
1172
|
|
|
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; |
|
1173
|
|
|
} |
|
1174
|
|
|
$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' '; |
|
1175
|
|
|
$totalvat.=vatrate(abs($tvakey),1).$tvacompl; |
|
1176
|
|
|
|
|
1177
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1); |
|
1178
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
|
1179
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1); |
|
1180
|
|
|
} |
|
1181
|
|
|
} |
|
1182
|
|
|
} |
|
1183
|
|
|
//} |
|
1184
|
|
|
//Local tax 2 after VAT |
|
1185
|
|
|
//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on') |
|
1186
|
|
|
//{ |
|
1187
|
|
|
foreach( $this->localtax2 as $localtax_type => $localtax_rate ) |
|
1188
|
|
|
{ |
|
1189
|
|
|
if (in_array((string) $localtax_type, array('2','4','6'))) continue; |
|
1190
|
|
|
|
|
1191
|
|
|
foreach( $localtax_rate as $tvakey => $tvaval ) |
|
1192
|
|
|
{ |
|
1193
|
|
|
// retrieve global local tax |
|
1194
|
|
|
if ($tvakey != 0) // On affiche pas taux 0 |
|
1195
|
|
|
{ |
|
1196
|
|
|
//$this->atleastoneratenotnull++; |
|
1197
|
|
|
|
|
1198
|
|
|
$index++; |
|
1199
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
|
1200
|
|
|
|
|
1201
|
|
|
$tvacompl=''; |
|
1202
|
|
|
if (preg_match('/\*/',$tvakey)) |
|
1203
|
|
|
{ |
|
1204
|
|
|
$tvakey=str_replace('*','',$tvakey); |
|
1205
|
|
|
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; |
|
1206
|
|
|
} |
|
1207
|
|
|
$totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' '; |
|
1208
|
|
|
|
|
1209
|
|
|
$totalvat.=vatrate(abs($tvakey),1).$tvacompl; |
|
1210
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1); |
|
1211
|
|
|
|
|
1212
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
|
1213
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1); |
|
1214
|
|
|
} |
|
1215
|
|
|
} |
|
1216
|
|
|
//} |
|
1217
|
|
|
} |
|
1218
|
|
|
|
|
1219
|
|
|
// Revenue stamp |
|
1220
|
|
|
if (price2num($object->revenuestamp) != 0) |
|
1221
|
|
|
{ |
|
1222
|
|
|
$index++; |
|
1223
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
|
1224
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp"), $useborder, 'L', 1); |
|
1225
|
|
|
|
|
1226
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
|
1227
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1); |
|
1228
|
|
|
} |
|
1229
|
|
|
|
|
1230
|
|
|
// Total TTC |
|
1231
|
|
|
$index++; |
|
1232
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
|
1233
|
|
|
$pdf->SetTextColor(0,0,60); |
|
1234
|
|
|
$pdf->SetFillColor(224,224,224); |
|
1235
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1); |
|
1236
|
|
|
|
|
1237
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
|
1238
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->total_ttc, 0, $outputlangs), $useborder, 'R', 1); |
|
1239
|
|
|
} |
|
1240
|
|
|
} |
|
1241
|
|
|
|
|
1242
|
|
|
$pdf->SetTextColor(0,0,0); |
|
1243
|
|
|
|
|
1244
|
|
|
$creditnoteamount=$object->getSumCreditNotesUsed(); |
|
1245
|
|
|
$depositsamount=$object->getSumDepositsUsed(); |
|
1246
|
|
|
//print "x".$creditnoteamount."-".$depositsamount;exit; |
|
1247
|
|
|
$resteapayer = price2num($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT'); |
|
1248
|
|
|
if ($object->paye) $resteapayer=0; |
|
1249
|
|
|
|
|
1250
|
|
|
if ($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) |
|
1251
|
|
|
{ |
|
1252
|
|
|
// Already paid + Deposits |
|
1253
|
|
|
$index++; |
|
1254
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
|
1255
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0); |
|
1256
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
|
1257
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0); |
|
1258
|
|
|
|
|
1259
|
|
|
// Credit note |
|
1260
|
|
|
if ($creditnoteamount) |
|
1261
|
|
|
{ |
|
1262
|
|
|
$index++; |
|
1263
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
|
1264
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("CreditNotes"), 0, 'L', 0); |
|
1265
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
|
1266
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0); |
|
1267
|
|
|
} |
|
1268
|
|
|
|
|
1269
|
|
|
// Escompte |
|
1270
|
|
|
if ($object->close_code == 'discount_vat') |
|
1271
|
|
|
{ |
|
1272
|
|
|
$index++; |
|
1273
|
|
|
$pdf->SetFillColor(255,255,255); |
|
1274
|
|
|
|
|
1275
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
|
1276
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOffered"), $useborder, 'L', 1); |
|
1277
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
|
1278
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1); |
|
1279
|
|
|
|
|
1280
|
|
|
$resteapayer=0; |
|
1281
|
|
|
} |
|
1282
|
|
|
|
|
1283
|
|
|
$index++; |
|
1284
|
|
|
$pdf->SetTextColor(0,0,60); |
|
1285
|
|
|
$pdf->SetFillColor(224,224,224); |
|
1286
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
|
1287
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1); |
|
1288
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
|
1289
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1); |
|
|
|
|
|
|
1290
|
|
|
|
|
1291
|
|
|
$pdf->SetFont('','', $default_font_size - 1); |
|
1292
|
|
|
$pdf->SetTextColor(0,0,0); |
|
1293
|
|
|
} |
|
1294
|
|
|
|
|
1295
|
|
|
$index++; |
|
1296
|
|
|
return ($tab2_top + ($tab2_hl * $index)); |
|
1297
|
|
|
} |
|
1298
|
|
|
|
|
1299
|
|
|
/** |
|
1300
|
|
|
* Show table for lines |
|
1301
|
|
|
* |
|
1302
|
|
|
* @param PDF $pdf Object PDF |
|
1303
|
|
|
* @param string $tab_top Top position of table |
|
1304
|
|
|
* @param string $tab_height Height of table (rectangle) |
|
1305
|
|
|
* @param int $nexY Y (not used) |
|
1306
|
|
|
* @param Translate $outputlangs Langs object |
|
1307
|
|
|
* @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title |
|
1308
|
|
|
* @param int $hidebottom Hide bottom bar of array |
|
1309
|
|
|
* @return void |
|
1310
|
|
|
*/ |
|
1311
|
|
|
function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0) |
|
|
|
|
|
|
1312
|
|
|
{ |
|
1313
|
|
|
global $conf; |
|
1314
|
|
|
|
|
1315
|
|
|
// Force to disable hidetop and hidebottom |
|
1316
|
|
|
$hidebottom=0; |
|
1317
|
|
|
if ($hidetop) $hidetop=-1; |
|
1318
|
|
|
|
|
1319
|
|
|
$default_font_size = pdf_getPDFFontSize($outputlangs); |
|
1320
|
|
|
|
|
1321
|
|
|
// Amount in (at tab_top - 1) |
|
1322
|
|
|
$pdf->SetTextColor(0,0,0); |
|
1323
|
|
|
$pdf->SetFont('','', $default_font_size - 2); |
|
1324
|
|
|
|
|
1325
|
|
|
if (empty($hidetop)) |
|
1326
|
|
|
{ |
|
1327
|
|
|
$titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$conf->currency)); |
|
1328
|
|
|
$pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4); |
|
1329
|
|
|
$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre); |
|
1330
|
|
|
|
|
1331
|
|
|
//$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230'; |
|
1332
|
|
|
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)); |
|
1333
|
|
|
} |
|
1334
|
|
|
|
|
1335
|
|
|
$pdf->SetDrawColor(128,128,128); |
|
1336
|
|
|
$pdf->SetFont('','', $default_font_size - 1); |
|
1337
|
|
|
|
|
1338
|
|
|
// Output Rect |
|
1339
|
|
|
$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 |
|
|
|
|
|
|
1340
|
|
|
|
|
1341
|
|
|
if (empty($hidetop)) |
|
1342
|
|
|
{ |
|
1343
|
|
|
$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 |
|
1344
|
|
|
|
|
1345
|
|
|
$pdf->SetXY($this->posxdesc-1, $tab_top+1); |
|
1346
|
|
|
$pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L'); |
|
1347
|
|
|
} |
|
1348
|
|
|
|
|
1349
|
|
|
if (! empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) |
|
1350
|
|
|
{ |
|
1351
|
|
|
$pdf->line($this->posxpicture-1, $tab_top, $this->posxpicture-1, $tab_top + $tab_height); |
|
1352
|
|
|
if (empty($hidetop)) |
|
1353
|
|
|
{ |
|
1354
|
|
|
//$pdf->SetXY($this->posxpicture-1, $tab_top+1); |
|
1355
|
|
|
//$pdf->MultiCell($this->posxtva-$this->posxpicture-1,2, $outputlangs->transnoentities("Photo"),'','C'); |
|
1356
|
|
|
} |
|
1357
|
|
|
} |
|
1358
|
|
|
|
|
1359
|
|
|
if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) |
|
1360
|
|
|
{ |
|
1361
|
|
|
$pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height); |
|
1362
|
|
|
if (empty($hidetop)) |
|
1363
|
|
|
{ |
|
1364
|
|
|
$pdf->SetXY($this->posxtva-3, $tab_top+1); |
|
1365
|
|
|
$pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C'); |
|
1366
|
|
|
} |
|
1367
|
|
|
} |
|
1368
|
|
|
|
|
1369
|
|
|
$pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height); |
|
1370
|
|
|
if (empty($hidetop)) |
|
1371
|
|
|
{ |
|
1372
|
|
|
$pdf->SetXY($this->posxup-1, $tab_top+1); |
|
1373
|
|
|
$pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C'); |
|
1374
|
|
|
} |
|
1375
|
|
|
|
|
1376
|
|
|
$pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height); |
|
1377
|
|
|
if (empty($hidetop)) |
|
1378
|
|
|
{ |
|
1379
|
|
|
$pdf->SetXY($this->posxqty-1, $tab_top+1); |
|
1380
|
|
|
$pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C'); |
|
1381
|
|
|
} |
|
1382
|
|
|
|
|
1383
|
|
|
$pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height); |
|
1384
|
|
|
if (empty($hidetop)) |
|
1385
|
|
|
{ |
|
1386
|
|
|
if ($this->atleastonediscount) |
|
1387
|
|
|
{ |
|
1388
|
|
|
$pdf->SetXY($this->posxdiscount-1, $tab_top+1); |
|
1389
|
|
|
$pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C'); |
|
1390
|
|
|
} |
|
1391
|
|
|
} |
|
1392
|
|
|
if ($this->atleastonediscount) |
|
1393
|
|
|
{ |
|
1394
|
|
|
$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height); |
|
1395
|
|
|
} |
|
1396
|
|
|
if (empty($hidetop)) |
|
1397
|
|
|
{ |
|
1398
|
|
|
$pdf->SetXY($this->postotalht-1, $tab_top+1); |
|
1399
|
|
|
$pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHT"),'','C'); |
|
1400
|
|
|
} |
|
1401
|
|
|
} |
|
1402
|
|
|
|
|
1403
|
|
|
/** |
|
1404
|
|
|
* Show top header of page. |
|
1405
|
|
|
* |
|
1406
|
|
|
* @param PDF $pdf Object PDF |
|
1407
|
|
|
* @param Object $object Object to show |
|
1408
|
|
|
* @param int $showaddress 0=no, 1=yes |
|
1409
|
|
|
* @param Translate $outputlangs Object lang for output |
|
1410
|
|
|
* @return void |
|
1411
|
|
|
*/ |
|
1412
|
|
|
function _pagehead(&$pdf, $object, $showaddress, $outputlangs) |
|
|
|
|
|
|
1413
|
|
|
{ |
|
1414
|
|
|
global $conf,$langs; |
|
1415
|
|
|
|
|
1416
|
|
|
$outputlangs->load("main"); |
|
1417
|
|
|
$outputlangs->load("bills"); |
|
1418
|
|
|
$outputlangs->load("propal"); |
|
1419
|
|
|
$outputlangs->load("companies"); |
|
1420
|
|
|
|
|
1421
|
|
|
$default_font_size = pdf_getPDFFontSize($outputlangs); |
|
1422
|
|
|
|
|
1423
|
|
|
pdf_pagehead($pdf,$outputlangs,$this->page_hauteur); |
|
1424
|
|
|
|
|
1425
|
|
|
// Show Draft Watermark |
|
1426
|
|
|
if($object->statut==0 && (! empty($conf->global->FACTURE_DRAFT_WATERMARK)) ) |
|
1427
|
|
|
{ |
|
1428
|
|
|
pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->FACTURE_DRAFT_WATERMARK); |
|
1429
|
|
|
} |
|
1430
|
|
|
|
|
1431
|
|
|
$pdf->SetTextColor(0,0,60); |
|
1432
|
|
|
$pdf->SetFont('','B', $default_font_size + 3); |
|
1433
|
|
|
|
|
1434
|
|
|
$posy=$this->marge_haute; |
|
1435
|
|
|
$posx=$this->page_largeur-$this->marge_droite-100; |
|
1436
|
|
|
|
|
1437
|
|
|
$pdf->SetXY($this->marge_gauche,$posy); |
|
1438
|
|
|
|
|
1439
|
|
|
// Logo |
|
1440
|
|
|
$logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo; |
|
1441
|
|
|
if ($this->emetteur->logo) |
|
1442
|
|
|
{ |
|
1443
|
|
|
if (is_readable($logo)) |
|
1444
|
|
|
{ |
|
1445
|
|
|
$height=pdf_getHeightForLogo($logo); |
|
1446
|
|
|
$pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) |
|
1447
|
|
|
} |
|
1448
|
|
|
else |
|
1449
|
|
|
{ |
|
1450
|
|
|
$pdf->SetTextColor(200,0,0); |
|
1451
|
|
|
$pdf->SetFont('','B',$default_font_size - 2); |
|
1452
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L'); |
|
1453
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L'); |
|
1454
|
|
|
} |
|
1455
|
|
|
} |
|
1456
|
|
|
else |
|
1457
|
|
|
{ |
|
1458
|
|
|
$text=$this->emetteur->name; |
|
1459
|
|
|
$pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L'); |
|
1460
|
|
|
} |
|
1461
|
|
|
|
|
1462
|
|
|
$pdf->SetFont('','B', $default_font_size + 3); |
|
1463
|
|
|
$pdf->SetXY($posx,$posy); |
|
1464
|
|
|
$pdf->SetTextColor(0,0,60); |
|
1465
|
|
|
$title=$outputlangs->transnoentities("Invoice"); |
|
1466
|
|
|
if ($object->type == 1) $title=$outputlangs->transnoentities("InvoiceReplacement"); |
|
1467
|
|
|
if ($object->type == 2) $title=$outputlangs->transnoentities("InvoiceAvoir"); |
|
1468
|
|
|
if ($object->type == 3) $title=$outputlangs->transnoentities("InvoiceDeposit"); |
|
1469
|
|
|
if ($object->type == 4) $title=$outputlangs->transnoentities("InvoiceProFormat"); |
|
1470
|
|
|
$pdf->MultiCell(100, 3, $title, '', 'R'); |
|
1471
|
|
|
|
|
1472
|
|
|
$pdf->SetFont('','B',$default_font_size); |
|
1473
|
|
|
|
|
1474
|
|
|
$posy+=5; |
|
1475
|
|
|
$pdf->SetXY($posx,$posy); |
|
1476
|
|
|
$pdf->SetTextColor(0,0,60); |
|
1477
|
|
|
$pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R'); |
|
1478
|
|
|
|
|
1479
|
|
|
$posy+=1; |
|
1480
|
|
|
$pdf->SetFont('','', $default_font_size - 2); |
|
1481
|
|
|
|
|
1482
|
|
|
if ($object->ref_client) |
|
1483
|
|
|
{ |
|
1484
|
|
|
$posy+=4; |
|
1485
|
|
|
$pdf->SetXY($posx,$posy); |
|
1486
|
|
|
$pdf->SetTextColor(0,0,60); |
|
1487
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R'); |
|
1488
|
|
|
} |
|
1489
|
|
|
|
|
1490
|
|
|
$objectidnext=$object->getIdReplacingInvoice('validated'); |
|
1491
|
|
|
if ($object->type == 0 && $objectidnext) |
|
1492
|
|
|
{ |
|
1493
|
|
|
$objectreplacing=new Facture($this->db); |
|
1494
|
|
|
$objectreplacing->fetch($objectidnext); |
|
1495
|
|
|
|
|
1496
|
|
|
$posy+=3; |
|
1497
|
|
|
$pdf->SetXY($posx,$posy); |
|
1498
|
|
|
$pdf->SetTextColor(0,0,60); |
|
1499
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R'); |
|
1500
|
|
|
} |
|
1501
|
|
|
if ($object->type == 1) |
|
1502
|
|
|
{ |
|
1503
|
|
|
$objectreplaced=new Facture($this->db); |
|
1504
|
|
|
$objectreplaced->fetch($object->fk_facture_source); |
|
1505
|
|
|
|
|
1506
|
|
|
$posy+=4; |
|
1507
|
|
|
$pdf->SetXY($posx,$posy); |
|
1508
|
|
|
$pdf->SetTextColor(0,0,60); |
|
1509
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R'); |
|
1510
|
|
|
} |
|
1511
|
|
|
if ($object->type == 2) |
|
1512
|
|
|
{ |
|
1513
|
|
|
$objectreplaced=new Facture($this->db); |
|
1514
|
|
|
$objectreplaced->fetch($object->fk_facture_source); |
|
1515
|
|
|
|
|
1516
|
|
|
$posy+=3; |
|
1517
|
|
|
$pdf->SetXY($posx,$posy); |
|
1518
|
|
|
$pdf->SetTextColor(0,0,60); |
|
1519
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R'); |
|
1520
|
|
|
} |
|
1521
|
|
|
|
|
1522
|
|
|
$posy+=4; |
|
1523
|
|
|
$pdf->SetXY($posx,$posy); |
|
1524
|
|
|
$pdf->SetTextColor(0,0,60); |
|
1525
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateInvoice")." : " . dol_print_date($object->date,"day",false,$outputlangs), '', 'R'); |
|
|
|
|
|
|
1526
|
|
|
|
|
1527
|
|
|
if ($object->type != 2) |
|
1528
|
|
|
{ |
|
1529
|
|
|
$posy+=3; |
|
1530
|
|
|
$pdf->SetXY($posx,$posy); |
|
1531
|
|
|
$pdf->SetTextColor(0,0,60); |
|
1532
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateEcheance")." : " . dol_print_date($object->date_lim_reglement,"day",false,$outputlangs,true), '', 'R'); |
|
1533
|
|
|
} |
|
1534
|
|
|
|
|
1535
|
|
|
if ($object->thirdparty->code_client) |
|
1536
|
|
|
{ |
|
1537
|
|
|
$posy+=3; |
|
1538
|
|
|
$pdf->SetXY($posx,$posy); |
|
1539
|
|
|
$pdf->SetTextColor(0,0,60); |
|
1540
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R'); |
|
1541
|
|
|
} |
|
1542
|
|
|
|
|
1543
|
|
|
$posy+=1; |
|
1544
|
|
|
|
|
1545
|
|
|
// Show list of linked objects |
|
1546
|
|
|
$posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size); |
|
|
|
|
|
|
1547
|
|
|
|
|
1548
|
|
|
if ($showaddress) |
|
1549
|
|
|
{ |
|
1550
|
|
|
// Sender properties |
|
1551
|
|
|
$carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty); |
|
1552
|
|
|
|
|
1553
|
|
|
// Show sender |
|
1554
|
|
|
$posy=42; |
|
1555
|
|
|
$posx=$this->marge_gauche; |
|
1556
|
|
|
if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80; |
|
1557
|
|
|
$hautcadre=40; |
|
1558
|
|
|
|
|
1559
|
|
|
// Show sender frame |
|
1560
|
|
|
$pdf->SetTextColor(0,0,0); |
|
1561
|
|
|
$pdf->SetFont('','', $default_font_size - 2); |
|
1562
|
|
|
$pdf->SetXY($posx,$posy-5); |
|
1563
|
|
|
$pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L'); |
|
1564
|
|
|
$pdf->SetXY($posx,$posy); |
|
1565
|
|
|
$pdf->SetFillColor(230,230,230); |
|
1566
|
|
|
$pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1); |
|
1567
|
|
|
$pdf->SetTextColor(0,0,60); |
|
1568
|
|
|
|
|
1569
|
|
|
// Show sender name |
|
1570
|
|
|
$pdf->SetXY($posx+2,$posy+3); |
|
1571
|
|
|
$pdf->SetFont('','B', $default_font_size); |
|
1572
|
|
|
$pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L'); |
|
1573
|
|
|
$posy=$pdf->getY(); |
|
1574
|
|
|
|
|
1575
|
|
|
// Show sender information |
|
1576
|
|
|
$pdf->SetXY($posx+2,$posy); |
|
1577
|
|
|
$pdf->SetFont('','', $default_font_size - 1); |
|
1578
|
|
|
$pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L'); |
|
1579
|
|
|
|
|
1580
|
|
|
|
|
1581
|
|
|
|
|
1582
|
|
|
// If BILLING contact defined on invoice, we use it |
|
1583
|
|
|
$usecontact=false; |
|
1584
|
|
|
$arrayidcontact=$object->getIdContact('external','BILLING'); |
|
1585
|
|
|
if (count($arrayidcontact) > 0) |
|
1586
|
|
|
{ |
|
1587
|
|
|
$usecontact=true; |
|
1588
|
|
|
$result=$object->fetch_contact($arrayidcontact[0]); |
|
|
|
|
|
|
1589
|
|
|
} |
|
1590
|
|
|
|
|
1591
|
|
|
// Recipient name |
|
1592
|
|
|
if (! empty($usecontact)) |
|
1593
|
|
|
{ |
|
1594
|
|
|
// On peut utiliser le nom de la societe du contact |
|
1595
|
|
|
if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socname = $object->contact->socname; |
|
1596
|
|
|
else $socname = $object->thirdparty->name; |
|
1597
|
|
|
$carac_client_name=$outputlangs->convToOutputCharset($socname); |
|
1598
|
|
|
} |
|
1599
|
|
|
else |
|
1600
|
|
|
{ |
|
1601
|
|
|
$carac_client_name=$outputlangs->convToOutputCharset($object->thirdparty->name); |
|
1602
|
|
|
} |
|
1603
|
|
|
|
|
1604
|
|
|
$carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target'); |
|
|
|
|
|
|
1605
|
|
|
|
|
1606
|
|
|
// Show recipient |
|
1607
|
|
|
$widthrecbox=100; |
|
1608
|
|
|
if ($this->page_largeur < 210) $widthrecbox=84; // To work with US executive format |
|
1609
|
|
|
$posy=42; |
|
1610
|
|
|
$posx=$this->page_largeur-$this->marge_droite-$widthrecbox; |
|
1611
|
|
|
if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche; |
|
1612
|
|
|
|
|
1613
|
|
|
// Show recipient frame |
|
1614
|
|
|
$pdf->SetTextColor(0,0,0); |
|
1615
|
|
|
$pdf->SetFont('','', $default_font_size - 2); |
|
1616
|
|
|
$pdf->SetXY($posx+2,$posy-5); |
|
1617
|
|
|
$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":",0,'L'); |
|
1618
|
|
|
$pdf->Rect($posx, $posy, $widthrecbox, $hautcadre); |
|
1619
|
|
|
|
|
1620
|
|
|
// Show recipient name |
|
1621
|
|
|
$pdf->SetXY($posx+2,$posy+3); |
|
1622
|
|
|
$pdf->SetFont('','B', $default_font_size); |
|
1623
|
|
|
$pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L'); |
|
1624
|
|
|
|
|
1625
|
|
|
// Show recipient information |
|
1626
|
|
|
$pdf->SetFont('','', $default_font_size - 1); |
|
1627
|
|
|
$pdf->SetXY($posx+2,$posy+4+(dol_nboflines_bis($carac_client_name,50)*4)); |
|
1628
|
|
|
$pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L'); |
|
1629
|
|
|
} |
|
1630
|
|
|
|
|
1631
|
|
|
$pdf->SetTextColor(0,0,0); |
|
1632
|
|
|
} |
|
1633
|
|
|
|
|
1634
|
|
|
/** |
|
1635
|
|
|
* Show footer of page. Need this->emetteur object |
|
1636
|
|
|
* |
|
1637
|
|
|
* @param PDF $pdf PDF |
|
1638
|
|
|
* @param Object $object Object to show |
|
1639
|
|
|
* @param Translate $outputlangs Object lang for output |
|
1640
|
|
|
* @param int $hidefreetext 1=Hide free text |
|
1641
|
|
|
* @return int Return height of bottom margin including footer text |
|
1642
|
|
|
*/ |
|
1643
|
|
|
function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0) |
|
|
|
|
|
|
1644
|
|
|
{ |
|
1645
|
|
|
$showdetails=0; |
|
1646
|
|
|
$free_text = (float)DOL_VERSION > 3.8 ? 'INVOICE_FREE_TEXT' : 'FACTURE_FREE_TEXT'; |
|
1647
|
|
|
return pdf_pagefoot($pdf,$outputlangs,$free_text,$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext); |
|
1648
|
|
|
} |
|
1649
|
|
|
|
|
1650
|
|
|
} |
|
1651
|
|
|
|
|
1652
|
|
|
|
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.