|
1
|
|
|
<?php |
|
2
|
|
|
/* Copyright (C) 2006-2011 Laurent Destailleur <[email protected]> |
|
3
|
|
|
* Copyright (C) 2006 Rodolphe Quiedeville <[email protected]> |
|
4
|
|
|
* Copyright (C) 2007 Patrick Raguin <[email protected]> |
|
5
|
|
|
* Copyright (C) 2010-2012 Regis Houssin <[email protected]> |
|
6
|
|
|
* Copyright (C) 2010 Juanjo Menent <[email protected]> |
|
7
|
|
|
* Copyright (C) 2012 Christophe Battarel <[email protected]> |
|
8
|
|
|
* Copyright (C) 2012 Cédric Salvador <[email protected]> |
|
9
|
|
|
* Copyright (C) 2012-2015 Raphaël Doursenaud <[email protected]> |
|
10
|
|
|
* Copyright (C) 2014 Cedric GROSS <[email protected]> |
|
11
|
|
|
* Copyright (C) 2014 Teddy Andreotti <[email protected]> |
|
12
|
|
|
* Copyright (C) 2015 Marcos García <[email protected]> |
|
13
|
|
|
* |
|
14
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
15
|
|
|
* it under the terms of the GNU General Public License as published by |
|
16
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
17
|
|
|
* (at your option) any later version. |
|
18
|
|
|
* |
|
19
|
|
|
* This program is distributed in the hope that it will be useful, |
|
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22
|
|
|
* GNU General Public License for more details. |
|
23
|
|
|
* |
|
24
|
|
|
* You should have received a copy of the GNU General Public License |
|
25
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
26
|
|
|
* or see http://www.gnu.org/ |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* \file htdocs/core/lib/pdf.lib.php |
|
31
|
|
|
* \brief Set of functions used for PDF generation |
|
32
|
|
|
* \ingroup core |
|
33
|
|
|
*/ |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Return array with format properties of default PDF format |
|
38
|
|
|
* |
|
39
|
|
|
* @param Translate $outputlangs Output lang to use to autodetect output format if setup not done |
|
40
|
|
|
* @return array Array('width'=>w,'height'=>h,'unit'=>u); |
|
41
|
|
|
*/ |
|
42
|
|
|
function pdf_getFormat($outputlangs='') |
|
43
|
|
|
{ |
|
44
|
|
|
global $conf,$db; |
|
45
|
|
|
|
|
46
|
|
|
// Default value if setup was not done and/or entry into c_paper_format not defined |
|
47
|
|
|
$width=210; $height=297; $unit='mm'; |
|
48
|
|
|
|
|
49
|
|
|
if (empty($conf->global->MAIN_PDF_FORMAT)) |
|
50
|
|
|
{ |
|
51
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
|
52
|
|
|
$pdfformat=dol_getDefaultFormat($outputlangs); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
else $pdfformat=$conf->global->MAIN_PDF_FORMAT; |
|
55
|
|
|
|
|
56
|
|
|
$sql="SELECT code, label, width, height, unit FROM ".MAIN_DB_PREFIX."c_paper_format"; |
|
57
|
|
|
$sql.=" WHERE code = '".$pdfformat."'"; |
|
58
|
|
|
$resql=$db->query($sql); |
|
59
|
|
|
if ($resql) |
|
60
|
|
|
{ |
|
61
|
|
|
$obj=$db->fetch_object($resql); |
|
62
|
|
|
if ($obj) |
|
63
|
|
|
{ |
|
64
|
|
|
$width=(int) $obj->width; |
|
65
|
|
|
$height=(int) $obj->height; |
|
66
|
|
|
$unit=$obj->unit; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
//print "pdfformat=".$pdfformat." width=".$width." height=".$height." unit=".$unit; |
|
71
|
|
|
return array('width'=>$width,'height'=>$height,'unit'=>$unit); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Return a PDF instance object. We create a FPDI instance that instantiate TCPDF. |
|
76
|
|
|
* |
|
77
|
|
|
* @param string $format Array(width,height). Keep empty to use default setup. |
|
78
|
|
|
* @param string $metric Unit of format ('mm') |
|
79
|
|
|
* @param string $pagetype 'P' or 'l' |
|
80
|
|
|
* @return TPDF PDF object |
|
|
|
|
|
|
81
|
|
|
*/ |
|
82
|
|
|
function pdf_getInstance($format='',$metric='mm',$pagetype='P') |
|
83
|
|
|
{ |
|
84
|
|
|
global $conf; |
|
85
|
|
|
|
|
86
|
|
|
// Define constant for TCPDF |
|
87
|
|
|
if (! defined('K_TCPDF_EXTERNAL_CONFIG')) |
|
88
|
|
|
{ |
|
89
|
|
|
define('K_TCPDF_EXTERNAL_CONFIG',1); // this avoid using tcpdf_config file |
|
90
|
|
|
define('K_PATH_CACHE', DOL_DATA_ROOT.'/admin/temp/'); |
|
91
|
|
|
define('K_PATH_URL_CACHE', DOL_DATA_ROOT.'/admin/temp/'); |
|
92
|
|
|
dol_mkdir(K_PATH_CACHE); |
|
93
|
|
|
define('K_BLANK_IMAGE', '_blank.png'); |
|
94
|
|
|
define('PDF_PAGE_FORMAT', 'A4'); |
|
95
|
|
|
define('PDF_PAGE_ORIENTATION', 'P'); |
|
96
|
|
|
define('PDF_CREATOR', 'TCPDF'); |
|
97
|
|
|
define('PDF_AUTHOR', 'TCPDF'); |
|
98
|
|
|
define('PDF_HEADER_TITLE', 'TCPDF Example'); |
|
99
|
|
|
define('PDF_HEADER_STRING', "by Dolibarr ERP CRM"); |
|
100
|
|
|
define('PDF_UNIT', 'mm'); |
|
101
|
|
|
define('PDF_MARGIN_HEADER', 5); |
|
102
|
|
|
define('PDF_MARGIN_FOOTER', 10); |
|
103
|
|
|
define('PDF_MARGIN_TOP', 27); |
|
104
|
|
|
define('PDF_MARGIN_BOTTOM', 25); |
|
105
|
|
|
define('PDF_MARGIN_LEFT', 15); |
|
106
|
|
|
define('PDF_MARGIN_RIGHT', 15); |
|
107
|
|
|
define('PDF_FONT_NAME_MAIN', 'helvetica'); |
|
108
|
|
|
define('PDF_FONT_SIZE_MAIN', 10); |
|
109
|
|
|
define('PDF_FONT_NAME_DATA', 'helvetica'); |
|
110
|
|
|
define('PDF_FONT_SIZE_DATA', 8); |
|
111
|
|
|
define('PDF_FONT_MONOSPACED', 'courier'); |
|
112
|
|
|
define('PDF_IMAGE_SCALE_RATIO', 1.25); |
|
113
|
|
|
define('HEAD_MAGNIFICATION', 1.1); |
|
114
|
|
|
define('K_CELL_HEIGHT_RATIO', 1.25); |
|
115
|
|
|
define('K_TITLE_MAGNIFICATION', 1.3); |
|
116
|
|
|
define('K_SMALL_RATIO', 2/3); |
|
117
|
|
|
define('K_THAI_TOPCHARS', true); |
|
118
|
|
|
define('K_TCPDF_CALLS_IN_HTML', true); |
|
119
|
|
|
define('K_TCPDF_THROW_EXCEPTION_ERROR', false); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
if (! empty($conf->global->MAIN_USE_FPDF) && ! empty($conf->global->MAIN_DISABLE_FPDI)) |
|
123
|
|
|
return "Error MAIN_USE_FPDF and MAIN_DISABLE_FPDI can't be set together"; |
|
124
|
|
|
|
|
125
|
|
|
// We use by default TCPDF else FPDF |
|
126
|
|
|
if (empty($conf->global->MAIN_USE_FPDF)) require_once TCPDF_PATH.'tcpdf.php'; |
|
127
|
|
|
else require_once FPDF_PATH.'fpdf.php'; |
|
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
// We need to instantiate tcpdi or fpdi object (instead of tcpdf) to use merging features. But we can disable it (this will break all merge features). |
|
130
|
|
|
if (empty($conf->global->MAIN_DISABLE_TCPDI)) require_once TCPDI_PATH.'tcpdi.php'; |
|
131
|
|
|
else if (empty($conf->global->MAIN_DISABLE_FPDI)) require_once FPDI_PATH.'fpdi.php'; |
|
|
|
|
|
|
132
|
|
|
|
|
133
|
|
|
//$arrayformat=pdf_getFormat(); |
|
134
|
|
|
//$format=array($arrayformat['width'],$arrayformat['height']); |
|
135
|
|
|
//$metric=$arrayformat['unit']; |
|
136
|
|
|
|
|
137
|
|
|
// Protection and encryption of pdf |
|
138
|
|
|
if (empty($conf->global->MAIN_USE_FPDF) && ! empty($conf->global->PDF_SECURITY_ENCRYPTION)) |
|
139
|
|
|
{ |
|
140
|
|
|
/* Permission supported by TCPDF |
|
141
|
|
|
- print : Print the document; |
|
142
|
|
|
- modify : Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble'; |
|
143
|
|
|
- copy : Copy or otherwise extract text and graphics from the document; |
|
144
|
|
|
- annot-forms : Add or modify text annotations, fill in interactive form fields, and, if 'modify' is also set, create or modify interactive form fields (including signature fields); |
|
145
|
|
|
- fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified; |
|
146
|
|
|
- extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes); |
|
147
|
|
|
- assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set; |
|
148
|
|
|
- print-high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality. |
|
149
|
|
|
- owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions. |
|
150
|
|
|
*/ |
|
151
|
|
|
if (class_exists('TCPDI')) $pdf = new TCPDI($pagetype,$metric,$format); |
|
152
|
|
|
else if (class_exists('FPDI')) $pdf = new FPDI($pagetype,$metric,$format); |
|
153
|
|
|
else $pdf = new TCPDF($pagetype,$metric,$format); |
|
154
|
|
|
// For TCPDF, we specify permission we want to block |
|
155
|
|
|
$pdfrights = array('modify','copy'); |
|
156
|
|
|
|
|
157
|
|
|
$pdfuserpass = ''; // Password for the end user |
|
158
|
|
|
$pdfownerpass = NULL; // Password of the owner, created randomly if not defined |
|
159
|
|
|
$pdf->SetProtection($pdfrights,$pdfuserpass,$pdfownerpass); |
|
160
|
|
|
} |
|
161
|
|
|
else |
|
162
|
|
|
{ |
|
163
|
|
|
if (class_exists('TCPDI')) $pdf = new TCPDI($pagetype,$metric,$format); |
|
164
|
|
|
else if (class_exists('FPDI')) $pdf = new FPDI($pagetype,$metric,$format); |
|
165
|
|
|
else $pdf = new TCPDF($pagetype,$metric,$format); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
// If we use FPDF class, we may need to add method writeHTMLCell |
|
169
|
|
|
if (! empty($conf->global->MAIN_USE_FPDF) && ! method_exists($pdf, 'writeHTMLCell')) |
|
170
|
|
|
{ |
|
171
|
|
|
// Declare here a class to overwrite FPDI to add method writeHTMLCell |
|
172
|
|
|
/** |
|
173
|
|
|
* This class is an enhanced FPDI class that support method writeHTMLCell |
|
174
|
|
|
*/ |
|
175
|
|
|
class FPDI_DolExtended extends FPDI |
|
176
|
|
|
{ |
|
177
|
|
|
/** |
|
178
|
|
|
* __call |
|
179
|
|
|
* |
|
180
|
|
|
* @param string $method Method |
|
181
|
|
|
* @param mixed $args Arguments |
|
182
|
|
|
* @return void |
|
183
|
|
|
*/ |
|
184
|
|
|
public function __call($method, $args) |
|
185
|
|
|
{ |
|
186
|
|
|
if (isset($this->$method)) { |
|
187
|
|
|
$func = $this->$method; |
|
188
|
|
|
$func($args); |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* writeHTMLCell |
|
194
|
|
|
* |
|
195
|
|
|
* @param int $w Width |
|
196
|
|
|
* @param int $h Height |
|
197
|
|
|
* @param int $x X |
|
198
|
|
|
* @param int $y Y |
|
199
|
|
|
* @param string $html Html |
|
200
|
|
|
* @param int $border Border |
|
201
|
|
|
* @param int $ln Ln |
|
202
|
|
|
* @param boolean $fill Fill |
|
203
|
|
|
* @param boolean $reseth Reseth |
|
204
|
|
|
* @param string $align Align |
|
205
|
|
|
* @param boolean $autopadding Autopadding |
|
206
|
|
|
* @return void |
|
207
|
|
|
*/ |
|
208
|
|
|
public function writeHTMLCell($w, $h, $x, $y, $html = '', $border = 0, $ln = 0, $fill = false, $reseth = true, $align = '', $autopadding = true) |
|
209
|
|
|
{ |
|
210
|
|
|
$this->SetXY($x,$y); |
|
211
|
|
|
$val=str_replace('<br>',"\n",$html); |
|
212
|
|
|
//$val=dol_string_nohtmltag($val,false,'ISO-8859-1'); |
|
213
|
|
|
$val=dol_string_nohtmltag($val,false,'UTF-8'); |
|
|
|
|
|
|
214
|
|
|
$this->MultiCell($w,$h,$val,$border,$align,$fill); |
|
215
|
|
|
} |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
$pdf2=new FPDI_DolExtended($pagetype,$metric,$format); |
|
219
|
|
|
unset($pdf); |
|
220
|
|
|
$pdf=$pdf2; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
return $pdf; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* Return font name to use for PDF generation |
|
229
|
|
|
* |
|
230
|
|
|
* @param Translate $outputlangs Output langs object |
|
231
|
|
|
* @return string Name of font to use |
|
232
|
|
|
*/ |
|
233
|
|
|
function pdf_getPDFFont($outputlangs) |
|
234
|
|
|
{ |
|
235
|
|
|
global $conf; |
|
236
|
|
|
|
|
237
|
|
|
if (! empty($conf->global->MAIN_PDF_FORCE_FONT)) return $conf->global->MAIN_PDF_FORCE_FONT; |
|
238
|
|
|
|
|
239
|
|
|
$font='Helvetica'; // By default, for FPDI, or ISO language on TCPDF |
|
240
|
|
|
if (class_exists('TCPDF')) // If TCPDF on, we can use an UTF8 one like DejaVuSans if required (slower) |
|
241
|
|
|
{ |
|
242
|
|
|
if ($outputlangs->trans('FONTFORPDF')!='FONTFORPDF') |
|
243
|
|
|
{ |
|
244
|
|
|
$font=$outputlangs->trans('FONTFORPDF'); |
|
245
|
|
|
} |
|
246
|
|
|
} |
|
247
|
|
|
return $font; |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* Return font size to use for PDF generation |
|
252
|
|
|
* |
|
253
|
|
|
* @param Translate $outputlangs Output langs object |
|
254
|
|
|
* @return int Size of font to use |
|
255
|
|
|
*/ |
|
256
|
|
|
function pdf_getPDFFontSize($outputlangs) |
|
257
|
|
|
{ |
|
258
|
|
|
$size=10; // By default, for FPDI or ISO language on TCPDF |
|
259
|
|
|
if (class_exists('TCPDF')) // If TCPDF on, we can use an UTF8 one like DejaVuSans if required (slower) |
|
260
|
|
|
{ |
|
261
|
|
|
if ($outputlangs->trans('FONTSIZEFORPDF')!='FONTSIZEFORPDF') |
|
262
|
|
|
{ |
|
263
|
|
|
$size = (int) $outputlangs->trans('FONTSIZEFORPDF'); |
|
264
|
|
|
} |
|
265
|
|
|
} |
|
266
|
|
|
return $size; |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
|
|
270
|
|
|
/** |
|
271
|
|
|
* Return height to use for Logo onto PDF |
|
272
|
|
|
* |
|
273
|
|
|
* @param string $logo Full path to logo file to use |
|
274
|
|
|
* @param bool $url Image with url (true or false) |
|
275
|
|
|
* @return number |
|
276
|
|
|
*/ |
|
277
|
|
|
function pdf_getHeightForLogo($logo, $url = false) |
|
278
|
|
|
{ |
|
279
|
|
|
global $conf; |
|
280
|
|
|
$height=(empty($conf->global->MAIN_DOCUMENTS_LOGO_HEIGHT)?22:$conf->global->MAIN_DOCUMENTS_LOGO_HEIGHT); |
|
281
|
|
|
$maxwidth=130; |
|
282
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; |
|
283
|
|
|
$tmp=dol_getImageSize($logo, $url); |
|
284
|
|
|
if ($tmp['height']) |
|
285
|
|
|
{ |
|
286
|
|
|
$width=round($height*$tmp['width']/$tmp['height']); |
|
287
|
|
|
if ($width > $maxwidth) $height=$height*$maxwidth/$width; |
|
288
|
|
|
} |
|
289
|
|
|
//print $tmp['width'].' '.$tmp['height'].' '.$width; exit; |
|
290
|
|
|
return $height; |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
/** |
|
294
|
|
|
* Returns the name of the thirdparty |
|
295
|
|
|
* |
|
296
|
|
|
* @param Societe|Contact $thirdparty Contact or thirdparty |
|
297
|
|
|
* @param Translate $outputlangs Output language |
|
298
|
|
|
* @return string |
|
299
|
|
|
*/ |
|
300
|
|
|
function pdfBuildThirdpartyName($thirdparty, Translate $outputlangs) |
|
301
|
|
|
{ |
|
302
|
|
|
//Recipient name |
|
303
|
|
|
$socname = ''; |
|
304
|
|
|
// On peut utiliser le nom de la societe du contact |
|
305
|
|
|
if ($thirdparty instanceof Societe) { |
|
306
|
|
|
if (!empty($thirdparty->name_alias)) { |
|
307
|
|
|
$socname = $thirdparty->name_alias."\n"; |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
|
$socname .= $thirdparty->name; |
|
311
|
|
|
} elseif ($thirdparty instanceof Contact) { |
|
|
|
|
|
|
312
|
|
|
$socname = $thirdparty->socname; |
|
313
|
|
|
} else { |
|
314
|
|
|
throw new InvalidArgumentException(); |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
return $outputlangs->convToOutputCharset($socname); |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
/** |
|
321
|
|
|
* Return a string with full address formated |
|
322
|
|
|
* |
|
323
|
|
|
* @param Translate $outputlangs Output langs object |
|
324
|
|
|
* @param Societe $sourcecompany Source company object |
|
325
|
|
|
* @param Societe $targetcompany Target company object |
|
326
|
|
|
* @param Contact $targetcontact Target contact object |
|
327
|
|
|
* @param int $usecontact Use contact instead of company |
|
328
|
|
|
* @param int $mode Address type ('source', 'target', 'targetwithdetails') |
|
329
|
|
|
* @return string String with full address |
|
330
|
|
|
*/ |
|
331
|
|
|
function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$targetcontact='',$usecontact=0,$mode='source') |
|
332
|
|
|
{ |
|
333
|
|
|
global $conf; |
|
334
|
|
|
$stringaddress = ''; |
|
335
|
|
|
|
|
336
|
|
|
if ($mode == 'source' && ! is_object($sourcecompany)) return -1; |
|
337
|
|
|
if ($mode == 'target' && ! is_object($targetcompany)) return -1; |
|
338
|
|
|
if ($mode == 'delivery' && ! is_object($deliverycompany)) return -1; |
|
|
|
|
|
|
339
|
|
|
|
|
340
|
|
|
if (! empty($sourcecompany->state_id) && empty($sourcecompany->departement)) $sourcecompany->departement=getState($sourcecompany->state_id); //TODO: Deprecated |
|
|
|
|
|
|
341
|
|
|
if (! empty($sourcecompany->state_id) && empty($sourcecompany->state)) $sourcecompany->state=getState($sourcecompany->state_id); |
|
|
|
|
|
|
342
|
|
|
if (! empty($targetcompany->state_id) && empty($targetcompany->departement)) $targetcompany->departement=getState($targetcompany->state_id); |
|
|
|
|
|
|
343
|
|
|
|
|
344
|
|
|
if ($mode == 'source') |
|
345
|
|
|
{ |
|
346
|
|
|
$withCountry = 0; |
|
347
|
|
|
if (!empty($sourcecompany->country_code) && ($targetcompany->country_code != $sourcecompany->country_code)) $withCountry = 1; |
|
348
|
|
|
|
|
349
|
|
|
$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($sourcecompany, $withCountry, "\n", $outputlangs))."\n"; |
|
350
|
|
|
|
|
351
|
|
|
if (empty($conf->global->MAIN_PDF_DISABLESOURCEDETAILS)) |
|
352
|
|
|
{ |
|
353
|
|
|
// Phone |
|
354
|
|
|
if ($sourcecompany->phone) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("PhoneShort").": ".$outputlangs->convToOutputCharset($sourcecompany->phone); |
|
355
|
|
|
// Fax |
|
356
|
|
|
if ($sourcecompany->fax) $stringaddress .= ($stringaddress ? ($sourcecompany->phone ? " - " : "\n") : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($sourcecompany->fax); |
|
357
|
|
|
// EMail |
|
358
|
|
|
if ($sourcecompany->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($sourcecompany->email); |
|
359
|
|
|
// Web |
|
360
|
|
|
if ($sourcecompany->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($sourcecompany->url); |
|
361
|
|
|
} |
|
362
|
|
|
} |
|
363
|
|
|
|
|
364
|
|
|
if ($mode == 'target' || $mode == 'targetwithdetails') |
|
365
|
|
|
{ |
|
366
|
|
|
if ($usecontact) |
|
367
|
|
|
{ |
|
368
|
|
|
$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($targetcontact->getFullName($outputlangs,1)); |
|
369
|
|
|
|
|
370
|
|
|
if (!empty($targetcontact->address)) { |
|
371
|
|
|
$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($targetcontact))."\n"; |
|
|
|
|
|
|
372
|
|
|
}else { |
|
373
|
|
|
$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($targetcompany))."\n"; |
|
374
|
|
|
} |
|
375
|
|
|
// Country |
|
376
|
|
|
if (!empty($targetcontact->country_code) && $targetcontact->country_code != $sourcecompany->country_code) { |
|
377
|
|
|
$stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcontact->country_code))."\n"; |
|
378
|
|
|
} |
|
379
|
|
|
else if (empty($targetcontact->country_code) && !empty($targetcompany->country_code) && ($targetcompany->country_code != $sourcecompany->country_code)) { |
|
380
|
|
|
$stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->country_code))."\n"; |
|
381
|
|
|
} |
|
382
|
|
|
|
|
383
|
|
|
if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails') |
|
384
|
|
|
{ |
|
385
|
|
|
// Phone |
|
386
|
|
|
if (! empty($targetcontact->phone_pro) || ! empty($targetcontact->phone_mobile)) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": "; |
|
387
|
|
|
if (! empty($targetcontact->phone_pro)) $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_pro); |
|
388
|
|
|
if (! empty($targetcontact->phone_pro) && ! empty($targetcontact->phone_mobile)) $stringaddress .= " / "; |
|
389
|
|
|
if (! empty($targetcontact->phone_mobile)) $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_mobile); |
|
390
|
|
|
// Fax |
|
391
|
|
|
if ($targetcontact->fax) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($targetcontact->fax); |
|
392
|
|
|
// EMail |
|
393
|
|
|
if ($targetcontact->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($targetcontact->email); |
|
394
|
|
|
// Web |
|
395
|
|
|
if ($targetcontact->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($targetcontact->url); |
|
|
|
|
|
|
396
|
|
|
} |
|
397
|
|
|
} |
|
398
|
|
|
else |
|
399
|
|
|
{ |
|
400
|
|
|
$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($targetcompany))."\n"; |
|
401
|
|
|
// Country |
|
402
|
|
|
if (!empty($targetcompany->country_code) && $targetcompany->country_code != $sourcecompany->country_code) $stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->country_code))."\n"; |
|
403
|
|
|
|
|
404
|
|
|
if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails') |
|
405
|
|
|
{ |
|
406
|
|
|
// Phone |
|
407
|
|
|
if (! empty($targetcompany->phone) || ! empty($targetcompany->phone_mobile)) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": "; |
|
408
|
|
|
if (! empty($targetcompany->phone)) $stringaddress .= $outputlangs->convToOutputCharset($targetcompany->phone); |
|
409
|
|
|
if (! empty($targetcompany->phone) && ! empty($targetcompany->phone_mobile)) $stringaddress .= " / "; |
|
410
|
|
|
if (! empty($targetcompany->phone_mobile)) $stringaddress .= $outputlangs->convToOutputCharset($targetcompany->phone_mobile); |
|
|
|
|
|
|
411
|
|
|
// Fax |
|
412
|
|
|
if ($targetcompany->fax) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($targetcompany->fax); |
|
413
|
|
|
// EMail |
|
414
|
|
|
if ($targetcompany->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($targetcompany->email); |
|
415
|
|
|
// Web |
|
416
|
|
|
if ($targetcompany->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($targetcompany->url); |
|
417
|
|
|
} |
|
418
|
|
|
} |
|
419
|
|
|
|
|
420
|
|
|
// Intra VAT |
|
421
|
|
|
if (empty($conf->global->MAIN_TVAINTRA_NOT_IN_ADDRESS)) |
|
422
|
|
|
{ |
|
423
|
|
|
if ($targetcompany->tva_intra) $stringaddress.="\n".$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($targetcompany->tva_intra); |
|
424
|
|
|
} |
|
425
|
|
|
|
|
426
|
|
|
// Professionnal Ids |
|
427
|
|
|
if (! empty($conf->global->MAIN_PROFID1_IN_ADDRESS) && ! empty($targetcompany->idprof1)) |
|
428
|
|
|
{ |
|
429
|
|
|
$tmp=$outputlangs->transcountrynoentities("ProfId1",$targetcompany->country_code); |
|
430
|
|
|
if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1]; |
|
431
|
|
|
$stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof1); |
|
432
|
|
|
} |
|
433
|
|
|
if (! empty($conf->global->MAIN_PROFID2_IN_ADDRESS) && ! empty($targetcompany->idprof2)) |
|
434
|
|
|
{ |
|
435
|
|
|
$tmp=$outputlangs->transcountrynoentities("ProfId2",$targetcompany->country_code); |
|
436
|
|
|
if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1]; |
|
437
|
|
|
$stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof2); |
|
438
|
|
|
} |
|
439
|
|
|
if (! empty($conf->global->MAIN_PROFID3_IN_ADDRESS) && ! empty($targetcompany->idprof3)) |
|
440
|
|
|
{ |
|
441
|
|
|
$tmp=$outputlangs->transcountrynoentities("ProfId3",$targetcompany->country_code); |
|
442
|
|
|
if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1]; |
|
443
|
|
|
$stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof3); |
|
444
|
|
|
} |
|
445
|
|
|
if (! empty($conf->global->MAIN_PROFID4_IN_ADDRESS) && ! empty($targetcompany->idprof4)) |
|
446
|
|
|
{ |
|
447
|
|
|
$tmp=$outputlangs->transcountrynoentities("ProfId4",$targetcompany->country_code); |
|
448
|
|
|
if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1]; |
|
449
|
|
|
$stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof4); |
|
450
|
|
|
} |
|
451
|
|
|
} |
|
452
|
|
|
|
|
453
|
|
|
return $stringaddress; |
|
454
|
|
|
} |
|
455
|
|
|
|
|
456
|
|
|
|
|
457
|
|
|
/** |
|
458
|
|
|
* Show header of page for PDF generation |
|
459
|
|
|
* |
|
460
|
|
|
* @param PDF $pdf Object PDF |
|
461
|
|
|
* @param Translate $outputlangs Object lang for output |
|
462
|
|
|
* @param int $page_height Height of page |
|
463
|
|
|
* @return void |
|
464
|
|
|
*/ |
|
465
|
|
|
function pdf_pagehead(&$pdf,$outputlangs,$page_height) |
|
|
|
|
|
|
466
|
|
|
{ |
|
467
|
|
|
global $conf; |
|
468
|
|
|
|
|
469
|
|
|
// Add a background image on document |
|
470
|
|
|
if (! empty($conf->global->MAIN_USE_BACKGROUND_ON_PDF)) // Warning, this option make TCPDF generation beeing crazy and some content disappeared behin the image |
|
471
|
|
|
{ |
|
472
|
|
|
$pdf->SetAutoPageBreak(0,0); // Disable auto pagebreak before adding image |
|
473
|
|
|
$pdf->Image($conf->mycompany->dir_output.'/logos/'.$conf->global->MAIN_USE_BACKGROUND_ON_PDF, (isset($conf->global->MAIN_USE_BACKGROUND_ON_PDF_X)?$conf->global->MAIN_USE_BACKGROUND_ON_PDF_X:0), (isset($conf->global->MAIN_USE_BACKGROUND_ON_PDF_Y)?$conf->global->MAIN_USE_BACKGROUND_ON_PDF_Y:0), 0, $page_height); |
|
474
|
|
|
$pdf->SetAutoPageBreak(1,0); // Restore pagebreak |
|
475
|
|
|
} |
|
476
|
|
|
} |
|
477
|
|
|
|
|
478
|
|
|
/** |
|
479
|
|
|
* Add a draft watermark on PDF files |
|
480
|
|
|
* |
|
481
|
|
|
* @param PDF $pdf Object PDF |
|
482
|
|
|
* @param Translate $outputlangs Object lang |
|
483
|
|
|
* @param int $h Height of PDF |
|
484
|
|
|
* @param int $w Width of PDF |
|
485
|
|
|
* @param string $unit Unit of height (mm, pt, ...) |
|
486
|
|
|
* @param string $text Text to show |
|
487
|
|
|
* @return void |
|
488
|
|
|
*/ |
|
489
|
|
|
function pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text) |
|
490
|
|
|
{ |
|
491
|
|
|
// Print Draft Watermark |
|
492
|
|
|
if ($unit=='pt') $k=1; |
|
493
|
|
|
elseif ($unit=='mm') $k=72/25.4; |
|
494
|
|
|
elseif ($unit=='cm') $k=72/2.54; |
|
495
|
|
|
elseif ($unit=='in') $k=72; |
|
496
|
|
|
|
|
497
|
|
|
$savx=$pdf->getX(); $savy=$pdf->getY(); |
|
498
|
|
|
|
|
499
|
|
|
$watermark_angle=atan($h/$w)/2; |
|
500
|
|
|
$watermark_x_pos=0; |
|
501
|
|
|
$watermark_y_pos=$h/3; |
|
502
|
|
|
$watermark_x=$w/2; |
|
503
|
|
|
$watermark_y=$h/3; |
|
504
|
|
|
$pdf->SetFont('','B',40); |
|
505
|
|
|
$pdf->SetTextColor(255,192,203); |
|
506
|
|
|
//rotate |
|
507
|
|
|
$pdf->_out(sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm',cos($watermark_angle),sin($watermark_angle),-sin($watermark_angle),cos($watermark_angle),$watermark_x*$k,($h-$watermark_y)*$k,-$watermark_x*$k,-($h-$watermark_y)*$k)); |
|
|
|
|
|
|
508
|
|
|
//print watermark |
|
509
|
|
|
$pdf->SetXY($watermark_x_pos,$watermark_y_pos); |
|
510
|
|
|
$pdf->Cell($w-20,25,$outputlangs->convToOutputCharset($text),"",2,"C",0); |
|
511
|
|
|
//antirotate |
|
512
|
|
|
$pdf->_out('Q'); |
|
513
|
|
|
|
|
514
|
|
|
$pdf->SetXY($savx,$savy); |
|
515
|
|
|
} |
|
516
|
|
|
|
|
517
|
|
|
|
|
518
|
|
|
/** |
|
519
|
|
|
* Show bank informations for PDF generation |
|
520
|
|
|
* |
|
521
|
|
|
* @param PDF $pdf Object PDF |
|
522
|
|
|
* @param Translate $outputlangs Object lang |
|
523
|
|
|
* @param int $curx X |
|
524
|
|
|
* @param int $cury Y |
|
525
|
|
|
* @param Account $account Bank account object |
|
526
|
|
|
* @param int $onlynumber Output only number (bank+desk+key+number according to country, but without name of bank and domiciliation) |
|
527
|
|
|
* @param int $default_font_size Default font size |
|
528
|
|
|
* @return float The Y PDF position |
|
529
|
|
|
*/ |
|
530
|
|
|
function pdf_bank(&$pdf,$outputlangs,$curx,$cury,$account,$onlynumber=0,$default_font_size=10) |
|
531
|
|
|
{ |
|
532
|
|
|
global $mysoc, $conf; |
|
533
|
|
|
|
|
534
|
|
|
$diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE); |
|
535
|
|
|
$diffsizecontent=(empty($conf->global->PDF_DIFFSIZE_CONTENT)?4:$conf->global->PDF_DIFFSIZE_CONTENT); |
|
536
|
|
|
$pdf->SetXY($curx, $cury); |
|
537
|
|
|
|
|
538
|
|
|
if (empty($onlynumber)) |
|
539
|
|
|
{ |
|
540
|
|
|
$pdf->SetFont('','B',$default_font_size - $diffsizetitle); |
|
541
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByTransferOnThisBankAccount').':', 0, 'L', 0); |
|
542
|
|
|
$cury+=4; |
|
543
|
|
|
} |
|
544
|
|
|
|
|
545
|
|
|
$outputlangs->load("banks"); |
|
546
|
|
|
|
|
547
|
|
|
// Use correct name of bank id according to country |
|
548
|
|
|
$bickey="BICNumber"; |
|
549
|
|
|
if ($account->getCountryCode() == 'IN') $bickey="SWIFT"; |
|
550
|
|
|
|
|
551
|
|
|
// Get format of bank account according to its country |
|
552
|
|
|
$usedetailedbban=$account->useDetailedBBAN(); |
|
553
|
|
|
|
|
554
|
|
|
//$onlynumber=0; $usedetailedbban=1; // For tests |
|
555
|
|
|
if ($usedetailedbban) |
|
556
|
|
|
{ |
|
557
|
|
|
$savcurx=$curx; |
|
|
|
|
|
|
558
|
|
|
|
|
559
|
|
|
if (empty($onlynumber)) |
|
560
|
|
|
{ |
|
561
|
|
|
$pdf->SetFont('','',$default_font_size - $diffsizecontent); |
|
562
|
|
|
$pdf->SetXY($curx, $cury); |
|
563
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0); |
|
564
|
|
|
$cury+=3; |
|
565
|
|
|
} |
|
566
|
|
|
|
|
567
|
|
|
/* |
|
568
|
|
|
if (empty($onlynumber)) $pdf->line($curx+1, $cury+1, $curx+1, $cury+8); |
|
569
|
|
|
|
|
570
|
|
|
if ($usedetailedbban == 1) |
|
571
|
|
|
{ |
|
572
|
|
|
$fieldstoshow=array('bank','desk','number','key'); |
|
573
|
|
|
if ($conf->global->BANK_SHOW_ORDER_OPTION==1) $fieldstoshow=array('bank','desk','key','number'); |
|
574
|
|
|
} |
|
575
|
|
|
else if ($usedetailedbban == 2) |
|
576
|
|
|
{ |
|
577
|
|
|
$fieldstoshow=array('bank','number'); |
|
578
|
|
|
} |
|
579
|
|
|
else dol_print_error('','Value returned by function useDetailedBBAN not managed'); |
|
580
|
|
|
|
|
581
|
|
|
foreach ($fieldstoshow as $val) |
|
582
|
|
|
{ |
|
583
|
|
|
if ($val == 'bank') |
|
584
|
|
|
{ |
|
585
|
|
|
// Bank code |
|
586
|
|
|
$tmplength=18; |
|
587
|
|
|
$pdf->SetXY($curx, $cury+5); |
|
588
|
|
|
$pdf->SetFont('','',$default_font_size - 3);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->code_banque), 0, 'C', 0); |
|
589
|
|
|
$pdf->SetXY($curx, $cury+1); |
|
590
|
|
|
$curx+=$tmplength; |
|
591
|
|
|
$pdf->SetFont('','B',$default_font_size - 4);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("BankCode"), 0, 'C', 0); |
|
592
|
|
|
if (empty($onlynumber)) $pdf->line($curx, $cury+1, $curx, $cury+8); |
|
593
|
|
|
} |
|
594
|
|
|
if ($val == 'desk') |
|
595
|
|
|
{ |
|
596
|
|
|
// Desk |
|
597
|
|
|
$tmplength=18; |
|
598
|
|
|
$pdf->SetXY($curx, $cury+5); |
|
599
|
|
|
$pdf->SetFont('','',$default_font_size - 3);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->code_guichet), 0, 'C', 0); |
|
600
|
|
|
$pdf->SetXY($curx, $cury+1); |
|
601
|
|
|
$curx+=$tmplength; |
|
602
|
|
|
$pdf->SetFont('','B',$default_font_size - 4);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("DeskCode"), 0, 'C', 0); |
|
603
|
|
|
if (empty($onlynumber)) $pdf->line($curx, $cury+1, $curx, $cury+8); |
|
604
|
|
|
} |
|
605
|
|
|
if ($val == 'number') |
|
606
|
|
|
{ |
|
607
|
|
|
// Number |
|
608
|
|
|
$tmplength=24; |
|
609
|
|
|
$pdf->SetXY($curx, $cury+5); |
|
610
|
|
|
$pdf->SetFont('','',$default_font_size - 3);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->number), 0, 'C', 0); |
|
611
|
|
|
$pdf->SetXY($curx, $cury+1); |
|
612
|
|
|
$curx+=$tmplength; |
|
613
|
|
|
$pdf->SetFont('','B',$default_font_size - 4);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("BankAccountNumber"), 0, 'C', 0); |
|
614
|
|
|
if (empty($onlynumber)) $pdf->line($curx, $cury+1, $curx, $cury+8); |
|
615
|
|
|
} |
|
616
|
|
|
if ($val == 'key') |
|
617
|
|
|
{ |
|
618
|
|
|
// Key |
|
619
|
|
|
$tmplength=13; |
|
620
|
|
|
$pdf->SetXY($curx, $cury+5); |
|
621
|
|
|
$pdf->SetFont('','',$default_font_size - 3);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->cle_rib), 0, 'C', 0); |
|
622
|
|
|
$pdf->SetXY($curx, $cury+1); |
|
623
|
|
|
$curx+=$tmplength; |
|
624
|
|
|
$pdf->SetFont('','B',$default_font_size - 4);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("BankAccountNumberKey"), 0, 'C', 0); |
|
625
|
|
|
if (empty($onlynumber)) $pdf->line($curx, $cury+1, $curx, $cury+8); |
|
626
|
|
|
} |
|
627
|
|
|
} |
|
628
|
|
|
|
|
629
|
|
|
$curx=$savcurx; |
|
630
|
|
|
$cury+=9; |
|
631
|
|
|
*/ |
|
632
|
|
|
} |
|
633
|
|
|
else |
|
634
|
|
|
{ |
|
635
|
|
|
$pdf->SetFont('','B',$default_font_size - $diffsizecontent); |
|
636
|
|
|
$pdf->SetXY($curx, $cury); |
|
637
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0); |
|
638
|
|
|
$cury+=3; |
|
639
|
|
|
|
|
640
|
|
|
$pdf->SetFont('','B',$default_font_size - $diffsizecontent); |
|
641
|
|
|
$pdf->SetXY($curx, $cury); |
|
642
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("BankAccountNumber").': ' . $outputlangs->convToOutputCharset($account->number), 0, 'L', 0); |
|
643
|
|
|
$cury+=3; |
|
644
|
|
|
|
|
645
|
|
|
if ($diffsizecontent <= 2) $cury+=1; |
|
646
|
|
|
} |
|
647
|
|
|
|
|
648
|
|
|
$pdf->SetFont('','',$default_font_size - $diffsizecontent); |
|
649
|
|
|
|
|
650
|
|
|
if (empty($onlynumber) && ! empty($account->domiciliation)) |
|
651
|
|
|
{ |
|
652
|
|
|
$pdf->SetXY($curx, $cury); |
|
653
|
|
|
$val=$outputlangs->transnoentities("Residence").': ' . $outputlangs->convToOutputCharset($account->domiciliation); |
|
654
|
|
|
$pdf->MultiCell(100, 3, $val, 0, 'L', 0); |
|
655
|
|
|
//$nboflines=dol_nboflines_bis($val,120); |
|
656
|
|
|
//$cury+=($nboflines*3)+2; |
|
657
|
|
|
$tmpy=$pdf->getStringHeight(100, $val); |
|
658
|
|
|
$cury+=$tmpy; |
|
659
|
|
|
} |
|
660
|
|
|
|
|
661
|
|
|
if (! empty($account->proprio)) |
|
662
|
|
|
{ |
|
663
|
|
|
$pdf->SetXY($curx, $cury); |
|
664
|
|
|
$val=$outputlangs->transnoentities("BankAccountOwner").': ' . $outputlangs->convToOutputCharset($account->proprio); |
|
665
|
|
|
$pdf->MultiCell(100, 3, $val, 0, 'L', 0); |
|
666
|
|
|
$tmpy=$pdf->getStringHeight(100, $val); |
|
667
|
|
|
$cury+=$tmpy; |
|
668
|
|
|
} |
|
669
|
|
|
|
|
670
|
|
|
else if (! $usedetailedbban) $cury+=1; |
|
671
|
|
|
|
|
672
|
|
|
// Use correct name of bank id according to country |
|
673
|
|
|
$ibankey="IBANNumber"; |
|
674
|
|
|
if ($account->getCountryCode() == 'IN') $ibankey="IFSC"; |
|
675
|
|
|
if (! empty($account->iban)) |
|
676
|
|
|
{ |
|
677
|
|
|
//Remove whitespaces to ensure we are dealing with the format we expect |
|
678
|
|
|
$ibanDisplay_temp = str_replace(' ', '', $outputlangs->convToOutputCharset($account->iban)); |
|
679
|
|
|
$ibanDisplay = ""; |
|
680
|
|
|
|
|
681
|
|
|
for($i = 0; $i < dol_strlen($ibanDisplay_temp); $i++) |
|
682
|
|
|
{ |
|
683
|
|
|
$ibanDisplay .= $ibanDisplay_temp[$i]; |
|
684
|
|
|
if($i%4 == 3 && $i > 0) $ibanDisplay .= " "; |
|
685
|
|
|
} |
|
686
|
|
|
|
|
687
|
|
|
$pdf->SetFont('','B',$default_font_size - 3); |
|
688
|
|
|
$pdf->SetXY($curx, $cury); |
|
689
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities($ibankey).': ' . $ibanDisplay, 0, 'L', 0); |
|
690
|
|
|
$cury+=3; |
|
691
|
|
|
} |
|
692
|
|
|
|
|
693
|
|
|
if (! empty($account->bic)) |
|
694
|
|
|
{ |
|
695
|
|
|
$pdf->SetFont('','B',$default_font_size - 3); |
|
696
|
|
|
$pdf->SetXY($curx, $cury); |
|
697
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities($bickey).': ' . $outputlangs->convToOutputCharset($account->bic), 0, 'L', 0); |
|
698
|
|
|
} |
|
699
|
|
|
|
|
700
|
|
|
return $pdf->getY(); |
|
701
|
|
|
} |
|
702
|
|
|
|
|
703
|
|
|
/** |
|
704
|
|
|
* Show footer of page for PDF generation |
|
705
|
|
|
* |
|
706
|
|
|
* @param PDF $pdf The PDF factory |
|
707
|
|
|
* @param Translate $outputlangs Object lang for output |
|
708
|
|
|
* @param string $paramfreetext Constant name of free text |
|
709
|
|
|
* @param Societe $fromcompany Object company |
|
710
|
|
|
* @param int $marge_basse Margin bottom we use for the autobreak |
|
711
|
|
|
* @param int $marge_gauche Margin left (no more used) |
|
712
|
|
|
* @param int $page_hauteur Page height (no more used) |
|
713
|
|
|
* @param Object $object Object shown in PDF |
|
714
|
|
|
* @param int $showdetails Show company details into footer. This param seems to not be used by standard version. (1=Show address, 2=Show managers, 3=Both) |
|
715
|
|
|
* @param int $hidefreetext 1=Hide free text, 0=Show free text |
|
716
|
|
|
* @return int Return height of bottom margin including footer text |
|
717
|
|
|
*/ |
|
718
|
|
|
function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_basse,$marge_gauche,$page_hauteur,$object,$showdetails=0,$hidefreetext=0) |
|
|
|
|
|
|
719
|
|
|
{ |
|
720
|
|
|
global $conf,$user; |
|
721
|
|
|
|
|
722
|
|
|
$outputlangs->load("dict"); |
|
723
|
|
|
$line=''; |
|
724
|
|
|
|
|
725
|
|
|
$dims=$pdf->getPageDimensions(); |
|
726
|
|
|
|
|
727
|
|
|
// Line of free text |
|
728
|
|
|
if (empty($hidefreetext) && ! empty($conf->global->$paramfreetext)) |
|
729
|
|
|
{ |
|
730
|
|
|
// Make substitution |
|
731
|
|
|
$substitutionarray=array( |
|
732
|
|
|
'__FROM_NAME__' => $fromcompany->name, |
|
733
|
|
|
'__FROM_EMAIL__' => $fromcompany->email, |
|
734
|
|
|
'__TOTAL_TTC__' => $object->total_ttc, |
|
735
|
|
|
'__TOTAL_HT__' => $object->total_ht, |
|
736
|
|
|
'__TOTAL_VAT__' => $object->total_vat |
|
737
|
|
|
); |
|
738
|
|
|
complete_substitutions_array($substitutionarray,$outputlangs,$object); |
|
739
|
|
|
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray); |
|
740
|
|
|
$line.=$outputlangs->convToOutputCharset($newfreetext); |
|
741
|
|
|
} |
|
742
|
|
|
|
|
743
|
|
|
// First line of company infos |
|
744
|
|
|
$line1=""; $line2=""; $line3=""; $line4=""; |
|
745
|
|
|
|
|
746
|
|
|
if ($showdetails) |
|
747
|
|
|
{ |
|
748
|
|
|
// Company name |
|
749
|
|
|
if ($fromcompany->name) |
|
750
|
|
|
{ |
|
751
|
|
|
$line1.=($line1?" - ":"").$outputlangs->transnoentities("RegisteredOffice").": ".$fromcompany->name; |
|
752
|
|
|
} |
|
753
|
|
|
// Address |
|
754
|
|
|
if ($fromcompany->address) |
|
755
|
|
|
{ |
|
756
|
|
|
$line1.=($line1?" - ":"").$fromcompany->address; |
|
757
|
|
|
} |
|
758
|
|
|
// Zip code |
|
759
|
|
|
if ($fromcompany->zip) |
|
760
|
|
|
{ |
|
761
|
|
|
$line1.=($line1?" - ":"").$fromcompany->zip; |
|
762
|
|
|
} |
|
763
|
|
|
// Town |
|
764
|
|
|
if ($fromcompany->town) |
|
765
|
|
|
{ |
|
766
|
|
|
$line1.=($line1?" ":"").$fromcompany->town; |
|
767
|
|
|
} |
|
768
|
|
|
// Phone |
|
769
|
|
|
if ($fromcompany->phone) |
|
770
|
|
|
{ |
|
771
|
|
|
$line1.=($line1?" - ":"").$outputlangs->transnoentities("Phone").": ".$fromcompany->phone; |
|
772
|
|
|
} |
|
773
|
|
|
// Fax |
|
774
|
|
|
if ($fromcompany->fax) |
|
775
|
|
|
{ |
|
776
|
|
|
$line1.=($line1?" - ":"").$outputlangs->transnoentities("Fax").": ".$fromcompany->fax; |
|
777
|
|
|
} |
|
778
|
|
|
|
|
779
|
|
|
// URL |
|
780
|
|
|
if ($fromcompany->url) |
|
781
|
|
|
{ |
|
782
|
|
|
$line2.=($line2?" - ":"").$fromcompany->url; |
|
783
|
|
|
} |
|
784
|
|
|
// Email |
|
785
|
|
|
if ($fromcompany->email) |
|
786
|
|
|
{ |
|
787
|
|
|
$line2.=($line2?" - ":"").$fromcompany->email; |
|
788
|
|
|
} |
|
789
|
|
|
} |
|
790
|
|
|
if ($showdetails || ($fromcompany->country_code == 'DE')) |
|
791
|
|
|
{ |
|
792
|
|
|
// Managers |
|
793
|
|
|
if ($fromcompany->managers) |
|
794
|
|
|
{ |
|
795
|
|
|
$line2.=($line2?" - ":"").$fromcompany->managers; |
|
796
|
|
|
} |
|
797
|
|
|
} |
|
798
|
|
|
|
|
799
|
|
|
// Line 3 of company infos |
|
800
|
|
|
// Juridical status |
|
801
|
|
|
if ($fromcompany->forme_juridique_code) |
|
802
|
|
|
{ |
|
803
|
|
|
$line3.=($line3?" - ":"").$outputlangs->convToOutputCharset(getFormeJuridiqueLabel($fromcompany->forme_juridique_code)); |
|
804
|
|
|
} |
|
805
|
|
|
// Capital |
|
806
|
|
|
if ($fromcompany->capital) |
|
807
|
|
|
{ |
|
808
|
|
|
$tmpamounttoshow = price2num($fromcompany->capital); // This field is a free string |
|
809
|
|
|
if (is_numeric($tmpamounttoshow) && $tmpamounttoshow > 0) $line3.=($line3?" - ":"").$outputlangs->transnoentities("CapitalOf",price($tmpamounttoshow, 0, $outputlangs, 0, 0, 0, $conf->currency)); |
|
|
|
|
|
|
810
|
|
|
else $line3.=($line3?" - ":"").$outputlangs->transnoentities("CapitalOf",$tmpamounttoshow,$outputlangs); |
|
|
|
|
|
|
811
|
|
|
} |
|
812
|
|
|
// Prof Id 1 |
|
813
|
|
|
if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2)) |
|
814
|
|
|
{ |
|
815
|
|
|
$field=$outputlangs->transcountrynoentities("ProfId1",$fromcompany->country_code); |
|
816
|
|
|
if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1]; |
|
817
|
|
|
$line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof1); |
|
818
|
|
|
} |
|
819
|
|
|
// Prof Id 2 |
|
820
|
|
|
if ($fromcompany->idprof2) |
|
821
|
|
|
{ |
|
822
|
|
|
$field=$outputlangs->transcountrynoentities("ProfId2",$fromcompany->country_code); |
|
823
|
|
|
if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1]; |
|
824
|
|
|
$line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof2); |
|
825
|
|
|
} |
|
826
|
|
|
|
|
827
|
|
|
// Line 4 of company infos |
|
828
|
|
|
// Prof Id 3 |
|
829
|
|
|
if ($fromcompany->idprof3) |
|
830
|
|
|
{ |
|
831
|
|
|
$field=$outputlangs->transcountrynoentities("ProfId3",$fromcompany->country_code); |
|
832
|
|
|
if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1]; |
|
833
|
|
|
$line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof3); |
|
834
|
|
|
} |
|
835
|
|
|
// Prof Id 4 |
|
836
|
|
|
if ($fromcompany->idprof4) |
|
837
|
|
|
{ |
|
838
|
|
|
$field=$outputlangs->transcountrynoentities("ProfId4",$fromcompany->country_code); |
|
839
|
|
|
if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1]; |
|
840
|
|
|
$line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof4); |
|
841
|
|
|
} |
|
842
|
|
|
// IntraCommunautary VAT |
|
843
|
|
|
if ($fromcompany->tva_intra != '') |
|
844
|
|
|
{ |
|
845
|
|
|
$line4.=($line4?" - ":"").$outputlangs->transnoentities("VATIntraShort").": ".$outputlangs->convToOutputCharset($fromcompany->tva_intra); |
|
846
|
|
|
} |
|
847
|
|
|
|
|
848
|
|
|
$pdf->SetFont('','',7); |
|
849
|
|
|
$pdf->SetDrawColor(224,224,224); |
|
850
|
|
|
|
|
851
|
|
|
// The start of the bottom of this page footer is positioned according to # of lines |
|
852
|
|
|
$freetextheight=0; |
|
853
|
|
|
if ($line) // Free text |
|
854
|
|
|
{ |
|
855
|
|
|
$width=20000; $align='L'; // By default, ask a manual break: We use a large value 20000, to not have automatic wrap. This make user understand, he need to add CR on its text. |
|
856
|
|
|
if (! empty($conf->global->MAIN_USE_AUTOWRAP_ON_FREETEXT)) { |
|
857
|
|
|
$width=200; $align='C'; |
|
858
|
|
|
} |
|
859
|
|
|
$freetextheight=$pdf->getStringHeight($width,$line); |
|
860
|
|
|
} |
|
861
|
|
|
|
|
862
|
|
|
$marginwithfooter=$marge_basse + $freetextheight + (! empty($line1)?3:0) + (! empty($line2)?3:0) + (! empty($line3)?3:0) + (! empty($line4)?3:0); |
|
863
|
|
|
$posy=$marginwithfooter+0; |
|
864
|
|
|
|
|
865
|
|
|
if ($line) // Free text |
|
866
|
|
|
{ |
|
867
|
|
|
$pdf->SetXY($dims['lm'],-$posy); |
|
868
|
|
|
$pdf->MultiCell(0, 3, $line, 0, $align, 0); |
|
|
|
|
|
|
869
|
|
|
$posy-=$freetextheight; |
|
870
|
|
|
} |
|
871
|
|
|
|
|
872
|
|
|
$pdf->SetY(-$posy); |
|
873
|
|
|
$pdf->line($dims['lm'], $dims['hk']-$posy, $dims['wk']-$dims['rm'], $dims['hk']-$posy); |
|
874
|
|
|
$posy--; |
|
875
|
|
|
|
|
876
|
|
|
if (! empty($line1)) |
|
877
|
|
|
{ |
|
878
|
|
|
$pdf->SetFont('','B',7); |
|
879
|
|
|
$pdf->SetXY($dims['lm'],-$posy); |
|
880
|
|
|
$pdf->MultiCell($dims['wk']-$dims['rm'], 2, $line1, 0, 'C', 0); |
|
881
|
|
|
$posy-=3; |
|
882
|
|
|
$pdf->SetFont('','',7); |
|
883
|
|
|
} |
|
884
|
|
|
|
|
885
|
|
|
if (! empty($line2)) |
|
886
|
|
|
{ |
|
887
|
|
|
$pdf->SetFont('','B',7); |
|
888
|
|
|
$pdf->SetXY($dims['lm'],-$posy); |
|
889
|
|
|
$pdf->MultiCell($dims['wk']-$dims['rm'], 2, $line2, 0, 'C', 0); |
|
890
|
|
|
$posy-=3; |
|
891
|
|
|
$pdf->SetFont('','',7); |
|
892
|
|
|
} |
|
893
|
|
|
|
|
894
|
|
|
if (! empty($line3)) |
|
895
|
|
|
{ |
|
896
|
|
|
$pdf->SetXY($dims['lm'],-$posy); |
|
897
|
|
|
$pdf->MultiCell($dims['wk']-$dims['rm'], 2, $line3, 0, 'C', 0); |
|
898
|
|
|
} |
|
899
|
|
|
|
|
900
|
|
|
if (! empty($line4)) |
|
901
|
|
|
{ |
|
902
|
|
|
$posy-=3; |
|
903
|
|
|
$pdf->SetXY($dims['lm'],-$posy); |
|
904
|
|
|
$pdf->MultiCell($dims['wk']-$dims['rm'], 2, $line4, 0, 'C', 0); |
|
905
|
|
|
} |
|
906
|
|
|
|
|
907
|
|
|
// Show page nb only on iso languages (so default Helvetica font) |
|
908
|
|
|
if (strtolower(pdf_getPDFFont($outputlangs)) == 'helvetica') |
|
909
|
|
|
{ |
|
910
|
|
|
$pdf->SetXY(-20,-$posy); |
|
911
|
|
|
//print 'xxx'.$pdf->PageNo().'-'.$pdf->getAliasNbPages().'-'.$pdf->getAliasNumPage();exit; |
|
912
|
|
|
if (empty($conf->global->MAIN_USE_FPDF)) $pdf->MultiCell(13, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0); |
|
913
|
|
|
else $pdf->MultiCell(13, 2, $pdf->PageNo().'/{nb}', 0, 'R', 0); |
|
914
|
|
|
} |
|
915
|
|
|
|
|
916
|
|
|
return $marginwithfooter; |
|
917
|
|
|
} |
|
918
|
|
|
|
|
919
|
|
|
/** |
|
920
|
|
|
* Show linked objects for PDF generation |
|
921
|
|
|
* |
|
922
|
|
|
* @param PDF $pdf Object PDF |
|
923
|
|
|
* @param object $object Object |
|
924
|
|
|
* @param Translate $outputlangs Object lang |
|
925
|
|
|
* @param int $posx X |
|
926
|
|
|
* @param int $posy Y |
|
927
|
|
|
* @param float $w Width of cells. If 0, they extend up to the right margin of the page. |
|
928
|
|
|
* @param float $h Cell minimum height. The cell extends automatically if needed. |
|
929
|
|
|
* @param int $align Align |
|
930
|
|
|
* @param string $default_font_size Font size |
|
931
|
|
|
* @return float The Y PDF position |
|
932
|
|
|
*/ |
|
933
|
|
|
function pdf_writeLinkedObjects(&$pdf,$object,$outputlangs,$posx,$posy,$w,$h,$align,$default_font_size) |
|
934
|
|
|
{ |
|
935
|
|
|
$linkedobjects = pdf_getLinkedObjects($object,$outputlangs); |
|
936
|
|
|
if (! empty($linkedobjects)) |
|
937
|
|
|
{ |
|
938
|
|
|
foreach($linkedobjects as $linkedobject) |
|
939
|
|
|
{ |
|
940
|
|
|
$posy+=3; |
|
941
|
|
|
$pdf->SetXY($posx,$posy); |
|
942
|
|
|
$pdf->SetFont('','', $default_font_size - 2); |
|
943
|
|
|
$pdf->MultiCell($w, $h, $linkedobject["ref_title"].' : '.$linkedobject["ref_value"], '', $align); |
|
944
|
|
|
|
|
945
|
|
|
if (! empty($linkedobject["date_title"]) && ! empty($linkedobject["date_value"])) |
|
946
|
|
|
{ |
|
947
|
|
|
$posy+=3; |
|
948
|
|
|
$pdf->SetXY($posx,$posy); |
|
949
|
|
|
$pdf->MultiCell($w, $h, $linkedobject["date_title"].' : '.$linkedobject["date_value"], '', $align); |
|
950
|
|
|
} |
|
951
|
|
|
} |
|
952
|
|
|
} |
|
953
|
|
|
|
|
954
|
|
|
return $pdf->getY(); |
|
955
|
|
|
} |
|
956
|
|
|
|
|
957
|
|
|
/** |
|
958
|
|
|
* Output line description into PDF |
|
959
|
|
|
* |
|
960
|
|
|
* @param PDF $pdf PDF object |
|
961
|
|
|
* @param Object $object Object |
|
962
|
|
|
* @param int $i Current line number |
|
963
|
|
|
* @param Translate $outputlangs Object lang for output |
|
964
|
|
|
* @param int $w Width |
|
965
|
|
|
* @param int $h Height |
|
966
|
|
|
* @param int $posx Pos x |
|
967
|
|
|
* @param int $posy Pos y |
|
968
|
|
|
* @param int $hideref Hide reference |
|
969
|
|
|
* @param int $hidedesc Hide description |
|
970
|
|
|
* @param int $issupplierline Is it a line for a supplier object ? |
|
971
|
|
|
* @return string|null |
|
972
|
|
|
*/ |
|
973
|
|
|
function pdf_writelinedesc(&$pdf,$object,$i,$outputlangs,$w,$h,$posx,$posy,$hideref=0,$hidedesc=0,$issupplierline=0) |
|
974
|
|
|
{ |
|
975
|
|
|
global $db, $conf, $langs, $hookmanager; |
|
976
|
|
|
|
|
977
|
|
|
$reshook=0; |
|
978
|
|
|
if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) ) |
|
979
|
|
|
{ |
|
980
|
|
|
$special_code = $object->lines[$i]->special_code; |
|
981
|
|
|
if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line); |
|
982
|
|
|
$parameters = array('pdf'=>$pdf,'i'=>$i,'outputlangs'=>$outputlangs,'w'=>$w,'h'=>$h,'posx'=>$posx,'posy'=>$posy,'hideref'=>$hideref,'hidedesc'=>$hidedesc,'issupplierline'=>$issupplierline,'special_code'=>$special_code); |
|
983
|
|
|
$action=''; |
|
984
|
|
|
$reshook=$hookmanager->executeHooks('pdf_writelinedesc',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
985
|
|
|
} |
|
986
|
|
|
if (empty($reshook)) |
|
987
|
|
|
{ |
|
988
|
|
|
$labelproductservice=pdf_getlinedesc($object,$i,$outputlangs,$hideref,$hidedesc,$issupplierline); |
|
989
|
|
|
// Description |
|
990
|
|
|
$pdf->writeHTMLCell($w, $h, $posx, $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1, false, true, 'J',true); |
|
991
|
|
|
return $labelproductservice; |
|
992
|
|
|
} |
|
993
|
|
|
} |
|
994
|
|
|
|
|
995
|
|
|
/** |
|
996
|
|
|
* Return line description translated in outputlangs and encoded into htmlentities and with <br> |
|
997
|
|
|
* |
|
998
|
|
|
* @param Object $object Object |
|
999
|
|
|
* @param int $i Current line number (0 = first line, 1 = second line, ...) |
|
1000
|
|
|
* @param Translate $outputlangs Object langs for output |
|
1001
|
|
|
* @param int $hideref Hide reference |
|
1002
|
|
|
* @param int $hidedesc Hide description |
|
1003
|
|
|
* @param int $issupplierline Is it a line for a supplier object ? |
|
1004
|
|
|
* @return string String with line |
|
1005
|
|
|
*/ |
|
1006
|
|
|
function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issupplierline=0) |
|
1007
|
|
|
{ |
|
1008
|
|
|
global $db, $conf, $langs; |
|
1009
|
|
|
|
|
1010
|
|
|
$idprod=(! empty($object->lines[$i]->fk_product)?$object->lines[$i]->fk_product:false); |
|
1011
|
|
|
$label=(! empty($object->lines[$i]->label)?$object->lines[$i]->label:(! empty($object->lines[$i]->product_label)?$object->lines[$i]->product_label:'')); |
|
1012
|
|
|
$desc=(! empty($object->lines[$i]->desc)?$object->lines[$i]->desc:(! empty($object->lines[$i]->description)?$object->lines[$i]->description:'')); |
|
1013
|
|
|
$ref_supplier=(! empty($object->lines[$i]->ref_supplier)?$object->lines[$i]->ref_supplier:(! empty($object->lines[$i]->ref_fourn)?$object->lines[$i]->ref_fourn:'')); // TODO Not yet saved for supplier invoices, only supplier orders |
|
1014
|
|
|
$note=(! empty($object->lines[$i]->note)?$object->lines[$i]->note:''); |
|
1015
|
|
|
$dbatch=(! empty($object->lines[$i]->detail_batch)?$object->lines[$i]->detail_batch:false); |
|
1016
|
|
|
|
|
1017
|
|
|
if ($issupplierline) $prodser = new ProductFournisseur($db); |
|
1018
|
|
|
else $prodser = new Product($db); |
|
1019
|
|
|
|
|
1020
|
|
|
if ($idprod) |
|
1021
|
|
|
{ |
|
1022
|
|
|
$prodser->fetch($idprod); |
|
1023
|
|
|
// If a predefined product and multilang and on other lang, we renamed label with label translated |
|
1024
|
|
|
if (! empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang)) |
|
1025
|
|
|
{ |
|
1026
|
|
|
$translatealsoifmodified=(! empty($conf->global->MAIN_MULTILANG_TRANSLATE_EVEN_IF_MODIFIED)); // By default if value was modified manually, we keep it (no translation because we don't have it) |
|
1027
|
|
|
|
|
1028
|
|
|
// TODO Instead of making a compare to see if param was modified, check that content contains reference translation. If yes, add the added part to the new translation |
|
1029
|
|
|
// ($textwasmodified is replaced with $textwasmodifiedorcompleted and we add completion). |
|
1030
|
|
|
|
|
1031
|
|
|
// Set label |
|
1032
|
|
|
// If we want another language, and if label is same than default language (we did force it to a specific value), we can use translation. |
|
1033
|
|
|
//var_dump($outputlangs->defaultlang.' - '.$langs->defaultlang.' - '.$label.' - '.$prodser->label);exit; |
|
1034
|
|
|
$textwasmodified=($label == $prodser->label); |
|
1035
|
|
|
if (! empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && ($textwasmodified || $translatealsoifmodified)) $label=$prodser->multilangs[$outputlangs->defaultlang]["label"]; |
|
1036
|
|
|
|
|
1037
|
|
|
// Set desc |
|
1038
|
|
|
// Manage HTML entities description test because $prodser->description is store with htmlentities but $desc no |
|
1039
|
|
|
$textwasmodified=false; |
|
1040
|
|
|
if (!empty($desc) && dol_textishtml($desc) && !empty($prodser->description) && dol_textishtml($prodser->description)) { |
|
1041
|
|
|
$textwasmodified=(strpos(dol_html_entity_decode($desc,ENT_QUOTES | ENT_HTML401),dol_html_entity_decode($prodser->description,ENT_QUOTES | ENT_HTML401))!==false); |
|
1042
|
|
|
} else { |
|
1043
|
|
|
$textwasmodified=($desc == $prodser->description); |
|
1044
|
|
|
} |
|
1045
|
|
|
if (! empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && ($textwasmodified || $translatealsoifmodified)) $desc=$prodser->multilangs[$outputlangs->defaultlang]["description"]; |
|
1046
|
|
|
|
|
1047
|
|
|
// Set note |
|
1048
|
|
|
$textwasmodified=($note == $prodser->note); |
|
1049
|
|
|
if (! empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && ($textwasmodified || $translatealsoifmodified)) $note=$prodser->multilangs[$outputlangs->defaultlang]["note"]; |
|
|
|
|
|
|
1050
|
|
|
} |
|
1051
|
|
|
} |
|
1052
|
|
|
|
|
1053
|
|
|
// Description short of product line |
|
1054
|
|
|
$libelleproduitservice=$label; |
|
1055
|
|
|
|
|
1056
|
|
|
// Description long of product line |
|
1057
|
|
|
if (! empty($desc) && ($desc != $label)) |
|
1058
|
|
|
{ |
|
1059
|
|
|
if ($libelleproduitservice && empty($hidedesc)) |
|
1060
|
|
|
{ |
|
1061
|
|
|
$libelleproduitservice.='__N__'; |
|
1062
|
|
|
} |
|
1063
|
|
|
|
|
1064
|
|
|
if ($desc == '(CREDIT_NOTE)' && $object->lines[$i]->fk_remise_except) |
|
1065
|
|
|
{ |
|
1066
|
|
|
$discount=new DiscountAbsolute($db); |
|
1067
|
|
|
$discount->fetch($object->lines[$i]->fk_remise_except); |
|
1068
|
|
|
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$discount->ref_facture_source); |
|
1069
|
|
|
} |
|
1070
|
|
|
elseif ($desc == '(DEPOSIT)' && $object->lines[$i]->fk_remise_except) |
|
1071
|
|
|
{ |
|
1072
|
|
|
$discount=new DiscountAbsolute($db); |
|
1073
|
|
|
$discount->fetch($object->lines[$i]->fk_remise_except); |
|
1074
|
|
|
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$discount->ref_facture_source); |
|
1075
|
|
|
// Add date of deposit |
|
1076
|
|
|
if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec,'day','',$outputlangs).')'; |
|
1077
|
|
|
} |
|
1078
|
|
|
else |
|
1079
|
|
|
{ |
|
1080
|
|
|
if ($idprod) |
|
1081
|
|
|
{ |
|
1082
|
|
|
if (empty($hidedesc)) $libelleproduitservice.=$desc; |
|
1083
|
|
|
} |
|
1084
|
|
|
else |
|
1085
|
|
|
{ |
|
1086
|
|
|
$libelleproduitservice.=$desc; |
|
1087
|
|
|
} |
|
1088
|
|
|
} |
|
1089
|
|
|
} |
|
1090
|
|
|
|
|
1091
|
|
|
// If line linked to a product |
|
1092
|
|
|
if ($idprod) |
|
1093
|
|
|
{ |
|
1094
|
|
|
// We add ref |
|
1095
|
|
|
if ($prodser->ref) |
|
1096
|
|
|
{ |
|
1097
|
|
|
$prefix_prodserv = ""; |
|
1098
|
|
|
$ref_prodserv = ""; |
|
1099
|
|
|
if (! empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) // In standard mode, we do not show this |
|
1100
|
|
|
{ |
|
1101
|
|
|
if ($prodser->isservice()) |
|
1102
|
|
|
{ |
|
1103
|
|
|
$prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." "; |
|
1104
|
|
|
} |
|
1105
|
|
|
else |
|
1106
|
|
|
{ |
|
1107
|
|
|
$prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." "; |
|
1108
|
|
|
} |
|
1109
|
|
|
} |
|
1110
|
|
|
|
|
1111
|
|
|
if (empty($hideref)) |
|
1112
|
|
|
{ |
|
1113
|
|
|
if ($issupplierline) $ref_prodserv = $prodser->ref.($ref_supplier ? ' ('.$outputlangs->transnoentitiesnoconv("SupplierRef").' '.$ref_supplier.')' : ''); // Show local ref and supplier ref |
|
1114
|
|
|
else $ref_prodserv = $prodser->ref; // Show local ref only |
|
1115
|
|
|
|
|
1116
|
|
|
if (! empty($libelleproduitservice)) $ref_prodserv .= " - "; |
|
1117
|
|
|
} |
|
1118
|
|
|
|
|
1119
|
|
|
$libelleproduitservice=$prefix_prodserv.$ref_prodserv.$libelleproduitservice; |
|
1120
|
|
|
} |
|
1121
|
|
|
} |
|
1122
|
|
|
|
|
1123
|
|
|
// Add an additional description for the category products |
|
1124
|
|
|
if (! empty($conf->global->CATEGORY_ADD_DESC_INTO_DOC) && $idprod && ! empty($conf->categorie->enabled)) |
|
1125
|
|
|
{ |
|
1126
|
|
|
include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; |
|
1127
|
|
|
$categstatic=new Categorie($db); |
|
1128
|
|
|
// recovering the list of all the categories linked to product |
|
1129
|
|
|
$tblcateg=$categstatic->containing($idprod, Categorie::TYPE_PRODUCT); |
|
1130
|
|
|
foreach ($tblcateg as $cate) |
|
1131
|
|
|
{ |
|
1132
|
|
|
// Adding the descriptions if they are filled |
|
1133
|
|
|
$desccateg=$cate->add_description; |
|
|
|
|
|
|
1134
|
|
|
if ($desccateg) |
|
1135
|
|
|
$libelleproduitservice.='__N__'.$desccateg; |
|
1136
|
|
|
} |
|
1137
|
|
|
} |
|
1138
|
|
|
|
|
1139
|
|
|
if (! empty($object->lines[$i]->date_start) || ! empty($object->lines[$i]->date_end)) |
|
1140
|
|
|
{ |
|
1141
|
|
|
$format='day'; |
|
1142
|
|
|
// Show duration if exists |
|
1143
|
|
|
if ($object->lines[$i]->date_start && $object->lines[$i]->date_end) |
|
1144
|
|
|
{ |
|
1145
|
|
|
$period='('.$outputlangs->transnoentitiesnoconv('DateFromTo',dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs),dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)).')'; |
|
|
|
|
|
|
1146
|
|
|
} |
|
1147
|
|
|
if ($object->lines[$i]->date_start && ! $object->lines[$i]->date_end) |
|
1148
|
|
|
{ |
|
1149
|
|
|
$period='('.$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs)).')'; |
|
1150
|
|
|
} |
|
1151
|
|
|
if (! $object->lines[$i]->date_start && $object->lines[$i]->date_end) |
|
1152
|
|
|
{ |
|
1153
|
|
|
$period='('.$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)).')'; |
|
1154
|
|
|
} |
|
1155
|
|
|
//print '>'.$outputlangs->charset_output.','.$period; |
|
1156
|
|
|
$libelleproduitservice.="__N__".$period; |
|
|
|
|
|
|
1157
|
|
|
//print $libelleproduitservice; |
|
1158
|
|
|
} |
|
1159
|
|
|
|
|
1160
|
|
|
if ($dbatch) |
|
1161
|
|
|
{ |
|
1162
|
|
|
$format='day'; |
|
1163
|
|
|
foreach ($dbatch as $detail) |
|
1164
|
|
|
{ |
|
1165
|
|
|
$dte=array(); |
|
1166
|
|
|
if ($detail->eatby) $dte[]=$outputlangs->transnoentitiesnoconv('printEatby',dol_print_date($detail->eatby, $format, false, $outputlangs)); |
|
1167
|
|
|
if ($detail->sellby) $dte[]=$outputlangs->transnoentitiesnoconv('printSellby',dol_print_date($detail->sellby, $format, false, $outputlangs)); |
|
1168
|
|
|
if ($detail->batch) $dte[]=$outputlangs->transnoentitiesnoconv('printBatch',$detail->batch); |
|
1169
|
|
|
$dte[]=$outputlangs->transnoentitiesnoconv('printQty',$detail->dluo_qty); |
|
1170
|
|
|
$libelleproduitservice.= "__N__ ".implode($dte,"-"); |
|
|
|
|
|
|
1171
|
|
|
} |
|
1172
|
|
|
} |
|
1173
|
|
|
|
|
1174
|
|
|
// Now we convert \n into br |
|
1175
|
|
|
if (dol_textishtml($libelleproduitservice)) $libelleproduitservice=preg_replace('/__N__/','<br>',$libelleproduitservice); |
|
1176
|
|
|
else $libelleproduitservice=preg_replace('/__N__/',"\n",$libelleproduitservice); |
|
1177
|
|
|
$libelleproduitservice=dol_htmlentitiesbr($libelleproduitservice,1); |
|
1178
|
|
|
|
|
1179
|
|
|
return $libelleproduitservice; |
|
1180
|
|
|
} |
|
1181
|
|
|
|
|
1182
|
|
|
/** |
|
1183
|
|
|
* Return line num |
|
1184
|
|
|
* |
|
1185
|
|
|
* @param Object $object Object |
|
1186
|
|
|
* @param int $i Current line number |
|
1187
|
|
|
* @param Translate $outputlangs Object langs for output |
|
1188
|
|
|
* @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) |
|
1189
|
|
|
* @return null|string |
|
1190
|
|
|
*/ |
|
1191
|
|
|
function pdf_getlinenum($object,$i,$outputlangs,$hidedetails=0) |
|
|
|
|
|
|
1192
|
|
|
{ |
|
1193
|
|
|
global $hookmanager; |
|
1194
|
|
|
|
|
1195
|
|
|
if (is_object($hookmanager) && (($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line))) |
|
1196
|
|
|
{ |
|
1197
|
|
|
$special_code = $object->lines[$i]->special_code; |
|
|
|
|
|
|
1198
|
|
|
if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line); |
|
1199
|
|
|
// TODO add hook function |
|
1200
|
|
|
} |
|
1201
|
|
|
else |
|
1202
|
|
|
{ |
|
1203
|
|
|
return dol_htmlentitiesbr($object->lines[$i]->num); |
|
1204
|
|
|
} |
|
1205
|
|
|
} |
|
1206
|
|
|
|
|
1207
|
|
|
|
|
1208
|
|
|
/** |
|
1209
|
|
|
* Return line product ref |
|
1210
|
|
|
* |
|
1211
|
|
|
* @param Object $object Object |
|
1212
|
|
|
* @param int $i Current line number |
|
1213
|
|
|
* @param Translate $outputlangs Object langs for output |
|
1214
|
|
|
* @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) |
|
1215
|
|
|
* @return null|string |
|
1216
|
|
|
*/ |
|
1217
|
|
|
function pdf_getlineref($object,$i,$outputlangs,$hidedetails=0) |
|
|
|
|
|
|
1218
|
|
|
{ |
|
1219
|
|
|
global $hookmanager; |
|
1220
|
|
|
|
|
1221
|
|
|
if (is_object($hookmanager) && (($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line))) |
|
1222
|
|
|
{ |
|
1223
|
|
|
$special_code = $object->lines[$i]->special_code; |
|
|
|
|
|
|
1224
|
|
|
if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line); |
|
1225
|
|
|
// TODO add hook function |
|
1226
|
|
|
} |
|
1227
|
|
|
else |
|
1228
|
|
|
{ |
|
1229
|
|
|
return dol_htmlentitiesbr($object->lines[$i]->product_ref); |
|
1230
|
|
|
} |
|
1231
|
|
|
} |
|
1232
|
|
|
|
|
1233
|
|
|
/** |
|
1234
|
|
|
* Return line ref_supplier |
|
1235
|
|
|
* |
|
1236
|
|
|
* @param Object $object Object |
|
1237
|
|
|
* @param int $i Current line number |
|
1238
|
|
|
* @param Translate $outputlangs Object langs for output |
|
1239
|
|
|
* @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) |
|
1240
|
|
|
* @return null|string |
|
1241
|
|
|
*/ |
|
1242
|
|
|
function pdf_getlineref_supplier($object,$i,$outputlangs,$hidedetails=0) |
|
|
|
|
|
|
1243
|
|
|
{ |
|
1244
|
|
|
global $hookmanager; |
|
1245
|
|
|
|
|
1246
|
|
|
if (is_object($hookmanager) && ( ($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) ) |
|
1247
|
|
|
{ |
|
1248
|
|
|
$special_code = $object->lines[$i]->special_code; |
|
|
|
|
|
|
1249
|
|
|
if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line); |
|
1250
|
|
|
// TODO add hook function |
|
1251
|
|
|
} |
|
1252
|
|
|
else |
|
1253
|
|
|
{ |
|
1254
|
|
|
return dol_htmlentitiesbr($object->lines[$i]->ref_supplier); |
|
1255
|
|
|
} |
|
1256
|
|
|
} |
|
1257
|
|
|
|
|
1258
|
|
|
/** |
|
1259
|
|
|
* Return line vat rate |
|
1260
|
|
|
* |
|
1261
|
|
|
* @param Object $object Object |
|
1262
|
|
|
* @param int $i Current line number |
|
1263
|
|
|
* @param Translate $outputlangs Object langs for output |
|
1264
|
|
|
* @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) |
|
1265
|
|
|
* @return string |
|
1266
|
|
|
*/ |
|
1267
|
|
|
function pdf_getlinevatrate($object,$i,$outputlangs,$hidedetails=0) |
|
1268
|
|
|
{ |
|
1269
|
|
|
global $hookmanager; |
|
1270
|
|
|
|
|
1271
|
|
|
if (is_object($hookmanager) && (($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line))) |
|
1272
|
|
|
{ |
|
1273
|
|
|
$special_code = $object->lines[$i]->special_code; |
|
1274
|
|
|
if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line); |
|
1275
|
|
|
$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code); |
|
1276
|
|
|
$action=''; |
|
1277
|
|
|
$reshook = $hookmanager->executeHooks('pdf_getlinevatrate',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
1278
|
|
|
|
|
1279
|
|
|
if(!empty($hookmanager->resPrint)) return $hookmanager->resPrint; |
|
1280
|
|
|
else return $reshook; |
|
1281
|
|
|
} |
|
1282
|
|
|
else |
|
1283
|
|
|
{ |
|
1284
|
|
|
if (empty($hidedetails) || $hidedetails > 1) return vatrate($object->lines[$i]->tva_tx,1,$object->lines[$i]->info_bits,1); |
|
1285
|
|
|
} |
|
1286
|
|
|
} |
|
1287
|
|
|
|
|
1288
|
|
|
/** |
|
1289
|
|
|
* Return line unit price excluding tax |
|
1290
|
|
|
* |
|
1291
|
|
|
* @param Object $object Object |
|
1292
|
|
|
* @param int $i Current line number |
|
1293
|
|
|
* @param Translate $outputlangs Object langs for output |
|
1294
|
|
|
* @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) |
|
1295
|
|
|
* @return string |
|
1296
|
|
|
*/ |
|
1297
|
|
|
function pdf_getlineupexcltax($object,$i,$outputlangs,$hidedetails=0) |
|
1298
|
|
|
{ |
|
1299
|
|
|
global $conf, $hookmanager; |
|
1300
|
|
|
|
|
1301
|
|
|
$sign=1; |
|
1302
|
|
|
if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1; |
|
1303
|
|
|
|
|
1304
|
|
|
if (is_object($hookmanager) && (($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line))) |
|
1305
|
|
|
{ |
|
1306
|
|
|
$special_code = $object->lines[$i]->special_code; |
|
1307
|
|
|
if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line); |
|
1308
|
|
|
$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code); |
|
1309
|
|
|
$action=''; |
|
1310
|
|
|
$reshook = $hookmanager->executeHooks('pdf_getlineupexcltax',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
1311
|
|
|
|
|
1312
|
|
|
if(!empty($hookmanager->resPrint)) return $hookmanager->resPrint; |
|
1313
|
|
|
else return $reshook; |
|
1314
|
|
|
} |
|
1315
|
|
|
else |
|
1316
|
|
|
{ |
|
1317
|
|
|
if (empty($hidedetails) || $hidedetails > 1) return price($sign * $object->lines[$i]->subprice, 0, $outputlangs); |
|
1318
|
|
|
} |
|
1319
|
|
|
} |
|
1320
|
|
|
|
|
1321
|
|
|
/** |
|
1322
|
|
|
* Return line unit price including tax |
|
1323
|
|
|
* |
|
1324
|
|
|
* @param Object $object Object |
|
1325
|
|
|
* @param int $i Current line number |
|
1326
|
|
|
* @param Translate $outputlangs Object langs for output |
|
1327
|
|
|
* @param int $hidedetails Hide value (0 = no, 1 = yes, 2 = just special lines) |
|
1328
|
|
|
* @return void |
|
1329
|
|
|
*/ |
|
1330
|
|
|
function pdf_getlineupwithtax($object,$i,$outputlangs,$hidedetails=0) |
|
1331
|
|
|
{ |
|
1332
|
|
|
global $hookmanager; |
|
1333
|
|
|
|
|
1334
|
|
|
if (is_object($hookmanager) && (($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line))) |
|
1335
|
|
|
{ |
|
1336
|
|
|
$special_code = $object->lines[$i]->special_code; |
|
1337
|
|
|
if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line); |
|
1338
|
|
|
foreach($object->hooks as $modules) |
|
1339
|
|
|
{ |
|
1340
|
|
|
if (method_exists($modules[$special_code],'pdf_getlineupwithtax')) return $modules[$special_code]->pdf_getlineupwithtax($object,$i,$outputlangs,$hidedetails); |
|
1341
|
|
|
} |
|
1342
|
|
|
} |
|
1343
|
|
|
else |
|
1344
|
|
|
{ |
|
1345
|
|
|
if (empty($hidedetails) || $hidedetails > 1) return price(($object->lines[$i]->subprice) + ($object->lines[$i]->subprice)*($object->lines[$i]->tva_tx)/100, 0, $outputlangs); |
|
1346
|
|
|
} |
|
1347
|
|
|
} |
|
1348
|
|
|
|
|
1349
|
|
|
/** |
|
1350
|
|
|
* Return line quantity |
|
1351
|
|
|
* |
|
1352
|
|
|
* @param Object $object Object |
|
1353
|
|
|
* @param int $i Current line number |
|
1354
|
|
|
* @param Translate $outputlangs Object langs for output |
|
1355
|
|
|
* @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) |
|
1356
|
|
|
* @return string |
|
1357
|
|
|
*/ |
|
1358
|
|
|
function pdf_getlineqty($object,$i,$outputlangs,$hidedetails=0) |
|
1359
|
|
|
{ |
|
1360
|
|
|
global $hookmanager; |
|
1361
|
|
|
|
|
1362
|
|
|
if ($object->lines[$i]->special_code != 3) |
|
1363
|
|
|
{ |
|
1364
|
|
|
if (is_object($hookmanager) && (( $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) ) |
|
1365
|
|
|
{ |
|
1366
|
|
|
$special_code = $object->lines[$i]->special_code; |
|
1367
|
|
|
if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line); |
|
1368
|
|
|
$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code); |
|
1369
|
|
|
$action=''; |
|
1370
|
|
|
$reshook = $hookmanager->executeHooks('pdf_getlineqty',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
1371
|
|
|
|
|
1372
|
|
|
if(!empty($hookmanager->resPrint)) return $hookmanager->resPrint; |
|
1373
|
|
|
else return $reshook; |
|
1374
|
|
|
|
|
1375
|
|
|
} |
|
1376
|
|
|
else |
|
1377
|
|
|
{ |
|
1378
|
|
|
if (empty($hidedetails) || $hidedetails > 1) return $object->lines[$i]->qty; |
|
1379
|
|
|
} |
|
1380
|
|
|
} |
|
1381
|
|
|
} |
|
1382
|
|
|
|
|
1383
|
|
|
/** |
|
1384
|
|
|
* Return line quantity asked |
|
1385
|
|
|
* |
|
1386
|
|
|
* @param Object $object Object |
|
1387
|
|
|
* @param int $i Current line number |
|
1388
|
|
|
* @param Translate $outputlangs Object langs for output |
|
1389
|
|
|
* @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) |
|
1390
|
|
|
* @return string |
|
1391
|
|
|
*/ |
|
1392
|
|
|
function pdf_getlineqty_asked($object,$i,$outputlangs,$hidedetails=0) |
|
1393
|
|
|
{ |
|
1394
|
|
|
global $hookmanager; |
|
1395
|
|
|
|
|
1396
|
|
|
if ($object->lines[$i]->special_code != 3) |
|
1397
|
|
|
{ |
|
1398
|
|
|
if (is_object($hookmanager) && (( $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) ) |
|
1399
|
|
|
{ |
|
1400
|
|
|
$special_code = $object->lines[$i]->special_code; |
|
1401
|
|
|
if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line); |
|
1402
|
|
|
$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code); |
|
1403
|
|
|
$action=''; |
|
1404
|
|
|
$reshook = $hookmanager->executeHooks('pdf_getlineqty_asked',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
1405
|
|
|
|
|
1406
|
|
|
if(!empty($hookmanager->resPrint)) return $hookmanager->resPrint; |
|
1407
|
|
|
else return $reshook; |
|
1408
|
|
|
} |
|
1409
|
|
|
else |
|
1410
|
|
|
{ |
|
1411
|
|
|
if (empty($hidedetails) || $hidedetails > 1) return $object->lines[$i]->qty_asked; |
|
1412
|
|
|
} |
|
1413
|
|
|
} |
|
1414
|
|
|
} |
|
1415
|
|
|
|
|
1416
|
|
|
/** |
|
1417
|
|
|
* Return line quantity shipped |
|
1418
|
|
|
* |
|
1419
|
|
|
* @param Object $object Object |
|
1420
|
|
|
* @param int $i Current line number |
|
1421
|
|
|
* @param Translate $outputlangs Object langs for output |
|
1422
|
|
|
* @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) |
|
1423
|
|
|
* @return string |
|
1424
|
|
|
*/ |
|
1425
|
|
|
function pdf_getlineqty_shipped($object,$i,$outputlangs,$hidedetails=0) |
|
1426
|
|
|
{ |
|
1427
|
|
|
global $hookmanager; |
|
1428
|
|
|
|
|
1429
|
|
|
if ($object->lines[$i]->special_code != 3) |
|
1430
|
|
|
{ |
|
1431
|
|
|
if (is_object($hookmanager) && (( $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) ) |
|
1432
|
|
|
{ |
|
1433
|
|
|
$special_code = $object->lines[$i]->special_code; |
|
1434
|
|
|
if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line); |
|
1435
|
|
|
$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code); |
|
1436
|
|
|
$action=''; |
|
1437
|
|
|
$reshook = $hookmanager->executeHooks('pdf_getlineqty_shipped',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
1438
|
|
|
|
|
1439
|
|
|
if(!empty($hookmanager->resPrint)) return $hookmanager->resPrint; |
|
1440
|
|
|
else return $reshook; |
|
1441
|
|
|
} |
|
1442
|
|
|
else |
|
1443
|
|
|
{ |
|
1444
|
|
|
if (empty($hidedetails) || $hidedetails > 1) return $object->lines[$i]->qty_shipped; |
|
1445
|
|
|
} |
|
1446
|
|
|
} |
|
1447
|
|
|
} |
|
1448
|
|
|
|
|
1449
|
|
|
/** |
|
1450
|
|
|
* Return line keep to ship quantity |
|
1451
|
|
|
* |
|
1452
|
|
|
* @param Object $object Object |
|
1453
|
|
|
* @param int $i Current line number |
|
1454
|
|
|
* @param Translate $outputlangs Object langs for output |
|
1455
|
|
|
* @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) |
|
1456
|
|
|
* @return void |
|
1457
|
|
|
*/ |
|
1458
|
|
|
function pdf_getlineqty_keeptoship($object,$i,$outputlangs,$hidedetails=0) |
|
1459
|
|
|
{ |
|
1460
|
|
|
global $hookmanager; |
|
1461
|
|
|
|
|
1462
|
|
|
if ($object->lines[$i]->special_code != 3) |
|
1463
|
|
|
{ |
|
1464
|
|
|
if (is_object($hookmanager) && (( $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) ) |
|
1465
|
|
|
{ |
|
1466
|
|
|
$special_code = $object->lines[$i]->special_code; |
|
1467
|
|
|
if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line); |
|
1468
|
|
|
$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code); |
|
1469
|
|
|
$action=''; |
|
1470
|
|
|
$reshook = $hookmanager->executeHooks('pdf_getlineqty_keeptoship',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
1471
|
|
|
|
|
1472
|
|
|
if(!empty($hookmanager->resPrint)) return $hookmanager->resPrint; |
|
1473
|
|
|
else return $reshook; |
|
1474
|
|
|
} |
|
1475
|
|
|
else |
|
1476
|
|
|
{ |
|
1477
|
|
|
if (empty($hidedetails) || $hidedetails > 1) return ($object->lines[$i]->qty_asked - $object->lines[$i]->qty_shipped); |
|
1478
|
|
|
} |
|
1479
|
|
|
} |
|
1480
|
|
|
} |
|
1481
|
|
|
|
|
1482
|
|
|
/** |
|
1483
|
|
|
* Return line unit |
|
1484
|
|
|
* |
|
1485
|
|
|
* @param Object $object Object |
|
1486
|
|
|
* @param int $i Current line number |
|
1487
|
|
|
* @param Translate $outputlangs Object langs for output |
|
1488
|
|
|
* @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) |
|
1489
|
|
|
* @param HookManager $hookmanager Hook manager instance |
|
1490
|
|
|
* @return void |
|
1491
|
|
|
*/ |
|
1492
|
|
|
function pdf_getlineunit($object, $i, $outputlangs, $hidedetails = 0, $hookmanager = false) |
|
1493
|
|
|
{ |
|
1494
|
|
|
global $langs; |
|
1495
|
|
|
if ($object->lines[$i]->special_code != 3) { |
|
1496
|
|
|
if (is_object($hookmanager) && (($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line))) { |
|
1497
|
|
|
$special_code = $object->lines[$i]->special_code; |
|
1498
|
|
|
if (!empty($object->lines[$i]->fk_parent_line)) { |
|
1499
|
|
|
$special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line); |
|
1500
|
|
|
} |
|
1501
|
|
|
$parameters = array( |
|
1502
|
|
|
'i' => $i, |
|
1503
|
|
|
'outputlangs' => $outputlangs, |
|
1504
|
|
|
'hidedetails' => $hidedetails, |
|
1505
|
|
|
'special_code' => $special_code |
|
1506
|
|
|
); |
|
1507
|
|
|
$action = ''; |
|
1508
|
|
|
$reshook = $hookmanager->executeHooks('pdf_getlineunit', $parameters, $object, |
|
1509
|
|
|
$action); // Note that $action and $object may have been modified by some hooks |
|
1510
|
|
|
|
|
1511
|
|
|
if(!empty($hookmanager->resPrint)) return $hookmanager->resPrint; |
|
1512
|
|
|
else return $reshook; |
|
1513
|
|
|
|
|
1514
|
|
|
} else { |
|
1515
|
|
|
if (empty($hidedetails) || $hidedetails > 1) { |
|
1516
|
|
|
return $langs->transnoentitiesnoconv($object->lines[$i]->getLabelOfUnit('short')); |
|
1517
|
|
|
} |
|
1518
|
|
|
} |
|
1519
|
|
|
} |
|
1520
|
|
|
} |
|
1521
|
|
|
|
|
1522
|
|
|
|
|
1523
|
|
|
/** |
|
1524
|
|
|
* Return line remise percent |
|
1525
|
|
|
* |
|
1526
|
|
|
* @param Object $object Object |
|
1527
|
|
|
* @param int $i Current line number |
|
1528
|
|
|
* @param Translate $outputlangs Object langs for output |
|
1529
|
|
|
* @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) |
|
1530
|
|
|
* @return string |
|
1531
|
|
|
*/ |
|
1532
|
|
|
function pdf_getlineremisepercent($object,$i,$outputlangs,$hidedetails=0) |
|
1533
|
|
|
{ |
|
1534
|
|
|
global $hookmanager; |
|
1535
|
|
|
|
|
1536
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
|
1537
|
|
|
|
|
1538
|
|
|
if ($object->lines[$i]->special_code != 3) |
|
1539
|
|
|
{ |
|
1540
|
|
|
if (is_object($hookmanager) && ( ($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) ) |
|
1541
|
|
|
{ |
|
1542
|
|
|
$special_code = $object->lines[$i]->special_code; |
|
1543
|
|
|
if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line); |
|
1544
|
|
|
$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code); |
|
1545
|
|
|
$action=''; |
|
1546
|
|
|
$reshook = $hookmanager->executeHooks('pdf_getlineremisepercent',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
1547
|
|
|
|
|
1548
|
|
|
if(!empty($hookmanager->resPrint)) return $hookmanager->resPrint; |
|
1549
|
|
|
else return $reshook; |
|
1550
|
|
|
} |
|
1551
|
|
|
else |
|
1552
|
|
|
{ |
|
1553
|
|
|
if (empty($hidedetails) || $hidedetails > 1) return dol_print_reduction($object->lines[$i]->remise_percent,$outputlangs); |
|
1554
|
|
|
} |
|
1555
|
|
|
} |
|
1556
|
|
|
} |
|
1557
|
|
|
|
|
1558
|
|
|
/** |
|
1559
|
|
|
* Return line percent |
|
1560
|
|
|
* |
|
1561
|
|
|
* @param Object $object Object |
|
1562
|
|
|
* @param int $i Current line number |
|
1563
|
|
|
* @param Translate $outputlangs Object langs for output |
|
1564
|
|
|
* @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) |
|
1565
|
|
|
* @param HookManager $hookmanager Hook manager instance |
|
1566
|
|
|
* @return void |
|
1567
|
|
|
*/ |
|
1568
|
|
|
function pdf_getlineprogress($object, $i, $outputlangs, $hidedetails = 0, $hookmanager = null) |
|
|
|
|
|
|
1569
|
|
|
{ |
|
1570
|
|
|
global $hookmanager; |
|
1571
|
|
|
|
|
1572
|
|
|
if ($object->lines[$i]->special_code != 3) { |
|
1573
|
|
|
if (is_object($hookmanager) && (($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line))) { |
|
1574
|
|
|
$special_code = $object->lines[$i]->special_code; |
|
1575
|
|
|
if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line); |
|
1576
|
|
|
$parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code); |
|
1577
|
|
|
$action = ''; |
|
1578
|
|
|
$reshook = $hookmanager->executeHooks('pdf_getlineprogress', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
|
1579
|
|
|
|
|
1580
|
|
|
if(!empty($hookmanager->resPrint)) return $hookmanager->resPrint; |
|
1581
|
|
|
else return $reshook; |
|
1582
|
|
|
} else { |
|
1583
|
|
|
if (empty($hidedetails) || $hidedetails > 1) return $object->lines[$i]->situation_percent . '%'; |
|
1584
|
|
|
} |
|
1585
|
|
|
} |
|
1586
|
|
|
} |
|
1587
|
|
|
|
|
1588
|
|
|
/** |
|
1589
|
|
|
* Return line total excluding tax |
|
1590
|
|
|
* |
|
1591
|
|
|
* @param Object $object Object |
|
1592
|
|
|
* @param int $i Current line number |
|
1593
|
|
|
* @param Translate $outputlangs Object langs for output |
|
1594
|
|
|
* @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) |
|
1595
|
|
|
* @return string Return total of line excl tax |
|
1596
|
|
|
*/ |
|
1597
|
|
|
function pdf_getlinetotalexcltax($object,$i,$outputlangs,$hidedetails=0) |
|
1598
|
|
|
{ |
|
1599
|
|
|
global $conf, $hookmanager; |
|
1600
|
|
|
|
|
1601
|
|
|
$sign=1; |
|
1602
|
|
|
if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1; |
|
1603
|
|
|
|
|
1604
|
|
|
if ($object->lines[$i]->special_code == 3) |
|
1605
|
|
|
{ |
|
1606
|
|
|
return $outputlangs->transnoentities("Option"); |
|
1607
|
|
|
} |
|
1608
|
|
|
else |
|
1609
|
|
|
{ |
|
1610
|
|
|
if (is_object($hookmanager) && (($object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line))) |
|
1611
|
|
|
{ |
|
1612
|
|
|
$special_code = $object->lines[$i]->special_code; |
|
1613
|
|
|
if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line); |
|
1614
|
|
|
$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code); |
|
1615
|
|
|
$action=''; |
|
1616
|
|
|
$reshook = $hookmanager->executeHooks('pdf_getlinetotalexcltax',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
1617
|
|
|
|
|
1618
|
|
|
if(!empty($hookmanager->resPrint)) return $hookmanager->resPrint; |
|
1619
|
|
|
else return $reshook; |
|
1620
|
|
|
} |
|
1621
|
|
|
else |
|
1622
|
|
|
{ |
|
1623
|
|
|
if (empty($hidedetails) || $hidedetails > 1) return price($sign * $object->lines[$i]->total_ht, 0, $outputlangs); |
|
1624
|
|
|
} |
|
1625
|
|
|
} |
|
1626
|
|
|
return ''; |
|
1627
|
|
|
} |
|
1628
|
|
|
|
|
1629
|
|
|
/** |
|
1630
|
|
|
* Return line total including tax |
|
1631
|
|
|
* |
|
1632
|
|
|
* @param Object $object Object |
|
1633
|
|
|
* @param int $i Current line number |
|
1634
|
|
|
* @param Translate $outputlangs Object langs for output |
|
1635
|
|
|
* @param int $hidedetails Hide value (0 = no, 1 = yes, 2 = just special lines) |
|
1636
|
|
|
* @return string Return total of line incl tax |
|
1637
|
|
|
*/ |
|
1638
|
|
|
function pdf_getlinetotalwithtax($object,$i,$outputlangs,$hidedetails=0) |
|
1639
|
|
|
{ |
|
1640
|
|
|
global $hookmanager; |
|
1641
|
|
|
|
|
1642
|
|
|
if ($object->lines[$i]->special_code == 3) |
|
1643
|
|
|
{ |
|
1644
|
|
|
return $outputlangs->transnoentities("Option"); |
|
1645
|
|
|
} |
|
1646
|
|
|
else |
|
1647
|
|
|
{ |
|
1648
|
|
|
if (is_object($hookmanager) && (($object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line))) |
|
1649
|
|
|
{ |
|
1650
|
|
|
$special_code = $object->lines[$i]->special_code; |
|
1651
|
|
|
if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line); |
|
1652
|
|
|
$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code); |
|
1653
|
|
|
$action=''; |
|
1654
|
|
|
$reshook = $hookmanager->executeHooks('pdf_getlinetotalwithtax',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
1655
|
|
|
|
|
1656
|
|
|
if(!empty($hookmanager->resPrint)) return $hookmanager->resPrint; |
|
1657
|
|
|
else return $reshook; |
|
1658
|
|
|
} |
|
1659
|
|
|
else |
|
1660
|
|
|
{ |
|
1661
|
|
|
if (empty($hidedetails) || $hidedetails > 1) return price(($object->lines[$i]->total_ht) + ($object->lines[$i]->total_ht)*($object->lines[$i]->tva_tx)/100, 0, $outputlangs); |
|
1662
|
|
|
} |
|
1663
|
|
|
} |
|
1664
|
|
|
return ''; |
|
1665
|
|
|
} |
|
1666
|
|
|
|
|
1667
|
|
|
/** |
|
1668
|
|
|
* Return total quantity of products and/or services |
|
1669
|
|
|
* |
|
1670
|
|
|
* @param Object $object Object |
|
1671
|
|
|
* @param string $type Type |
|
1672
|
|
|
* @param Translate $outputlangs Object langs for output |
|
1673
|
|
|
* @return integer |
|
1674
|
|
|
*/ |
|
1675
|
|
|
function pdf_getTotalQty($object,$type,$outputlangs) |
|
|
|
|
|
|
1676
|
|
|
{ |
|
1677
|
|
|
global $hookmanager; |
|
1678
|
|
|
|
|
1679
|
|
|
$total=0; |
|
1680
|
|
|
$nblignes=count($object->lines); |
|
1681
|
|
|
|
|
1682
|
|
|
// Loop on each lines |
|
1683
|
|
|
for ($i = 0 ; $i < $nblignes ; $i++) |
|
1684
|
|
|
{ |
|
1685
|
|
|
if ($object->lines[$i]->special_code != 3) |
|
1686
|
|
|
{ |
|
1687
|
|
|
if ($type=='all') |
|
1688
|
|
|
{ |
|
1689
|
|
|
$total += $object->lines[$i]->qty; |
|
1690
|
|
|
} |
|
1691
|
|
|
else if ($type==9 && is_object($hookmanager) && (($object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line))) |
|
1692
|
|
|
{ |
|
1693
|
|
|
$special_code = $object->lines[$i]->special_code; |
|
|
|
|
|
|
1694
|
|
|
if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line); |
|
1695
|
|
|
// TODO add hook function |
|
1696
|
|
|
} |
|
1697
|
|
|
else if ($type==0 && $object->lines[$i]->product_type == 0) |
|
1698
|
|
|
{ |
|
1699
|
|
|
$total += $object->lines[$i]->qty; |
|
1700
|
|
|
} |
|
1701
|
|
|
else if ($type==1 && $object->lines[$i]->product_type == 1) |
|
1702
|
|
|
{ |
|
1703
|
|
|
$total += $object->lines[$i]->qty; |
|
1704
|
|
|
} |
|
1705
|
|
|
} |
|
1706
|
|
|
} |
|
1707
|
|
|
|
|
1708
|
|
|
return $total; |
|
1709
|
|
|
} |
|
1710
|
|
|
|
|
1711
|
|
|
/** |
|
1712
|
|
|
* Return linked objects |
|
1713
|
|
|
* |
|
1714
|
|
|
* @param object $object Object |
|
1715
|
|
|
* @param Translate $outputlangs Object lang for output |
|
1716
|
|
|
* @return array Linked objects |
|
1717
|
|
|
*/ |
|
1718
|
|
|
function pdf_getLinkedObjects($object,$outputlangs) |
|
1719
|
|
|
{ |
|
1720
|
|
|
global $hookmanager; |
|
1721
|
|
|
|
|
1722
|
|
|
$linkedobjects=array(); |
|
1723
|
|
|
|
|
1724
|
|
|
$object->fetchObjectLinked(); |
|
1725
|
|
|
|
|
1726
|
|
|
foreach($object->linkedObjects as $objecttype => $objects) |
|
1727
|
|
|
{ |
|
1728
|
|
|
if ($objecttype == 'propal') |
|
1729
|
|
|
{ |
|
1730
|
|
|
$outputlangs->load('propal'); |
|
1731
|
|
|
|
|
1732
|
|
|
foreach($objects as $elementobject) |
|
1733
|
|
|
{ |
|
1734
|
|
|
$linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefProposal"); |
|
1735
|
|
|
$linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref); |
|
1736
|
|
|
$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DatePropal"); |
|
1737
|
|
|
$linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date,'day','',$outputlangs); |
|
1738
|
|
|
} |
|
1739
|
|
|
} |
|
1740
|
|
|
else if ($objecttype == 'commande') |
|
1741
|
|
|
{ |
|
1742
|
|
|
$outputlangs->load('orders'); |
|
1743
|
|
|
foreach($objects as $elementobject) |
|
1744
|
|
|
{ |
|
1745
|
|
|
$linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder"); |
|
1746
|
|
|
$linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref) . ($elementobject->ref_client ? ' ('.$elementobject->ref_client.')' : ''); |
|
1747
|
|
|
$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate"); |
|
1748
|
|
|
$linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date,'day','',$outputlangs); |
|
1749
|
|
|
} |
|
1750
|
|
|
} |
|
1751
|
|
|
else if ($objecttype == 'contrat') |
|
1752
|
|
|
{ |
|
1753
|
|
|
$outputlangs->load('contracts'); |
|
1754
|
|
|
foreach($objects as $elementobject) |
|
1755
|
|
|
{ |
|
1756
|
|
|
$linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefContract"); |
|
1757
|
|
|
$linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref); |
|
1758
|
|
|
$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DateContract"); |
|
1759
|
|
|
$linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date_contrat,'day','',$outputlangs); |
|
1760
|
|
|
} |
|
1761
|
|
|
} |
|
1762
|
|
|
else if ($objecttype == 'shipping') |
|
1763
|
|
|
{ |
|
1764
|
|
|
$outputlangs->load('orders'); |
|
1765
|
|
|
$outputlangs->load('sendings'); |
|
1766
|
|
|
foreach($objects as $elementobject) |
|
1767
|
|
|
{ |
|
1768
|
|
|
$elementobject->fetchObjectLinked(); |
|
1769
|
|
|
$order = $elementobject->linkedObjects['commande'][0]; |
|
1770
|
|
|
|
|
1771
|
|
|
if (! empty($object->linkedObjects['commande'])) // There is already a link to order so we show only info of shipment |
|
1772
|
|
|
{ |
|
1773
|
|
|
$linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefSending"); |
|
1774
|
|
|
$linkedobjects[$objecttype]['ref_value'].= $outputlangs->transnoentities($elementobject->ref); |
|
1775
|
|
|
$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DateSending"); |
|
1776
|
|
|
$linkedobjects[$objecttype]['date_value'].= dol_print_date($elementobject->date_delivery,'day','',$outputlangs); |
|
1777
|
|
|
} |
|
1778
|
|
|
else // We show both info of order and shipment |
|
1779
|
|
|
{ |
|
1780
|
|
|
$linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder") . ' / ' . $outputlangs->transnoentities("RefSending"); |
|
1781
|
|
|
$linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($order->ref) . ($order->ref_client ? ' ('.$order->ref_client.')' : ''); |
|
1782
|
|
|
$linkedobjects[$objecttype]['ref_value'].= ' / ' . $outputlangs->transnoentities($elementobject->ref); |
|
1783
|
|
|
$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate") . ' / ' . $outputlangs->transnoentities("DateSending"); |
|
1784
|
|
|
$linkedobjects[$objecttype]['date_value'] = dol_print_date($order->date,'day','',$outputlangs); |
|
1785
|
|
|
$linkedobjects[$objecttype]['date_value'].= ' / ' . dol_print_date($elementobject->date_delivery,'day','',$outputlangs); |
|
1786
|
|
|
} |
|
1787
|
|
|
} |
|
1788
|
|
|
} |
|
1789
|
|
|
} |
|
1790
|
|
|
|
|
1791
|
|
|
// For add external linked objects |
|
1792
|
|
|
if (is_object($hookmanager)) |
|
1793
|
|
|
{ |
|
1794
|
|
|
$parameters = array('linkedobjects' => $linkedobjects, 'outputlangs'=>$outputlangs); |
|
1795
|
|
|
$action=''; |
|
1796
|
|
|
$hookmanager->executeHooks('pdf_getLinkedObjects',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
1797
|
|
|
if (! empty($hookmanager->resArray)) $linkedobjects = $hookmanager->resArray; |
|
1798
|
|
|
} |
|
1799
|
|
|
|
|
1800
|
|
|
return $linkedobjects; |
|
1801
|
|
|
} |
|
1802
|
|
|
|
|
1803
|
|
|
/** |
|
1804
|
|
|
* Return dimensions to use for images onto PDF checking that width and height are not higher than |
|
1805
|
|
|
* maximum (16x32 by default). |
|
1806
|
|
|
* |
|
1807
|
|
|
* @param string $realpath Full path to photo file to use |
|
1808
|
|
|
* @return array Height and width to use to output image (in pdf user unit, so mm) |
|
1809
|
|
|
*/ |
|
1810
|
|
|
function pdf_getSizeForImage($realpath) |
|
1811
|
|
|
{ |
|
1812
|
|
|
global $conf; |
|
1813
|
|
|
|
|
1814
|
|
|
$maxwidth=(empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); |
|
1815
|
|
|
$maxheight=(empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT)?32:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT); |
|
1816
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; |
|
1817
|
|
|
$tmp=dol_getImageSize($realpath); |
|
1818
|
|
|
if ($tmp['height']) |
|
1819
|
|
|
{ |
|
1820
|
|
|
$width=(int) round($maxheight*$tmp['width']/$tmp['height']); // I try to use maxheight |
|
1821
|
|
|
if ($width > $maxwidth) // Pb with maxheight, so i use maxwidth |
|
1822
|
|
|
{ |
|
1823
|
|
|
$width=$maxwidth; |
|
1824
|
|
|
$height=(int) round($maxwidth*$tmp['height']/$tmp['width']); |
|
1825
|
|
|
} |
|
1826
|
|
|
else // No pb with maxheight |
|
1827
|
|
|
{ |
|
1828
|
|
|
$height=$maxheight; |
|
1829
|
|
|
} |
|
1830
|
|
|
} |
|
1831
|
|
|
return array('width'=>$width,'height'=>$height); |
|
|
|
|
|
|
1832
|
|
|
} |
|
1833
|
|
|
|
|
1834
|
|
|
|