Passed
Push — master ( 222e44...208bd5 )
by Alxarafe
31:22
created
dolibarr/htdocs/core/modules/import/import_csv.modules.php 3 patches
Indentation   +562 added lines, -562 removed lines patch added patch discarded remove patch
@@ -40,383 +40,383 @@  discard block
 block discarded – undo
40 40
 
41 41
     public $datatoimport;
42 42
 
43
-	/**
44
-	 * @var string Error code (or message)
45
-	 */
46
-	public $error='';
43
+    /**
44
+     * @var string Error code (or message)
45
+     */
46
+    public $error='';
47 47
 
48
-	/**
49
-	 * @var string[] Error codes (or messages)
50
-	 */
51
-	public $errors = array();
48
+    /**
49
+     * @var string[] Error codes (or messages)
50
+     */
51
+    public $errors = array();
52 52
 
53 53
     /**
54
-	 * @var int ID
55
-	 */
56
-	public $id;
54
+     * @var int ID
55
+     */
56
+    public $id;
57 57
 
58
-	/**
58
+    /**
59 59
      * @var string label
60 60
      */
61 61
     public $label;
62 62
 
63
-	public $extension;    // Extension of files imported by driver
63
+    public $extension;    // Extension of files imported by driver
64 64
 
65
-	/**
65
+    /**
66 66
      * Dolibarr version of driver
67 67
      * @public string
68 68
      */
69
-	public $version = 'dolibarr';
69
+    public $version = 'dolibarr';
70 70
 
71
-	public $label_lib;    // Label of external lib used by driver
71
+    public $label_lib;    // Label of external lib used by driver
72 72
 
73
-	public $version_lib;  // Version of external lib used by driver
73
+    public $version_lib;  // Version of external lib used by driver
74 74
 
75
-	public $separator;
75
+    public $separator;
76 76
 
77
-	public $file;      // Path of file
77
+    public $file;      // Path of file
78 78
 
79
-	public $handle;    // Handle fichier
79
+    public $handle;    // Handle fichier
80 80
 
81
-	public $cacheconvert=array();      // Array to cache list of value found after a convertion
81
+    public $cacheconvert=array();      // Array to cache list of value found after a convertion
82 82
 
83
-	public $cachefieldtable=array();   // Array to cache list of value found into fields@tables
83
+    public $cachefieldtable=array();   // Array to cache list of value found into fields@tables
84 84
 
85
-	public $nbinsert = 0; // # of insert done during the import
85
+    public $nbinsert = 0; // # of insert done during the import
86 86
 
87
-	public $nbupdate = 0; // # of update done during the import
87
+    public $nbupdate = 0; // # of update done during the import
88 88
 
89 89
 
90
-	/**
91
-	 *	Constructor
92
-	 *
93
-	 *	@param	DoliDB		$db				Database handler
94
-	 *	@param	string		$datatoimport	String code describing import set (ex: 'societe_1')
95
-	 */
96
-	function __construct($db,$datatoimport)
97
-	{
98
-		global $conf, $langs;
99
-		$this->db = $db;
100
-
101
-		$this->separator=(GETPOST('separator')?GETPOST('separator'):(empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE)?',':$conf->global->IMPORT_CSV_SEPARATOR_TO_USE));
102
-		$this->enclosure='"';
103
-		$this->escape='"';
104
-
105
-		$this->id='csv';                // Same value then xxx in file name export_xxx.modules.php
106
-		$this->label='Csv';             // Label of driver
107
-		$this->desc=$langs->trans("CSVFormatDesc",$this->separator,$this->enclosure,$this->escape);
108
-		$this->extension='csv';         // Extension for generated file by this driver
109
-		$this->picto='mime/other';		// Picto
110
-		$this->version='1.34';         // Driver version
111
-
112
-		// If driver use an external library, put its name here
113
-		$this->label_lib='Dolibarr';
114
-		$this->version_lib=DOL_VERSION;
115
-
116
-		$this->datatoimport=$datatoimport;
117
-		if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db);
118
-	}
90
+    /**
91
+     *	Constructor
92
+     *
93
+     *	@param	DoliDB		$db				Database handler
94
+     *	@param	string		$datatoimport	String code describing import set (ex: 'societe_1')
95
+     */
96
+    function __construct($db,$datatoimport)
97
+    {
98
+        global $conf, $langs;
99
+        $this->db = $db;
100
+
101
+        $this->separator=(GETPOST('separator')?GETPOST('separator'):(empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE)?',':$conf->global->IMPORT_CSV_SEPARATOR_TO_USE));
102
+        $this->enclosure='"';
103
+        $this->escape='"';
104
+
105
+        $this->id='csv';                // Same value then xxx in file name export_xxx.modules.php
106
+        $this->label='Csv';             // Label of driver
107
+        $this->desc=$langs->trans("CSVFormatDesc",$this->separator,$this->enclosure,$this->escape);
108
+        $this->extension='csv';         // Extension for generated file by this driver
109
+        $this->picto='mime/other';		// Picto
110
+        $this->version='1.34';         // Driver version
111
+
112
+        // If driver use an external library, put its name here
113
+        $this->label_lib='Dolibarr';
114
+        $this->version_lib=DOL_VERSION;
115
+
116
+        $this->datatoimport=$datatoimport;
117
+        if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db);
118
+    }
119 119
 
120 120
 
121 121
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
122
-	/**
123
-	 * 	Output header of an example file for this format
124
-	 *
125
-	 * 	@param	Translate	$outputlangs		Output language
126
-	 *  @return	string
127
-	 */
128
-	function write_header_example($outputlangs)
129
-	{
122
+    /**
123
+     * 	Output header of an example file for this format
124
+     *
125
+     * 	@param	Translate	$outputlangs		Output language
126
+     *  @return	string
127
+     */
128
+    function write_header_example($outputlangs)
129
+    {
130 130
         // phpcs:enable
131
-		return '';
132
-	}
131
+        return '';
132
+    }
133 133
 
134 134
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
135
-	/**
136
-	 * 	Output title line of an example file for this format
137
-	 *
138
-	 * 	@param	Translate	$outputlangs		Output language
139
-	 *  @param	array		$headerlinefields	Array of fields name
140
-	 * 	@return	string
141
-	 */
142
-	function write_title_example($outputlangs,$headerlinefields)
143
-	{
135
+    /**
136
+     * 	Output title line of an example file for this format
137
+     *
138
+     * 	@param	Translate	$outputlangs		Output language
139
+     *  @param	array		$headerlinefields	Array of fields name
140
+     * 	@return	string
141
+     */
142
+    function write_title_example($outputlangs,$headerlinefields)
143
+    {
144 144
         // phpcs:enable
145
-		$s=join($this->separator,array_map('cleansep',$headerlinefields));
146
-		return $s."\n";
147
-	}
145
+        $s=join($this->separator,array_map('cleansep',$headerlinefields));
146
+        return $s."\n";
147
+    }
148 148
 
149 149
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
150
-	/**
151
-	 * 	Output record of an example file for this format
152
-	 *
153
-	 * 	@param	Translate	$outputlangs		Output language
154
-	 * 	@param	array		$contentlinevalues	Array of lines
155
-	 * 	@return	string
156
-	 */
157
-	function write_record_example($outputlangs,$contentlinevalues)
158
-	{
150
+    /**
151
+     * 	Output record of an example file for this format
152
+     *
153
+     * 	@param	Translate	$outputlangs		Output language
154
+     * 	@param	array		$contentlinevalues	Array of lines
155
+     * 	@return	string
156
+     */
157
+    function write_record_example($outputlangs,$contentlinevalues)
158
+    {
159 159
         // phpcs:enable
160
-		$s=join($this->separator,array_map('cleansep',$contentlinevalues));
161
-		return $s."\n";
162
-	}
160
+        $s=join($this->separator,array_map('cleansep',$contentlinevalues));
161
+        return $s."\n";
162
+    }
163 163
 
164 164
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
165
-	/**
166
-	 * 	Output footer of an example file for this format
167
-	 *
168
-	 * 	@param	Translate	$outputlangs		Output language
169
-	 *  @return	string
170
-	 */
171
-	function write_footer_example($outputlangs)
172
-	{
165
+    /**
166
+     * 	Output footer of an example file for this format
167
+     *
168
+     * 	@param	Translate	$outputlangs		Output language
169
+     *  @return	string
170
+     */
171
+    function write_footer_example($outputlangs)
172
+    {
173 173
         // phpcs:enable
174
-		return '';
175
-	}
174
+        return '';
175
+    }
176 176
 
177 177
 
178 178
 
179 179
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
180
-	/**
181
-	 *	Open input file
182
-	 *
183
-	 *	@param	string	$file		Path of filename
184
-	 *	@return	int					<0 if KO, >=0 if OK
185
-	 */
186
-	function import_open_file($file)
187
-	{
180
+    /**
181
+     *	Open input file
182
+     *
183
+     *	@param	string	$file		Path of filename
184
+     *	@return	int					<0 if KO, >=0 if OK
185
+     */
186
+    function import_open_file($file)
187
+    {
188 188
         // phpcs:enable
189
-		global $langs;
190
-		$ret=1;
191
-
192
-		dol_syslog(get_class($this)."::open_file file=".$file);
193
-
194
-		ini_set('auto_detect_line_endings',1);	// For MAC compatibility
195
-
196
-		$this->handle = fopen(dol_osencode($file), "r");
197
-		if (! $this->handle)
198
-		{
199
-			$langs->load("errors");
200
-			$this->error=$langs->trans("ErrorFailToOpenFile",$file);
201
-			$ret=-1;
202
-		}
203
-		else
204
-		{
205
-			$this->file=$file;
206
-		}
207
-
208
-		return $ret;
209
-	}
189
+        global $langs;
190
+        $ret=1;
191
+
192
+        dol_syslog(get_class($this)."::open_file file=".$file);
193
+
194
+        ini_set('auto_detect_line_endings',1);	// For MAC compatibility
195
+
196
+        $this->handle = fopen(dol_osencode($file), "r");
197
+        if (! $this->handle)
198
+        {
199
+            $langs->load("errors");
200
+            $this->error=$langs->trans("ErrorFailToOpenFile",$file);
201
+            $ret=-1;
202
+        }
203
+        else
204
+        {
205
+            $this->file=$file;
206
+        }
207
+
208
+        return $ret;
209
+    }
210 210
 
211 211
 
212 212
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
213
-	/**
214
-	 * 	Return nb of records. File must be closed.
215
-	 *
216
-	 *	@param	string	$file		Path of filename
217
-	 * 	@return		int		<0 if KO, >=0 if OK
218
-	 */
219
-	function import_get_nb_of_lines($file)
220
-	{
213
+    /**
214
+     * 	Return nb of records. File must be closed.
215
+     *
216
+     *	@param	string	$file		Path of filename
217
+     * 	@return		int		<0 if KO, >=0 if OK
218
+     */
219
+    function import_get_nb_of_lines($file)
220
+    {
221 221
         // phpcs:enable
222
-       return dol_count_nb_of_line($file);
222
+        return dol_count_nb_of_line($file);
223 223
     }
224 224
 
225 225
 
226 226
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
227
-	/**
228
-	 * 	Input header line from file
229
-	 *
230
-	 * 	@return		int		<0 if KO, >=0 if OK
231
-	 */
232
-	function import_read_header()
233
-	{
227
+    /**
228
+     * 	Input header line from file
229
+     *
230
+     * 	@return		int		<0 if KO, >=0 if OK
231
+     */
232
+    function import_read_header()
233
+    {
234 234
         // phpcs:enable
235
-		return 0;
236
-	}
235
+        return 0;
236
+    }
237 237
 
238 238
 
239 239
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
240
-	/**
241
-	 * 	Return array of next record in input file.
242
-	 *
243
-	 * 	@return		Array		Array of field values. Data are UTF8 encoded. [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=not empty string)
244
-	 */
245
-	function import_read_record()
246
-	{
240
+    /**
241
+     * 	Return array of next record in input file.
242
+     *
243
+     * 	@return		Array		Array of field values. Data are UTF8 encoded. [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=not empty string)
244
+     */
245
+    function import_read_record()
246
+    {
247 247
         // phpcs:enable
248
-		global $conf;
249
-
250
-		$arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure,$this->escape);
251
-
252
-		// End of file
253
-		if ($arrayres === false) return false;
254
-
255
-		//var_dump($this->handle);
256
-		//var_dump($arrayres);exit;
257
-		$newarrayres=array();
258
-		if ($arrayres && is_array($arrayres))
259
-		{
260
-			foreach($arrayres as $key => $val)
261
-			{
262
-				if (! empty($conf->global->IMPORT_CSV_FORCE_CHARSET))	// Forced charset
263
-				{
264
-					if (strtolower($conf->global->IMPORT_CSV_FORCE_CHARSET) == 'utf8')
265
-					{
266
-						$newarrayres[$key]['val']=$val;
267
-						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
268
-					}
269
-					else
270
-					{
271
-						$newarrayres[$key]['val']=utf8_encode($val);
272
-						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
273
-					}
274
-				}
275
-				else	// Autodetect format (UTF8 or ISO)
276
-				{
277
-					if (utf8_check($val))
278
-					{
279
-						$newarrayres[$key]['val']=$val;
280
-						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
281
-					}
282
-					else
283
-					{
284
-						$newarrayres[$key]['val']=utf8_encode($val);
285
-						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
286
-					}
287
-				}
288
-			}
289
-
290
-			$this->col=count($newarrayres);
291
-		}
292
-
293
-		return $newarrayres;
294
-	}
248
+        global $conf;
249
+
250
+        $arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure,$this->escape);
251
+
252
+        // End of file
253
+        if ($arrayres === false) return false;
254
+
255
+        //var_dump($this->handle);
256
+        //var_dump($arrayres);exit;
257
+        $newarrayres=array();
258
+        if ($arrayres && is_array($arrayres))
259
+        {
260
+            foreach($arrayres as $key => $val)
261
+            {
262
+                if (! empty($conf->global->IMPORT_CSV_FORCE_CHARSET))	// Forced charset
263
+                {
264
+                    if (strtolower($conf->global->IMPORT_CSV_FORCE_CHARSET) == 'utf8')
265
+                    {
266
+                        $newarrayres[$key]['val']=$val;
267
+                        $newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
268
+                    }
269
+                    else
270
+                    {
271
+                        $newarrayres[$key]['val']=utf8_encode($val);
272
+                        $newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
273
+                    }
274
+                }
275
+                else	// Autodetect format (UTF8 or ISO)
276
+                {
277
+                    if (utf8_check($val))
278
+                    {
279
+                        $newarrayres[$key]['val']=$val;
280
+                        $newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
281
+                    }
282
+                    else
283
+                    {
284
+                        $newarrayres[$key]['val']=utf8_encode($val);
285
+                        $newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
286
+                    }
287
+                }
288
+            }
289
+
290
+            $this->col=count($newarrayres);
291
+        }
292
+
293
+        return $newarrayres;
294
+    }
295 295
 
296 296
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
297
-	/**
298
-	 * 	Close file handle
299
-	 *
300
-	 *  @return	integer
301
-	 */
302
-	function import_close_file()
303
-	{
297
+    /**
298
+     * 	Close file handle
299
+     *
300
+     *  @return	integer
301
+     */
302
+    function import_close_file()
303
+    {
304 304
         // phpcs:enable
305
-		fclose($this->handle);
306
-		return 0;
307
-	}
305
+        fclose($this->handle);
306
+        return 0;
307
+    }
308 308
 
309 309
 
310 310
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
311
-	/**
312
-	 * Insert a record into database
313
-	 *
314
-	 * @param	array	$arrayrecord					Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]...
315
-	 * @param	array	$array_match_file_to_database	Array of target fields where to insert data: [fieldpos] => 's.fieldname', [fieldpos+1]...
316
-	 * @param 	Object	$objimport						Object import (contains objimport->array_import_tables, objimport->array_import_fields, objimport->array_import_convertvalue, ...)
317
-	 * @param	int		$maxfields						Max number of fields to use
318
-	 * @param	string	$importid						Import key
319
-	 * @param	array	$updatekeys						Array of keys to use to try to do an update first before insert. This field are defined into the module descriptor.
320
-	 * @return	int										<0 if KO, >0 if OK
321
-	 */
322
-	function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid,$updatekeys)
323
-	{
311
+    /**
312
+     * Insert a record into database
313
+     *
314
+     * @param	array	$arrayrecord					Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]...
315
+     * @param	array	$array_match_file_to_database	Array of target fields where to insert data: [fieldpos] => 's.fieldname', [fieldpos+1]...
316
+     * @param 	Object	$objimport						Object import (contains objimport->array_import_tables, objimport->array_import_fields, objimport->array_import_convertvalue, ...)
317
+     * @param	int		$maxfields						Max number of fields to use
318
+     * @param	string	$importid						Import key
319
+     * @param	array	$updatekeys						Array of keys to use to try to do an update first before insert. This field are defined into the module descriptor.
320
+     * @return	int										<0 if KO, >0 if OK
321
+     */
322
+    function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid,$updatekeys)
323
+    {
324 324
         // phpcs:enable
325
-		global $langs,$conf,$user;
325
+        global $langs,$conf,$user;
326 326
         global $thirdparty_static;    	// Specific to thirdparty import
327
-		global $tablewithentity_cache;	// Cache to avoid to call  desc at each rows on tables
328
-
329
-		$error=0;
330
-		$warning=0;
331
-		$this->errors=array();
332
-		$this->warnings=array();
333
-
334
-		//dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid);
335
-
336
-		//var_dump($array_match_file_to_database);
337
-		//var_dump($arrayrecord);
338
-		$array_match_database_to_file=array_flip($array_match_file_to_database);
339
-		$sort_array_match_file_to_database=$array_match_file_to_database;
340
-		ksort($sort_array_match_file_to_database);
341
-
342
-		//var_dump($sort_array_match_file_to_database);
343
-
344
-		if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0]['val'])))
345
-		{
346
-			//print 'W';
347
-			$this->warnings[$warning]['lib']=$langs->trans('EmptyLine');
348
-			$this->warnings[$warning]['type']='EMPTY';
349
-			$warning++;
350
-		}
351
-		else
352
-		{
353
-			$last_insert_id_array = array(); // store the last inserted auto_increment id for each table, so that dependent tables can be inserted with the appropriate id (eg: extrafields fk_object will be set with the last inserted object's id)
354
-			$updatedone = false;
355
-			$insertdone = false;
356
-			// For each table to insert, me make a separate insert
357
-			foreach($objimport->array_import_tables[0] as $alias => $tablename)
358
-			{
359
-				// Build sql request
360
-				$sql='';
361
-				$listfields=array();
362
-				$listvalues=array();
363
-				$i=0;
364
-				$errorforthistable=0;
365
-
366
-				// Define $tablewithentity_cache[$tablename] if not already defined
367
-				if (! isset($tablewithentity_cache[$tablename]))	// keep this test with "isset"
368
-				{
369
-					dol_syslog("Check if table ".$tablename." has an entity field");
370
-					$resql=$this->db->DDLDescTable($tablename,'entity');
371
-					if ($resql)
372
-					{
373
-						$obj=$this->db->fetch_object($resql);
374
-						if ($obj) $tablewithentity_cache[$tablename]=1;		// table contains entity field
375
-						else $tablewithentity_cache[$tablename]=0;			// table does not contains entity field
376
-					}
377
-					else dol_print_error($this->db);
378
-				}
379
-				else
380
-				{
381
-					//dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]);
382
-				}
383
-
384
-
385
-				// Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom)
386
-				foreach($sort_array_match_file_to_database as $key => $val)
387
-				{
388
-				    $fieldalias=preg_replace('/\..*$/i','',$val);
389
-				    $fieldname=preg_replace('/^.*\./i','',$val);
390
-
391
-				    if ($alias != $fieldalias) continue;    // Not a field of current table
392
-
393
-					if ($key <= $maxfields)
394
-					{
395
-						// Set $newval with value to insert and set $listvalues with sql request part for insert
396
-						$newval='';
397
-						if ($arrayrecord[($key-1)]['type'] > 0) $newval=$arrayrecord[($key-1)]['val'];    // If type of field into input file is not empty string (so defined into input file), we get value
398
-
399
-						// Make some tests on $newval
400
-
401
-						// Is it a required field ?
402
-						if (preg_match('/\*/',$objimport->array_import_fields[0][$val]) && ((string) $newval==''))
403
-						{
404
-							$this->errors[$error]['lib']=$langs->trans('ErrorMissingMandatoryValue',$key);
405
-							$this->errors[$error]['type']='NOTNULL';
406
-							$errorforthistable++;
407
-							$error++;
408
-						}
409
-						// Test format only if field is not a missing mandatory field (field may be a value or empty but not mandatory)
410
-						else
411
-						{
412
-						    // We convert field if required
413
-						    if (! empty($objimport->array_import_convertvalue[0][$val]))
414
-						    {
327
+        global $tablewithentity_cache;	// Cache to avoid to call  desc at each rows on tables
328
+
329
+        $error=0;
330
+        $warning=0;
331
+        $this->errors=array();
332
+        $this->warnings=array();
333
+
334
+        //dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid);
335
+
336
+        //var_dump($array_match_file_to_database);
337
+        //var_dump($arrayrecord);
338
+        $array_match_database_to_file=array_flip($array_match_file_to_database);
339
+        $sort_array_match_file_to_database=$array_match_file_to_database;
340
+        ksort($sort_array_match_file_to_database);
341
+
342
+        //var_dump($sort_array_match_file_to_database);
343
+
344
+        if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0]['val'])))
345
+        {
346
+            //print 'W';
347
+            $this->warnings[$warning]['lib']=$langs->trans('EmptyLine');
348
+            $this->warnings[$warning]['type']='EMPTY';
349
+            $warning++;
350
+        }
351
+        else
352
+        {
353
+            $last_insert_id_array = array(); // store the last inserted auto_increment id for each table, so that dependent tables can be inserted with the appropriate id (eg: extrafields fk_object will be set with the last inserted object's id)
354
+            $updatedone = false;
355
+            $insertdone = false;
356
+            // For each table to insert, me make a separate insert
357
+            foreach($objimport->array_import_tables[0] as $alias => $tablename)
358
+            {
359
+                // Build sql request
360
+                $sql='';
361
+                $listfields=array();
362
+                $listvalues=array();
363
+                $i=0;
364
+                $errorforthistable=0;
365
+
366
+                // Define $tablewithentity_cache[$tablename] if not already defined
367
+                if (! isset($tablewithentity_cache[$tablename]))	// keep this test with "isset"
368
+                {
369
+                    dol_syslog("Check if table ".$tablename." has an entity field");
370
+                    $resql=$this->db->DDLDescTable($tablename,'entity');
371
+                    if ($resql)
372
+                    {
373
+                        $obj=$this->db->fetch_object($resql);
374
+                        if ($obj) $tablewithentity_cache[$tablename]=1;		// table contains entity field
375
+                        else $tablewithentity_cache[$tablename]=0;			// table does not contains entity field
376
+                    }
377
+                    else dol_print_error($this->db);
378
+                }
379
+                else
380
+                {
381
+                    //dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]);
382
+                }
383
+
384
+
385
+                // Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom)
386
+                foreach($sort_array_match_file_to_database as $key => $val)
387
+                {
388
+                    $fieldalias=preg_replace('/\..*$/i','',$val);
389
+                    $fieldname=preg_replace('/^.*\./i','',$val);
390
+
391
+                    if ($alias != $fieldalias) continue;    // Not a field of current table
392
+
393
+                    if ($key <= $maxfields)
394
+                    {
395
+                        // Set $newval with value to insert and set $listvalues with sql request part for insert
396
+                        $newval='';
397
+                        if ($arrayrecord[($key-1)]['type'] > 0) $newval=$arrayrecord[($key-1)]['val'];    // If type of field into input file is not empty string (so defined into input file), we get value
398
+
399
+                        // Make some tests on $newval
400
+
401
+                        // Is it a required field ?
402
+                        if (preg_match('/\*/',$objimport->array_import_fields[0][$val]) && ((string) $newval==''))
403
+                        {
404
+                            $this->errors[$error]['lib']=$langs->trans('ErrorMissingMandatoryValue',$key);
405
+                            $this->errors[$error]['type']='NOTNULL';
406
+                            $errorforthistable++;
407
+                            $error++;
408
+                        }
409
+                        // Test format only if field is not a missing mandatory field (field may be a value or empty but not mandatory)
410
+                        else
411
+                        {
412
+                            // We convert field if required
413
+                            if (! empty($objimport->array_import_convertvalue[0][$val]))
414
+                            {
415 415
                                 //print 'Must convert '.$newval.' with rule '.join(',',$objimport->array_import_convertvalue[0][$val]).'. ';
416 416
                                 if ($objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeid'
417
-                                	|| $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromref'
418
-                                	|| $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel'
419
-                                	)
417
+                                    || $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromref'
418
+                                    || $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel'
419
+                                    )
420 420
                                 {
421 421
                                     // New val can be an id or ref. If it start with id: it is forced to id, if it start with ref: it is forced to ref. It not, we try to guess.
422 422
                                     $isidorref='id';
@@ -431,10 +431,10 @@  discard block
 block discarded – undo
431 431
                                         $method=$objimport->array_import_convertvalue[0][$val]['method'];
432 432
                                         if ($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] != '')
433 433
                                         {
434
-                                        	$newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval];
434
+                                            $newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval];
435 435
                                         }
436 436
                                         else
437
-										{
437
+                                        {
438 438
                                             $resultload = dol_include_once($file);
439 439
                                             if (empty($resultload))
440 440
                                             {
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
                                             // If not found, try the fetch from label
448 448
                                             if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel')
449 449
                                             {
450
-												call_user_func_array(array($classinstance, $method),array('', '', $newval));
450
+                                                call_user_func_array(array($classinstance, $method),array('', '', $newval));
451 451
                                             }
452 452
                                             $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]=$classinstance->id;
453 453
                                             //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. ';
@@ -534,264 +534,264 @@  discard block
 block discarded – undo
534 534
                                 }
535 535
 
536 536
                                 //print 'Val to use as insert is '.$newval.'<br>';
537
-						    }
538
-
539
-						    // Test regexp
540
-							if (! empty($objimport->array_import_regex[0][$val]) && ($newval != ''))
541
-							{
542
-								// If test is "Must exist in a field@table"
543
-								if (preg_match('/^(.*)@(.*)$/',$objimport->array_import_regex[0][$val],$reg))
544
-								{
545
-									$field=$reg[1];
546
-									$table=$reg[2];
547
-
548
-									// Load content of field@table into cache array
549
-									if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
550
-									{
551
-										$sql="SELECT ".$field." as aliasfield FROM ".$table;
552
-										$resql=$this->db->query($sql);
553
-										if ($resql)
554
-										{
555
-											$num=$this->db->num_rows($resql);
556
-											$i=0;
557
-											while ($i < $num)
558
-											{
559
-												$obj=$this->db->fetch_object($resql);
560
-												if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
561
-												$i++;
562
-											}
563
-										}
564
-										else
565
-										{
566
-											dol_print_error($this->db);
567
-										}
568
-									}
569
-
570
-									// Now we check cache is not empty (should not) and key is into cache
571
-									if (! is_array($this->cachefieldtable[$field.'@'.$table]) || ! in_array($newval,$this->cachefieldtable[$field.'@'.$table]))
572
-									{
573
-										$this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$table);
574
-										$this->errors[$error]['type']='FOREIGNKEY';
575
-									    $errorforthistable++;
576
-										$error++;
577
-									}
578
-								}
579
-								// If test is just a static regex
580
-								else if (! preg_match('/'.$objimport->array_import_regex[0][$val].'/i',$newval))
581
-								{
582
-								    //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."<br>";
583
-									$this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorWrongValueForField',$key,$newval,$objimport->array_import_regex[0][$val]);
584
-									$this->errors[$error]['type']='REGEX';
585
-									$errorforthistable++;
586
-									$error++;
587
-								}
588
-							}
589
-
590
-							// Other tests
591
-							// ...
592
-						}
593
-
594
-						// Define $listfields and $listvalues to build SQL request
595
-						$listfields[] = $fieldname;
596
-
597
-						// Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert
598
-						if (empty($newval) && $arrayrecord[($key-1)]['type'] < 0) {
537
+                            }
538
+
539
+                            // Test regexp
540
+                            if (! empty($objimport->array_import_regex[0][$val]) && ($newval != ''))
541
+                            {
542
+                                // If test is "Must exist in a field@table"
543
+                                if (preg_match('/^(.*)@(.*)$/',$objimport->array_import_regex[0][$val],$reg))
544
+                                {
545
+                                    $field=$reg[1];
546
+                                    $table=$reg[2];
547
+
548
+                                    // Load content of field@table into cache array
549
+                                    if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
550
+                                    {
551
+                                        $sql="SELECT ".$field." as aliasfield FROM ".$table;
552
+                                        $resql=$this->db->query($sql);
553
+                                        if ($resql)
554
+                                        {
555
+                                            $num=$this->db->num_rows($resql);
556
+                                            $i=0;
557
+                                            while ($i < $num)
558
+                                            {
559
+                                                $obj=$this->db->fetch_object($resql);
560
+                                                if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
561
+                                                $i++;
562
+                                            }
563
+                                        }
564
+                                        else
565
+                                        {
566
+                                            dol_print_error($this->db);
567
+                                        }
568
+                                    }
569
+
570
+                                    // Now we check cache is not empty (should not) and key is into cache
571
+                                    if (! is_array($this->cachefieldtable[$field.'@'.$table]) || ! in_array($newval,$this->cachefieldtable[$field.'@'.$table]))
572
+                                    {
573
+                                        $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$table);
574
+                                        $this->errors[$error]['type']='FOREIGNKEY';
575
+                                        $errorforthistable++;
576
+                                        $error++;
577
+                                    }
578
+                                }
579
+                                // If test is just a static regex
580
+                                else if (! preg_match('/'.$objimport->array_import_regex[0][$val].'/i',$newval))
581
+                                {
582
+                                    //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."<br>";
583
+                                    $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorWrongValueForField',$key,$newval,$objimport->array_import_regex[0][$val]);
584
+                                    $this->errors[$error]['type']='REGEX';
585
+                                    $errorforthistable++;
586
+                                    $error++;
587
+                                }
588
+                            }
589
+
590
+                            // Other tests
591
+                            // ...
592
+                        }
593
+
594
+                        // Define $listfields and $listvalues to build SQL request
595
+                        $listfields[] = $fieldname;
596
+
597
+                        // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert
598
+                        if (empty($newval) && $arrayrecord[($key-1)]['type'] < 0) {
599 599
                             $listvalues[] = ($newval=='0'?$newval:"null");
600 600
                         } elseif (empty($newval) && $arrayrecord[($key-1)]['type'] == 0) {
601 601
                             $listvalues[] = "''";
602 602
                         } else {
603 603
                             $listvalues[] = "'".$this->db->escape($newval)."'";
604 604
                         }
605
-					}
606
-					$i++;
607
-				}
608
-
609
-				// We add hidden fields (but only if there is at least one field to add into table)
610
-				if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0]))
611
-				{
612
-    				// Loop on each hidden fields to add them into listfields/listvalues
613
-				    foreach($objimport->array_import_fieldshidden[0] as $key => $val)
614
-    				{
615
-    				    if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue;    // Not a field of current table
616
-    				    if ($val == 'user->id')
617
-    				    {
618
-    				        $listfields[] = preg_replace('/^'.preg_quote($alias).'\./','',$key);
619
-    				        $listvalues[] = $user->id;
620
-    				    }
621
-    				    elseif (preg_match('/^lastrowid-/',$val))
622
-    				    {
623
-    				        $tmp=explode('-',$val);
624
-    				        $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0;
625
-							$keyfield = preg_replace('/^'.preg_quote($alias).'\./','',$key);
626
-    				        $listfields[] = $keyfield;
605
+                    }
606
+                    $i++;
607
+                }
608
+
609
+                // We add hidden fields (but only if there is at least one field to add into table)
610
+                if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0]))
611
+                {
612
+                    // Loop on each hidden fields to add them into listfields/listvalues
613
+                    foreach($objimport->array_import_fieldshidden[0] as $key => $val)
614
+                    {
615
+                        if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue;    // Not a field of current table
616
+                        if ($val == 'user->id')
617
+                        {
618
+                            $listfields[] = preg_replace('/^'.preg_quote($alias).'\./','',$key);
619
+                            $listvalues[] = $user->id;
620
+                        }
621
+                        elseif (preg_match('/^lastrowid-/',$val))
622
+                        {
623
+                            $tmp=explode('-',$val);
624
+                            $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0;
625
+                            $keyfield = preg_replace('/^'.preg_quote($alias).'\./','',$key);
626
+                            $listfields[] = $keyfield;
627 627
                             $listvalues[] = $lastinsertid;
628
-    				        //print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit;
629
-    				    }
630
-    				}
631
-				}
632
-				//print 'listfields='.$listfields.'<br>listvalues='.$listvalues.'<br>';
633
-
634
-				// If no error for this $alias/$tablename, we have a complete $listfields and $listvalues that are defined
635
-				// so we can try to make the insert or update now.
636
-				if (! $errorforthistable)
637
-				{
638
-					//print "$alias/$tablename/$listfields/$listvalues<br>";
639
-					if (!empty($listfields))
640
-					{
641
-						$updatedone = false;
642
-						$insertdone = false;
643
-
644
-						if (!empty($updatekeys)) {
645
-							// We do SELECT to get the rowid, if we already have the rowid, it's to be used below for related tables (extrafields)
646
-
647
-							if (empty($lastinsertid)) {	// No insert done yet for a parent table
648
-								$sqlSelect = 'SELECT rowid FROM '.$tablename;
649
-
650
-								$data = array_combine($listfields, $listvalues);
651
-								$where = array();
652
-								$filters = array();
653
-								foreach ($updatekeys as $key) {
654
-									$col = $objimport->array_import_updatekeys[0][$key];
655
-									$key=preg_replace('/^.*\./i','',$key);
656
-									$where[] = $key.' = '.$data[$key];
657
-									$filters[] = $col.' = '.$data[$key];
658
-								}
659
-								$sqlSelect.= ' WHERE '.implode(' AND ', $where);
660
-
661
-								$resql=$this->db->query($sqlSelect);
662
-								if($resql) {
663
-									$res = $this->db->fetch_object($resql);
664
-									if($resql->num_rows == 1) {
665
-										$lastinsertid = $res->rowid;
666
-										$last_insert_id_array[$tablename] = $lastinsertid;
667
-									} else if($resql->num_rows > 1) {
668
-										$this->errors[$error]['lib']=$langs->trans('MultipleRecordFoundWithTheseFilters', implode($filters, ', '));
669
-										$this->errors[$error]['type']='SQL';
670
-										$error++;
671
-									} else {
672
-										// No record found with filters, insert will be tried below
673
-									}
674
-								}
675
-								else
676
-								{
677
-									//print 'E';
678
-									$this->errors[$error]['lib']=$this->db->lasterror();
679
-									$this->errors[$error]['type']='SQL';
680
-									$error++;
681
-								}
682
-							} else {
683
-								// We have a last INSERT ID (got by previous pass), so we check if we have a row referencing this foreign key.
684
-								// This is required when updating table with some extrafields. When inserting a record in parent table, we can make
685
-								// a direct insert into subtable extrafields, but when me wake an update, the insertid is defined and the child record
686
-								// may already exists. So we rescan the extrafield table to know if record exists or not for the rowid.
687
-								// Note: For extrafield tablename, we have in importfieldshidden_array an enty 'extra.fk_object'=>'lastrowid-tableparent' so $keyfield is 'fk_object'
688
-								$sqlSelect = 'SELECT rowid FROM '.$tablename;
689
-
690
-								if(empty($keyfield)) $keyfield = 'rowid';
691
-								$sqlSelect .= ' WHERE '.$keyfield.' = '.$lastinsertid;
692
-
693
-								$resql=$this->db->query($sqlSelect);
694
-								if($resql) {
695
-									$res = $this->db->fetch_object($resql);
696
-									if($resql->num_rows == 1) {
697
-										// We have a row referencing this last foreign key, continue with UPDATE.
698
-									} else {
699
-										// No record found referencing this last foreign key,
700
-										// force $lastinsertid to 0 so we INSERT below.
701
-										$lastinsertid = 0;
702
-									}
703
-								}
704
-								else
705
-								{
706
-									//print 'E';
707
-									$this->errors[$error]['lib']=$this->db->lasterror();
708
-									$this->errors[$error]['type']='SQL';
709
-									$error++;
710
-								}
711
-							}
712
-
713
-							if (!empty($lastinsertid)) {
714
-								// Build SQL UPDATE request
715
-								$sqlstart = 'UPDATE '.$tablename;
716
-
717
-								$data = array_combine($listfields, $listvalues);
718
-								$set = array();
719
-								foreach ($data as $key => $val) {
720
-									$set[] = $key.' = '.$val;
721
-								}
722
-								$sqlstart.= ' SET '.implode(', ', $set);
723
-
724
-								if(empty($keyfield)) $keyfield = 'rowid';
725
-								$sqlend = ' WHERE '.$keyfield.' = '.$lastinsertid;
726
-
727
-								$sql = $sqlstart.$sqlend;
728
-
729
-								// Run update request
730
-								$resql=$this->db->query($sql);
731
-								if($resql) {
732
-									// No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed
733
-									$updatedone = true;
734
-								}
735
-								else
736
-								{
737
-									//print 'E';
738
-									$this->errors[$error]['lib']=$this->db->lasterror();
739
-									$this->errors[$error]['type']='SQL';
740
-									$error++;
741
-								}
742
-							}
743
-						}
744
-
745
-						// Update not done, we do insert
746
-						if (!$error && !$updatedone) {
747
-							// Build SQL INSERT request
748
-							$sqlstart = 'INSERT INTO '.$tablename.'('.implode(', ', $listfields).', import_key';
749
-							$sqlend = ') VALUES('.implode(', ', $listvalues).", '".$importid."'";
750
-							if (! empty($tablewithentity_cache[$tablename])) {
751
-								$sqlstart.= ', entity';
752
-								$sqlend.= ', '.$conf->entity;
753
-							}
754
-							if (! empty($objimport->array_import_tables_creator[0][$alias])) {
755
-								$sqlstart.= ', '.$objimport->array_import_tables_creator[0][$alias];
756
-								$sqlend.=', '.$user->id;
757
-							}
758
-							$sql = $sqlstart.$sqlend.')';
759
-							dol_syslog("import_csv.modules", LOG_DEBUG);
760
-
761
-							// Run insert request
762
-							if ($sql)
763
-							{
764
-								$resql=$this->db->query($sql);
765
-								if ($resql)
766
-								{
767
-								    $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename); // store the last inserted auto_increment id for each table, so that child tables can be inserted with the appropriate id. This must be done just after the INSERT request, else we risk losing the id (because another sql query will be issued somewhere in Dolibarr).
768
-								    $insertdone = true;
769
-								}
770
-								else
771
-								{
772
-									//print 'E';
773
-									$this->errors[$error]['lib']=$this->db->lasterror();
774
-									$this->errors[$error]['type']='SQL';
775
-									$error++;
776
-								}
777
-							}
778
-						}
779
-					}
780
-					/*else
628
+                            //print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit;
629
+                        }
630
+                    }
631
+                }
632
+                //print 'listfields='.$listfields.'<br>listvalues='.$listvalues.'<br>';
633
+
634
+                // If no error for this $alias/$tablename, we have a complete $listfields and $listvalues that are defined
635
+                // so we can try to make the insert or update now.
636
+                if (! $errorforthistable)
637
+                {
638
+                    //print "$alias/$tablename/$listfields/$listvalues<br>";
639
+                    if (!empty($listfields))
640
+                    {
641
+                        $updatedone = false;
642
+                        $insertdone = false;
643
+
644
+                        if (!empty($updatekeys)) {
645
+                            // We do SELECT to get the rowid, if we already have the rowid, it's to be used below for related tables (extrafields)
646
+
647
+                            if (empty($lastinsertid)) {	// No insert done yet for a parent table
648
+                                $sqlSelect = 'SELECT rowid FROM '.$tablename;
649
+
650
+                                $data = array_combine($listfields, $listvalues);
651
+                                $where = array();
652
+                                $filters = array();
653
+                                foreach ($updatekeys as $key) {
654
+                                    $col = $objimport->array_import_updatekeys[0][$key];
655
+                                    $key=preg_replace('/^.*\./i','',$key);
656
+                                    $where[] = $key.' = '.$data[$key];
657
+                                    $filters[] = $col.' = '.$data[$key];
658
+                                }
659
+                                $sqlSelect.= ' WHERE '.implode(' AND ', $where);
660
+
661
+                                $resql=$this->db->query($sqlSelect);
662
+                                if($resql) {
663
+                                    $res = $this->db->fetch_object($resql);
664
+                                    if($resql->num_rows == 1) {
665
+                                        $lastinsertid = $res->rowid;
666
+                                        $last_insert_id_array[$tablename] = $lastinsertid;
667
+                                    } else if($resql->num_rows > 1) {
668
+                                        $this->errors[$error]['lib']=$langs->trans('MultipleRecordFoundWithTheseFilters', implode($filters, ', '));
669
+                                        $this->errors[$error]['type']='SQL';
670
+                                        $error++;
671
+                                    } else {
672
+                                        // No record found with filters, insert will be tried below
673
+                                    }
674
+                                }
675
+                                else
676
+                                {
677
+                                    //print 'E';
678
+                                    $this->errors[$error]['lib']=$this->db->lasterror();
679
+                                    $this->errors[$error]['type']='SQL';
680
+                                    $error++;
681
+                                }
682
+                            } else {
683
+                                // We have a last INSERT ID (got by previous pass), so we check if we have a row referencing this foreign key.
684
+                                // This is required when updating table with some extrafields. When inserting a record in parent table, we can make
685
+                                // a direct insert into subtable extrafields, but when me wake an update, the insertid is defined and the child record
686
+                                // may already exists. So we rescan the extrafield table to know if record exists or not for the rowid.
687
+                                // Note: For extrafield tablename, we have in importfieldshidden_array an enty 'extra.fk_object'=>'lastrowid-tableparent' so $keyfield is 'fk_object'
688
+                                $sqlSelect = 'SELECT rowid FROM '.$tablename;
689
+
690
+                                if(empty($keyfield)) $keyfield = 'rowid';
691
+                                $sqlSelect .= ' WHERE '.$keyfield.' = '.$lastinsertid;
692
+
693
+                                $resql=$this->db->query($sqlSelect);
694
+                                if($resql) {
695
+                                    $res = $this->db->fetch_object($resql);
696
+                                    if($resql->num_rows == 1) {
697
+                                        // We have a row referencing this last foreign key, continue with UPDATE.
698
+                                    } else {
699
+                                        // No record found referencing this last foreign key,
700
+                                        // force $lastinsertid to 0 so we INSERT below.
701
+                                        $lastinsertid = 0;
702
+                                    }
703
+                                }
704
+                                else
705
+                                {
706
+                                    //print 'E';
707
+                                    $this->errors[$error]['lib']=$this->db->lasterror();
708
+                                    $this->errors[$error]['type']='SQL';
709
+                                    $error++;
710
+                                }
711
+                            }
712
+
713
+                            if (!empty($lastinsertid)) {
714
+                                // Build SQL UPDATE request
715
+                                $sqlstart = 'UPDATE '.$tablename;
716
+
717
+                                $data = array_combine($listfields, $listvalues);
718
+                                $set = array();
719
+                                foreach ($data as $key => $val) {
720
+                                    $set[] = $key.' = '.$val;
721
+                                }
722
+                                $sqlstart.= ' SET '.implode(', ', $set);
723
+
724
+                                if(empty($keyfield)) $keyfield = 'rowid';
725
+                                $sqlend = ' WHERE '.$keyfield.' = '.$lastinsertid;
726
+
727
+                                $sql = $sqlstart.$sqlend;
728
+
729
+                                // Run update request
730
+                                $resql=$this->db->query($sql);
731
+                                if($resql) {
732
+                                    // No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed
733
+                                    $updatedone = true;
734
+                                }
735
+                                else
736
+                                {
737
+                                    //print 'E';
738
+                                    $this->errors[$error]['lib']=$this->db->lasterror();
739
+                                    $this->errors[$error]['type']='SQL';
740
+                                    $error++;
741
+                                }
742
+                            }
743
+                        }
744
+
745
+                        // Update not done, we do insert
746
+                        if (!$error && !$updatedone) {
747
+                            // Build SQL INSERT request
748
+                            $sqlstart = 'INSERT INTO '.$tablename.'('.implode(', ', $listfields).', import_key';
749
+                            $sqlend = ') VALUES('.implode(', ', $listvalues).", '".$importid."'";
750
+                            if (! empty($tablewithentity_cache[$tablename])) {
751
+                                $sqlstart.= ', entity';
752
+                                $sqlend.= ', '.$conf->entity;
753
+                            }
754
+                            if (! empty($objimport->array_import_tables_creator[0][$alias])) {
755
+                                $sqlstart.= ', '.$objimport->array_import_tables_creator[0][$alias];
756
+                                $sqlend.=', '.$user->id;
757
+                            }
758
+                            $sql = $sqlstart.$sqlend.')';
759
+                            dol_syslog("import_csv.modules", LOG_DEBUG);
760
+
761
+                            // Run insert request
762
+                            if ($sql)
763
+                            {
764
+                                $resql=$this->db->query($sql);
765
+                                if ($resql)
766
+                                {
767
+                                    $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename); // store the last inserted auto_increment id for each table, so that child tables can be inserted with the appropriate id. This must be done just after the INSERT request, else we risk losing the id (because another sql query will be issued somewhere in Dolibarr).
768
+                                    $insertdone = true;
769
+                                }
770
+                                else
771
+                                {
772
+                                    //print 'E';
773
+                                    $this->errors[$error]['lib']=$this->db->lasterror();
774
+                                    $this->errors[$error]['type']='SQL';
775
+                                    $error++;
776
+                                }
777
+                            }
778
+                        }
779
+                    }
780
+                    /*else
781 781
 					{
782 782
 						dol_print_error('','ErrorFieldListEmptyFor '.$alias."/".$tablename);
783 783
 					}*/
784
-				}
784
+                }
785 785
 
786
-			    if ($error) break;
787
-			}
786
+                if ($error) break;
787
+            }
788 788
 
789
-			if($updatedone) $this->nbupdate++;
790
-			if($insertdone) $this->nbinsert++;
791
-		}
789
+            if($updatedone) $this->nbupdate++;
790
+            if($insertdone) $this->nbinsert++;
791
+        }
792 792
 
793
-		return 1;
794
-	}
793
+        return 1;
794
+    }
795 795
 }
796 796
 
797 797
 /**
@@ -802,5 +802,5 @@  discard block
 block discarded – undo
802 802
  */
803 803
 function cleansep($value)
804 804
 {
805
-	return str_replace(array(',',';'),'/',$value);
805
+    return str_replace(array(',',';'),'/',$value);
806 806
 };
Please login to merge, or discard this patch.
Spacing   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  *		\brief      File to load import files with CSV format
26 26
  */
27 27
 
28
-require_once DOL_DOCUMENT_ROOT .'/core/modules/import/modules_import.php';
28
+require_once DOL_DOCUMENT_ROOT.'/core/modules/import/modules_import.php';
29 29
 
30 30
 
31 31
 /**
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	/**
44 44
 	 * @var string Error code (or message)
45 45
 	 */
46
-	public $error='';
46
+	public $error = '';
47 47
 
48 48
 	/**
49 49
 	 * @var string[] Error codes (or messages)
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      */
61 61
     public $label;
62 62
 
63
-	public $extension;    // Extension of files imported by driver
63
+	public $extension; // Extension of files imported by driver
64 64
 
65 65
 	/**
66 66
      * Dolibarr version of driver
@@ -68,19 +68,19 @@  discard block
 block discarded – undo
68 68
      */
69 69
 	public $version = 'dolibarr';
70 70
 
71
-	public $label_lib;    // Label of external lib used by driver
71
+	public $label_lib; // Label of external lib used by driver
72 72
 
73
-	public $version_lib;  // Version of external lib used by driver
73
+	public $version_lib; // Version of external lib used by driver
74 74
 
75 75
 	public $separator;
76 76
 
77
-	public $file;      // Path of file
77
+	public $file; // Path of file
78 78
 
79
-	public $handle;    // Handle fichier
79
+	public $handle; // Handle fichier
80 80
 
81
-	public $cacheconvert=array();      // Array to cache list of value found after a convertion
81
+	public $cacheconvert = array(); // Array to cache list of value found after a convertion
82 82
 
83
-	public $cachefieldtable=array();   // Array to cache list of value found into fields@tables
83
+	public $cachefieldtable = array(); // Array to cache list of value found into fields@tables
84 84
 
85 85
 	public $nbinsert = 0; // # of insert done during the import
86 86
 
@@ -93,28 +93,28 @@  discard block
 block discarded – undo
93 93
 	 *	@param	DoliDB		$db				Database handler
94 94
 	 *	@param	string		$datatoimport	String code describing import set (ex: 'societe_1')
95 95
 	 */
96
-	function __construct($db,$datatoimport)
96
+	function __construct($db, $datatoimport)
97 97
 	{
98 98
 		global $conf, $langs;
99 99
 		$this->db = $db;
100 100
 
101
-		$this->separator=(GETPOST('separator')?GETPOST('separator'):(empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE)?',':$conf->global->IMPORT_CSV_SEPARATOR_TO_USE));
102
-		$this->enclosure='"';
103
-		$this->escape='"';
101
+		$this->separator = (GETPOST('separator') ?GETPOST('separator') : (empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE) ? ',' : $conf->global->IMPORT_CSV_SEPARATOR_TO_USE));
102
+		$this->enclosure = '"';
103
+		$this->escape = '"';
104 104
 
105
-		$this->id='csv';                // Same value then xxx in file name export_xxx.modules.php
106
-		$this->label='Csv';             // Label of driver
107
-		$this->desc=$langs->trans("CSVFormatDesc",$this->separator,$this->enclosure,$this->escape);
108
-		$this->extension='csv';         // Extension for generated file by this driver
109
-		$this->picto='mime/other';		// Picto
110
-		$this->version='1.34';         // Driver version
105
+		$this->id = 'csv'; // Same value then xxx in file name export_xxx.modules.php
106
+		$this->label = 'Csv'; // Label of driver
107
+		$this->desc = $langs->trans("CSVFormatDesc", $this->separator, $this->enclosure, $this->escape);
108
+		$this->extension = 'csv'; // Extension for generated file by this driver
109
+		$this->picto = 'mime/other'; // Picto
110
+		$this->version = '1.34'; // Driver version
111 111
 
112 112
 		// If driver use an external library, put its name here
113
-		$this->label_lib='Dolibarr';
114
-		$this->version_lib=DOL_VERSION;
113
+		$this->label_lib = 'Dolibarr';
114
+		$this->version_lib = DOL_VERSION;
115 115
 
116
-		$this->datatoimport=$datatoimport;
117
-		if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db);
116
+		$this->datatoimport = $datatoimport;
117
+		if (preg_match('/^societe_/', $datatoimport)) $this->thirpartyobject = new Societe($this->db);
118 118
 	}
119 119
 
120 120
 
@@ -139,10 +139,10 @@  discard block
 block discarded – undo
139 139
 	 *  @param	array		$headerlinefields	Array of fields name
140 140
 	 * 	@return	string
141 141
 	 */
142
-	function write_title_example($outputlangs,$headerlinefields)
142
+	function write_title_example($outputlangs, $headerlinefields)
143 143
 	{
144 144
         // phpcs:enable
145
-		$s=join($this->separator,array_map('cleansep',$headerlinefields));
145
+		$s = join($this->separator, array_map('cleansep', $headerlinefields));
146 146
 		return $s."\n";
147 147
 	}
148 148
 
@@ -154,10 +154,10 @@  discard block
 block discarded – undo
154 154
 	 * 	@param	array		$contentlinevalues	Array of lines
155 155
 	 * 	@return	string
156 156
 	 */
157
-	function write_record_example($outputlangs,$contentlinevalues)
157
+	function write_record_example($outputlangs, $contentlinevalues)
158 158
 	{
159 159
         // phpcs:enable
160
-		$s=join($this->separator,array_map('cleansep',$contentlinevalues));
160
+		$s = join($this->separator, array_map('cleansep', $contentlinevalues));
161 161
 		return $s."\n";
162 162
 	}
163 163
 
@@ -187,22 +187,22 @@  discard block
 block discarded – undo
187 187
 	{
188 188
         // phpcs:enable
189 189
 		global $langs;
190
-		$ret=1;
190
+		$ret = 1;
191 191
 
192 192
 		dol_syslog(get_class($this)."::open_file file=".$file);
193 193
 
194
-		ini_set('auto_detect_line_endings',1);	// For MAC compatibility
194
+		ini_set('auto_detect_line_endings', 1); // For MAC compatibility
195 195
 
196 196
 		$this->handle = fopen(dol_osencode($file), "r");
197
-		if (! $this->handle)
197
+		if (!$this->handle)
198 198
 		{
199 199
 			$langs->load("errors");
200
-			$this->error=$langs->trans("ErrorFailToOpenFile",$file);
201
-			$ret=-1;
200
+			$this->error = $langs->trans("ErrorFailToOpenFile", $file);
201
+			$ret = -1;
202 202
 		}
203 203
 		else
204 204
 		{
205
-			$this->file=$file;
205
+			$this->file = $file;
206 206
 		}
207 207
 
208 208
 		return $ret;
@@ -247,47 +247,47 @@  discard block
 block discarded – undo
247 247
         // phpcs:enable
248 248
 		global $conf;
249 249
 
250
-		$arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure,$this->escape);
250
+		$arrayres = fgetcsv($this->handle, 100000, $this->separator, $this->enclosure, $this->escape);
251 251
 
252 252
 		// End of file
253 253
 		if ($arrayres === false) return false;
254 254
 
255 255
 		//var_dump($this->handle);
256 256
 		//var_dump($arrayres);exit;
257
-		$newarrayres=array();
257
+		$newarrayres = array();
258 258
 		if ($arrayres && is_array($arrayres))
259 259
 		{
260
-			foreach($arrayres as $key => $val)
260
+			foreach ($arrayres as $key => $val)
261 261
 			{
262
-				if (! empty($conf->global->IMPORT_CSV_FORCE_CHARSET))	// Forced charset
262
+				if (!empty($conf->global->IMPORT_CSV_FORCE_CHARSET))	// Forced charset
263 263
 				{
264 264
 					if (strtolower($conf->global->IMPORT_CSV_FORCE_CHARSET) == 'utf8')
265 265
 					{
266
-						$newarrayres[$key]['val']=$val;
267
-						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
266
+						$newarrayres[$key]['val'] = $val;
267
+						$newarrayres[$key]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we considere it's null
268 268
 					}
269 269
 					else
270 270
 					{
271
-						$newarrayres[$key]['val']=utf8_encode($val);
272
-						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
271
+						$newarrayres[$key]['val'] = utf8_encode($val);
272
+						$newarrayres[$key]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we considere it's null
273 273
 					}
274 274
 				}
275 275
 				else	// Autodetect format (UTF8 or ISO)
276 276
 				{
277 277
 					if (utf8_check($val))
278 278
 					{
279
-						$newarrayres[$key]['val']=$val;
280
-						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
279
+						$newarrayres[$key]['val'] = $val;
280
+						$newarrayres[$key]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we considere it's null
281 281
 					}
282 282
 					else
283 283
 					{
284
-						$newarrayres[$key]['val']=utf8_encode($val);
285
-						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
284
+						$newarrayres[$key]['val'] = utf8_encode($val);
285
+						$newarrayres[$key]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we considere it's null
286 286
 					}
287 287
 				}
288 288
 			}
289 289
 
290
-			$this->col=count($newarrayres);
290
+			$this->col = count($newarrayres);
291 291
 		}
292 292
 
293 293
 		return $newarrayres;
@@ -319,24 +319,24 @@  discard block
 block discarded – undo
319 319
 	 * @param	array	$updatekeys						Array of keys to use to try to do an update first before insert. This field are defined into the module descriptor.
320 320
 	 * @return	int										<0 if KO, >0 if OK
321 321
 	 */
322
-	function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid,$updatekeys)
322
+	function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
323 323
 	{
324 324
         // phpcs:enable
325
-		global $langs,$conf,$user;
326
-        global $thirdparty_static;    	// Specific to thirdparty import
327
-		global $tablewithentity_cache;	// Cache to avoid to call  desc at each rows on tables
325
+		global $langs, $conf, $user;
326
+        global $thirdparty_static; // Specific to thirdparty import
327
+		global $tablewithentity_cache; // Cache to avoid to call  desc at each rows on tables
328 328
 
329
-		$error=0;
330
-		$warning=0;
331
-		$this->errors=array();
332
-		$this->warnings=array();
329
+		$error = 0;
330
+		$warning = 0;
331
+		$this->errors = array();
332
+		$this->warnings = array();
333 333
 
334 334
 		//dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid);
335 335
 
336 336
 		//var_dump($array_match_file_to_database);
337 337
 		//var_dump($arrayrecord);
338
-		$array_match_database_to_file=array_flip($array_match_file_to_database);
339
-		$sort_array_match_file_to_database=$array_match_file_to_database;
338
+		$array_match_database_to_file = array_flip($array_match_file_to_database);
339
+		$sort_array_match_file_to_database = $array_match_file_to_database;
340 340
 		ksort($sort_array_match_file_to_database);
341 341
 
342 342
 		//var_dump($sort_array_match_file_to_database);
@@ -344,8 +344,8 @@  discard block
 block discarded – undo
344 344
 		if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0]['val'])))
345 345
 		{
346 346
 			//print 'W';
347
-			$this->warnings[$warning]['lib']=$langs->trans('EmptyLine');
348
-			$this->warnings[$warning]['type']='EMPTY';
347
+			$this->warnings[$warning]['lib'] = $langs->trans('EmptyLine');
348
+			$this->warnings[$warning]['type'] = 'EMPTY';
349 349
 			$warning++;
350 350
 		}
351 351
 		else
@@ -354,25 +354,25 @@  discard block
 block discarded – undo
354 354
 			$updatedone = false;
355 355
 			$insertdone = false;
356 356
 			// For each table to insert, me make a separate insert
357
-			foreach($objimport->array_import_tables[0] as $alias => $tablename)
357
+			foreach ($objimport->array_import_tables[0] as $alias => $tablename)
358 358
 			{
359 359
 				// Build sql request
360
-				$sql='';
361
-				$listfields=array();
362
-				$listvalues=array();
363
-				$i=0;
364
-				$errorforthistable=0;
360
+				$sql = '';
361
+				$listfields = array();
362
+				$listvalues = array();
363
+				$i = 0;
364
+				$errorforthistable = 0;
365 365
 
366 366
 				// Define $tablewithentity_cache[$tablename] if not already defined
367
-				if (! isset($tablewithentity_cache[$tablename]))	// keep this test with "isset"
367
+				if (!isset($tablewithentity_cache[$tablename]))	// keep this test with "isset"
368 368
 				{
369 369
 					dol_syslog("Check if table ".$tablename." has an entity field");
370
-					$resql=$this->db->DDLDescTable($tablename,'entity');
370
+					$resql = $this->db->DDLDescTable($tablename, 'entity');
371 371
 					if ($resql)
372 372
 					{
373
-						$obj=$this->db->fetch_object($resql);
374
-						if ($obj) $tablewithentity_cache[$tablename]=1;		// table contains entity field
375
-						else $tablewithentity_cache[$tablename]=0;			// table does not contains entity field
373
+						$obj = $this->db->fetch_object($resql);
374
+						if ($obj) $tablewithentity_cache[$tablename] = 1; // table contains entity field
375
+						else $tablewithentity_cache[$tablename] = 0; // table does not contains entity field
376 376
 					}
377 377
 					else dol_print_error($this->db);
378 378
 				}
@@ -383,26 +383,26 @@  discard block
 block discarded – undo
383 383
 
384 384
 
385 385
 				// Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom)
386
-				foreach($sort_array_match_file_to_database as $key => $val)
386
+				foreach ($sort_array_match_file_to_database as $key => $val)
387 387
 				{
388
-				    $fieldalias=preg_replace('/\..*$/i','',$val);
389
-				    $fieldname=preg_replace('/^.*\./i','',$val);
388
+				    $fieldalias = preg_replace('/\..*$/i', '', $val);
389
+				    $fieldname = preg_replace('/^.*\./i', '', $val);
390 390
 
391
-				    if ($alias != $fieldalias) continue;    // Not a field of current table
391
+				    if ($alias != $fieldalias) continue; // Not a field of current table
392 392
 
393 393
 					if ($key <= $maxfields)
394 394
 					{
395 395
 						// Set $newval with value to insert and set $listvalues with sql request part for insert
396
-						$newval='';
397
-						if ($arrayrecord[($key-1)]['type'] > 0) $newval=$arrayrecord[($key-1)]['val'];    // If type of field into input file is not empty string (so defined into input file), we get value
396
+						$newval = '';
397
+						if ($arrayrecord[($key - 1)]['type'] > 0) $newval = $arrayrecord[($key - 1)]['val']; // If type of field into input file is not empty string (so defined into input file), we get value
398 398
 
399 399
 						// Make some tests on $newval
400 400
 
401 401
 						// Is it a required field ?
402
-						if (preg_match('/\*/',$objimport->array_import_fields[0][$val]) && ((string) $newval==''))
402
+						if (preg_match('/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval == ''))
403 403
 						{
404
-							$this->errors[$error]['lib']=$langs->trans('ErrorMissingMandatoryValue',$key);
405
-							$this->errors[$error]['type']='NOTNULL';
404
+							$this->errors[$error]['lib'] = $langs->trans('ErrorMissingMandatoryValue', $key);
405
+							$this->errors[$error]['type'] = 'NOTNULL';
406 406
 							$errorforthistable++;
407 407
 							$error++;
408 408
 						}
@@ -410,28 +410,28 @@  discard block
 block discarded – undo
410 410
 						else
411 411
 						{
412 412
 						    // We convert field if required
413
-						    if (! empty($objimport->array_import_convertvalue[0][$val]))
413
+						    if (!empty($objimport->array_import_convertvalue[0][$val]))
414 414
 						    {
415 415
                                 //print 'Must convert '.$newval.' with rule '.join(',',$objimport->array_import_convertvalue[0][$val]).'. ';
416
-                                if ($objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeid'
417
-                                	|| $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromref'
418
-                                	|| $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel'
416
+                                if ($objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeid'
417
+                                	|| $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromref'
418
+                                	|| $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeorlabel'
419 419
                                 	)
420 420
                                 {
421 421
                                     // New val can be an id or ref. If it start with id: it is forced to id, if it start with ref: it is forced to ref. It not, we try to guess.
422
-                                    $isidorref='id';
423
-                                    if (! is_numeric($newval) && $newval != '' && ! preg_match('/^id:/i',$newval)) $isidorref='ref';
424
-                                    $newval=preg_replace('/^(id|ref):/i','',$newval);    // Remove id: or ref: that was used to force if field is id or ref
422
+                                    $isidorref = 'id';
423
+                                    if (!is_numeric($newval) && $newval != '' && !preg_match('/^id:/i', $newval)) $isidorref = 'ref';
424
+                                    $newval = preg_replace('/^(id|ref):/i', '', $newval); // Remove id: or ref: that was used to force if field is id or ref
425 425
                                     //print 'Val is now '.$newval.' and is type '.$isidorref."<br>\n";
426 426
 
427 427
                                     if ($isidorref == 'ref')    // If value into input import file is a ref, we apply the function defined into descriptor
428 428
                                     {
429
-                                        $file=(empty($objimport->array_import_convertvalue[0][$val]['classfile'])?$objimport->array_import_convertvalue[0][$val]['file']:$objimport->array_import_convertvalue[0][$val]['classfile']);
430
-                                        $class=$objimport->array_import_convertvalue[0][$val]['class'];
431
-                                        $method=$objimport->array_import_convertvalue[0][$val]['method'];
429
+                                        $file = (empty($objimport->array_import_convertvalue[0][$val]['classfile']) ? $objimport->array_import_convertvalue[0][$val]['file'] : $objimport->array_import_convertvalue[0][$val]['classfile']);
430
+                                        $class = $objimport->array_import_convertvalue[0][$val]['class'];
431
+                                        $method = $objimport->array_import_convertvalue[0][$val]['method'];
432 432
                                         if ($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] != '')
433 433
                                         {
434
-                                        	$newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval];
434
+                                        	$newval = $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval];
435 435
                                         }
436 436
                                         else
437 437
 										{
@@ -441,94 +441,94 @@  discard block
 block discarded – undo
441 441
                                                 dol_print_error('', 'Error trying to call file='.$file.', class='.$class.', method='.$method);
442 442
                                                 break;
443 443
                                             }
444
-                                            $classinstance=new $class($this->db);
444
+                                            $classinstance = new $class($this->db);
445 445
                                             // Try the fetch from code or ref
446
-                                            call_user_func_array(array($classinstance, $method),array('', $newval));
446
+                                            call_user_func_array(array($classinstance, $method), array('', $newval));
447 447
                                             // If not found, try the fetch from label
448
-                                            if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel')
448
+                                            if (!($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeorlabel')
449 449
                                             {
450
-												call_user_func_array(array($classinstance, $method),array('', '', $newval));
450
+												call_user_func_array(array($classinstance, $method), array('', '', $newval));
451 451
                                             }
452
-                                            $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]=$classinstance->id;
452
+                                            $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] = $classinstance->id;
453 453
                                             //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. ';
454 454
                                             if ($classinstance->id != '')	// id may be 0, it is a found value
455 455
                                             {
456
-                                                $newval=$classinstance->id;
456
+                                                $newval = $classinstance->id;
457 457
                                             }
458 458
                                             else
459 459
                                             {
460
-                                                if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldValueNotIn',$key,$newval,'code',$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
461
-                                                else if (!empty($objimport->array_import_convertvalue[0][$val]['element'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldRefNotIn',$key,$newval,$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element']));
462
-                                                else $this->errors[$error]['lib']='ErrorFieldValueNotIn';
463
-                                                $this->errors[$error]['type']='FOREIGNKEY';
460
+                                                if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) $this->errors[$error]['lib'] = $langs->trans('ErrorFieldValueNotIn', $key, $newval, 'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
461
+                                                else if (!empty($objimport->array_import_convertvalue[0][$val]['element'])) $this->errors[$error]['lib'] = $langs->trans('ErrorFieldRefNotIn', $key, $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element']));
462
+                                                else $this->errors[$error]['lib'] = 'ErrorFieldValueNotIn';
463
+                                                $this->errors[$error]['type'] = 'FOREIGNKEY';
464 464
                                                 $errorforthistable++;
465 465
                                                 $error++;
466 466
                                             }
467 467
                                         }
468 468
                                     }
469 469
                                 }
470
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull')
470
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'zeroifnull')
471 471
                                 {
472
-                                    if (empty($newval)) $newval='0';
472
+                                    if (empty($newval)) $newval = '0';
473 473
                                 }
474
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto')
474
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getcustomercodeifauto')
475 475
                                 {
476 476
                                     if (strtolower($newval) == 'auto')
477 477
                                     {
478
-                                        $this->thirpartyobject->get_codeclient(0,0);
479
-                                        $newval=$this->thirpartyobject->code_client;
478
+                                        $this->thirpartyobject->get_codeclient(0, 0);
479
+                                        $newval = $this->thirpartyobject->code_client;
480 480
                                         //print 'code_client='.$newval;
481 481
                                     }
482
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
482
+                                    if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
483 483
                                 }
484
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifauto')
484
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getsuppliercodeifauto')
485 485
                                 {
486 486
                                     if (strtolower($newval) == 'auto')
487 487
                                     {
488
-                                        $newval=$this->thirpartyobject->get_codefournisseur(0,1);
489
-                                        $newval=$this->thirpartyobject->code_fournisseur;
488
+                                        $newval = $this->thirpartyobject->get_codefournisseur(0, 1);
489
+                                        $newval = $this->thirpartyobject->code_fournisseur;
490 490
                                         //print 'code_fournisseur='.$newval;
491 491
                                     }
492
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
492
+                                    if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
493 493
                                 }
494
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifauto')
494
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getcustomeraccountancycodeifauto')
495 495
                                 {
496 496
                                     if (strtolower($newval) == 'auto')
497 497
                                     {
498 498
                                         $this->thirpartyobject->get_codecompta('customer');
499
-                                        $newval=$this->thirpartyobject->code_compta;
499
+                                        $newval = $this->thirpartyobject->code_compta;
500 500
                                         //print 'code_compta='.$newval;
501 501
                                     }
502
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
502
+                                    if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
503 503
                                 }
504
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifauto')
504
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getsupplieraccountancycodeifauto')
505 505
                                 {
506 506
                                     if (strtolower($newval) == 'auto')
507 507
                                     {
508 508
                                         $this->thirpartyobject->get_codecompta('supplier');
509
-                                        $newval=$this->thirpartyobject->code_compta_fournisseur;
510
-                                        if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
509
+                                        $newval = $this->thirpartyobject->code_compta_fournisseur;
510
+                                        if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
511 511
                                         //print 'code_compta_fournisseur='.$newval;
512 512
                                     }
513
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
513
+                                    if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
514 514
                                 }
515
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getrefifauto')
515
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getrefifauto')
516 516
                                 {
517
-                                    $defaultref='';
517
+                                    $defaultref = '';
518 518
                                     // TODO provide the $modTask (module of generation of ref) as parameter of import_insert function
519
-                                    $obj = empty($conf->global->PROJECT_TASK_ADDON)?'mod_task_simple':$conf->global->PROJECT_TASK_ADDON;
520
-                                    if (! empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php"))
519
+                                    $obj = empty($conf->global->PROJECT_TASK_ADDON) ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON;
520
+                                    if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php"))
521 521
                                     {
522
-                                        require_once DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php';
522
+                                        require_once DOL_DOCUMENT_ROOT."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php';
523 523
                                         $modTask = new $obj;
524
-                                        $defaultref = $modTask->getNextValue(null,null);
524
+                                        $defaultref = $modTask->getNextValue(null, null);
525 525
                                     }
526
-                                    if (is_numeric($defaultref) && $defaultref <= 0) $defaultref='';
527
-                                    $newval=$defaultref;
526
+                                    if (is_numeric($defaultref) && $defaultref <= 0) $defaultref = '';
527
+                                    $newval = $defaultref;
528 528
                                 }
529 529
 
530 530
 
531
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric')
531
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'numeric')
532 532
                                 {
533 533
                                     $newval = price2num($newval);
534 534
                                 }
@@ -537,27 +537,27 @@  discard block
 block discarded – undo
537 537
 						    }
538 538
 
539 539
 						    // Test regexp
540
-							if (! empty($objimport->array_import_regex[0][$val]) && ($newval != ''))
540
+							if (!empty($objimport->array_import_regex[0][$val]) && ($newval != ''))
541 541
 							{
542 542
 								// If test is "Must exist in a field@table"
543
-								if (preg_match('/^(.*)@(.*)$/',$objimport->array_import_regex[0][$val],$reg))
543
+								if (preg_match('/^(.*)@(.*)$/', $objimport->array_import_regex[0][$val], $reg))
544 544
 								{
545
-									$field=$reg[1];
546
-									$table=$reg[2];
545
+									$field = $reg[1];
546
+									$table = $reg[2];
547 547
 
548 548
 									// Load content of field@table into cache array
549
-									if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
549
+									if (!is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
550 550
 									{
551
-										$sql="SELECT ".$field." as aliasfield FROM ".$table;
552
-										$resql=$this->db->query($sql);
551
+										$sql = "SELECT ".$field." as aliasfield FROM ".$table;
552
+										$resql = $this->db->query($sql);
553 553
 										if ($resql)
554 554
 										{
555
-											$num=$this->db->num_rows($resql);
556
-											$i=0;
555
+											$num = $this->db->num_rows($resql);
556
+											$i = 0;
557 557
 											while ($i < $num)
558 558
 											{
559
-												$obj=$this->db->fetch_object($resql);
560
-												if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
559
+												$obj = $this->db->fetch_object($resql);
560
+												if ($obj) $this->cachefieldtable[$field.'@'.$table][] = $obj->aliasfield;
561 561
 												$i++;
562 562
 											}
563 563
 										}
@@ -568,20 +568,20 @@  discard block
 block discarded – undo
568 568
 									}
569 569
 
570 570
 									// Now we check cache is not empty (should not) and key is into cache
571
-									if (! is_array($this->cachefieldtable[$field.'@'.$table]) || ! in_array($newval,$this->cachefieldtable[$field.'@'.$table]))
571
+									if (!is_array($this->cachefieldtable[$field.'@'.$table]) || !in_array($newval, $this->cachefieldtable[$field.'@'.$table]))
572 572
 									{
573
-										$this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$table);
574
-										$this->errors[$error]['type']='FOREIGNKEY';
573
+										$this->errors[$error]['lib'] = $langs->transnoentitiesnoconv('ErrorFieldValueNotIn', $key, $newval, $field, $table);
574
+										$this->errors[$error]['type'] = 'FOREIGNKEY';
575 575
 									    $errorforthistable++;
576 576
 										$error++;
577 577
 									}
578 578
 								}
579 579
 								// If test is just a static regex
580
-								else if (! preg_match('/'.$objimport->array_import_regex[0][$val].'/i',$newval))
580
+								else if (!preg_match('/'.$objimport->array_import_regex[0][$val].'/i', $newval))
581 581
 								{
582 582
 								    //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."<br>";
583
-									$this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorWrongValueForField',$key,$newval,$objimport->array_import_regex[0][$val]);
584
-									$this->errors[$error]['type']='REGEX';
583
+									$this->errors[$error]['lib'] = $langs->transnoentitiesnoconv('ErrorWrongValueForField', $key, $newval, $objimport->array_import_regex[0][$val]);
584
+									$this->errors[$error]['type'] = 'REGEX';
585 585
 									$errorforthistable++;
586 586
 									$error++;
587 587
 								}
@@ -595,9 +595,9 @@  discard block
 block discarded – undo
595 595
 						$listfields[] = $fieldname;
596 596
 
597 597
 						// Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert
598
-						if (empty($newval) && $arrayrecord[($key-1)]['type'] < 0) {
599
-                            $listvalues[] = ($newval=='0'?$newval:"null");
600
-                        } elseif (empty($newval) && $arrayrecord[($key-1)]['type'] == 0) {
598
+						if (empty($newval) && $arrayrecord[($key - 1)]['type'] < 0) {
599
+                            $listvalues[] = ($newval == '0' ? $newval : "null");
600
+                        } elseif (empty($newval) && $arrayrecord[($key - 1)]['type'] == 0) {
601 601
                             $listvalues[] = "''";
602 602
                         } else {
603 603
                             $listvalues[] = "'".$this->db->escape($newval)."'";
@@ -610,19 +610,19 @@  discard block
 block discarded – undo
610 610
 				if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0]))
611 611
 				{
612 612
     				// Loop on each hidden fields to add them into listfields/listvalues
613
-				    foreach($objimport->array_import_fieldshidden[0] as $key => $val)
613
+				    foreach ($objimport->array_import_fieldshidden[0] as $key => $val)
614 614
     				{
615
-    				    if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue;    // Not a field of current table
615
+    				    if (!preg_match('/^'.preg_quote($alias).'\./', $key)) continue; // Not a field of current table
616 616
     				    if ($val == 'user->id')
617 617
     				    {
618
-    				        $listfields[] = preg_replace('/^'.preg_quote($alias).'\./','',$key);
618
+    				        $listfields[] = preg_replace('/^'.preg_quote($alias).'\./', '', $key);
619 619
     				        $listvalues[] = $user->id;
620 620
     				    }
621
-    				    elseif (preg_match('/^lastrowid-/',$val))
621
+    				    elseif (preg_match('/^lastrowid-/', $val))
622 622
     				    {
623
-    				        $tmp=explode('-',$val);
624
-    				        $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0;
625
-							$keyfield = preg_replace('/^'.preg_quote($alias).'\./','',$key);
623
+    				        $tmp = explode('-', $val);
624
+    				        $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
625
+							$keyfield = preg_replace('/^'.preg_quote($alias).'\./', '', $key);
626 626
     				        $listfields[] = $keyfield;
627 627
                             $listvalues[] = $lastinsertid;
628 628
     				        //print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit;
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
 
634 634
 				// If no error for this $alias/$tablename, we have a complete $listfields and $listvalues that are defined
635 635
 				// so we can try to make the insert or update now.
636
-				if (! $errorforthistable)
636
+				if (!$errorforthistable)
637 637
 				{
638 638
 					//print "$alias/$tablename/$listfields/$listvalues<br>";
639 639
 					if (!empty($listfields))
@@ -652,21 +652,21 @@  discard block
 block discarded – undo
652 652
 								$filters = array();
653 653
 								foreach ($updatekeys as $key) {
654 654
 									$col = $objimport->array_import_updatekeys[0][$key];
655
-									$key=preg_replace('/^.*\./i','',$key);
655
+									$key = preg_replace('/^.*\./i', '', $key);
656 656
 									$where[] = $key.' = '.$data[$key];
657 657
 									$filters[] = $col.' = '.$data[$key];
658 658
 								}
659
-								$sqlSelect.= ' WHERE '.implode(' AND ', $where);
659
+								$sqlSelect .= ' WHERE '.implode(' AND ', $where);
660 660
 
661
-								$resql=$this->db->query($sqlSelect);
662
-								if($resql) {
661
+								$resql = $this->db->query($sqlSelect);
662
+								if ($resql) {
663 663
 									$res = $this->db->fetch_object($resql);
664
-									if($resql->num_rows == 1) {
664
+									if ($resql->num_rows == 1) {
665 665
 										$lastinsertid = $res->rowid;
666 666
 										$last_insert_id_array[$tablename] = $lastinsertid;
667
-									} else if($resql->num_rows > 1) {
668
-										$this->errors[$error]['lib']=$langs->trans('MultipleRecordFoundWithTheseFilters', implode($filters, ', '));
669
-										$this->errors[$error]['type']='SQL';
667
+									} else if ($resql->num_rows > 1) {
668
+										$this->errors[$error]['lib'] = $langs->trans('MultipleRecordFoundWithTheseFilters', implode($filters, ', '));
669
+										$this->errors[$error]['type'] = 'SQL';
670 670
 										$error++;
671 671
 									} else {
672 672
 										// No record found with filters, insert will be tried below
@@ -675,8 +675,8 @@  discard block
 block discarded – undo
675 675
 								else
676 676
 								{
677 677
 									//print 'E';
678
-									$this->errors[$error]['lib']=$this->db->lasterror();
679
-									$this->errors[$error]['type']='SQL';
678
+									$this->errors[$error]['lib'] = $this->db->lasterror();
679
+									$this->errors[$error]['type'] = 'SQL';
680 680
 									$error++;
681 681
 								}
682 682
 							} else {
@@ -687,13 +687,13 @@  discard block
 block discarded – undo
687 687
 								// Note: For extrafield tablename, we have in importfieldshidden_array an enty 'extra.fk_object'=>'lastrowid-tableparent' so $keyfield is 'fk_object'
688 688
 								$sqlSelect = 'SELECT rowid FROM '.$tablename;
689 689
 
690
-								if(empty($keyfield)) $keyfield = 'rowid';
690
+								if (empty($keyfield)) $keyfield = 'rowid';
691 691
 								$sqlSelect .= ' WHERE '.$keyfield.' = '.$lastinsertid;
692 692
 
693
-								$resql=$this->db->query($sqlSelect);
694
-								if($resql) {
693
+								$resql = $this->db->query($sqlSelect);
694
+								if ($resql) {
695 695
 									$res = $this->db->fetch_object($resql);
696
-									if($resql->num_rows == 1) {
696
+									if ($resql->num_rows == 1) {
697 697
 										// We have a row referencing this last foreign key, continue with UPDATE.
698 698
 									} else {
699 699
 										// No record found referencing this last foreign key,
@@ -704,8 +704,8 @@  discard block
 block discarded – undo
704 704
 								else
705 705
 								{
706 706
 									//print 'E';
707
-									$this->errors[$error]['lib']=$this->db->lasterror();
708
-									$this->errors[$error]['type']='SQL';
707
+									$this->errors[$error]['lib'] = $this->db->lasterror();
708
+									$this->errors[$error]['type'] = 'SQL';
709 709
 									$error++;
710 710
 								}
711 711
 							}
@@ -719,24 +719,24 @@  discard block
 block discarded – undo
719 719
 								foreach ($data as $key => $val) {
720 720
 									$set[] = $key.' = '.$val;
721 721
 								}
722
-								$sqlstart.= ' SET '.implode(', ', $set);
722
+								$sqlstart .= ' SET '.implode(', ', $set);
723 723
 
724
-								if(empty($keyfield)) $keyfield = 'rowid';
724
+								if (empty($keyfield)) $keyfield = 'rowid';
725 725
 								$sqlend = ' WHERE '.$keyfield.' = '.$lastinsertid;
726 726
 
727 727
 								$sql = $sqlstart.$sqlend;
728 728
 
729 729
 								// Run update request
730
-								$resql=$this->db->query($sql);
731
-								if($resql) {
730
+								$resql = $this->db->query($sql);
731
+								if ($resql) {
732 732
 									// No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed
733 733
 									$updatedone = true;
734 734
 								}
735 735
 								else
736 736
 								{
737 737
 									//print 'E';
738
-									$this->errors[$error]['lib']=$this->db->lasterror();
739
-									$this->errors[$error]['type']='SQL';
738
+									$this->errors[$error]['lib'] = $this->db->lasterror();
739
+									$this->errors[$error]['type'] = 'SQL';
740 740
 									$error++;
741 741
 								}
742 742
 							}
@@ -747,13 +747,13 @@  discard block
 block discarded – undo
747 747
 							// Build SQL INSERT request
748 748
 							$sqlstart = 'INSERT INTO '.$tablename.'('.implode(', ', $listfields).', import_key';
749 749
 							$sqlend = ') VALUES('.implode(', ', $listvalues).", '".$importid."'";
750
-							if (! empty($tablewithentity_cache[$tablename])) {
751
-								$sqlstart.= ', entity';
752
-								$sqlend.= ', '.$conf->entity;
750
+							if (!empty($tablewithentity_cache[$tablename])) {
751
+								$sqlstart .= ', entity';
752
+								$sqlend .= ', '.$conf->entity;
753 753
 							}
754
-							if (! empty($objimport->array_import_tables_creator[0][$alias])) {
755
-								$sqlstart.= ', '.$objimport->array_import_tables_creator[0][$alias];
756
-								$sqlend.=', '.$user->id;
754
+							if (!empty($objimport->array_import_tables_creator[0][$alias])) {
755
+								$sqlstart .= ', '.$objimport->array_import_tables_creator[0][$alias];
756
+								$sqlend .= ', '.$user->id;
757 757
 							}
758 758
 							$sql = $sqlstart.$sqlend.')';
759 759
 							dol_syslog("import_csv.modules", LOG_DEBUG);
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
 							// Run insert request
762 762
 							if ($sql)
763 763
 							{
764
-								$resql=$this->db->query($sql);
764
+								$resql = $this->db->query($sql);
765 765
 								if ($resql)
766 766
 								{
767 767
 								    $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename); // store the last inserted auto_increment id for each table, so that child tables can be inserted with the appropriate id. This must be done just after the INSERT request, else we risk losing the id (because another sql query will be issued somewhere in Dolibarr).
@@ -770,8 +770,8 @@  discard block
 block discarded – undo
770 770
 								else
771 771
 								{
772 772
 									//print 'E';
773
-									$this->errors[$error]['lib']=$this->db->lasterror();
774
-									$this->errors[$error]['type']='SQL';
773
+									$this->errors[$error]['lib'] = $this->db->lasterror();
774
+									$this->errors[$error]['type'] = 'SQL';
775 775
 									$error++;
776 776
 								}
777 777
 							}
@@ -786,8 +786,8 @@  discard block
 block discarded – undo
786 786
 			    if ($error) break;
787 787
 			}
788 788
 
789
-			if($updatedone) $this->nbupdate++;
790
-			if($insertdone) $this->nbinsert++;
789
+			if ($updatedone) $this->nbupdate++;
790
+			if ($insertdone) $this->nbinsert++;
791 791
 		}
792 792
 
793 793
 		return 1;
@@ -802,5 +802,5 @@  discard block
 block discarded – undo
802 802
  */
803 803
 function cleansep($value)
804 804
 {
805
-	return str_replace(array(',',';'),'/',$value);
805
+	return str_replace(array(',', ';'), '/', $value);
806 806
 };
Please login to merge, or discard this patch.
Braces   +117 added lines, -73 removed lines patch added patch discarded remove patch
@@ -114,7 +114,9 @@  discard block
 block discarded – undo
114 114
 		$this->version_lib=DOL_VERSION;
115 115
 
116 116
 		$this->datatoimport=$datatoimport;
117
-		if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db);
117
+		if (preg_match('/^societe_/',$datatoimport)) {
118
+		    $this->thirpartyobject=new Societe($this->db);
119
+		}
118 120
 	}
119 121
 
120 122
 
@@ -199,8 +201,7 @@  discard block
 block discarded – undo
199 201
 			$langs->load("errors");
200 202
 			$this->error=$langs->trans("ErrorFailToOpenFile",$file);
201 203
 			$ret=-1;
202
-		}
203
-		else
204
+		} else
204 205
 		{
205 206
 			$this->file=$file;
206 207
 		}
@@ -250,7 +251,9 @@  discard block
 block discarded – undo
250 251
 		$arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure,$this->escape);
251 252
 
252 253
 		// End of file
253
-		if ($arrayres === false) return false;
254
+		if ($arrayres === false) {
255
+		    return false;
256
+		}
254 257
 
255 258
 		//var_dump($this->handle);
256 259
 		//var_dump($arrayres);exit;
@@ -259,27 +262,26 @@  discard block
 block discarded – undo
259 262
 		{
260 263
 			foreach($arrayres as $key => $val)
261 264
 			{
262
-				if (! empty($conf->global->IMPORT_CSV_FORCE_CHARSET))	// Forced charset
265
+				if (! empty($conf->global->IMPORT_CSV_FORCE_CHARSET)) {
266
+				    // Forced charset
263 267
 				{
264 268
 					if (strtolower($conf->global->IMPORT_CSV_FORCE_CHARSET) == 'utf8')
265 269
 					{
266 270
 						$newarrayres[$key]['val']=$val;
271
+				}
267 272
 						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
268
-					}
269
-					else
273
+					} else
270 274
 					{
271 275
 						$newarrayres[$key]['val']=utf8_encode($val);
272 276
 						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
273 277
 					}
274
-				}
275
-				else	// Autodetect format (UTF8 or ISO)
278
+				} else	// Autodetect format (UTF8 or ISO)
276 279
 				{
277 280
 					if (utf8_check($val))
278 281
 					{
279 282
 						$newarrayres[$key]['val']=$val;
280 283
 						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
281
-					}
282
-					else
284
+					} else
283 285
 					{
284 286
 						$newarrayres[$key]['val']=utf8_encode($val);
285 287
 						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
@@ -347,8 +349,7 @@  discard block
 block discarded – undo
347 349
 			$this->warnings[$warning]['lib']=$langs->trans('EmptyLine');
348 350
 			$this->warnings[$warning]['type']='EMPTY';
349 351
 			$warning++;
350
-		}
351
-		else
352
+		} else
352 353
 		{
353 354
 			$last_insert_id_array = array(); // store the last inserted auto_increment id for each table, so that dependent tables can be inserted with the appropriate id (eg: extrafields fk_object will be set with the last inserted object's id)
354 355
 			$updatedone = false;
@@ -364,19 +365,27 @@  discard block
 block discarded – undo
364 365
 				$errorforthistable=0;
365 366
 
366 367
 				// Define $tablewithentity_cache[$tablename] if not already defined
367
-				if (! isset($tablewithentity_cache[$tablename]))	// keep this test with "isset"
368
+				if (! isset($tablewithentity_cache[$tablename])) {
369
+				    // keep this test with "isset"
368 370
 				{
369 371
 					dol_syslog("Check if table ".$tablename." has an entity field");
372
+				}
370 373
 					$resql=$this->db->DDLDescTable($tablename,'entity');
371 374
 					if ($resql)
372 375
 					{
373 376
 						$obj=$this->db->fetch_object($resql);
374
-						if ($obj) $tablewithentity_cache[$tablename]=1;		// table contains entity field
375
-						else $tablewithentity_cache[$tablename]=0;			// table does not contains entity field
377
+						if ($obj) {
378
+						    $tablewithentity_cache[$tablename]=1;
379
+						}
380
+						// table contains entity field
381
+						else {
382
+						    $tablewithentity_cache[$tablename]=0;
383
+						}
384
+						// table does not contains entity field
385
+					} else {
386
+					    dol_print_error($this->db);
376 387
 					}
377
-					else dol_print_error($this->db);
378
-				}
379
-				else
388
+				} else
380 389
 				{
381 390
 					//dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]);
382 391
 				}
@@ -388,13 +397,19 @@  discard block
 block discarded – undo
388 397
 				    $fieldalias=preg_replace('/\..*$/i','',$val);
389 398
 				    $fieldname=preg_replace('/^.*\./i','',$val);
390 399
 
391
-				    if ($alias != $fieldalias) continue;    // Not a field of current table
400
+				    if ($alias != $fieldalias) {
401
+				        continue;
402
+				    }
403
+				    // Not a field of current table
392 404
 
393 405
 					if ($key <= $maxfields)
394 406
 					{
395 407
 						// Set $newval with value to insert and set $listvalues with sql request part for insert
396 408
 						$newval='';
397
-						if ($arrayrecord[($key-1)]['type'] > 0) $newval=$arrayrecord[($key-1)]['val'];    // If type of field into input file is not empty string (so defined into input file), we get value
409
+						if ($arrayrecord[($key-1)]['type'] > 0) {
410
+						    $newval=$arrayrecord[($key-1)]['val'];
411
+						}
412
+						// If type of field into input file is not empty string (so defined into input file), we get value
398 413
 
399 414
 						// Make some tests on $newval
400 415
 
@@ -420,20 +435,23 @@  discard block
 block discarded – undo
420 435
                                 {
421 436
                                     // New val can be an id or ref. If it start with id: it is forced to id, if it start with ref: it is forced to ref. It not, we try to guess.
422 437
                                     $isidorref='id';
423
-                                    if (! is_numeric($newval) && $newval != '' && ! preg_match('/^id:/i',$newval)) $isidorref='ref';
438
+                                    if (! is_numeric($newval) && $newval != '' && ! preg_match('/^id:/i',$newval)) {
439
+                                        $isidorref='ref';
440
+                                    }
424 441
                                     $newval=preg_replace('/^(id|ref):/i','',$newval);    // Remove id: or ref: that was used to force if field is id or ref
425 442
                                     //print 'Val is now '.$newval.' and is type '.$isidorref."<br>\n";
426 443
 
427
-                                    if ($isidorref == 'ref')    // If value into input import file is a ref, we apply the function defined into descriptor
444
+                                    if ($isidorref == 'ref') {
445
+                                        // If value into input import file is a ref, we apply the function defined into descriptor
428 446
                                     {
429 447
                                         $file=(empty($objimport->array_import_convertvalue[0][$val]['classfile'])?$objimport->array_import_convertvalue[0][$val]['file']:$objimport->array_import_convertvalue[0][$val]['classfile']);
448
+                                    }
430 449
                                         $class=$objimport->array_import_convertvalue[0][$val]['class'];
431 450
                                         $method=$objimport->array_import_convertvalue[0][$val]['method'];
432 451
                                         if ($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] != '')
433 452
                                         {
434 453
                                         	$newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval];
435
-                                        }
436
-                                        else
454
+                                        } else
437 455
 										{
438 456
                                             $resultload = dol_include_once($file);
439 457
                                             if (empty($resultload))
@@ -451,27 +469,32 @@  discard block
 block discarded – undo
451 469
                                             }
452 470
                                             $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]=$classinstance->id;
453 471
                                             //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. ';
454
-                                            if ($classinstance->id != '')	// id may be 0, it is a found value
472
+                                            if ($classinstance->id != '') {
473
+                                                // id may be 0, it is a found value
455 474
                                             {
456 475
                                                 $newval=$classinstance->id;
457 476
                                             }
458
-                                            else
477
+                                            } else
459 478
                                             {
460
-                                                if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldValueNotIn',$key,$newval,'code',$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
461
-                                                else if (!empty($objimport->array_import_convertvalue[0][$val]['element'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldRefNotIn',$key,$newval,$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element']));
462
-                                                else $this->errors[$error]['lib']='ErrorFieldValueNotIn';
479
+                                                if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) {
480
+                                                    $this->errors[$error]['lib']=$langs->trans('ErrorFieldValueNotIn',$key,$newval,'code',$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
481
+                                                } else if (!empty($objimport->array_import_convertvalue[0][$val]['element'])) {
482
+                                                    $this->errors[$error]['lib']=$langs->trans('ErrorFieldRefNotIn',$key,$newval,$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element']));
483
+                                                } else {
484
+                                                    $this->errors[$error]['lib']='ErrorFieldValueNotIn';
485
+                                                }
463 486
                                                 $this->errors[$error]['type']='FOREIGNKEY';
464 487
                                                 $errorforthistable++;
465 488
                                                 $error++;
466 489
                                             }
467 490
                                         }
468 491
                                     }
469
-                                }
470
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull')
492
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull')
471 493
                                 {
472
-                                    if (empty($newval)) $newval='0';
473
-                                }
474
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto')
494
+                                    if (empty($newval)) {
495
+                                        $newval='0';
496
+                                    }
497
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto')
475 498
                                 {
476 499
                                     if (strtolower($newval) == 'auto')
477 500
                                     {
@@ -479,9 +502,11 @@  discard block
 block discarded – undo
479 502
                                         $newval=$this->thirpartyobject->code_client;
480 503
                                         //print 'code_client='.$newval;
481 504
                                     }
482
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
483
-                                }
484
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifauto')
505
+                                    if (empty($newval)) {
506
+                                        $arrayrecord[($key-1)]['type']=-1;
507
+                                    }
508
+                                    // If we get empty value, we will use "null"
509
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifauto')
485 510
                                 {
486 511
                                     if (strtolower($newval) == 'auto')
487 512
                                     {
@@ -489,9 +514,11 @@  discard block
 block discarded – undo
489 514
                                         $newval=$this->thirpartyobject->code_fournisseur;
490 515
                                         //print 'code_fournisseur='.$newval;
491 516
                                     }
492
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
493
-                                }
494
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifauto')
517
+                                    if (empty($newval)) {
518
+                                        $arrayrecord[($key-1)]['type']=-1;
519
+                                    }
520
+                                    // If we get empty value, we will use "null"
521
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifauto')
495 522
                                 {
496 523
                                     if (strtolower($newval) == 'auto')
497 524
                                     {
@@ -499,20 +526,27 @@  discard block
 block discarded – undo
499 526
                                         $newval=$this->thirpartyobject->code_compta;
500 527
                                         //print 'code_compta='.$newval;
501 528
                                     }
502
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
503
-                                }
504
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifauto')
529
+                                    if (empty($newval)) {
530
+                                        $arrayrecord[($key-1)]['type']=-1;
531
+                                    }
532
+                                    // If we get empty value, we will use "null"
533
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifauto')
505 534
                                 {
506 535
                                     if (strtolower($newval) == 'auto')
507 536
                                     {
508 537
                                         $this->thirpartyobject->get_codecompta('supplier');
509 538
                                         $newval=$this->thirpartyobject->code_compta_fournisseur;
510
-                                        if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
539
+                                        if (empty($newval)) {
540
+                                            $arrayrecord[($key-1)]['type']=-1;
541
+                                        }
542
+                                        // If we get empty value, we will use "null"
511 543
                                         //print 'code_compta_fournisseur='.$newval;
512 544
                                     }
513
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
514
-                                }
515
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getrefifauto')
545
+                                    if (empty($newval)) {
546
+                                        $arrayrecord[($key-1)]['type']=-1;
547
+                                    }
548
+                                    // If we get empty value, we will use "null"
549
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getrefifauto')
516 550
                                 {
517 551
                                     $defaultref='';
518 552
                                     // TODO provide the $modTask (module of generation of ref) as parameter of import_insert function
@@ -523,12 +557,11 @@  discard block
 block discarded – undo
523 557
                                         $modTask = new $obj;
524 558
                                         $defaultref = $modTask->getNextValue(null,null);
525 559
                                     }
526
-                                    if (is_numeric($defaultref) && $defaultref <= 0) $defaultref='';
560
+                                    if (is_numeric($defaultref) && $defaultref <= 0) {
561
+                                        $defaultref='';
562
+                                    }
527 563
                                     $newval=$defaultref;
528
-                                }
529
-
530
-
531
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric')
564
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric')
532 565
                                 {
533 566
                                     $newval = price2num($newval);
534 567
                                 }
@@ -546,9 +579,11 @@  discard block
 block discarded – undo
546 579
 									$table=$reg[2];
547 580
 
548 581
 									// Load content of field@table into cache array
549
-									if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
582
+									if (! is_array($this->cachefieldtable[$field.'@'.$table])) {
583
+									    // If content of field@table not already loaded into cache
550 584
 									{
551 585
 										$sql="SELECT ".$field." as aliasfield FROM ".$table;
586
+									}
552 587
 										$resql=$this->db->query($sql);
553 588
 										if ($resql)
554 589
 										{
@@ -557,11 +592,12 @@  discard block
 block discarded – undo
557 592
 											while ($i < $num)
558 593
 											{
559 594
 												$obj=$this->db->fetch_object($resql);
560
-												if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
595
+												if ($obj) {
596
+												    $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
597
+												}
561 598
 												$i++;
562 599
 											}
563
-										}
564
-										else
600
+										} else
565 601
 										{
566 602
 											dol_print_error($this->db);
567 603
 										}
@@ -612,13 +648,15 @@  discard block
 block discarded – undo
612 648
     				// Loop on each hidden fields to add them into listfields/listvalues
613 649
 				    foreach($objimport->array_import_fieldshidden[0] as $key => $val)
614 650
     				{
615
-    				    if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue;    // Not a field of current table
651
+    				    if (! preg_match('/^'.preg_quote($alias).'\./', $key)) {
652
+    				        continue;
653
+    				    }
654
+    				    // Not a field of current table
616 655
     				    if ($val == 'user->id')
617 656
     				    {
618 657
     				        $listfields[] = preg_replace('/^'.preg_quote($alias).'\./','',$key);
619 658
     				        $listvalues[] = $user->id;
620
-    				    }
621
-    				    elseif (preg_match('/^lastrowid-/',$val))
659
+    				    } elseif (preg_match('/^lastrowid-/',$val))
622 660
     				    {
623 661
     				        $tmp=explode('-',$val);
624 662
     				        $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0;
@@ -671,8 +709,7 @@  discard block
 block discarded – undo
671 709
 									} else {
672 710
 										// No record found with filters, insert will be tried below
673 711
 									}
674
-								}
675
-								else
712
+								} else
676 713
 								{
677 714
 									//print 'E';
678 715
 									$this->errors[$error]['lib']=$this->db->lasterror();
@@ -687,7 +724,9 @@  discard block
 block discarded – undo
687 724
 								// Note: For extrafield tablename, we have in importfieldshidden_array an enty 'extra.fk_object'=>'lastrowid-tableparent' so $keyfield is 'fk_object'
688 725
 								$sqlSelect = 'SELECT rowid FROM '.$tablename;
689 726
 
690
-								if(empty($keyfield)) $keyfield = 'rowid';
727
+								if(empty($keyfield)) {
728
+								    $keyfield = 'rowid';
729
+								}
691 730
 								$sqlSelect .= ' WHERE '.$keyfield.' = '.$lastinsertid;
692 731
 
693 732
 								$resql=$this->db->query($sqlSelect);
@@ -700,8 +739,7 @@  discard block
 block discarded – undo
700 739
 										// force $lastinsertid to 0 so we INSERT below.
701 740
 										$lastinsertid = 0;
702 741
 									}
703
-								}
704
-								else
742
+								} else
705 743
 								{
706 744
 									//print 'E';
707 745
 									$this->errors[$error]['lib']=$this->db->lasterror();
@@ -721,7 +759,9 @@  discard block
 block discarded – undo
721 759
 								}
722 760
 								$sqlstart.= ' SET '.implode(', ', $set);
723 761
 
724
-								if(empty($keyfield)) $keyfield = 'rowid';
762
+								if(empty($keyfield)) {
763
+								    $keyfield = 'rowid';
764
+								}
725 765
 								$sqlend = ' WHERE '.$keyfield.' = '.$lastinsertid;
726 766
 
727 767
 								$sql = $sqlstart.$sqlend;
@@ -731,8 +771,7 @@  discard block
 block discarded – undo
731 771
 								if($resql) {
732 772
 									// No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed
733 773
 									$updatedone = true;
734
-								}
735
-								else
774
+								} else
736 775
 								{
737 776
 									//print 'E';
738 777
 									$this->errors[$error]['lib']=$this->db->lasterror();
@@ -766,8 +805,7 @@  discard block
 block discarded – undo
766 805
 								{
767 806
 								    $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename); // store the last inserted auto_increment id for each table, so that child tables can be inserted with the appropriate id. This must be done just after the INSERT request, else we risk losing the id (because another sql query will be issued somewhere in Dolibarr).
768 807
 								    $insertdone = true;
769
-								}
770
-								else
808
+								} else
771 809
 								{
772 810
 									//print 'E';
773 811
 									$this->errors[$error]['lib']=$this->db->lasterror();
@@ -783,11 +821,17 @@  discard block
 block discarded – undo
783 821
 					}*/
784 822
 				}
785 823
 
786
-			    if ($error) break;
824
+			    if ($error) {
825
+			        break;
826
+			    }
787 827
 			}
788 828
 
789
-			if($updatedone) $this->nbupdate++;
790
-			if($insertdone) $this->nbinsert++;
829
+			if($updatedone) {
830
+			    $this->nbupdate++;
831
+			}
832
+			if($insertdone) {
833
+			    $this->nbinsert++;
834
+			}
791 835
 		}
792 836
 
793 837
 		return 1;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/modClickToDial.class.php 2 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -33,44 +33,44 @@
 block discarded – undo
33 33
 class modClickToDial extends DolibarrModules
34 34
 {
35 35
 
36
-	/**
37
-	 *   Constructor. Define names, constants, directories, boxes, permissions
38
-	 *
39
-	 *   @param      DoliDB		$db      Database handler
40
-	 */
41
-	function __construct($db)
42
-	{
43
-		$this->db = $db;
44
-		$this->numero = 58;
36
+    /**
37
+     *   Constructor. Define names, constants, directories, boxes, permissions
38
+     *
39
+     *   @param      DoliDB		$db      Database handler
40
+     */
41
+    function __construct($db)
42
+    {
43
+        $this->db = $db;
44
+        $this->numero = 58;
45 45
 
46
-		$this->family = "interface";
47
-		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
48
-		$this->name = preg_replace('/^mod/i','',get_class($this));
49
-		$this->description = "Gestion du Click To Dial";
46
+        $this->family = "interface";
47
+        // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
48
+        $this->name = preg_replace('/^mod/i','',get_class($this));
49
+        $this->description = "Gestion du Click To Dial";
50 50
 
51
-		$this->version = 'dolibarr';		// 'development' or 'experimental' or 'dolibarr' or version
51
+        $this->version = 'dolibarr';		// 'development' or 'experimental' or 'dolibarr' or version
52 52
 
53
-		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
54
-		$this->picto='phoning';
53
+        $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
54
+        $this->picto='phoning';
55 55
 
56
-		// Data directories to create when module is enabled
57
-		$this->dirs = array();
56
+        // Data directories to create when module is enabled
57
+        $this->dirs = array();
58 58
 
59
-		// Dependencies
60
-		$this->depends = array();
61
-		$this->requiredby = array();
59
+        // Dependencies
60
+        $this->depends = array();
61
+        $this->requiredby = array();
62 62
 
63
-		// Config pages
64
-		$this->config_page_url = array("clicktodial.php");
63
+        // Config pages
64
+        $this->config_page_url = array("clicktodial.php");
65 65
 
66
-		// Constants
67
-		$this->const = array();
66
+        // Constants
67
+        $this->const = array();
68 68
 
69
-		// Boxes
70
-		$this->boxes = array();
69
+        // Boxes
70
+        $this->boxes = array();
71 71
 
72
-		// Permissions
73
-		$this->rights = array();
74
-		$this->rights_class = 'clicktodial';
75
-	}
72
+        // Permissions
73
+        $this->rights = array();
74
+        $this->rights_class = 'clicktodial';
75
+    }
76 76
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
  *	\brief      Fichier de description et activation du module de click to Dial
25 25
  */
26 26
 
27
-include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
27
+include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
28 28
 
29 29
 
30 30
 /**
@@ -45,13 +45,13 @@  discard block
 block discarded – undo
45 45
 
46 46
 		$this->family = "interface";
47 47
 		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
48
-		$this->name = preg_replace('/^mod/i','',get_class($this));
48
+		$this->name = preg_replace('/^mod/i', '', get_class($this));
49 49
 		$this->description = "Gestion du Click To Dial";
50 50
 
51
-		$this->version = 'dolibarr';		// 'development' or 'experimental' or 'dolibarr' or version
51
+		$this->version = 'dolibarr'; // 'development' or 'experimental' or 'dolibarr' or version
52 52
 
53 53
 		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
54
-		$this->picto='phoning';
54
+		$this->picto = 'phoning';
55 55
 
56 56
 		// Data directories to create when module is enabled
57 57
 		$this->dirs = array();
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/modAccounting.class.php 2 patches
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -32,161 +32,161 @@  discard block
 block discarded – undo
32 32
  */
33 33
 class modAccounting extends DolibarrModules
34 34
 {
35
-	/**
36
-	 *   Constructor. Define names, constants, directories, boxes, permissions
37
-	 *
38
-	 *   @param      DoliDB		$db      Database handler
39
-	 */
40
-	function __construct($db)
41
-	{
42
-		global $conf;
35
+    /**
36
+     *   Constructor. Define names, constants, directories, boxes, permissions
37
+     *
38
+     *   @param      DoliDB		$db      Database handler
39
+     */
40
+    function __construct($db)
41
+    {
42
+        global $conf;
43 43
 
44
-		$this->db = $db;
45
-		$this->numero = 50400;
44
+        $this->db = $db;
45
+        $this->numero = 50400;
46 46
 
47
-		$this->family = "financial";
48
-		$this->module_position = '61';
49
-		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
50
-		$this->name = preg_replace('/^mod/i', '', get_class($this));
51
-		$this->description = "Advanced accounting management";
47
+        $this->family = "financial";
48
+        $this->module_position = '61';
49
+        // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
50
+        $this->name = preg_replace('/^mod/i', '', get_class($this));
51
+        $this->description = "Advanced accounting management";
52 52
 
53
-		// Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
54
-		$this->version = 'dolibarr';
53
+        // Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
54
+        $this->version = 'dolibarr';
55 55
 
56
-		$this->const_name = 'MAIN_MODULE_' . strtoupper($this->name);
57
-		$this->picto = 'accounting';
56
+        $this->const_name = 'MAIN_MODULE_' . strtoupper($this->name);
57
+        $this->picto = 'accounting';
58 58
 
59
-		// Data directories to create when module is enabled
60
-		$this->dirs = array('/accounting/temp');
59
+        // Data directories to create when module is enabled
60
+        $this->dirs = array('/accounting/temp');
61 61
 
62
-		// Config pages
63
-		$this->config_page_url = array();
62
+        // Config pages
63
+        $this->config_page_url = array();
64 64
 
65
-		// Dependencies
66
-		$this->depends = array("modFacture","modBanque","modTax"); // List of modules id that must be enabled if this module is enabled
67
-		$this->requiredby = array(); // List of modules id to disable if this one is disabled
68
-		$this->conflictwith = array("modComptabilite"); // List of modules are in conflict with this module
69
-		$this->phpmin = array(5, 4); // Minimum version of PHP required by module
70
-		$this->need_dolibarr_version = array(3, 9); // Minimum version of Dolibarr required by module
71
-		$this->langfiles = array("accountancy","compta");
65
+        // Dependencies
66
+        $this->depends = array("modFacture","modBanque","modTax"); // List of modules id that must be enabled if this module is enabled
67
+        $this->requiredby = array(); // List of modules id to disable if this one is disabled
68
+        $this->conflictwith = array("modComptabilite"); // List of modules are in conflict with this module
69
+        $this->phpmin = array(5, 4); // Minimum version of PHP required by module
70
+        $this->need_dolibarr_version = array(3, 9); // Minimum version of Dolibarr required by module
71
+        $this->langfiles = array("accountancy","compta");
72 72
 
73
-		// Constants
74
-		// List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
75
-		// Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
76
-		//                             1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
77
-		// );
78
-		$this->const = array();
79
-		$this->const[1] = array(
80
-				"MAIN_COMPANY_CODE_ALWAYS_REQUIRED",
81
-				"chaine",
82
-				"1",
83
-				"With this constants on, third party code is always required whatever is numbering module behaviour", 0, 'current', 1
84
-		);
85
-		$this->const[2] = array(
86
-				"MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED",
87
-				"chaine",
88
-				"1",
89
-				"With this constants on, bank account number is always required", 0, 'current', 1
90
-		);
91
-		$this->const[3] = array(
92
-				"ACCOUNTING_ACCOUNT_SUSPENSE",
93
-				"chaine",
94
-				"471",
95
-				"", 0, 'current', 0
96
-		);
97
-		$this->const[4] = array(
98
-				"ACCOUNTING_ACCOUNT_TRANSFER_CASH",
99
-				"chaine",
100
-				"58",
101
-				"", 0, 'current', 0
102
-		);
103
-		$this->const[5] = array(
104
-				"CHARTOFACCOUNTS",
105
-				"chaine",
106
-				"2",
107
-				"", 0, 'current', 0
108
-		);
109
-		$this->const[6] = array(
110
-				"ACCOUNTING_EXPORT_MODELCSV",
111
-				"chaine",
112
-				"1",
113
-				"", 0, 'current', 0
114
-		);
115
-		$this->const[7] = array(
116
-				"ACCOUNTING_LENGTH_GACCOUNT",
117
-				"chaine",
118
-				"",
119
-				"", 0, 'current', 0
120
-		);
121
-		$this->const[8] = array(
122
-				"ACCOUNTING_LENGTH_AACCOUNT",
123
-				"chaine",
124
-				"",
125
-				"", 0, 'current', 0
126
-		);
127
-		$this->const[9] = array(
128
-				"ACCOUNTING_LIST_SORT_VENTILATION_TODO",
129
-				"yesno",
130
-				"1",
131
-				"", 0, 'current', 0
132
-		);
133
-		$this->const[10] = array(
134
-				"ACCOUNTING_LIST_SORT_VENTILATION_DONE",
135
-				"yesno",
136
-				"1",
137
-				"", 0, 'current', 0
138
-		);
139
-		$this->const[11] = array (
140
-				"ACCOUNTING_EXPORT_DATE",
141
-				"chaine",
142
-				"%d%m%Y",
143
-				"", 0, 'current', 0
144
-		);
145
-		$this->const[12] = array(
146
-				"ACCOUNTING_EXPORT_SEPARATORCSV",
147
-				"string",
148
-				",",
149
-				"", 0, 'current', 0
150
-		);
151
-		$this->const[13] = array(
152
-				"ACCOUNTING_EXPORT_FORMAT",
153
-				"chaine",
154
-				"csv",
155
-				"", 0, 'current', 0
156
-		);
73
+        // Constants
74
+        // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
75
+        // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
76
+        //                             1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
77
+        // );
78
+        $this->const = array();
79
+        $this->const[1] = array(
80
+                "MAIN_COMPANY_CODE_ALWAYS_REQUIRED",
81
+                "chaine",
82
+                "1",
83
+                "With this constants on, third party code is always required whatever is numbering module behaviour", 0, 'current', 1
84
+        );
85
+        $this->const[2] = array(
86
+                "MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED",
87
+                "chaine",
88
+                "1",
89
+                "With this constants on, bank account number is always required", 0, 'current', 1
90
+        );
91
+        $this->const[3] = array(
92
+                "ACCOUNTING_ACCOUNT_SUSPENSE",
93
+                "chaine",
94
+                "471",
95
+                "", 0, 'current', 0
96
+        );
97
+        $this->const[4] = array(
98
+                "ACCOUNTING_ACCOUNT_TRANSFER_CASH",
99
+                "chaine",
100
+                "58",
101
+                "", 0, 'current', 0
102
+        );
103
+        $this->const[5] = array(
104
+                "CHARTOFACCOUNTS",
105
+                "chaine",
106
+                "2",
107
+                "", 0, 'current', 0
108
+        );
109
+        $this->const[6] = array(
110
+                "ACCOUNTING_EXPORT_MODELCSV",
111
+                "chaine",
112
+                "1",
113
+                "", 0, 'current', 0
114
+        );
115
+        $this->const[7] = array(
116
+                "ACCOUNTING_LENGTH_GACCOUNT",
117
+                "chaine",
118
+                "",
119
+                "", 0, 'current', 0
120
+        );
121
+        $this->const[8] = array(
122
+                "ACCOUNTING_LENGTH_AACCOUNT",
123
+                "chaine",
124
+                "",
125
+                "", 0, 'current', 0
126
+        );
127
+        $this->const[9] = array(
128
+                "ACCOUNTING_LIST_SORT_VENTILATION_TODO",
129
+                "yesno",
130
+                "1",
131
+                "", 0, 'current', 0
132
+        );
133
+        $this->const[10] = array(
134
+                "ACCOUNTING_LIST_SORT_VENTILATION_DONE",
135
+                "yesno",
136
+                "1",
137
+                "", 0, 'current', 0
138
+        );
139
+        $this->const[11] = array (
140
+                "ACCOUNTING_EXPORT_DATE",
141
+                "chaine",
142
+                "%d%m%Y",
143
+                "", 0, 'current', 0
144
+        );
145
+        $this->const[12] = array(
146
+                "ACCOUNTING_EXPORT_SEPARATORCSV",
147
+                "string",
148
+                ",",
149
+                "", 0, 'current', 0
150
+        );
151
+        $this->const[13] = array(
152
+                "ACCOUNTING_EXPORT_FORMAT",
153
+                "chaine",
154
+                "csv",
155
+                "", 0, 'current', 0
156
+        );
157 157
 
158
-		// Tabs
159
-		$this->tabs = array();
158
+        // Tabs
159
+        $this->tabs = array();
160 160
 
161
-		// Css
162
-		$this->module_parts = array();
161
+        // Css
162
+        $this->module_parts = array();
163 163
 
164
-		// Boxes
165
-		$this->boxes = array();
164
+        // Boxes
165
+        $this->boxes = array();
166 166
 
167
-		// Permissions
168
-		$this->rights_class = 'accounting';
167
+        // Permissions
168
+        $this->rights_class = 'accounting';
169 169
 
170
-		$this->rights = array(); // Permission array used by this module
171
-		$r = 0;
170
+        $this->rights = array(); // Permission array used by this module
171
+        $r = 0;
172 172
 
173
-		$this->rights[$r][0] = 50440;
174
-		$this->rights[$r][1] = 'Manage chart of accounts, setup of accountancy';
175
-		$this->rights[$r][2] = 'r';
176
-		$this->rights[$r][3] = 0;
177
-		$this->rights[$r][4] = 'chartofaccount';
178
-		$this->rights[$r][5] = '';
179
-		$r++;
173
+        $this->rights[$r][0] = 50440;
174
+        $this->rights[$r][1] = 'Manage chart of accounts, setup of accountancy';
175
+        $this->rights[$r][2] = 'r';
176
+        $this->rights[$r][3] = 0;
177
+        $this->rights[$r][4] = 'chartofaccount';
178
+        $this->rights[$r][5] = '';
179
+        $r++;
180 180
 
181
-		$this->rights[$r][0] = 50401;
182
-		$this->rights[$r][1] = 'Bind products and invoices with accounting accounts';
183
-		$this->rights[$r][2] = 'r';
184
-		$this->rights[$r][3] = 0;
185
-		$this->rights[$r][4] = 'bind';
186
-		$this->rights[$r][5] = 'write';
187
-		$r++;
181
+        $this->rights[$r][0] = 50401;
182
+        $this->rights[$r][1] = 'Bind products and invoices with accounting accounts';
183
+        $this->rights[$r][2] = 'r';
184
+        $this->rights[$r][3] = 0;
185
+        $this->rights[$r][4] = 'bind';
186
+        $this->rights[$r][5] = 'write';
187
+        $r++;
188 188
 
189
-		/*
189
+        /*
190 190
 		$this->rights[$r][0] = 50402;
191 191
 		$this->rights[$r][1] = 'Make binding with products and invoices';
192 192
 		$this->rights[$r][2] = 'r';
@@ -196,96 +196,96 @@  discard block
 block discarded – undo
196 196
 		$r++;
197 197
         */
198 198
 
199
-		$this->rights[$r][0] = 50411;
200
-		$this->rights[$r][1] = 'Read operations in Ledger';
201
-		$this->rights[$r][2] = 'r';
202
-		$this->rights[$r][3] = 0;
203
-		$this->rights[$r][4] = 'mouvements';
204
-		$this->rights[$r][5] = 'lire';
205
-		$r++;
199
+        $this->rights[$r][0] = 50411;
200
+        $this->rights[$r][1] = 'Read operations in Ledger';
201
+        $this->rights[$r][2] = 'r';
202
+        $this->rights[$r][3] = 0;
203
+        $this->rights[$r][4] = 'mouvements';
204
+        $this->rights[$r][5] = 'lire';
205
+        $r++;
206 206
 
207
-		$this->rights[$r][0] = 50412;
208
-		$this->rights[$r][1] = 'Write/Edit operations in Ledger';
209
-		$this->rights[$r][2] = 'w';
210
-		$this->rights[$r][3] = 0;
211
-		$this->rights[$r][4] = 'mouvements';
212
-		$this->rights[$r][5] = 'creer';
213
-		$r++;
207
+        $this->rights[$r][0] = 50412;
208
+        $this->rights[$r][1] = 'Write/Edit operations in Ledger';
209
+        $this->rights[$r][2] = 'w';
210
+        $this->rights[$r][3] = 0;
211
+        $this->rights[$r][4] = 'mouvements';
212
+        $this->rights[$r][5] = 'creer';
213
+        $r++;
214 214
 
215
-		$this->rights[$r][0] = 50420;
216
-		$this->rights[$r][1] = 'Report and export reports (turnover, balance, journals, ledger)';
217
-		$this->rights[$r][2] = 'r';
218
-		$this->rights[$r][3] = 0;
219
-		$this->rights[$r][4] = 'comptarapport';
220
-		$this->rights[$r][5] = 'lire';
221
-		$r++;
215
+        $this->rights[$r][0] = 50420;
216
+        $this->rights[$r][1] = 'Report and export reports (turnover, balance, journals, ledger)';
217
+        $this->rights[$r][2] = 'r';
218
+        $this->rights[$r][3] = 0;
219
+        $this->rights[$r][4] = 'comptarapport';
220
+        $this->rights[$r][5] = 'lire';
221
+        $r++;
222 222
 
223
-		$this->rights[$r][0] = 50430;
224
-		$this->rights[$r][1] = 'Define and close a fiscal year';
225
-		$this->rights[$r][2] = 'r';
226
-		$this->rights[$r][3] = 0;
227
-		$this->rights[$r][4] = 'fiscalyear';
228
-		$this->rights[$r][5] = '';
229
-		$r++;
223
+        $this->rights[$r][0] = 50430;
224
+        $this->rights[$r][1] = 'Define and close a fiscal year';
225
+        $this->rights[$r][2] = 'r';
226
+        $this->rights[$r][3] = 0;
227
+        $this->rights[$r][4] = 'fiscalyear';
228
+        $this->rights[$r][5] = '';
229
+        $r++;
230 230
 
231 231
 
232
-		// Menus
233
-		//-------
234
-		$this->menu = 1;        // This module add menu entries. They are coded into menu manager.
232
+        // Menus
233
+        //-------
234
+        $this->menu = 1;        // This module add menu entries. They are coded into menu manager.
235 235
 
236
-		// Exports
237
-		//--------
238
-		$r=0;
236
+        // Exports
237
+        //--------
238
+        $r=0;
239 239
 
240
-		$r++;
241
-		$this->export_code[$r]=$this->rights_class.'_'.$r;
242
-		$this->export_label[$r]='Chartofaccounts';
243
-		$this->export_icon[$r]='Accounting';
244
-		$this->export_permission[$r]=array(array("accounting","chartofaccount"));
245
-		$this->export_fields_array[$r]=array('ac.rowid'=>'ChartofaccountsId','ac.pcg_version'=>'Chartofaccounts','aa.rowid'=>'Id','aa.account_number'=>"AccountAccounting",'aa.label'=>"Label",'aa.account_parent'=>"Accountparent",'aa.pcg_type'=>"Pcgtype",'aa.pcg_subtype'=>'Pcgsubtype','aa.active'=>'Status');
246
-		$this->export_TypeFields_array[$r]=array('ac.rowid'=>'List:accounting_system:pcg_version','aa.account_number'=>"Text",'aa.label'=>"Text",'aa.pcg_type'=>'Text','aa.pcg_subtype'=>'Text','aa.active'=>'Status');
247
-		$this->export_entities_array[$r]=array('ac.rowid'=>"Accounting",'ac.pcg_version'=>"Accounting",'aa.rowid'=>'Accounting','aa.account_number'=>"Accounting",'aa.label'=>"Accounting",'aa.accountparent'=>"Accounting",'aa.pcg_type'=>"Accounting",'aa.pcgsubtype'=>"Accounting",'aa_active'=>"Accounting");
240
+        $r++;
241
+        $this->export_code[$r]=$this->rights_class.'_'.$r;
242
+        $this->export_label[$r]='Chartofaccounts';
243
+        $this->export_icon[$r]='Accounting';
244
+        $this->export_permission[$r]=array(array("accounting","chartofaccount"));
245
+        $this->export_fields_array[$r]=array('ac.rowid'=>'ChartofaccountsId','ac.pcg_version'=>'Chartofaccounts','aa.rowid'=>'Id','aa.account_number'=>"AccountAccounting",'aa.label'=>"Label",'aa.account_parent'=>"Accountparent",'aa.pcg_type'=>"Pcgtype",'aa.pcg_subtype'=>'Pcgsubtype','aa.active'=>'Status');
246
+        $this->export_TypeFields_array[$r]=array('ac.rowid'=>'List:accounting_system:pcg_version','aa.account_number'=>"Text",'aa.label'=>"Text",'aa.pcg_type'=>'Text','aa.pcg_subtype'=>'Text','aa.active'=>'Status');
247
+        $this->export_entities_array[$r]=array('ac.rowid'=>"Accounting",'ac.pcg_version'=>"Accounting",'aa.rowid'=>'Accounting','aa.account_number'=>"Accounting",'aa.label'=>"Accounting",'aa.accountparent'=>"Accounting",'aa.pcg_type'=>"Accounting",'aa.pcgsubtype'=>"Accounting",'aa_active'=>"Accounting");
248 248
 
249
-		$this->export_sql_start[$r]='SELECT DISTINCT ';
250
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'accounting_account as aa, '.MAIN_DB_PREFIX.'accounting_system as ac';
251
-		$this->export_sql_end[$r] .=' WHERE ac.pcg_version = aa.fk_pcg_version AND aa.entity IN ('.getEntity('accounting').') ';
249
+        $this->export_sql_start[$r]='SELECT DISTINCT ';
250
+        $this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'accounting_account as aa, '.MAIN_DB_PREFIX.'accounting_system as ac';
251
+        $this->export_sql_end[$r] .=' WHERE ac.pcg_version = aa.fk_pcg_version AND aa.entity IN ('.getEntity('accounting').') ';
252 252
 
253 253
 
254
-		// Imports
255
-		//--------
256
-		$r=0;
254
+        // Imports
255
+        //--------
256
+        $r=0;
257 257
 
258
-		// General ledger
259
-		$r++;
260
-		$this->import_code[$r]=$this->rights_class.'_'.$r;
261
-		$this->import_label[$r]='ImportAccountingEntries';
262
-		$this->import_icon[$r]=$this->picto;
263
-		$this->import_entities_array[$r]=array();	// We define here only fields that use another icon that the one defined into import_icon
264
-		$this->import_tables_array[$r]=array('b'=>MAIN_DB_PREFIX.'accounting_bookkeeping');	// List of tables to insert into (insert done in same order)
265
-		$this->import_fields_array[$r]=array('b.doc_date'=>"Docdate",'b.code_journal'=>'Codejournal','b.numero_compte'=>'AccountAccountingShort','b.label_operation'=>'LabelOperation','b.debit'=>"Debit",'b.credit'=>"Credit",'b.date_creation'=>"DateCreation");
266
-		$this->import_fieldshidden_array[$r]=array('b.fk_user'=>'user->id');    // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
267
-		$this->import_convertvalue_array[$r]=array(
268
-				't.fk_projet'=>array('rule'=>'fetchidfromref','classfile'=>'/projet/class/project.class.php','class'=>'Project','method'=>'fetch','element'=>'Project'),
269
-				't.ref'=>array('rule'=>'getrefifauto')
270
-		);
271
-		//$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
272
-		$this->import_regex_array[$r]=array('b.doc_date'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$');
273
-		//$this->import_examplevalues_array[$r]=array('t.fk_projet'=>'MyProjectRef','t.ref'=>"auto or TK2010-1234",'t.label'=>"My task",'t.progress'=>"0 (not started) to 100 (finished)",'t.datec'=>'1972-10-10','t.note_private'=>"My private note",'t.note_public'=>"My public note");
258
+        // General ledger
259
+        $r++;
260
+        $this->import_code[$r]=$this->rights_class.'_'.$r;
261
+        $this->import_label[$r]='ImportAccountingEntries';
262
+        $this->import_icon[$r]=$this->picto;
263
+        $this->import_entities_array[$r]=array();	// We define here only fields that use another icon that the one defined into import_icon
264
+        $this->import_tables_array[$r]=array('b'=>MAIN_DB_PREFIX.'accounting_bookkeeping');	// List of tables to insert into (insert done in same order)
265
+        $this->import_fields_array[$r]=array('b.doc_date'=>"Docdate",'b.code_journal'=>'Codejournal','b.numero_compte'=>'AccountAccountingShort','b.label_operation'=>'LabelOperation','b.debit'=>"Debit",'b.credit'=>"Credit",'b.date_creation'=>"DateCreation");
266
+        $this->import_fieldshidden_array[$r]=array('b.fk_user'=>'user->id');    // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
267
+        $this->import_convertvalue_array[$r]=array(
268
+                't.fk_projet'=>array('rule'=>'fetchidfromref','classfile'=>'/projet/class/project.class.php','class'=>'Project','method'=>'fetch','element'=>'Project'),
269
+                't.ref'=>array('rule'=>'getrefifauto')
270
+        );
271
+        //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
272
+        $this->import_regex_array[$r]=array('b.doc_date'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$');
273
+        //$this->import_examplevalues_array[$r]=array('t.fk_projet'=>'MyProjectRef','t.ref'=>"auto or TK2010-1234",'t.label'=>"My task",'t.progress'=>"0 (not started) to 100 (finished)",'t.datec'=>'1972-10-10','t.note_private'=>"My private note",'t.note_public'=>"My public note");
274 274
 
275
-		// Chart of accounts
276
-		$r++;
277
-		$this->import_code[$r]=$this->rights_class.'_'.$r;
278
-		$this->import_label[$r]="Chartofaccounts"; // Translation key
279
-		$this->import_icon[$r]=$this->picto;
280
-		$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
281
-		$this->import_tables_array[$r]=array('aa'=>MAIN_DB_PREFIX.'accounting_account');
282
-		$this->import_tables_creator_array[$r]=array('aa'=>'fk_user_author');    // Fields to store import user id
283
-		$this->import_fields_array[$r]=array('aa.fk_pcg_version'=>"Chartofaccounts*",'aa.account_number'=>"AccountAccounting*",'aa.label'=>"Label*",'aa.account_parent'=>"Accountparent","aa.fk_accounting_category"=>"AccountingCategory","aa.pcg_type"=>"Pcgtype*",'aa.pcg_subtype'=>'Pcgsubtype*','aa.active'=>'Status*','aa.datec'=>"DateCreation");
284
-		$this->import_regex_array[$r]=array('aa.fk_pcg_version'=>'pcg_version@'.MAIN_DB_PREFIX.'accounting_system','aa.account_number'=>'^\d{1,32}$','aa.label'=>'^.{1,255}$','aa.account_parent'=>'^\d{0,32}$','aa.fk_accounting_category'=>'rowid@'.MAIN_DB_PREFIX.'c_accounting_category','aa.pcg_type'=>'^.{1,20}$','aa.pcg_subtype'=>'^.{1,20}$','aa.active'=>'^0|1$','aa.datec'=>'^\d{4}-\d{2}-\d{2}$');
285
-		$this->import_convertvalue_array[$r]=array(
286
-			'aa.fk_accounting_category'=>array('rule'=>'fetchidfromcodeorlabel','classfile'=>'/accountancy/class/accountancycategory.class.php','class'=>'AccountancyCategory','method'=>'fetch','dict'=>'DictionaryAccountancyCategory'),
287
-			'aa.account_parent'=>array('rule'=>'zeroifnull'),
288
-		);
289
-		$this->import_examplevalues_array[$r]=array('aa.fk_pcg_version'=>"PCG99-ABREGE",'aa.account_number'=>"707",'aa.label'=>"Product sales",'aa.account_parent'=>"1407","aa.fk_accounting_category"=>"","aa.pcg_type"=>"PROD",'aa.pcg_subtype'=>'PRODUCT','aa.active'=>'1','aa.datec'=>"2017-04-28");
290
-	}
275
+        // Chart of accounts
276
+        $r++;
277
+        $this->import_code[$r]=$this->rights_class.'_'.$r;
278
+        $this->import_label[$r]="Chartofaccounts"; // Translation key
279
+        $this->import_icon[$r]=$this->picto;
280
+        $this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
281
+        $this->import_tables_array[$r]=array('aa'=>MAIN_DB_PREFIX.'accounting_account');
282
+        $this->import_tables_creator_array[$r]=array('aa'=>'fk_user_author');    // Fields to store import user id
283
+        $this->import_fields_array[$r]=array('aa.fk_pcg_version'=>"Chartofaccounts*",'aa.account_number'=>"AccountAccounting*",'aa.label'=>"Label*",'aa.account_parent'=>"Accountparent","aa.fk_accounting_category"=>"AccountingCategory","aa.pcg_type"=>"Pcgtype*",'aa.pcg_subtype'=>'Pcgsubtype*','aa.active'=>'Status*','aa.datec'=>"DateCreation");
284
+        $this->import_regex_array[$r]=array('aa.fk_pcg_version'=>'pcg_version@'.MAIN_DB_PREFIX.'accounting_system','aa.account_number'=>'^\d{1,32}$','aa.label'=>'^.{1,255}$','aa.account_parent'=>'^\d{0,32}$','aa.fk_accounting_category'=>'rowid@'.MAIN_DB_PREFIX.'c_accounting_category','aa.pcg_type'=>'^.{1,20}$','aa.pcg_subtype'=>'^.{1,20}$','aa.active'=>'^0|1$','aa.datec'=>'^\d{4}-\d{2}-\d{2}$');
285
+        $this->import_convertvalue_array[$r]=array(
286
+            'aa.fk_accounting_category'=>array('rule'=>'fetchidfromcodeorlabel','classfile'=>'/accountancy/class/accountancycategory.class.php','class'=>'AccountancyCategory','method'=>'fetch','dict'=>'DictionaryAccountancyCategory'),
287
+            'aa.account_parent'=>array('rule'=>'zeroifnull'),
288
+        );
289
+        $this->import_examplevalues_array[$r]=array('aa.fk_pcg_version'=>"PCG99-ABREGE",'aa.account_number'=>"707",'aa.label'=>"Product sales",'aa.account_parent'=>"1407","aa.fk_accounting_category"=>"","aa.pcg_type"=>"PROD",'aa.pcg_subtype'=>'PRODUCT','aa.active'=>'1','aa.datec'=>"2017-04-28");
290
+    }
291 291
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  * \ingroup		Advanced accountancy
26 26
  * \brief		Module to activate Accounting Expert module
27 27
  */
28
-include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
28
+include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
29 29
 
30 30
 /**
31 31
  * Description and activation class for module accounting expert
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 		// Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
54 54
 		$this->version = 'dolibarr';
55 55
 
56
-		$this->const_name = 'MAIN_MODULE_' . strtoupper($this->name);
56
+		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
57 57
 		$this->picto = 'accounting';
58 58
 
59 59
 		// Data directories to create when module is enabled
@@ -63,12 +63,12 @@  discard block
 block discarded – undo
63 63
 		$this->config_page_url = array();
64 64
 
65 65
 		// Dependencies
66
-		$this->depends = array("modFacture","modBanque","modTax"); // List of modules id that must be enabled if this module is enabled
66
+		$this->depends = array("modFacture", "modBanque", "modTax"); // List of modules id that must be enabled if this module is enabled
67 67
 		$this->requiredby = array(); // List of modules id to disable if this one is disabled
68 68
 		$this->conflictwith = array("modComptabilite"); // List of modules are in conflict with this module
69 69
 		$this->phpmin = array(5, 4); // Minimum version of PHP required by module
70 70
 		$this->need_dolibarr_version = array(3, 9); // Minimum version of Dolibarr required by module
71
-		$this->langfiles = array("accountancy","compta");
71
+		$this->langfiles = array("accountancy", "compta");
72 72
 
73 73
 		// Constants
74 74
 		// List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 				"1",
137 137
 				"", 0, 'current', 0
138 138
 		);
139
-		$this->const[11] = array (
139
+		$this->const[11] = array(
140 140
 				"ACCOUNTING_EXPORT_DATE",
141 141
 				"chaine",
142 142
 				"%d%m%Y",
@@ -231,61 +231,61 @@  discard block
 block discarded – undo
231 231
 
232 232
 		// Menus
233 233
 		//-------
234
-		$this->menu = 1;        // This module add menu entries. They are coded into menu manager.
234
+		$this->menu = 1; // This module add menu entries. They are coded into menu manager.
235 235
 
236 236
 		// Exports
237 237
 		//--------
238
-		$r=0;
238
+		$r = 0;
239 239
 
240 240
 		$r++;
241
-		$this->export_code[$r]=$this->rights_class.'_'.$r;
242
-		$this->export_label[$r]='Chartofaccounts';
243
-		$this->export_icon[$r]='Accounting';
244
-		$this->export_permission[$r]=array(array("accounting","chartofaccount"));
245
-		$this->export_fields_array[$r]=array('ac.rowid'=>'ChartofaccountsId','ac.pcg_version'=>'Chartofaccounts','aa.rowid'=>'Id','aa.account_number'=>"AccountAccounting",'aa.label'=>"Label",'aa.account_parent'=>"Accountparent",'aa.pcg_type'=>"Pcgtype",'aa.pcg_subtype'=>'Pcgsubtype','aa.active'=>'Status');
246
-		$this->export_TypeFields_array[$r]=array('ac.rowid'=>'List:accounting_system:pcg_version','aa.account_number'=>"Text",'aa.label'=>"Text",'aa.pcg_type'=>'Text','aa.pcg_subtype'=>'Text','aa.active'=>'Status');
247
-		$this->export_entities_array[$r]=array('ac.rowid'=>"Accounting",'ac.pcg_version'=>"Accounting",'aa.rowid'=>'Accounting','aa.account_number'=>"Accounting",'aa.label'=>"Accounting",'aa.accountparent'=>"Accounting",'aa.pcg_type'=>"Accounting",'aa.pcgsubtype'=>"Accounting",'aa_active'=>"Accounting");
241
+		$this->export_code[$r] = $this->rights_class.'_'.$r;
242
+		$this->export_label[$r] = 'Chartofaccounts';
243
+		$this->export_icon[$r] = 'Accounting';
244
+		$this->export_permission[$r] = array(array("accounting", "chartofaccount"));
245
+		$this->export_fields_array[$r] = array('ac.rowid'=>'ChartofaccountsId', 'ac.pcg_version'=>'Chartofaccounts', 'aa.rowid'=>'Id', 'aa.account_number'=>"AccountAccounting", 'aa.label'=>"Label", 'aa.account_parent'=>"Accountparent", 'aa.pcg_type'=>"Pcgtype", 'aa.pcg_subtype'=>'Pcgsubtype', 'aa.active'=>'Status');
246
+		$this->export_TypeFields_array[$r] = array('ac.rowid'=>'List:accounting_system:pcg_version', 'aa.account_number'=>"Text", 'aa.label'=>"Text", 'aa.pcg_type'=>'Text', 'aa.pcg_subtype'=>'Text', 'aa.active'=>'Status');
247
+		$this->export_entities_array[$r] = array('ac.rowid'=>"Accounting", 'ac.pcg_version'=>"Accounting", 'aa.rowid'=>'Accounting', 'aa.account_number'=>"Accounting", 'aa.label'=>"Accounting", 'aa.accountparent'=>"Accounting", 'aa.pcg_type'=>"Accounting", 'aa.pcgsubtype'=>"Accounting", 'aa_active'=>"Accounting");
248 248
 
249
-		$this->export_sql_start[$r]='SELECT DISTINCT ';
250
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'accounting_account as aa, '.MAIN_DB_PREFIX.'accounting_system as ac';
251
-		$this->export_sql_end[$r] .=' WHERE ac.pcg_version = aa.fk_pcg_version AND aa.entity IN ('.getEntity('accounting').') ';
249
+		$this->export_sql_start[$r] = 'SELECT DISTINCT ';
250
+		$this->export_sql_end[$r]  = ' FROM '.MAIN_DB_PREFIX.'accounting_account as aa, '.MAIN_DB_PREFIX.'accounting_system as ac';
251
+		$this->export_sql_end[$r] .= ' WHERE ac.pcg_version = aa.fk_pcg_version AND aa.entity IN ('.getEntity('accounting').') ';
252 252
 
253 253
 
254 254
 		// Imports
255 255
 		//--------
256
-		$r=0;
256
+		$r = 0;
257 257
 
258 258
 		// General ledger
259 259
 		$r++;
260
-		$this->import_code[$r]=$this->rights_class.'_'.$r;
261
-		$this->import_label[$r]='ImportAccountingEntries';
262
-		$this->import_icon[$r]=$this->picto;
263
-		$this->import_entities_array[$r]=array();	// We define here only fields that use another icon that the one defined into import_icon
264
-		$this->import_tables_array[$r]=array('b'=>MAIN_DB_PREFIX.'accounting_bookkeeping');	// List of tables to insert into (insert done in same order)
265
-		$this->import_fields_array[$r]=array('b.doc_date'=>"Docdate",'b.code_journal'=>'Codejournal','b.numero_compte'=>'AccountAccountingShort','b.label_operation'=>'LabelOperation','b.debit'=>"Debit",'b.credit'=>"Credit",'b.date_creation'=>"DateCreation");
266
-		$this->import_fieldshidden_array[$r]=array('b.fk_user'=>'user->id');    // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
267
-		$this->import_convertvalue_array[$r]=array(
268
-				't.fk_projet'=>array('rule'=>'fetchidfromref','classfile'=>'/projet/class/project.class.php','class'=>'Project','method'=>'fetch','element'=>'Project'),
260
+		$this->import_code[$r] = $this->rights_class.'_'.$r;
261
+		$this->import_label[$r] = 'ImportAccountingEntries';
262
+		$this->import_icon[$r] = $this->picto;
263
+		$this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
264
+		$this->import_tables_array[$r] = array('b'=>MAIN_DB_PREFIX.'accounting_bookkeeping'); // List of tables to insert into (insert done in same order)
265
+		$this->import_fields_array[$r] = array('b.doc_date'=>"Docdate", 'b.code_journal'=>'Codejournal', 'b.numero_compte'=>'AccountAccountingShort', 'b.label_operation'=>'LabelOperation', 'b.debit'=>"Debit", 'b.credit'=>"Credit", 'b.date_creation'=>"DateCreation");
266
+		$this->import_fieldshidden_array[$r] = array('b.fk_user'=>'user->id'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
267
+		$this->import_convertvalue_array[$r] = array(
268
+				't.fk_projet'=>array('rule'=>'fetchidfromref', 'classfile'=>'/projet/class/project.class.php', 'class'=>'Project', 'method'=>'fetch', 'element'=>'Project'),
269 269
 				't.ref'=>array('rule'=>'getrefifauto')
270 270
 		);
271 271
 		//$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
272
-		$this->import_regex_array[$r]=array('b.doc_date'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$');
272
+		$this->import_regex_array[$r] = array('b.doc_date'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$');
273 273
 		//$this->import_examplevalues_array[$r]=array('t.fk_projet'=>'MyProjectRef','t.ref'=>"auto or TK2010-1234",'t.label'=>"My task",'t.progress'=>"0 (not started) to 100 (finished)",'t.datec'=>'1972-10-10','t.note_private'=>"My private note",'t.note_public'=>"My public note");
274 274
 
275 275
 		// Chart of accounts
276 276
 		$r++;
277
-		$this->import_code[$r]=$this->rights_class.'_'.$r;
278
-		$this->import_label[$r]="Chartofaccounts"; // Translation key
279
-		$this->import_icon[$r]=$this->picto;
280
-		$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
281
-		$this->import_tables_array[$r]=array('aa'=>MAIN_DB_PREFIX.'accounting_account');
282
-		$this->import_tables_creator_array[$r]=array('aa'=>'fk_user_author');    // Fields to store import user id
283
-		$this->import_fields_array[$r]=array('aa.fk_pcg_version'=>"Chartofaccounts*",'aa.account_number'=>"AccountAccounting*",'aa.label'=>"Label*",'aa.account_parent'=>"Accountparent","aa.fk_accounting_category"=>"AccountingCategory","aa.pcg_type"=>"Pcgtype*",'aa.pcg_subtype'=>'Pcgsubtype*','aa.active'=>'Status*','aa.datec'=>"DateCreation");
284
-		$this->import_regex_array[$r]=array('aa.fk_pcg_version'=>'pcg_version@'.MAIN_DB_PREFIX.'accounting_system','aa.account_number'=>'^\d{1,32}$','aa.label'=>'^.{1,255}$','aa.account_parent'=>'^\d{0,32}$','aa.fk_accounting_category'=>'rowid@'.MAIN_DB_PREFIX.'c_accounting_category','aa.pcg_type'=>'^.{1,20}$','aa.pcg_subtype'=>'^.{1,20}$','aa.active'=>'^0|1$','aa.datec'=>'^\d{4}-\d{2}-\d{2}$');
285
-		$this->import_convertvalue_array[$r]=array(
286
-			'aa.fk_accounting_category'=>array('rule'=>'fetchidfromcodeorlabel','classfile'=>'/accountancy/class/accountancycategory.class.php','class'=>'AccountancyCategory','method'=>'fetch','dict'=>'DictionaryAccountancyCategory'),
277
+		$this->import_code[$r] = $this->rights_class.'_'.$r;
278
+		$this->import_label[$r] = "Chartofaccounts"; // Translation key
279
+		$this->import_icon[$r] = $this->picto;
280
+		$this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
281
+		$this->import_tables_array[$r] = array('aa'=>MAIN_DB_PREFIX.'accounting_account');
282
+		$this->import_tables_creator_array[$r] = array('aa'=>'fk_user_author'); // Fields to store import user id
283
+		$this->import_fields_array[$r] = array('aa.fk_pcg_version'=>"Chartofaccounts*", 'aa.account_number'=>"AccountAccounting*", 'aa.label'=>"Label*", 'aa.account_parent'=>"Accountparent", "aa.fk_accounting_category"=>"AccountingCategory", "aa.pcg_type"=>"Pcgtype*", 'aa.pcg_subtype'=>'Pcgsubtype*', 'aa.active'=>'Status*', 'aa.datec'=>"DateCreation");
284
+		$this->import_regex_array[$r] = array('aa.fk_pcg_version'=>'pcg_version@'.MAIN_DB_PREFIX.'accounting_system', 'aa.account_number'=>'^\d{1,32}$', 'aa.label'=>'^.{1,255}$', 'aa.account_parent'=>'^\d{0,32}$', 'aa.fk_accounting_category'=>'rowid@'.MAIN_DB_PREFIX.'c_accounting_category', 'aa.pcg_type'=>'^.{1,20}$', 'aa.pcg_subtype'=>'^.{1,20}$', 'aa.active'=>'^0|1$', 'aa.datec'=>'^\d{4}-\d{2}-\d{2}$');
285
+		$this->import_convertvalue_array[$r] = array(
286
+			'aa.fk_accounting_category'=>array('rule'=>'fetchidfromcodeorlabel', 'classfile'=>'/accountancy/class/accountancycategory.class.php', 'class'=>'AccountancyCategory', 'method'=>'fetch', 'dict'=>'DictionaryAccountancyCategory'),
287 287
 			'aa.account_parent'=>array('rule'=>'zeroifnull'),
288 288
 		);
289
-		$this->import_examplevalues_array[$r]=array('aa.fk_pcg_version'=>"PCG99-ABREGE",'aa.account_number'=>"707",'aa.label'=>"Product sales",'aa.account_parent'=>"1407","aa.fk_accounting_category"=>"","aa.pcg_type"=>"PROD",'aa.pcg_subtype'=>'PRODUCT','aa.active'=>'1','aa.datec'=>"2017-04-28");
289
+		$this->import_examplevalues_array[$r] = array('aa.fk_pcg_version'=>"PCG99-ABREGE", 'aa.account_number'=>"707", 'aa.label'=>"Product sales", 'aa.account_parent'=>"1407", "aa.fk_accounting_category"=>"", "aa.pcg_type"=>"PROD", 'aa.pcg_subtype'=>'PRODUCT', 'aa.active'=>'1', 'aa.datec'=>"2017-04-28");
290 290
 	}
291 291
 }
Please login to merge, or discard this patch.
htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php 3 patches
Indentation   +489 added lines, -489 removed lines patch added patch discarded remove patch
@@ -38,511 +38,511 @@
 block discarded – undo
38 38
  */
39 39
 class doc_generic_proposal_odt extends ModelePDFPropales
40 40
 {
41
-	/**
42
-	 * Issuer
43
-	 * @var Company object that emits
44
-	 */
45
-	public $emetteur;
46
-
47
-	/**
48
-   * @var array() Minimum version of PHP required by module.
49
-	 * e.g.: PHP ≥ 5.4 = array(5, 4)
50
-   */
51
-	public $phpmin = array(5, 4);
52
-
53
-	/**
41
+    /**
42
+     * Issuer
43
+     * @var Company object that emits
44
+     */
45
+    public $emetteur;
46
+
47
+    /**
48
+     * @var array() Minimum version of PHP required by module.
49
+     * e.g.: PHP ≥ 5.4 = array(5, 4)
50
+     */
51
+    public $phpmin = array(5, 4);
52
+
53
+    /**
54 54
      * Dolibarr version of the loaded document
55 55
      * @public string
56 56
      */
57
-	public $version = 'dolibarr';
57
+    public $version = 'dolibarr';
58 58
 
59 59
 
60
-	/**
61
-	 *	Constructor
62
-	 *
63
-	 *  @param		DoliDB		$db      Database handler
64
-	 */
65
-	function __construct($db)
66
-	{
67
-		global $conf, $langs, $mysoc;
60
+    /**
61
+     *	Constructor
62
+     *
63
+     *  @param		DoliDB		$db      Database handler
64
+     */
65
+    function __construct($db)
66
+    {
67
+        global $conf, $langs, $mysoc;
68 68
 
69
-		// Load translation files required by the page
69
+        // Load translation files required by the page
70 70
         $langs->loadLangs(array("main","companies"));
71 71
 
72
-		$this->db = $db;
73
-		$this->name = "ODT templates";
74
-		$this->description = $langs->trans("DocumentModelOdt");
75
-		$this->scandir = 'PROPALE_ADDON_PDF_ODT_PATH';	// Name of constant that is used to save list of directories to scan
76
-
77
-		// Dimension page pour format A4
78
-		$this->type = 'odt';
79
-		$this->page_largeur = 0;
80
-		$this->page_hauteur = 0;
81
-		$this->format = array($this->page_largeur,$this->page_hauteur);
82
-		$this->marge_gauche=0;
83
-		$this->marge_droite=0;
84
-		$this->marge_haute=0;
85
-		$this->marge_basse=0;
86
-
87
-		$this->option_logo = 1;                    // Affiche logo
88
-		$this->option_tva = 0;                     // Gere option tva PROPALE_TVAOPTION
89
-		$this->option_modereg = 0;                 // Affiche mode reglement
90
-		$this->option_condreg = 0;                 // Affiche conditions reglement
91
-		$this->option_codeproduitservice = 0;      // Affiche code produit-service
92
-		$this->option_multilang = 1;               // Dispo en plusieurs langues
93
-		$this->option_escompte = 0;                // Affiche si il y a eu escompte
94
-		$this->option_credit_note = 0;             // Support credit notes
95
-		$this->option_freetext = 1;				   // Support add of a personalised text
96
-		$this->option_draft_watermark = 0;		   // Support add of a watermark on drafts
97
-
98
-		// Recupere emetteur
99
-		$this->emetteur=$mysoc;
100
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
101
-	}
102
-
103
-
104
-	/**
105
-	 *	Return description of a module
106
-	 *
107
-	 *	@param	Translate	$langs      Lang object to use for output
108
-	 *	@return string       			Description
109
-	 */
110
-	function info($langs)
111
-	{
112
-		global $conf,$langs;
113
-
114
-		// Load translation files required by the page
72
+        $this->db = $db;
73
+        $this->name = "ODT templates";
74
+        $this->description = $langs->trans("DocumentModelOdt");
75
+        $this->scandir = 'PROPALE_ADDON_PDF_ODT_PATH';	// Name of constant that is used to save list of directories to scan
76
+
77
+        // Dimension page pour format A4
78
+        $this->type = 'odt';
79
+        $this->page_largeur = 0;
80
+        $this->page_hauteur = 0;
81
+        $this->format = array($this->page_largeur,$this->page_hauteur);
82
+        $this->marge_gauche=0;
83
+        $this->marge_droite=0;
84
+        $this->marge_haute=0;
85
+        $this->marge_basse=0;
86
+
87
+        $this->option_logo = 1;                    // Affiche logo
88
+        $this->option_tva = 0;                     // Gere option tva PROPALE_TVAOPTION
89
+        $this->option_modereg = 0;                 // Affiche mode reglement
90
+        $this->option_condreg = 0;                 // Affiche conditions reglement
91
+        $this->option_codeproduitservice = 0;      // Affiche code produit-service
92
+        $this->option_multilang = 1;               // Dispo en plusieurs langues
93
+        $this->option_escompte = 0;                // Affiche si il y a eu escompte
94
+        $this->option_credit_note = 0;             // Support credit notes
95
+        $this->option_freetext = 1;				   // Support add of a personalised text
96
+        $this->option_draft_watermark = 0;		   // Support add of a watermark on drafts
97
+
98
+        // Recupere emetteur
99
+        $this->emetteur=$mysoc;
100
+        if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
101
+    }
102
+
103
+
104
+    /**
105
+     *	Return description of a module
106
+     *
107
+     *	@param	Translate	$langs      Lang object to use for output
108
+     *	@return string       			Description
109
+     */
110
+    function info($langs)
111
+    {
112
+        global $conf,$langs;
113
+
114
+        // Load translation files required by the page
115 115
         $langs->loadLangs(array("errors","companies"));
116 116
 
117
-		$form = new Form($this->db);
118
-
119
-		$texte = $this->description.".<br>\n";
120
-		$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
121
-		$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
122
-		$texte.= '<input type="hidden" name="action" value="setModuleOptions">';
123
-		$texte.= '<input type="hidden" name="param1" value="PROPALE_ADDON_PDF_ODT_PATH">';
124
-		if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0)
125
-		{
126
-			$texte.= '<input type="hidden" name="param2" value="PROPALE_ADDON_PDF_ODT_DEFAULT">';
127
-			$texte.= '<input type="hidden" name="param3" value="PROPALE_ADDON_PDF_ODT_TOBILL">';
128
-			$texte.= '<input type="hidden" name="param4" value="PROPALE_ADDON_PDF_ODT_CLOSED">';
129
-		}
130
-		$texte.= '<table class="nobordernopadding" width="100%">';
131
-
132
-		// List of directories area
133
-		$texte.= '<tr><td>';
134
-		$texttitle=$langs->trans("ListOfDirectories");
135
-		$listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->PROPALE_ADDON_PDF_ODT_PATH)));
136
-		$listoffiles=array();
137
-		foreach($listofdir as $key=>$tmpdir)
138
-		{
139
-			$tmpdir=trim($tmpdir);
140
-			$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
141
-			if (! $tmpdir) {
142
-				unset($listofdir[$key]); continue;
143
-			}
144
-			if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
145
-			else
146
-			{
147
-				$tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
148
-				if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
149
-			}
150
-		}
151
-		$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
152
-		// Add list of substitution keys
153
-		$texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
154
-		$texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation");    // This contains an url, we don't modify it
155
-
156
-		$texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
157
-		$texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
158
-		$texte.= '<textarea class="flat" cols="60" name="value1">';
159
-		$texte.=$conf->global->PROPALE_ADDON_PDF_ODT_PATH;
160
-		$texte.= '</textarea>';
161
-		$texte.= '</div><div style="display: inline-block; vertical-align: middle;">';
162
-		$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
163
-		$texte.= '<br></div></div>';
164
-
165
-		// Scan directories
166
-		$nbofiles=count($listoffiles);
167
-		if (! empty($conf->global->PROPALE_ADDON_PDF_ODT_PATH))
168
-		{
169
-			$texte.=$langs->trans("NumberOfModelFilesFound").': <b>';
170
-			//$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':'';
171
-			$texte.=count($listoffiles);
172
-			//$texte.=$nbofiles?'</a>':'';
173
-			$texte.='</b>';
174
-		}
175
-
176
-		if ($nbofiles)
177
-		{
178
-   			$texte.='<div id="div_'.get_class($this).'" class="hidden">';
179
-   			foreach($listoffiles as $file)
180
-   			{
117
+        $form = new Form($this->db);
118
+
119
+        $texte = $this->description.".<br>\n";
120
+        $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
121
+        $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
122
+        $texte.= '<input type="hidden" name="action" value="setModuleOptions">';
123
+        $texte.= '<input type="hidden" name="param1" value="PROPALE_ADDON_PDF_ODT_PATH">';
124
+        if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0)
125
+        {
126
+            $texte.= '<input type="hidden" name="param2" value="PROPALE_ADDON_PDF_ODT_DEFAULT">';
127
+            $texte.= '<input type="hidden" name="param3" value="PROPALE_ADDON_PDF_ODT_TOBILL">';
128
+            $texte.= '<input type="hidden" name="param4" value="PROPALE_ADDON_PDF_ODT_CLOSED">';
129
+        }
130
+        $texte.= '<table class="nobordernopadding" width="100%">';
131
+
132
+        // List of directories area
133
+        $texte.= '<tr><td>';
134
+        $texttitle=$langs->trans("ListOfDirectories");
135
+        $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->PROPALE_ADDON_PDF_ODT_PATH)));
136
+        $listoffiles=array();
137
+        foreach($listofdir as $key=>$tmpdir)
138
+        {
139
+            $tmpdir=trim($tmpdir);
140
+            $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
141
+            if (! $tmpdir) {
142
+                unset($listofdir[$key]); continue;
143
+            }
144
+            if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
145
+            else
146
+            {
147
+                $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
148
+                if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
149
+            }
150
+        }
151
+        $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
152
+        // Add list of substitution keys
153
+        $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
154
+        $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation");    // This contains an url, we don't modify it
155
+
156
+        $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
157
+        $texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
158
+        $texte.= '<textarea class="flat" cols="60" name="value1">';
159
+        $texte.=$conf->global->PROPALE_ADDON_PDF_ODT_PATH;
160
+        $texte.= '</textarea>';
161
+        $texte.= '</div><div style="display: inline-block; vertical-align: middle;">';
162
+        $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
163
+        $texte.= '<br></div></div>';
164
+
165
+        // Scan directories
166
+        $nbofiles=count($listoffiles);
167
+        if (! empty($conf->global->PROPALE_ADDON_PDF_ODT_PATH))
168
+        {
169
+            $texte.=$langs->trans("NumberOfModelFilesFound").': <b>';
170
+            //$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':'';
171
+            $texte.=count($listoffiles);
172
+            //$texte.=$nbofiles?'</a>':'';
173
+            $texte.='</b>';
174
+        }
175
+
176
+        if ($nbofiles)
177
+        {
178
+                $texte.='<div id="div_'.get_class($this).'" class="hidden">';
179
+                foreach($listoffiles as $file)
180
+                {
181 181
                 $texte.=$file['name'].'<br>';
182
-   			}
183
-   			$texte.='<div id="div_'.get_class($this).'">';
184
-
185
-			if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0)
186
-			{
187
-				// Model for creation
188
-				$liste=ModelePDFPropales::liste_modeles($this->db);
189
-				$texte.= '<table width="50%;">';
190
-				$texte.= '<tr>';
191
-				$texte.= '<td width="60%;">'.$langs->trans("DefaultModelPropalCreate").'</td>';
192
-				$texte.= '<td colspan="">';
193
-				$texte.= $form->selectarray('value2',$liste,$conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT);
194
-				$texte.= "</td></tr>";
195
-
196
-				$texte.= '<tr>';
197
-				$texte.= '<td width="60%;">'.$langs->trans("DefaultModelPropalToBill").'</td>';
198
-				$texte.= '<td colspan="">';
199
-				$texte.= $form->selectarray('value3',$liste,$conf->global->PROPALE_ADDON_PDF_ODT_TOBILL);
200
-				$texte.= "</td></tr>";
201
-				$texte.= '<tr>';
202
-
203
-				$texte.= '<td width="60%;">'.$langs->trans("DefaultModelPropalClosed").'</td>';
204
-				$texte.= '<td colspan="">';
205
-				$texte.= $form->selectarray('value4',$liste,$conf->global->PROPALE_ADDON_PDF_ODT_CLOSED);
206
-				$texte.= "</td></tr>";
207
-				$texte.= '</table>';
208
-			}
209
-		}
210
-
211
-		$texte.= '</td>';
212
-
213
-		$texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">';
214
-		$texte.= $langs->trans("ExampleOfDirectoriesForModelGen");
215
-		$texte.= '</td>';
216
-		$texte.= '</tr>';
217
-
218
-		$texte.= '</table>';
219
-		$texte.= '</form>';
220
-
221
-		return $texte;
222
-	}
182
+                }
183
+                $texte.='<div id="div_'.get_class($this).'">';
184
+
185
+            if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0)
186
+            {
187
+                // Model for creation
188
+                $liste=ModelePDFPropales::liste_modeles($this->db);
189
+                $texte.= '<table width="50%;">';
190
+                $texte.= '<tr>';
191
+                $texte.= '<td width="60%;">'.$langs->trans("DefaultModelPropalCreate").'</td>';
192
+                $texte.= '<td colspan="">';
193
+                $texte.= $form->selectarray('value2',$liste,$conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT);
194
+                $texte.= "</td></tr>";
195
+
196
+                $texte.= '<tr>';
197
+                $texte.= '<td width="60%;">'.$langs->trans("DefaultModelPropalToBill").'</td>';
198
+                $texte.= '<td colspan="">';
199
+                $texte.= $form->selectarray('value3',$liste,$conf->global->PROPALE_ADDON_PDF_ODT_TOBILL);
200
+                $texte.= "</td></tr>";
201
+                $texte.= '<tr>';
202
+
203
+                $texte.= '<td width="60%;">'.$langs->trans("DefaultModelPropalClosed").'</td>';
204
+                $texte.= '<td colspan="">';
205
+                $texte.= $form->selectarray('value4',$liste,$conf->global->PROPALE_ADDON_PDF_ODT_CLOSED);
206
+                $texte.= "</td></tr>";
207
+                $texte.= '</table>';
208
+            }
209
+        }
210
+
211
+        $texte.= '</td>';
212
+
213
+        $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">';
214
+        $texte.= $langs->trans("ExampleOfDirectoriesForModelGen");
215
+        $texte.= '</td>';
216
+        $texte.= '</tr>';
217
+
218
+        $texte.= '</table>';
219
+        $texte.= '</form>';
220
+
221
+        return $texte;
222
+    }
223 223
 
224 224
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
225
-	/**
226
-	 *	Function to build a document on disk using the generic odt module.
227
-	 *
228
-	 *	@param		Propale		$object				Object source to build document
229
-	 *	@param		Translate	$outputlangs		Lang output object
230
-	 * 	@param		string		$srctemplatepath	Full path of source filename for generator using a template file
231
-	 *  @param		int			$hidedetails		Do not show line details
232
-	 *  @param		int			$hidedesc			Do not show desc
233
-	 *  @param		int			$hideref			Do not show ref
234
-	 *	@return		int         					1 if OK, <=0 if KO
235
-	 */
236
-	function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
237
-	{
225
+    /**
226
+     *	Function to build a document on disk using the generic odt module.
227
+     *
228
+     *	@param		Propale		$object				Object source to build document
229
+     *	@param		Translate	$outputlangs		Lang output object
230
+     * 	@param		string		$srctemplatepath	Full path of source filename for generator using a template file
231
+     *  @param		int			$hidedetails		Do not show line details
232
+     *  @param		int			$hidedesc			Do not show desc
233
+     *  @param		int			$hideref			Do not show ref
234
+     *	@return		int         					1 if OK, <=0 if KO
235
+     */
236
+    function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
237
+    {
238 238
         // phpcs:enable
239
-		global $user,$langs,$conf,$mysoc,$hookmanager;
240
-
241
-		if (empty($srctemplatepath))
242
-		{
243
-			dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
244
-			return -1;
245
-		}
246
-
247
-		// Add odtgeneration hook
248
-		if (! is_object($hookmanager))
249
-		{
250
-			include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
251
-			$hookmanager=new HookManager($this->db);
252
-		}
253
-		$hookmanager->initHooks(array('odtgeneration'));
254
-		global $action;
255
-
256
-		if (! is_object($outputlangs)) $outputlangs=$langs;
257
-		$sav_charset_output=$outputlangs->charset_output;
258
-		$outputlangs->charset_output='UTF-8';
259
-
260
-		// Load translation files required by the page
261
-		$outputlangs->loadLangs(array("main", "dict", "companies", "bills"));
262
-
263
-		if ($conf->propal->multidir_output[$conf->entity])
264
-		{
265
-			// If $object is id instead of object
266
-			if (! is_object($object))
267
-			{
268
-				$id = $object;
269
-				$object = new Propal($this->db);
270
-				$result=$object->fetch($id);
271
-				if ($result < 0)
272
-				{
273
-					dol_print_error($this->db,$object->error);
274
-					return -1;
275
-				}
276
-			}
277
-
278
-			$dir = $conf->propal->multidir_output[$object->entity];
279
-			$objectref = dol_sanitizeFileName($object->ref);
280
-			if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
281
-			$file = $dir . "/" . $objectref . ".odt";
282
-
283
-			if (! file_exists($dir))
284
-			{
285
-				if (dol_mkdir($dir) < 0)
286
-				{
287
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
288
-					return -1;
289
-				}
290
-			}
291
-
292
-			if (file_exists($dir))
293
-			{
294
-				//print "srctemplatepath=".$srctemplatepath;	// Src filename
295
-				$newfile=basename($srctemplatepath);
296
-				$newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile);
297
-				$newfiletmp=preg_replace('/template_/i','',$newfiletmp);
298
-				$newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
299
-
300
-				$newfiletmp=$objectref.'_'.$newfiletmp;
301
-
302
-				// Get extension (ods or odt)
303
-				$newfileformat=substr($newfile, strrpos($newfile, '.')+1);
304
-				if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
305
-				{
306
-				    $format=$conf->global->MAIN_DOC_USE_TIMING;
307
-				    if ($format == '1') $format='%Y%m%d%H%M%S';
308
-					$filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
309
-				}
310
-				else
311
-				{
312
-					$filename=$newfiletmp.'.'.$newfileformat;
313
-				}
314
-				$file=$dir.'/'.$filename;
315
-				//print "newdir=".$dir;
316
-				//print "newfile=".$newfile;
317
-				//print "file=".$file;
318
-				//print "conf->propal->dir_temp=".$conf->propal->dir_temp;
319
-
320
-				dol_mkdir($conf->propal->multidir_temp[$object->entity]);
321
-
322
-
323
-				// If CUSTOMER contact defined on proposal, we use it
324
-				$usecontact=false;
325
-				$arrayidcontact=$object->getIdContact('external','CUSTOMER');
326
-				if (count($arrayidcontact) > 0)
327
-				{
328
-					$usecontact=true;
329
-					$result=$object->fetch_contact($arrayidcontact[0]);
330
-				}
331
-
332
-				// Recipient name
333
-				$contactobject=null;
334
-				if (! empty($usecontact))
335
-				{
336
-					// On peut utiliser le nom de la societe du contact
337
-					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
338
-					else {
339
-                        			$socobject = $object->thirdparty;
340
-                        			// if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use
341
-                        			$contactobject = $object->contact;
342
-                    			}
343
-				}
344
-				else
345
-				{
346
-					$socobject=$object->thirdparty;
347
-				}
348
-				// Make substitution
349
-				$substitutionarray=array(
350
-				'__FROM_NAME__' => $this->emetteur->name,
351
-				'__FROM_EMAIL__' => $this->emetteur->email,
352
-				'__TOTAL_TTC__' => $object->total_ttc,
353
-				'__TOTAL_HT__' => $object->total_ht,
354
-				'__TOTAL_VAT__' => $object->total_vat
355
-				);
356
-				complete_substitutions_array($substitutionarray, $langs, $object);
357
-				// Call the ODTSubstitution hook
358
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
359
-				$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
360
-
361
-				// Line of free text
362
-				$newfreetext='';
363
-				$paramfreetext='PROPOSAL_FREE_TEXT';
364
-				if (! empty($conf->global->$paramfreetext))
365
-				{
366
-					$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
367
-				}
368
-
369
-				// Open and load template
370
-				require_once ODTPHP_PATH.'odf.php';
371
-				try {
372
-					$odfHandler = new odf(
373
-						$srctemplatepath,
374
-						array(
375
-						'PATH_TO_TMP'	  => $conf->propal->multidir_temp[$object->entity],
376
-						'ZIP_PROXY'		  => 'PclZipProxy',	// PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
377
-						'DELIMITER_LEFT'  => '{',
378
-						'DELIMITER_RIGHT' => '}'
379
-						)
380
-					);
381
-				}
382
-				catch(Exception $e)
383
-				{
384
-					$this->error=$e->getMessage();
385
-					dol_syslog($e->getMessage(), LOG_INFO);
386
-					return -1;
387
-				}
388
-				// After construction $odfHandler->contentXml contains content and
389
-				// [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
390
-				// [!-- BEGIN lines --]*[!-- END lines --]
391
-				//print html_entity_decode($odfHandler->__toString());
392
-				//print exit;
393
-
394
-				$object->fetch_optionals();
395
-
396
-				// Make substitutions into odt of freetext
397
-				try {
398
-					$odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
399
-				}
400
-				catch (OdfException $e)
401
-				{
402
-					dol_syslog($e->getMessage(), LOG_INFO);
403
-				}
404
-
405
-				// Define substitution array
406
-				$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
407
-				$array_object_from_properties=$this->get_substitutionarray_each_var_object($object, $outputlangs);
408
-				$array_objet=$this->get_substitutionarray_object($object,$outputlangs);
409
-				$array_user=$this->get_substitutionarray_user($user,$outputlangs);
410
-				$array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
411
-				$array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
412
-				$array_other=$this->get_substitutionarray_other($outputlangs);
413
-				// retrieve contact information for use in object as contact_xxx tags
414
-				$array_thirdparty_contact = array();
415
-				if ($usecontact && is_object($contactobject)) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
416
-
417
-				$tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other,$array_thirdparty_contact);
418
-				complete_substitutions_array($tmparray, $outputlangs, $object);
419
-
420
-				// Call the ODTSubstitution hook
421
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
422
-				$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
423
-
424
-				foreach($tmparray as $key=>$value)
425
-				{
426
-					try {
427
-						if (preg_match('/logo$/',$key)) // Image
428
-						{
429
-							if (file_exists($value)) $odfHandler->setImage($key, $value);
430
-							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
431
-						}
432
-						else    // Text
433
-						{
434
-							$odfHandler->setVars($key, $value, true, 'UTF-8');
435
-						}
436
-					}
437
-					catch(OdfException $e)
438
-					{
239
+        global $user,$langs,$conf,$mysoc,$hookmanager;
240
+
241
+        if (empty($srctemplatepath))
242
+        {
243
+            dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
244
+            return -1;
245
+        }
246
+
247
+        // Add odtgeneration hook
248
+        if (! is_object($hookmanager))
249
+        {
250
+            include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
251
+            $hookmanager=new HookManager($this->db);
252
+        }
253
+        $hookmanager->initHooks(array('odtgeneration'));
254
+        global $action;
255
+
256
+        if (! is_object($outputlangs)) $outputlangs=$langs;
257
+        $sav_charset_output=$outputlangs->charset_output;
258
+        $outputlangs->charset_output='UTF-8';
259
+
260
+        // Load translation files required by the page
261
+        $outputlangs->loadLangs(array("main", "dict", "companies", "bills"));
262
+
263
+        if ($conf->propal->multidir_output[$conf->entity])
264
+        {
265
+            // If $object is id instead of object
266
+            if (! is_object($object))
267
+            {
268
+                $id = $object;
269
+                $object = new Propal($this->db);
270
+                $result=$object->fetch($id);
271
+                if ($result < 0)
272
+                {
273
+                    dol_print_error($this->db,$object->error);
274
+                    return -1;
275
+                }
276
+            }
277
+
278
+            $dir = $conf->propal->multidir_output[$object->entity];
279
+            $objectref = dol_sanitizeFileName($object->ref);
280
+            if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
281
+            $file = $dir . "/" . $objectref . ".odt";
282
+
283
+            if (! file_exists($dir))
284
+            {
285
+                if (dol_mkdir($dir) < 0)
286
+                {
287
+                    $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
288
+                    return -1;
289
+                }
290
+            }
291
+
292
+            if (file_exists($dir))
293
+            {
294
+                //print "srctemplatepath=".$srctemplatepath;	// Src filename
295
+                $newfile=basename($srctemplatepath);
296
+                $newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile);
297
+                $newfiletmp=preg_replace('/template_/i','',$newfiletmp);
298
+                $newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
299
+
300
+                $newfiletmp=$objectref.'_'.$newfiletmp;
301
+
302
+                // Get extension (ods or odt)
303
+                $newfileformat=substr($newfile, strrpos($newfile, '.')+1);
304
+                if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
305
+                {
306
+                    $format=$conf->global->MAIN_DOC_USE_TIMING;
307
+                    if ($format == '1') $format='%Y%m%d%H%M%S';
308
+                    $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
309
+                }
310
+                else
311
+                {
312
+                    $filename=$newfiletmp.'.'.$newfileformat;
313
+                }
314
+                $file=$dir.'/'.$filename;
315
+                //print "newdir=".$dir;
316
+                //print "newfile=".$newfile;
317
+                //print "file=".$file;
318
+                //print "conf->propal->dir_temp=".$conf->propal->dir_temp;
319
+
320
+                dol_mkdir($conf->propal->multidir_temp[$object->entity]);
321
+
322
+
323
+                // If CUSTOMER contact defined on proposal, we use it
324
+                $usecontact=false;
325
+                $arrayidcontact=$object->getIdContact('external','CUSTOMER');
326
+                if (count($arrayidcontact) > 0)
327
+                {
328
+                    $usecontact=true;
329
+                    $result=$object->fetch_contact($arrayidcontact[0]);
330
+                }
331
+
332
+                // Recipient name
333
+                $contactobject=null;
334
+                if (! empty($usecontact))
335
+                {
336
+                    // On peut utiliser le nom de la societe du contact
337
+                    if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
338
+                    else {
339
+                                    $socobject = $object->thirdparty;
340
+                                    // if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use
341
+                                    $contactobject = $object->contact;
342
+                                }
343
+                }
344
+                else
345
+                {
346
+                    $socobject=$object->thirdparty;
347
+                }
348
+                // Make substitution
349
+                $substitutionarray=array(
350
+                '__FROM_NAME__' => $this->emetteur->name,
351
+                '__FROM_EMAIL__' => $this->emetteur->email,
352
+                '__TOTAL_TTC__' => $object->total_ttc,
353
+                '__TOTAL_HT__' => $object->total_ht,
354
+                '__TOTAL_VAT__' => $object->total_vat
355
+                );
356
+                complete_substitutions_array($substitutionarray, $langs, $object);
357
+                // Call the ODTSubstitution hook
358
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
359
+                $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
360
+
361
+                // Line of free text
362
+                $newfreetext='';
363
+                $paramfreetext='PROPOSAL_FREE_TEXT';
364
+                if (! empty($conf->global->$paramfreetext))
365
+                {
366
+                    $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
367
+                }
368
+
369
+                // Open and load template
370
+                require_once ODTPHP_PATH.'odf.php';
371
+                try {
372
+                    $odfHandler = new odf(
373
+                        $srctemplatepath,
374
+                        array(
375
+                        'PATH_TO_TMP'	  => $conf->propal->multidir_temp[$object->entity],
376
+                        'ZIP_PROXY'		  => 'PclZipProxy',	// PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
377
+                        'DELIMITER_LEFT'  => '{',
378
+                        'DELIMITER_RIGHT' => '}'
379
+                        )
380
+                    );
381
+                }
382
+                catch(Exception $e)
383
+                {
384
+                    $this->error=$e->getMessage();
385
+                    dol_syslog($e->getMessage(), LOG_INFO);
386
+                    return -1;
387
+                }
388
+                // After construction $odfHandler->contentXml contains content and
389
+                // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
390
+                // [!-- BEGIN lines --]*[!-- END lines --]
391
+                //print html_entity_decode($odfHandler->__toString());
392
+                //print exit;
393
+
394
+                $object->fetch_optionals();
395
+
396
+                // Make substitutions into odt of freetext
397
+                try {
398
+                    $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
399
+                }
400
+                catch (OdfException $e)
401
+                {
402
+                    dol_syslog($e->getMessage(), LOG_INFO);
403
+                }
404
+
405
+                // Define substitution array
406
+                $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
407
+                $array_object_from_properties=$this->get_substitutionarray_each_var_object($object, $outputlangs);
408
+                $array_objet=$this->get_substitutionarray_object($object,$outputlangs);
409
+                $array_user=$this->get_substitutionarray_user($user,$outputlangs);
410
+                $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
411
+                $array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
412
+                $array_other=$this->get_substitutionarray_other($outputlangs);
413
+                // retrieve contact information for use in object as contact_xxx tags
414
+                $array_thirdparty_contact = array();
415
+                if ($usecontact && is_object($contactobject)) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
416
+
417
+                $tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other,$array_thirdparty_contact);
418
+                complete_substitutions_array($tmparray, $outputlangs, $object);
419
+
420
+                // Call the ODTSubstitution hook
421
+                $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
422
+                $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
423
+
424
+                foreach($tmparray as $key=>$value)
425
+                {
426
+                    try {
427
+                        if (preg_match('/logo$/',$key)) // Image
428
+                        {
429
+                            if (file_exists($value)) $odfHandler->setImage($key, $value);
430
+                            else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
431
+                        }
432
+                        else    // Text
433
+                        {
434
+                            $odfHandler->setVars($key, $value, true, 'UTF-8');
435
+                        }
436
+                    }
437
+                    catch(OdfException $e)
438
+                    {
439
+                        dol_syslog($e->getMessage(), LOG_INFO);
440
+                    }
441
+                }
442
+                // Replace tags of lines
443
+                try
444
+                {
445
+                    $foundtagforlines = 1;
446
+                    try {
447
+                        $listlines = $odfHandler->setSegment('lines');
448
+                    }
449
+                    catch(OdfException $e)
450
+                    {
451
+                        // We may arrive here if tags for lines not present into template
452
+                        $foundtagforlines = 0;
439 453
                         dol_syslog($e->getMessage(), LOG_INFO);
440
-					}
441
-				}
442
-				// Replace tags of lines
443
-				try
444
-				{
445
-					$foundtagforlines = 1;
446
-					try {
447
-						$listlines = $odfHandler->setSegment('lines');
448
-					}
449
-					catch(OdfException $e)
450
-					{
451
-						// We may arrive here if tags for lines not present into template
452
-						$foundtagforlines = 0;
453
-						dol_syslog($e->getMessage(), LOG_INFO);
454
-					}
455
-					if ($foundtagforlines)
456
-					{
457
-						foreach ($object->lines as $line)
458
-						{
459
-							$tmparray=$this->get_substitutionarray_lines($line,$outputlangs);
460
-							complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
461
-							// Call the ODTSubstitutionLine hook
462
-							$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line);
463
-							$reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
464
-							foreach($tmparray as $key => $val)
465
-							{
466
-								try
467
-								{
468
-									$listlines->setVars($key, $val, true, 'UTF-8');
469
-								}
470
-								catch(OdfException $e)
471
-								{
472
-									dol_syslog($e->getMessage(), LOG_INFO);
473
-								}
474
-								catch(SegmentException $e)
475
-								{
476
-									dol_syslog($e->getMessage(), LOG_INFO);
477
-								}
478
-							}
479
-							$listlines->merge();
480
-						}
481
-						$odfHandler->mergeSegment($listlines);
482
-					}
483
-				}
484
-				catch(OdfException $e)
485
-				{
486
-					$this->error=$e->getMessage();
487
-					dol_syslog($this->error, LOG_WARNING);
488
-					return -1;
489
-				}
490
-
491
-				// Replace labels translated
492
-				$tmparray=$outputlangs->get_translations_for_substitutions();
493
-				foreach($tmparray as $key=>$value)
494
-				{
495
-					try {
496
-						$odfHandler->setVars($key, $value, true, 'UTF-8');
497
-					}
498
-					catch (OdfException $e)
499
-					{
454
+                    }
455
+                    if ($foundtagforlines)
456
+                    {
457
+                        foreach ($object->lines as $line)
458
+                        {
459
+                            $tmparray=$this->get_substitutionarray_lines($line,$outputlangs);
460
+                            complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
461
+                            // Call the ODTSubstitutionLine hook
462
+                            $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line);
463
+                            $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
464
+                            foreach($tmparray as $key => $val)
465
+                            {
466
+                                try
467
+                                {
468
+                                    $listlines->setVars($key, $val, true, 'UTF-8');
469
+                                }
470
+                                catch(OdfException $e)
471
+                                {
472
+                                    dol_syslog($e->getMessage(), LOG_INFO);
473
+                                }
474
+                                catch(SegmentException $e)
475
+                                {
476
+                                    dol_syslog($e->getMessage(), LOG_INFO);
477
+                                }
478
+                            }
479
+                            $listlines->merge();
480
+                        }
481
+                        $odfHandler->mergeSegment($listlines);
482
+                    }
483
+                }
484
+                catch(OdfException $e)
485
+                {
486
+                    $this->error=$e->getMessage();
487
+                    dol_syslog($this->error, LOG_WARNING);
488
+                    return -1;
489
+                }
490
+
491
+                // Replace labels translated
492
+                $tmparray=$outputlangs->get_translations_for_substitutions();
493
+                foreach($tmparray as $key=>$value)
494
+                {
495
+                    try {
496
+                        $odfHandler->setVars($key, $value, true, 'UTF-8');
497
+                    }
498
+                    catch (OdfException $e)
499
+                    {
500 500
                         dol_syslog($e->getMessage(), LOG_INFO);
501
-					}
502
-				}
503
-
504
-				// Call the beforeODTSave hook
505
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
506
-				$reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
507
-
508
-				// Write new file
509
-				if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
510
-					try {
511
-						$odfHandler->exportAsAttachedPDF($file);
512
-					} catch (Exception $e) {
513
-						$this->error=$e->getMessage();
501
+                    }
502
+                }
503
+
504
+                // Call the beforeODTSave hook
505
+                $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
506
+                $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
507
+
508
+                // Write new file
509
+                if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
510
+                    try {
511
+                        $odfHandler->exportAsAttachedPDF($file);
512
+                    } catch (Exception $e) {
513
+                        $this->error=$e->getMessage();
514 514
                         dol_syslog($e->getMessage(), LOG_INFO);
515
-						return -1;
516
-					}
517
-				}
518
-				else {
519
-					try {
520
-					$odfHandler->saveToDisk($file);
521
-					} catch (Exception $e) {
522
-						$this->error=$e->getMessage();
515
+                        return -1;
516
+                    }
517
+                }
518
+                else {
519
+                    try {
520
+                    $odfHandler->saveToDisk($file);
521
+                    } catch (Exception $e) {
522
+                        $this->error=$e->getMessage();
523 523
                         dol_syslog($e->getMessage(), LOG_INFO);
524
-						return -1;
525
-					}
526
-				}
527
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
528
-				$reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
529
-
530
-				if (! empty($conf->global->MAIN_UMASK))
531
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
532
-
533
-				$odfHandler=null;	// Destroy object
534
-
535
-				$this->result = array('fullpath'=>$file);
536
-
537
-				return 1;   // Success
538
-			}
539
-			else
540
-			{
541
-				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
542
-				return -1;
543
-			}
544
-		}
545
-
546
-		return -1;
547
-	}
524
+                        return -1;
525
+                    }
526
+                }
527
+                $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
528
+                $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
529
+
530
+                if (! empty($conf->global->MAIN_UMASK))
531
+                    @chmod($file, octdec($conf->global->MAIN_UMASK));
532
+
533
+                $odfHandler=null;	// Destroy object
534
+
535
+                $this->result = array('fullpath'=>$file);
536
+
537
+                return 1;   // Success
538
+            }
539
+            else
540
+            {
541
+                $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
542
+                return -1;
543
+            }
544
+        }
545
+
546
+        return -1;
547
+    }
548 548
 }
Please login to merge, or discard this patch.
Spacing   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -67,37 +67,37 @@  discard block
 block discarded – undo
67 67
 		global $conf, $langs, $mysoc;
68 68
 
69 69
 		// Load translation files required by the page
70
-        $langs->loadLangs(array("main","companies"));
70
+        $langs->loadLangs(array("main", "companies"));
71 71
 
72 72
 		$this->db = $db;
73 73
 		$this->name = "ODT templates";
74 74
 		$this->description = $langs->trans("DocumentModelOdt");
75
-		$this->scandir = 'PROPALE_ADDON_PDF_ODT_PATH';	// Name of constant that is used to save list of directories to scan
75
+		$this->scandir = 'PROPALE_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan
76 76
 
77 77
 		// Dimension page pour format A4
78 78
 		$this->type = 'odt';
79 79
 		$this->page_largeur = 0;
80 80
 		$this->page_hauteur = 0;
81
-		$this->format = array($this->page_largeur,$this->page_hauteur);
82
-		$this->marge_gauche=0;
83
-		$this->marge_droite=0;
84
-		$this->marge_haute=0;
85
-		$this->marge_basse=0;
86
-
87
-		$this->option_logo = 1;                    // Affiche logo
88
-		$this->option_tva = 0;                     // Gere option tva PROPALE_TVAOPTION
89
-		$this->option_modereg = 0;                 // Affiche mode reglement
90
-		$this->option_condreg = 0;                 // Affiche conditions reglement
91
-		$this->option_codeproduitservice = 0;      // Affiche code produit-service
92
-		$this->option_multilang = 1;               // Dispo en plusieurs langues
93
-		$this->option_escompte = 0;                // Affiche si il y a eu escompte
94
-		$this->option_credit_note = 0;             // Support credit notes
95
-		$this->option_freetext = 1;				   // Support add of a personalised text
96
-		$this->option_draft_watermark = 0;		   // Support add of a watermark on drafts
81
+		$this->format = array($this->page_largeur, $this->page_hauteur);
82
+		$this->marge_gauche = 0;
83
+		$this->marge_droite = 0;
84
+		$this->marge_haute = 0;
85
+		$this->marge_basse = 0;
86
+
87
+		$this->option_logo = 1; // Affiche logo
88
+		$this->option_tva = 0; // Gere option tva PROPALE_TVAOPTION
89
+		$this->option_modereg = 0; // Affiche mode reglement
90
+		$this->option_condreg = 0; // Affiche conditions reglement
91
+		$this->option_codeproduitservice = 0; // Affiche code produit-service
92
+		$this->option_multilang = 1; // Dispo en plusieurs langues
93
+		$this->option_escompte = 0; // Affiche si il y a eu escompte
94
+		$this->option_credit_note = 0; // Support credit notes
95
+		$this->option_freetext = 1; // Support add of a personalised text
96
+		$this->option_draft_watermark = 0; // Support add of a watermark on drafts
97 97
 
98 98
 		// Recupere emetteur
99
-		$this->emetteur=$mysoc;
100
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
99
+		$this->emetteur = $mysoc;
100
+		if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
101 101
 	}
102 102
 
103 103
 
@@ -109,114 +109,114 @@  discard block
 block discarded – undo
109 109
 	 */
110 110
 	function info($langs)
111 111
 	{
112
-		global $conf,$langs;
112
+		global $conf, $langs;
113 113
 
114 114
 		// Load translation files required by the page
115
-        $langs->loadLangs(array("errors","companies"));
115
+        $langs->loadLangs(array("errors", "companies"));
116 116
 
117 117
 		$form = new Form($this->db);
118 118
 
119 119
 		$texte = $this->description.".<br>\n";
120
-		$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
121
-		$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
122
-		$texte.= '<input type="hidden" name="action" value="setModuleOptions">';
123
-		$texte.= '<input type="hidden" name="param1" value="PROPALE_ADDON_PDF_ODT_PATH">';
120
+		$texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
121
+		$texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
122
+		$texte .= '<input type="hidden" name="action" value="setModuleOptions">';
123
+		$texte .= '<input type="hidden" name="param1" value="PROPALE_ADDON_PDF_ODT_PATH">';
124 124
 		if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0)
125 125
 		{
126
-			$texte.= '<input type="hidden" name="param2" value="PROPALE_ADDON_PDF_ODT_DEFAULT">';
127
-			$texte.= '<input type="hidden" name="param3" value="PROPALE_ADDON_PDF_ODT_TOBILL">';
128
-			$texte.= '<input type="hidden" name="param4" value="PROPALE_ADDON_PDF_ODT_CLOSED">';
126
+			$texte .= '<input type="hidden" name="param2" value="PROPALE_ADDON_PDF_ODT_DEFAULT">';
127
+			$texte .= '<input type="hidden" name="param3" value="PROPALE_ADDON_PDF_ODT_TOBILL">';
128
+			$texte .= '<input type="hidden" name="param4" value="PROPALE_ADDON_PDF_ODT_CLOSED">';
129 129
 		}
130
-		$texte.= '<table class="nobordernopadding" width="100%">';
130
+		$texte .= '<table class="nobordernopadding" width="100%">';
131 131
 
132 132
 		// List of directories area
133
-		$texte.= '<tr><td>';
134
-		$texttitle=$langs->trans("ListOfDirectories");
135
-		$listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->PROPALE_ADDON_PDF_ODT_PATH)));
136
-		$listoffiles=array();
137
-		foreach($listofdir as $key=>$tmpdir)
133
+		$texte .= '<tr><td>';
134
+		$texttitle = $langs->trans("ListOfDirectories");
135
+		$listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->PROPALE_ADDON_PDF_ODT_PATH)));
136
+		$listoffiles = array();
137
+		foreach ($listofdir as $key=>$tmpdir)
138 138
 		{
139
-			$tmpdir=trim($tmpdir);
140
-			$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
141
-			if (! $tmpdir) {
139
+			$tmpdir = trim($tmpdir);
140
+			$tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
141
+			if (!$tmpdir) {
142 142
 				unset($listofdir[$key]); continue;
143 143
 			}
144
-			if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
144
+			if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0);
145 145
 			else
146 146
 			{
147
-				$tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
148
-				if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
147
+				$tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)');
148
+				if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles);
149 149
 			}
150 150
 		}
151
-		$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
151
+		$texthelp = $langs->trans("ListOfDirectoriesForModelGenODT");
152 152
 		// Add list of substitution keys
153
-		$texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
154
-		$texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation");    // This contains an url, we don't modify it
155
-
156
-		$texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
157
-		$texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
158
-		$texte.= '<textarea class="flat" cols="60" name="value1">';
159
-		$texte.=$conf->global->PROPALE_ADDON_PDF_ODT_PATH;
160
-		$texte.= '</textarea>';
161
-		$texte.= '</div><div style="display: inline-block; vertical-align: middle;">';
162
-		$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
163
-		$texte.= '<br></div></div>';
153
+		$texthelp .= '<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
154
+		$texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it
155
+
156
+		$texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1);
157
+		$texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
158
+		$texte .= '<textarea class="flat" cols="60" name="value1">';
159
+		$texte .= $conf->global->PROPALE_ADDON_PDF_ODT_PATH;
160
+		$texte .= '</textarea>';
161
+		$texte .= '</div><div style="display: inline-block; vertical-align: middle;">';
162
+		$texte .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
163
+		$texte .= '<br></div></div>';
164 164
 
165 165
 		// Scan directories
166
-		$nbofiles=count($listoffiles);
167
-		if (! empty($conf->global->PROPALE_ADDON_PDF_ODT_PATH))
166
+		$nbofiles = count($listoffiles);
167
+		if (!empty($conf->global->PROPALE_ADDON_PDF_ODT_PATH))
168 168
 		{
169
-			$texte.=$langs->trans("NumberOfModelFilesFound").': <b>';
169
+			$texte .= $langs->trans("NumberOfModelFilesFound").': <b>';
170 170
 			//$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':'';
171
-			$texte.=count($listoffiles);
171
+			$texte .= count($listoffiles);
172 172
 			//$texte.=$nbofiles?'</a>':'';
173
-			$texte.='</b>';
173
+			$texte .= '</b>';
174 174
 		}
175 175
 
176 176
 		if ($nbofiles)
177 177
 		{
178
-   			$texte.='<div id="div_'.get_class($this).'" class="hidden">';
179
-   			foreach($listoffiles as $file)
178
+   			$texte .= '<div id="div_'.get_class($this).'" class="hidden">';
179
+   			foreach ($listoffiles as $file)
180 180
    			{
181
-                $texte.=$file['name'].'<br>';
181
+                $texte .= $file['name'].'<br>';
182 182
    			}
183
-   			$texte.='<div id="div_'.get_class($this).'">';
183
+   			$texte .= '<div id="div_'.get_class($this).'">';
184 184
 
185 185
 			if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0)
186 186
 			{
187 187
 				// Model for creation
188
-				$liste=ModelePDFPropales::liste_modeles($this->db);
189
-				$texte.= '<table width="50%;">';
190
-				$texte.= '<tr>';
191
-				$texte.= '<td width="60%;">'.$langs->trans("DefaultModelPropalCreate").'</td>';
192
-				$texte.= '<td colspan="">';
193
-				$texte.= $form->selectarray('value2',$liste,$conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT);
194
-				$texte.= "</td></tr>";
195
-
196
-				$texte.= '<tr>';
197
-				$texte.= '<td width="60%;">'.$langs->trans("DefaultModelPropalToBill").'</td>';
198
-				$texte.= '<td colspan="">';
199
-				$texte.= $form->selectarray('value3',$liste,$conf->global->PROPALE_ADDON_PDF_ODT_TOBILL);
200
-				$texte.= "</td></tr>";
201
-				$texte.= '<tr>';
202
-
203
-				$texte.= '<td width="60%;">'.$langs->trans("DefaultModelPropalClosed").'</td>';
204
-				$texte.= '<td colspan="">';
205
-				$texte.= $form->selectarray('value4',$liste,$conf->global->PROPALE_ADDON_PDF_ODT_CLOSED);
206
-				$texte.= "</td></tr>";
207
-				$texte.= '</table>';
188
+				$liste = ModelePDFPropales::liste_modeles($this->db);
189
+				$texte .= '<table width="50%;">';
190
+				$texte .= '<tr>';
191
+				$texte .= '<td width="60%;">'.$langs->trans("DefaultModelPropalCreate").'</td>';
192
+				$texte .= '<td colspan="">';
193
+				$texte .= $form->selectarray('value2', $liste, $conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT);
194
+				$texte .= "</td></tr>";
195
+
196
+				$texte .= '<tr>';
197
+				$texte .= '<td width="60%;">'.$langs->trans("DefaultModelPropalToBill").'</td>';
198
+				$texte .= '<td colspan="">';
199
+				$texte .= $form->selectarray('value3', $liste, $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL);
200
+				$texte .= "</td></tr>";
201
+				$texte .= '<tr>';
202
+
203
+				$texte .= '<td width="60%;">'.$langs->trans("DefaultModelPropalClosed").'</td>';
204
+				$texte .= '<td colspan="">';
205
+				$texte .= $form->selectarray('value4', $liste, $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED);
206
+				$texte .= "</td></tr>";
207
+				$texte .= '</table>';
208 208
 			}
209 209
 		}
210 210
 
211
-		$texte.= '</td>';
211
+		$texte .= '</td>';
212 212
 
213
-		$texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">';
214
-		$texte.= $langs->trans("ExampleOfDirectoriesForModelGen");
215
-		$texte.= '</td>';
216
-		$texte.= '</tr>';
213
+		$texte .= '<td valign="top" rowspan="2" class="hideonsmartphone">';
214
+		$texte .= $langs->trans("ExampleOfDirectoriesForModelGen");
215
+		$texte .= '</td>';
216
+		$texte .= '</tr>';
217 217
 
218
-		$texte.= '</table>';
219
-		$texte.= '</form>';
218
+		$texte .= '</table>';
219
+		$texte .= '</form>';
220 220
 
221 221
 		return $texte;
222 222
 	}
@@ -233,10 +233,10 @@  discard block
 block discarded – undo
233 233
 	 *  @param		int			$hideref			Do not show ref
234 234
 	 *	@return		int         					1 if OK, <=0 if KO
235 235
 	 */
236
-	function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
236
+	function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
237 237
 	{
238 238
         // phpcs:enable
239
-		global $user,$langs,$conf,$mysoc,$hookmanager;
239
+		global $user, $langs, $conf, $mysoc, $hookmanager;
240 240
 
241 241
 		if (empty($srctemplatepath))
242 242
 		{
@@ -245,17 +245,17 @@  discard block
 block discarded – undo
245 245
 		}
246 246
 
247 247
 		// Add odtgeneration hook
248
-		if (! is_object($hookmanager))
248
+		if (!is_object($hookmanager))
249 249
 		{
250 250
 			include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
251
-			$hookmanager=new HookManager($this->db);
251
+			$hookmanager = new HookManager($this->db);
252 252
 		}
253 253
 		$hookmanager->initHooks(array('odtgeneration'));
254 254
 		global $action;
255 255
 
256
-		if (! is_object($outputlangs)) $outputlangs=$langs;
257
-		$sav_charset_output=$outputlangs->charset_output;
258
-		$outputlangs->charset_output='UTF-8';
256
+		if (!is_object($outputlangs)) $outputlangs = $langs;
257
+		$sav_charset_output = $outputlangs->charset_output;
258
+		$outputlangs->charset_output = 'UTF-8';
259 259
 
260 260
 		// Load translation files required by the page
261 261
 		$outputlangs->loadLangs(array("main", "dict", "companies", "bills"));
@@ -263,28 +263,28 @@  discard block
 block discarded – undo
263 263
 		if ($conf->propal->multidir_output[$conf->entity])
264 264
 		{
265 265
 			// If $object is id instead of object
266
-			if (! is_object($object))
266
+			if (!is_object($object))
267 267
 			{
268 268
 				$id = $object;
269 269
 				$object = new Propal($this->db);
270
-				$result=$object->fetch($id);
270
+				$result = $object->fetch($id);
271 271
 				if ($result < 0)
272 272
 				{
273
-					dol_print_error($this->db,$object->error);
273
+					dol_print_error($this->db, $object->error);
274 274
 					return -1;
275 275
 				}
276 276
 			}
277 277
 
278 278
 			$dir = $conf->propal->multidir_output[$object->entity];
279 279
 			$objectref = dol_sanitizeFileName($object->ref);
280
-			if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
281
-			$file = $dir . "/" . $objectref . ".odt";
280
+			if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref;
281
+			$file = $dir."/".$objectref.".odt";
282 282
 
283
-			if (! file_exists($dir))
283
+			if (!file_exists($dir))
284 284
 			{
285 285
 				if (dol_mkdir($dir) < 0)
286 286
 				{
287
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
287
+					$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
288 288
 					return -1;
289 289
 				}
290 290
 			}
@@ -292,26 +292,26 @@  discard block
 block discarded – undo
292 292
 			if (file_exists($dir))
293 293
 			{
294 294
 				//print "srctemplatepath=".$srctemplatepath;	// Src filename
295
-				$newfile=basename($srctemplatepath);
296
-				$newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile);
297
-				$newfiletmp=preg_replace('/template_/i','',$newfiletmp);
298
-				$newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
295
+				$newfile = basename($srctemplatepath);
296
+				$newfiletmp = preg_replace('/\.od(t|s)/i', '', $newfile);
297
+				$newfiletmp = preg_replace('/template_/i', '', $newfiletmp);
298
+				$newfiletmp = preg_replace('/modele_/i', '', $newfiletmp);
299 299
 
300
-				$newfiletmp=$objectref.'_'.$newfiletmp;
300
+				$newfiletmp = $objectref.'_'.$newfiletmp;
301 301
 
302 302
 				// Get extension (ods or odt)
303
-				$newfileformat=substr($newfile, strrpos($newfile, '.')+1);
304
-				if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
303
+				$newfileformat = substr($newfile, strrpos($newfile, '.') + 1);
304
+				if (!empty($conf->global->MAIN_DOC_USE_TIMING))
305 305
 				{
306
-				    $format=$conf->global->MAIN_DOC_USE_TIMING;
307
-				    if ($format == '1') $format='%Y%m%d%H%M%S';
308
-					$filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
306
+				    $format = $conf->global->MAIN_DOC_USE_TIMING;
307
+				    if ($format == '1') $format = '%Y%m%d%H%M%S';
308
+					$filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat;
309 309
 				}
310 310
 				else
311 311
 				{
312
-					$filename=$newfiletmp.'.'.$newfileformat;
312
+					$filename = $newfiletmp.'.'.$newfileformat;
313 313
 				}
314
-				$file=$dir.'/'.$filename;
314
+				$file = $dir.'/'.$filename;
315 315
 				//print "newdir=".$dir;
316 316
 				//print "newfile=".$newfile;
317 317
 				//print "file=".$file;
@@ -321,20 +321,20 @@  discard block
 block discarded – undo
321 321
 
322 322
 
323 323
 				// If CUSTOMER contact defined on proposal, we use it
324
-				$usecontact=false;
325
-				$arrayidcontact=$object->getIdContact('external','CUSTOMER');
324
+				$usecontact = false;
325
+				$arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
326 326
 				if (count($arrayidcontact) > 0)
327 327
 				{
328
-					$usecontact=true;
329
-					$result=$object->fetch_contact($arrayidcontact[0]);
328
+					$usecontact = true;
329
+					$result = $object->fetch_contact($arrayidcontact[0]);
330 330
 				}
331 331
 
332 332
 				// Recipient name
333
-				$contactobject=null;
334
-				if (! empty($usecontact))
333
+				$contactobject = null;
334
+				if (!empty($usecontact))
335 335
 				{
336 336
 					// On peut utiliser le nom de la societe du contact
337
-					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
337
+					if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
338 338
 					else {
339 339
                         			$socobject = $object->thirdparty;
340 340
                         			// if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use
@@ -343,10 +343,10 @@  discard block
 block discarded – undo
343 343
 				}
344 344
 				else
345 345
 				{
346
-					$socobject=$object->thirdparty;
346
+					$socobject = $object->thirdparty;
347 347
 				}
348 348
 				// Make substitution
349
-				$substitutionarray=array(
349
+				$substitutionarray = array(
350 350
 				'__FROM_NAME__' => $this->emetteur->name,
351 351
 				'__FROM_EMAIL__' => $this->emetteur->email,
352 352
 				'__TOTAL_TTC__' => $object->total_ttc,
@@ -355,15 +355,15 @@  discard block
 block discarded – undo
355 355
 				);
356 356
 				complete_substitutions_array($substitutionarray, $langs, $object);
357 357
 				// Call the ODTSubstitution hook
358
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
359
-				$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
358
+				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$substitutionarray);
359
+				$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
360 360
 
361 361
 				// Line of free text
362
-				$newfreetext='';
363
-				$paramfreetext='PROPOSAL_FREE_TEXT';
364
-				if (! empty($conf->global->$paramfreetext))
362
+				$newfreetext = '';
363
+				$paramfreetext = 'PROPOSAL_FREE_TEXT';
364
+				if (!empty($conf->global->$paramfreetext))
365 365
 				{
366
-					$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
366
+					$newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray);
367 367
 				}
368 368
 
369 369
 				// Open and load template
@@ -373,15 +373,15 @@  discard block
 block discarded – undo
373 373
 						$srctemplatepath,
374 374
 						array(
375 375
 						'PATH_TO_TMP'	  => $conf->propal->multidir_temp[$object->entity],
376
-						'ZIP_PROXY'		  => 'PclZipProxy',	// PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
376
+						'ZIP_PROXY'		  => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
377 377
 						'DELIMITER_LEFT'  => '{',
378 378
 						'DELIMITER_RIGHT' => '}'
379 379
 						)
380 380
 					);
381 381
 				}
382
-				catch(Exception $e)
382
+				catch (Exception $e)
383 383
 				{
384
-					$this->error=$e->getMessage();
384
+					$this->error = $e->getMessage();
385 385
 					dol_syslog($e->getMessage(), LOG_INFO);
386 386
 					return -1;
387 387
 				}
@@ -404,27 +404,27 @@  discard block
 block discarded – undo
404 404
 
405 405
 				// Define substitution array
406 406
 				$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
407
-				$array_object_from_properties=$this->get_substitutionarray_each_var_object($object, $outputlangs);
408
-				$array_objet=$this->get_substitutionarray_object($object,$outputlangs);
409
-				$array_user=$this->get_substitutionarray_user($user,$outputlangs);
410
-				$array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
411
-				$array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
412
-				$array_other=$this->get_substitutionarray_other($outputlangs);
407
+				$array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs);
408
+				$array_objet = $this->get_substitutionarray_object($object, $outputlangs);
409
+				$array_user = $this->get_substitutionarray_user($user, $outputlangs);
410
+				$array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs);
411
+				$array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs);
412
+				$array_other = $this->get_substitutionarray_other($outputlangs);
413 413
 				// retrieve contact information for use in object as contact_xxx tags
414 414
 				$array_thirdparty_contact = array();
415
-				if ($usecontact && is_object($contactobject)) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
415
+				if ($usecontact && is_object($contactobject)) $array_thirdparty_contact = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact');
416 416
 
417
-				$tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other,$array_thirdparty_contact);
417
+				$tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
418 418
 				complete_substitutions_array($tmparray, $outputlangs, $object);
419 419
 
420 420
 				// Call the ODTSubstitution hook
421
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
422
-				$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
421
+				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
422
+				$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
423 423
 
424
-				foreach($tmparray as $key=>$value)
424
+				foreach ($tmparray as $key=>$value)
425 425
 				{
426 426
 					try {
427
-						if (preg_match('/logo$/',$key)) // Image
427
+						if (preg_match('/logo$/', $key)) // Image
428 428
 						{
429 429
 							if (file_exists($value)) $odfHandler->setImage($key, $value);
430 430
 							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 							$odfHandler->setVars($key, $value, true, 'UTF-8');
435 435
 						}
436 436
 					}
437
-					catch(OdfException $e)
437
+					catch (OdfException $e)
438 438
 					{
439 439
                         dol_syslog($e->getMessage(), LOG_INFO);
440 440
 					}
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 					try {
447 447
 						$listlines = $odfHandler->setSegment('lines');
448 448
 					}
449
-					catch(OdfException $e)
449
+					catch (OdfException $e)
450 450
 					{
451 451
 						// We may arrive here if tags for lines not present into template
452 452
 						$foundtagforlines = 0;
@@ -456,22 +456,22 @@  discard block
 block discarded – undo
456 456
 					{
457 457
 						foreach ($object->lines as $line)
458 458
 						{
459
-							$tmparray=$this->get_substitutionarray_lines($line,$outputlangs);
459
+							$tmparray = $this->get_substitutionarray_lines($line, $outputlangs);
460 460
 							complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
461 461
 							// Call the ODTSubstitutionLine hook
462
-							$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line);
463
-							$reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
464
-							foreach($tmparray as $key => $val)
462
+							$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray, 'line'=>$line);
463
+							$reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
464
+							foreach ($tmparray as $key => $val)
465 465
 							{
466 466
 								try
467 467
 								{
468 468
 									$listlines->setVars($key, $val, true, 'UTF-8');
469 469
 								}
470
-								catch(OdfException $e)
470
+								catch (OdfException $e)
471 471
 								{
472 472
 									dol_syslog($e->getMessage(), LOG_INFO);
473 473
 								}
474
-								catch(SegmentException $e)
474
+								catch (SegmentException $e)
475 475
 								{
476 476
 									dol_syslog($e->getMessage(), LOG_INFO);
477 477
 								}
@@ -481,16 +481,16 @@  discard block
 block discarded – undo
481 481
 						$odfHandler->mergeSegment($listlines);
482 482
 					}
483 483
 				}
484
-				catch(OdfException $e)
484
+				catch (OdfException $e)
485 485
 				{
486
-					$this->error=$e->getMessage();
486
+					$this->error = $e->getMessage();
487 487
 					dol_syslog($this->error, LOG_WARNING);
488 488
 					return -1;
489 489
 				}
490 490
 
491 491
 				// Replace labels translated
492
-				$tmparray=$outputlangs->get_translations_for_substitutions();
493
-				foreach($tmparray as $key=>$value)
492
+				$tmparray = $outputlangs->get_translations_for_substitutions();
493
+				foreach ($tmparray as $key=>$value)
494 494
 				{
495 495
 					try {
496 496
 						$odfHandler->setVars($key, $value, true, 'UTF-8');
@@ -502,15 +502,15 @@  discard block
 block discarded – undo
502 502
 				}
503 503
 
504 504
 				// Call the beforeODTSave hook
505
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
506
-				$reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
505
+				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
506
+				$reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
507 507
 
508 508
 				// Write new file
509 509
 				if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
510 510
 					try {
511 511
 						$odfHandler->exportAsAttachedPDF($file);
512 512
 					} catch (Exception $e) {
513
-						$this->error=$e->getMessage();
513
+						$this->error = $e->getMessage();
514 514
                         dol_syslog($e->getMessage(), LOG_INFO);
515 515
 						return -1;
516 516
 					}
@@ -519,26 +519,26 @@  discard block
 block discarded – undo
519 519
 					try {
520 520
 					$odfHandler->saveToDisk($file);
521 521
 					} catch (Exception $e) {
522
-						$this->error=$e->getMessage();
522
+						$this->error = $e->getMessage();
523 523
                         dol_syslog($e->getMessage(), LOG_INFO);
524 524
 						return -1;
525 525
 					}
526 526
 				}
527
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
528
-				$reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
527
+				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
528
+				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
529 529
 
530
-				if (! empty($conf->global->MAIN_UMASK))
530
+				if (!empty($conf->global->MAIN_UMASK))
531 531
 					@chmod($file, octdec($conf->global->MAIN_UMASK));
532 532
 
533
-				$odfHandler=null;	// Destroy object
533
+				$odfHandler = null; // Destroy object
534 534
 
535 535
 				$this->result = array('fullpath'=>$file);
536 536
 
537
-				return 1;   // Success
537
+				return 1; // Success
538 538
 			}
539 539
 			else
540 540
 			{
541
-				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
541
+				$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
542 542
 				return -1;
543 543
 			}
544 544
 		}
Please login to merge, or discard this patch.
Braces   +46 added lines, -40 removed lines patch added patch discarded remove patch
@@ -97,7 +97,10 @@  discard block
 block discarded – undo
97 97
 
98 98
 		// Recupere emetteur
99 99
 		$this->emetteur=$mysoc;
100
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
100
+		if (! $this->emetteur->country_code) {
101
+		    $this->emetteur->country_code=substr($langs->defaultlang,-2);
102
+		}
103
+		// By default if not defined
101 104
 	}
102 105
 
103 106
 
@@ -141,11 +144,14 @@  discard block
 block discarded – undo
141 144
 			if (! $tmpdir) {
142 145
 				unset($listofdir[$key]); continue;
143 146
 			}
144
-			if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
145
-			else
147
+			if (! is_dir($tmpdir)) {
148
+			    $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
149
+			} else
146 150
 			{
147 151
 				$tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
148
-				if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
152
+				if (count($tmpfiles)) {
153
+				    $listoffiles=array_merge($listoffiles,$tmpfiles);
154
+				}
149 155
 			}
150 156
 		}
151 157
 		$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
@@ -253,7 +259,9 @@  discard block
 block discarded – undo
253 259
 		$hookmanager->initHooks(array('odtgeneration'));
254 260
 		global $action;
255 261
 
256
-		if (! is_object($outputlangs)) $outputlangs=$langs;
262
+		if (! is_object($outputlangs)) {
263
+		    $outputlangs=$langs;
264
+		}
257 265
 		$sav_charset_output=$outputlangs->charset_output;
258 266
 		$outputlangs->charset_output='UTF-8';
259 267
 
@@ -277,7 +285,9 @@  discard block
 block discarded – undo
277 285
 
278 286
 			$dir = $conf->propal->multidir_output[$object->entity];
279 287
 			$objectref = dol_sanitizeFileName($object->ref);
280
-			if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
288
+			if (! preg_match('/specimen/i',$objectref)) {
289
+			    $dir.= "/" . $objectref;
290
+			}
281 291
 			$file = $dir . "/" . $objectref . ".odt";
282 292
 
283 293
 			if (! file_exists($dir))
@@ -304,10 +314,11 @@  discard block
 block discarded – undo
304 314
 				if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
305 315
 				{
306 316
 				    $format=$conf->global->MAIN_DOC_USE_TIMING;
307
-				    if ($format == '1') $format='%Y%m%d%H%M%S';
317
+				    if ($format == '1') {
318
+				        $format='%Y%m%d%H%M%S';
319
+				    }
308 320
 					$filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
309
-				}
310
-				else
321
+				} else
311 322
 				{
312 323
 					$filename=$newfiletmp.'.'.$newfileformat;
313 324
 				}
@@ -334,14 +345,14 @@  discard block
 block discarded – undo
334 345
 				if (! empty($usecontact))
335 346
 				{
336 347
 					// On peut utiliser le nom de la societe du contact
337
-					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
338
-					else {
348
+					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
349
+					    $socobject = $object->contact;
350
+					} else {
339 351
                         			$socobject = $object->thirdparty;
340 352
                         			// if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use
341 353
                         			$contactobject = $object->contact;
342 354
                     			}
343
-				}
344
-				else
355
+				} else
345 356
 				{
346 357
 					$socobject=$object->thirdparty;
347 358
 				}
@@ -378,8 +389,7 @@  discard block
 block discarded – undo
378 389
 						'DELIMITER_RIGHT' => '}'
379 390
 						)
380 391
 					);
381
-				}
382
-				catch(Exception $e)
392
+				} catch(Exception $e)
383 393
 				{
384 394
 					$this->error=$e->getMessage();
385 395
 					dol_syslog($e->getMessage(), LOG_INFO);
@@ -396,8 +406,7 @@  discard block
 block discarded – undo
396 406
 				// Make substitutions into odt of freetext
397 407
 				try {
398 408
 					$odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
399
-				}
400
-				catch (OdfException $e)
409
+				} catch (OdfException $e)
401 410
 				{
402 411
 					dol_syslog($e->getMessage(), LOG_INFO);
403 412
 				}
@@ -412,7 +421,9 @@  discard block
 block discarded – undo
412 421
 				$array_other=$this->get_substitutionarray_other($outputlangs);
413 422
 				// retrieve contact information for use in object as contact_xxx tags
414 423
 				$array_thirdparty_contact = array();
415
-				if ($usecontact && is_object($contactobject)) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
424
+				if ($usecontact && is_object($contactobject)) {
425
+				    $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
426
+				}
416 427
 
417 428
 				$tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other,$array_thirdparty_contact);
418 429
 				complete_substitutions_array($tmparray, $outputlangs, $object);
@@ -424,17 +435,18 @@  discard block
 block discarded – undo
424 435
 				foreach($tmparray as $key=>$value)
425 436
 				{
426 437
 					try {
427
-						if (preg_match('/logo$/',$key)) // Image
438
+						if (preg_match('/logo$/',$key)) {
439
+						    // Image
428 440
 						{
429 441
 							if (file_exists($value)) $odfHandler->setImage($key, $value);
430
-							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
431
-						}
432
-						else    // Text
442
+						} else {
443
+							    $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
444
+							}
445
+						} else    // Text
433 446
 						{
434 447
 							$odfHandler->setVars($key, $value, true, 'UTF-8');
435 448
 						}
436
-					}
437
-					catch(OdfException $e)
449
+					} catch(OdfException $e)
438 450
 					{
439 451
                         dol_syslog($e->getMessage(), LOG_INFO);
440 452
 					}
@@ -445,8 +457,7 @@  discard block
 block discarded – undo
445 457
 					$foundtagforlines = 1;
446 458
 					try {
447 459
 						$listlines = $odfHandler->setSegment('lines');
448
-					}
449
-					catch(OdfException $e)
460
+					} catch(OdfException $e)
450 461
 					{
451 462
 						// We may arrive here if tags for lines not present into template
452 463
 						$foundtagforlines = 0;
@@ -466,12 +477,10 @@  discard block
 block discarded – undo
466 477
 								try
467 478
 								{
468 479
 									$listlines->setVars($key, $val, true, 'UTF-8');
469
-								}
470
-								catch(OdfException $e)
480
+								} catch(OdfException $e)
471 481
 								{
472 482
 									dol_syslog($e->getMessage(), LOG_INFO);
473
-								}
474
-								catch(SegmentException $e)
483
+								} catch(SegmentException $e)
475 484
 								{
476 485
 									dol_syslog($e->getMessage(), LOG_INFO);
477 486
 								}
@@ -480,8 +489,7 @@  discard block
 block discarded – undo
480 489
 						}
481 490
 						$odfHandler->mergeSegment($listlines);
482 491
 					}
483
-				}
484
-				catch(OdfException $e)
492
+				} catch(OdfException $e)
485 493
 				{
486 494
 					$this->error=$e->getMessage();
487 495
 					dol_syslog($this->error, LOG_WARNING);
@@ -494,8 +502,7 @@  discard block
 block discarded – undo
494 502
 				{
495 503
 					try {
496 504
 						$odfHandler->setVars($key, $value, true, 'UTF-8');
497
-					}
498
-					catch (OdfException $e)
505
+					} catch (OdfException $e)
499 506
 					{
500 507
                         dol_syslog($e->getMessage(), LOG_INFO);
501 508
 					}
@@ -514,8 +521,7 @@  discard block
 block discarded – undo
514 521
                         dol_syslog($e->getMessage(), LOG_INFO);
515 522
 						return -1;
516 523
 					}
517
-				}
518
-				else {
524
+				} else {
519 525
 					try {
520 526
 					$odfHandler->saveToDisk($file);
521 527
 					} catch (Exception $e) {
@@ -527,16 +533,16 @@  discard block
 block discarded – undo
527 533
 				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
528 534
 				$reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
529 535
 
530
-				if (! empty($conf->global->MAIN_UMASK))
531
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
536
+				if (! empty($conf->global->MAIN_UMASK)) {
537
+									@chmod($file, octdec($conf->global->MAIN_UMASK));
538
+				}
532 539
 
533 540
 				$odfHandler=null;	// Destroy object
534 541
 
535 542
 				$this->result = array('fullpath'=>$file);
536 543
 
537 544
 				return 1;   // Success
538
-			}
539
-			else
545
+			} else
540 546
 			{
541 547
 				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
542 548
 				return -1;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/propale/doc/pdf_azur.modules.php 3 patches
Indentation   +1446 added lines, -1446 removed lines patch added patch discarded remove patch
@@ -41,17 +41,17 @@  discard block
 block discarded – undo
41 41
  */
42 42
 class pdf_azur extends ModelePDFPropales
43 43
 {
44
-	/**
44
+    /**
45 45
      * @var DoliDb Database handler
46 46
      */
47 47
     public $db;
48 48
 
49
-	/**
49
+    /**
50 50
      * @var string model name
51 51
      */
52 52
     public $name;
53 53
 
54
-	/**
54
+    /**
55 55
      * @var string model description (short text)
56 56
      */
57 57
     public $description;
@@ -59,151 +59,151 @@  discard block
 block discarded – undo
59 59
     /**
60 60
      * @var string Save the name of generated file as the main doc when generating a doc with this template
61 61
      */
62
-	public $update_main_doc_field;
62
+    public $update_main_doc_field;
63 63
 
64
-	/**
64
+    /**
65 65
      * @var string document type
66 66
      */
67 67
     public $type;
68 68
 
69 69
     /**
70 70
      * @var array() Minimum version of PHP required by module.
71
-	 * e.g.: PHP ≥ 5.4 = array(5, 4)
71
+     * e.g.: PHP ≥ 5.4 = array(5, 4)
72 72
      */
73
-	public $phpmin = array(5, 4);
73
+    public $phpmin = array(5, 4);
74 74
 
75
-	/**
75
+    /**
76 76
      * Dolibarr version of the loaded document
77 77
      * @public string
78 78
      */
79
-	public $version = 'dolibarr';
79
+    public $version = 'dolibarr';
80 80
 
81
-	/**
81
+    /**
82 82
      * @var int page_largeur
83 83
      */
84 84
     public $page_largeur;
85 85
 
86
-	/**
86
+    /**
87 87
      * @var int page_hauteur
88 88
      */
89 89
     public $page_hauteur;
90 90
 
91
-	/**
91
+    /**
92 92
      * @var array format
93 93
      */
94 94
     public $format;
95 95
 
96
-	/**
96
+    /**
97 97
      * @var int marge_gauche
98 98
      */
99
-	public $marge_gauche;
99
+    public $marge_gauche;
100 100
 
101
-	/**
101
+    /**
102 102
      * @var int marge_droite
103 103
      */
104
-	public $marge_droite;
104
+    public $marge_droite;
105 105
 
106
-	/**
106
+    /**
107 107
      * @var int marge_haute
108 108
      */
109
-	public $marge_haute;
109
+    public $marge_haute;
110 110
 
111
-	/**
111
+    /**
112 112
      * @var int marge_basse
113 113
      */
114
-	public $marge_basse;
115
-
116
-	/**
117
-	 * Issuer
118
-	 * @var Company object that emits
119
-	 */
120
-	public $emetteur;
121
-
122
-
123
-	/**
124
-	 *	Constructor
125
-	 *
126
-	 *  @param		DoliDB		$db      Database handler
127
-	 */
128
-	function __construct($db)
129
-	{
130
-		global $conf,$langs,$mysoc;
131
-
132
-		// Translations
133
-		$langs->loadLangs(array("main", "bills"));
134
-
135
-		$this->db = $db;
136
-		$this->name = "azur";
137
-		$this->description = $langs->trans('DocModelAzurDescription');
138
-		$this->update_main_doc_field = 1;		// Save the name of generated file as the main doc when generating a doc with this template
139
-
140
-		// Dimension page
141
-		$this->type = 'pdf';
142
-		$formatarray=pdf_getFormat();
143
-		$this->page_largeur = $formatarray['width'];
144
-		$this->page_hauteur = $formatarray['height'];
145
-		$this->format = array($this->page_largeur,$this->page_hauteur);
146
-		$this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
147
-		$this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
148
-		$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
149
-		$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
150
-
151
-		$this->option_logo = 1;                    // Affiche logo
152
-		$this->option_tva = 1;                     // Gere option tva FACTURE_TVAOPTION
153
-		$this->option_modereg = 1;                 // Affiche mode reglement
154
-		$this->option_condreg = 1;                 // Affiche conditions reglement
155
-		$this->option_codeproduitservice = 1;      // Affiche code produit-service
156
-		$this->option_multilang = 1;               // Dispo en plusieurs langues
157
-		$this->option_escompte = 0;                // Affiche si il y a eu escompte
158
-		$this->option_credit_note = 0;             // Support credit notes
159
-		$this->option_freetext = 1;				   // Support add of a personalised text
160
-		$this->option_draft_watermark = 1;		   //Support add of a watermark on drafts
161
-
162
-		$this->franchise=!$mysoc->tva_assuj;
163
-
164
-		// Get source company
165
-		$this->emetteur=$mysoc;
166
-		if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
167
-
168
-		// Define position of columns
169
-		$this->posxdesc=$this->marge_gauche+1;
170
-		if($conf->global->PRODUCT_USE_UNITS)
171
-		{
172
-			$this->posxtva=101;
173
-			$this->posxup=118;
174
-			$this->posxqty=135;
175
-			$this->posxunit=151;
176
-		}
177
-		else
178
-		{
179
-			$this->posxtva=110;
180
-			$this->posxup=126;
181
-			$this->posxqty=145;
182
-		}
183
-		$this->posxdiscount=162;
184
-		$this->postotalht=174;
185
-		if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup;
186
-		$this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);	// width of images
187
-		if ($this->page_largeur < 210) // To work with US executive format
188
-		{
189
-			$this->posxpicture-=20;
190
-			$this->posxtva-=20;
191
-			$this->posxup-=20;
192
-			$this->posxqty-=20;
193
-			$this->posxunit-=20;
194
-			$this->posxdiscount-=20;
195
-			$this->postotalht-=20;
196
-		}
197
-
198
-		$this->tva=array();
199
-		$this->localtax1=array();
200
-		$this->localtax2=array();
201
-		$this->atleastoneratenotnull=0;
202
-		$this->atleastonediscount=0;
203
-	}
114
+    public $marge_basse;
115
+
116
+    /**
117
+     * Issuer
118
+     * @var Company object that emits
119
+     */
120
+    public $emetteur;
121
+
122
+
123
+    /**
124
+     *	Constructor
125
+     *
126
+     *  @param		DoliDB		$db      Database handler
127
+     */
128
+    function __construct($db)
129
+    {
130
+        global $conf,$langs,$mysoc;
131
+
132
+        // Translations
133
+        $langs->loadLangs(array("main", "bills"));
134
+
135
+        $this->db = $db;
136
+        $this->name = "azur";
137
+        $this->description = $langs->trans('DocModelAzurDescription');
138
+        $this->update_main_doc_field = 1;		// Save the name of generated file as the main doc when generating a doc with this template
139
+
140
+        // Dimension page
141
+        $this->type = 'pdf';
142
+        $formatarray=pdf_getFormat();
143
+        $this->page_largeur = $formatarray['width'];
144
+        $this->page_hauteur = $formatarray['height'];
145
+        $this->format = array($this->page_largeur,$this->page_hauteur);
146
+        $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
147
+        $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
148
+        $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
149
+        $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
150
+
151
+        $this->option_logo = 1;                    // Affiche logo
152
+        $this->option_tva = 1;                     // Gere option tva FACTURE_TVAOPTION
153
+        $this->option_modereg = 1;                 // Affiche mode reglement
154
+        $this->option_condreg = 1;                 // Affiche conditions reglement
155
+        $this->option_codeproduitservice = 1;      // Affiche code produit-service
156
+        $this->option_multilang = 1;               // Dispo en plusieurs langues
157
+        $this->option_escompte = 0;                // Affiche si il y a eu escompte
158
+        $this->option_credit_note = 0;             // Support credit notes
159
+        $this->option_freetext = 1;				   // Support add of a personalised text
160
+        $this->option_draft_watermark = 1;		   //Support add of a watermark on drafts
161
+
162
+        $this->franchise=!$mysoc->tva_assuj;
163
+
164
+        // Get source company
165
+        $this->emetteur=$mysoc;
166
+        if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
167
+
168
+        // Define position of columns
169
+        $this->posxdesc=$this->marge_gauche+1;
170
+        if($conf->global->PRODUCT_USE_UNITS)
171
+        {
172
+            $this->posxtva=101;
173
+            $this->posxup=118;
174
+            $this->posxqty=135;
175
+            $this->posxunit=151;
176
+        }
177
+        else
178
+        {
179
+            $this->posxtva=110;
180
+            $this->posxup=126;
181
+            $this->posxqty=145;
182
+        }
183
+        $this->posxdiscount=162;
184
+        $this->postotalht=174;
185
+        if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup;
186
+        $this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);	// width of images
187
+        if ($this->page_largeur < 210) // To work with US executive format
188
+        {
189
+            $this->posxpicture-=20;
190
+            $this->posxtva-=20;
191
+            $this->posxup-=20;
192
+            $this->posxqty-=20;
193
+            $this->posxunit-=20;
194
+            $this->posxdiscount-=20;
195
+            $this->postotalht-=20;
196
+        }
197
+
198
+        $this->tva=array();
199
+        $this->localtax1=array();
200
+        $this->localtax2=array();
201
+        $this->atleastoneratenotnull=0;
202
+        $this->atleastonediscount=0;
203
+    }
204 204
 
205 205
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
206
-	/**
206
+    /**
207 207
      *  Function to build pdf onto disk
208 208
      *
209 209
      *  @param		Object		$object				Object to generate
@@ -213,126 +213,126 @@  discard block
 block discarded – undo
213 213
      *  @param		int			$hidedesc			Do not show desc
214 214
      *  @param		int			$hideref			Do not show ref
215 215
      *  @return     int             				1=OK, 0=KO
216
-	 */
217
-	function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
218
-	{
216
+     */
217
+    function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
218
+    {
219 219
         // phpcs:enable
220
-		global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
220
+        global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
221 221
 
222
-		if (! is_object($outputlangs)) $outputlangs=$langs;
223
-		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
224
-		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
222
+        if (! is_object($outputlangs)) $outputlangs=$langs;
223
+        // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
224
+        if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
225 225
 
226
-		// Load traductions files requiredby by page
227
-		$outputlangs->loadLangs(array("main", "dict", "companies", "bills", "propal", "products"));
226
+        // Load traductions files requiredby by page
227
+        $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "propal", "products"));
228 228
 
229
-		$nblignes = count($object->lines);
229
+        $nblignes = count($object->lines);
230 230
 
231
-		// Loop on each lines to detect if there is at least one image to show
232
-		$realpatharray=array();
233
-		if (! empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE))
234
-		{
235
-			$objphoto = new Product($this->db);
231
+        // Loop on each lines to detect if there is at least one image to show
232
+        $realpatharray=array();
233
+        if (! empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE))
234
+        {
235
+            $objphoto = new Product($this->db);
236 236
 
237
-			for ($i = 0 ; $i < $nblignes ; $i++)
238
-			{
239
-				if (empty($object->lines[$i]->fk_product)) continue;
237
+            for ($i = 0 ; $i < $nblignes ; $i++)
238
+            {
239
+                if (empty($object->lines[$i]->fk_product)) continue;
240 240
 
241
-				$objphoto->fetch($object->lines[$i]->fk_product);
241
+                $objphoto->fetch($object->lines[$i]->fk_product);
242 242
                 //var_dump($objphoto->ref);exit;
243
-				if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
244
-				{
245
-					$pdir[0] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";
246
-					$pdir[1] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';
247
-				}
248
-				else
249
-				{
250
-					$pdir[0] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';				// default
251
-					$pdir[1] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";	// alternative
252
-				}
253
-
254
-				$arephoto = false;
255
-				foreach ($pdir as $midir)
256
-				{
257
-					if (! $arephoto)
258
-					{
259
-						$dir = $conf->product->dir_output.'/'.$midir;
260
-
261
-						foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
262
-						{
263
-							if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES))		// If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
264
-							{
265
-								if ($obj['photo_vignette'])
266
-								{
267
-									$filename= $obj['photo_vignette'];
268
-								}
269
-								else
270
-								{
271
-									$filename=$obj['photo'];
272
-								}
273
-							}
274
-							else
275
-							{
276
-								$filename=$obj['photo'];
277
-							}
278
-
279
-							$realpath = $dir.$filename;
280
-							$arephoto = true;
281
-						}
282
-					}
283
-				}
284
-
285
-				if ($realpath && $arephoto) $realpatharray[$i]=$realpath;
286
-			}
287
-		}
288
-
289
-		if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
290
-
291
-		if ($conf->propal->multidir_output[$conf->entity])
292
-		{
293
-			$object->fetch_thirdparty();
294
-
295
-			$deja_regle = 0;
243
+                if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
244
+                {
245
+                    $pdir[0] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";
246
+                    $pdir[1] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';
247
+                }
248
+                else
249
+                {
250
+                    $pdir[0] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';				// default
251
+                    $pdir[1] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";	// alternative
252
+                }
296 253
 
297
-			// Definition of $dir and $file
298
-			if ($object->specimen)
299
-			{
300
-				$dir = $conf->propal->multidir_output[$conf->entity];
301
-				$file = $dir . "/SPECIMEN.pdf";
302
-			}
303
-			else
304
-			{
305
-				$objectref = dol_sanitizeFileName($object->ref);
306
-				$dir = $conf->propal->multidir_output[$object->entity] . "/" . $objectref;
307
-				$file = $dir . "/" . $objectref . ".pdf";
308
-			}
254
+                $arephoto = false;
255
+                foreach ($pdir as $midir)
256
+                {
257
+                    if (! $arephoto)
258
+                    {
259
+                        $dir = $conf->product->dir_output.'/'.$midir;
260
+
261
+                        foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
262
+                        {
263
+                            if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES))		// If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
264
+                            {
265
+                                if ($obj['photo_vignette'])
266
+                                {
267
+                                    $filename= $obj['photo_vignette'];
268
+                                }
269
+                                else
270
+                                {
271
+                                    $filename=$obj['photo'];
272
+                                }
273
+                            }
274
+                            else
275
+                            {
276
+                                $filename=$obj['photo'];
277
+                            }
278
+
279
+                            $realpath = $dir.$filename;
280
+                            $arephoto = true;
281
+                        }
282
+                    }
283
+                }
309 284
 
310
-			if (! file_exists($dir))
311
-			{
312
-				if (dol_mkdir($dir) < 0)
313
-				{
314
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
315
-					return 0;
316
-				}
317
-			}
285
+                if ($realpath && $arephoto) $realpatharray[$i]=$realpath;
286
+            }
287
+        }
288
+
289
+        if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
290
+
291
+        if ($conf->propal->multidir_output[$conf->entity])
292
+        {
293
+            $object->fetch_thirdparty();
294
+
295
+            $deja_regle = 0;
296
+
297
+            // Definition of $dir and $file
298
+            if ($object->specimen)
299
+            {
300
+                $dir = $conf->propal->multidir_output[$conf->entity];
301
+                $file = $dir . "/SPECIMEN.pdf";
302
+            }
303
+            else
304
+            {
305
+                $objectref = dol_sanitizeFileName($object->ref);
306
+                $dir = $conf->propal->multidir_output[$object->entity] . "/" . $objectref;
307
+                $file = $dir . "/" . $objectref . ".pdf";
308
+            }
309
+
310
+            if (! file_exists($dir))
311
+            {
312
+                if (dol_mkdir($dir) < 0)
313
+                {
314
+                    $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
315
+                    return 0;
316
+                }
317
+            }
318 318
 
319
-			if (file_exists($dir))
320
-			{
321
-				// Add pdfgeneration hook
322
-				if (! is_object($hookmanager))
323
-				{
324
-					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
325
-					$hookmanager=new HookManager($this->db);
326
-				}
327
-				$hookmanager->initHooks(array('pdfgeneration'));
328
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
329
-				global $action;
330
-				$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
319
+            if (file_exists($dir))
320
+            {
321
+                // Add pdfgeneration hook
322
+                if (! is_object($hookmanager))
323
+                {
324
+                    include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
325
+                    $hookmanager=new HookManager($this->db);
326
+                }
327
+                $hookmanager->initHooks(array('pdfgeneration'));
328
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
329
+                global $action;
330
+                $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
331 331
 
332
-				// Create pdf instance
332
+                // Create pdf instance
333 333
                 $pdf=pdf_getInstance($this->format);
334 334
                 $default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
335
-	            $pdf->SetAutoPageBreak(1,0);
335
+                $pdf->SetAutoPageBreak(1,0);
336 336
 
337 337
                 if (class_exists('TCPDF'))
338 338
                 {
@@ -347,589 +347,589 @@  discard block
 block discarded – undo
347 347
                     $tplidx = $pdf->importPage(1);
348 348
                 }
349 349
 
350
-				$pdf->Open();
351
-				$pagenb=0;
352
-				$pdf->SetDrawColor(128,128,128);
350
+                $pdf->Open();
351
+                $pagenb=0;
352
+                $pdf->SetDrawColor(128,128,128);
353 353
 
354
-				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
355
-				$pdf->SetSubject($outputlangs->transnoentities("PdfCommercialProposalTitle"));
356
-				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
357
-				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
358
-				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfCommercialProposalTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
359
-				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
354
+                $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
355
+                $pdf->SetSubject($outputlangs->transnoentities("PdfCommercialProposalTitle"));
356
+                $pdf->SetCreator("Dolibarr ".DOL_VERSION);
357
+                $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
358
+                $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfCommercialProposalTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
359
+                if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
360 360
 
361
-				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
361
+                $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
362 362
 
363
-				// Positionne $this->atleastonediscount si on a au moins une remise
364
-				for ($i = 0 ; $i < $nblignes ; $i++)
365
-				{
366
-					if ($object->lines[$i]->remise_percent)
367
-					{
368
-						$this->atleastonediscount++;
369
-					}
370
-				}
371
-				if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS))
372
-				{
373
-					$this->posxpicture+=($this->postotalht - $this->posxdiscount);
374
-					$this->posxtva+=($this->postotalht - $this->posxdiscount);
375
-					$this->posxup+=($this->postotalht - $this->posxdiscount);
376
-					$this->posxqty+=($this->postotalht - $this->posxdiscount);
377
-					$this->posxdiscount+=($this->postotalht - $this->posxdiscount);
378
-					//$this->postotalht;
379
-				}
363
+                // Positionne $this->atleastonediscount si on a au moins une remise
364
+                for ($i = 0 ; $i < $nblignes ; $i++)
365
+                {
366
+                    if ($object->lines[$i]->remise_percent)
367
+                    {
368
+                        $this->atleastonediscount++;
369
+                    }
370
+                }
371
+                if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS))
372
+                {
373
+                    $this->posxpicture+=($this->postotalht - $this->posxdiscount);
374
+                    $this->posxtva+=($this->postotalht - $this->posxdiscount);
375
+                    $this->posxup+=($this->postotalht - $this->posxdiscount);
376
+                    $this->posxqty+=($this->postotalht - $this->posxdiscount);
377
+                    $this->posxdiscount+=($this->postotalht - $this->posxdiscount);
378
+                    //$this->postotalht;
379
+                }
380 380
 
381
-				// New page
382
-				$pdf->AddPage();
383
-				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
384
-				$pagenb++;
381
+                // New page
382
+                $pdf->AddPage();
383
+                if (! empty($tplidx)) $pdf->useTemplate($tplidx);
384
+                $pagenb++;
385 385
 
386 386
                 $heightforinfotot = 40;	// Height reserved to output the info and total part
387 387
                 $heightforsignature = empty($conf->global->PROPAL_DISABLE_SIGNATURE)?(pdfGetHeightForHtmlContent($pdf, $outputlangs->transnoentities("ProposalCustomerSignature"))+10):0;
388 388
                 $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5);	// Height reserved to output the free text on last page
389
-	            $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
390
-				if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
389
+                $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
390
+                if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
391 391
                 //print $heightforinfotot + $heightforsignature + $heightforfreetext + $heightforfooter;exit;
392 392
 
393
-				$top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
394
-				$pdf->SetFont('','', $default_font_size - 1);
395
-				$pdf->MultiCell(0, 3, '');		// Set interline to 3
396
-				$pdf->SetTextColor(0,0,0);
393
+                $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
394
+                $pdf->SetFont('','', $default_font_size - 1);
395
+                $pdf->MultiCell(0, 3, '');		// Set interline to 3
396
+                $pdf->SetTextColor(0,0,0);
397 397
 
398 398
 
399
-	            $tab_top = 90+$top_shift;
400
-				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10);
399
+                $tab_top = 90+$top_shift;
400
+                $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10);
401 401
 
402
-				// Incoterm
403
-				if ($conf->incoterm->enabled)
404
-				{
405
-					$desc_incoterms = $object->getIncotermsForPDF();
406
-					if ($desc_incoterms)
407
-					{
408
-						$tab_top -= 2;
409
-
410
-						$pdf->SetFont('','', $default_font_size - 1);
411
-						$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
412
-						$nexY = $pdf->GetY();
413
-						$height_incoterms=$nexY-$tab_top;
414
-
415
-						// Rect prend une longueur en 3eme param
416
-						$pdf->SetDrawColor(192,192,192);
417
-						$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
418
-
419
-						$tab_top = $nexY+6;
420
-					}
421
-				}
402
+                // Incoterm
403
+                if ($conf->incoterm->enabled)
404
+                {
405
+                    $desc_incoterms = $object->getIncotermsForPDF();
406
+                    if ($desc_incoterms)
407
+                    {
408
+                        $tab_top -= 2;
409
+
410
+                        $pdf->SetFont('','', $default_font_size - 1);
411
+                        $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
412
+                        $nexY = $pdf->GetY();
413
+                        $height_incoterms=$nexY-$tab_top;
414
+
415
+                        // Rect prend une longueur en 3eme param
416
+                        $pdf->SetDrawColor(192,192,192);
417
+                        $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
418
+
419
+                        $tab_top = $nexY+6;
420
+                    }
421
+                }
422 422
 
423
-				// Affiche notes
424
-				$notetoshow=empty($object->note_public)?'':$object->note_public;
425
-				if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
426
-				{
427
-					// Get first sale rep
428
-					if (is_object($object->thirdparty))
429
-					{
430
-						$salereparray=$object->thirdparty->getSalesRepresentatives($user);
431
-						$salerepobj=new User($this->db);
432
-						$salerepobj->fetch($salereparray[0]['id']);
433
-						if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
434
-					}
435
-				}
436
-				if (! empty($conf->global->MAIN_ADD_CREATOR_IN_NOTE) && $object->user_author_id > 0)
437
-				{
438
-				    $tmpuser=new User($this->db);
439
-				    $tmpuser->fetch($object->user_author_id);
440
-				    $notetoshow.='Affaire suivi par '.$tmpuser->getFullName($langs);
441
-				    if ($tmpuser->email) $notetoshow.=',  Mail: '.$tmpuser->email;
442
-				    if ($tmpuser->office_phone) $notetoshow.=', Tel: '.$tmpuser->office_phone;
443
-				}
444
-				if ($notetoshow)
445
-				{
446
-					$tab_top -= 2;
423
+                // Affiche notes
424
+                $notetoshow=empty($object->note_public)?'':$object->note_public;
425
+                if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
426
+                {
427
+                    // Get first sale rep
428
+                    if (is_object($object->thirdparty))
429
+                    {
430
+                        $salereparray=$object->thirdparty->getSalesRepresentatives($user);
431
+                        $salerepobj=new User($this->db);
432
+                        $salerepobj->fetch($salereparray[0]['id']);
433
+                        if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
434
+                    }
435
+                }
436
+                if (! empty($conf->global->MAIN_ADD_CREATOR_IN_NOTE) && $object->user_author_id > 0)
437
+                {
438
+                    $tmpuser=new User($this->db);
439
+                    $tmpuser->fetch($object->user_author_id);
440
+                    $notetoshow.='Affaire suivi par '.$tmpuser->getFullName($langs);
441
+                    if ($tmpuser->email) $notetoshow.=',  Mail: '.$tmpuser->email;
442
+                    if ($tmpuser->office_phone) $notetoshow.=', Tel: '.$tmpuser->office_phone;
443
+                }
444
+                if ($notetoshow)
445
+                {
446
+                    $tab_top -= 2;
447 447
 
448
-					$substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
449
-					complete_substitutions_array($substitutionarray, $outputlangs, $object);
450
-					$notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
448
+                    $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
449
+                    complete_substitutions_array($substitutionarray, $outputlangs, $object);
450
+                    $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
451 451
 
452
-					$pdf->SetFont('','', $default_font_size - 1);
453
-					$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($notetoshow), 0, 1);
454
-					$nexY = $pdf->GetY();
455
-					$height_note=$nexY-$tab_top;
452
+                    $pdf->SetFont('','', $default_font_size - 1);
453
+                    $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($notetoshow), 0, 1);
454
+                    $nexY = $pdf->GetY();
455
+                    $height_note=$nexY-$tab_top;
456 456
 
457
-					// Rect prend une longueur en 3eme param
458
-					$pdf->SetDrawColor(192,192,192);
459
-					$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
457
+                    // Rect prend une longueur en 3eme param
458
+                    $pdf->SetDrawColor(192,192,192);
459
+                    $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
460 460
 
461
-					$tab_top = $nexY+6;
462
-				}
461
+                    $tab_top = $nexY+6;
462
+                }
463 463
 
464
-				$iniY = $tab_top + 7;
465
-				$curY = $tab_top + 7;
466
-				$nexY = $tab_top + 7;
464
+                $iniY = $tab_top + 7;
465
+                $curY = $tab_top + 7;
466
+                $nexY = $tab_top + 7;
467 467
 
468
-				// Loop on each lines
469
-				for ($i = 0; $i < $nblignes; $i++)
470
-				{
471
-					$curY = $nexY;
472
-					$pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
473
-					$pdf->SetTextColor(0,0,0);
474
-
475
-					// Define size of image if we need it
476
-					$imglinesize=array();
477
-					if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
478
-
479
-					$pdf->setTopMargin($tab_top_newpage);
480
-					$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
481
-					$pageposbefore=$pdf->getPage();
482
-
483
-					$showpricebeforepagebreak=1;
484
-					$posYAfterImage=0;
485
-					$posYAfterDescription=0;
486
-
487
-					// We start with Photo of product line
488
-					if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot)))	// If photo too high, we moved completely on new page
489
-					{
490
-						$pdf->AddPage('','',true);
491
-						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
492
-						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
493
-						$pdf->setPage($pageposbefore+1);
494
-
495
-						$curY = $tab_top_newpage;
496
-						$showpricebeforepagebreak=0;
497
-					}
498
-
499
-					if (isset($imglinesize['width']) && isset($imglinesize['height']))
500
-					{
501
-						$curX = $this->posxpicture-1;
502
-						$pdf->Image($realpatharray[$i], $curX + (($this->posxtva-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);	// Use 300 dpi
503
-						// $pdf->Image does not increase value return by getY, so we save it manually
504
-						$posYAfterImage=$curY+$imglinesize['height'];
505
-					}
506
-
507
-					// Description of product line
508
-					$curX = $this->posxdesc-1;
509
-
510
-					$pdf->startTransaction();
511
-					pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc);
512
-					$pageposafter=$pdf->getPage();
513
-					if ($pageposafter > $pageposbefore)	// There is a pagebreak
514
-					{
515
-						$pdf->rollbackTransaction(true);
516
-						$pageposafter=$pageposbefore;
517
-						//print $pageposafter.'-'.$pageposbefore;exit;
518
-						$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
519
-						pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc);
520
-
521
-						$pageposafter=$pdf->getPage();
522
-						$posyafter=$pdf->GetY();
523
-						//var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
524
-						if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot)))	// There is no space left for total+free text
525
-						{
526
-							if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
527
-							{
528
-								$pdf->AddPage('','',true);
529
-								if (! empty($tplidx)) $pdf->useTemplate($tplidx);
530
-								if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
531
-								$pdf->setPage($pageposafter+1);
532
-							}
533
-						}
534
-						else
535
-						{
536
-							// We found a page break
537
-							$showpricebeforepagebreak=0;
538
-						}
539
-					}
540
-					else	// No pagebreak
541
-					{
542
-						$pdf->commitTransaction();
543
-					}
544
-					$posYAfterDescription=$pdf->GetY();
545
-
546
-					$nexY = $pdf->GetY();
547
-					$pageposafter=$pdf->getPage();
548
-
549
-					$pdf->setPage($pageposbefore);
550
-					$pdf->setTopMargin($this->marge_haute);
551
-					$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
552
-
553
-					// We suppose that a too long description or photo were moved completely on next page
554
-					if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
555
-						$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
556
-					}
557
-
558
-					$pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
559
-
560
-					// VAT Rate
561
-					if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
562
-					{
563
-						$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
564
-						$pdf->SetXY($this->posxtva-5, $curY);
565
-						$pdf->MultiCell($this->posxup-$this->posxtva+4, 3, $vat_rate, 0, 'R');
566
-					}
567
-
568
-					// Unit price before discount
569
-					$up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
570
-					$pdf->SetXY($this->posxup, $curY);
571
-					$pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
572
-
573
-					// Quantity
574
-					$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
575
-					$pdf->SetXY($this->posxqty, $curY);
576
-					// Enough for 6 chars
577
-					if($conf->global->PRODUCT_USE_UNITS)
578
-					{
579
-						$pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R');
580
-					}
581
-					else
582
-					{
583
-						$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $qty, 0, 'R');
584
-					}
585
-
586
-					// Unit
587
-					if($conf->global->PRODUCT_USE_UNITS)
588
-					{
589
-						$unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
590
-						$pdf->SetXY($this->posxunit, $curY);
591
-						$pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
592
-					}
593
-
594
-					// Discount on line
595
-					$pdf->SetXY($this->posxdiscount, $curY);
596
-					if ($object->lines[$i]->remise_percent)
597
-					{
598
-						$pdf->SetXY($this->posxdiscount-2, $curY);
599
-						$remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
600
-						$pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R');
601
-					}
602
-
603
-					// Total HT line
604
-					$total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
605
-					$pdf->SetXY($this->postotalht, $curY);
606
-					$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
607
-
608
-					// Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
609
-					if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
610
-					else $tvaligne=$object->lines[$i]->total_tva;
611
-
612
-					$localtax1ligne=$object->lines[$i]->total_localtax1;
613
-					$localtax2ligne=$object->lines[$i]->total_localtax2;
614
-					$localtax1_rate=$object->lines[$i]->localtax1_tx;
615
-					$localtax2_rate=$object->lines[$i]->localtax2_tx;
616
-					$localtax1_type=$object->lines[$i]->localtax1_type;
617
-					$localtax2_type=$object->lines[$i]->localtax2_type;
618
-
619
-					if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
620
-					if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
621
-					if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
622
-
623
-					$vatrate=(string) $object->lines[$i]->tva_tx;
624
-
625
-					// Retrieve type from database for backward compatibility with old records
626
-					if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
627
-					&& (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
628
-					{
629
-						$localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc);
630
-						$localtax1_type = $localtaxtmp_array[0];
631
-						$localtax2_type = $localtaxtmp_array[2];
632
-					}
633
-
634
-				    // retrieve global local tax
635
-					if ($localtax1_type && $localtax1ligne != 0)
636
-						$this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
637
-					if ($localtax2_type && $localtax2ligne != 0)
638
-						$this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
639
-
640
-					if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
641
-					if (! isset($this->tva[$vatrate]))				$this->tva[$vatrate]=0;
642
-					$this->tva[$vatrate] += $tvaligne;
643
-
644
-					if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
645
-
646
-					// Add line
647
-					if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
648
-					{
649
-						$pdf->setPage($pageposafter);
650
-						$pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
651
-						//$pdf->SetDrawColor(190,190,200);
652
-						$pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
653
-						$pdf->SetLineStyle(array('dash'=>0));
654
-					}
655
-
656
-					$nexY+=2;    // Passe espace entre les lignes
657
-
658
-					// Detect if some page were added automatically and output _tableau for past pages
659
-					while ($pagenb < $pageposafter)
660
-					{
661
-						$pdf->setPage($pagenb);
662
-						if ($pagenb == 1)
663
-						{
664
-							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
665
-						}
666
-						else
667
-						{
668
-							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
669
-						}
670
-						$this->_pagefoot($pdf,$object,$outputlangs,1);
671
-						$pagenb++;
672
-						$pdf->setPage($pagenb);
673
-						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
674
-						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
675
-					}
676
-					if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
677
-					{
678
-						if ($pagenb == 1)
679
-						{
680
-							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
681
-						}
682
-						else
683
-						{
684
-							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
685
-						}
686
-						$this->_pagefoot($pdf,$object,$outputlangs,1);
687
-						// New page
688
-						$pdf->AddPage();
689
-						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
690
-						$pagenb++;
691
-						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
692
-					}
693
-				}
468
+                // Loop on each lines
469
+                for ($i = 0; $i < $nblignes; $i++)
470
+                {
471
+                    $curY = $nexY;
472
+                    $pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
473
+                    $pdf->SetTextColor(0,0,0);
474
+
475
+                    // Define size of image if we need it
476
+                    $imglinesize=array();
477
+                    if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
478
+
479
+                    $pdf->setTopMargin($tab_top_newpage);
480
+                    $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
481
+                    $pageposbefore=$pdf->getPage();
482
+
483
+                    $showpricebeforepagebreak=1;
484
+                    $posYAfterImage=0;
485
+                    $posYAfterDescription=0;
486
+
487
+                    // We start with Photo of product line
488
+                    if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot)))	// If photo too high, we moved completely on new page
489
+                    {
490
+                        $pdf->AddPage('','',true);
491
+                        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
492
+                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
493
+                        $pdf->setPage($pageposbefore+1);
494
+
495
+                        $curY = $tab_top_newpage;
496
+                        $showpricebeforepagebreak=0;
497
+                    }
498
+
499
+                    if (isset($imglinesize['width']) && isset($imglinesize['height']))
500
+                    {
501
+                        $curX = $this->posxpicture-1;
502
+                        $pdf->Image($realpatharray[$i], $curX + (($this->posxtva-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);	// Use 300 dpi
503
+                        // $pdf->Image does not increase value return by getY, so we save it manually
504
+                        $posYAfterImage=$curY+$imglinesize['height'];
505
+                    }
506
+
507
+                    // Description of product line
508
+                    $curX = $this->posxdesc-1;
509
+
510
+                    $pdf->startTransaction();
511
+                    pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc);
512
+                    $pageposafter=$pdf->getPage();
513
+                    if ($pageposafter > $pageposbefore)	// There is a pagebreak
514
+                    {
515
+                        $pdf->rollbackTransaction(true);
516
+                        $pageposafter=$pageposbefore;
517
+                        //print $pageposafter.'-'.$pageposbefore;exit;
518
+                        $pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
519
+                        pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc);
520
+
521
+                        $pageposafter=$pdf->getPage();
522
+                        $posyafter=$pdf->GetY();
523
+                        //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
524
+                        if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot)))	// There is no space left for total+free text
525
+                        {
526
+                            if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
527
+                            {
528
+                                $pdf->AddPage('','',true);
529
+                                if (! empty($tplidx)) $pdf->useTemplate($tplidx);
530
+                                if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
531
+                                $pdf->setPage($pageposafter+1);
532
+                            }
533
+                        }
534
+                        else
535
+                        {
536
+                            // We found a page break
537
+                            $showpricebeforepagebreak=0;
538
+                        }
539
+                    }
540
+                    else	// No pagebreak
541
+                    {
542
+                        $pdf->commitTransaction();
543
+                    }
544
+                    $posYAfterDescription=$pdf->GetY();
545
+
546
+                    $nexY = $pdf->GetY();
547
+                    $pageposafter=$pdf->getPage();
548
+
549
+                    $pdf->setPage($pageposbefore);
550
+                    $pdf->setTopMargin($this->marge_haute);
551
+                    $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
552
+
553
+                    // We suppose that a too long description or photo were moved completely on next page
554
+                    if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
555
+                        $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
556
+                    }
557
+
558
+                    $pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
559
+
560
+                    // VAT Rate
561
+                    if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
562
+                    {
563
+                        $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
564
+                        $pdf->SetXY($this->posxtva-5, $curY);
565
+                        $pdf->MultiCell($this->posxup-$this->posxtva+4, 3, $vat_rate, 0, 'R');
566
+                    }
567
+
568
+                    // Unit price before discount
569
+                    $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
570
+                    $pdf->SetXY($this->posxup, $curY);
571
+                    $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
572
+
573
+                    // Quantity
574
+                    $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
575
+                    $pdf->SetXY($this->posxqty, $curY);
576
+                    // Enough for 6 chars
577
+                    if($conf->global->PRODUCT_USE_UNITS)
578
+                    {
579
+                        $pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R');
580
+                    }
581
+                    else
582
+                    {
583
+                        $pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $qty, 0, 'R');
584
+                    }
585
+
586
+                    // Unit
587
+                    if($conf->global->PRODUCT_USE_UNITS)
588
+                    {
589
+                        $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
590
+                        $pdf->SetXY($this->posxunit, $curY);
591
+                        $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
592
+                    }
593
+
594
+                    // Discount on line
595
+                    $pdf->SetXY($this->posxdiscount, $curY);
596
+                    if ($object->lines[$i]->remise_percent)
597
+                    {
598
+                        $pdf->SetXY($this->posxdiscount-2, $curY);
599
+                        $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
600
+                        $pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R');
601
+                    }
602
+
603
+                    // Total HT line
604
+                    $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
605
+                    $pdf->SetXY($this->postotalht, $curY);
606
+                    $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
607
+
608
+                    // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
609
+                    if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
610
+                    else $tvaligne=$object->lines[$i]->total_tva;
611
+
612
+                    $localtax1ligne=$object->lines[$i]->total_localtax1;
613
+                    $localtax2ligne=$object->lines[$i]->total_localtax2;
614
+                    $localtax1_rate=$object->lines[$i]->localtax1_tx;
615
+                    $localtax2_rate=$object->lines[$i]->localtax2_tx;
616
+                    $localtax1_type=$object->lines[$i]->localtax1_type;
617
+                    $localtax2_type=$object->lines[$i]->localtax2_type;
618
+
619
+                    if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
620
+                    if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
621
+                    if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
622
+
623
+                    $vatrate=(string) $object->lines[$i]->tva_tx;
624
+
625
+                    // Retrieve type from database for backward compatibility with old records
626
+                    if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
627
+                    && (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
628
+                    {
629
+                        $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc);
630
+                        $localtax1_type = $localtaxtmp_array[0];
631
+                        $localtax2_type = $localtaxtmp_array[2];
632
+                    }
633
+
634
+                    // retrieve global local tax
635
+                    if ($localtax1_type && $localtax1ligne != 0)
636
+                        $this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
637
+                    if ($localtax2_type && $localtax2ligne != 0)
638
+                        $this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
639
+
640
+                    if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
641
+                    if (! isset($this->tva[$vatrate]))				$this->tva[$vatrate]=0;
642
+                    $this->tva[$vatrate] += $tvaligne;
643
+
644
+                    if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
645
+
646
+                    // Add line
647
+                    if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
648
+                    {
649
+                        $pdf->setPage($pageposafter);
650
+                        $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
651
+                        //$pdf->SetDrawColor(190,190,200);
652
+                        $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
653
+                        $pdf->SetLineStyle(array('dash'=>0));
654
+                    }
655
+
656
+                    $nexY+=2;    // Passe espace entre les lignes
657
+
658
+                    // Detect if some page were added automatically and output _tableau for past pages
659
+                    while ($pagenb < $pageposafter)
660
+                    {
661
+                        $pdf->setPage($pagenb);
662
+                        if ($pagenb == 1)
663
+                        {
664
+                            $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
665
+                        }
666
+                        else
667
+                        {
668
+                            $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
669
+                        }
670
+                        $this->_pagefoot($pdf,$object,$outputlangs,1);
671
+                        $pagenb++;
672
+                        $pdf->setPage($pagenb);
673
+                        $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
674
+                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
675
+                    }
676
+                    if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
677
+                    {
678
+                        if ($pagenb == 1)
679
+                        {
680
+                            $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
681
+                        }
682
+                        else
683
+                        {
684
+                            $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
685
+                        }
686
+                        $this->_pagefoot($pdf,$object,$outputlangs,1);
687
+                        // New page
688
+                        $pdf->AddPage();
689
+                        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
690
+                        $pagenb++;
691
+                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
692
+                    }
693
+                }
694 694
 
695
-				// Show square
696
-				if ($pagenb == 1)
697
-				{
698
-					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
699
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
700
-				}
701
-				else
702
-				{
703
-					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
704
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
705
-				}
695
+                // Show square
696
+                if ($pagenb == 1)
697
+                {
698
+                    $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
699
+                    $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
700
+                }
701
+                else
702
+                {
703
+                    $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
704
+                    $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
705
+                }
706 706
 
707
-				// Affiche zone infos
708
-				$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
707
+                // Affiche zone infos
708
+                $posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
709 709
 
710
-				// Affiche zone totaux
711
-				$posy=$this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs);
710
+                // Affiche zone totaux
711
+                $posy=$this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs);
712 712
 
713
-				// Affiche zone versements
714
-				/*
713
+                // Affiche zone versements
714
+                /*
715 715
 				if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
716 716
 				{
717 717
 					$posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
718 718
 				}
719 719
 				*/
720 720
 
721
-				// Customer signature area
722
-				if (empty($conf->global->PROPAL_DISABLE_SIGNATURE))
723
-				{
724
-				    $posy=$this->_signature_area($pdf, $object, $posy, $outputlangs);
725
-				}
721
+                // Customer signature area
722
+                if (empty($conf->global->PROPAL_DISABLE_SIGNATURE))
723
+                {
724
+                    $posy=$this->_signature_area($pdf, $object, $posy, $outputlangs);
725
+                }
726 726
 
727
-				// Pied de page
728
-				$this->_pagefoot($pdf,$object,$outputlangs);
729
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
727
+                // Pied de page
728
+                $this->_pagefoot($pdf,$object,$outputlangs);
729
+                if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
730 730
 
731
-				//If propal merge product PDF is active
732
-				if (!empty($conf->global->PRODUIT_PDF_MERGE_PROPAL))
733
-				{
734
-					require_once DOL_DOCUMENT_ROOT.'/product/class/propalmergepdfproduct.class.php';
735
-
736
-					$already_merged = array ();
737
-					foreach ( $object->lines as $line ) {
738
-						if (! empty($line->fk_product) && ! (in_array($line->fk_product, $already_merged))) {
739
-							// Find the desire PDF
740
-							$filetomerge = new Propalmergepdfproduct($this->db);
741
-
742
-							if ($conf->global->MAIN_MULTILANGS) {
743
-								$filetomerge->fetch_by_product($line->fk_product, $outputlangs->defaultlang);
744
-							} else {
745
-								$filetomerge->fetch_by_product($line->fk_product);
746
-							}
747
-
748
-							$already_merged[] = $line->fk_product;
749
-
750
-							$product = new Product($this->db);
751
-							$product->fetch($line->fk_product);
752
-
753
-							if ($product->entity!=$conf->entity) {
754
-								$entity_product_file=$product->entity;
755
-							} else {
756
-								$entity_product_file=$conf->entity;
757
-							}
758
-
759
-							// If PDF is selected and file is not empty
760
-							if (count($filetomerge->lines) > 0) {
761
-								foreach ( $filetomerge->lines as $linefile ) {
762
-									if (! empty($linefile->id) && ! empty($linefile->file_name)) {
763
-
764
-
765
-										if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
766
-										{
767
-											if (! empty($conf->product->enabled)) {
768
-												$filetomerge_dir = $conf->product->multidir_output[$entity_product_file] . '/' . get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos";
769
-											} elseif (! empty($conf->service->enabled)) {
770
-												$filetomerge_dir = $conf->service->multidir_output[$entity_product_file] . '/' . get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos";
771
-											}
772
-										}
773
-										else
774
-										{
775
-											if (! empty($conf->product->enabled)) {
776
-												$filetomerge_dir = $conf->product->multidir_output[$entity_product_file] . '/' . get_exdir(0,0,0,0,$product,'product') . dol_sanitizeFileName($product->ref);
777
-											} elseif (! empty($conf->service->enabled)) {
778
-												$filetomerge_dir = $conf->service->multidir_output[$entity_product_file] . '/' . get_exdir(0,0,0,0,$product,'product') . dol_sanitizeFileName($product->ref);
779
-											}
780
-										}
781
-
782
-										dol_syslog(get_class($this) . ':: upload_dir=' . $filetomerge_dir, LOG_DEBUG);
783
-
784
-										$infile = $filetomerge_dir . '/' . $linefile->file_name;
785
-										if (file_exists($infile) && is_readable($infile)) {
786
-											$pagecount = $pdf->setSourceFile($infile);
787
-											for($i = 1; $i <= $pagecount; $i ++) {
788
-												$tplIdx = $pdf->importPage($i);
789
-												if ($tplIdx!==false) {
790
-													$s = $pdf->getTemplatesize($tplIdx);
791
-													$pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
792
-													$pdf->useTemplate($tplIdx);
793
-												} else {
794
-													setEventMessages(null, array($infile.' cannot be added, probably protected PDF'),'warnings');
795
-												}
796
-											}
797
-										}
798
-									}
799
-								}
800
-							}
801
-						}
802
-					}
803
-				}
731
+                //If propal merge product PDF is active
732
+                if (!empty($conf->global->PRODUIT_PDF_MERGE_PROPAL))
733
+                {
734
+                    require_once DOL_DOCUMENT_ROOT.'/product/class/propalmergepdfproduct.class.php';
735
+
736
+                    $already_merged = array ();
737
+                    foreach ( $object->lines as $line ) {
738
+                        if (! empty($line->fk_product) && ! (in_array($line->fk_product, $already_merged))) {
739
+                            // Find the desire PDF
740
+                            $filetomerge = new Propalmergepdfproduct($this->db);
741
+
742
+                            if ($conf->global->MAIN_MULTILANGS) {
743
+                                $filetomerge->fetch_by_product($line->fk_product, $outputlangs->defaultlang);
744
+                            } else {
745
+                                $filetomerge->fetch_by_product($line->fk_product);
746
+                            }
747
+
748
+                            $already_merged[] = $line->fk_product;
749
+
750
+                            $product = new Product($this->db);
751
+                            $product->fetch($line->fk_product);
752
+
753
+                            if ($product->entity!=$conf->entity) {
754
+                                $entity_product_file=$product->entity;
755
+                            } else {
756
+                                $entity_product_file=$conf->entity;
757
+                            }
758
+
759
+                            // If PDF is selected and file is not empty
760
+                            if (count($filetomerge->lines) > 0) {
761
+                                foreach ( $filetomerge->lines as $linefile ) {
762
+                                    if (! empty($linefile->id) && ! empty($linefile->file_name)) {
763
+
764
+
765
+                                        if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
766
+                                        {
767
+                                            if (! empty($conf->product->enabled)) {
768
+                                                $filetomerge_dir = $conf->product->multidir_output[$entity_product_file] . '/' . get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos";
769
+                                            } elseif (! empty($conf->service->enabled)) {
770
+                                                $filetomerge_dir = $conf->service->multidir_output[$entity_product_file] . '/' . get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos";
771
+                                            }
772
+                                        }
773
+                                        else
774
+                                        {
775
+                                            if (! empty($conf->product->enabled)) {
776
+                                                $filetomerge_dir = $conf->product->multidir_output[$entity_product_file] . '/' . get_exdir(0,0,0,0,$product,'product') . dol_sanitizeFileName($product->ref);
777
+                                            } elseif (! empty($conf->service->enabled)) {
778
+                                                $filetomerge_dir = $conf->service->multidir_output[$entity_product_file] . '/' . get_exdir(0,0,0,0,$product,'product') . dol_sanitizeFileName($product->ref);
779
+                                            }
780
+                                        }
781
+
782
+                                        dol_syslog(get_class($this) . ':: upload_dir=' . $filetomerge_dir, LOG_DEBUG);
783
+
784
+                                        $infile = $filetomerge_dir . '/' . $linefile->file_name;
785
+                                        if (file_exists($infile) && is_readable($infile)) {
786
+                                            $pagecount = $pdf->setSourceFile($infile);
787
+                                            for($i = 1; $i <= $pagecount; $i ++) {
788
+                                                $tplIdx = $pdf->importPage($i);
789
+                                                if ($tplIdx!==false) {
790
+                                                    $s = $pdf->getTemplatesize($tplIdx);
791
+                                                    $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
792
+                                                    $pdf->useTemplate($tplIdx);
793
+                                                } else {
794
+                                                    setEventMessages(null, array($infile.' cannot be added, probably protected PDF'),'warnings');
795
+                                                }
796
+                                            }
797
+                                        }
798
+                                    }
799
+                                }
800
+                            }
801
+                        }
802
+                    }
803
+                }
804 804
 
805
-				$pdf->Close();
805
+                $pdf->Close();
806 806
 
807
-				$pdf->Output($file,'F');
807
+                $pdf->Output($file,'F');
808 808
 
809
-				//Add pdfgeneration hook
810
-				$hookmanager->initHooks(array('pdfgeneration'));
811
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
812
-				global $action;
813
-				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
809
+                //Add pdfgeneration hook
810
+                $hookmanager->initHooks(array('pdfgeneration'));
811
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
812
+                global $action;
813
+                $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
814 814
 
815
-				if (! empty($conf->global->MAIN_UMASK))
816
-				@chmod($file, octdec($conf->global->MAIN_UMASK));
815
+                if (! empty($conf->global->MAIN_UMASK))
816
+                @chmod($file, octdec($conf->global->MAIN_UMASK));
817 817
 
818
-				$this->result = array('fullpath'=>$file);
818
+                $this->result = array('fullpath'=>$file);
819 819
 
820
-				return 1;   // Pas d'erreur
821
-			}
822
-			else
823
-			{
824
-				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
825
-				return 0;
826
-			}
827
-		}
828
-		else
829
-		{
830
-			$this->error=$langs->trans("ErrorConstantNotDefined","PROP_OUTPUTDIR");
831
-			return 0;
832
-		}
833
-	}
820
+                return 1;   // Pas d'erreur
821
+            }
822
+            else
823
+            {
824
+                $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
825
+                return 0;
826
+            }
827
+        }
828
+        else
829
+        {
830
+            $this->error=$langs->trans("ErrorConstantNotDefined","PROP_OUTPUTDIR");
831
+            return 0;
832
+        }
833
+    }
834 834
 
835 835
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
836
-	/**
837
-	 *  Show payments table
838
-	 *
836
+    /**
837
+     *  Show payments table
838
+     *
839 839
      *  @param	TCPDF		$pdf           Object PDF
840 840
      *  @param  Object		$object         Object proposal
841 841
      *  @param  int			$posy           Position y in PDF
842 842
      *  @param  Translate	$outputlangs    Object langs for output
843 843
      *  @return int             			<0 if KO, >0 if OK
844
-	 */
845
-	function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
846
-	{
844
+     */
845
+    function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
846
+    {
847 847
         // phpcs:enable
848
-	}
848
+    }
849 849
 
850 850
 
851 851
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
852
-	/**
853
-	 *   Show miscellaneous information (payment mode, payment term, ...)
854
-	 *
855
-	 *   @param		TCPDF		$pdf     		Object PDF
856
-	 *   @param		Object		$object			Object to show
857
-	 *   @param		int			$posy			Y
858
-	 *   @param		Translate	$outputlangs	Langs object
859
-	 *   @return	void
860
-	 */
861
-	function _tableau_info(&$pdf, $object, $posy, $outputlangs)
862
-	{
852
+    /**
853
+     *   Show miscellaneous information (payment mode, payment term, ...)
854
+     *
855
+     *   @param		TCPDF		$pdf     		Object PDF
856
+     *   @param		Object		$object			Object to show
857
+     *   @param		int			$posy			Y
858
+     *   @param		Translate	$outputlangs	Langs object
859
+     *   @return	void
860
+     */
861
+    function _tableau_info(&$pdf, $object, $posy, $outputlangs)
862
+    {
863 863
         // phpcs:enable
864
-		global $conf;
865
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
864
+        global $conf;
865
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
866 866
 
867
-		$pdf->SetFont('','', $default_font_size - 1);
867
+        $pdf->SetFont('','', $default_font_size - 1);
868 868
 
869
-		// If France, show VAT mention if not applicable
870
-		if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
871
-		{
872
-			$pdf->SetFont('','B', $default_font_size - 2);
873
-			$pdf->SetXY($this->marge_gauche, $posy);
874
-			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
869
+        // If France, show VAT mention if not applicable
870
+        if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
871
+        {
872
+            $pdf->SetFont('','B', $default_font_size - 2);
873
+            $pdf->SetXY($this->marge_gauche, $posy);
874
+            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
875 875
 
876
-			$posy=$pdf->GetY()+4;
877
-		}
876
+            $posy=$pdf->GetY()+4;
877
+        }
878 878
 
879
-		$posxval=52;
879
+        $posxval=52;
880 880
 
881 881
         // Show shipping date
882 882
         if (! empty($object->date_livraison))
883
-		{
883
+        {
884 884
             $outputlangs->load("sendings");
885
-			$pdf->SetFont('','B', $default_font_size - 2);
886
-			$pdf->SetXY($this->marge_gauche, $posy);
887
-			$titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
888
-			$pdf->MultiCell(80, 4, $titre, 0, 'L');
889
-			$pdf->SetFont('','', $default_font_size - 2);
890
-			$pdf->SetXY($posxval, $posy);
891
-			$dlp=dol_print_date($object->date_livraison,"daytext",false,$outputlangs,true);
892
-			$pdf->MultiCell(80, 4, $dlp, 0, 'L');
885
+            $pdf->SetFont('','B', $default_font_size - 2);
886
+            $pdf->SetXY($this->marge_gauche, $posy);
887
+            $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
888
+            $pdf->MultiCell(80, 4, $titre, 0, 'L');
889
+            $pdf->SetFont('','', $default_font_size - 2);
890
+            $pdf->SetXY($posxval, $posy);
891
+            $dlp=dol_print_date($object->date_livraison,"daytext",false,$outputlangs,true);
892
+            $pdf->MultiCell(80, 4, $dlp, 0, 'L');
893 893
 
894 894
             $posy=$pdf->GetY()+1;
895
-		}
895
+        }
896 896
         elseif ($object->availability_code || $object->availability)    // Show availability conditions
897
-		{
898
-			$pdf->SetFont('','B', $default_font_size - 2);
899
-			$pdf->SetXY($this->marge_gauche, $posy);
900
-			$titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
901
-			$pdf->MultiCell(80, 4, $titre, 0, 'L');
902
-			$pdf->SetTextColor(0,0,0);
903
-			$pdf->SetFont('','', $default_font_size - 2);
904
-			$pdf->SetXY($posxval, $posy);
905
-			$lib_availability=$outputlangs->transnoentities("AvailabilityType".$object->availability_code)!=('AvailabilityType'.$object->availability_code)?$outputlangs->transnoentities("AvailabilityType".$object->availability_code):$outputlangs->convToOutputCharset($object->availability);
906
-			$lib_availability=str_replace('\n',"\n",$lib_availability);
907
-			$pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
908
-
909
-			$posy=$pdf->GetY()+1;
910
-		}
911
-
912
-		// Show payments conditions
913
-		if (empty($conf->global->PROPALE_PDF_HIDE_PAYMENTTERMCOND) && ($object->cond_reglement_code || $object->cond_reglement))
914
-		{
915
-			$pdf->SetFont('','B', $default_font_size - 2);
916
-			$pdf->SetXY($this->marge_gauche, $posy);
917
-			$titre = $outputlangs->transnoentities("PaymentConditions").':';
918
-			$pdf->MultiCell(43, 4, $titre, 0, 'L');
919
-
920
-			$pdf->SetFont('','', $default_font_size - 2);
921
-			$pdf->SetXY($posxval, $posy);
922
-			$lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc);
923
-			$lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
924
-			$pdf->MultiCell(67, 4, $lib_condition_paiement,0,'L');
925
-
926
-			$posy=$pdf->GetY()+3;
927
-		}
928
-
929
-		if (empty($conf->global->PROPALE_PDF_HIDE_PAYMENTTERMMODE))
930
-		{
931
-			// Check a payment mode is defined
932
-			/* Not required on a proposal
897
+        {
898
+            $pdf->SetFont('','B', $default_font_size - 2);
899
+            $pdf->SetXY($this->marge_gauche, $posy);
900
+            $titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
901
+            $pdf->MultiCell(80, 4, $titre, 0, 'L');
902
+            $pdf->SetTextColor(0,0,0);
903
+            $pdf->SetFont('','', $default_font_size - 2);
904
+            $pdf->SetXY($posxval, $posy);
905
+            $lib_availability=$outputlangs->transnoentities("AvailabilityType".$object->availability_code)!=('AvailabilityType'.$object->availability_code)?$outputlangs->transnoentities("AvailabilityType".$object->availability_code):$outputlangs->convToOutputCharset($object->availability);
906
+            $lib_availability=str_replace('\n',"\n",$lib_availability);
907
+            $pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
908
+
909
+            $posy=$pdf->GetY()+1;
910
+        }
911
+
912
+        // Show payments conditions
913
+        if (empty($conf->global->PROPALE_PDF_HIDE_PAYMENTTERMCOND) && ($object->cond_reglement_code || $object->cond_reglement))
914
+        {
915
+            $pdf->SetFont('','B', $default_font_size - 2);
916
+            $pdf->SetXY($this->marge_gauche, $posy);
917
+            $titre = $outputlangs->transnoentities("PaymentConditions").':';
918
+            $pdf->MultiCell(43, 4, $titre, 0, 'L');
919
+
920
+            $pdf->SetFont('','', $default_font_size - 2);
921
+            $pdf->SetXY($posxval, $posy);
922
+            $lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc);
923
+            $lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
924
+            $pdf->MultiCell(67, 4, $lib_condition_paiement,0,'L');
925
+
926
+            $posy=$pdf->GetY()+3;
927
+        }
928
+
929
+        if (empty($conf->global->PROPALE_PDF_HIDE_PAYMENTTERMMODE))
930
+        {
931
+            // Check a payment mode is defined
932
+            /* Not required on a proposal
933 933
 			if (empty($object->mode_reglement_code)
934 934
 			&& ! $conf->global->FACTURE_CHQ_NUMBER
935 935
 			&& ! $conf->global->FACTURE_RIB_NUMBER)
@@ -944,335 +944,335 @@  discard block
 block discarded – undo
944 944
 			}
945 945
 			*/
946 946
 
947
-			// Show payment mode
948
-			if ($object->mode_reglement_code
949
-			&& $object->mode_reglement_code != 'CHQ'
950
-			&& $object->mode_reglement_code != 'VIR')
951
-			{
952
-				$pdf->SetFont('','B', $default_font_size - 2);
953
-				$pdf->SetXY($this->marge_gauche, $posy);
954
-				$titre = $outputlangs->transnoentities("PaymentMode").':';
955
-				$pdf->MultiCell(80, 5, $titre, 0, 'L');
956
-				$pdf->SetFont('','', $default_font_size - 2);
957
-				$pdf->SetXY($posxval, $posy);
958
-				$lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement);
959
-				$pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
960
-
961
-				$posy=$pdf->GetY()+2;
962
-			}
963
-
964
-			// Show payment mode CHQ
965
-			if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
966
-			{
967
-				// Si mode reglement non force ou si force a CHQ
968
-				if (! empty($conf->global->FACTURE_CHQ_NUMBER))
969
-				{
970
-					$diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
971
-
972
-					if ($conf->global->FACTURE_CHQ_NUMBER > 0)
973
-					{
974
-						$account = new Account($this->db);
975
-						$account->fetch($conf->global->FACTURE_CHQ_NUMBER);
976
-
977
-						$pdf->SetXY($this->marge_gauche, $posy);
978
-						$pdf->SetFont('','B', $default_font_size - $diffsizetitle);
979
-						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio),0,'L',0);
980
-						$posy=$pdf->GetY()+1;
981
-
982
-			            if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
983
-			            {
984
-							$pdf->SetXY($this->marge_gauche, $posy);
985
-							$pdf->SetFont('','', $default_font_size - $diffsizetitle);
986
-							$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
987
-							$posy=$pdf->GetY()+2;
988
-			            }
989
-					}
990
-					if ($conf->global->FACTURE_CHQ_NUMBER == -1)
991
-					{
992
-						$pdf->SetXY($this->marge_gauche, $posy);
993
-						$pdf->SetFont('','B', $default_font_size - $diffsizetitle);
994
-						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$this->emetteur->name),0,'L',0);
995
-						$posy=$pdf->GetY()+1;
996
-
997
-			            if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
998
-			            {
999
-							$pdf->SetXY($this->marge_gauche, $posy);
1000
-							$pdf->SetFont('','', $default_font_size - $diffsizetitle);
1001
-							$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1002
-							$posy=$pdf->GetY()+2;
1003
-			            }
1004
-					}
1005
-				}
1006
-			}
947
+            // Show payment mode
948
+            if ($object->mode_reglement_code
949
+            && $object->mode_reglement_code != 'CHQ'
950
+            && $object->mode_reglement_code != 'VIR')
951
+            {
952
+                $pdf->SetFont('','B', $default_font_size - 2);
953
+                $pdf->SetXY($this->marge_gauche, $posy);
954
+                $titre = $outputlangs->transnoentities("PaymentMode").':';
955
+                $pdf->MultiCell(80, 5, $titre, 0, 'L');
956
+                $pdf->SetFont('','', $default_font_size - 2);
957
+                $pdf->SetXY($posxval, $posy);
958
+                $lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement);
959
+                $pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
960
+
961
+                $posy=$pdf->GetY()+2;
962
+            }
963
+
964
+            // Show payment mode CHQ
965
+            if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
966
+            {
967
+                // Si mode reglement non force ou si force a CHQ
968
+                if (! empty($conf->global->FACTURE_CHQ_NUMBER))
969
+                {
970
+                    $diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
971
+
972
+                    if ($conf->global->FACTURE_CHQ_NUMBER > 0)
973
+                    {
974
+                        $account = new Account($this->db);
975
+                        $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
976
+
977
+                        $pdf->SetXY($this->marge_gauche, $posy);
978
+                        $pdf->SetFont('','B', $default_font_size - $diffsizetitle);
979
+                        $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio),0,'L',0);
980
+                        $posy=$pdf->GetY()+1;
981
+
982
+                        if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
983
+                        {
984
+                            $pdf->SetXY($this->marge_gauche, $posy);
985
+                            $pdf->SetFont('','', $default_font_size - $diffsizetitle);
986
+                            $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
987
+                            $posy=$pdf->GetY()+2;
988
+                        }
989
+                    }
990
+                    if ($conf->global->FACTURE_CHQ_NUMBER == -1)
991
+                    {
992
+                        $pdf->SetXY($this->marge_gauche, $posy);
993
+                        $pdf->SetFont('','B', $default_font_size - $diffsizetitle);
994
+                        $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$this->emetteur->name),0,'L',0);
995
+                        $posy=$pdf->GetY()+1;
996
+
997
+                        if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
998
+                        {
999
+                            $pdf->SetXY($this->marge_gauche, $posy);
1000
+                            $pdf->SetFont('','', $default_font_size - $diffsizetitle);
1001
+                            $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1002
+                            $posy=$pdf->GetY()+2;
1003
+                        }
1004
+                    }
1005
+                }
1006
+            }
1007 1007
 
1008
-			// If payment mode not forced or forced to VIR, show payment with BAN
1009
-			if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
1010
-			{
1011
-				if (! empty($object->fk_account) || ! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
1012
-				{
1013
-					$bankid=(empty($object->fk_account)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_account);
1014
-					if (! empty($object->fk_bank)) $bankid=$object->fk_bank;   // For backward compatibility when object->fk_account is forced with object->fk_bank
1015
-					$account = new Account($this->db);
1016
-					$account->fetch($bankid);
1008
+            // If payment mode not forced or forced to VIR, show payment with BAN
1009
+            if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
1010
+            {
1011
+                if (! empty($object->fk_account) || ! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
1012
+                {
1013
+                    $bankid=(empty($object->fk_account)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_account);
1014
+                    if (! empty($object->fk_bank)) $bankid=$object->fk_bank;   // For backward compatibility when object->fk_account is forced with object->fk_bank
1015
+                    $account = new Account($this->db);
1016
+                    $account->fetch($bankid);
1017 1017
 
1018
-					$curx=$this->marge_gauche;
1019
-					$cury=$posy;
1018
+                    $curx=$this->marge_gauche;
1019
+                    $cury=$posy;
1020 1020
 
1021
-					$posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size);
1021
+                    $posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size);
1022 1022
 
1023
-					$posy+=2;
1024
-				}
1025
-			}
1026
-		}
1023
+                    $posy+=2;
1024
+                }
1025
+            }
1026
+        }
1027 1027
 
1028
-		return $posy;
1029
-	}
1028
+        return $posy;
1029
+    }
1030 1030
 
1031 1031
 
1032 1032
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1033
-	/**
1034
-	 *	Show total to pay
1035
-	 *
1036
-	 *	@param	PDF			$pdf            Object PDF
1037
-	 *	@param  Facture		$object         Object invoice
1038
-	 *	@param  int			$deja_regle     Montant deja regle
1039
-	 *	@param	int			$posy			Position depart
1040
-	 *	@param	Translate	$outputlangs	Objet langs
1041
-	 *	@return int							Position pour suite
1042
-	 */
1043
-	function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
1044
-	{
1033
+    /**
1034
+     *	Show total to pay
1035
+     *
1036
+     *	@param	PDF			$pdf            Object PDF
1037
+     *	@param  Facture		$object         Object invoice
1038
+     *	@param  int			$deja_regle     Montant deja regle
1039
+     *	@param	int			$posy			Position depart
1040
+     *	@param	Translate	$outputlangs	Objet langs
1041
+     *	@return int							Position pour suite
1042
+     */
1043
+    function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
1044
+    {
1045 1045
         // phpcs:enable
1046
-		global $conf,$mysoc;
1047
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
1048
-
1049
-		$tab2_top = $posy;
1050
-		$tab2_hl = 4;
1051
-		$pdf->SetFont('','', $default_font_size - 1);
1052
-
1053
-		// Tableau total
1054
-		$col1x = 120; $col2x = 170;
1055
-		if ($this->page_largeur < 210) // To work with US executive format
1056
-		{
1057
-			$col2x-=20;
1058
-		}
1059
-		$largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1060
-
1061
-		$useborder=0;
1062
-		$index = 0;
1063
-
1064
-		// Total HT
1065
-		$pdf->SetFillColor(255,255,255);
1066
-		$pdf->SetXY($col1x, $tab2_top + 0);
1067
-		$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1068
-
1069
-		$total_ht = (($conf->multicurrency->enabled && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1070
-		$pdf->SetXY($col2x, $tab2_top + 0);
1071
-		$pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (! empty($object->remise)?$object->remise:0), 0, $outputlangs), 0, 'R', 1);
1072
-
1073
-		// Show VAT by rates and total
1074
-		$pdf->SetFillColor(248,248,248);
1075
-
1076
-		$total_ttc = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1077
-
1078
-		$this->atleastoneratenotnull=0;
1079
-		if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1080
-		{
1081
-			$tvaisnull=((! empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1082
-			if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1083
-			{
1084
-				// Nothing to do
1085
-			}
1086
-			else
1087
-			{
1088
-				//Local tax 1 before VAT
1089
-				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1090
-				//{
1091
-					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1092
-					{
1093
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1094
-
1095
-						foreach( $localtax_rate as $tvakey => $tvaval )
1096
-						{
1097
-							if ($tvakey!=0)    // On affiche pas taux 0
1098
-							{
1099
-								//$this->atleastoneratenotnull++;
1100
-
1101
-								$index++;
1102
-								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1103
-
1104
-								$tvacompl='';
1105
-								if (preg_match('/\*/',$tvakey))
1106
-								{
1107
-									$tvakey=str_replace('*','',$tvakey);
1108
-									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1109
-								}
1110
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1111
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1112
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1113
-
1114
-								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1115
-								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1116
-							}
1117
-						}
1118
-					}
1119
-	      		//}
1120
-				//Local tax 2 before VAT
1121
-				//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1122
-				//{
1123
-					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1124
-					{
1125
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1126
-
1127
-						foreach( $localtax_rate as $tvakey => $tvaval )
1128
-						{
1129
-							if ($tvakey!=0)    // On affiche pas taux 0
1130
-							{
1131
-								//$this->atleastoneratenotnull++;
1132
-
1133
-
1134
-
1135
-								$index++;
1136
-								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1137
-
1138
-								$tvacompl='';
1139
-								if (preg_match('/\*/',$tvakey))
1140
-								{
1141
-									$tvakey=str_replace('*','',$tvakey);
1142
-									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1143
-								}
1144
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1145
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1146
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1147
-
1148
-								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1149
-								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1150
-							}
1151
-						}
1152
-					}
1153
-				//}
1154
-				// VAT
1155
-				foreach($this->tva as $tvakey => $tvaval)
1156
-				{
1157
-					if ($tvakey != 0)    // On affiche pas taux 0
1158
-					{
1159
-						$this->atleastoneratenotnull++;
1160
-
1161
-						$index++;
1162
-						$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1163
-
1164
-						$tvacompl='';
1165
-						if (preg_match('/\*/',$tvakey))
1166
-						{
1167
-							$tvakey=str_replace('*','',$tvakey);
1168
-							$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1169
-						}
1170
-						$totalvat =$outputlangs->transcountrynoentities("TotalVAT",$mysoc->country_code).' ';
1171
-						$totalvat.=vatrate($tvakey,1).$tvacompl;
1172
-						$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1173
-
1174
-						$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1175
-						$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1176
-					}
1177
-				}
1178
-
1179
-				//Local tax 1 after VAT
1180
-				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1181
-				//{
1182
-					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1183
-					{
1184
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1185
-
1186
-						foreach( $localtax_rate as $tvakey => $tvaval )
1187
-						{
1188
-							if ($tvakey != 0)    // On affiche pas taux 0
1189
-							{
1190
-								//$this->atleastoneratenotnull++;
1191
-
1192
-								$index++;
1193
-								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1194
-
1195
-								$tvacompl='';
1196
-								if (preg_match('/\*/',$tvakey))
1197
-								{
1198
-									$tvakey=str_replace('*','',$tvakey);
1199
-									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1200
-								}
1201
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1202
-
1203
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1204
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1205
-								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1206
-								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1207
-							}
1208
-						}
1209
-					}
1210
-	      		//}
1211
-				//Local tax 2 after VAT
1212
-				//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1213
-				//{
1214
-					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1215
-					{
1216
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1217
-
1218
-						foreach( $localtax_rate as $tvakey => $tvaval )
1219
-						{
1220
-						    // retrieve global local tax
1221
-							if ($tvakey != 0)    // On affiche pas taux 0
1222
-							{
1223
-								//$this->atleastoneratenotnull++;
1224
-
1225
-								$index++;
1226
-								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1227
-
1228
-								$tvacompl='';
1229
-								if (preg_match('/\*/',$tvakey))
1230
-								{
1231
-									$tvakey=str_replace('*','',$tvakey);
1232
-									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1233
-								}
1234
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1235
-
1236
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1237
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1238
-
1239
-								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1240
-								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1241
-							}
1242
-						}
1243
-					}
1244
-				//}
1245
-
1246
-				// Total TTC
1247
-				$index++;
1248
-				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1249
-				$pdf->SetTextColor(0,0,60);
1250
-				$pdf->SetFillColor(224,224,224);
1251
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1252
-
1253
-				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1254
-				$pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1255
-			}
1256
-		}
1257
-
1258
-		$pdf->SetTextColor(0,0,0);
1046
+        global $conf,$mysoc;
1047
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
1048
+
1049
+        $tab2_top = $posy;
1050
+        $tab2_hl = 4;
1051
+        $pdf->SetFont('','', $default_font_size - 1);
1052
+
1053
+        // Tableau total
1054
+        $col1x = 120; $col2x = 170;
1055
+        if ($this->page_largeur < 210) // To work with US executive format
1056
+        {
1057
+            $col2x-=20;
1058
+        }
1059
+        $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1060
+
1061
+        $useborder=0;
1062
+        $index = 0;
1063
+
1064
+        // Total HT
1065
+        $pdf->SetFillColor(255,255,255);
1066
+        $pdf->SetXY($col1x, $tab2_top + 0);
1067
+        $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1068
+
1069
+        $total_ht = (($conf->multicurrency->enabled && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1070
+        $pdf->SetXY($col2x, $tab2_top + 0);
1071
+        $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (! empty($object->remise)?$object->remise:0), 0, $outputlangs), 0, 'R', 1);
1072
+
1073
+        // Show VAT by rates and total
1074
+        $pdf->SetFillColor(248,248,248);
1075
+
1076
+        $total_ttc = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1077
+
1078
+        $this->atleastoneratenotnull=0;
1079
+        if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1080
+        {
1081
+            $tvaisnull=((! empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1082
+            if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1083
+            {
1084
+                // Nothing to do
1085
+            }
1086
+            else
1087
+            {
1088
+                //Local tax 1 before VAT
1089
+                //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1090
+                //{
1091
+                    foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1092
+                    {
1093
+                        if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1094
+
1095
+                        foreach( $localtax_rate as $tvakey => $tvaval )
1096
+                        {
1097
+                            if ($tvakey!=0)    // On affiche pas taux 0
1098
+                            {
1099
+                                //$this->atleastoneratenotnull++;
1100
+
1101
+                                $index++;
1102
+                                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1103
+
1104
+                                $tvacompl='';
1105
+                                if (preg_match('/\*/',$tvakey))
1106
+                                {
1107
+                                    $tvakey=str_replace('*','',$tvakey);
1108
+                                    $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1109
+                                }
1110
+                                $totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1111
+                                $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1112
+                                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1113
+
1114
+                                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1115
+                                $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1116
+                            }
1117
+                        }
1118
+                    }
1119
+                    //}
1120
+                //Local tax 2 before VAT
1121
+                //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1122
+                //{
1123
+                    foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1124
+                    {
1125
+                        if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1126
+
1127
+                        foreach( $localtax_rate as $tvakey => $tvaval )
1128
+                        {
1129
+                            if ($tvakey!=0)    // On affiche pas taux 0
1130
+                            {
1131
+                                //$this->atleastoneratenotnull++;
1132
+
1133
+
1134
+
1135
+                                $index++;
1136
+                                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1137
+
1138
+                                $tvacompl='';
1139
+                                if (preg_match('/\*/',$tvakey))
1140
+                                {
1141
+                                    $tvakey=str_replace('*','',$tvakey);
1142
+                                    $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1143
+                                }
1144
+                                $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1145
+                                $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1146
+                                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1147
+
1148
+                                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1149
+                                $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1150
+                            }
1151
+                        }
1152
+                    }
1153
+                //}
1154
+                // VAT
1155
+                foreach($this->tva as $tvakey => $tvaval)
1156
+                {
1157
+                    if ($tvakey != 0)    // On affiche pas taux 0
1158
+                    {
1159
+                        $this->atleastoneratenotnull++;
1160
+
1161
+                        $index++;
1162
+                        $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1163
+
1164
+                        $tvacompl='';
1165
+                        if (preg_match('/\*/',$tvakey))
1166
+                        {
1167
+                            $tvakey=str_replace('*','',$tvakey);
1168
+                            $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1169
+                        }
1170
+                        $totalvat =$outputlangs->transcountrynoentities("TotalVAT",$mysoc->country_code).' ';
1171
+                        $totalvat.=vatrate($tvakey,1).$tvacompl;
1172
+                        $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1173
+
1174
+                        $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1175
+                        $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1176
+                    }
1177
+                }
1259 1178
 
1260
-		/*
1179
+                //Local tax 1 after VAT
1180
+                //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1181
+                //{
1182
+                    foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1183
+                    {
1184
+                        if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1185
+
1186
+                        foreach( $localtax_rate as $tvakey => $tvaval )
1187
+                        {
1188
+                            if ($tvakey != 0)    // On affiche pas taux 0
1189
+                            {
1190
+                                //$this->atleastoneratenotnull++;
1191
+
1192
+                                $index++;
1193
+                                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1194
+
1195
+                                $tvacompl='';
1196
+                                if (preg_match('/\*/',$tvakey))
1197
+                                {
1198
+                                    $tvakey=str_replace('*','',$tvakey);
1199
+                                    $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1200
+                                }
1201
+                                $totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1202
+
1203
+                                $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1204
+                                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1205
+                                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1206
+                                $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1207
+                            }
1208
+                        }
1209
+                    }
1210
+                    //}
1211
+                //Local tax 2 after VAT
1212
+                //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1213
+                //{
1214
+                    foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1215
+                    {
1216
+                        if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1217
+
1218
+                        foreach( $localtax_rate as $tvakey => $tvaval )
1219
+                        {
1220
+                            // retrieve global local tax
1221
+                            if ($tvakey != 0)    // On affiche pas taux 0
1222
+                            {
1223
+                                //$this->atleastoneratenotnull++;
1224
+
1225
+                                $index++;
1226
+                                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1227
+
1228
+                                $tvacompl='';
1229
+                                if (preg_match('/\*/',$tvakey))
1230
+                                {
1231
+                                    $tvakey=str_replace('*','',$tvakey);
1232
+                                    $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1233
+                                }
1234
+                                $totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1235
+
1236
+                                $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1237
+                                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1238
+
1239
+                                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1240
+                                $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1241
+                            }
1242
+                        }
1243
+                    }
1244
+                //}
1245
+
1246
+                // Total TTC
1247
+                $index++;
1248
+                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1249
+                $pdf->SetTextColor(0,0,60);
1250
+                $pdf->SetFillColor(224,224,224);
1251
+                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1252
+
1253
+                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1254
+                $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1255
+            }
1256
+        }
1257
+
1258
+        $pdf->SetTextColor(0,0,0);
1259
+
1260
+        /*
1261 1261
 		$resteapayer = $object->total_ttc - $deja_regle;
1262 1262
 		if (! empty($object->paye)) $resteapayer=0;
1263 1263
 		*/
1264 1264
 
1265
-		if ($deja_regle > 0)
1266
-		{
1267
-			$index++;
1265
+        if ($deja_regle > 0)
1266
+        {
1267
+            $index++;
1268 1268
 
1269
-			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1270
-			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
1269
+            $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1270
+            $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
1271 1271
 
1272
-			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1273
-			$pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
1272
+            $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1273
+            $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
1274 1274
 
1275
-			/*
1275
+            /*
1276 1276
 			if ($object->close_code == 'discount_vat')
1277 1277
 			{
1278 1278
 				$index++;
@@ -1288,419 +1288,419 @@  discard block
 block discarded – undo
1288 1288
 			}
1289 1289
 			*/
1290 1290
 
1291
-			$index++;
1292
-			$pdf->SetTextColor(0,0,60);
1293
-			$pdf->SetFillColor(224,224,224);
1294
-			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1295
-			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1296
-
1297
-			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1298
-			$pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1299
-
1300
-			$pdf->SetFont('','', $default_font_size - 1);
1301
-			$pdf->SetTextColor(0,0,0);
1302
-		}
1303
-
1304
-		$index++;
1305
-		return ($tab2_top + ($tab2_hl * $index));
1306
-	}
1307
-
1308
-	/**
1309
-	 *   Show table for lines
1310
-	 *
1311
-	 *   @param		PDF			$pdf     		Object PDF
1312
-	 *   @param		string		$tab_top		Top position of table
1313
-	 *   @param		string		$tab_height		Height of table (rectangle)
1314
-	 *   @param		int			$nexY			Y (not used)
1315
-	 *   @param		Translate	$outputlangs	Langs object
1316
-	 *   @param		int			$hidetop		1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
1317
-	 *   @param		int			$hidebottom		Hide bottom bar of array
1318
-	 *   @param		string		$currency		Currency code
1319
-	 *   @return	void
1320
-	 */
1321
-	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
1322
-	{
1323
-		global $conf;
1324
-
1325
-		// Force to disable hidetop and hidebottom
1326
-		$hidebottom=0;
1327
-		if ($hidetop) $hidetop=-1;
1328
-
1329
-		$currency = !empty($currency) ? $currency : $conf->currency;
1330
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
1331
-
1332
-		// Amount in (at tab_top - 1)
1333
-		$pdf->SetTextColor(0,0,0);
1334
-		$pdf->SetFont('','',$default_font_size - 2);
1335
-
1336
-		if (empty($hidetop))
1337
-		{
1338
-			$titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
1339
-			$pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
1340
-			$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1341
-
1342
-			//$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1343
-			if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1344
-		}
1345
-
1346
-		$pdf->SetDrawColor(128,128,128);
1347
-		$pdf->SetFont('','',$default_font_size - 1);
1348
-
1349
-		// Output Rect
1350
-		$this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom);	// Rect prend une longueur en 3eme param et 4eme param
1351
-
1352
-		if (empty($hidetop))
1353
-		{
1354
-			$pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);	// line prend une position y en 2eme param et 4eme param
1355
-
1356
-			$pdf->SetXY($this->posxdesc-1, $tab_top+1);
1357
-			$pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
1358
-		}
1359
-
1360
-		if (! empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE))
1361
-		{
1362
-			$pdf->line($this->posxpicture-1, $tab_top, $this->posxpicture-1, $tab_top + $tab_height);
1363
-			if (empty($hidetop))
1364
-			{
1365
-				//$pdf->SetXY($this->posxpicture-1, $tab_top+1);
1366
-				//$pdf->MultiCell($this->posxtva-$this->posxpicture-1,2, $outputlangs->transnoentities("Photo"),'','C');
1367
-			}
1368
-		}
1369
-
1370
-		if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
1371
-		{
1372
-			$pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
1373
-			if (empty($hidetop))
1374
-			{
1375
-				// Not do -3 and +3 instead of -1 -1 to have more space for text 'Sales tax'
1376
-				$pdf->SetXY($this->posxtva-3, $tab_top+1);
1377
-				$pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
1378
-			}
1379
-		}
1380
-
1381
-		$pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
1382
-		if (empty($hidetop))
1383
-		{
1384
-			$pdf->SetXY($this->posxup-1, $tab_top+1);
1385
-			$pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
1386
-		}
1387
-
1388
-		$pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
1389
-		if (empty($hidetop))
1390
-		{
1391
-			$pdf->SetXY($this->posxqty-1, $tab_top+1);
1392
-			if($conf->global->PRODUCT_USE_UNITS)
1393
-			{
1394
-				$pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1395
-			}
1396
-			else
1397
-			{
1398
-				$pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1399
-			}
1400
-		}
1401
-
1402
-		if($conf->global->PRODUCT_USE_UNITS) {
1403
-			$pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1404
-			if (empty($hidetop)) {
1405
-				$pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1406
-				$pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '',
1407
-					'C');
1408
-			}
1409
-		}
1291
+            $index++;
1292
+            $pdf->SetTextColor(0,0,60);
1293
+            $pdf->SetFillColor(224,224,224);
1294
+            $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1295
+            $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1410 1296
 
1411
-		$pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
1412
-		if (empty($hidetop))
1413
-		{
1414
-			if ($this->atleastonediscount)
1415
-			{
1416
-				$pdf->SetXY($this->posxdiscount-1, $tab_top+1);
1417
-				$pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
1418
-			}
1419
-		}
1420
-		if ($this->atleastonediscount)
1421
-		{
1422
-			$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1423
-		}
1424
-		if (empty($hidetop))
1425
-		{
1426
-			$pdf->SetXY($this->postotalht-1, $tab_top+1);
1427
-			$pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHT"),'','C');
1428
-		}
1429
-	}
1430
-
1431
-	/**
1432
-	 *  Show top header of page.
1433
-	 *
1434
-	 *  @param	PDF			$pdf     		Object PDF
1435
-	 *  @param  Object		$object     	Object to show
1436
-	 *  @param  int	    	$showaddress    0=no, 1=yes
1437
-	 *  @param  Translate	$outputlangs	Object lang for output
1438
-	 *  @return	void
1439
-	 */
1440
-	function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1441
-	{
1442
-		global $conf,$langs;
1443
-
1444
-		// Load traductions files requiredby by page
1445
-		$outputlangs->loadLangs(array("main", "propal", "companies", "bills"));
1446
-
1447
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
1448
-
1449
-		pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1450
-
1451
-		//  Show Draft Watermark
1452
-		if($object->statut==0 && (! empty($conf->global->PROPALE_DRAFT_WATERMARK)) )
1453
-		{
1454
-            pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->PROPALE_DRAFT_WATERMARK);
1455
-		}
1297
+            $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1298
+            $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1456 1299
 
1457
-		$pdf->SetTextColor(0,0,60);
1458
-		$pdf->SetFont('','B', $default_font_size + 3);
1300
+            $pdf->SetFont('','', $default_font_size - 1);
1301
+            $pdf->SetTextColor(0,0,0);
1302
+        }
1459 1303
 
1460
-		$posy=$this->marge_haute;
1461
-		$posx=$this->page_largeur-$this->marge_droite-100;
1304
+        $index++;
1305
+        return ($tab2_top + ($tab2_hl * $index));
1306
+    }
1462 1307
 
1463
-		$pdf->SetXY($this->marge_gauche,$posy);
1308
+    /**
1309
+     *   Show table for lines
1310
+     *
1311
+     *   @param		PDF			$pdf     		Object PDF
1312
+     *   @param		string		$tab_top		Top position of table
1313
+     *   @param		string		$tab_height		Height of table (rectangle)
1314
+     *   @param		int			$nexY			Y (not used)
1315
+     *   @param		Translate	$outputlangs	Langs object
1316
+     *   @param		int			$hidetop		1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
1317
+     *   @param		int			$hidebottom		Hide bottom bar of array
1318
+     *   @param		string		$currency		Currency code
1319
+     *   @return	void
1320
+     */
1321
+    function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
1322
+    {
1323
+        global $conf;
1324
+
1325
+        // Force to disable hidetop and hidebottom
1326
+        $hidebottom=0;
1327
+        if ($hidetop) $hidetop=-1;
1328
+
1329
+        $currency = !empty($currency) ? $currency : $conf->currency;
1330
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
1331
+
1332
+        // Amount in (at tab_top - 1)
1333
+        $pdf->SetTextColor(0,0,0);
1334
+        $pdf->SetFont('','',$default_font_size - 2);
1335
+
1336
+        if (empty($hidetop))
1337
+        {
1338
+            $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
1339
+            $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
1340
+            $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1341
+
1342
+            //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1343
+            if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1344
+        }
1345
+
1346
+        $pdf->SetDrawColor(128,128,128);
1347
+        $pdf->SetFont('','',$default_font_size - 1);
1348
+
1349
+        // Output Rect
1350
+        $this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom);	// Rect prend une longueur en 3eme param et 4eme param
1351
+
1352
+        if (empty($hidetop))
1353
+        {
1354
+            $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);	// line prend une position y en 2eme param et 4eme param
1355
+
1356
+            $pdf->SetXY($this->posxdesc-1, $tab_top+1);
1357
+            $pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
1358
+        }
1359
+
1360
+        if (! empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE))
1361
+        {
1362
+            $pdf->line($this->posxpicture-1, $tab_top, $this->posxpicture-1, $tab_top + $tab_height);
1363
+            if (empty($hidetop))
1364
+            {
1365
+                //$pdf->SetXY($this->posxpicture-1, $tab_top+1);
1366
+                //$pdf->MultiCell($this->posxtva-$this->posxpicture-1,2, $outputlangs->transnoentities("Photo"),'','C');
1367
+            }
1368
+        }
1369
+
1370
+        if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
1371
+        {
1372
+            $pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
1373
+            if (empty($hidetop))
1374
+            {
1375
+                // Not do -3 and +3 instead of -1 -1 to have more space for text 'Sales tax'
1376
+                $pdf->SetXY($this->posxtva-3, $tab_top+1);
1377
+                $pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
1378
+            }
1379
+        }
1380
+
1381
+        $pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
1382
+        if (empty($hidetop))
1383
+        {
1384
+            $pdf->SetXY($this->posxup-1, $tab_top+1);
1385
+            $pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
1386
+        }
1387
+
1388
+        $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
1389
+        if (empty($hidetop))
1390
+        {
1391
+            $pdf->SetXY($this->posxqty-1, $tab_top+1);
1392
+            if($conf->global->PRODUCT_USE_UNITS)
1393
+            {
1394
+                $pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1395
+            }
1396
+            else
1397
+            {
1398
+                $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1399
+            }
1400
+        }
1401
+
1402
+        if($conf->global->PRODUCT_USE_UNITS) {
1403
+            $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1404
+            if (empty($hidetop)) {
1405
+                $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1406
+                $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '',
1407
+                    'C');
1408
+            }
1409
+        }
1410
+
1411
+        $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
1412
+        if (empty($hidetop))
1413
+        {
1414
+            if ($this->atleastonediscount)
1415
+            {
1416
+                $pdf->SetXY($this->posxdiscount-1, $tab_top+1);
1417
+                $pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
1418
+            }
1419
+        }
1420
+        if ($this->atleastonediscount)
1421
+        {
1422
+            $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1423
+        }
1424
+        if (empty($hidetop))
1425
+        {
1426
+            $pdf->SetXY($this->postotalht-1, $tab_top+1);
1427
+            $pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHT"),'','C');
1428
+        }
1429
+    }
1464 1430
 
1465
-		// Logo
1466
-		if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO))
1467
-		{
1468
-			$logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1469
-			if ($this->emetteur->logo)
1470
-			{
1471
-				if (is_readable($logo))
1472
-				{
1473
-				    $height=pdf_getHeightForLogo($logo);
1474
-				    $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
1475
-				}
1476
-				else
1477
-				{
1478
-					$pdf->SetTextColor(200,0,0);
1479
-					$pdf->SetFont('','B',$default_font_size - 2);
1480
-					$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1481
-					$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1482
-				}
1483
-			}
1484
-			else
1485
-			{
1486
-				$text=$this->emetteur->name;
1487
-				$pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1488
-			}
1489
-		}
1490
-
1491
-		$pdf->SetFont('','B',$default_font_size + 3);
1492
-		$pdf->SetXY($posx,$posy);
1493
-		$pdf->SetTextColor(0,0,60);
1494
-		$title=$outputlangs->transnoentities("PdfCommercialProposalTitle");
1495
-		$pdf->MultiCell(100, 4, $title, '', 'R');
1496
-
1497
-		$pdf->SetFont('','B',$default_font_size);
1498
-
1499
-		$posy+=5;
1500
-		$pdf->SetXY($posx,$posy);
1501
-		$pdf->SetTextColor(0,0,60);
1502
-		$pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
1503
-
1504
-		$posy+=1;
1505
-		$pdf->SetFont('','', $default_font_size - 2);
1506
-
1507
-		if ($object->ref_client)
1508
-		{
1509
-			$posy+=4;
1510
-			$pdf->SetXY($posx,$posy);
1511
-			$pdf->SetTextColor(0,0,60);
1512
-			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1513
-		}
1514
-
1515
-		$posy+=4;
1516
-		$pdf->SetXY($posx,$posy);
1517
-		$pdf->SetTextColor(0,0,60);
1518
-		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date,"day",false,$outputlangs,true), '', 'R');
1519
-
1520
-		$posy+=4;
1521
-		$pdf->SetXY($posx,$posy);
1522
-		$pdf->SetTextColor(0,0,60);
1523
-		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateEndPropal")." : " . dol_print_date($object->fin_validite,"day",false,$outputlangs,true), '', 'R');
1524
-
1525
-		if ($object->thirdparty->code_client)
1526
-		{
1527
-			$posy+=4;
1528
-			$pdf->SetXY($posx,$posy);
1529
-			$pdf->SetTextColor(0,0,60);
1530
-			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1531
-		}
1532
-
1533
-		// Get contact
1534
-		if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1535
-		{
1536
-		    $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1537
-		    if (count($arrayidcontact) > 0)
1538
-		    {
1539
-		        $usertmp=new User($this->db);
1540
-		        $usertmp->fetch($arrayidcontact[0]);
1541
-                $posy+=4;
1542
-                $pdf->SetXY($posx,$posy);
1543
-		        $pdf->SetTextColor(0,0,60);
1544
-		        $pdf->MultiCell(100, 3, $langs->trans("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1545
-		    }
1546
-		}
1547
-
1548
-		$posy+=2;
1549
-
1550
-		$top_shift = 0;
1551
-		// Show list of linked objects
1552
-		$current_y = $pdf->getY();
1553
-		$posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1554
-		if ($current_y < $pdf->getY())
1555
-		{
1556
-			$top_shift = $pdf->getY() - $current_y;
1557
-		}
1558
-
1559
-		if ($showaddress)
1560
-		{
1561
-			// Sender properties
1562
-			$carac_emetteur='';
1563
-		 	// Add internal contact of proposal if defined
1564
-			$arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1565
-		 	if (count($arrayidcontact) > 0)
1566
-		 	{
1567
-		 		$object->fetch_user($arrayidcontact[0]);
1568
-		 		$labelbeforecontactname=($outputlangs->transnoentities("FromContactName")!='FromContactName'?$outputlangs->transnoentities("FromContactName"):$outputlangs->transnoentities("Name"));
1569
-		 		$carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1570
-		 	}
1571
-
1572
-		 	$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1573
-
1574
-			// Show sender
1575
-			$posy=42+$top_shift;
1576
-		 	$posx=$this->marge_gauche;
1577
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1578
-			$hautcadre=40;
1579
-
1580
-			// Show sender frame
1581
-			$pdf->SetTextColor(0,0,0);
1582
-			$pdf->SetFont('','', $default_font_size - 2);
1583
-			$pdf->SetXY($posx,$posy-5);
1584
-			$pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1585
-			$pdf->SetXY($posx,$posy);
1586
-			$pdf->SetFillColor(230,230,230);
1587
-			$pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1588
-			$pdf->SetTextColor(0,0,60);
1589
-
1590
-			// Show sender name
1591
-			$pdf->SetXY($posx+2,$posy+3);
1592
-			$pdf->SetFont('','B', $default_font_size);
1593
-			$pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1594
-			$posy=$pdf->getY();
1595
-
1596
-			// Show sender information
1597
-			$pdf->SetXY($posx+2,$posy);
1598
-			$pdf->SetFont('','', $default_font_size - 1);
1599
-			$pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1600
-
1601
-
1602
-			// If CUSTOMER contact defined, we use it
1603
-			$usecontact=false;
1604
-			$arrayidcontact=$object->getIdContact('external','CUSTOMER');
1605
-			if (count($arrayidcontact) > 0)
1606
-			{
1607
-				$usecontact=true;
1608
-				$result=$object->fetch_contact($arrayidcontact[0]);
1609
-			}
1431
+    /**
1432
+     *  Show top header of page.
1433
+     *
1434
+     *  @param	PDF			$pdf     		Object PDF
1435
+     *  @param  Object		$object     	Object to show
1436
+     *  @param  int	    	$showaddress    0=no, 1=yes
1437
+     *  @param  Translate	$outputlangs	Object lang for output
1438
+     *  @return	void
1439
+     */
1440
+    function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1441
+    {
1442
+        global $conf,$langs;
1610 1443
 
1611
-			//Recipient name
1612
-			// On peut utiliser le nom de la societe du contact
1613
-			if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
1614
-				$thirdparty = $object->contact;
1615
-			} else {
1616
-				$thirdparty = $object->thirdparty;
1617
-			}
1444
+        // Load traductions files requiredby by page
1445
+        $outputlangs->loadLangs(array("main", "propal", "companies", "bills"));
1618 1446
 
1619
-			$carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
1447
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
1620 1448
 
1621
-			$carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target',$object);
1449
+        pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1622 1450
 
1623
-			// Show recipient
1624
-			$widthrecbox=100;
1625
-			if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1626
-			$posy=42+$top_shift;
1627
-			$posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1628
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1451
+        //  Show Draft Watermark
1452
+        if($object->statut==0 && (! empty($conf->global->PROPALE_DRAFT_WATERMARK)) )
1453
+        {
1454
+            pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->PROPALE_DRAFT_WATERMARK);
1455
+        }
1629 1456
 
1630
-			// Show recipient frame
1631
-			$pdf->SetTextColor(0,0,0);
1632
-			$pdf->SetFont('','', $default_font_size - 2);
1633
-			$pdf->SetXY($posx+2,$posy-5);
1634
-			$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":", 0, 'L');
1635
-			$pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1457
+        $pdf->SetTextColor(0,0,60);
1458
+        $pdf->SetFont('','B', $default_font_size + 3);
1636 1459
 
1637
-			// Show recipient name
1638
-			$pdf->SetXY($posx+2,$posy+3);
1639
-			$pdf->SetFont('','B', $default_font_size);
1640
-			$pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1460
+        $posy=$this->marge_haute;
1461
+        $posx=$this->page_largeur-$this->marge_droite-100;
1641 1462
 
1642
-			$posy = $pdf->getY();
1463
+        $pdf->SetXY($this->marge_gauche,$posy);
1643 1464
 
1644
-			// Show recipient information
1645
-			$pdf->SetFont('','', $default_font_size - 1);
1646
-			$pdf->SetXY($posx+2,$posy);
1647
-			$pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1648
-		}
1465
+        // Logo
1466
+        if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO))
1467
+        {
1468
+            $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1469
+            if ($this->emetteur->logo)
1470
+            {
1471
+                if (is_readable($logo))
1472
+                {
1473
+                    $height=pdf_getHeightForLogo($logo);
1474
+                    $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
1475
+                }
1476
+                else
1477
+                {
1478
+                    $pdf->SetTextColor(200,0,0);
1479
+                    $pdf->SetFont('','B',$default_font_size - 2);
1480
+                    $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1481
+                    $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1482
+                }
1483
+            }
1484
+            else
1485
+            {
1486
+                $text=$this->emetteur->name;
1487
+                $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1488
+            }
1489
+        }
1490
+
1491
+        $pdf->SetFont('','B',$default_font_size + 3);
1492
+        $pdf->SetXY($posx,$posy);
1493
+        $pdf->SetTextColor(0,0,60);
1494
+        $title=$outputlangs->transnoentities("PdfCommercialProposalTitle");
1495
+        $pdf->MultiCell(100, 4, $title, '', 'R');
1496
+
1497
+        $pdf->SetFont('','B',$default_font_size);
1498
+
1499
+        $posy+=5;
1500
+        $pdf->SetXY($posx,$posy);
1501
+        $pdf->SetTextColor(0,0,60);
1502
+        $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
1503
+
1504
+        $posy+=1;
1505
+        $pdf->SetFont('','', $default_font_size - 2);
1506
+
1507
+        if ($object->ref_client)
1508
+        {
1509
+            $posy+=4;
1510
+            $pdf->SetXY($posx,$posy);
1511
+            $pdf->SetTextColor(0,0,60);
1512
+            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1513
+        }
1514
+
1515
+        $posy+=4;
1516
+        $pdf->SetXY($posx,$posy);
1517
+        $pdf->SetTextColor(0,0,60);
1518
+        $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date,"day",false,$outputlangs,true), '', 'R');
1519
+
1520
+        $posy+=4;
1521
+        $pdf->SetXY($posx,$posy);
1522
+        $pdf->SetTextColor(0,0,60);
1523
+        $pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateEndPropal")." : " . dol_print_date($object->fin_validite,"day",false,$outputlangs,true), '', 'R');
1524
+
1525
+        if ($object->thirdparty->code_client)
1526
+        {
1527
+            $posy+=4;
1528
+            $pdf->SetXY($posx,$posy);
1529
+            $pdf->SetTextColor(0,0,60);
1530
+            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1531
+        }
1532
+
1533
+        // Get contact
1534
+        if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1535
+        {
1536
+            $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1537
+            if (count($arrayidcontact) > 0)
1538
+            {
1539
+                $usertmp=new User($this->db);
1540
+                $usertmp->fetch($arrayidcontact[0]);
1541
+                $posy+=4;
1542
+                $pdf->SetXY($posx,$posy);
1543
+                $pdf->SetTextColor(0,0,60);
1544
+                $pdf->MultiCell(100, 3, $langs->trans("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1545
+            }
1546
+        }
1547
+
1548
+        $posy+=2;
1549
+
1550
+        $top_shift = 0;
1551
+        // Show list of linked objects
1552
+        $current_y = $pdf->getY();
1553
+        $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1554
+        if ($current_y < $pdf->getY())
1555
+        {
1556
+            $top_shift = $pdf->getY() - $current_y;
1557
+        }
1558
+
1559
+        if ($showaddress)
1560
+        {
1561
+            // Sender properties
1562
+            $carac_emetteur='';
1563
+                // Add internal contact of proposal if defined
1564
+            $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1565
+                if (count($arrayidcontact) > 0)
1566
+                {
1567
+                    $object->fetch_user($arrayidcontact[0]);
1568
+                    $labelbeforecontactname=($outputlangs->transnoentities("FromContactName")!='FromContactName'?$outputlangs->transnoentities("FromContactName"):$outputlangs->transnoentities("Name"));
1569
+                    $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1570
+                }
1649 1571
 
1650
-		$pdf->SetTextColor(0,0,0);
1651
-		return $top_shift;
1652
-	}
1572
+                $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1573
+
1574
+            // Show sender
1575
+            $posy=42+$top_shift;
1576
+                $posx=$this->marge_gauche;
1577
+            if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1578
+            $hautcadre=40;
1579
+
1580
+            // Show sender frame
1581
+            $pdf->SetTextColor(0,0,0);
1582
+            $pdf->SetFont('','', $default_font_size - 2);
1583
+            $pdf->SetXY($posx,$posy-5);
1584
+            $pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1585
+            $pdf->SetXY($posx,$posy);
1586
+            $pdf->SetFillColor(230,230,230);
1587
+            $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1588
+            $pdf->SetTextColor(0,0,60);
1589
+
1590
+            // Show sender name
1591
+            $pdf->SetXY($posx+2,$posy+3);
1592
+            $pdf->SetFont('','B', $default_font_size);
1593
+            $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1594
+            $posy=$pdf->getY();
1595
+
1596
+            // Show sender information
1597
+            $pdf->SetXY($posx+2,$posy);
1598
+            $pdf->SetFont('','', $default_font_size - 1);
1599
+            $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1600
+
1601
+
1602
+            // If CUSTOMER contact defined, we use it
1603
+            $usecontact=false;
1604
+            $arrayidcontact=$object->getIdContact('external','CUSTOMER');
1605
+            if (count($arrayidcontact) > 0)
1606
+            {
1607
+                $usecontact=true;
1608
+                $result=$object->fetch_contact($arrayidcontact[0]);
1609
+            }
1610
+
1611
+            //Recipient name
1612
+            // On peut utiliser le nom de la societe du contact
1613
+            if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
1614
+                $thirdparty = $object->contact;
1615
+            } else {
1616
+                $thirdparty = $object->thirdparty;
1617
+            }
1618
+
1619
+            $carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
1620
+
1621
+            $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target',$object);
1622
+
1623
+            // Show recipient
1624
+            $widthrecbox=100;
1625
+            if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1626
+            $posy=42+$top_shift;
1627
+            $posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1628
+            if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1629
+
1630
+            // Show recipient frame
1631
+            $pdf->SetTextColor(0,0,0);
1632
+            $pdf->SetFont('','', $default_font_size - 2);
1633
+            $pdf->SetXY($posx+2,$posy-5);
1634
+            $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":", 0, 'L');
1635
+            $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1636
+
1637
+            // Show recipient name
1638
+            $pdf->SetXY($posx+2,$posy+3);
1639
+            $pdf->SetFont('','B', $default_font_size);
1640
+            $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1641
+
1642
+            $posy = $pdf->getY();
1643
+
1644
+            // Show recipient information
1645
+            $pdf->SetFont('','', $default_font_size - 1);
1646
+            $pdf->SetXY($posx+2,$posy);
1647
+            $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1648
+        }
1649
+
1650
+        $pdf->SetTextColor(0,0,0);
1651
+        return $top_shift;
1652
+    }
1653 1653
 
1654
-	/**
1655
-	 *   	Show footer of page. Need this->emetteur object
1654
+    /**
1655
+     *   	Show footer of page. Need this->emetteur object
1656 1656
      *
1657
-	 *   	@param	PDF			$pdf     			PDF
1658
-	 * 		@param	Object		$object				Object to show
1659
-	 *      @param	Translate	$outputlangs		Object lang for output
1660
-	 *      @param	int			$hidefreetext		1=Hide free text
1661
-	 *      @return	int								Return height of bottom margin including footer text
1662
-	 */
1663
-	function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1664
-	{
1665
-		global $conf;
1666
-		$showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1667
-		return pdf_pagefoot($pdf,$outputlangs,'PROPOSAL_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1668
-	}
1657
+     *   	@param	PDF			$pdf     			PDF
1658
+     * 		@param	Object		$object				Object to show
1659
+     *      @param	Translate	$outputlangs		Object lang for output
1660
+     *      @param	int			$hidefreetext		1=Hide free text
1661
+     *      @return	int								Return height of bottom margin including footer text
1662
+     */
1663
+    function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1664
+    {
1665
+        global $conf;
1666
+        $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1667
+        return pdf_pagefoot($pdf,$outputlangs,'PROPOSAL_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1668
+    }
1669 1669
 
1670 1670
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1671
-	/**
1672
-	 *	Show area for the customer to sign
1673
-	 *
1674
-	 *	@param	PDF			$pdf            Object PDF
1675
-	 *	@param  Facture		$object         Object invoice
1676
-	 *	@param	int			$posy			Position depart
1677
-	 *	@param	Translate	$outputlangs	Objet langs
1678
-	 *	@return int							Position pour suite
1679
-	 */
1680
-	function _signature_area(&$pdf, $object, $posy, $outputlangs)
1681
-	{
1671
+    /**
1672
+     *	Show area for the customer to sign
1673
+     *
1674
+     *	@param	PDF			$pdf            Object PDF
1675
+     *	@param  Facture		$object         Object invoice
1676
+     *	@param	int			$posy			Position depart
1677
+     *	@param	Translate	$outputlangs	Objet langs
1678
+     *	@return int							Position pour suite
1679
+     */
1680
+    function _signature_area(&$pdf, $object, $posy, $outputlangs)
1681
+    {
1682 1682
         // phpcs:enable
1683
-		global $conf;
1684
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
1685
-		$tab_top = $posy + 4;
1686
-		$tab_hl = 4;
1687
-
1688
-		$posx = 120;
1689
-		$largcol = ($this->page_largeur - $this->marge_droite - $posx);
1690
-		$useborder=0;
1691
-		$index = 0;
1692
-		// Total HT
1693
-		$pdf->SetFillColor(255,255,255);
1694
-		$pdf->SetXY($posx, $tab_top + 0);
1695
-		$pdf->SetFont('','', $default_font_size - 2);
1696
-		$pdf->MultiCell($largcol, $tab_hl, $outputlangs->transnoentities("ProposalCustomerSignature"), 0, 'L', 1);
1697
-
1698
-		$pdf->SetXY($posx, $tab_top + $tab_hl);
1699
-		$pdf->MultiCell($largcol, $tab_hl*3, '', 1, 'R');
1700
-		if (! empty($conf->global->MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING)) {
1701
-			$pdf->addEmptySignatureAppearance($posx, $tab_top + $tab_hl, $largcol, $tab_hl*3);
1702
-		}
1703
-
1704
-		return ($tab_hl*7);
1705
-	}
1683
+        global $conf;
1684
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
1685
+        $tab_top = $posy + 4;
1686
+        $tab_hl = 4;
1687
+
1688
+        $posx = 120;
1689
+        $largcol = ($this->page_largeur - $this->marge_droite - $posx);
1690
+        $useborder=0;
1691
+        $index = 0;
1692
+        // Total HT
1693
+        $pdf->SetFillColor(255,255,255);
1694
+        $pdf->SetXY($posx, $tab_top + 0);
1695
+        $pdf->SetFont('','', $default_font_size - 2);
1696
+        $pdf->MultiCell($largcol, $tab_hl, $outputlangs->transnoentities("ProposalCustomerSignature"), 0, 'L', 1);
1697
+
1698
+        $pdf->SetXY($posx, $tab_top + $tab_hl);
1699
+        $pdf->MultiCell($largcol, $tab_hl*3, '', 1, 'R');
1700
+        if (! empty($conf->global->MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING)) {
1701
+            $pdf->addEmptySignatureAppearance($posx, $tab_top + $tab_hl, $largcol, $tab_hl*3);
1702
+        }
1703
+
1704
+        return ($tab_hl*7);
1705
+    }
1706 1706
 }
Please login to merge, or discard this patch.
Spacing   +476 added lines, -476 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 	 */
128 128
 	function __construct($db)
129 129
 	{
130
-		global $conf,$langs,$mysoc;
130
+		global $conf, $langs, $mysoc;
131 131
 
132 132
 		// Translations
133 133
 		$langs->loadLangs(array("main", "bills"));
@@ -135,71 +135,71 @@  discard block
 block discarded – undo
135 135
 		$this->db = $db;
136 136
 		$this->name = "azur";
137 137
 		$this->description = $langs->trans('DocModelAzurDescription');
138
-		$this->update_main_doc_field = 1;		// Save the name of generated file as the main doc when generating a doc with this template
138
+		$this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
139 139
 
140 140
 		// Dimension page
141 141
 		$this->type = 'pdf';
142
-		$formatarray=pdf_getFormat();
142
+		$formatarray = pdf_getFormat();
143 143
 		$this->page_largeur = $formatarray['width'];
144 144
 		$this->page_hauteur = $formatarray['height'];
145
-		$this->format = array($this->page_largeur,$this->page_hauteur);
146
-		$this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
147
-		$this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
148
-		$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
149
-		$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
150
-
151
-		$this->option_logo = 1;                    // Affiche logo
152
-		$this->option_tva = 1;                     // Gere option tva FACTURE_TVAOPTION
153
-		$this->option_modereg = 1;                 // Affiche mode reglement
154
-		$this->option_condreg = 1;                 // Affiche conditions reglement
155
-		$this->option_codeproduitservice = 1;      // Affiche code produit-service
156
-		$this->option_multilang = 1;               // Dispo en plusieurs langues
157
-		$this->option_escompte = 0;                // Affiche si il y a eu escompte
158
-		$this->option_credit_note = 0;             // Support credit notes
159
-		$this->option_freetext = 1;				   // Support add of a personalised text
160
-		$this->option_draft_watermark = 1;		   //Support add of a watermark on drafts
161
-
162
-		$this->franchise=!$mysoc->tva_assuj;
145
+		$this->format = array($this->page_largeur, $this->page_hauteur);
146
+		$this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
147
+		$this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
148
+		$this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
149
+		$this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
150
+
151
+		$this->option_logo = 1; // Affiche logo
152
+		$this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
153
+		$this->option_modereg = 1; // Affiche mode reglement
154
+		$this->option_condreg = 1; // Affiche conditions reglement
155
+		$this->option_codeproduitservice = 1; // Affiche code produit-service
156
+		$this->option_multilang = 1; // Dispo en plusieurs langues
157
+		$this->option_escompte = 0; // Affiche si il y a eu escompte
158
+		$this->option_credit_note = 0; // Support credit notes
159
+		$this->option_freetext = 1; // Support add of a personalised text
160
+		$this->option_draft_watermark = 1; //Support add of a watermark on drafts
161
+
162
+		$this->franchise = !$mysoc->tva_assuj;
163 163
 
164 164
 		// Get source company
165
-		$this->emetteur=$mysoc;
166
-		if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
165
+		$this->emetteur = $mysoc;
166
+		if (empty($this->emetteur->country_code)) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
167 167
 
168 168
 		// Define position of columns
169
-		$this->posxdesc=$this->marge_gauche+1;
170
-		if($conf->global->PRODUCT_USE_UNITS)
169
+		$this->posxdesc = $this->marge_gauche + 1;
170
+		if ($conf->global->PRODUCT_USE_UNITS)
171 171
 		{
172
-			$this->posxtva=101;
173
-			$this->posxup=118;
174
-			$this->posxqty=135;
175
-			$this->posxunit=151;
172
+			$this->posxtva = 101;
173
+			$this->posxup = 118;
174
+			$this->posxqty = 135;
175
+			$this->posxunit = 151;
176 176
 		}
177 177
 		else
178 178
 		{
179
-			$this->posxtva=110;
180
-			$this->posxup=126;
181
-			$this->posxqty=145;
179
+			$this->posxtva = 110;
180
+			$this->posxup = 126;
181
+			$this->posxqty = 145;
182 182
 		}
183
-		$this->posxdiscount=162;
184
-		$this->postotalht=174;
185
-		if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup;
186
-		$this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);	// width of images
183
+		$this->posxdiscount = 162;
184
+		$this->postotalht = 174;
185
+		if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || !empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva = $this->posxup;
186
+		$this->posxpicture = $this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
187 187
 		if ($this->page_largeur < 210) // To work with US executive format
188 188
 		{
189
-			$this->posxpicture-=20;
190
-			$this->posxtva-=20;
191
-			$this->posxup-=20;
192
-			$this->posxqty-=20;
193
-			$this->posxunit-=20;
194
-			$this->posxdiscount-=20;
195
-			$this->postotalht-=20;
189
+			$this->posxpicture -= 20;
190
+			$this->posxtva -= 20;
191
+			$this->posxup -= 20;
192
+			$this->posxqty -= 20;
193
+			$this->posxunit -= 20;
194
+			$this->posxdiscount -= 20;
195
+			$this->postotalht -= 20;
196 196
 		}
197 197
 
198
-		$this->tva=array();
199
-		$this->localtax1=array();
200
-		$this->localtax2=array();
201
-		$this->atleastoneratenotnull=0;
202
-		$this->atleastonediscount=0;
198
+		$this->tva = array();
199
+		$this->localtax1 = array();
200
+		$this->localtax2 = array();
201
+		$this->atleastoneratenotnull = 0;
202
+		$this->atleastonediscount = 0;
203 203
 	}
204 204
 
205 205
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -214,14 +214,14 @@  discard block
 block discarded – undo
214 214
      *  @param		int			$hideref			Do not show ref
215 215
      *  @return     int             				1=OK, 0=KO
216 216
 	 */
217
-	function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
217
+	function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
218 218
 	{
219 219
         // phpcs:enable
220
-		global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
220
+		global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblignes;
221 221
 
222
-		if (! is_object($outputlangs)) $outputlangs=$langs;
222
+		if (!is_object($outputlangs)) $outputlangs = $langs;
223 223
 		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
224
-		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
224
+		if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1';
225 225
 
226 226
 		// Load traductions files requiredby by page
227 227
 		$outputlangs->loadLangs(array("main", "dict", "companies", "bills", "propal", "products"));
@@ -229,51 +229,51 @@  discard block
 block discarded – undo
229 229
 		$nblignes = count($object->lines);
230 230
 
231 231
 		// Loop on each lines to detect if there is at least one image to show
232
-		$realpatharray=array();
233
-		if (! empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE))
232
+		$realpatharray = array();
233
+		if (!empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE))
234 234
 		{
235 235
 			$objphoto = new Product($this->db);
236 236
 
237
-			for ($i = 0 ; $i < $nblignes ; $i++)
237
+			for ($i = 0; $i < $nblignes; $i++)
238 238
 			{
239 239
 				if (empty($object->lines[$i]->fk_product)) continue;
240 240
 
241 241
 				$objphoto->fetch($object->lines[$i]->fk_product);
242 242
                 //var_dump($objphoto->ref);exit;
243
-				if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
243
+				if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
244 244
 				{
245
-					$pdir[0] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";
246
-					$pdir[1] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';
245
+					$pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
246
+					$pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
247 247
 				}
248 248
 				else
249 249
 				{
250
-					$pdir[0] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';				// default
251
-					$pdir[1] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";	// alternative
250
+					$pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/'; // default
251
+					$pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
252 252
 				}
253 253
 
254 254
 				$arephoto = false;
255 255
 				foreach ($pdir as $midir)
256 256
 				{
257
-					if (! $arephoto)
257
+					if (!$arephoto)
258 258
 					{
259 259
 						$dir = $conf->product->dir_output.'/'.$midir;
260 260
 
261
-						foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
261
+						foreach ($objphoto->liste_photos($dir, 1) as $key => $obj)
262 262
 						{
263 263
 							if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES))		// If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
264 264
 							{
265 265
 								if ($obj['photo_vignette'])
266 266
 								{
267
-									$filename= $obj['photo_vignette'];
267
+									$filename = $obj['photo_vignette'];
268 268
 								}
269 269
 								else
270 270
 								{
271
-									$filename=$obj['photo'];
271
+									$filename = $obj['photo'];
272 272
 								}
273 273
 							}
274 274
 							else
275 275
 							{
276
-								$filename=$obj['photo'];
276
+								$filename = $obj['photo'];
277 277
 							}
278 278
 
279 279
 							$realpath = $dir.$filename;
@@ -282,11 +282,11 @@  discard block
 block discarded – undo
282 282
 					}
283 283
 				}
284 284
 
285
-				if ($realpath && $arephoto) $realpatharray[$i]=$realpath;
285
+				if ($realpath && $arephoto) $realpatharray[$i] = $realpath;
286 286
 			}
287 287
 		}
288 288
 
289
-		if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
289
+		if (count($realpatharray) == 0) $this->posxpicture = $this->posxtva;
290 290
 
291 291
 		if ($conf->propal->multidir_output[$conf->entity])
292 292
 		{
@@ -298,20 +298,20 @@  discard block
 block discarded – undo
298 298
 			if ($object->specimen)
299 299
 			{
300 300
 				$dir = $conf->propal->multidir_output[$conf->entity];
301
-				$file = $dir . "/SPECIMEN.pdf";
301
+				$file = $dir."/SPECIMEN.pdf";
302 302
 			}
303 303
 			else
304 304
 			{
305 305
 				$objectref = dol_sanitizeFileName($object->ref);
306
-				$dir = $conf->propal->multidir_output[$object->entity] . "/" . $objectref;
307
-				$file = $dir . "/" . $objectref . ".pdf";
306
+				$dir = $conf->propal->multidir_output[$object->entity]."/".$objectref;
307
+				$file = $dir."/".$objectref.".pdf";
308 308
 			}
309 309
 
310
-			if (! file_exists($dir))
310
+			if (!file_exists($dir))
311 311
 			{
312 312
 				if (dol_mkdir($dir) < 0)
313 313
 				{
314
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
314
+					$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
315 315
 					return 0;
316 316
 				}
317 317
 			}
@@ -319,20 +319,20 @@  discard block
 block discarded – undo
319 319
 			if (file_exists($dir))
320 320
 			{
321 321
 				// Add pdfgeneration hook
322
-				if (! is_object($hookmanager))
322
+				if (!is_object($hookmanager))
323 323
 				{
324 324
 					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
325
-					$hookmanager=new HookManager($this->db);
325
+					$hookmanager = new HookManager($this->db);
326 326
 				}
327 327
 				$hookmanager->initHooks(array('pdfgeneration'));
328
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
328
+				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
329 329
 				global $action;
330
-				$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
330
+				$reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
331 331
 
332 332
 				// Create pdf instance
333
-                $pdf=pdf_getInstance($this->format);
334
-                $default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
335
-	            $pdf->SetAutoPageBreak(1,0);
333
+                $pdf = pdf_getInstance($this->format);
334
+                $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
335
+	            $pdf->SetAutoPageBreak(1, 0);
336 336
 
337 337
                 if (class_exists('TCPDF'))
338 338
                 {
@@ -341,27 +341,27 @@  discard block
 block discarded – undo
341 341
                 }
342 342
                 $pdf->SetFont(pdf_getPDFFont($outputlangs));
343 343
                 // Set path to the background PDF File
344
-                if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
344
+                if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
345 345
                 {
346 346
                     $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
347 347
                     $tplidx = $pdf->importPage(1);
348 348
                 }
349 349
 
350 350
 				$pdf->Open();
351
-				$pagenb=0;
352
-				$pdf->SetDrawColor(128,128,128);
351
+				$pagenb = 0;
352
+				$pdf->SetDrawColor(128, 128, 128);
353 353
 
354 354
 				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
355 355
 				$pdf->SetSubject($outputlangs->transnoentities("PdfCommercialProposalTitle"));
356 356
 				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
357 357
 				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
358 358
 				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfCommercialProposalTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
359
-				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
359
+				if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
360 360
 
361
-				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
361
+				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
362 362
 
363 363
 				// Positionne $this->atleastonediscount si on a au moins une remise
364
-				for ($i = 0 ; $i < $nblignes ; $i++)
364
+				for ($i = 0; $i < $nblignes; $i++)
365 365
 				{
366 366
 					if ($object->lines[$i]->remise_percent)
367 367
 					{
@@ -370,34 +370,34 @@  discard block
 block discarded – undo
370 370
 				}
371 371
 				if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS))
372 372
 				{
373
-					$this->posxpicture+=($this->postotalht - $this->posxdiscount);
374
-					$this->posxtva+=($this->postotalht - $this->posxdiscount);
375
-					$this->posxup+=($this->postotalht - $this->posxdiscount);
376
-					$this->posxqty+=($this->postotalht - $this->posxdiscount);
377
-					$this->posxdiscount+=($this->postotalht - $this->posxdiscount);
373
+					$this->posxpicture += ($this->postotalht - $this->posxdiscount);
374
+					$this->posxtva += ($this->postotalht - $this->posxdiscount);
375
+					$this->posxup += ($this->postotalht - $this->posxdiscount);
376
+					$this->posxqty += ($this->postotalht - $this->posxdiscount);
377
+					$this->posxdiscount += ($this->postotalht - $this->posxdiscount);
378 378
 					//$this->postotalht;
379 379
 				}
380 380
 
381 381
 				// New page
382 382
 				$pdf->AddPage();
383
-				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
383
+				if (!empty($tplidx)) $pdf->useTemplate($tplidx);
384 384
 				$pagenb++;
385 385
 
386
-                $heightforinfotot = 40;	// Height reserved to output the info and total part
387
-                $heightforsignature = empty($conf->global->PROPAL_DISABLE_SIGNATURE)?(pdfGetHeightForHtmlContent($pdf, $outputlangs->transnoentities("ProposalCustomerSignature"))+10):0;
388
-                $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5);	// Height reserved to output the free text on last page
389
-	            $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
390
-				if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
386
+                $heightforinfotot = 40; // Height reserved to output the info and total part
387
+                $heightforsignature = empty($conf->global->PROPAL_DISABLE_SIGNATURE) ? (pdfGetHeightForHtmlContent($pdf, $outputlangs->transnoentities("ProposalCustomerSignature")) + 10) : 0;
388
+                $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page
389
+	            $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
390
+				if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS > 0) $heightforfooter += 6;
391 391
                 //print $heightforinfotot + $heightforsignature + $heightforfreetext + $heightforfooter;exit;
392 392
 
393 393
 				$top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
394
-				$pdf->SetFont('','', $default_font_size - 1);
395
-				$pdf->MultiCell(0, 3, '');		// Set interline to 3
396
-				$pdf->SetTextColor(0,0,0);
394
+				$pdf->SetFont('', '', $default_font_size - 1);
395
+				$pdf->MultiCell(0, 3, ''); // Set interline to 3
396
+				$pdf->SetTextColor(0, 0, 0);
397 397
 
398 398
 
399
-	            $tab_top = 90+$top_shift;
400
-				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10);
399
+	            $tab_top = 90 + $top_shift;
400
+				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 + $top_shift : 10);
401 401
 
402 402
 				// Incoterm
403 403
 				if ($conf->incoterm->enabled)
@@ -407,58 +407,58 @@  discard block
 block discarded – undo
407 407
 					{
408 408
 						$tab_top -= 2;
409 409
 
410
-						$pdf->SetFont('','', $default_font_size - 1);
411
-						$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
410
+						$pdf->SetFont('', '', $default_font_size - 1);
411
+						$pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
412 412
 						$nexY = $pdf->GetY();
413
-						$height_incoterms=$nexY-$tab_top;
413
+						$height_incoterms = $nexY - $tab_top;
414 414
 
415 415
 						// Rect prend une longueur en 3eme param
416
-						$pdf->SetDrawColor(192,192,192);
417
-						$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
416
+						$pdf->SetDrawColor(192, 192, 192);
417
+						$pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
418 418
 
419
-						$tab_top = $nexY+6;
419
+						$tab_top = $nexY + 6;
420 420
 					}
421 421
 				}
422 422
 
423 423
 				// Affiche notes
424
-				$notetoshow=empty($object->note_public)?'':$object->note_public;
425
-				if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
424
+				$notetoshow = empty($object->note_public) ? '' : $object->note_public;
425
+				if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
426 426
 				{
427 427
 					// Get first sale rep
428 428
 					if (is_object($object->thirdparty))
429 429
 					{
430
-						$salereparray=$object->thirdparty->getSalesRepresentatives($user);
431
-						$salerepobj=new User($this->db);
430
+						$salereparray = $object->thirdparty->getSalesRepresentatives($user);
431
+						$salerepobj = new User($this->db);
432 432
 						$salerepobj->fetch($salereparray[0]['id']);
433
-						if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
433
+						if (!empty($salerepobj->signature)) $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
434 434
 					}
435 435
 				}
436
-				if (! empty($conf->global->MAIN_ADD_CREATOR_IN_NOTE) && $object->user_author_id > 0)
436
+				if (!empty($conf->global->MAIN_ADD_CREATOR_IN_NOTE) && $object->user_author_id > 0)
437 437
 				{
438
-				    $tmpuser=new User($this->db);
438
+				    $tmpuser = new User($this->db);
439 439
 				    $tmpuser->fetch($object->user_author_id);
440
-				    $notetoshow.='Affaire suivi par '.$tmpuser->getFullName($langs);
441
-				    if ($tmpuser->email) $notetoshow.=',  Mail: '.$tmpuser->email;
442
-				    if ($tmpuser->office_phone) $notetoshow.=', Tel: '.$tmpuser->office_phone;
440
+				    $notetoshow .= 'Affaire suivi par '.$tmpuser->getFullName($langs);
441
+				    if ($tmpuser->email) $notetoshow .= ',  Mail: '.$tmpuser->email;
442
+				    if ($tmpuser->office_phone) $notetoshow .= ', Tel: '.$tmpuser->office_phone;
443 443
 				}
444 444
 				if ($notetoshow)
445 445
 				{
446 446
 					$tab_top -= 2;
447 447
 
448
-					$substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
448
+					$substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
449 449
 					complete_substitutions_array($substitutionarray, $outputlangs, $object);
450 450
 					$notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
451 451
 
452
-					$pdf->SetFont('','', $default_font_size - 1);
453
-					$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($notetoshow), 0, 1);
452
+					$pdf->SetFont('', '', $default_font_size - 1);
453
+					$pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
454 454
 					$nexY = $pdf->GetY();
455
-					$height_note=$nexY-$tab_top;
455
+					$height_note = $nexY - $tab_top;
456 456
 
457 457
 					// Rect prend une longueur en 3eme param
458
-					$pdf->SetDrawColor(192,192,192);
459
-					$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
458
+					$pdf->SetDrawColor(192, 192, 192);
459
+					$pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
460 460
 
461
-					$tab_top = $nexY+6;
461
+					$tab_top = $nexY + 6;
462 462
 				}
463 463
 
464 464
 				$iniY = $tab_top + 7;
@@ -469,191 +469,191 @@  discard block
 block discarded – undo
469 469
 				for ($i = 0; $i < $nblignes; $i++)
470 470
 				{
471 471
 					$curY = $nexY;
472
-					$pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
473
-					$pdf->SetTextColor(0,0,0);
472
+					$pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
473
+					$pdf->SetTextColor(0, 0, 0);
474 474
 
475 475
 					// Define size of image if we need it
476
-					$imglinesize=array();
477
-					if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
476
+					$imglinesize = array();
477
+					if (!empty($realpatharray[$i])) $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
478 478
 
479 479
 					$pdf->setTopMargin($tab_top_newpage);
480
-					$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
481
-					$pageposbefore=$pdf->getPage();
480
+					$pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
481
+					$pageposbefore = $pdf->getPage();
482 482
 
483
-					$showpricebeforepagebreak=1;
484
-					$posYAfterImage=0;
485
-					$posYAfterDescription=0;
483
+					$showpricebeforepagebreak = 1;
484
+					$posYAfterImage = 0;
485
+					$posYAfterDescription = 0;
486 486
 
487 487
 					// We start with Photo of product line
488
-					if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot)))	// If photo too high, we moved completely on new page
488
+					if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot)))	// If photo too high, we moved completely on new page
489 489
 					{
490
-						$pdf->AddPage('','',true);
491
-						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
490
+						$pdf->AddPage('', '', true);
491
+						if (!empty($tplidx)) $pdf->useTemplate($tplidx);
492 492
 						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
493
-						$pdf->setPage($pageposbefore+1);
493
+						$pdf->setPage($pageposbefore + 1);
494 494
 
495 495
 						$curY = $tab_top_newpage;
496
-						$showpricebeforepagebreak=0;
496
+						$showpricebeforepagebreak = 0;
497 497
 					}
498 498
 
499 499
 					if (isset($imglinesize['width']) && isset($imglinesize['height']))
500 500
 					{
501
-						$curX = $this->posxpicture-1;
502
-						$pdf->Image($realpatharray[$i], $curX + (($this->posxtva-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);	// Use 300 dpi
501
+						$curX = $this->posxpicture - 1;
502
+						$pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
503 503
 						// $pdf->Image does not increase value return by getY, so we save it manually
504
-						$posYAfterImage=$curY+$imglinesize['height'];
504
+						$posYAfterImage = $curY + $imglinesize['height'];
505 505
 					}
506 506
 
507 507
 					// Description of product line
508
-					$curX = $this->posxdesc-1;
508
+					$curX = $this->posxdesc - 1;
509 509
 
510 510
 					$pdf->startTransaction();
511
-					pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc);
512
-					$pageposafter=$pdf->getPage();
511
+					pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
512
+					$pageposafter = $pdf->getPage();
513 513
 					if ($pageposafter > $pageposbefore)	// There is a pagebreak
514 514
 					{
515 515
 						$pdf->rollbackTransaction(true);
516
-						$pageposafter=$pageposbefore;
516
+						$pageposafter = $pageposbefore;
517 517
 						//print $pageposafter.'-'.$pageposbefore;exit;
518
-						$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
519
-						pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc);
518
+						$pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
519
+						pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
520 520
 
521
-						$pageposafter=$pdf->getPage();
522
-						$posyafter=$pdf->GetY();
521
+						$pageposafter = $pdf->getPage();
522
+						$posyafter = $pdf->GetY();
523 523
 						//var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
524
-						if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot)))	// There is no space left for total+free text
524
+						if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot)))	// There is no space left for total+free text
525 525
 						{
526
-							if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
526
+							if ($i == ($nblignes - 1))	// No more lines, and no space left to show total, so we create a new page
527 527
 							{
528
-								$pdf->AddPage('','',true);
529
-								if (! empty($tplidx)) $pdf->useTemplate($tplidx);
528
+								$pdf->AddPage('', '', true);
529
+								if (!empty($tplidx)) $pdf->useTemplate($tplidx);
530 530
 								if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
531
-								$pdf->setPage($pageposafter+1);
531
+								$pdf->setPage($pageposafter + 1);
532 532
 							}
533 533
 						}
534 534
 						else
535 535
 						{
536 536
 							// We found a page break
537
-							$showpricebeforepagebreak=0;
537
+							$showpricebeforepagebreak = 0;
538 538
 						}
539 539
 					}
540 540
 					else	// No pagebreak
541 541
 					{
542 542
 						$pdf->commitTransaction();
543 543
 					}
544
-					$posYAfterDescription=$pdf->GetY();
544
+					$posYAfterDescription = $pdf->GetY();
545 545
 
546 546
 					$nexY = $pdf->GetY();
547
-					$pageposafter=$pdf->getPage();
547
+					$pageposafter = $pdf->getPage();
548 548
 
549 549
 					$pdf->setPage($pageposbefore);
550 550
 					$pdf->setTopMargin($this->marge_haute);
551
-					$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
551
+					$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
552 552
 
553 553
 					// We suppose that a too long description or photo were moved completely on next page
554 554
 					if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
555 555
 						$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
556 556
 					}
557 557
 
558
-					$pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
558
+					$pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
559 559
 
560 560
 					// VAT Rate
561 561
 					if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
562 562
 					{
563 563
 						$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
564
-						$pdf->SetXY($this->posxtva-5, $curY);
565
-						$pdf->MultiCell($this->posxup-$this->posxtva+4, 3, $vat_rate, 0, 'R');
564
+						$pdf->SetXY($this->posxtva - 5, $curY);
565
+						$pdf->MultiCell($this->posxup - $this->posxtva + 4, 3, $vat_rate, 0, 'R');
566 566
 					}
567 567
 
568 568
 					// Unit price before discount
569 569
 					$up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
570 570
 					$pdf->SetXY($this->posxup, $curY);
571
-					$pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
571
+					$pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', 0);
572 572
 
573 573
 					// Quantity
574 574
 					$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
575 575
 					$pdf->SetXY($this->posxqty, $curY);
576 576
 					// Enough for 6 chars
577
-					if($conf->global->PRODUCT_USE_UNITS)
577
+					if ($conf->global->PRODUCT_USE_UNITS)
578 578
 					{
579
-						$pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R');
579
+						$pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R');
580 580
 					}
581 581
 					else
582 582
 					{
583
-						$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $qty, 0, 'R');
583
+						$pdf->MultiCell($this->posxdiscount - $this->posxqty - 0.8, 4, $qty, 0, 'R');
584 584
 					}
585 585
 
586 586
 					// Unit
587
-					if($conf->global->PRODUCT_USE_UNITS)
587
+					if ($conf->global->PRODUCT_USE_UNITS)
588 588
 					{
589 589
 						$unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
590 590
 						$pdf->SetXY($this->posxunit, $curY);
591
-						$pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
591
+						$pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
592 592
 					}
593 593
 
594 594
 					// Discount on line
595 595
 					$pdf->SetXY($this->posxdiscount, $curY);
596 596
 					if ($object->lines[$i]->remise_percent)
597 597
 					{
598
-						$pdf->SetXY($this->posxdiscount-2, $curY);
598
+						$pdf->SetXY($this->posxdiscount - 2, $curY);
599 599
 						$remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
600
-						$pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R');
600
+						$pdf->MultiCell($this->postotalht - $this->posxdiscount + 2, 3, $remise_percent, 0, 'R');
601 601
 					}
602 602
 
603 603
 					// Total HT line
604 604
 					$total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
605 605
 					$pdf->SetXY($this->postotalht, $curY);
606
-					$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
606
+					$pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
607 607
 
608 608
 					// Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
609
-					if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
610
-					else $tvaligne=$object->lines[$i]->total_tva;
609
+					if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne = $object->lines[$i]->multicurrency_total_tva;
610
+					else $tvaligne = $object->lines[$i]->total_tva;
611 611
 
612
-					$localtax1ligne=$object->lines[$i]->total_localtax1;
613
-					$localtax2ligne=$object->lines[$i]->total_localtax2;
614
-					$localtax1_rate=$object->lines[$i]->localtax1_tx;
615
-					$localtax2_rate=$object->lines[$i]->localtax2_tx;
616
-					$localtax1_type=$object->lines[$i]->localtax1_type;
617
-					$localtax2_type=$object->lines[$i]->localtax2_type;
612
+					$localtax1ligne = $object->lines[$i]->total_localtax1;
613
+					$localtax2ligne = $object->lines[$i]->total_localtax2;
614
+					$localtax1_rate = $object->lines[$i]->localtax1_tx;
615
+					$localtax2_rate = $object->lines[$i]->localtax2_tx;
616
+					$localtax1_type = $object->lines[$i]->localtax1_type;
617
+					$localtax2_type = $object->lines[$i]->localtax2_type;
618 618
 
619
-					if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
620
-					if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
621
-					if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
619
+					if ($object->remise_percent) $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
620
+					if ($object->remise_percent) $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
621
+					if ($object->remise_percent) $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
622 622
 
623
-					$vatrate=(string) $object->lines[$i]->tva_tx;
623
+					$vatrate = (string) $object->lines[$i]->tva_tx;
624 624
 
625 625
 					// Retrieve type from database for backward compatibility with old records
626
-					if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
627
-					&& (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
626
+					if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
627
+					&& (!empty($localtax1_rate) || !empty($localtax2_rate))) // and there is local tax
628 628
 					{
629
-						$localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc);
629
+						$localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
630 630
 						$localtax1_type = $localtaxtmp_array[0];
631 631
 						$localtax2_type = $localtaxtmp_array[2];
632 632
 					}
633 633
 
634 634
 				    // retrieve global local tax
635 635
 					if ($localtax1_type && $localtax1ligne != 0)
636
-						$this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
636
+						$this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
637 637
 					if ($localtax2_type && $localtax2ligne != 0)
638
-						$this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
638
+						$this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
639 639
 
640
-					if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
641
-					if (! isset($this->tva[$vatrate]))				$this->tva[$vatrate]=0;
640
+					if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate .= '*';
641
+					if (!isset($this->tva[$vatrate]))				$this->tva[$vatrate] = 0;
642 642
 					$this->tva[$vatrate] += $tvaligne;
643 643
 
644
-					if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
644
+					if ($posYAfterImage > $posYAfterDescription) $nexY = $posYAfterImage;
645 645
 
646 646
 					// Add line
647
-					if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
647
+					if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
648 648
 					{
649 649
 						$pdf->setPage($pageposafter);
650
-						$pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
650
+						$pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
651 651
 						//$pdf->SetDrawColor(190,190,200);
652
-						$pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
652
+						$pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
653 653
 						$pdf->SetLineStyle(array('dash'=>0));
654 654
 					}
655 655
 
656
-					$nexY+=2;    // Passe espace entre les lignes
656
+					$nexY += 2; // Passe espace entre les lignes
657 657
 
658 658
 					// Detect if some page were added automatically and output _tableau for past pages
659 659
 					while ($pagenb < $pageposafter)
@@ -667,13 +667,13 @@  discard block
 block discarded – undo
667 667
 						{
668 668
 							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
669 669
 						}
670
-						$this->_pagefoot($pdf,$object,$outputlangs,1);
670
+						$this->_pagefoot($pdf, $object, $outputlangs, 1);
671 671
 						$pagenb++;
672 672
 						$pdf->setPage($pagenb);
673
-						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
673
+						$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
674 674
 						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
675 675
 					}
676
-					if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
676
+					if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak)
677 677
 					{
678 678
 						if ($pagenb == 1)
679 679
 						{
@@ -683,10 +683,10 @@  discard block
 block discarded – undo
683 683
 						{
684 684
 							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
685 685
 						}
686
-						$this->_pagefoot($pdf,$object,$outputlangs,1);
686
+						$this->_pagefoot($pdf, $object, $outputlangs, 1);
687 687
 						// New page
688 688
 						$pdf->AddPage();
689
-						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
689
+						if (!empty($tplidx)) $pdf->useTemplate($tplidx);
690 690
 						$pagenb++;
691 691
 						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
692 692
 					}
@@ -696,19 +696,19 @@  discard block
 block discarded – undo
696 696
 				if ($pagenb == 1)
697 697
 				{
698 698
 					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
699
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
699
+					$bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
700 700
 				}
701 701
 				else
702 702
 				{
703 703
 					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
704
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
704
+					$bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
705 705
 				}
706 706
 
707 707
 				// Affiche zone infos
708
-				$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
708
+				$posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
709 709
 
710 710
 				// Affiche zone totaux
711
-				$posy=$this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs);
711
+				$posy = $this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs);
712 712
 
713 713
 				// Affiche zone versements
714 714
 				/*
@@ -721,21 +721,21 @@  discard block
 block discarded – undo
721 721
 				// Customer signature area
722 722
 				if (empty($conf->global->PROPAL_DISABLE_SIGNATURE))
723 723
 				{
724
-				    $posy=$this->_signature_area($pdf, $object, $posy, $outputlangs);
724
+				    $posy = $this->_signature_area($pdf, $object, $posy, $outputlangs);
725 725
 				}
726 726
 
727 727
 				// Pied de page
728
-				$this->_pagefoot($pdf,$object,$outputlangs);
729
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
728
+				$this->_pagefoot($pdf, $object, $outputlangs);
729
+				if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
730 730
 
731 731
 				//If propal merge product PDF is active
732 732
 				if (!empty($conf->global->PRODUIT_PDF_MERGE_PROPAL))
733 733
 				{
734 734
 					require_once DOL_DOCUMENT_ROOT.'/product/class/propalmergepdfproduct.class.php';
735 735
 
736
-					$already_merged = array ();
737
-					foreach ( $object->lines as $line ) {
738
-						if (! empty($line->fk_product) && ! (in_array($line->fk_product, $already_merged))) {
736
+					$already_merged = array();
737
+					foreach ($object->lines as $line) {
738
+						if (!empty($line->fk_product) && !(in_array($line->fk_product, $already_merged))) {
739 739
 							// Find the desire PDF
740 740
 							$filetomerge = new Propalmergepdfproduct($this->db);
741 741
 
@@ -750,48 +750,48 @@  discard block
 block discarded – undo
750 750
 							$product = new Product($this->db);
751 751
 							$product->fetch($line->fk_product);
752 752
 
753
-							if ($product->entity!=$conf->entity) {
754
-								$entity_product_file=$product->entity;
753
+							if ($product->entity != $conf->entity) {
754
+								$entity_product_file = $product->entity;
755 755
 							} else {
756
-								$entity_product_file=$conf->entity;
756
+								$entity_product_file = $conf->entity;
757 757
 							}
758 758
 
759 759
 							// If PDF is selected and file is not empty
760 760
 							if (count($filetomerge->lines) > 0) {
761
-								foreach ( $filetomerge->lines as $linefile ) {
762
-									if (! empty($linefile->id) && ! empty($linefile->file_name)) {
761
+								foreach ($filetomerge->lines as $linefile) {
762
+									if (!empty($linefile->id) && !empty($linefile->file_name)) {
763 763
 
764 764
 
765
-										if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
765
+										if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
766 766
 										{
767
-											if (! empty($conf->product->enabled)) {
768
-												$filetomerge_dir = $conf->product->multidir_output[$entity_product_file] . '/' . get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos";
769
-											} elseif (! empty($conf->service->enabled)) {
770
-												$filetomerge_dir = $conf->service->multidir_output[$entity_product_file] . '/' . get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos";
767
+											if (!empty($conf->product->enabled)) {
768
+												$filetomerge_dir = $conf->product->multidir_output[$entity_product_file].'/'.get_exdir($product->id, 2, 0, 0, $product, 'product').$product->id."/photos";
769
+											} elseif (!empty($conf->service->enabled)) {
770
+												$filetomerge_dir = $conf->service->multidir_output[$entity_product_file].'/'.get_exdir($product->id, 2, 0, 0, $product, 'product').$product->id."/photos";
771 771
 											}
772 772
 										}
773 773
 										else
774 774
 										{
775
-											if (! empty($conf->product->enabled)) {
776
-												$filetomerge_dir = $conf->product->multidir_output[$entity_product_file] . '/' . get_exdir(0,0,0,0,$product,'product') . dol_sanitizeFileName($product->ref);
777
-											} elseif (! empty($conf->service->enabled)) {
778
-												$filetomerge_dir = $conf->service->multidir_output[$entity_product_file] . '/' . get_exdir(0,0,0,0,$product,'product') . dol_sanitizeFileName($product->ref);
775
+											if (!empty($conf->product->enabled)) {
776
+												$filetomerge_dir = $conf->product->multidir_output[$entity_product_file].'/'.get_exdir(0, 0, 0, 0, $product, 'product').dol_sanitizeFileName($product->ref);
777
+											} elseif (!empty($conf->service->enabled)) {
778
+												$filetomerge_dir = $conf->service->multidir_output[$entity_product_file].'/'.get_exdir(0, 0, 0, 0, $product, 'product').dol_sanitizeFileName($product->ref);
779 779
 											}
780 780
 										}
781 781
 
782
-										dol_syslog(get_class($this) . ':: upload_dir=' . $filetomerge_dir, LOG_DEBUG);
782
+										dol_syslog(get_class($this).':: upload_dir='.$filetomerge_dir, LOG_DEBUG);
783 783
 
784
-										$infile = $filetomerge_dir . '/' . $linefile->file_name;
784
+										$infile = $filetomerge_dir.'/'.$linefile->file_name;
785 785
 										if (file_exists($infile) && is_readable($infile)) {
786 786
 											$pagecount = $pdf->setSourceFile($infile);
787
-											for($i = 1; $i <= $pagecount; $i ++) {
787
+											for ($i = 1; $i <= $pagecount; $i++) {
788 788
 												$tplIdx = $pdf->importPage($i);
789
-												if ($tplIdx!==false) {
789
+												if ($tplIdx !== false) {
790 790
 													$s = $pdf->getTemplatesize($tplIdx);
791 791
 													$pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
792 792
 													$pdf->useTemplate($tplIdx);
793 793
 												} else {
794
-													setEventMessages(null, array($infile.' cannot be added, probably protected PDF'),'warnings');
794
+													setEventMessages(null, array($infile.' cannot be added, probably protected PDF'), 'warnings');
795 795
 												}
796 796
 											}
797 797
 										}
@@ -804,30 +804,30 @@  discard block
 block discarded – undo
804 804
 
805 805
 				$pdf->Close();
806 806
 
807
-				$pdf->Output($file,'F');
807
+				$pdf->Output($file, 'F');
808 808
 
809 809
 				//Add pdfgeneration hook
810 810
 				$hookmanager->initHooks(array('pdfgeneration'));
811
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
811
+				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
812 812
 				global $action;
813
-				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
813
+				$reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
814 814
 
815
-				if (! empty($conf->global->MAIN_UMASK))
815
+				if (!empty($conf->global->MAIN_UMASK))
816 816
 				@chmod($file, octdec($conf->global->MAIN_UMASK));
817 817
 
818 818
 				$this->result = array('fullpath'=>$file);
819 819
 
820
-				return 1;   // Pas d'erreur
820
+				return 1; // Pas d'erreur
821 821
 			}
822 822
 			else
823 823
 			{
824
-				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
824
+				$this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
825 825
 				return 0;
826 826
 			}
827 827
 		}
828 828
 		else
829 829
 		{
830
-			$this->error=$langs->trans("ErrorConstantNotDefined","PROP_OUTPUTDIR");
830
+			$this->error = $langs->trans("ErrorConstantNotDefined", "PROP_OUTPUTDIR");
831 831
 			return 0;
832 832
 		}
833 833
 	}
@@ -864,66 +864,66 @@  discard block
 block discarded – undo
864 864
 		global $conf;
865 865
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
866 866
 
867
-		$pdf->SetFont('','', $default_font_size - 1);
867
+		$pdf->SetFont('', '', $default_font_size - 1);
868 868
 
869 869
 		// If France, show VAT mention if not applicable
870 870
 		if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
871 871
 		{
872
-			$pdf->SetFont('','B', $default_font_size - 2);
872
+			$pdf->SetFont('', 'B', $default_font_size - 2);
873 873
 			$pdf->SetXY($this->marge_gauche, $posy);
874 874
 			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
875 875
 
876
-			$posy=$pdf->GetY()+4;
876
+			$posy = $pdf->GetY() + 4;
877 877
 		}
878 878
 
879
-		$posxval=52;
879
+		$posxval = 52;
880 880
 
881 881
         // Show shipping date
882
-        if (! empty($object->date_livraison))
882
+        if (!empty($object->date_livraison))
883 883
 		{
884 884
             $outputlangs->load("sendings");
885
-			$pdf->SetFont('','B', $default_font_size - 2);
885
+			$pdf->SetFont('', 'B', $default_font_size - 2);
886 886
 			$pdf->SetXY($this->marge_gauche, $posy);
887 887
 			$titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
888 888
 			$pdf->MultiCell(80, 4, $titre, 0, 'L');
889
-			$pdf->SetFont('','', $default_font_size - 2);
889
+			$pdf->SetFont('', '', $default_font_size - 2);
890 890
 			$pdf->SetXY($posxval, $posy);
891
-			$dlp=dol_print_date($object->date_livraison,"daytext",false,$outputlangs,true);
891
+			$dlp = dol_print_date($object->date_livraison, "daytext", false, $outputlangs, true);
892 892
 			$pdf->MultiCell(80, 4, $dlp, 0, 'L');
893 893
 
894
-            $posy=$pdf->GetY()+1;
894
+            $posy = $pdf->GetY() + 1;
895 895
 		}
896 896
         elseif ($object->availability_code || $object->availability)    // Show availability conditions
897 897
 		{
898
-			$pdf->SetFont('','B', $default_font_size - 2);
898
+			$pdf->SetFont('', 'B', $default_font_size - 2);
899 899
 			$pdf->SetXY($this->marge_gauche, $posy);
900 900
 			$titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
901 901
 			$pdf->MultiCell(80, 4, $titre, 0, 'L');
902
-			$pdf->SetTextColor(0,0,0);
903
-			$pdf->SetFont('','', $default_font_size - 2);
902
+			$pdf->SetTextColor(0, 0, 0);
903
+			$pdf->SetFont('', '', $default_font_size - 2);
904 904
 			$pdf->SetXY($posxval, $posy);
905
-			$lib_availability=$outputlangs->transnoentities("AvailabilityType".$object->availability_code)!=('AvailabilityType'.$object->availability_code)?$outputlangs->transnoentities("AvailabilityType".$object->availability_code):$outputlangs->convToOutputCharset($object->availability);
906
-			$lib_availability=str_replace('\n',"\n",$lib_availability);
905
+			$lib_availability = $outputlangs->transnoentities("AvailabilityType".$object->availability_code) != ('AvailabilityType'.$object->availability_code) ? $outputlangs->transnoentities("AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset($object->availability);
906
+			$lib_availability = str_replace('\n', "\n", $lib_availability);
907 907
 			$pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
908 908
 
909
-			$posy=$pdf->GetY()+1;
909
+			$posy = $pdf->GetY() + 1;
910 910
 		}
911 911
 
912 912
 		// Show payments conditions
913 913
 		if (empty($conf->global->PROPALE_PDF_HIDE_PAYMENTTERMCOND) && ($object->cond_reglement_code || $object->cond_reglement))
914 914
 		{
915
-			$pdf->SetFont('','B', $default_font_size - 2);
915
+			$pdf->SetFont('', 'B', $default_font_size - 2);
916 916
 			$pdf->SetXY($this->marge_gauche, $posy);
917 917
 			$titre = $outputlangs->transnoentities("PaymentConditions").':';
918 918
 			$pdf->MultiCell(43, 4, $titre, 0, 'L');
919 919
 
920
-			$pdf->SetFont('','', $default_font_size - 2);
920
+			$pdf->SetFont('', '', $default_font_size - 2);
921 921
 			$pdf->SetXY($posxval, $posy);
922
-			$lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc);
923
-			$lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
924
-			$pdf->MultiCell(67, 4, $lib_condition_paiement,0,'L');
922
+			$lib_condition_paiement = $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) != ('PaymentCondition'.$object->cond_reglement_code) ? $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc);
923
+			$lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
924
+			$pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
925 925
 
926
-			$posy=$pdf->GetY()+3;
926
+			$posy = $pdf->GetY() + 3;
927 927
 		}
928 928
 
929 929
 		if (empty($conf->global->PROPALE_PDF_HIDE_PAYMENTTERMMODE))
@@ -949,25 +949,25 @@  discard block
 block discarded – undo
949 949
 			&& $object->mode_reglement_code != 'CHQ'
950 950
 			&& $object->mode_reglement_code != 'VIR')
951 951
 			{
952
-				$pdf->SetFont('','B', $default_font_size - 2);
952
+				$pdf->SetFont('', 'B', $default_font_size - 2);
953 953
 				$pdf->SetXY($this->marge_gauche, $posy);
954 954
 				$titre = $outputlangs->transnoentities("PaymentMode").':';
955 955
 				$pdf->MultiCell(80, 5, $titre, 0, 'L');
956
-				$pdf->SetFont('','', $default_font_size - 2);
956
+				$pdf->SetFont('', '', $default_font_size - 2);
957 957
 				$pdf->SetXY($posxval, $posy);
958
-				$lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement);
959
-				$pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
958
+				$lib_mode_reg = $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) != ('PaymentType'.$object->mode_reglement_code) ? $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) : $outputlangs->convToOutputCharset($object->mode_reglement);
959
+				$pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
960 960
 
961
-				$posy=$pdf->GetY()+2;
961
+				$posy = $pdf->GetY() + 2;
962 962
 			}
963 963
 
964 964
 			// Show payment mode CHQ
965 965
 			if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
966 966
 			{
967 967
 				// Si mode reglement non force ou si force a CHQ
968
-				if (! empty($conf->global->FACTURE_CHQ_NUMBER))
968
+				if (!empty($conf->global->FACTURE_CHQ_NUMBER))
969 969
 				{
970
-					$diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
970
+					$diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
971 971
 
972 972
 					if ($conf->global->FACTURE_CHQ_NUMBER > 0)
973 973
 					{
@@ -975,31 +975,31 @@  discard block
 block discarded – undo
975 975
 						$account->fetch($conf->global->FACTURE_CHQ_NUMBER);
976 976
 
977 977
 						$pdf->SetXY($this->marge_gauche, $posy);
978
-						$pdf->SetFont('','B', $default_font_size - $diffsizetitle);
979
-						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio),0,'L',0);
980
-						$posy=$pdf->GetY()+1;
978
+						$pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
979
+						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0);
980
+						$posy = $pdf->GetY() + 1;
981 981
 
982 982
 			            if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
983 983
 			            {
984 984
 							$pdf->SetXY($this->marge_gauche, $posy);
985
-							$pdf->SetFont('','', $default_font_size - $diffsizetitle);
985
+							$pdf->SetFont('', '', $default_font_size - $diffsizetitle);
986 986
 							$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
987
-							$posy=$pdf->GetY()+2;
987
+							$posy = $pdf->GetY() + 2;
988 988
 			            }
989 989
 					}
990 990
 					if ($conf->global->FACTURE_CHQ_NUMBER == -1)
991 991
 					{
992 992
 						$pdf->SetXY($this->marge_gauche, $posy);
993
-						$pdf->SetFont('','B', $default_font_size - $diffsizetitle);
994
-						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$this->emetteur->name),0,'L',0);
995
-						$posy=$pdf->GetY()+1;
993
+						$pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
994
+						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
995
+						$posy = $pdf->GetY() + 1;
996 996
 
997 997
 			            if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
998 998
 			            {
999 999
 							$pdf->SetXY($this->marge_gauche, $posy);
1000
-							$pdf->SetFont('','', $default_font_size - $diffsizetitle);
1000
+							$pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1001 1001
 							$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1002
-							$posy=$pdf->GetY()+2;
1002
+							$posy = $pdf->GetY() + 2;
1003 1003
 			            }
1004 1004
 					}
1005 1005
 				}
@@ -1008,19 +1008,19 @@  discard block
 block discarded – undo
1008 1008
 			// If payment mode not forced or forced to VIR, show payment with BAN
1009 1009
 			if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
1010 1010
 			{
1011
-				if (! empty($object->fk_account) || ! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
1011
+				if (!empty($object->fk_account) || !empty($object->fk_bank) || !empty($conf->global->FACTURE_RIB_NUMBER))
1012 1012
 				{
1013
-					$bankid=(empty($object->fk_account)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_account);
1014
-					if (! empty($object->fk_bank)) $bankid=$object->fk_bank;   // For backward compatibility when object->fk_account is forced with object->fk_bank
1013
+					$bankid = (empty($object->fk_account) ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1014
+					if (!empty($object->fk_bank)) $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1015 1015
 					$account = new Account($this->db);
1016 1016
 					$account->fetch($bankid);
1017 1017
 
1018
-					$curx=$this->marge_gauche;
1019
-					$cury=$posy;
1018
+					$curx = $this->marge_gauche;
1019
+					$cury = $posy;
1020 1020
 
1021
-					$posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size);
1021
+					$posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1022 1022
 
1023
-					$posy+=2;
1023
+					$posy += 2;
1024 1024
 				}
1025 1025
 			}
1026 1026
 		}
@@ -1043,43 +1043,43 @@  discard block
 block discarded – undo
1043 1043
 	function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
1044 1044
 	{
1045 1045
         // phpcs:enable
1046
-		global $conf,$mysoc;
1046
+		global $conf, $mysoc;
1047 1047
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
1048 1048
 
1049 1049
 		$tab2_top = $posy;
1050 1050
 		$tab2_hl = 4;
1051
-		$pdf->SetFont('','', $default_font_size - 1);
1051
+		$pdf->SetFont('', '', $default_font_size - 1);
1052 1052
 
1053 1053
 		// Tableau total
1054 1054
 		$col1x = 120; $col2x = 170;
1055 1055
 		if ($this->page_largeur < 210) // To work with US executive format
1056 1056
 		{
1057
-			$col2x-=20;
1057
+			$col2x -= 20;
1058 1058
 		}
1059 1059
 		$largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1060 1060
 
1061
-		$useborder=0;
1061
+		$useborder = 0;
1062 1062
 		$index = 0;
1063 1063
 
1064 1064
 		// Total HT
1065
-		$pdf->SetFillColor(255,255,255);
1065
+		$pdf->SetFillColor(255, 255, 255);
1066 1066
 		$pdf->SetXY($col1x, $tab2_top + 0);
1067
-		$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1067
+		$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1068 1068
 
1069 1069
 		$total_ht = (($conf->multicurrency->enabled && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1070 1070
 		$pdf->SetXY($col2x, $tab2_top + 0);
1071
-		$pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (! empty($object->remise)?$object->remise:0), 0, $outputlangs), 0, 'R', 1);
1071
+		$pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0, 'R', 1);
1072 1072
 
1073 1073
 		// Show VAT by rates and total
1074
-		$pdf->SetFillColor(248,248,248);
1074
+		$pdf->SetFillColor(248, 248, 248);
1075 1075
 
1076 1076
 		$total_ttc = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1077 1077
 
1078
-		$this->atleastoneratenotnull=0;
1078
+		$this->atleastoneratenotnull = 0;
1079 1079
 		if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1080 1080
 		{
1081
-			$tvaisnull=((! empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1082
-			if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1081
+			$tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1082
+			if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1083 1083
 			{
1084 1084
 				// Nothing to do
1085 1085
 			}
@@ -1088,28 +1088,28 @@  discard block
 block discarded – undo
1088 1088
 				//Local tax 1 before VAT
1089 1089
 				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1090 1090
 				//{
1091
-					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1091
+					foreach ($this->localtax1 as $localtax_type => $localtax_rate)
1092 1092
 					{
1093
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1093
+						if (in_array((string) $localtax_type, array('1', '3', '5'))) continue;
1094 1094
 
1095
-						foreach( $localtax_rate as $tvakey => $tvaval )
1095
+						foreach ($localtax_rate as $tvakey => $tvaval)
1096 1096
 						{
1097
-							if ($tvakey!=0)    // On affiche pas taux 0
1097
+							if ($tvakey != 0)    // On affiche pas taux 0
1098 1098
 							{
1099 1099
 								//$this->atleastoneratenotnull++;
1100 1100
 
1101 1101
 								$index++;
1102 1102
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1103 1103
 
1104
-								$tvacompl='';
1105
-								if (preg_match('/\*/',$tvakey))
1104
+								$tvacompl = '';
1105
+								if (preg_match('/\*/', $tvakey))
1106 1106
 								{
1107
-									$tvakey=str_replace('*','',$tvakey);
1107
+									$tvakey = str_replace('*', '', $tvakey);
1108 1108
 									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1109 1109
 								}
1110
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1111
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1112
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1110
+								$totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
1111
+								$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1112
+								$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1113 1113
 
1114 1114
 								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1115 1115
 								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
@@ -1120,13 +1120,13 @@  discard block
 block discarded – undo
1120 1120
 				//Local tax 2 before VAT
1121 1121
 				//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1122 1122
 				//{
1123
-					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1123
+					foreach ($this->localtax2 as $localtax_type => $localtax_rate)
1124 1124
 					{
1125
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1125
+						if (in_array((string) $localtax_type, array('1', '3', '5'))) continue;
1126 1126
 
1127
-						foreach( $localtax_rate as $tvakey => $tvaval )
1127
+						foreach ($localtax_rate as $tvakey => $tvaval)
1128 1128
 						{
1129
-							if ($tvakey!=0)    // On affiche pas taux 0
1129
+							if ($tvakey != 0)    // On affiche pas taux 0
1130 1130
 							{
1131 1131
 								//$this->atleastoneratenotnull++;
1132 1132
 
@@ -1135,15 +1135,15 @@  discard block
 block discarded – undo
1135 1135
 								$index++;
1136 1136
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1137 1137
 
1138
-								$tvacompl='';
1139
-								if (preg_match('/\*/',$tvakey))
1138
+								$tvacompl = '';
1139
+								if (preg_match('/\*/', $tvakey))
1140 1140
 								{
1141
-									$tvakey=str_replace('*','',$tvakey);
1141
+									$tvakey = str_replace('*', '', $tvakey);
1142 1142
 									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1143 1143
 								}
1144 1144
 								$totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1145
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1146
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1145
+								$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1146
+								$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1147 1147
 
1148 1148
 								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1149 1149
 								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
@@ -1152,7 +1152,7 @@  discard block
 block discarded – undo
1152 1152
 					}
1153 1153
 				//}
1154 1154
 				// VAT
1155
-				foreach($this->tva as $tvakey => $tvaval)
1155
+				foreach ($this->tva as $tvakey => $tvaval)
1156 1156
 				{
1157 1157
 					if ($tvakey != 0)    // On affiche pas taux 0
1158 1158
 					{
@@ -1161,15 +1161,15 @@  discard block
 block discarded – undo
1161 1161
 						$index++;
1162 1162
 						$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1163 1163
 
1164
-						$tvacompl='';
1165
-						if (preg_match('/\*/',$tvakey))
1164
+						$tvacompl = '';
1165
+						if (preg_match('/\*/', $tvakey))
1166 1166
 						{
1167
-							$tvakey=str_replace('*','',$tvakey);
1167
+							$tvakey = str_replace('*', '', $tvakey);
1168 1168
 							$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1169 1169
 						}
1170
-						$totalvat =$outputlangs->transcountrynoentities("TotalVAT",$mysoc->country_code).' ';
1171
-						$totalvat.=vatrate($tvakey,1).$tvacompl;
1172
-						$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1170
+						$totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
1171
+						$totalvat .= vatrate($tvakey, 1).$tvacompl;
1172
+						$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1173 1173
 
1174 1174
 						$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1175 1175
 						$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
@@ -1179,11 +1179,11 @@  discard block
 block discarded – undo
1179 1179
 				//Local tax 1 after VAT
1180 1180
 				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1181 1181
 				//{
1182
-					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1182
+					foreach ($this->localtax1 as $localtax_type => $localtax_rate)
1183 1183
 					{
1184
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1184
+						if (in_array((string) $localtax_type, array('2', '4', '6'))) continue;
1185 1185
 
1186
-						foreach( $localtax_rate as $tvakey => $tvaval )
1186
+						foreach ($localtax_rate as $tvakey => $tvaval)
1187 1187
 						{
1188 1188
 							if ($tvakey != 0)    // On affiche pas taux 0
1189 1189
 							{
@@ -1192,16 +1192,16 @@  discard block
 block discarded – undo
1192 1192
 								$index++;
1193 1193
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1194 1194
 
1195
-								$tvacompl='';
1196
-								if (preg_match('/\*/',$tvakey))
1195
+								$tvacompl = '';
1196
+								if (preg_match('/\*/', $tvakey))
1197 1197
 								{
1198
-									$tvakey=str_replace('*','',$tvakey);
1198
+									$tvakey = str_replace('*', '', $tvakey);
1199 1199
 									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1200 1200
 								}
1201
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1201
+								$totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
1202 1202
 
1203
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1204
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1203
+								$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1204
+								$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1205 1205
 								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1206 1206
 								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1207 1207
 							}
@@ -1211,11 +1211,11 @@  discard block
 block discarded – undo
1211 1211
 				//Local tax 2 after VAT
1212 1212
 				//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1213 1213
 				//{
1214
-					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1214
+					foreach ($this->localtax2 as $localtax_type => $localtax_rate)
1215 1215
 					{
1216
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1216
+						if (in_array((string) $localtax_type, array('2', '4', '6'))) continue;
1217 1217
 
1218
-						foreach( $localtax_rate as $tvakey => $tvaval )
1218
+						foreach ($localtax_rate as $tvakey => $tvaval)
1219 1219
 						{
1220 1220
 						    // retrieve global local tax
1221 1221
 							if ($tvakey != 0)    // On affiche pas taux 0
@@ -1225,16 +1225,16 @@  discard block
 block discarded – undo
1225 1225
 								$index++;
1226 1226
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1227 1227
 
1228
-								$tvacompl='';
1229
-								if (preg_match('/\*/',$tvakey))
1228
+								$tvacompl = '';
1229
+								if (preg_match('/\*/', $tvakey))
1230 1230
 								{
1231
-									$tvakey=str_replace('*','',$tvakey);
1231
+									$tvakey = str_replace('*', '', $tvakey);
1232 1232
 									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1233 1233
 								}
1234
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1234
+								$totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1235 1235
 
1236
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1237
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1236
+								$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1237
+								$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1238 1238
 
1239 1239
 								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1240 1240
 								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
@@ -1246,16 +1246,16 @@  discard block
 block discarded – undo
1246 1246
 				// Total TTC
1247 1247
 				$index++;
1248 1248
 				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1249
-				$pdf->SetTextColor(0,0,60);
1250
-				$pdf->SetFillColor(224,224,224);
1251
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1249
+				$pdf->SetTextColor(0, 0, 60);
1250
+				$pdf->SetFillColor(224, 224, 224);
1251
+				$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1252 1252
 
1253 1253
 				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1254 1254
 				$pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1255 1255
 			}
1256 1256
 		}
1257 1257
 
1258
-		$pdf->SetTextColor(0,0,0);
1258
+		$pdf->SetTextColor(0, 0, 0);
1259 1259
 
1260 1260
 		/*
1261 1261
 		$resteapayer = $object->total_ttc - $deja_regle;
@@ -1267,7 +1267,7 @@  discard block
 block discarded – undo
1267 1267
 			$index++;
1268 1268
 
1269 1269
 			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1270
-			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
1270
+			$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
1271 1271
 
1272 1272
 			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1273 1273
 			$pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
@@ -1289,16 +1289,16 @@  discard block
 block discarded – undo
1289 1289
 			*/
1290 1290
 
1291 1291
 			$index++;
1292
-			$pdf->SetTextColor(0,0,60);
1293
-			$pdf->SetFillColor(224,224,224);
1292
+			$pdf->SetTextColor(0, 0, 60);
1293
+			$pdf->SetFillColor(224, 224, 224);
1294 1294
 			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1295
-			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1295
+			$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1296 1296
 
1297 1297
 			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1298 1298
 			$pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1299 1299
 
1300
-			$pdf->SetFont('','', $default_font_size - 1);
1301
-			$pdf->SetTextColor(0,0,0);
1300
+			$pdf->SetFont('', '', $default_font_size - 1);
1301
+			$pdf->SetTextColor(0, 0, 0);
1302 1302
 		}
1303 1303
 
1304 1304
 		$index++;
@@ -1318,48 +1318,48 @@  discard block
 block discarded – undo
1318 1318
 	 *   @param		string		$currency		Currency code
1319 1319
 	 *   @return	void
1320 1320
 	 */
1321
-	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
1321
+	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1322 1322
 	{
1323 1323
 		global $conf;
1324 1324
 
1325 1325
 		// Force to disable hidetop and hidebottom
1326
-		$hidebottom=0;
1327
-		if ($hidetop) $hidetop=-1;
1326
+		$hidebottom = 0;
1327
+		if ($hidetop) $hidetop = -1;
1328 1328
 
1329 1329
 		$currency = !empty($currency) ? $currency : $conf->currency;
1330 1330
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
1331 1331
 
1332 1332
 		// Amount in (at tab_top - 1)
1333
-		$pdf->SetTextColor(0,0,0);
1334
-		$pdf->SetFont('','',$default_font_size - 2);
1333
+		$pdf->SetTextColor(0, 0, 0);
1334
+		$pdf->SetFont('', '', $default_font_size - 2);
1335 1335
 
1336 1336
 		if (empty($hidetop))
1337 1337
 		{
1338
-			$titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
1339
-			$pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
1338
+			$titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1339
+			$pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1340 1340
 			$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1341 1341
 
1342 1342
 			//$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1343
-			if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1343
+			if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1344 1344
 		}
1345 1345
 
1346
-		$pdf->SetDrawColor(128,128,128);
1347
-		$pdf->SetFont('','',$default_font_size - 1);
1346
+		$pdf->SetDrawColor(128, 128, 128);
1347
+		$pdf->SetFont('', '', $default_font_size - 1);
1348 1348
 
1349 1349
 		// Output Rect
1350
-		$this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom);	// Rect prend une longueur en 3eme param et 4eme param
1350
+		$this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect prend une longueur en 3eme param et 4eme param
1351 1351
 
1352 1352
 		if (empty($hidetop))
1353 1353
 		{
1354
-			$pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);	// line prend une position y en 2eme param et 4eme param
1354
+			$pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5); // line prend une position y en 2eme param et 4eme param
1355 1355
 
1356
-			$pdf->SetXY($this->posxdesc-1, $tab_top+1);
1357
-			$pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
1356
+			$pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1357
+			$pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
1358 1358
 		}
1359 1359
 
1360
-		if (! empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE))
1360
+		if (!empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE))
1361 1361
 		{
1362
-			$pdf->line($this->posxpicture-1, $tab_top, $this->posxpicture-1, $tab_top + $tab_height);
1362
+			$pdf->line($this->posxpicture - 1, $tab_top, $this->posxpicture - 1, $tab_top + $tab_height);
1363 1363
 			if (empty($hidetop))
1364 1364
 			{
1365 1365
 				//$pdf->SetXY($this->posxpicture-1, $tab_top+1);
@@ -1369,37 +1369,37 @@  discard block
 block discarded – undo
1369 1369
 
1370 1370
 		if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
1371 1371
 		{
1372
-			$pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
1372
+			$pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
1373 1373
 			if (empty($hidetop))
1374 1374
 			{
1375 1375
 				// Not do -3 and +3 instead of -1 -1 to have more space for text 'Sales tax'
1376
-				$pdf->SetXY($this->posxtva-3, $tab_top+1);
1377
-				$pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
1376
+				$pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1377
+				$pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
1378 1378
 			}
1379 1379
 		}
1380 1380
 
1381
-		$pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
1381
+		$pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
1382 1382
 		if (empty($hidetop))
1383 1383
 		{
1384
-			$pdf->SetXY($this->posxup-1, $tab_top+1);
1385
-			$pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
1384
+			$pdf->SetXY($this->posxup - 1, $tab_top + 1);
1385
+			$pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
1386 1386
 		}
1387 1387
 
1388
-		$pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
1388
+		$pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1389 1389
 		if (empty($hidetop))
1390 1390
 		{
1391
-			$pdf->SetXY($this->posxqty-1, $tab_top+1);
1392
-			if($conf->global->PRODUCT_USE_UNITS)
1391
+			$pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1392
+			if ($conf->global->PRODUCT_USE_UNITS)
1393 1393
 			{
1394
-				$pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1394
+				$pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
1395 1395
 			}
1396 1396
 			else
1397 1397
 			{
1398
-				$pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1398
+				$pdf->MultiCell($this->posxdiscount - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
1399 1399
 			}
1400 1400
 		}
1401 1401
 
1402
-		if($conf->global->PRODUCT_USE_UNITS) {
1402
+		if ($conf->global->PRODUCT_USE_UNITS) {
1403 1403
 			$pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1404 1404
 			if (empty($hidetop)) {
1405 1405
 				$pdf->SetXY($this->posxunit - 1, $tab_top + 1);
@@ -1408,13 +1408,13 @@  discard block
 block discarded – undo
1408 1408
 			}
1409 1409
 		}
1410 1410
 
1411
-		$pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
1411
+		$pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1412 1412
 		if (empty($hidetop))
1413 1413
 		{
1414 1414
 			if ($this->atleastonediscount)
1415 1415
 			{
1416
-				$pdf->SetXY($this->posxdiscount-1, $tab_top+1);
1417
-				$pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
1416
+				$pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1417
+				$pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
1418 1418
 			}
1419 1419
 		}
1420 1420
 		if ($this->atleastonediscount)
@@ -1423,8 +1423,8 @@  discard block
 block discarded – undo
1423 1423
 		}
1424 1424
 		if (empty($hidetop))
1425 1425
 		{
1426
-			$pdf->SetXY($this->postotalht-1, $tab_top+1);
1427
-			$pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHT"),'','C');
1426
+			$pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1427
+			$pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
1428 1428
 		}
1429 1429
 	}
1430 1430
 
@@ -1439,113 +1439,113 @@  discard block
 block discarded – undo
1439 1439
 	 */
1440 1440
 	function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1441 1441
 	{
1442
-		global $conf,$langs;
1442
+		global $conf, $langs;
1443 1443
 
1444 1444
 		// Load traductions files requiredby by page
1445 1445
 		$outputlangs->loadLangs(array("main", "propal", "companies", "bills"));
1446 1446
 
1447 1447
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
1448 1448
 
1449
-		pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1449
+		pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
1450 1450
 
1451 1451
 		//  Show Draft Watermark
1452
-		if($object->statut==0 && (! empty($conf->global->PROPALE_DRAFT_WATERMARK)) )
1452
+		if ($object->statut == 0 && (!empty($conf->global->PROPALE_DRAFT_WATERMARK)))
1453 1453
 		{
1454
-            pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->PROPALE_DRAFT_WATERMARK);
1454
+            pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->PROPALE_DRAFT_WATERMARK);
1455 1455
 		}
1456 1456
 
1457
-		$pdf->SetTextColor(0,0,60);
1458
-		$pdf->SetFont('','B', $default_font_size + 3);
1457
+		$pdf->SetTextColor(0, 0, 60);
1458
+		$pdf->SetFont('', 'B', $default_font_size + 3);
1459 1459
 
1460
-		$posy=$this->marge_haute;
1461
-		$posx=$this->page_largeur-$this->marge_droite-100;
1460
+		$posy = $this->marge_haute;
1461
+		$posx = $this->page_largeur - $this->marge_droite - 100;
1462 1462
 
1463
-		$pdf->SetXY($this->marge_gauche,$posy);
1463
+		$pdf->SetXY($this->marge_gauche, $posy);
1464 1464
 
1465 1465
 		// Logo
1466 1466
 		if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO))
1467 1467
 		{
1468
-			$logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1468
+			$logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1469 1469
 			if ($this->emetteur->logo)
1470 1470
 			{
1471 1471
 				if (is_readable($logo))
1472 1472
 				{
1473
-				    $height=pdf_getHeightForLogo($logo);
1474
-				    $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
1473
+				    $height = pdf_getHeightForLogo($logo);
1474
+				    $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1475 1475
 				}
1476 1476
 				else
1477 1477
 				{
1478
-					$pdf->SetTextColor(200,0,0);
1479
-					$pdf->SetFont('','B',$default_font_size - 2);
1480
-					$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1478
+					$pdf->SetTextColor(200, 0, 0);
1479
+					$pdf->SetFont('', 'B', $default_font_size - 2);
1480
+					$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1481 1481
 					$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1482 1482
 				}
1483 1483
 			}
1484 1484
 			else
1485 1485
 			{
1486
-				$text=$this->emetteur->name;
1486
+				$text = $this->emetteur->name;
1487 1487
 				$pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1488 1488
 			}
1489 1489
 		}
1490 1490
 
1491
-		$pdf->SetFont('','B',$default_font_size + 3);
1492
-		$pdf->SetXY($posx,$posy);
1493
-		$pdf->SetTextColor(0,0,60);
1494
-		$title=$outputlangs->transnoentities("PdfCommercialProposalTitle");
1491
+		$pdf->SetFont('', 'B', $default_font_size + 3);
1492
+		$pdf->SetXY($posx, $posy);
1493
+		$pdf->SetTextColor(0, 0, 60);
1494
+		$title = $outputlangs->transnoentities("PdfCommercialProposalTitle");
1495 1495
 		$pdf->MultiCell(100, 4, $title, '', 'R');
1496 1496
 
1497
-		$pdf->SetFont('','B',$default_font_size);
1497
+		$pdf->SetFont('', 'B', $default_font_size);
1498 1498
 
1499
-		$posy+=5;
1500
-		$pdf->SetXY($posx,$posy);
1501
-		$pdf->SetTextColor(0,0,60);
1502
-		$pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
1499
+		$posy += 5;
1500
+		$pdf->SetXY($posx, $posy);
1501
+		$pdf->SetTextColor(0, 0, 60);
1502
+		$pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
1503 1503
 
1504
-		$posy+=1;
1505
-		$pdf->SetFont('','', $default_font_size - 2);
1504
+		$posy += 1;
1505
+		$pdf->SetFont('', '', $default_font_size - 2);
1506 1506
 
1507 1507
 		if ($object->ref_client)
1508 1508
 		{
1509
-			$posy+=4;
1510
-			$pdf->SetXY($posx,$posy);
1511
-			$pdf->SetTextColor(0,0,60);
1512
-			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1509
+			$posy += 4;
1510
+			$pdf->SetXY($posx, $posy);
1511
+			$pdf->SetTextColor(0, 0, 60);
1512
+			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1513 1513
 		}
1514 1514
 
1515
-		$posy+=4;
1516
-		$pdf->SetXY($posx,$posy);
1517
-		$pdf->SetTextColor(0,0,60);
1518
-		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date,"day",false,$outputlangs,true), '', 'R');
1515
+		$posy += 4;
1516
+		$pdf->SetXY($posx, $posy);
1517
+		$pdf->SetTextColor(0, 0, 60);
1518
+		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
1519 1519
 
1520
-		$posy+=4;
1521
-		$pdf->SetXY($posx,$posy);
1522
-		$pdf->SetTextColor(0,0,60);
1523
-		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateEndPropal")." : " . dol_print_date($object->fin_validite,"day",false,$outputlangs,true), '', 'R');
1520
+		$posy += 4;
1521
+		$pdf->SetXY($posx, $posy);
1522
+		$pdf->SetTextColor(0, 0, 60);
1523
+		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateEndPropal")." : ".dol_print_date($object->fin_validite, "day", false, $outputlangs, true), '', 'R');
1524 1524
 
1525 1525
 		if ($object->thirdparty->code_client)
1526 1526
 		{
1527
-			$posy+=4;
1528
-			$pdf->SetXY($posx,$posy);
1529
-			$pdf->SetTextColor(0,0,60);
1530
-			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1527
+			$posy += 4;
1528
+			$pdf->SetXY($posx, $posy);
1529
+			$pdf->SetTextColor(0, 0, 60);
1530
+			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1531 1531
 		}
1532 1532
 
1533 1533
 		// Get contact
1534 1534
 		if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1535 1535
 		{
1536
-		    $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1536
+		    $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1537 1537
 		    if (count($arrayidcontact) > 0)
1538 1538
 		    {
1539
-		        $usertmp=new User($this->db);
1539
+		        $usertmp = new User($this->db);
1540 1540
 		        $usertmp->fetch($arrayidcontact[0]);
1541
-                $posy+=4;
1542
-                $pdf->SetXY($posx,$posy);
1543
-		        $pdf->SetTextColor(0,0,60);
1541
+                $posy += 4;
1542
+                $pdf->SetXY($posx, $posy);
1543
+		        $pdf->SetTextColor(0, 0, 60);
1544 1544
 		        $pdf->MultiCell(100, 3, $langs->trans("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1545 1545
 		    }
1546 1546
 		}
1547 1547
 
1548
-		$posy+=2;
1548
+		$posy += 2;
1549 1549
 
1550 1550
 		$top_shift = 0;
1551 1551
 		// Show list of linked objects
@@ -1559,53 +1559,53 @@  discard block
 block discarded – undo
1559 1559
 		if ($showaddress)
1560 1560
 		{
1561 1561
 			// Sender properties
1562
-			$carac_emetteur='';
1562
+			$carac_emetteur = '';
1563 1563
 		 	// Add internal contact of proposal if defined
1564
-			$arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1564
+			$arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1565 1565
 		 	if (count($arrayidcontact) > 0)
1566 1566
 		 	{
1567 1567
 		 		$object->fetch_user($arrayidcontact[0]);
1568
-		 		$labelbeforecontactname=($outputlangs->transnoentities("FromContactName")!='FromContactName'?$outputlangs->transnoentities("FromContactName"):$outputlangs->transnoentities("Name"));
1569
-		 		$carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1568
+		 		$labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
1569
+		 		$carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1570 1570
 		 	}
1571 1571
 
1572 1572
 		 	$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1573 1573
 
1574 1574
 			// Show sender
1575
-			$posy=42+$top_shift;
1576
-		 	$posx=$this->marge_gauche;
1577
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1578
-			$hautcadre=40;
1575
+			$posy = 42 + $top_shift;
1576
+		 	$posx = $this->marge_gauche;
1577
+			if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->page_largeur - $this->marge_droite - 80;
1578
+			$hautcadre = 40;
1579 1579
 
1580 1580
 			// Show sender frame
1581
-			$pdf->SetTextColor(0,0,0);
1582
-			$pdf->SetFont('','', $default_font_size - 2);
1583
-			$pdf->SetXY($posx,$posy-5);
1584
-			$pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1585
-			$pdf->SetXY($posx,$posy);
1586
-			$pdf->SetFillColor(230,230,230);
1581
+			$pdf->SetTextColor(0, 0, 0);
1582
+			$pdf->SetFont('', '', $default_font_size - 2);
1583
+			$pdf->SetXY($posx, $posy - 5);
1584
+			$pdf->MultiCell(66, 5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1585
+			$pdf->SetXY($posx, $posy);
1586
+			$pdf->SetFillColor(230, 230, 230);
1587 1587
 			$pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1588
-			$pdf->SetTextColor(0,0,60);
1588
+			$pdf->SetTextColor(0, 0, 60);
1589 1589
 
1590 1590
 			// Show sender name
1591
-			$pdf->SetXY($posx+2,$posy+3);
1592
-			$pdf->SetFont('','B', $default_font_size);
1591
+			$pdf->SetXY($posx + 2, $posy + 3);
1592
+			$pdf->SetFont('', 'B', $default_font_size);
1593 1593
 			$pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1594
-			$posy=$pdf->getY();
1594
+			$posy = $pdf->getY();
1595 1595
 
1596 1596
 			// Show sender information
1597
-			$pdf->SetXY($posx+2,$posy);
1598
-			$pdf->SetFont('','', $default_font_size - 1);
1597
+			$pdf->SetXY($posx + 2, $posy);
1598
+			$pdf->SetFont('', '', $default_font_size - 1);
1599 1599
 			$pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1600 1600
 
1601 1601
 
1602 1602
 			// If CUSTOMER contact defined, we use it
1603
-			$usecontact=false;
1604
-			$arrayidcontact=$object->getIdContact('external','CUSTOMER');
1603
+			$usecontact = false;
1604
+			$arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
1605 1605
 			if (count($arrayidcontact) > 0)
1606 1606
 			{
1607
-				$usecontact=true;
1608
-				$result=$object->fetch_contact($arrayidcontact[0]);
1607
+				$usecontact = true;
1608
+				$result = $object->fetch_contact($arrayidcontact[0]);
1609 1609
 			}
1610 1610
 
1611 1611
 			//Recipient name
@@ -1616,38 +1616,38 @@  discard block
 block discarded – undo
1616 1616
 				$thirdparty = $object->thirdparty;
1617 1617
 			}
1618 1618
 
1619
-			$carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
1619
+			$carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1620 1620
 
1621
-			$carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target',$object);
1621
+			$carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, 'target', $object);
1622 1622
 
1623 1623
 			// Show recipient
1624
-			$widthrecbox=100;
1625
-			if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1626
-			$posy=42+$top_shift;
1627
-			$posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1628
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1624
+			$widthrecbox = 100;
1625
+			if ($this->page_largeur < 210) $widthrecbox = 84; // To work with US executive format
1626
+			$posy = 42 + $top_shift;
1627
+			$posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1628
+			if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->marge_gauche;
1629 1629
 
1630 1630
 			// Show recipient frame
1631
-			$pdf->SetTextColor(0,0,0);
1632
-			$pdf->SetFont('','', $default_font_size - 2);
1633
-			$pdf->SetXY($posx+2,$posy-5);
1631
+			$pdf->SetTextColor(0, 0, 0);
1632
+			$pdf->SetFont('', '', $default_font_size - 2);
1633
+			$pdf->SetXY($posx + 2, $posy - 5);
1634 1634
 			$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":", 0, 'L');
1635 1635
 			$pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1636 1636
 
1637 1637
 			// Show recipient name
1638
-			$pdf->SetXY($posx+2,$posy+3);
1639
-			$pdf->SetFont('','B', $default_font_size);
1638
+			$pdf->SetXY($posx + 2, $posy + 3);
1639
+			$pdf->SetFont('', 'B', $default_font_size);
1640 1640
 			$pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1641 1641
 
1642 1642
 			$posy = $pdf->getY();
1643 1643
 
1644 1644
 			// Show recipient information
1645
-			$pdf->SetFont('','', $default_font_size - 1);
1646
-			$pdf->SetXY($posx+2,$posy);
1645
+			$pdf->SetFont('', '', $default_font_size - 1);
1646
+			$pdf->SetXY($posx + 2, $posy);
1647 1647
 			$pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1648 1648
 		}
1649 1649
 
1650
-		$pdf->SetTextColor(0,0,0);
1650
+		$pdf->SetTextColor(0, 0, 0);
1651 1651
 		return $top_shift;
1652 1652
 	}
1653 1653
 
@@ -1660,11 +1660,11 @@  discard block
 block discarded – undo
1660 1660
 	 *      @param	int			$hidefreetext		1=Hide free text
1661 1661
 	 *      @return	int								Return height of bottom margin including footer text
1662 1662
 	 */
1663
-	function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1663
+	function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1664 1664
 	{
1665 1665
 		global $conf;
1666
-		$showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1667
-		return pdf_pagefoot($pdf,$outputlangs,'PROPOSAL_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1666
+		$showdetails = $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1667
+		return pdf_pagefoot($pdf, $outputlangs, 'PROPOSAL_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1668 1668
 	}
1669 1669
 
1670 1670
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -1687,20 +1687,20 @@  discard block
 block discarded – undo
1687 1687
 
1688 1688
 		$posx = 120;
1689 1689
 		$largcol = ($this->page_largeur - $this->marge_droite - $posx);
1690
-		$useborder=0;
1690
+		$useborder = 0;
1691 1691
 		$index = 0;
1692 1692
 		// Total HT
1693
-		$pdf->SetFillColor(255,255,255);
1693
+		$pdf->SetFillColor(255, 255, 255);
1694 1694
 		$pdf->SetXY($posx, $tab_top + 0);
1695
-		$pdf->SetFont('','', $default_font_size - 2);
1695
+		$pdf->SetFont('', '', $default_font_size - 2);
1696 1696
 		$pdf->MultiCell($largcol, $tab_hl, $outputlangs->transnoentities("ProposalCustomerSignature"), 0, 'L', 1);
1697 1697
 
1698 1698
 		$pdf->SetXY($posx, $tab_top + $tab_hl);
1699
-		$pdf->MultiCell($largcol, $tab_hl*3, '', 1, 'R');
1700
-		if (! empty($conf->global->MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING)) {
1701
-			$pdf->addEmptySignatureAppearance($posx, $tab_top + $tab_hl, $largcol, $tab_hl*3);
1699
+		$pdf->MultiCell($largcol, $tab_hl * 3, '', 1, 'R');
1700
+		if (!empty($conf->global->MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING)) {
1701
+			$pdf->addEmptySignatureAppearance($posx, $tab_top + $tab_hl, $largcol, $tab_hl * 3);
1702 1702
 		}
1703 1703
 
1704
-		return ($tab_hl*7);
1704
+		return ($tab_hl * 7);
1705 1705
 	}
1706 1706
 }
Please login to merge, or discard this patch.
Braces   +188 added lines, -96 removed lines patch added patch discarded remove patch
@@ -163,7 +163,10 @@  discard block
 block discarded – undo
163 163
 
164 164
 		// Get source company
165 165
 		$this->emetteur=$mysoc;
166
-		if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
166
+		if (empty($this->emetteur->country_code)) {
167
+		    $this->emetteur->country_code=substr($langs->defaultlang,-2);
168
+		}
169
+		// By default, if was not defined
167 170
 
168 171
 		// Define position of columns
169 172
 		$this->posxdesc=$this->marge_gauche+1;
@@ -173,8 +176,7 @@  discard block
 block discarded – undo
173 176
 			$this->posxup=118;
174 177
 			$this->posxqty=135;
175 178
 			$this->posxunit=151;
176
-		}
177
-		else
179
+		} else
178 180
 		{
179 181
 			$this->posxtva=110;
180 182
 			$this->posxup=126;
@@ -182,11 +184,15 @@  discard block
 block discarded – undo
182 184
 		}
183 185
 		$this->posxdiscount=162;
184 186
 		$this->postotalht=174;
185
-		if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup;
187
+		if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
188
+		    $this->posxtva=$this->posxup;
189
+		}
186 190
 		$this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);	// width of images
187
-		if ($this->page_largeur < 210) // To work with US executive format
191
+		if ($this->page_largeur < 210) {
192
+		    // To work with US executive format
188 193
 		{
189 194
 			$this->posxpicture-=20;
195
+		}
190 196
 			$this->posxtva-=20;
191 197
 			$this->posxup-=20;
192 198
 			$this->posxqty-=20;
@@ -219,9 +225,13 @@  discard block
 block discarded – undo
219 225
         // phpcs:enable
220 226
 		global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
221 227
 
222
-		if (! is_object($outputlangs)) $outputlangs=$langs;
228
+		if (! is_object($outputlangs)) {
229
+		    $outputlangs=$langs;
230
+		}
223 231
 		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
224
-		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
232
+		if (! empty($conf->global->MAIN_USE_FPDF)) {
233
+		    $outputlangs->charset_output='ISO-8859-1';
234
+		}
225 235
 
226 236
 		// Load traductions files requiredby by page
227 237
 		$outputlangs->loadLangs(array("main", "dict", "companies", "bills", "propal", "products"));
@@ -236,7 +246,9 @@  discard block
 block discarded – undo
236 246
 
237 247
 			for ($i = 0 ; $i < $nblignes ; $i++)
238 248
 			{
239
-				if (empty($object->lines[$i]->fk_product)) continue;
249
+				if (empty($object->lines[$i]->fk_product)) {
250
+				    continue;
251
+				}
240 252
 
241 253
 				$objphoto->fetch($object->lines[$i]->fk_product);
242 254
                 //var_dump($objphoto->ref);exit;
@@ -244,8 +256,7 @@  discard block
 block discarded – undo
244 256
 				{
245 257
 					$pdir[0] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";
246 258
 					$pdir[1] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';
247
-				}
248
-				else
259
+				} else
249 260
 				{
250 261
 					$pdir[0] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';				// default
251 262
 					$pdir[1] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";	// alternative
@@ -260,18 +271,18 @@  discard block
 block discarded – undo
260 271
 
261 272
 						foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
262 273
 						{
263
-							if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES))		// If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
274
+							if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) {
275
+							    // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
264 276
 							{
265 277
 								if ($obj['photo_vignette'])
266 278
 								{
267 279
 									$filename= $obj['photo_vignette'];
268
-								}
269
-								else
280
+							}
281
+								} else
270 282
 								{
271 283
 									$filename=$obj['photo'];
272 284
 								}
273
-							}
274
-							else
285
+							} else
275 286
 							{
276 287
 								$filename=$obj['photo'];
277 288
 							}
@@ -282,11 +293,15 @@  discard block
 block discarded – undo
282 293
 					}
283 294
 				}
284 295
 
285
-				if ($realpath && $arephoto) $realpatharray[$i]=$realpath;
296
+				if ($realpath && $arephoto) {
297
+				    $realpatharray[$i]=$realpath;
298
+				}
286 299
 			}
287 300
 		}
288 301
 
289
-		if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
302
+		if (count($realpatharray) == 0) {
303
+		    $this->posxpicture=$this->posxtva;
304
+		}
290 305
 
291 306
 		if ($conf->propal->multidir_output[$conf->entity])
292 307
 		{
@@ -299,8 +314,7 @@  discard block
 block discarded – undo
299 314
 			{
300 315
 				$dir = $conf->propal->multidir_output[$conf->entity];
301 316
 				$file = $dir . "/SPECIMEN.pdf";
302
-			}
303
-			else
317
+			} else
304 318
 			{
305 319
 				$objectref = dol_sanitizeFileName($object->ref);
306 320
 				$dir = $conf->propal->multidir_output[$object->entity] . "/" . $objectref;
@@ -356,7 +370,9 @@  discard block
 block discarded – undo
356 370
 				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
357 371
 				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
358 372
 				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfCommercialProposalTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
359
-				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
373
+				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
374
+				    $pdf->SetCompression(false);
375
+				}
360 376
 
361 377
 				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
362 378
 
@@ -380,14 +396,18 @@  discard block
 block discarded – undo
380 396
 
381 397
 				// New page
382 398
 				$pdf->AddPage();
383
-				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
399
+				if (! empty($tplidx)) {
400
+				    $pdf->useTemplate($tplidx);
401
+				}
384 402
 				$pagenb++;
385 403
 
386 404
                 $heightforinfotot = 40;	// Height reserved to output the info and total part
387 405
                 $heightforsignature = empty($conf->global->PROPAL_DISABLE_SIGNATURE)?(pdfGetHeightForHtmlContent($pdf, $outputlangs->transnoentities("ProposalCustomerSignature"))+10):0;
388 406
                 $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5);	// Height reserved to output the free text on last page
389 407
 	            $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
390
-				if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
408
+				if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) {
409
+				    $heightforfooter+= 6;
410
+				}
391 411
                 //print $heightforinfotot + $heightforsignature + $heightforfreetext + $heightforfooter;exit;
392 412
 
393 413
 				$top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
@@ -430,7 +450,9 @@  discard block
 block discarded – undo
430 450
 						$salereparray=$object->thirdparty->getSalesRepresentatives($user);
431 451
 						$salerepobj=new User($this->db);
432 452
 						$salerepobj->fetch($salereparray[0]['id']);
433
-						if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
453
+						if (! empty($salerepobj->signature)) {
454
+						    $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
455
+						}
434 456
 					}
435 457
 				}
436 458
 				if (! empty($conf->global->MAIN_ADD_CREATOR_IN_NOTE) && $object->user_author_id > 0)
@@ -438,8 +460,12 @@  discard block
 block discarded – undo
438 460
 				    $tmpuser=new User($this->db);
439 461
 				    $tmpuser->fetch($object->user_author_id);
440 462
 				    $notetoshow.='Affaire suivi par '.$tmpuser->getFullName($langs);
441
-				    if ($tmpuser->email) $notetoshow.=',  Mail: '.$tmpuser->email;
442
-				    if ($tmpuser->office_phone) $notetoshow.=', Tel: '.$tmpuser->office_phone;
463
+				    if ($tmpuser->email) {
464
+				        $notetoshow.=',  Mail: '.$tmpuser->email;
465
+				    }
466
+				    if ($tmpuser->office_phone) {
467
+				        $notetoshow.=', Tel: '.$tmpuser->office_phone;
468
+				    }
443 469
 				}
444 470
 				if ($notetoshow)
445 471
 				{
@@ -474,7 +500,9 @@  discard block
 block discarded – undo
474 500
 
475 501
 					// Define size of image if we need it
476 502
 					$imglinesize=array();
477
-					if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
503
+					if (! empty($realpatharray[$i])) {
504
+					    $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
505
+					}
478 506
 
479 507
 					$pdf->setTopMargin($tab_top_newpage);
480 508
 					$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
@@ -485,11 +513,17 @@  discard block
 block discarded – undo
485 513
 					$posYAfterDescription=0;
486 514
 
487 515
 					// We start with Photo of product line
488
-					if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot)))	// If photo too high, we moved completely on new page
516
+					if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot))) {
517
+					    // If photo too high, we moved completely on new page
489 518
 					{
490 519
 						$pdf->AddPage('','',true);
491
-						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
492
-						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
520
+					}
521
+						if (! empty($tplidx)) {
522
+						    $pdf->useTemplate($tplidx);
523
+						}
524
+						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
525
+						    $this->_pagehead($pdf, $object, 0, $outputlangs);
526
+						}
493 527
 						$pdf->setPage($pageposbefore+1);
494 528
 
495 529
 						$curY = $tab_top_newpage;
@@ -510,9 +544,11 @@  discard block
 block discarded – undo
510 544
 					$pdf->startTransaction();
511 545
 					pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc);
512 546
 					$pageposafter=$pdf->getPage();
513
-					if ($pageposafter > $pageposbefore)	// There is a pagebreak
547
+					if ($pageposafter > $pageposbefore) {
548
+					    // There is a pagebreak
514 549
 					{
515 550
 						$pdf->rollbackTransaction(true);
551
+					}
516 552
 						$pageposafter=$pageposbefore;
517 553
 						//print $pageposafter.'-'.$pageposbefore;exit;
518 554
 						$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
@@ -521,23 +557,27 @@  discard block
 block discarded – undo
521 557
 						$pageposafter=$pdf->getPage();
522 558
 						$posyafter=$pdf->GetY();
523 559
 						//var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
524
-						if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot)))	// There is no space left for total+free text
560
+						if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot))) {
561
+						    // There is no space left for total+free text
525 562
 						{
526 563
 							if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
527 564
 							{
528 565
 								$pdf->AddPage('','',true);
529
-								if (! empty($tplidx)) $pdf->useTemplate($tplidx);
530
-								if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
566
+						}
567
+								if (! empty($tplidx)) {
568
+								    $pdf->useTemplate($tplidx);
569
+								}
570
+								if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
571
+								    $this->_pagehead($pdf, $object, 0, $outputlangs);
572
+								}
531 573
 								$pdf->setPage($pageposafter+1);
532 574
 							}
533
-						}
534
-						else
575
+						} else
535 576
 						{
536 577
 							// We found a page break
537 578
 							$showpricebeforepagebreak=0;
538 579
 						}
539
-					}
540
-					else	// No pagebreak
580
+					} else	// No pagebreak
541 581
 					{
542 582
 						$pdf->commitTransaction();
543 583
 					}
@@ -577,8 +617,7 @@  discard block
 block discarded – undo
577 617
 					if($conf->global->PRODUCT_USE_UNITS)
578 618
 					{
579 619
 						$pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R');
580
-					}
581
-					else
620
+					} else
582 621
 					{
583 622
 						$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $qty, 0, 'R');
584 623
 					}
@@ -606,8 +645,11 @@  discard block
 block discarded – undo
606 645
 					$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
607 646
 
608 647
 					// Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
609
-					if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
610
-					else $tvaligne=$object->lines[$i]->total_tva;
648
+					if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) {
649
+					    $tvaligne=$object->lines[$i]->multicurrency_total_tva;
650
+					} else {
651
+					    $tvaligne=$object->lines[$i]->total_tva;
652
+					}
611 653
 
612 654
 					$localtax1ligne=$object->lines[$i]->total_localtax1;
613 655
 					$localtax2ligne=$object->lines[$i]->total_localtax2;
@@ -616,32 +658,48 @@  discard block
 block discarded – undo
616 658
 					$localtax1_type=$object->lines[$i]->localtax1_type;
617 659
 					$localtax2_type=$object->lines[$i]->localtax2_type;
618 660
 
619
-					if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
620
-					if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
621
-					if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
661
+					if ($object->remise_percent) {
662
+					    $tvaligne-=($tvaligne*$object->remise_percent)/100;
663
+					}
664
+					if ($object->remise_percent) {
665
+					    $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
666
+					}
667
+					if ($object->remise_percent) {
668
+					    $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
669
+					}
622 670
 
623 671
 					$vatrate=(string) $object->lines[$i]->tva_tx;
624 672
 
625 673
 					// Retrieve type from database for backward compatibility with old records
626 674
 					if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
627
-					&& (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
675
+					&& (! empty($localtax1_rate) || ! empty($localtax2_rate))) {
676
+					    // and there is local tax
628 677
 					{
629 678
 						$localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc);
679
+					}
630 680
 						$localtax1_type = $localtaxtmp_array[0];
631 681
 						$localtax2_type = $localtaxtmp_array[2];
632 682
 					}
633 683
 
634 684
 				    // retrieve global local tax
635
-					if ($localtax1_type && $localtax1ligne != 0)
636
-						$this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
637
-					if ($localtax2_type && $localtax2ligne != 0)
638
-						$this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
685
+					if ($localtax1_type && $localtax1ligne != 0) {
686
+											$this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
687
+					}
688
+					if ($localtax2_type && $localtax2ligne != 0) {
689
+											$this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
690
+					}
639 691
 
640
-					if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
641
-					if (! isset($this->tva[$vatrate]))				$this->tva[$vatrate]=0;
692
+					if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
693
+					    $vatrate.='*';
694
+					}
695
+					if (! isset($this->tva[$vatrate])) {
696
+					    $this->tva[$vatrate]=0;
697
+					}
642 698
 					$this->tva[$vatrate] += $tvaligne;
643 699
 
644
-					if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
700
+					if ($posYAfterImage > $posYAfterDescription) {
701
+					    $nexY=$posYAfterImage;
702
+					}
645 703
 
646 704
 					// Add line
647 705
 					if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
@@ -662,8 +720,7 @@  discard block
 block discarded – undo
662 720
 						if ($pagenb == 1)
663 721
 						{
664 722
 							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
665
-						}
666
-						else
723
+						} else
667 724
 						{
668 725
 							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
669 726
 						}
@@ -671,24 +728,29 @@  discard block
 block discarded – undo
671 728
 						$pagenb++;
672 729
 						$pdf->setPage($pagenb);
673 730
 						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
674
-						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
731
+						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
732
+						    $this->_pagehead($pdf, $object, 0, $outputlangs);
733
+						}
675 734
 					}
676 735
 					if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
677 736
 					{
678 737
 						if ($pagenb == 1)
679 738
 						{
680 739
 							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
681
-						}
682
-						else
740
+						} else
683 741
 						{
684 742
 							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
685 743
 						}
686 744
 						$this->_pagefoot($pdf,$object,$outputlangs,1);
687 745
 						// New page
688 746
 						$pdf->AddPage();
689
-						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
747
+						if (! empty($tplidx)) {
748
+						    $pdf->useTemplate($tplidx);
749
+						}
690 750
 						$pagenb++;
691
-						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
751
+						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
752
+						    $this->_pagehead($pdf, $object, 0, $outputlangs);
753
+						}
692 754
 					}
693 755
 				}
694 756
 
@@ -697,8 +759,7 @@  discard block
 block discarded – undo
697 759
 				{
698 760
 					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
699 761
 					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
700
-				}
701
-				else
762
+				} else
702 763
 				{
703 764
 					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
704 765
 					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
@@ -726,7 +787,9 @@  discard block
 block discarded – undo
726 787
 
727 788
 				// Pied de page
728 789
 				$this->_pagefoot($pdf,$object,$outputlangs);
729
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
790
+				if (method_exists($pdf,'AliasNbPages')) {
791
+				    $pdf->AliasNbPages();
792
+				}
730 793
 
731 794
 				//If propal merge product PDF is active
732 795
 				if (!empty($conf->global->PRODUIT_PDF_MERGE_PROPAL))
@@ -769,8 +832,7 @@  discard block
 block discarded – undo
769 832
 											} elseif (! empty($conf->service->enabled)) {
770 833
 												$filetomerge_dir = $conf->service->multidir_output[$entity_product_file] . '/' . get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos";
771 834
 											}
772
-										}
773
-										else
835
+										} else
774 836
 										{
775 837
 											if (! empty($conf->product->enabled)) {
776 838
 												$filetomerge_dir = $conf->product->multidir_output[$entity_product_file] . '/' . get_exdir(0,0,0,0,$product,'product') . dol_sanitizeFileName($product->ref);
@@ -812,20 +874,19 @@  discard block
 block discarded – undo
812 874
 				global $action;
813 875
 				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
814 876
 
815
-				if (! empty($conf->global->MAIN_UMASK))
816
-				@chmod($file, octdec($conf->global->MAIN_UMASK));
877
+				if (! empty($conf->global->MAIN_UMASK)) {
878
+								@chmod($file, octdec($conf->global->MAIN_UMASK));
879
+				}
817 880
 
818 881
 				$this->result = array('fullpath'=>$file);
819 882
 
820 883
 				return 1;   // Pas d'erreur
821
-			}
822
-			else
884
+			} else
823 885
 			{
824 886
 				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
825 887
 				return 0;
826 888
 			}
827
-		}
828
-		else
889
+		} else
829 890
 		{
830 891
 			$this->error=$langs->trans("ErrorConstantNotDefined","PROP_OUTPUTDIR");
831 892
 			return 0;
@@ -892,10 +953,11 @@  discard block
 block discarded – undo
892 953
 			$pdf->MultiCell(80, 4, $dlp, 0, 'L');
893 954
 
894 955
             $posy=$pdf->GetY()+1;
895
-		}
896
-        elseif ($object->availability_code || $object->availability)    // Show availability conditions
956
+		} elseif ($object->availability_code || $object->availability) {
957
+            // Show availability conditions
897 958
 		{
898 959
 			$pdf->SetFont('','B', $default_font_size - 2);
960
+        }
899 961
 			$pdf->SetXY($this->marge_gauche, $posy);
900 962
 			$titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
901 963
 			$pdf->MultiCell(80, 4, $titre, 0, 'L');
@@ -1011,7 +1073,10 @@  discard block
 block discarded – undo
1011 1073
 				if (! empty($object->fk_account) || ! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
1012 1074
 				{
1013 1075
 					$bankid=(empty($object->fk_account)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_account);
1014
-					if (! empty($object->fk_bank)) $bankid=$object->fk_bank;   // For backward compatibility when object->fk_account is forced with object->fk_bank
1076
+					if (! empty($object->fk_bank)) {
1077
+					    $bankid=$object->fk_bank;
1078
+					}
1079
+					// For backward compatibility when object->fk_account is forced with object->fk_bank
1015 1080
 					$account = new Account($this->db);
1016 1081
 					$account->fetch($bankid);
1017 1082
 
@@ -1052,10 +1117,12 @@  discard block
 block discarded – undo
1052 1117
 
1053 1118
 		// Tableau total
1054 1119
 		$col1x = 120; $col2x = 170;
1055
-		if ($this->page_largeur < 210) // To work with US executive format
1120
+		if ($this->page_largeur < 210) {
1121
+		    // To work with US executive format
1056 1122
 		{
1057 1123
 			$col2x-=20;
1058 1124
 		}
1125
+		}
1059 1126
 		$largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1060 1127
 
1061 1128
 		$useborder=0;
@@ -1082,23 +1149,26 @@  discard block
 block discarded – undo
1082 1149
 			if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1083 1150
 			{
1084 1151
 				// Nothing to do
1085
-			}
1086
-			else
1152
+			} else
1087 1153
 			{
1088 1154
 				//Local tax 1 before VAT
1089 1155
 				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1090 1156
 				//{
1091 1157
 					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1092 1158
 					{
1093
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1159
+						if (in_array((string) $localtax_type, array('1','3','5'))) {
1160
+						    continue;
1161
+						}
1094 1162
 
1095 1163
 						foreach( $localtax_rate as $tvakey => $tvaval )
1096 1164
 						{
1097
-							if ($tvakey!=0)    // On affiche pas taux 0
1165
+							if ($tvakey!=0) {
1166
+							    // On affiche pas taux 0
1098 1167
 							{
1099 1168
 								//$this->atleastoneratenotnull++;
1100 1169
 
1101 1170
 								$index++;
1171
+							}
1102 1172
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1103 1173
 
1104 1174
 								$tvacompl='';
@@ -1122,17 +1192,21 @@  discard block
 block discarded – undo
1122 1192
 				//{
1123 1193
 					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1124 1194
 					{
1125
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1195
+						if (in_array((string) $localtax_type, array('1','3','5'))) {
1196
+						    continue;
1197
+						}
1126 1198
 
1127 1199
 						foreach( $localtax_rate as $tvakey => $tvaval )
1128 1200
 						{
1129
-							if ($tvakey!=0)    // On affiche pas taux 0
1201
+							if ($tvakey!=0) {
1202
+							    // On affiche pas taux 0
1130 1203
 							{
1131 1204
 								//$this->atleastoneratenotnull++;
1132 1205
 
1133 1206
 
1134 1207
 
1135 1208
 								$index++;
1209
+							}
1136 1210
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1137 1211
 
1138 1212
 								$tvacompl='';
@@ -1154,9 +1228,11 @@  discard block
 block discarded – undo
1154 1228
 				// VAT
1155 1229
 				foreach($this->tva as $tvakey => $tvaval)
1156 1230
 				{
1157
-					if ($tvakey != 0)    // On affiche pas taux 0
1231
+					if ($tvakey != 0) {
1232
+					    // On affiche pas taux 0
1158 1233
 					{
1159 1234
 						$this->atleastoneratenotnull++;
1235
+					}
1160 1236
 
1161 1237
 						$index++;
1162 1238
 						$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
@@ -1181,15 +1257,19 @@  discard block
 block discarded – undo
1181 1257
 				//{
1182 1258
 					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1183 1259
 					{
1184
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1260
+						if (in_array((string) $localtax_type, array('2','4','6'))) {
1261
+						    continue;
1262
+						}
1185 1263
 
1186 1264
 						foreach( $localtax_rate as $tvakey => $tvaval )
1187 1265
 						{
1188
-							if ($tvakey != 0)    // On affiche pas taux 0
1266
+							if ($tvakey != 0) {
1267
+							    // On affiche pas taux 0
1189 1268
 							{
1190 1269
 								//$this->atleastoneratenotnull++;
1191 1270
 
1192 1271
 								$index++;
1272
+							}
1193 1273
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1194 1274
 
1195 1275
 								$tvacompl='';
@@ -1213,16 +1293,20 @@  discard block
 block discarded – undo
1213 1293
 				//{
1214 1294
 					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1215 1295
 					{
1216
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1296
+						if (in_array((string) $localtax_type, array('2','4','6'))) {
1297
+						    continue;
1298
+						}
1217 1299
 
1218 1300
 						foreach( $localtax_rate as $tvakey => $tvaval )
1219 1301
 						{
1220 1302
 						    // retrieve global local tax
1221
-							if ($tvakey != 0)    // On affiche pas taux 0
1303
+							if ($tvakey != 0) {
1304
+							    // On affiche pas taux 0
1222 1305
 							{
1223 1306
 								//$this->atleastoneratenotnull++;
1224 1307
 
1225 1308
 								$index++;
1309
+							}
1226 1310
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1227 1311
 
1228 1312
 								$tvacompl='';
@@ -1324,7 +1408,9 @@  discard block
 block discarded – undo
1324 1408
 
1325 1409
 		// Force to disable hidetop and hidebottom
1326 1410
 		$hidebottom=0;
1327
-		if ($hidetop) $hidetop=-1;
1411
+		if ($hidetop) {
1412
+		    $hidetop=-1;
1413
+		}
1328 1414
 
1329 1415
 		$currency = !empty($currency) ? $currency : $conf->currency;
1330 1416
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
@@ -1340,7 +1426,9 @@  discard block
 block discarded – undo
1340 1426
 			$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1341 1427
 
1342 1428
 			//$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1343
-			if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1429
+			if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1430
+			    $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1431
+			}
1344 1432
 		}
1345 1433
 
1346 1434
 		$pdf->SetDrawColor(128,128,128);
@@ -1392,8 +1480,7 @@  discard block
 block discarded – undo
1392 1480
 			if($conf->global->PRODUCT_USE_UNITS)
1393 1481
 			{
1394 1482
 				$pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1395
-			}
1396
-			else
1483
+			} else
1397 1484
 			{
1398 1485
 				$pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1399 1486
 			}
@@ -1472,16 +1559,14 @@  discard block
 block discarded – undo
1472 1559
 				{
1473 1560
 				    $height=pdf_getHeightForLogo($logo);
1474 1561
 				    $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
1475
-				}
1476
-				else
1562
+				} else
1477 1563
 				{
1478 1564
 					$pdf->SetTextColor(200,0,0);
1479 1565
 					$pdf->SetFont('','B',$default_font_size - 2);
1480 1566
 					$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1481 1567
 					$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1482 1568
 				}
1483
-			}
1484
-			else
1569
+			} else
1485 1570
 			{
1486 1571
 				$text=$this->emetteur->name;
1487 1572
 				$pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
@@ -1574,7 +1659,9 @@  discard block
 block discarded – undo
1574 1659
 			// Show sender
1575 1660
 			$posy=42+$top_shift;
1576 1661
 		 	$posx=$this->marge_gauche;
1577
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1662
+			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1663
+			    $posx=$this->page_largeur-$this->marge_droite-80;
1664
+			}
1578 1665
 			$hautcadre=40;
1579 1666
 
1580 1667
 			// Show sender frame
@@ -1622,10 +1709,15 @@  discard block
 block discarded – undo
1622 1709
 
1623 1710
 			// Show recipient
1624 1711
 			$widthrecbox=100;
1625
-			if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1712
+			if ($this->page_largeur < 210) {
1713
+			    $widthrecbox=84;
1714
+			}
1715
+			// To work with US executive format
1626 1716
 			$posy=42+$top_shift;
1627 1717
 			$posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1628
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1718
+			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1719
+			    $posx=$this->marge_gauche;
1720
+			}
1629 1721
 
1630 1722
 			// Show recipient frame
1631 1723
 			$pdf->SetTextColor(0,0,0);
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/propale/doc/pdf_cyan.modules.php 3 patches
Indentation   +1687 added lines, -1687 removed lines patch added patch discarded remove patch
@@ -41,85 +41,85 @@  discard block
 block discarded – undo
41 41
  */
42 42
 class pdf_cyan extends ModelePDFPropales
43 43
 {
44
-	public $db;
45
-	public $name;
46
-	public $description;
47
-	public $update_main_doc_field;	// Save the name of generated file as the main doc when generating a doc with this template
48
-	public $type;
49
-
50
-	public $phpmin = array(4,3,0); // Minimum version of PHP required by module
51
-	public $version = 'development';
52
-
53
-	public $page_largeur;
54
-	public $page_hauteur;
55
-	public $format;
56
-	public $marge_gauche;
57
-	public	$marge_droite;
58
-	public	$marge_haute;
59
-	public	$marge_basse;
60
-
61
-	public $emetteur;	// Objet societe qui emet
62
-
63
-
64
-	/**
65
-	 *	Constructor
66
-	 *
67
-	 *  @param		DoliDB		$db      Database handler
68
-	 */
69
-	public function __construct($db)
70
-	{
71
-		global $conf,$langs,$mysoc;
72
-
73
-		// Translations
74
-		$langs->loadLangs(array("main", "bills"));
75
-
76
-		$this->db = $db;
77
-		$this->name = "cyan";
78
-		$this->description = $langs->trans('DocModelCyanDescription');
79
-		$this->update_main_doc_field = 1;		// Save the name of generated file as the main doc when generating a doc with this template
80
-
81
-		// Dimension page
82
-		$this->type = 'pdf';
83
-		$formatarray=pdf_getFormat();
84
-		$this->page_largeur = $formatarray['width'];
85
-		$this->page_hauteur = $formatarray['height'];
86
-		$this->format = array($this->page_largeur,$this->page_hauteur);
87
-		$this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
88
-		$this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
89
-		$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
90
-		$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
91
-
92
-		$this->option_logo = 1;                    // Affiche logo
93
-		$this->option_tva = 1;                     // Gere option tva FACTURE_TVAOPTION
94
-		$this->option_modereg = 1;                 // Affiche mode reglement
95
-		$this->option_condreg = 1;                 // Affiche conditions reglement
96
-		$this->option_codeproduitservice = 1;      // Affiche code produit-service
97
-		$this->option_multilang = 1;               // Dispo en plusieurs langues
98
-		$this->option_escompte = 0;                // Affiche si il y a eu escompte
99
-		$this->option_credit_note = 0;             // Support credit notes
100
-		$this->option_freetext = 1;				   // Support add of a personalised text
101
-		$this->option_draft_watermark = 1;		   //Support add of a watermark on drafts
102
-
103
-		$this->franchise=!$mysoc->tva_assuj;
104
-
105
-		// Get source company
106
-		$this->emetteur=$mysoc;
107
-		if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
108
-
109
-		// Define position of columns
110
-		$this->posxdesc=$this->marge_gauche+1;
111
-
112
-
113
-
114
-		$this->tva=array();
115
-		$this->localtax1=array();
116
-		$this->localtax2=array();
117
-		$this->atleastoneratenotnull=0;
118
-		$this->atleastonediscount=0;
119
-	}
44
+    public $db;
45
+    public $name;
46
+    public $description;
47
+    public $update_main_doc_field;	// Save the name of generated file as the main doc when generating a doc with this template
48
+    public $type;
49
+
50
+    public $phpmin = array(4,3,0); // Minimum version of PHP required by module
51
+    public $version = 'development';
52
+
53
+    public $page_largeur;
54
+    public $page_hauteur;
55
+    public $format;
56
+    public $marge_gauche;
57
+    public	$marge_droite;
58
+    public	$marge_haute;
59
+    public	$marge_basse;
60
+
61
+    public $emetteur;	// Objet societe qui emet
62
+
63
+
64
+    /**
65
+     *	Constructor
66
+     *
67
+     *  @param		DoliDB		$db      Database handler
68
+     */
69
+    public function __construct($db)
70
+    {
71
+        global $conf,$langs,$mysoc;
72
+
73
+        // Translations
74
+        $langs->loadLangs(array("main", "bills"));
75
+
76
+        $this->db = $db;
77
+        $this->name = "cyan";
78
+        $this->description = $langs->trans('DocModelCyanDescription');
79
+        $this->update_main_doc_field = 1;		// Save the name of generated file as the main doc when generating a doc with this template
80
+
81
+        // Dimension page
82
+        $this->type = 'pdf';
83
+        $formatarray=pdf_getFormat();
84
+        $this->page_largeur = $formatarray['width'];
85
+        $this->page_hauteur = $formatarray['height'];
86
+        $this->format = array($this->page_largeur,$this->page_hauteur);
87
+        $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
88
+        $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
89
+        $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
90
+        $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
91
+
92
+        $this->option_logo = 1;                    // Affiche logo
93
+        $this->option_tva = 1;                     // Gere option tva FACTURE_TVAOPTION
94
+        $this->option_modereg = 1;                 // Affiche mode reglement
95
+        $this->option_condreg = 1;                 // Affiche conditions reglement
96
+        $this->option_codeproduitservice = 1;      // Affiche code produit-service
97
+        $this->option_multilang = 1;               // Dispo en plusieurs langues
98
+        $this->option_escompte = 0;                // Affiche si il y a eu escompte
99
+        $this->option_credit_note = 0;             // Support credit notes
100
+        $this->option_freetext = 1;				   // Support add of a personalised text
101
+        $this->option_draft_watermark = 1;		   //Support add of a watermark on drafts
102
+
103
+        $this->franchise=!$mysoc->tva_assuj;
104
+
105
+        // Get source company
106
+        $this->emetteur=$mysoc;
107
+        if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
108
+
109
+        // Define position of columns
110
+        $this->posxdesc=$this->marge_gauche+1;
111
+
112
+
113
+
114
+        $this->tva=array();
115
+        $this->localtax1=array();
116
+        $this->localtax2=array();
117
+        $this->atleastoneratenotnull=0;
118
+        $this->atleastonediscount=0;
119
+    }
120 120
 
121 121
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
122
-	/**
122
+    /**
123 123
      *  Function to build pdf onto disk
124 124
      *
125 125
      *  @param		Object		$object				Object to generate
@@ -129,132 +129,132 @@  discard block
 block discarded – undo
129 129
      *  @param		int			$hidedesc			Do not show desc
130 130
      *  @param		int			$hideref			Do not show ref
131 131
      *  @return     int             				1=OK, 0=KO
132
-	 */
133
-	public function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
134
-	{
135
-	  // phpcs:enable
136
-		global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
137
-
138
-		if (! is_object($outputlangs)) $outputlangs=$langs;
139
-		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
140
-		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
141
-
142
-		$outputlangs->load("main");
143
-		$outputlangs->load("dict");
144
-		$outputlangs->load("companies");
145
-		$outputlangs->load("bills");
146
-		$outputlangs->load("propal");
147
-		$outputlangs->load("products");
148
-
149
-		$nblignes = count($object->lines);
150
-
151
-		// Loop on each lines to detect if there is at least one image to show
152
-		$realpatharray=array();
153
-		$this->atleastonephoto = false;
154
-		if (! empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE))
155
-		{
156
-			$objphoto = new Product($this->db);
157
-
158
-			for ($i = 0 ; $i < $nblignes ; $i++)
159
-			{
160
-				if (empty($object->lines[$i]->fk_product)) continue;
161
-
162
-				$objphoto->fetch($object->lines[$i]->fk_product);
132
+     */
133
+    public function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
134
+    {
135
+        // phpcs:enable
136
+        global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
137
+
138
+        if (! is_object($outputlangs)) $outputlangs=$langs;
139
+        // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
140
+        if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
141
+
142
+        $outputlangs->load("main");
143
+        $outputlangs->load("dict");
144
+        $outputlangs->load("companies");
145
+        $outputlangs->load("bills");
146
+        $outputlangs->load("propal");
147
+        $outputlangs->load("products");
148
+
149
+        $nblignes = count($object->lines);
150
+
151
+        // Loop on each lines to detect if there is at least one image to show
152
+        $realpatharray=array();
153
+        $this->atleastonephoto = false;
154
+        if (! empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE))
155
+        {
156
+            $objphoto = new Product($this->db);
157
+
158
+            for ($i = 0 ; $i < $nblignes ; $i++)
159
+            {
160
+                if (empty($object->lines[$i]->fk_product)) continue;
161
+
162
+                $objphoto->fetch($object->lines[$i]->fk_product);
163 163
                 //var_dump($objphoto->ref);exit;
164
-				if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
165
-				{
166
-					$pdir[0] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";
167
-					$pdir[1] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';
168
-				}
169
-				else
170
-				{
171
-					$pdir[0] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';				// default
172
-					$pdir[1] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";	// alternative
173
-				}
174
-
175
-				$arephoto = false;
176
-				foreach ($pdir as $midir)
177
-				{
178
-					if (! $arephoto)
179
-					{
180
-						$dir = $conf->product->dir_output.'/'.$midir;
181
-
182
-						foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
183
-						{
184
-							if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES))		// If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
185
-							{
186
-								if ($obj['photo_vignette'])
187
-								{
188
-									$filename= $obj['photo_vignette'];
189
-								}
190
-								else
191
-								{
192
-									$filename=$obj['photo'];
193
-								}
194
-							}
195
-							else
196
-							{
197
-								$filename=$obj['photo'];
198
-							}
199
-
200
-							$realpath = $dir.$filename;
201
-							$arephoto = true;
202
-							$this->atleastonephoto = true;
203
-						}
204
-					}
205
-				}
206
-
207
-				if ($realpath && $arephoto) $realpatharray[$i]=$realpath;
208
-			}
209
-		}
210
-
211
-		if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
212
-
213
-		if ($conf->propal->multidir_output[$conf->entity])
214
-		{
215
-			$object->fetch_thirdparty();
216
-
217
-			$deja_regle = 0;
164
+                if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
165
+                {
166
+                    $pdir[0] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";
167
+                    $pdir[1] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';
168
+                }
169
+                else
170
+                {
171
+                    $pdir[0] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';				// default
172
+                    $pdir[1] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";	// alternative
173
+                }
218 174
 
219
-			// Definition of $dir and $file
220
-			if ($object->specimen)
221
-			{
222
-				$dir = $conf->propal->multidir_output[$conf->entity];
223
-				$file = $dir . "/SPECIMEN.pdf";
224
-			}
225
-			else
226
-			{
227
-				$objectref = dol_sanitizeFileName($object->ref);
228
-				$dir = $conf->propal->multidir_output[$object->entity] . "/" . $objectref;
229
-				$file = $dir . "/" . $objectref . ".pdf";
230
-			}
175
+                $arephoto = false;
176
+                foreach ($pdir as $midir)
177
+                {
178
+                    if (! $arephoto)
179
+                    {
180
+                        $dir = $conf->product->dir_output.'/'.$midir;
181
+
182
+                        foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
183
+                        {
184
+                            if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES))		// If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
185
+                            {
186
+                                if ($obj['photo_vignette'])
187
+                                {
188
+                                    $filename= $obj['photo_vignette'];
189
+                                }
190
+                                else
191
+                                {
192
+                                    $filename=$obj['photo'];
193
+                                }
194
+                            }
195
+                            else
196
+                            {
197
+                                $filename=$obj['photo'];
198
+                            }
199
+
200
+                            $realpath = $dir.$filename;
201
+                            $arephoto = true;
202
+                            $this->atleastonephoto = true;
203
+                        }
204
+                    }
205
+                }
231 206
 
232
-			if (! file_exists($dir))
233
-			{
234
-				if (dol_mkdir($dir) < 0)
235
-				{
236
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
237
-					return 0;
238
-				}
239
-			}
207
+                if ($realpath && $arephoto) $realpatharray[$i]=$realpath;
208
+            }
209
+        }
210
+
211
+        if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
212
+
213
+        if ($conf->propal->multidir_output[$conf->entity])
214
+        {
215
+            $object->fetch_thirdparty();
216
+
217
+            $deja_regle = 0;
218
+
219
+            // Definition of $dir and $file
220
+            if ($object->specimen)
221
+            {
222
+                $dir = $conf->propal->multidir_output[$conf->entity];
223
+                $file = $dir . "/SPECIMEN.pdf";
224
+            }
225
+            else
226
+            {
227
+                $objectref = dol_sanitizeFileName($object->ref);
228
+                $dir = $conf->propal->multidir_output[$object->entity] . "/" . $objectref;
229
+                $file = $dir . "/" . $objectref . ".pdf";
230
+            }
231
+
232
+            if (! file_exists($dir))
233
+            {
234
+                if (dol_mkdir($dir) < 0)
235
+                {
236
+                    $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
237
+                    return 0;
238
+                }
239
+            }
240 240
 
241
-			if (file_exists($dir))
242
-			{
243
-				// Add pdfgeneration hook
244
-				if (! is_object($hookmanager))
245
-				{
246
-					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
247
-					$hookmanager=new HookManager($this->db);
248
-				}
249
-				$hookmanager->initHooks(array('pdfgeneration'));
250
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
251
-				global $action;
252
-				$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
241
+            if (file_exists($dir))
242
+            {
243
+                // Add pdfgeneration hook
244
+                if (! is_object($hookmanager))
245
+                {
246
+                    include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
247
+                    $hookmanager=new HookManager($this->db);
248
+                }
249
+                $hookmanager->initHooks(array('pdfgeneration'));
250
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
251
+                global $action;
252
+                $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
253 253
 
254
-				// Create pdf instance
254
+                // Create pdf instance
255 255
                 $pdf=pdf_getInstance($this->format);
256 256
                 $default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
257
-	            $pdf->SetAutoPageBreak(1,0);
257
+                $pdf->SetAutoPageBreak(1,0);
258 258
 
259 259
                 if (class_exists('TCPDF'))
260 260
                 {
@@ -269,33 +269,33 @@  discard block
 block discarded – undo
269 269
                     $tplidx = $pdf->importPage(1);
270 270
                 }
271 271
 
272
-				$pdf->Open();
273
-				$pagenb=0;
274
-				$pdf->SetDrawColor(128,128,128);
275
-
276
-				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
277
-				$pdf->SetSubject($outputlangs->transnoentities("PdfCommercialProposalTitle"));
278
-				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
279
-				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
280
-				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfCommercialProposalTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
281
-				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
282
-
283
-				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
284
-
285
-				// Does we have at least one line with discount $this->atleastonediscount
286
-				foreach ($object->lines as $line) {
287
-				    if ($line->remise_percent){
288
-				        $this->atleastonediscount = true;
289
-				        break;
290
-				    }
291
-				}
272
+                $pdf->Open();
273
+                $pagenb=0;
274
+                $pdf->SetDrawColor(128,128,128);
275
+
276
+                $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
277
+                $pdf->SetSubject($outputlangs->transnoentities("PdfCommercialProposalTitle"));
278
+                $pdf->SetCreator("Dolibarr ".DOL_VERSION);
279
+                $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
280
+                $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfCommercialProposalTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
281
+                if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
282
+
283
+                $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
284
+
285
+                // Does we have at least one line with discount $this->atleastonediscount
286
+                foreach ($object->lines as $line) {
287
+                    if ($line->remise_percent){
288
+                        $this->atleastonediscount = true;
289
+                        break;
290
+                    }
291
+                }
292 292
 
293 293
 
294 294
 
295
-				// New page
296
-				$pdf->AddPage();
297
-				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
298
-				$pagenb++;
295
+                // New page
296
+                $pdf->AddPage();
297
+                if (! empty($tplidx)) $pdf->useTemplate($tplidx);
298
+                $pagenb++;
299 299
 
300 300
                 $heightforinfotot = 40;	// Height reserved to output the info and total part
301 301
                 $heightforsignature = empty($conf->global->PROPAL_DISABLE_SIGNATURE)?(pdfGetHeightForHtmlContent($pdf, $outputlangs->transnoentities("ProposalCustomerSignature"))+10):0;
@@ -303,669 +303,669 @@  discard block
 block discarded – undo
303 303
                 $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)?12:22);	// Height reserved to output the footer (value include bottom margin)
304 304
                 //print $heightforinfotot + $heightforsignature + $heightforfreetext + $heightforfooter;exit;
305 305
 
306
-				$top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
307
-				$pdf->SetFont('','', $default_font_size - 1);
308
-				$pdf->MultiCell(0, 3, '');		// Set interline to 3
309
-				$pdf->SetTextColor(0,0,0);
306
+                $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
307
+                $pdf->SetFont('','', $default_font_size - 1);
308
+                $pdf->MultiCell(0, 3, '');		// Set interline to 3
309
+                $pdf->SetTextColor(0,0,0);
310 310
 
311 311
 
312
-	            $tab_top = 90+$top_shift;
313
-				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10);
312
+                $tab_top = 90+$top_shift;
313
+                $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10);
314 314
 
315 315
 
316
-				// Incoterm
317
-				$height_incoterms = 0;
318
-				if ($conf->incoterm->enabled)
319
-				{
320
-					$desc_incoterms = $object->getIncotermsForPDF();
321
-					if ($desc_incoterms)
322
-					{
323
-						$tab_top -= 2;
324
-
325
-						$pdf->SetFont('','', $default_font_size - 1);
326
-						$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
327
-						$nexY = $pdf->GetY();
328
-						$height_incoterms=$nexY-$tab_top;
329
-
330
-						// Rect prend une longueur en 3eme param
331
-						$pdf->SetDrawColor(192,192,192);
332
-						$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
333
-
334
-						$tab_top = $nexY+6;
335
-					}
336
-				}
316
+                // Incoterm
317
+                $height_incoterms = 0;
318
+                if ($conf->incoterm->enabled)
319
+                {
320
+                    $desc_incoterms = $object->getIncotermsForPDF();
321
+                    if ($desc_incoterms)
322
+                    {
323
+                        $tab_top -= 2;
324
+
325
+                        $pdf->SetFont('','', $default_font_size - 1);
326
+                        $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
327
+                        $nexY = $pdf->GetY();
328
+                        $height_incoterms=$nexY-$tab_top;
329
+
330
+                        // Rect prend une longueur en 3eme param
331
+                        $pdf->SetDrawColor(192,192,192);
332
+                        $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
333
+
334
+                        $tab_top = $nexY+6;
335
+                    }
336
+                }
337 337
 
338
-				// Affiche notes
339
-				$notetoshow=empty($object->note_public)?'':$object->note_public;
340
-				if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
341
-				{
342
-					// Get first sale rep
343
-					if (is_object($object->thirdparty))
344
-					{
345
-						$salereparray=$object->thirdparty->getSalesRepresentatives($user);
346
-						$salerepobj=new User($this->db);
347
-						$salerepobj->fetch($salereparray[0]['id']);
348
-						if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
349
-					}
350
-				}
351
-				if (! empty($conf->global->MAIN_ADD_CREATOR_IN_NOTE) && $object->user_author_id > 0)
352
-				{
353
-				    $tmpuser=new User($this->db);
354
-				    $tmpuser->fetch($object->user_author_id);
355
-				    $notetoshow.='Affaire suivi par '.$tmpuser->getFullName($langs);
356
-				    if ($tmpuser->email) $notetoshow.=',  Mail: '.$tmpuser->email;
357
-				    if ($tmpuser->office_phone) $notetoshow.=', Tel: '.$tmpuser->office_phone;
358
-				}
338
+                // Affiche notes
339
+                $notetoshow=empty($object->note_public)?'':$object->note_public;
340
+                if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
341
+                {
342
+                    // Get first sale rep
343
+                    if (is_object($object->thirdparty))
344
+                    {
345
+                        $salereparray=$object->thirdparty->getSalesRepresentatives($user);
346
+                        $salerepobj=new User($this->db);
347
+                        $salerepobj->fetch($salereparray[0]['id']);
348
+                        if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
349
+                    }
350
+                }
351
+                if (! empty($conf->global->MAIN_ADD_CREATOR_IN_NOTE) && $object->user_author_id > 0)
352
+                {
353
+                    $tmpuser=new User($this->db);
354
+                    $tmpuser->fetch($object->user_author_id);
355
+                    $notetoshow.='Affaire suivi par '.$tmpuser->getFullName($langs);
356
+                    if ($tmpuser->email) $notetoshow.=',  Mail: '.$tmpuser->email;
357
+                    if ($tmpuser->office_phone) $notetoshow.=', Tel: '.$tmpuser->office_phone;
358
+                }
359 359
 
360
-				$pagenb = $pdf->getPage();
361
-				if ($notetoshow)
362
-				{
363
-					$tab_top -= 2;
364
-
365
-				    $tab_width = $this->page_largeur-$this->marge_gauche-$this->marge_droite;
366
-				    $pageposbeforenote = $pagenb;
367
-
368
-					$substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
369
-					complete_substitutions_array($substitutionarray, $outputlangs, $object);
370
-					$notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
371
-
372
-
373
-					$pdf->startTransaction();
374
-
375
-					$pdf->SetFont('','', $default_font_size - 1);
376
-					$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
377
-					// Description
378
-					$pageposafternote=$pdf->getPage();
379
-					$posyafter = $pdf->GetY();
380
-
381
-					if($pageposafternote>$pageposbeforenote )
382
-					{
383
-					    $pdf->rollbackTransaction(true);
384
-
385
-					    // prepar pages to receive notes
386
-					    while ($pagenb < $pageposafternote) {
387
-					        $pdf->AddPage();
388
-					        $pagenb++;
389
-					        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
390
-					        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
391
-					        // $this->_pagefoot($pdf,$object,$outputlangs,1);
392
-					        $pdf->setTopMargin($tab_top_newpage);
393
-					        // The only function to edit the bottom margin of current page to set it.
394
-					        $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
395
-					    }
396
-
397
-					    // back to start
398
-					    $pdf->setPage($pageposbeforenote);
399
-					    $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
400
-					    $pdf->SetFont('','', $default_font_size - 1);
401
-					    $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
402
-					    $pageposafternote=$pdf->getPage();
403
-
404
-					    $posyafter = $pdf->GetY();
405
-
406
-					    if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20)))	// There is no space left for total+free text
407
-					    {
408
-					        $pdf->AddPage('','',true);
409
-					        $pagenb++;
410
-					        $pageposafternote++;
411
-					        $pdf->setPage($pageposafternote);
412
-					        $pdf->setTopMargin($tab_top_newpage);
413
-					        // The only function to edit the bottom margin of current page to set it.
414
-					        $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
415
-					        //$posyafter = $tab_top_newpage;
416
-					    }
417
-
418
-
419
-					    // apply note frame to previus pages
420
-					    $i = $pageposbeforenote;
421
-					    while ($i < $pageposafternote) {
422
-					        $pdf->setPage($i);
423
-
424
-
425
-					        $pdf->SetDrawColor(128,128,128);
426
-					        // Draw note frame
427
-					        if($i>$pageposbeforenote){
428
-					            $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
429
-					            $pdf->Rect($this->marge_gauche, $tab_top_newpage-1, $tab_width, $height_note + 1);
430
-					        }
431
-					        else{
432
-					            $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
433
-					            $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note + 1);
434
-					        }
435
-
436
-					        // Add footer
437
-					        $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
438
-					        $this->_pagefoot($pdf,$object,$outputlangs,1);
439
-
440
-					        $i++;
441
-					    }
442
-
443
-					    // apply note frame to last page
444
-					    $pdf->setPage($pageposafternote);
445
-					    if (! empty($tplidx)) $pdf->useTemplate($tplidx);
446
-					    if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
447
-					    $height_note=$posyafter-$tab_top_newpage;
448
-					    $pdf->Rect($this->marge_gauche, $tab_top_newpage-1, $tab_width, $height_note+1);
449
-					}
450
-					else // No pagebreak
451
-					{
452
-					    $pdf->commitTransaction();
453
-					    $posyafter = $pdf->GetY();
454
-					    $height_note=$posyafter-$tab_top;
455
-					    $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note+1);
456
-
457
-
458
-					    if($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20)) )
459
-					    {
460
-					        // not enough space, need to add page
461
-					        $pdf->AddPage('','',true);
462
-					        $pagenb++;
463
-					        $pageposafternote++;
464
-					        $pdf->setPage($pageposafternote);
465
-					        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
466
-					        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
467
-
468
-					        $posyafter = $tab_top_newpage;
469
-					    }
470
-					}
471
-
472
-					$tab_height = $tab_height - $height_note;
473
-					$tab_top = $posyafter +6;
474
-				}
475
-				else
476
-				{
477
-					$height_note=0;
478
-				}
360
+                $pagenb = $pdf->getPage();
361
+                if ($notetoshow)
362
+                {
363
+                    $tab_top -= 2;
364
+
365
+                    $tab_width = $this->page_largeur-$this->marge_gauche-$this->marge_droite;
366
+                    $pageposbeforenote = $pagenb;
367
+
368
+                    $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
369
+                    complete_substitutions_array($substitutionarray, $outputlangs, $object);
370
+                    $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
371
+
372
+
373
+                    $pdf->startTransaction();
374
+
375
+                    $pdf->SetFont('','', $default_font_size - 1);
376
+                    $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
377
+                    // Description
378
+                    $pageposafternote=$pdf->getPage();
379
+                    $posyafter = $pdf->GetY();
380
+
381
+                    if($pageposafternote>$pageposbeforenote )
382
+                    {
383
+                        $pdf->rollbackTransaction(true);
384
+
385
+                        // prepar pages to receive notes
386
+                        while ($pagenb < $pageposafternote) {
387
+                            $pdf->AddPage();
388
+                            $pagenb++;
389
+                            if (! empty($tplidx)) $pdf->useTemplate($tplidx);
390
+                            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
391
+                            // $this->_pagefoot($pdf,$object,$outputlangs,1);
392
+                            $pdf->setTopMargin($tab_top_newpage);
393
+                            // The only function to edit the bottom margin of current page to set it.
394
+                            $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
395
+                        }
396
+
397
+                        // back to start
398
+                        $pdf->setPage($pageposbeforenote);
399
+                        $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
400
+                        $pdf->SetFont('','', $default_font_size - 1);
401
+                        $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
402
+                        $pageposafternote=$pdf->getPage();
403
+
404
+                        $posyafter = $pdf->GetY();
405
+
406
+                        if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20)))	// There is no space left for total+free text
407
+                        {
408
+                            $pdf->AddPage('','',true);
409
+                            $pagenb++;
410
+                            $pageposafternote++;
411
+                            $pdf->setPage($pageposafternote);
412
+                            $pdf->setTopMargin($tab_top_newpage);
413
+                            // The only function to edit the bottom margin of current page to set it.
414
+                            $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
415
+                            //$posyafter = $tab_top_newpage;
416
+                        }
417
+
418
+
419
+                        // apply note frame to previus pages
420
+                        $i = $pageposbeforenote;
421
+                        while ($i < $pageposafternote) {
422
+                            $pdf->setPage($i);
423
+
424
+
425
+                            $pdf->SetDrawColor(128,128,128);
426
+                            // Draw note frame
427
+                            if($i>$pageposbeforenote){
428
+                                $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
429
+                                $pdf->Rect($this->marge_gauche, $tab_top_newpage-1, $tab_width, $height_note + 1);
430
+                            }
431
+                            else{
432
+                                $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
433
+                                $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note + 1);
434
+                            }
435
+
436
+                            // Add footer
437
+                            $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
438
+                            $this->_pagefoot($pdf,$object,$outputlangs,1);
439
+
440
+                            $i++;
441
+                        }
442
+
443
+                        // apply note frame to last page
444
+                        $pdf->setPage($pageposafternote);
445
+                        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
446
+                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
447
+                        $height_note=$posyafter-$tab_top_newpage;
448
+                        $pdf->Rect($this->marge_gauche, $tab_top_newpage-1, $tab_width, $height_note+1);
449
+                    }
450
+                    else // No pagebreak
451
+                    {
452
+                        $pdf->commitTransaction();
453
+                        $posyafter = $pdf->GetY();
454
+                        $height_note=$posyafter-$tab_top;
455
+                        $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note+1);
456
+
457
+
458
+                        if($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20)) )
459
+                        {
460
+                            // not enough space, need to add page
461
+                            $pdf->AddPage('','',true);
462
+                            $pagenb++;
463
+                            $pageposafternote++;
464
+                            $pdf->setPage($pageposafternote);
465
+                            if (! empty($tplidx)) $pdf->useTemplate($tplidx);
466
+                            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
467
+
468
+                            $posyafter = $tab_top_newpage;
469
+                        }
470
+                    }
471
+
472
+                    $tab_height = $tab_height - $height_note;
473
+                    $tab_top = $posyafter +6;
474
+                }
475
+                else
476
+                {
477
+                    $height_note=0;
478
+                }
479 479
 
480
-				$iniY = $tab_top + 7;
481
-				$curY = $tab_top + 7;
482
-				$nexY = $tab_top + 7;
480
+                $iniY = $tab_top + 7;
481
+                $curY = $tab_top + 7;
482
+                $nexY = $tab_top + 7;
483 483
 
484
-				// Use new auto collum system
485
-				$this->prepareArrayColumnField($object,$outputlangs,$hidedetails,$hidedesc,$hideref);
484
+                // Use new auto collum system
485
+                $this->prepareArrayColumnField($object,$outputlangs,$hidedetails,$hidedesc,$hideref);
486 486
 
487
-				// Loop on each lines
488
-				$pageposbeforeprintlines=$pdf->getPage();
489
-				$pagenb = $pageposbeforeprintlines;
490
-				for ($i = 0; $i < $nblignes; $i++)
491
-				{
492
-					$curY = $nexY;
493
-					$pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
494
-					$pdf->SetTextColor(0,0,0);
495
-
496
-					// Define size of image if we need it
497
-					$imglinesize=array();
498
-					if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
499
-
500
-					$pdf->setTopMargin($tab_top_newpage);
501
-					$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
502
-					$pageposbefore=$pdf->getPage();
503
-
504
-					$showpricebeforepagebreak=1;
505
-					$posYAfterImage=0;
506
-					$posYAfterDescription=0;
507
-
508
-					if($this->getColumnStatus('photo'))
509
-					{
510
-    					// We start with Photo of product line
511
-    					if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot)))	// If photo too high, we moved completely on new page
512
-    					{
513
-    						$pdf->AddPage('','',true);
514
-    						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
515
-    						//if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
516
-    						$pdf->setPage($pageposbefore+1);
517
-
518
-    						$curY = $tab_top_newpage;
519
-    						$showpricebeforepagebreak=0;
520
-    					}
521
-
522
-
523
-    					if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height']))
524
-    					{
525
-    						$pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);	// Use 300 dpi
526
-    						// $pdf->Image does not increase value return by getY, so we save it manually
527
-    						$posYAfterImage=$curY+$imglinesize['height'];
528
-    					}
529
-					}
530
-
531
-					// Description of product line
532
-					if($this->getColumnStatus('desc'))
533
-					{
534
-    					$pdf->startTransaction();
535
-    					pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->getColumnContentWidth('desc'),3,$this->getColumnContentXStart('desc'),$curY,$hideref,$hidedesc);
536
-    					$pageposafter=$pdf->getPage();
537
-    					if ($pageposafter > $pageposbefore)	// There is a pagebreak
538
-    					{
539
-    						$pdf->rollbackTransaction(true);
540
-    						$pageposafter=$pageposbefore;
541
-    						//print $pageposafter.'-'.$pageposbefore;exit;
542
-    						$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
543
-    						pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->getColumnContentWidth('desc'),3,$this->getColumnContentXStart('desc'),$curY,$hideref,$hidedesc);
544
-
545
-    						$pageposafter=$pdf->getPage();
546
-    						$posyafter=$pdf->GetY();
547
-    						//var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
548
-    						if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot)))	// There is no space left for total+free text
549
-    						{
550
-    							if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
551
-    							{
552
-    								$pdf->AddPage('','',true);
553
-    								if (! empty($tplidx)) $pdf->useTemplate($tplidx);
554
-    								//if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
555
-    								$pdf->setPage($pageposafter+1);
556
-    							}
557
-    						}
558
-    						else
559
-    						{
560
-    							// We found a page break
561
-    							$showpricebeforepagebreak=0;
562
-    						}
563
-    					}
564
-    					else	// No pagebreak
565
-    					{
566
-    						$pdf->commitTransaction();
567
-    					}
568
-    					$posYAfterDescription=$pdf->GetY();
569
-					}
570
-
571
-					$nexY = $pdf->GetY();
572
-					$pageposafter=$pdf->getPage();
573
-
574
-					$pdf->setPage($pageposbefore);
575
-					$pdf->setTopMargin($this->marge_haute);
576
-					$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
577
-
578
-					// We suppose that a too long description or photo were moved completely on next page
579
-					if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
580
-						$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
581
-					}
582
-
583
-					$pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
584
-
585
-					// VAT Rate
586
-					if ($this->getColumnStatus('vat'))
587
-					{
588
-					    $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
589
-					    $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
590
-					    $nexY = max($pdf->GetY(),$nexY);
591
-					}
592
-
593
-					// Unit price before discount
594
-					if ($this->getColumnStatus('subprice'))
595
-					{
596
-					    $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
597
-					    $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
598
-					    $nexY = max($pdf->GetY(),$nexY);
599
-					}
600
-
601
-					// Quantity
602
-					// Enough for 6 chars
603
-					if ($this->getColumnStatus('qty'))
604
-					{
605
-					    $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
606
-					    $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
607
-					    $nexY = max($pdf->GetY(),$nexY);
608
-					}
609
-
610
-
611
-					// Unit
612
-					if ($this->getColumnStatus('unit'))
613
-					{
614
-					    $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
615
-					    $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
616
-					    $nexY = max($pdf->GetY(),$nexY);
617
-					}
618
-
619
-					// Discount on line
620
-					if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent)
621
-					{
622
-					    $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
623
-					    $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
624
-					    $nexY = max($pdf->GetY(),$nexY);
625
-					}
626
-
627
-					// Total HT line
628
-					if ($this->getColumnStatus('totalexcltax'))
629
-					{
630
-					    $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
631
-					    $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
632
-					    $nexY = max($pdf->GetY(),$nexY);
633
-					}
634
-
635
-
636
-					$parameters=array(
637
-					    'object' => $object,
638
-					    'i' => $i,
639
-					    'pdf' =>& $pdf,
640
-					    'curY' =>& $curY,
641
-					    'nexY' =>& $nexY,
642
-					    'outputlangs' => $outputlangs,
643
-					    'hidedetails' => $hidedetails
644
-					);
645
-					$reshook=$hookmanager->executeHooks('printPDFline',$parameters,$this);    // Note that $object may have been modified by hook
646
-
647
-
648
-
649
-					// Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
650
-					if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
651
-					else $tvaligne=$object->lines[$i]->total_tva;
652
-
653
-					$localtax1ligne=$object->lines[$i]->total_localtax1;
654
-					$localtax2ligne=$object->lines[$i]->total_localtax2;
655
-					$localtax1_rate=$object->lines[$i]->localtax1_tx;
656
-					$localtax2_rate=$object->lines[$i]->localtax2_tx;
657
-					$localtax1_type=$object->lines[$i]->localtax1_type;
658
-					$localtax2_type=$object->lines[$i]->localtax2_type;
659
-
660
-					if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
661
-					if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
662
-					if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
663
-
664
-					$vatrate=(string) $object->lines[$i]->tva_tx;
665
-
666
-					// Retrieve type from database for backward compatibility with old records
667
-					if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
668
-					&& (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
669
-					{
670
-						$localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc);
671
-						$localtax1_type = $localtaxtmp_array[0];
672
-						$localtax2_type = $localtaxtmp_array[2];
673
-					}
674
-
675
-				    // retrieve global local tax
676
-					if ($localtax1_type && $localtax1ligne != 0)
677
-						$this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
678
-					if ($localtax2_type && $localtax2ligne != 0)
679
-						$this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
680
-
681
-					if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
682
-					if (! isset($this->tva[$vatrate]))				$this->tva[$vatrate]=0;
683
-					$this->tva[$vatrate] += $tvaligne;
684
-
685
-					if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
686
-
687
-					// Add line
688
-					if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
689
-					{
690
-						$pdf->setPage($pageposafter);
691
-						$pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
692
-						//$pdf->SetDrawColor(190,190,200);
693
-						$pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
694
-						$pdf->SetLineStyle(array('dash'=>0));
695
-					}
696
-
697
-					$nexY+=2;    // Passe espace entre les lignes
698
-
699
-					// Detect if some page were added automatically and output _tableau for past pages
700
-					while ($pagenb < $pageposafter)
701
-					{
702
-						$pdf->setPage($pagenb);
703
-						if ($pagenb == $pageposbeforeprintlines)
704
-						{
705
-							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
706
-						}
707
-						else
708
-						{
709
-							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
710
-						}
711
-						$this->_pagefoot($pdf,$object,$outputlangs,1);
712
-						$pagenb++;
713
-						$pdf->setPage($pagenb);
714
-						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
715
-						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
716
-					}
717
-					if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
718
-					{
719
-					    if ($pagenb == $pageposafter)
720
-						{
721
-							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
722
-						}
723
-						else
724
-						{
725
-							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
726
-						}
727
-						$this->_pagefoot($pdf,$object,$outputlangs,1);
728
-						// New page
729
-						$pdf->AddPage();
730
-						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
731
-						$pagenb++;
732
-						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
733
-					}
734
-				}
487
+                // Loop on each lines
488
+                $pageposbeforeprintlines=$pdf->getPage();
489
+                $pagenb = $pageposbeforeprintlines;
490
+                for ($i = 0; $i < $nblignes; $i++)
491
+                {
492
+                    $curY = $nexY;
493
+                    $pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
494
+                    $pdf->SetTextColor(0,0,0);
495
+
496
+                    // Define size of image if we need it
497
+                    $imglinesize=array();
498
+                    if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
499
+
500
+                    $pdf->setTopMargin($tab_top_newpage);
501
+                    $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
502
+                    $pageposbefore=$pdf->getPage();
503
+
504
+                    $showpricebeforepagebreak=1;
505
+                    $posYAfterImage=0;
506
+                    $posYAfterDescription=0;
507
+
508
+                    if($this->getColumnStatus('photo'))
509
+                    {
510
+                        // We start with Photo of product line
511
+                        if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot)))	// If photo too high, we moved completely on new page
512
+                        {
513
+                            $pdf->AddPage('','',true);
514
+                            if (! empty($tplidx)) $pdf->useTemplate($tplidx);
515
+                            //if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
516
+                            $pdf->setPage($pageposbefore+1);
517
+
518
+                            $curY = $tab_top_newpage;
519
+                            $showpricebeforepagebreak=0;
520
+                        }
521
+
522
+
523
+                        if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height']))
524
+                        {
525
+                            $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);	// Use 300 dpi
526
+                            // $pdf->Image does not increase value return by getY, so we save it manually
527
+                            $posYAfterImage=$curY+$imglinesize['height'];
528
+                        }
529
+                    }
530
+
531
+                    // Description of product line
532
+                    if($this->getColumnStatus('desc'))
533
+                    {
534
+                        $pdf->startTransaction();
535
+                        pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->getColumnContentWidth('desc'),3,$this->getColumnContentXStart('desc'),$curY,$hideref,$hidedesc);
536
+                        $pageposafter=$pdf->getPage();
537
+                        if ($pageposafter > $pageposbefore)	// There is a pagebreak
538
+                        {
539
+                            $pdf->rollbackTransaction(true);
540
+                            $pageposafter=$pageposbefore;
541
+                            //print $pageposafter.'-'.$pageposbefore;exit;
542
+                            $pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
543
+                            pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->getColumnContentWidth('desc'),3,$this->getColumnContentXStart('desc'),$curY,$hideref,$hidedesc);
544
+
545
+                            $pageposafter=$pdf->getPage();
546
+                            $posyafter=$pdf->GetY();
547
+                            //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
548
+                            if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot)))	// There is no space left for total+free text
549
+                            {
550
+                                if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
551
+                                {
552
+                                    $pdf->AddPage('','',true);
553
+                                    if (! empty($tplidx)) $pdf->useTemplate($tplidx);
554
+                                    //if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
555
+                                    $pdf->setPage($pageposafter+1);
556
+                                }
557
+                            }
558
+                            else
559
+                            {
560
+                                // We found a page break
561
+                                $showpricebeforepagebreak=0;
562
+                            }
563
+                        }
564
+                        else	// No pagebreak
565
+                        {
566
+                            $pdf->commitTransaction();
567
+                        }
568
+                        $posYAfterDescription=$pdf->GetY();
569
+                    }
570
+
571
+                    $nexY = $pdf->GetY();
572
+                    $pageposafter=$pdf->getPage();
573
+
574
+                    $pdf->setPage($pageposbefore);
575
+                    $pdf->setTopMargin($this->marge_haute);
576
+                    $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
577
+
578
+                    // We suppose that a too long description or photo were moved completely on next page
579
+                    if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
580
+                        $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
581
+                    }
582
+
583
+                    $pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
584
+
585
+                    // VAT Rate
586
+                    if ($this->getColumnStatus('vat'))
587
+                    {
588
+                        $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
589
+                        $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
590
+                        $nexY = max($pdf->GetY(),$nexY);
591
+                    }
592
+
593
+                    // Unit price before discount
594
+                    if ($this->getColumnStatus('subprice'))
595
+                    {
596
+                        $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
597
+                        $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
598
+                        $nexY = max($pdf->GetY(),$nexY);
599
+                    }
600
+
601
+                    // Quantity
602
+                    // Enough for 6 chars
603
+                    if ($this->getColumnStatus('qty'))
604
+                    {
605
+                        $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
606
+                        $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
607
+                        $nexY = max($pdf->GetY(),$nexY);
608
+                    }
609
+
610
+
611
+                    // Unit
612
+                    if ($this->getColumnStatus('unit'))
613
+                    {
614
+                        $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
615
+                        $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
616
+                        $nexY = max($pdf->GetY(),$nexY);
617
+                    }
618
+
619
+                    // Discount on line
620
+                    if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent)
621
+                    {
622
+                        $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
623
+                        $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
624
+                        $nexY = max($pdf->GetY(),$nexY);
625
+                    }
626
+
627
+                    // Total HT line
628
+                    if ($this->getColumnStatus('totalexcltax'))
629
+                    {
630
+                        $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
631
+                        $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
632
+                        $nexY = max($pdf->GetY(),$nexY);
633
+                    }
634
+
635
+
636
+                    $parameters=array(
637
+                        'object' => $object,
638
+                        'i' => $i,
639
+                        'pdf' =>& $pdf,
640
+                        'curY' =>& $curY,
641
+                        'nexY' =>& $nexY,
642
+                        'outputlangs' => $outputlangs,
643
+                        'hidedetails' => $hidedetails
644
+                    );
645
+                    $reshook=$hookmanager->executeHooks('printPDFline',$parameters,$this);    // Note that $object may have been modified by hook
646
+
647
+
648
+
649
+                    // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
650
+                    if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
651
+                    else $tvaligne=$object->lines[$i]->total_tva;
652
+
653
+                    $localtax1ligne=$object->lines[$i]->total_localtax1;
654
+                    $localtax2ligne=$object->lines[$i]->total_localtax2;
655
+                    $localtax1_rate=$object->lines[$i]->localtax1_tx;
656
+                    $localtax2_rate=$object->lines[$i]->localtax2_tx;
657
+                    $localtax1_type=$object->lines[$i]->localtax1_type;
658
+                    $localtax2_type=$object->lines[$i]->localtax2_type;
659
+
660
+                    if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
661
+                    if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
662
+                    if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
663
+
664
+                    $vatrate=(string) $object->lines[$i]->tva_tx;
665
+
666
+                    // Retrieve type from database for backward compatibility with old records
667
+                    if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
668
+                    && (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
669
+                    {
670
+                        $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc);
671
+                        $localtax1_type = $localtaxtmp_array[0];
672
+                        $localtax2_type = $localtaxtmp_array[2];
673
+                    }
674
+
675
+                    // retrieve global local tax
676
+                    if ($localtax1_type && $localtax1ligne != 0)
677
+                        $this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
678
+                    if ($localtax2_type && $localtax2ligne != 0)
679
+                        $this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
680
+
681
+                    if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
682
+                    if (! isset($this->tva[$vatrate]))				$this->tva[$vatrate]=0;
683
+                    $this->tva[$vatrate] += $tvaligne;
684
+
685
+                    if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
686
+
687
+                    // Add line
688
+                    if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
689
+                    {
690
+                        $pdf->setPage($pageposafter);
691
+                        $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
692
+                        //$pdf->SetDrawColor(190,190,200);
693
+                        $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
694
+                        $pdf->SetLineStyle(array('dash'=>0));
695
+                    }
696
+
697
+                    $nexY+=2;    // Passe espace entre les lignes
698
+
699
+                    // Detect if some page were added automatically and output _tableau for past pages
700
+                    while ($pagenb < $pageposafter)
701
+                    {
702
+                        $pdf->setPage($pagenb);
703
+                        if ($pagenb == $pageposbeforeprintlines)
704
+                        {
705
+                            $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
706
+                        }
707
+                        else
708
+                        {
709
+                            $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
710
+                        }
711
+                        $this->_pagefoot($pdf,$object,$outputlangs,1);
712
+                        $pagenb++;
713
+                        $pdf->setPage($pagenb);
714
+                        $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
715
+                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
716
+                    }
717
+                    if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
718
+                    {
719
+                        if ($pagenb == $pageposafter)
720
+                        {
721
+                            $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
722
+                        }
723
+                        else
724
+                        {
725
+                            $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
726
+                        }
727
+                        $this->_pagefoot($pdf,$object,$outputlangs,1);
728
+                        // New page
729
+                        $pdf->AddPage();
730
+                        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
731
+                        $pagenb++;
732
+                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
733
+                    }
734
+                }
735 735
 
736
-				// Show square
737
-				if ($pagenb == $pageposbeforeprintlines)
738
-				{
739
-					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
740
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
741
-				}
742
-				else
743
-				{
744
-					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
745
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
746
-				}
736
+                // Show square
737
+                if ($pagenb == $pageposbeforeprintlines)
738
+                {
739
+                    $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
740
+                    $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
741
+                }
742
+                else
743
+                {
744
+                    $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
745
+                    $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
746
+                }
747 747
 
748
-				// Affiche zone infos
749
-				$posy=$this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
748
+                // Affiche zone infos
749
+                $posy=$this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
750 750
 
751
-				// Affiche zone totaux
752
-				$posy=$this->drawTotalTable($pdf, $object, 0, $bottomlasttab, $outputlangs);
751
+                // Affiche zone totaux
752
+                $posy=$this->drawTotalTable($pdf, $object, 0, $bottomlasttab, $outputlangs);
753 753
 
754
-				// Affiche zone versements
755
-				/*
754
+                // Affiche zone versements
755
+                /*
756 756
 				if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
757 757
 				{
758 758
 					$posy=$this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
759 759
 				}
760 760
 				*/
761 761
 
762
-				// Customer signature area
763
-				if (empty($conf->global->PROPAL_DISABLE_SIGNATURE))
764
-				{
765
-				    $posy=$this->drawSignatureArea($pdf, $object, $posy, $outputlangs);
766
-				}
767
-
768
-				// Pied de page
769
-				$this->_pagefoot($pdf,$object,$outputlangs);
770
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
771
-
772
-				//If propal merge product PDF is active
773
-				if (!empty($conf->global->PRODUIT_PDF_MERGE_PROPAL))
774
-				{
775
-					require_once DOL_DOCUMENT_ROOT.'/product/class/propalmergepdfproduct.class.php';
776
-
777
-					$already_merged = array ();
778
-					foreach ( $object->lines as $line ) {
779
-						if (! empty($line->fk_product) && ! (in_array($line->fk_product, $already_merged))) {
780
-							// Find the desire PDF
781
-							$filetomerge = new Propalmergepdfproduct($this->db);
782
-
783
-							if ($conf->global->MAIN_MULTILANGS) {
784
-								$filetomerge->fetch_by_product($line->fk_product, $outputlangs->defaultlang);
785
-							} else {
786
-								$filetomerge->fetch_by_product($line->fk_product);
787
-							}
788
-
789
-							$already_merged[] = $line->fk_product;
790
-
791
-							$product = new Product($this->db);
792
-							$product->fetch($line->fk_product);
793
-
794
-							if ($product->entity!=$conf->entity) {
795
-								$entity_product_file=$product->entity;
796
-							} else {
797
-								$entity_product_file=$conf->entity;
798
-							}
799
-
800
-							// If PDF is selected and file is not empty
801
-							if (count($filetomerge->lines) > 0) {
802
-								foreach ( $filetomerge->lines as $linefile ) {
803
-									if (! empty($linefile->id) && ! empty($linefile->file_name)) {
804
-
805
-
806
-										if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
807
-										{
808
-											if (! empty($conf->product->enabled)) {
809
-												$filetomerge_dir = $conf->product->multidir_output[$entity_product_file] . '/' . get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos";
810
-											} elseif (! empty($conf->service->enabled)) {
811
-												$filetomerge_dir = $conf->service->multidir_output[$entity_product_file] . '/' . get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos";
812
-											}
813
-										}
814
-										else
815
-										{
816
-											if (! empty($conf->product->enabled)) {
817
-												$filetomerge_dir = $conf->product->multidir_output[$entity_product_file] . '/' . get_exdir(0,0,0,0,$product,'product') . dol_sanitizeFileName($product->ref);
818
-											} elseif (! empty($conf->service->enabled)) {
819
-												$filetomerge_dir = $conf->service->multidir_output[$entity_product_file] . '/' . get_exdir(0,0,0,0,$product,'product') . dol_sanitizeFileName($product->ref);
820
-											}
821
-										}
822
-
823
-										dol_syslog(get_class($this) . ':: upload_dir=' . $filetomerge_dir, LOG_DEBUG);
824
-
825
-										$infile = $filetomerge_dir . '/' . $linefile->file_name;
826
-										if (file_exists($infile) && is_readable($infile)) {
827
-											$pagecount = $pdf->setSourceFile($infile);
828
-											for($i = 1; $i <= $pagecount; $i ++) {
829
-												$tplIdx = $pdf->importPage($i);
830
-												if ($tplIdx!==false) {
831
-													$s = $pdf->getTemplatesize($tplIdx);
832
-													$pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
833
-													$pdf->useTemplate($tplIdx);
834
-												} else {
835
-													setEventMessages(null, array($infile.' cannot be added, probably protected PDF'),'warnings');
836
-												}
837
-											}
838
-										}
839
-									}
840
-								}
841
-							}
842
-						}
843
-					}
844
-				}
845
-
846
-				$pdf->Close();
847
-
848
-				$pdf->Output($file,'F');
849
-
850
-				//Add pdfgeneration hook
851
-				$hookmanager->initHooks(array('pdfgeneration'));
852
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
853
-				global $action;
854
-				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
762
+                // Customer signature area
763
+                if (empty($conf->global->PROPAL_DISABLE_SIGNATURE))
764
+                {
765
+                    $posy=$this->drawSignatureArea($pdf, $object, $posy, $outputlangs);
766
+                }
855 767
 
856
-				if (! empty($conf->global->MAIN_UMASK))
857
-				@chmod($file, octdec($conf->global->MAIN_UMASK));
768
+                // Pied de page
769
+                $this->_pagefoot($pdf,$object,$outputlangs);
770
+                if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
858 771
 
859
-				$this->result = array('fullpath'=>$file);
772
+                //If propal merge product PDF is active
773
+                if (!empty($conf->global->PRODUIT_PDF_MERGE_PROPAL))
774
+                {
775
+                    require_once DOL_DOCUMENT_ROOT.'/product/class/propalmergepdfproduct.class.php';
776
+
777
+                    $already_merged = array ();
778
+                    foreach ( $object->lines as $line ) {
779
+                        if (! empty($line->fk_product) && ! (in_array($line->fk_product, $already_merged))) {
780
+                            // Find the desire PDF
781
+                            $filetomerge = new Propalmergepdfproduct($this->db);
782
+
783
+                            if ($conf->global->MAIN_MULTILANGS) {
784
+                                $filetomerge->fetch_by_product($line->fk_product, $outputlangs->defaultlang);
785
+                            } else {
786
+                                $filetomerge->fetch_by_product($line->fk_product);
787
+                            }
788
+
789
+                            $already_merged[] = $line->fk_product;
790
+
791
+                            $product = new Product($this->db);
792
+                            $product->fetch($line->fk_product);
793
+
794
+                            if ($product->entity!=$conf->entity) {
795
+                                $entity_product_file=$product->entity;
796
+                            } else {
797
+                                $entity_product_file=$conf->entity;
798
+                            }
799
+
800
+                            // If PDF is selected and file is not empty
801
+                            if (count($filetomerge->lines) > 0) {
802
+                                foreach ( $filetomerge->lines as $linefile ) {
803
+                                    if (! empty($linefile->id) && ! empty($linefile->file_name)) {
804
+
805
+
806
+                                        if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
807
+                                        {
808
+                                            if (! empty($conf->product->enabled)) {
809
+                                                $filetomerge_dir = $conf->product->multidir_output[$entity_product_file] . '/' . get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos";
810
+                                            } elseif (! empty($conf->service->enabled)) {
811
+                                                $filetomerge_dir = $conf->service->multidir_output[$entity_product_file] . '/' . get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos";
812
+                                            }
813
+                                        }
814
+                                        else
815
+                                        {
816
+                                            if (! empty($conf->product->enabled)) {
817
+                                                $filetomerge_dir = $conf->product->multidir_output[$entity_product_file] . '/' . get_exdir(0,0,0,0,$product,'product') . dol_sanitizeFileName($product->ref);
818
+                                            } elseif (! empty($conf->service->enabled)) {
819
+                                                $filetomerge_dir = $conf->service->multidir_output[$entity_product_file] . '/' . get_exdir(0,0,0,0,$product,'product') . dol_sanitizeFileName($product->ref);
820
+                                            }
821
+                                        }
822
+
823
+                                        dol_syslog(get_class($this) . ':: upload_dir=' . $filetomerge_dir, LOG_DEBUG);
824
+
825
+                                        $infile = $filetomerge_dir . '/' . $linefile->file_name;
826
+                                        if (file_exists($infile) && is_readable($infile)) {
827
+                                            $pagecount = $pdf->setSourceFile($infile);
828
+                                            for($i = 1; $i <= $pagecount; $i ++) {
829
+                                                $tplIdx = $pdf->importPage($i);
830
+                                                if ($tplIdx!==false) {
831
+                                                    $s = $pdf->getTemplatesize($tplIdx);
832
+                                                    $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
833
+                                                    $pdf->useTemplate($tplIdx);
834
+                                                } else {
835
+                                                    setEventMessages(null, array($infile.' cannot be added, probably protected PDF'),'warnings');
836
+                                                }
837
+                                            }
838
+                                        }
839
+                                    }
840
+                                }
841
+                            }
842
+                        }
843
+                    }
844
+                }
860 845
 
861
-				return 1;   // Pas d'erreur
862
-			}
863
-			else
864
-			{
865
-				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
866
-				return 0;
867
-			}
868
-		}
869
-		else
870
-		{
871
-			$this->error=$langs->trans("ErrorConstantNotDefined","PROP_OUTPUTDIR");
872
-			return 0;
873
-		}
874
-	}
875
-
876
-	/**
877
-	 *  Show payments table
878
-	 *
846
+                $pdf->Close();
847
+
848
+                $pdf->Output($file,'F');
849
+
850
+                //Add pdfgeneration hook
851
+                $hookmanager->initHooks(array('pdfgeneration'));
852
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
853
+                global $action;
854
+                $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
855
+
856
+                if (! empty($conf->global->MAIN_UMASK))
857
+                @chmod($file, octdec($conf->global->MAIN_UMASK));
858
+
859
+                $this->result = array('fullpath'=>$file);
860
+
861
+                return 1;   // Pas d'erreur
862
+            }
863
+            else
864
+            {
865
+                $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
866
+                return 0;
867
+            }
868
+        }
869
+        else
870
+        {
871
+            $this->error=$langs->trans("ErrorConstantNotDefined","PROP_OUTPUTDIR");
872
+            return 0;
873
+        }
874
+    }
875
+
876
+    /**
877
+     *  Show payments table
878
+     *
879 879
      *  @param	TCPDF		$pdf           Object PDF
880 880
      *  @param  Object		$object         Object proposal
881 881
      *  @param  int			$posy           Position y in PDF
882 882
      *  @param  Translate	$outputlangs    Object langs for output
883 883
      *  @return int             			<0 if KO, >0 if OK
884
-	 */
885
-	private function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
886
-	{
887
-	}
888
-
889
-	/**
890
-	 *   Show miscellaneous information (payment mode, payment term, ...)
891
-	 *
892
-	 *   @param		TCPDF		$pdf     		Object PDF
893
-	 *   @param		Object		$object			Object to show
894
-	 *   @param		int			$posy			Y
895
-	 *   @param		Translate	$outputlangs	Langs object
896
-	 *   @return	void
897
-	 */
898
-	function drawInfoTable(&$pdf, $object, $posy, $outputlangs)
899
-	{
900
-		global $conf;
901
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
902
-
903
-		$pdf->SetFont('','', $default_font_size - 1);
904
-
905
-		// If France, show VAT mention if not applicable
906
-		if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
907
-		{
908
-			$pdf->SetFont('','B', $default_font_size - 2);
909
-			$pdf->SetXY($this->marge_gauche, $posy);
910
-			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
911
-
912
-			$posy=$pdf->GetY()+4;
913
-		}
914
-
915
-		$posxval=52;
884
+     */
885
+    private function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
886
+    {
887
+    }
888
+
889
+    /**
890
+     *   Show miscellaneous information (payment mode, payment term, ...)
891
+     *
892
+     *   @param		TCPDF		$pdf     		Object PDF
893
+     *   @param		Object		$object			Object to show
894
+     *   @param		int			$posy			Y
895
+     *   @param		Translate	$outputlangs	Langs object
896
+     *   @return	void
897
+     */
898
+    function drawInfoTable(&$pdf, $object, $posy, $outputlangs)
899
+    {
900
+        global $conf;
901
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
902
+
903
+        $pdf->SetFont('','', $default_font_size - 1);
904
+
905
+        // If France, show VAT mention if not applicable
906
+        if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
907
+        {
908
+            $pdf->SetFont('','B', $default_font_size - 2);
909
+            $pdf->SetXY($this->marge_gauche, $posy);
910
+            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
911
+
912
+            $posy=$pdf->GetY()+4;
913
+        }
914
+
915
+        $posxval=52;
916 916
 
917 917
         // Show shipping date
918 918
         if (! empty($object->date_livraison))
919
-		{
919
+        {
920 920
             $outputlangs->load("sendings");
921
-			$pdf->SetFont('','B', $default_font_size - 2);
922
-			$pdf->SetXY($this->marge_gauche, $posy);
923
-			$titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
924
-			$pdf->MultiCell(80, 4, $titre, 0, 'L');
925
-			$pdf->SetFont('','', $default_font_size - 2);
926
-			$pdf->SetXY($posxval, $posy);
927
-			$dlp=dol_print_date($object->date_livraison,"daytext",false,$outputlangs,true);
928
-			$pdf->MultiCell(80, 4, $dlp, 0, 'L');
921
+            $pdf->SetFont('','B', $default_font_size - 2);
922
+            $pdf->SetXY($this->marge_gauche, $posy);
923
+            $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
924
+            $pdf->MultiCell(80, 4, $titre, 0, 'L');
925
+            $pdf->SetFont('','', $default_font_size - 2);
926
+            $pdf->SetXY($posxval, $posy);
927
+            $dlp=dol_print_date($object->date_livraison,"daytext",false,$outputlangs,true);
928
+            $pdf->MultiCell(80, 4, $dlp, 0, 'L');
929 929
 
930 930
             $posy=$pdf->GetY()+1;
931
-		}
931
+        }
932 932
         elseif ($object->availability_code || $object->availability)    // Show availability conditions
933
-		{
934
-			$pdf->SetFont('','B', $default_font_size - 2);
935
-			$pdf->SetXY($this->marge_gauche, $posy);
936
-			$titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
937
-			$pdf->MultiCell(80, 4, $titre, 0, 'L');
938
-			$pdf->SetTextColor(0,0,0);
939
-			$pdf->SetFont('','', $default_font_size - 2);
940
-			$pdf->SetXY($posxval, $posy);
941
-			$lib_availability=$outputlangs->transnoentities("AvailabilityType".$object->availability_code)!=('AvailabilityType'.$object->availability_code)?$outputlangs->transnoentities("AvailabilityType".$object->availability_code):$outputlangs->convToOutputCharset($object->availability);
942
-			$lib_availability=str_replace('\n',"\n",$lib_availability);
943
-			$pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
944
-
945
-			$posy=$pdf->GetY()+1;
946
-		}
947
-
948
-		// Show payments conditions
949
-		if (empty($conf->global->PROPALE_PDF_HIDE_PAYMENTTERMCOND) && ($object->cond_reglement_code || $object->cond_reglement))
950
-		{
951
-			$pdf->SetFont('','B', $default_font_size - 2);
952
-			$pdf->SetXY($this->marge_gauche, $posy);
953
-			$titre = $outputlangs->transnoentities("PaymentConditions").':';
954
-			$pdf->MultiCell(43, 4, $titre, 0, 'L');
955
-
956
-			$pdf->SetFont('','', $default_font_size - 2);
957
-			$pdf->SetXY($posxval, $posy);
958
-			$lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc);
959
-			$lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
960
-			$pdf->MultiCell(67, 4, $lib_condition_paiement,0,'L');
961
-
962
-			$posy=$pdf->GetY()+3;
963
-		}
964
-
965
-		if (empty($conf->global->PROPALE_PDF_HIDE_PAYMENTTERMMODE))
966
-		{
967
-			// Check a payment mode is defined
968
-			/* Not required on a proposal
933
+        {
934
+            $pdf->SetFont('','B', $default_font_size - 2);
935
+            $pdf->SetXY($this->marge_gauche, $posy);
936
+            $titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
937
+            $pdf->MultiCell(80, 4, $titre, 0, 'L');
938
+            $pdf->SetTextColor(0,0,0);
939
+            $pdf->SetFont('','', $default_font_size - 2);
940
+            $pdf->SetXY($posxval, $posy);
941
+            $lib_availability=$outputlangs->transnoentities("AvailabilityType".$object->availability_code)!=('AvailabilityType'.$object->availability_code)?$outputlangs->transnoentities("AvailabilityType".$object->availability_code):$outputlangs->convToOutputCharset($object->availability);
942
+            $lib_availability=str_replace('\n',"\n",$lib_availability);
943
+            $pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
944
+
945
+            $posy=$pdf->GetY()+1;
946
+        }
947
+
948
+        // Show payments conditions
949
+        if (empty($conf->global->PROPALE_PDF_HIDE_PAYMENTTERMCOND) && ($object->cond_reglement_code || $object->cond_reglement))
950
+        {
951
+            $pdf->SetFont('','B', $default_font_size - 2);
952
+            $pdf->SetXY($this->marge_gauche, $posy);
953
+            $titre = $outputlangs->transnoentities("PaymentConditions").':';
954
+            $pdf->MultiCell(43, 4, $titre, 0, 'L');
955
+
956
+            $pdf->SetFont('','', $default_font_size - 2);
957
+            $pdf->SetXY($posxval, $posy);
958
+            $lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc);
959
+            $lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
960
+            $pdf->MultiCell(67, 4, $lib_condition_paiement,0,'L');
961
+
962
+            $posy=$pdf->GetY()+3;
963
+        }
964
+
965
+        if (empty($conf->global->PROPALE_PDF_HIDE_PAYMENTTERMMODE))
966
+        {
967
+            // Check a payment mode is defined
968
+            /* Not required on a proposal
969 969
 			if (empty($object->mode_reglement_code)
970 970
 			&& ! $conf->global->FACTURE_CHQ_NUMBER
971 971
 			&& ! $conf->global->FACTURE_RIB_NUMBER)
@@ -980,333 +980,333 @@  discard block
 block discarded – undo
980 980
 			}
981 981
 			*/
982 982
 
983
-			// Show payment mode
984
-			if ($object->mode_reglement_code
985
-			&& $object->mode_reglement_code != 'CHQ'
986
-			&& $object->mode_reglement_code != 'VIR')
987
-			{
988
-				$pdf->SetFont('','B', $default_font_size - 2);
989
-				$pdf->SetXY($this->marge_gauche, $posy);
990
-				$titre = $outputlangs->transnoentities("PaymentMode").':';
991
-				$pdf->MultiCell(80, 5, $titre, 0, 'L');
992
-				$pdf->SetFont('','', $default_font_size - 2);
993
-				$pdf->SetXY($posxval, $posy);
994
-				$lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement);
995
-				$pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
996
-
997
-				$posy=$pdf->GetY()+2;
998
-			}
999
-
1000
-			// Show payment mode CHQ
1001
-			if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
1002
-			{
1003
-				// Si mode reglement non force ou si force a CHQ
1004
-				if (! empty($conf->global->FACTURE_CHQ_NUMBER))
1005
-				{
1006
-					$diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
1007
-
1008
-					if ($conf->global->FACTURE_CHQ_NUMBER > 0)
1009
-					{
1010
-						$account = new Account($this->db);
1011
-						$account->fetch($conf->global->FACTURE_CHQ_NUMBER);
1012
-
1013
-						$pdf->SetXY($this->marge_gauche, $posy);
1014
-						$pdf->SetFont('','B', $default_font_size - $diffsizetitle);
1015
-						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio),0,'L',0);
1016
-						$posy=$pdf->GetY()+1;
1017
-
1018
-			            if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1019
-			            {
1020
-							$pdf->SetXY($this->marge_gauche, $posy);
1021
-							$pdf->SetFont('','', $default_font_size - $diffsizetitle);
1022
-							$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
1023
-							$posy=$pdf->GetY()+2;
1024
-			            }
1025
-					}
1026
-					if ($conf->global->FACTURE_CHQ_NUMBER == -1)
1027
-					{
1028
-						$pdf->SetXY($this->marge_gauche, $posy);
1029
-						$pdf->SetFont('','B', $default_font_size - $diffsizetitle);
1030
-						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$this->emetteur->name),0,'L',0);
1031
-						$posy=$pdf->GetY()+1;
1032
-
1033
-			            if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1034
-			            {
1035
-							$pdf->SetXY($this->marge_gauche, $posy);
1036
-							$pdf->SetFont('','', $default_font_size - $diffsizetitle);
1037
-							$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1038
-							$posy=$pdf->GetY()+2;
1039
-			            }
1040
-					}
1041
-				}
1042
-			}
983
+            // Show payment mode
984
+            if ($object->mode_reglement_code
985
+            && $object->mode_reglement_code != 'CHQ'
986
+            && $object->mode_reglement_code != 'VIR')
987
+            {
988
+                $pdf->SetFont('','B', $default_font_size - 2);
989
+                $pdf->SetXY($this->marge_gauche, $posy);
990
+                $titre = $outputlangs->transnoentities("PaymentMode").':';
991
+                $pdf->MultiCell(80, 5, $titre, 0, 'L');
992
+                $pdf->SetFont('','', $default_font_size - 2);
993
+                $pdf->SetXY($posxval, $posy);
994
+                $lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement);
995
+                $pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
996
+
997
+                $posy=$pdf->GetY()+2;
998
+            }
999
+
1000
+            // Show payment mode CHQ
1001
+            if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
1002
+            {
1003
+                // Si mode reglement non force ou si force a CHQ
1004
+                if (! empty($conf->global->FACTURE_CHQ_NUMBER))
1005
+                {
1006
+                    $diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
1007
+
1008
+                    if ($conf->global->FACTURE_CHQ_NUMBER > 0)
1009
+                    {
1010
+                        $account = new Account($this->db);
1011
+                        $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
1012
+
1013
+                        $pdf->SetXY($this->marge_gauche, $posy);
1014
+                        $pdf->SetFont('','B', $default_font_size - $diffsizetitle);
1015
+                        $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio),0,'L',0);
1016
+                        $posy=$pdf->GetY()+1;
1017
+
1018
+                        if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1019
+                        {
1020
+                            $pdf->SetXY($this->marge_gauche, $posy);
1021
+                            $pdf->SetFont('','', $default_font_size - $diffsizetitle);
1022
+                            $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
1023
+                            $posy=$pdf->GetY()+2;
1024
+                        }
1025
+                    }
1026
+                    if ($conf->global->FACTURE_CHQ_NUMBER == -1)
1027
+                    {
1028
+                        $pdf->SetXY($this->marge_gauche, $posy);
1029
+                        $pdf->SetFont('','B', $default_font_size - $diffsizetitle);
1030
+                        $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$this->emetteur->name),0,'L',0);
1031
+                        $posy=$pdf->GetY()+1;
1032
+
1033
+                        if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1034
+                        {
1035
+                            $pdf->SetXY($this->marge_gauche, $posy);
1036
+                            $pdf->SetFont('','', $default_font_size - $diffsizetitle);
1037
+                            $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1038
+                            $posy=$pdf->GetY()+2;
1039
+                        }
1040
+                    }
1041
+                }
1042
+            }
1043 1043
 
1044
-			// If payment mode not forced or forced to VIR, show payment with BAN
1045
-			if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
1046
-			{
1047
-				if (! empty($object->fk_account) || ! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
1048
-				{
1049
-					$bankid=(empty($object->fk_account)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_account);
1050
-					if (! empty($object->fk_bank)) $bankid=$object->fk_bank;   // For backward compatibility when object->fk_account is forced with object->fk_bank
1051
-					$account = new Account($this->db);
1052
-					$account->fetch($bankid);
1044
+            // If payment mode not forced or forced to VIR, show payment with BAN
1045
+            if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
1046
+            {
1047
+                if (! empty($object->fk_account) || ! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
1048
+                {
1049
+                    $bankid=(empty($object->fk_account)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_account);
1050
+                    if (! empty($object->fk_bank)) $bankid=$object->fk_bank;   // For backward compatibility when object->fk_account is forced with object->fk_bank
1051
+                    $account = new Account($this->db);
1052
+                    $account->fetch($bankid);
1053 1053
 
1054
-					$curx=$this->marge_gauche;
1055
-					$cury=$posy;
1054
+                    $curx=$this->marge_gauche;
1055
+                    $cury=$posy;
1056 1056
 
1057
-					$posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size);
1057
+                    $posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size);
1058 1058
 
1059
-					$posy+=2;
1060
-				}
1061
-			}
1062
-		}
1063
-
1064
-		return $posy;
1065
-	}
1066
-
1067
-
1068
-	/**
1069
-	 *	Show total to pay
1070
-	 *
1071
-	 *	@param	PDF			$pdf            Object PDF
1072
-	 *	@param  Facture		$object         Object invoice
1073
-	 *	@param  int			$deja_regle     Montant deja regle
1074
-	 *	@param	int			$posy			Position depart
1075
-	 *	@param	Translate	$outputlangs	Objet langs
1076
-	 *	@return int							Position pour suite
1077
-	 */
1078
-	private function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs)
1079
-	{
1080
-		global $conf,$mysoc;
1081
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
1082
-
1083
-		$tab2_top = $posy;
1084
-		$tab2_hl = 4;
1085
-		$pdf->SetFont('','', $default_font_size - 1);
1086
-
1087
-		// Tableau total
1088
-		$col1x = 120; $col2x = 170;
1089
-		if ($this->page_largeur < 210) // To work with US executive format
1090
-		{
1091
-			$col2x-=20;
1092
-		}
1093
-		$largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1094
-
1095
-		$useborder=0;
1096
-		$index = 0;
1097
-
1098
-		// Total HT
1099
-		$pdf->SetFillColor(255,255,255);
1100
-		$pdf->SetXY($col1x, $tab2_top + 0);
1101
-		$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1102
-
1103
-		$total_ht = ($conf->multicurrency->enabled && $object->mylticurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1104
-		$pdf->SetXY($col2x, $tab2_top + 0);
1105
-		$pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (! empty($object->remise)?$object->remise:0), 0, $outputlangs), 0, 'R', 1);
1106
-
1107
-		// Show VAT by rates and total
1108
-		$pdf->SetFillColor(248,248,248);
1109
-
1110
-		$total_ttc = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1111
-
1112
-		$this->atleastoneratenotnull=0;
1113
-		if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1114
-		{
1115
-			$tvaisnull=((! empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1116
-			if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1117
-			{
1118
-				// Nothing to do
1119
-			}
1120
-			else
1121
-			{
1122
-				//Local tax 1 before VAT
1123
-				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1124
-				//{
1125
-					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1126
-					{
1127
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1128
-
1129
-						foreach( $localtax_rate as $tvakey => $tvaval )
1130
-						{
1131
-							if ($tvakey!=0)    // On affiche pas taux 0
1132
-							{
1133
-								//$this->atleastoneratenotnull++;
1134
-
1135
-								$index++;
1136
-								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1137
-
1138
-								$tvacompl='';
1139
-								if (preg_match('/\*/',$tvakey))
1140
-								{
1141
-									$tvakey=str_replace('*','',$tvakey);
1142
-									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1143
-								}
1144
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1145
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1146
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1147
-
1148
-								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1149
-								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1150
-							}
1151
-						}
1152
-					}
1153
-	      		//}
1154
-				//Local tax 2 before VAT
1155
-				//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1156
-				//{
1157
-					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1158
-					{
1159
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1160
-
1161
-						foreach( $localtax_rate as $tvakey => $tvaval )
1162
-						{
1163
-							if ($tvakey!=0)    // On affiche pas taux 0
1164
-							{
1165
-								//$this->atleastoneratenotnull++;
1166
-
1167
-
1168
-
1169
-								$index++;
1170
-								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1171
-
1172
-								$tvacompl='';
1173
-								if (preg_match('/\*/',$tvakey))
1174
-								{
1175
-									$tvakey=str_replace('*','',$tvakey);
1176
-									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1177
-								}
1178
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1179
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1180
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1181
-
1182
-								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1183
-								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1184
-							}
1185
-						}
1186
-					}
1187
-				//}
1188
-				// VAT
1189
-				foreach($this->tva as $tvakey => $tvaval)
1190
-				{
1191
-					if ($tvakey != 0)    // On affiche pas taux 0
1192
-					{
1193
-						$this->atleastoneratenotnull++;
1194
-
1195
-						$index++;
1196
-						$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1197
-
1198
-						$tvacompl='';
1199
-						if (preg_match('/\*/',$tvakey))
1200
-						{
1201
-							$tvakey=str_replace('*','',$tvakey);
1202
-							$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1203
-						}
1204
-						$totalvat =$outputlangs->transcountrynoentities("TotalVAT",$mysoc->country_code).' ';
1205
-						$totalvat.=vatrate($tvakey,1).$tvacompl;
1206
-						$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1207
-
1208
-						$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1209
-						$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1210
-					}
1211
-				}
1059
+                    $posy+=2;
1060
+                }
1061
+            }
1062
+        }
1212 1063
 
1213
-				//Local tax 1 after VAT
1214
-				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1215
-				//{
1216
-					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1217
-					{
1218
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1219
-
1220
-						foreach( $localtax_rate as $tvakey => $tvaval )
1221
-						{
1222
-							if ($tvakey != 0)    // On affiche pas taux 0
1223
-							{
1224
-								//$this->atleastoneratenotnull++;
1225
-
1226
-								$index++;
1227
-								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1228
-
1229
-								$tvacompl='';
1230
-								if (preg_match('/\*/',$tvakey))
1231
-								{
1232
-									$tvakey=str_replace('*','',$tvakey);
1233
-									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1234
-								}
1235
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1236
-
1237
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1238
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1239
-								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1240
-								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1241
-							}
1242
-						}
1243
-					}
1244
-	      		//}
1245
-				//Local tax 2 after VAT
1246
-				//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1247
-				//{
1248
-					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1249
-					{
1250
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1251
-
1252
-						foreach( $localtax_rate as $tvakey => $tvaval )
1253
-						{
1254
-						    // retrieve global local tax
1255
-							if ($tvakey != 0)    // On affiche pas taux 0
1256
-							{
1257
-								//$this->atleastoneratenotnull++;
1258
-
1259
-								$index++;
1260
-								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1261
-
1262
-								$tvacompl='';
1263
-								if (preg_match('/\*/',$tvakey))
1264
-								{
1265
-									$tvakey=str_replace('*','',$tvakey);
1266
-									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1267
-								}
1268
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1269
-
1270
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1271
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1272
-
1273
-								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1274
-								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1275
-							}
1276
-						}
1277
-					}
1278
-				//}
1279
-
1280
-				// Total TTC
1281
-				$index++;
1282
-				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1283
-				$pdf->SetTextColor(0,0,60);
1284
-				$pdf->SetFillColor(224,224,224);
1285
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1064
+        return $posy;
1065
+    }
1286 1066
 
1287
-				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1288
-				$pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1289
-			}
1290
-		}
1291 1067
 
1292
-		$pdf->SetTextColor(0,0,0);
1068
+    /**
1069
+     *	Show total to pay
1070
+     *
1071
+     *	@param	PDF			$pdf            Object PDF
1072
+     *	@param  Facture		$object         Object invoice
1073
+     *	@param  int			$deja_regle     Montant deja regle
1074
+     *	@param	int			$posy			Position depart
1075
+     *	@param	Translate	$outputlangs	Objet langs
1076
+     *	@return int							Position pour suite
1077
+     */
1078
+    private function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs)
1079
+    {
1080
+        global $conf,$mysoc;
1081
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
1082
+
1083
+        $tab2_top = $posy;
1084
+        $tab2_hl = 4;
1085
+        $pdf->SetFont('','', $default_font_size - 1);
1086
+
1087
+        // Tableau total
1088
+        $col1x = 120; $col2x = 170;
1089
+        if ($this->page_largeur < 210) // To work with US executive format
1090
+        {
1091
+            $col2x-=20;
1092
+        }
1093
+        $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1094
+
1095
+        $useborder=0;
1096
+        $index = 0;
1097
+
1098
+        // Total HT
1099
+        $pdf->SetFillColor(255,255,255);
1100
+        $pdf->SetXY($col1x, $tab2_top + 0);
1101
+        $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1102
+
1103
+        $total_ht = ($conf->multicurrency->enabled && $object->mylticurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1104
+        $pdf->SetXY($col2x, $tab2_top + 0);
1105
+        $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (! empty($object->remise)?$object->remise:0), 0, $outputlangs), 0, 'R', 1);
1106
+
1107
+        // Show VAT by rates and total
1108
+        $pdf->SetFillColor(248,248,248);
1109
+
1110
+        $total_ttc = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1111
+
1112
+        $this->atleastoneratenotnull=0;
1113
+        if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1114
+        {
1115
+            $tvaisnull=((! empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1116
+            if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1117
+            {
1118
+                // Nothing to do
1119
+            }
1120
+            else
1121
+            {
1122
+                //Local tax 1 before VAT
1123
+                //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1124
+                //{
1125
+                    foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1126
+                    {
1127
+                        if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1128
+
1129
+                        foreach( $localtax_rate as $tvakey => $tvaval )
1130
+                        {
1131
+                            if ($tvakey!=0)    // On affiche pas taux 0
1132
+                            {
1133
+                                //$this->atleastoneratenotnull++;
1134
+
1135
+                                $index++;
1136
+                                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1137
+
1138
+                                $tvacompl='';
1139
+                                if (preg_match('/\*/',$tvakey))
1140
+                                {
1141
+                                    $tvakey=str_replace('*','',$tvakey);
1142
+                                    $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1143
+                                }
1144
+                                $totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1145
+                                $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1146
+                                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1147
+
1148
+                                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1149
+                                $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1150
+                            }
1151
+                        }
1152
+                    }
1153
+                    //}
1154
+                //Local tax 2 before VAT
1155
+                //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1156
+                //{
1157
+                    foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1158
+                    {
1159
+                        if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1160
+
1161
+                        foreach( $localtax_rate as $tvakey => $tvaval )
1162
+                        {
1163
+                            if ($tvakey!=0)    // On affiche pas taux 0
1164
+                            {
1165
+                                //$this->atleastoneratenotnull++;
1166
+
1167
+
1168
+
1169
+                                $index++;
1170
+                                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1171
+
1172
+                                $tvacompl='';
1173
+                                if (preg_match('/\*/',$tvakey))
1174
+                                {
1175
+                                    $tvakey=str_replace('*','',$tvakey);
1176
+                                    $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1177
+                                }
1178
+                                $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1179
+                                $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1180
+                                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1181
+
1182
+                                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1183
+                                $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1184
+                            }
1185
+                        }
1186
+                    }
1187
+                //}
1188
+                // VAT
1189
+                foreach($this->tva as $tvakey => $tvaval)
1190
+                {
1191
+                    if ($tvakey != 0)    // On affiche pas taux 0
1192
+                    {
1193
+                        $this->atleastoneratenotnull++;
1194
+
1195
+                        $index++;
1196
+                        $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1197
+
1198
+                        $tvacompl='';
1199
+                        if (preg_match('/\*/',$tvakey))
1200
+                        {
1201
+                            $tvakey=str_replace('*','',$tvakey);
1202
+                            $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1203
+                        }
1204
+                        $totalvat =$outputlangs->transcountrynoentities("TotalVAT",$mysoc->country_code).' ';
1205
+                        $totalvat.=vatrate($tvakey,1).$tvacompl;
1206
+                        $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1207
+
1208
+                        $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1209
+                        $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1210
+                    }
1211
+                }
1293 1212
 
1294
-		/*
1213
+                //Local tax 1 after VAT
1214
+                //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1215
+                //{
1216
+                    foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1217
+                    {
1218
+                        if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1219
+
1220
+                        foreach( $localtax_rate as $tvakey => $tvaval )
1221
+                        {
1222
+                            if ($tvakey != 0)    // On affiche pas taux 0
1223
+                            {
1224
+                                //$this->atleastoneratenotnull++;
1225
+
1226
+                                $index++;
1227
+                                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1228
+
1229
+                                $tvacompl='';
1230
+                                if (preg_match('/\*/',$tvakey))
1231
+                                {
1232
+                                    $tvakey=str_replace('*','',$tvakey);
1233
+                                    $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1234
+                                }
1235
+                                $totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1236
+
1237
+                                $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1238
+                                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1239
+                                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1240
+                                $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1241
+                            }
1242
+                        }
1243
+                    }
1244
+                    //}
1245
+                //Local tax 2 after VAT
1246
+                //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1247
+                //{
1248
+                    foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1249
+                    {
1250
+                        if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1251
+
1252
+                        foreach( $localtax_rate as $tvakey => $tvaval )
1253
+                        {
1254
+                            // retrieve global local tax
1255
+                            if ($tvakey != 0)    // On affiche pas taux 0
1256
+                            {
1257
+                                //$this->atleastoneratenotnull++;
1258
+
1259
+                                $index++;
1260
+                                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1261
+
1262
+                                $tvacompl='';
1263
+                                if (preg_match('/\*/',$tvakey))
1264
+                                {
1265
+                                    $tvakey=str_replace('*','',$tvakey);
1266
+                                    $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1267
+                                }
1268
+                                $totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1269
+
1270
+                                $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1271
+                                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1272
+
1273
+                                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1274
+                                $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1275
+                            }
1276
+                        }
1277
+                    }
1278
+                //}
1279
+
1280
+                // Total TTC
1281
+                $index++;
1282
+                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1283
+                $pdf->SetTextColor(0,0,60);
1284
+                $pdf->SetFillColor(224,224,224);
1285
+                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1286
+
1287
+                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1288
+                $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1289
+            }
1290
+        }
1291
+
1292
+        $pdf->SetTextColor(0,0,0);
1293
+
1294
+        /*
1295 1295
 		$resteapayer = $object->total_ttc - $deja_regle;
1296 1296
 		if (! empty($object->paye)) $resteapayer=0;
1297 1297
 		*/
1298 1298
 
1299
-		if ($deja_regle > 0)
1300
-		{
1301
-			$index++;
1299
+        if ($deja_regle > 0)
1300
+        {
1301
+            $index++;
1302 1302
 
1303
-			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1304
-			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
1303
+            $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1304
+            $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
1305 1305
 
1306
-			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1307
-			$pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
1306
+            $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1307
+            $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
1308 1308
 
1309
-			/*
1309
+            /*
1310 1310
 			if ($object->close_code == 'discount_vat')
1311 1311
 			{
1312 1312
 				$index++;
@@ -1322,398 +1322,398 @@  discard block
 block discarded – undo
1322 1322
 			}
1323 1323
 			*/
1324 1324
 
1325
-			$index++;
1326
-			$pdf->SetTextColor(0,0,60);
1327
-			$pdf->SetFillColor(224,224,224);
1328
-			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1329
-			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1330
-
1331
-			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1332
-			$pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1333
-
1334
-			$pdf->SetFont('','', $default_font_size - 1);
1335
-			$pdf->SetTextColor(0,0,0);
1336
-		}
1337
-
1338
-		$index++;
1339
-		return ($tab2_top + ($tab2_hl * $index));
1340
-	}
1341
-
1342
-	/**
1343
-	 *   Show table for lines
1344
-	 *
1345
-	 *   @param		PDF			$pdf     		Object PDF
1346
-	 *   @param		string		$tab_top		Top position of table
1347
-	 *   @param		string		$tab_height		Height of table (rectangle)
1348
-	 *   @param		int			$nexY			Y (not used)
1349
-	 *   @param		Translate	$outputlangs	Langs object
1350
-	 *   @param		int			$hidetop		1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
1351
-	 *   @param		int			$hidebottom		Hide bottom bar of array
1352
-	 *   @param		string		$currency		Currency code
1353
-	 *   @return	void
1354
-	 */
1355
-	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
1356
-	{
1357
-		global $conf;
1358
-
1359
-		// Force to disable hidetop and hidebottom
1360
-		$hidebottom=0;
1361
-		if ($hidetop) $hidetop=-1;
1362
-
1363
-		$currency = !empty($currency) ? $currency : $conf->currency;
1364
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
1365
-
1366
-		// Amount in (at tab_top - 1)
1367
-		$pdf->SetTextColor(0,0,0);
1368
-		$pdf->SetFont('','', $default_font_size - 2);
1369
-
1370
-		if (empty($hidetop))
1371
-		{
1372
-			$titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
1373
-			$pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
1374
-			$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1375
-
1376
-			//$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1377
-			if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1378
-		}
1379
-
1380
-		$pdf->SetDrawColor(128,128,128);
1381
-		$pdf->SetFont('','', $default_font_size - 1);
1382
-
1383
-		// Output Rect
1384
-		$this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom);	// Rect prend une longueur en 3eme param et 4eme param
1385
-
1386
-
1387
-		foreach ($this->cols as $colKey => $colDef)
1388
-		{
1389
-		    if(!$this->getColumnStatus($colKey)) continue;
1390
-
1391
-		    // get title label
1392
-		    $colDef['title']['label'] = !empty($colDef['title']['label'])?$colDef['title']['label']:$outputlangs->transnoentities($colDef['title']['textkey']);
1393
-
1394
-		    // Add column separator
1395
-		    if(!empty($colDef['border-left'])){
1396
-		        $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
1397
-		    }
1398
-
1399
-		    if (empty($hidetop))
1400
-		    {
1401
-		      $pdf->SetXY($colDef['xStartPos'] + $colDef['title']['padding'][3], $tab_top + $colDef['title']['padding'][0] );
1402
-
1403
-		      $textWidth = $colDef['width'] - $colDef['title']['padding'][3] -$colDef['title']['padding'][1];
1404
-		      $pdf->MultiCell($textWidth,2,$colDef['title']['label'],'',$colDef['title']['align']);
1405
-		    }
1406
-		}
1407
-
1408
-		if (empty($hidetop)){
1409
-			$pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);	// line prend une position y en 2eme param et 4eme param
1410
-		}
1411
-	}
1412
-
1413
-	/**
1414
-	 *  Show top header of page.
1415
-	 *
1416
-	 *  @param	PDF			$pdf     		Object PDF
1417
-	 *  @param  Object		$object     	Object to show
1418
-	 *  @param  int	    	$showaddress    0=no, 1=yes
1419
-	 *  @param  Translate	$outputlangs	Object lang for output
1420
-	 *  @return	void
1421
-	 */
1422
-	function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1423
-	{
1424
-		global $conf,$langs;
1425
-
1426
-		$outputlangs->load("main");
1427
-		$outputlangs->load("bills");
1428
-		$outputlangs->load("propal");
1429
-		$outputlangs->load("companies");
1430
-
1431
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
1432
-
1433
-		pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1434
-
1435
-		//  Show Draft Watermark
1436
-		if($object->statut==0 && (! empty($conf->global->PROPALE_DRAFT_WATERMARK)) )
1437
-		{
1438
-            pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->PROPALE_DRAFT_WATERMARK);
1439
-		}
1325
+            $index++;
1326
+            $pdf->SetTextColor(0,0,60);
1327
+            $pdf->SetFillColor(224,224,224);
1328
+            $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1329
+            $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1440 1330
 
1441
-		$pdf->SetTextColor(0,0,60);
1442
-		$pdf->SetFont('','B', $default_font_size + 3);
1331
+            $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1332
+            $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1443 1333
 
1444
-		$posy=$this->marge_haute;
1445
-		$posx=$this->page_largeur-$this->marge_droite-100;
1334
+            $pdf->SetFont('','', $default_font_size - 1);
1335
+            $pdf->SetTextColor(0,0,0);
1336
+        }
1446 1337
 
1447
-		$pdf->SetXY($this->marge_gauche,$posy);
1338
+        $index++;
1339
+        return ($tab2_top + ($tab2_hl * $index));
1340
+    }
1448 1341
 
1449
-		// Logo
1450
-		if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO))
1451
-		{
1452
-			$logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1453
-			if ($this->emetteur->logo)
1454
-			{
1455
-				if (is_readable($logo))
1456
-				{
1457
-				    $height=pdf_getHeightForLogo($logo);
1458
-				    $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
1459
-				}
1460
-				else
1461
-				{
1462
-					$pdf->SetTextColor(200,0,0);
1463
-					$pdf->SetFont('','B',$default_font_size - 2);
1464
-					$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1465
-					$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1466
-				}
1467
-			}
1468
-			else
1469
-			{
1470
-				$text=$this->emetteur->name;
1471
-				$pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1472
-			}
1473
-		}
1474
-
1475
-		$pdf->SetFont('','B',$default_font_size + 3);
1476
-		$pdf->SetXY($posx,$posy);
1477
-		$pdf->SetTextColor(0,0,60);
1478
-		$title=$outputlangs->transnoentities("PdfCommercialProposalTitle");
1479
-		$pdf->MultiCell(100, 4, $title, '', 'R');
1480
-
1481
-		$pdf->SetFont('','B',$default_font_size);
1482
-
1483
-		$posy+=5;
1484
-		$pdf->SetXY($posx,$posy);
1485
-		$pdf->SetTextColor(0,0,60);
1486
-		$pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
1487
-
1488
-		$posy+=1;
1489
-		$pdf->SetFont('','', $default_font_size - 2);
1490
-
1491
-		if ($object->ref_client)
1492
-		{
1493
-			$posy+=4;
1494
-			$pdf->SetXY($posx,$posy);
1495
-			$pdf->SetTextColor(0,0,60);
1496
-			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1497
-		}
1498
-
1499
-		$posy+=4;
1500
-		$pdf->SetXY($posx,$posy);
1501
-		$pdf->SetTextColor(0,0,60);
1502
-		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date,"day",false,$outputlangs,true), '', 'R');
1503
-
1504
-		$posy+=4;
1505
-		$pdf->SetXY($posx,$posy);
1506
-		$pdf->SetTextColor(0,0,60);
1507
-		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateEndPropal")." : " . dol_print_date($object->fin_validite,"day",false,$outputlangs,true), '', 'R');
1508
-
1509
-		if ($object->thirdparty->code_client)
1510
-		{
1511
-			$posy+=4;
1512
-			$pdf->SetXY($posx,$posy);
1513
-			$pdf->SetTextColor(0,0,60);
1514
-			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1515
-		}
1516
-
1517
-		// Get contact
1518
-		if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1519
-		{
1520
-		    $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1521
-		    if (count($arrayidcontact) > 0)
1522
-		    {
1523
-		        $usertmp=new User($this->db);
1524
-		        $usertmp->fetch($arrayidcontact[0]);
1525
-                $posy+=4;
1526
-                $pdf->SetXY($posx,$posy);
1527
-		        $pdf->SetTextColor(0,0,60);
1528
-		        $pdf->MultiCell(100, 3, $langs->trans("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1529
-		    }
1530
-		}
1531
-
1532
-		$posy+=2;
1533
-
1534
-		$top_shift = 0;
1535
-		// Show list of linked objects
1536
-		$current_y = $pdf->getY();
1537
-		$posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1538
-		if ($current_y < $pdf->getY())
1539
-		{
1540
-			$top_shift = $pdf->getY() - $current_y;
1541
-		}
1542
-
1543
-		if ($showaddress)
1544
-		{
1545
-			// Sender properties
1546
-			$carac_emetteur='';
1547
-		 	// Add internal contact of proposal if defined
1548
-			$arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1549
-		 	if (count($arrayidcontact) > 0)
1550
-		 	{
1551
-		 		$object->fetch_user($arrayidcontact[0]);
1552
-		 		$labelbeforecontactname=($outputlangs->transnoentities("FromContactName")!='FromContactName'?$outputlangs->transnoentities("FromContactName"):$outputlangs->transnoentities("Name"));
1553
-		 		$carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1554
-		 	}
1555
-
1556
-		 	$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1557
-
1558
-			// Show sender
1559
-			$posy=42+$top_shift;
1560
-		 	$posx=$this->marge_gauche;
1561
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1562
-			$hautcadre=40;
1563
-
1564
-			// Show sender frame
1565
-			$pdf->SetTextColor(0,0,0);
1566
-			$pdf->SetFont('','', $default_font_size - 2);
1567
-			$pdf->SetXY($posx,$posy-5);
1568
-			$pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1569
-			$pdf->SetXY($posx,$posy);
1570
-			$pdf->SetFillColor(230,230,230);
1571
-			$pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1572
-			$pdf->SetTextColor(0,0,60);
1573
-
1574
-			// Show sender name
1575
-			$pdf->SetXY($posx+2,$posy+3);
1576
-			$pdf->SetFont('','B', $default_font_size);
1577
-			$pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1578
-			$posy=$pdf->getY();
1579
-
1580
-			// Show sender information
1581
-			$pdf->SetXY($posx+2,$posy);
1582
-			$pdf->SetFont('','', $default_font_size - 1);
1583
-			$pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1584
-
1585
-
1586
-			// If CUSTOMER contact defined, we use it
1587
-			$usecontact=false;
1588
-			$arrayidcontact=$object->getIdContact('external','CUSTOMER');
1589
-			if (count($arrayidcontact) > 0)
1590
-			{
1591
-				$usecontact=true;
1592
-				$result=$object->fetch_contact($arrayidcontact[0]);
1593
-			}
1342
+    /**
1343
+     *   Show table for lines
1344
+     *
1345
+     *   @param		PDF			$pdf     		Object PDF
1346
+     *   @param		string		$tab_top		Top position of table
1347
+     *   @param		string		$tab_height		Height of table (rectangle)
1348
+     *   @param		int			$nexY			Y (not used)
1349
+     *   @param		Translate	$outputlangs	Langs object
1350
+     *   @param		int			$hidetop		1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
1351
+     *   @param		int			$hidebottom		Hide bottom bar of array
1352
+     *   @param		string		$currency		Currency code
1353
+     *   @return	void
1354
+     */
1355
+    function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
1356
+    {
1357
+        global $conf;
1594 1358
 
1595
-			//Recipient name
1596
-			// On peut utiliser le nom de la societe du contact
1597
-			if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
1598
-				$thirdparty = $object->contact;
1599
-			} else {
1600
-				$thirdparty = $object->thirdparty;
1601
-			}
1359
+        // Force to disable hidetop and hidebottom
1360
+        $hidebottom=0;
1361
+        if ($hidetop) $hidetop=-1;
1362
+
1363
+        $currency = !empty($currency) ? $currency : $conf->currency;
1364
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
1365
+
1366
+        // Amount in (at tab_top - 1)
1367
+        $pdf->SetTextColor(0,0,0);
1368
+        $pdf->SetFont('','', $default_font_size - 2);
1369
+
1370
+        if (empty($hidetop))
1371
+        {
1372
+            $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
1373
+            $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
1374
+            $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1602 1375
 
1603
-			$carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
1376
+            //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1377
+            if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1378
+        }
1604 1379
 
1605
-			$carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target',$object);
1380
+        $pdf->SetDrawColor(128,128,128);
1381
+        $pdf->SetFont('','', $default_font_size - 1);
1606 1382
 
1607
-			// Show recipient
1608
-			$widthrecbox=100;
1609
-			if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1610
-			$posy=42+$top_shift;
1611
-			$posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1612
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1383
+        // Output Rect
1384
+        $this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom);	// Rect prend une longueur en 3eme param et 4eme param
1613 1385
 
1614
-			// Show recipient frame
1615
-			$pdf->SetTextColor(0,0,0);
1616
-			$pdf->SetFont('','', $default_font_size - 2);
1617
-			$pdf->SetXY($posx+2,$posy-5);
1618
-			$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":", 0, 'L');
1619
-			$pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1620 1386
 
1621
-			// Show recipient name
1622
-			$pdf->SetXY($posx+2,$posy+3);
1623
-			$pdf->SetFont('','B', $default_font_size);
1624
-			$pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1387
+        foreach ($this->cols as $colKey => $colDef)
1388
+        {
1389
+            if(!$this->getColumnStatus($colKey)) continue;
1625 1390
 
1626
-			$posy = $pdf->getY();
1391
+            // get title label
1392
+            $colDef['title']['label'] = !empty($colDef['title']['label'])?$colDef['title']['label']:$outputlangs->transnoentities($colDef['title']['textkey']);
1627 1393
 
1628
-			// Show recipient information
1629
-			$pdf->SetFont('','', $default_font_size - 1);
1630
-			$pdf->SetXY($posx+2,$posy);
1631
-			$pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1632
-		}
1394
+            // Add column separator
1395
+            if(!empty($colDef['border-left'])){
1396
+                $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
1397
+            }
1633 1398
 
1634
-		$pdf->SetTextColor(0,0,0);
1635
-		return $top_shift;
1636
-	}
1399
+            if (empty($hidetop))
1400
+            {
1401
+                $pdf->SetXY($colDef['xStartPos'] + $colDef['title']['padding'][3], $tab_top + $colDef['title']['padding'][0] );
1402
+
1403
+                $textWidth = $colDef['width'] - $colDef['title']['padding'][3] -$colDef['title']['padding'][1];
1404
+                $pdf->MultiCell($textWidth,2,$colDef['title']['label'],'',$colDef['title']['align']);
1405
+            }
1406
+        }
1407
+
1408
+        if (empty($hidetop)){
1409
+            $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);	// line prend une position y en 2eme param et 4eme param
1410
+        }
1411
+    }
1412
+
1413
+    /**
1414
+     *  Show top header of page.
1415
+     *
1416
+     *  @param	PDF			$pdf     		Object PDF
1417
+     *  @param  Object		$object     	Object to show
1418
+     *  @param  int	    	$showaddress    0=no, 1=yes
1419
+     *  @param  Translate	$outputlangs	Object lang for output
1420
+     *  @return	void
1421
+     */
1422
+    function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1423
+    {
1424
+        global $conf,$langs;
1637 1425
 
1638
-	/**
1639
-	 *   	Show footer of page. Need this->emetteur object
1426
+        $outputlangs->load("main");
1427
+        $outputlangs->load("bills");
1428
+        $outputlangs->load("propal");
1429
+        $outputlangs->load("companies");
1430
+
1431
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
1432
+
1433
+        pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1434
+
1435
+        //  Show Draft Watermark
1436
+        if($object->statut==0 && (! empty($conf->global->PROPALE_DRAFT_WATERMARK)) )
1437
+        {
1438
+            pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->PROPALE_DRAFT_WATERMARK);
1439
+        }
1440
+
1441
+        $pdf->SetTextColor(0,0,60);
1442
+        $pdf->SetFont('','B', $default_font_size + 3);
1443
+
1444
+        $posy=$this->marge_haute;
1445
+        $posx=$this->page_largeur-$this->marge_droite-100;
1446
+
1447
+        $pdf->SetXY($this->marge_gauche,$posy);
1448
+
1449
+        // Logo
1450
+        if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO))
1451
+        {
1452
+            $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1453
+            if ($this->emetteur->logo)
1454
+            {
1455
+                if (is_readable($logo))
1456
+                {
1457
+                    $height=pdf_getHeightForLogo($logo);
1458
+                    $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
1459
+                }
1460
+                else
1461
+                {
1462
+                    $pdf->SetTextColor(200,0,0);
1463
+                    $pdf->SetFont('','B',$default_font_size - 2);
1464
+                    $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1465
+                    $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1466
+                }
1467
+            }
1468
+            else
1469
+            {
1470
+                $text=$this->emetteur->name;
1471
+                $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1472
+            }
1473
+        }
1474
+
1475
+        $pdf->SetFont('','B',$default_font_size + 3);
1476
+        $pdf->SetXY($posx,$posy);
1477
+        $pdf->SetTextColor(0,0,60);
1478
+        $title=$outputlangs->transnoentities("PdfCommercialProposalTitle");
1479
+        $pdf->MultiCell(100, 4, $title, '', 'R');
1480
+
1481
+        $pdf->SetFont('','B',$default_font_size);
1482
+
1483
+        $posy+=5;
1484
+        $pdf->SetXY($posx,$posy);
1485
+        $pdf->SetTextColor(0,0,60);
1486
+        $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
1487
+
1488
+        $posy+=1;
1489
+        $pdf->SetFont('','', $default_font_size - 2);
1490
+
1491
+        if ($object->ref_client)
1492
+        {
1493
+            $posy+=4;
1494
+            $pdf->SetXY($posx,$posy);
1495
+            $pdf->SetTextColor(0,0,60);
1496
+            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1497
+        }
1498
+
1499
+        $posy+=4;
1500
+        $pdf->SetXY($posx,$posy);
1501
+        $pdf->SetTextColor(0,0,60);
1502
+        $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date,"day",false,$outputlangs,true), '', 'R');
1503
+
1504
+        $posy+=4;
1505
+        $pdf->SetXY($posx,$posy);
1506
+        $pdf->SetTextColor(0,0,60);
1507
+        $pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateEndPropal")." : " . dol_print_date($object->fin_validite,"day",false,$outputlangs,true), '', 'R');
1508
+
1509
+        if ($object->thirdparty->code_client)
1510
+        {
1511
+            $posy+=4;
1512
+            $pdf->SetXY($posx,$posy);
1513
+            $pdf->SetTextColor(0,0,60);
1514
+            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1515
+        }
1516
+
1517
+        // Get contact
1518
+        if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1519
+        {
1520
+            $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1521
+            if (count($arrayidcontact) > 0)
1522
+            {
1523
+                $usertmp=new User($this->db);
1524
+                $usertmp->fetch($arrayidcontact[0]);
1525
+                $posy+=4;
1526
+                $pdf->SetXY($posx,$posy);
1527
+                $pdf->SetTextColor(0,0,60);
1528
+                $pdf->MultiCell(100, 3, $langs->trans("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1529
+            }
1530
+        }
1531
+
1532
+        $posy+=2;
1533
+
1534
+        $top_shift = 0;
1535
+        // Show list of linked objects
1536
+        $current_y = $pdf->getY();
1537
+        $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1538
+        if ($current_y < $pdf->getY())
1539
+        {
1540
+            $top_shift = $pdf->getY() - $current_y;
1541
+        }
1542
+
1543
+        if ($showaddress)
1544
+        {
1545
+            // Sender properties
1546
+            $carac_emetteur='';
1547
+                // Add internal contact of proposal if defined
1548
+            $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1549
+                if (count($arrayidcontact) > 0)
1550
+                {
1551
+                    $object->fetch_user($arrayidcontact[0]);
1552
+                    $labelbeforecontactname=($outputlangs->transnoentities("FromContactName")!='FromContactName'?$outputlangs->transnoentities("FromContactName"):$outputlangs->transnoentities("Name"));
1553
+                    $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1554
+                }
1555
+
1556
+                $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1557
+
1558
+            // Show sender
1559
+            $posy=42+$top_shift;
1560
+                $posx=$this->marge_gauche;
1561
+            if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1562
+            $hautcadre=40;
1563
+
1564
+            // Show sender frame
1565
+            $pdf->SetTextColor(0,0,0);
1566
+            $pdf->SetFont('','', $default_font_size - 2);
1567
+            $pdf->SetXY($posx,$posy-5);
1568
+            $pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1569
+            $pdf->SetXY($posx,$posy);
1570
+            $pdf->SetFillColor(230,230,230);
1571
+            $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1572
+            $pdf->SetTextColor(0,0,60);
1573
+
1574
+            // Show sender name
1575
+            $pdf->SetXY($posx+2,$posy+3);
1576
+            $pdf->SetFont('','B', $default_font_size);
1577
+            $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1578
+            $posy=$pdf->getY();
1579
+
1580
+            // Show sender information
1581
+            $pdf->SetXY($posx+2,$posy);
1582
+            $pdf->SetFont('','', $default_font_size - 1);
1583
+            $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1584
+
1585
+
1586
+            // If CUSTOMER contact defined, we use it
1587
+            $usecontact=false;
1588
+            $arrayidcontact=$object->getIdContact('external','CUSTOMER');
1589
+            if (count($arrayidcontact) > 0)
1590
+            {
1591
+                $usecontact=true;
1592
+                $result=$object->fetch_contact($arrayidcontact[0]);
1593
+            }
1594
+
1595
+            //Recipient name
1596
+            // On peut utiliser le nom de la societe du contact
1597
+            if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
1598
+                $thirdparty = $object->contact;
1599
+            } else {
1600
+                $thirdparty = $object->thirdparty;
1601
+            }
1602
+
1603
+            $carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
1604
+
1605
+            $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target',$object);
1606
+
1607
+            // Show recipient
1608
+            $widthrecbox=100;
1609
+            if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1610
+            $posy=42+$top_shift;
1611
+            $posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1612
+            if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1613
+
1614
+            // Show recipient frame
1615
+            $pdf->SetTextColor(0,0,0);
1616
+            $pdf->SetFont('','', $default_font_size - 2);
1617
+            $pdf->SetXY($posx+2,$posy-5);
1618
+            $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":", 0, 'L');
1619
+            $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1620
+
1621
+            // Show recipient name
1622
+            $pdf->SetXY($posx+2,$posy+3);
1623
+            $pdf->SetFont('','B', $default_font_size);
1624
+            $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1625
+
1626
+            $posy = $pdf->getY();
1627
+
1628
+            // Show recipient information
1629
+            $pdf->SetFont('','', $default_font_size - 1);
1630
+            $pdf->SetXY($posx+2,$posy);
1631
+            $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1632
+        }
1633
+
1634
+        $pdf->SetTextColor(0,0,0);
1635
+        return $top_shift;
1636
+    }
1637
+
1638
+    /**
1639
+     *   	Show footer of page. Need this->emetteur object
1640
+     *
1641
+     *   	@param	PDF			$pdf     			PDF
1642
+     * 		@param	Object		$object				Object to show
1643
+     *      @param	Translate	$outputlangs		Object lang for output
1644
+     *      @param	int			$hidefreetext		1=Hide free text
1645
+     *      @return	int								Return height of bottom margin including footer text
1646
+     */
1647
+    function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1648
+    {
1649
+        global $conf;
1650
+        $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1651
+        return pdf_pagefoot($pdf,$outputlangs,'PROPOSAL_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1652
+    }
1653
+
1654
+    /**
1655
+     *	Show area for the customer to sign
1656
+     *
1657
+     *	@param	PDF			$pdf            Object PDF
1658
+     *	@param  Facture		$object         Object invoice
1659
+     *	@param	int			$posy			Position depart
1660
+     *	@param	Translate	$outputlangs	Objet langs
1661
+     *	@return int							Position pour suite
1662
+     */
1663
+    private function drawSignatureArea(&$pdf, $object, $posy, $outputlangs)
1664
+    {
1665
+        global $conf;
1666
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
1667
+        $tab_top = $posy + 4;
1668
+        $tab_hl = 4;
1669
+
1670
+        $posx = 120;
1671
+        $largcol = ($this->page_largeur - $this->marge_droite - $posx);
1672
+        $useborder=0;
1673
+        $index = 0;
1674
+        // Total HT
1675
+        $pdf->SetFillColor(255,255,255);
1676
+        $pdf->SetXY($posx, $tab_top + 0);
1677
+        $pdf->SetFont('','', $default_font_size - 2);
1678
+        $pdf->MultiCell($largcol, $tab_hl, $outputlangs->transnoentities("ProposalCustomerSignature"), 0, 'L', 1);
1679
+
1680
+        $pdf->SetXY($posx, $tab_top + $tab_hl);
1681
+        $pdf->MultiCell($largcol, $tab_hl*3, '', 1, 'R');
1682
+        if (! empty($conf->global->MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING)) {
1683
+            $pdf->addEmptySignatureAppearance($posx, $tab_top + $tab_hl, $largcol, $tab_hl*3);
1684
+        }
1685
+
1686
+        return ($tab_hl*7);
1687
+    }
1688
+
1689
+
1690
+    /**
1691
+     *   	Define Array Column Field
1640 1692
      *
1641
-	 *   	@param	PDF			$pdf     			PDF
1642
-	 * 		@param	Object		$object				Object to show
1643
-	 *      @param	Translate	$outputlangs		Object lang for output
1644
-	 *      @param	int			$hidefreetext		1=Hide free text
1645
-	 *      @return	int								Return height of bottom margin including footer text
1646
-	 */
1647
-	function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1648
-	{
1649
-		global $conf;
1650
-		$showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1651
-		return pdf_pagefoot($pdf,$outputlangs,'PROPOSAL_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1652
-	}
1653
-
1654
-	/**
1655
-	 *	Show area for the customer to sign
1656
-	 *
1657
-	 *	@param	PDF			$pdf            Object PDF
1658
-	 *	@param  Facture		$object         Object invoice
1659
-	 *	@param	int			$posy			Position depart
1660
-	 *	@param	Translate	$outputlangs	Objet langs
1661
-	 *	@return int							Position pour suite
1662
-	 */
1663
-	private function drawSignatureArea(&$pdf, $object, $posy, $outputlangs)
1664
-	{
1665
-		global $conf;
1666
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
1667
-		$tab_top = $posy + 4;
1668
-		$tab_hl = 4;
1669
-
1670
-		$posx = 120;
1671
-		$largcol = ($this->page_largeur - $this->marge_droite - $posx);
1672
-		$useborder=0;
1673
-		$index = 0;
1674
-		// Total HT
1675
-		$pdf->SetFillColor(255,255,255);
1676
-		$pdf->SetXY($posx, $tab_top + 0);
1677
-		$pdf->SetFont('','', $default_font_size - 2);
1678
-		$pdf->MultiCell($largcol, $tab_hl, $outputlangs->transnoentities("ProposalCustomerSignature"), 0, 'L', 1);
1679
-
1680
-		$pdf->SetXY($posx, $tab_top + $tab_hl);
1681
-		$pdf->MultiCell($largcol, $tab_hl*3, '', 1, 'R');
1682
-		if (! empty($conf->global->MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING)) {
1683
-			$pdf->addEmptySignatureAppearance($posx, $tab_top + $tab_hl, $largcol, $tab_hl*3);
1684
-		}
1685
-
1686
-		return ($tab_hl*7);
1687
-	}
1688
-
1689
-
1690
-	/**
1691
-	 *   	Define Array Column Field
1692
-	 *
1693
-	 *   	@param	object			$object			common object
1694
-	 *   	@param	Translate		$outputlangs	langs
1695
-	 *      @param	int				$hidedetails	Do not show line details
1696
-	 *      @param	int				$hidedesc		Do not show desc
1697
-	 *      @param	int				$hideref		Do not show ref
1698
-	 *      @return	null
1699
-	 */
1693
+     *   	@param	object			$object			common object
1694
+     *   	@param	Translate		$outputlangs	langs
1695
+     *      @param	int				$hidedetails	Do not show line details
1696
+     *      @param	int				$hidedesc		Do not show desc
1697
+     *      @param	int				$hideref		Do not show ref
1698
+     *      @return	null
1699
+     */
1700 1700
     function defineColumnField($object,$outputlangs,$hidedetails=0,$hidedesc=0,$hideref=0)
1701 1701
     {
1702
-	    global $conf, $hookmanager;
1702
+        global $conf, $hookmanager;
1703 1703
 
1704
-	    // Default field style for content
1705
-	    $this->defaultContentsFieldsStyle = array(
1706
-	        'align' => 'R', // R,C,L
1707
-	        'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1708
-	    );
1704
+        // Default field style for content
1705
+        $this->defaultContentsFieldsStyle = array(
1706
+            'align' => 'R', // R,C,L
1707
+            'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1708
+        );
1709 1709
 
1710
-	    // Default field style for content
1711
-	    $this->defaultTitlesFieldsStyle = array(
1712
-	        'align' => 'C', // R,C,L
1713
-	        'padding' => array(0.5,0,0.5,0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1714
-	    );
1710
+        // Default field style for content
1711
+        $this->defaultTitlesFieldsStyle = array(
1712
+            'align' => 'C', // R,C,L
1713
+            'padding' => array(0.5,0,0.5,0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1714
+        );
1715 1715
 
1716
-	    /*
1716
+        /*
1717 1717
 	     * For exemple
1718 1718
 	     $this->cols['theColKey'] = array(
1719 1719
 	     'rank' => $rank, // int : use for ordering columns
@@ -1731,158 +1731,158 @@  discard block
 block discarded – undo
1731 1731
 	     );
1732 1732
 	     */
1733 1733
 
1734
-	    $rank=0; // do not use negative rank
1735
-	    $this->cols['desc'] = array(
1736
-	        'rank' => $rank,
1737
-	        'width' => false, // only for desc
1738
-	        'status' => true,
1739
-	        'title' => array(
1740
-	            'textkey' => 'Designation', // use lang key is usefull in somme case with module
1741
-	            'align' => 'L',
1742
-	            // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1743
-	            // 'label' => ' ', // the final label
1744
-	            'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1745
-	        ),
1746
-	        'content' => array(
1747
-	            'align' => 'L',
1748
-	        ),
1749
-	    );
1750
-
1751
-	    $rank = $rank + 10;
1752
-	    $this->cols['photo'] = array(
1753
-	        'rank' => $rank,
1754
-	        'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
1755
-	        'status' => false,
1756
-	        'title' => array(
1757
-	            'textkey' => 'Photo',
1758
-	            'label' => ' '
1759
-	        ),
1760
-	        'content' => array(
1761
-	            'padding' => array(0,0,0,0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1762
-	        ),
1763
-	        'border-left' => false, // remove left line separator
1764
-	    );
1765
-
1766
-	    if (! empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE) && !empty($this->atleastonephoto))
1767
-	    {
1768
-	        $this->cols['photo']['status'] = true;
1769
-	    }
1770
-
1771
-
1772
-	    $rank = $rank + 10;
1773
-	    $this->cols['vat'] = array(
1774
-	        'rank' => $rank,
1775
-	        'status' => false,
1776
-	        'width' => 16, // in mm
1777
-	        'title' => array(
1778
-	            'textkey' => 'VAT'
1779
-	        ),
1780
-	        'border-left' => true, // add left line separator
1781
-	    );
1782
-
1783
-	    if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
1784
-	    {
1785
-	        $this->cols['vat']['status'] = true;
1786
-	    }
1787
-
1788
-	    $rank = $rank + 10;
1789
-	    $this->cols['subprice'] = array(
1790
-	        'rank' => $rank,
1791
-	        'width' => 19, // in mm
1792
-	        'status' => true,
1793
-	        'title' => array(
1794
-	            'textkey' => 'PriceUHT'
1795
-	        ),
1796
-	        'border-left' => true, // add left line separator
1797
-	    );
1798
-
1799
-	    $rank = $rank + 10;
1800
-	    $this->cols['qty'] = array(
1801
-	        'rank' => $rank,
1802
-	        'width' => 16, // in mm
1803
-	        'status' => true,
1804
-	        'title' => array(
1805
-	            'textkey' => 'Qty'
1806
-	        ),
1807
-	        'border-left' => true, // add left line separator
1808
-	    );
1809
-
1810
-	    $rank = $rank + 10;
1811
-	    $this->cols['progress'] = array(
1812
-	        'rank' => $rank,
1813
-	        'width' => 19, // in mm
1814
-	        'status' => false,
1815
-	        'title' => array(
1816
-	            'textkey' => 'Progress'
1817
-	        ),
1818
-	        'border-left' => false, // add left line separator
1819
-	    );
1820
-
1821
-	    if($this->situationinvoice)
1822
-	    {
1823
-	        $this->cols['progress']['status'] = true;
1824
-	    }
1825
-
1826
-	    $rank = $rank + 10;
1827
-	    $this->cols['unit'] = array(
1828
-	        'rank' => $rank,
1829
-	        'width' => 11, // in mm
1830
-	        'status' => false,
1831
-	        'title' => array(
1832
-	            'textkey' => 'Unit'
1833
-	        ),
1834
-	        'border-left' => true, // add left line separator
1835
-	    );
1836
-	    if($conf->global->PRODUCT_USE_UNITS){
1837
-	        $this->cols['unit']['status'] = true;
1838
-	    }
1839
-
1840
-	    $rank = $rank + 10;
1841
-	    $this->cols['discount'] = array(
1842
-	        'rank' => $rank,
1843
-	        'width' => 13, // in mm
1844
-	        'status' => false,
1845
-	        'title' => array(
1846
-	            'textkey' => 'ReductionShort'
1847
-	        ),
1848
-	        'border-left' => true, // add left line separator
1849
-	    );
1850
-	    if ($this->atleastonediscount){
1851
-	        $this->cols['discount']['status'] = true;
1852
-	    }
1853
-
1854
-	    $rank = $rank + 10;
1855
-	    $this->cols['totalexcltax'] = array(
1856
-	        'rank' => $rank,
1857
-	        'width' => 26, // in mm
1858
-	        'status' => true,
1859
-	        'title' => array(
1860
-	            'textkey' => 'TotalHT'
1861
-	        ),
1862
-	        'border-left' => true, // add left line separator
1863
-	    );
1864
-
1865
-
1866
-	    $parameters=array(
1867
-	        'object' => $object,
1868
-	        'outputlangs' => $outputlangs,
1869
-	        'hidedetails' => $hidedetails,
1870
-	        'hidedesc' => $hidedesc,
1871
-	        'hideref' => $hideref
1872
-	    );
1873
-
1874
-	    $reshook=$hookmanager->executeHooks('defineColumnField',$parameters,$this);    // Note that $object may have been modified by hook
1875
-	    if ($reshook < 0)
1876
-	    {
1877
-	        setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1878
-	    }
1879
-	    elseif (empty($reshook))
1880
-	    {
1881
-	        $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
1882
-	    }
1883
-	    else
1884
-	    {
1885
-	        $this->cols = $hookmanager->resArray;
1886
-	    }
1887
-	}
1734
+        $rank=0; // do not use negative rank
1735
+        $this->cols['desc'] = array(
1736
+            'rank' => $rank,
1737
+            'width' => false, // only for desc
1738
+            'status' => true,
1739
+            'title' => array(
1740
+                'textkey' => 'Designation', // use lang key is usefull in somme case with module
1741
+                'align' => 'L',
1742
+                // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1743
+                // 'label' => ' ', // the final label
1744
+                'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1745
+            ),
1746
+            'content' => array(
1747
+                'align' => 'L',
1748
+            ),
1749
+        );
1750
+
1751
+        $rank = $rank + 10;
1752
+        $this->cols['photo'] = array(
1753
+            'rank' => $rank,
1754
+            'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
1755
+            'status' => false,
1756
+            'title' => array(
1757
+                'textkey' => 'Photo',
1758
+                'label' => ' '
1759
+            ),
1760
+            'content' => array(
1761
+                'padding' => array(0,0,0,0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1762
+            ),
1763
+            'border-left' => false, // remove left line separator
1764
+        );
1765
+
1766
+        if (! empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE) && !empty($this->atleastonephoto))
1767
+        {
1768
+            $this->cols['photo']['status'] = true;
1769
+        }
1770
+
1771
+
1772
+        $rank = $rank + 10;
1773
+        $this->cols['vat'] = array(
1774
+            'rank' => $rank,
1775
+            'status' => false,
1776
+            'width' => 16, // in mm
1777
+            'title' => array(
1778
+                'textkey' => 'VAT'
1779
+            ),
1780
+            'border-left' => true, // add left line separator
1781
+        );
1782
+
1783
+        if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
1784
+        {
1785
+            $this->cols['vat']['status'] = true;
1786
+        }
1787
+
1788
+        $rank = $rank + 10;
1789
+        $this->cols['subprice'] = array(
1790
+            'rank' => $rank,
1791
+            'width' => 19, // in mm
1792
+            'status' => true,
1793
+            'title' => array(
1794
+                'textkey' => 'PriceUHT'
1795
+            ),
1796
+            'border-left' => true, // add left line separator
1797
+        );
1798
+
1799
+        $rank = $rank + 10;
1800
+        $this->cols['qty'] = array(
1801
+            'rank' => $rank,
1802
+            'width' => 16, // in mm
1803
+            'status' => true,
1804
+            'title' => array(
1805
+                'textkey' => 'Qty'
1806
+            ),
1807
+            'border-left' => true, // add left line separator
1808
+        );
1809
+
1810
+        $rank = $rank + 10;
1811
+        $this->cols['progress'] = array(
1812
+            'rank' => $rank,
1813
+            'width' => 19, // in mm
1814
+            'status' => false,
1815
+            'title' => array(
1816
+                'textkey' => 'Progress'
1817
+            ),
1818
+            'border-left' => false, // add left line separator
1819
+        );
1820
+
1821
+        if($this->situationinvoice)
1822
+        {
1823
+            $this->cols['progress']['status'] = true;
1824
+        }
1825
+
1826
+        $rank = $rank + 10;
1827
+        $this->cols['unit'] = array(
1828
+            'rank' => $rank,
1829
+            'width' => 11, // in mm
1830
+            'status' => false,
1831
+            'title' => array(
1832
+                'textkey' => 'Unit'
1833
+            ),
1834
+            'border-left' => true, // add left line separator
1835
+        );
1836
+        if($conf->global->PRODUCT_USE_UNITS){
1837
+            $this->cols['unit']['status'] = true;
1838
+        }
1839
+
1840
+        $rank = $rank + 10;
1841
+        $this->cols['discount'] = array(
1842
+            'rank' => $rank,
1843
+            'width' => 13, // in mm
1844
+            'status' => false,
1845
+            'title' => array(
1846
+                'textkey' => 'ReductionShort'
1847
+            ),
1848
+            'border-left' => true, // add left line separator
1849
+        );
1850
+        if ($this->atleastonediscount){
1851
+            $this->cols['discount']['status'] = true;
1852
+        }
1853
+
1854
+        $rank = $rank + 10;
1855
+        $this->cols['totalexcltax'] = array(
1856
+            'rank' => $rank,
1857
+            'width' => 26, // in mm
1858
+            'status' => true,
1859
+            'title' => array(
1860
+                'textkey' => 'TotalHT'
1861
+            ),
1862
+            'border-left' => true, // add left line separator
1863
+        );
1864
+
1865
+
1866
+        $parameters=array(
1867
+            'object' => $object,
1868
+            'outputlangs' => $outputlangs,
1869
+            'hidedetails' => $hidedetails,
1870
+            'hidedesc' => $hidedesc,
1871
+            'hideref' => $hideref
1872
+        );
1873
+
1874
+        $reshook=$hookmanager->executeHooks('defineColumnField',$parameters,$this);    // Note that $object may have been modified by hook
1875
+        if ($reshook < 0)
1876
+        {
1877
+            setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1878
+        }
1879
+        elseif (empty($reshook))
1880
+        {
1881
+            $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
1882
+        }
1883
+        else
1884
+        {
1885
+            $this->cols = $hookmanager->resArray;
1886
+        }
1887
+    }
1888 1888
 }
Please login to merge, or discard this patch.
Spacing   +474 added lines, -474 removed lines patch added patch discarded remove patch
@@ -44,10 +44,10 @@  discard block
 block discarded – undo
44 44
 	public $db;
45 45
 	public $name;
46 46
 	public $description;
47
-	public $update_main_doc_field;	// Save the name of generated file as the main doc when generating a doc with this template
47
+	public $update_main_doc_field; // Save the name of generated file as the main doc when generating a doc with this template
48 48
 	public $type;
49 49
 
50
-	public $phpmin = array(4,3,0); // Minimum version of PHP required by module
50
+	public $phpmin = array(4, 3, 0); // Minimum version of PHP required by module
51 51
 	public $version = 'development';
52 52
 
53 53
 	public $page_largeur;
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	public	$marge_haute;
59 59
 	public	$marge_basse;
60 60
 
61
-	public $emetteur;	// Objet societe qui emet
61
+	public $emetteur; // Objet societe qui emet
62 62
 
63 63
 
64 64
 	/**
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	 */
69 69
 	public function __construct($db)
70 70
 	{
71
-		global $conf,$langs,$mysoc;
71
+		global $conf, $langs, $mysoc;
72 72
 
73 73
 		// Translations
74 74
 		$langs->loadLangs(array("main", "bills"));
@@ -76,46 +76,46 @@  discard block
 block discarded – undo
76 76
 		$this->db = $db;
77 77
 		$this->name = "cyan";
78 78
 		$this->description = $langs->trans('DocModelCyanDescription');
79
-		$this->update_main_doc_field = 1;		// Save the name of generated file as the main doc when generating a doc with this template
79
+		$this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
80 80
 
81 81
 		// Dimension page
82 82
 		$this->type = 'pdf';
83
-		$formatarray=pdf_getFormat();
83
+		$formatarray = pdf_getFormat();
84 84
 		$this->page_largeur = $formatarray['width'];
85 85
 		$this->page_hauteur = $formatarray['height'];
86
-		$this->format = array($this->page_largeur,$this->page_hauteur);
87
-		$this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
88
-		$this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
89
-		$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
90
-		$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
91
-
92
-		$this->option_logo = 1;                    // Affiche logo
93
-		$this->option_tva = 1;                     // Gere option tva FACTURE_TVAOPTION
94
-		$this->option_modereg = 1;                 // Affiche mode reglement
95
-		$this->option_condreg = 1;                 // Affiche conditions reglement
96
-		$this->option_codeproduitservice = 1;      // Affiche code produit-service
97
-		$this->option_multilang = 1;               // Dispo en plusieurs langues
98
-		$this->option_escompte = 0;                // Affiche si il y a eu escompte
99
-		$this->option_credit_note = 0;             // Support credit notes
100
-		$this->option_freetext = 1;				   // Support add of a personalised text
101
-		$this->option_draft_watermark = 1;		   //Support add of a watermark on drafts
102
-
103
-		$this->franchise=!$mysoc->tva_assuj;
86
+		$this->format = array($this->page_largeur, $this->page_hauteur);
87
+		$this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
88
+		$this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
89
+		$this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
90
+		$this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
91
+
92
+		$this->option_logo = 1; // Affiche logo
93
+		$this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
94
+		$this->option_modereg = 1; // Affiche mode reglement
95
+		$this->option_condreg = 1; // Affiche conditions reglement
96
+		$this->option_codeproduitservice = 1; // Affiche code produit-service
97
+		$this->option_multilang = 1; // Dispo en plusieurs langues
98
+		$this->option_escompte = 0; // Affiche si il y a eu escompte
99
+		$this->option_credit_note = 0; // Support credit notes
100
+		$this->option_freetext = 1; // Support add of a personalised text
101
+		$this->option_draft_watermark = 1; //Support add of a watermark on drafts
102
+
103
+		$this->franchise = !$mysoc->tva_assuj;
104 104
 
105 105
 		// Get source company
106
-		$this->emetteur=$mysoc;
107
-		if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
106
+		$this->emetteur = $mysoc;
107
+		if (empty($this->emetteur->country_code)) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
108 108
 
109 109
 		// Define position of columns
110
-		$this->posxdesc=$this->marge_gauche+1;
110
+		$this->posxdesc = $this->marge_gauche + 1;
111 111
 
112 112
 
113 113
 
114
-		$this->tva=array();
115
-		$this->localtax1=array();
116
-		$this->localtax2=array();
117
-		$this->atleastoneratenotnull=0;
118
-		$this->atleastonediscount=0;
114
+		$this->tva = array();
115
+		$this->localtax1 = array();
116
+		$this->localtax2 = array();
117
+		$this->atleastoneratenotnull = 0;
118
+		$this->atleastonediscount = 0;
119 119
 	}
120 120
 
121 121
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
@@ -130,14 +130,14 @@  discard block
 block discarded – undo
130 130
      *  @param		int			$hideref			Do not show ref
131 131
      *  @return     int             				1=OK, 0=KO
132 132
 	 */
133
-	public function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
133
+	public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
134 134
 	{
135 135
 	  // phpcs:enable
136
-		global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
136
+		global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblignes;
137 137
 
138
-		if (! is_object($outputlangs)) $outputlangs=$langs;
138
+		if (!is_object($outputlangs)) $outputlangs = $langs;
139 139
 		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
140
-		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
140
+		if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1';
141 141
 
142 142
 		$outputlangs->load("main");
143 143
 		$outputlangs->load("dict");
@@ -149,52 +149,52 @@  discard block
 block discarded – undo
149 149
 		$nblignes = count($object->lines);
150 150
 
151 151
 		// Loop on each lines to detect if there is at least one image to show
152
-		$realpatharray=array();
152
+		$realpatharray = array();
153 153
 		$this->atleastonephoto = false;
154
-		if (! empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE))
154
+		if (!empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE))
155 155
 		{
156 156
 			$objphoto = new Product($this->db);
157 157
 
158
-			for ($i = 0 ; $i < $nblignes ; $i++)
158
+			for ($i = 0; $i < $nblignes; $i++)
159 159
 			{
160 160
 				if (empty($object->lines[$i]->fk_product)) continue;
161 161
 
162 162
 				$objphoto->fetch($object->lines[$i]->fk_product);
163 163
                 //var_dump($objphoto->ref);exit;
164
-				if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
164
+				if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
165 165
 				{
166
-					$pdir[0] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";
167
-					$pdir[1] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';
166
+					$pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
167
+					$pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
168 168
 				}
169 169
 				else
170 170
 				{
171
-					$pdir[0] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';				// default
172
-					$pdir[1] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";	// alternative
171
+					$pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/'; // default
172
+					$pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
173 173
 				}
174 174
 
175 175
 				$arephoto = false;
176 176
 				foreach ($pdir as $midir)
177 177
 				{
178
-					if (! $arephoto)
178
+					if (!$arephoto)
179 179
 					{
180 180
 						$dir = $conf->product->dir_output.'/'.$midir;
181 181
 
182
-						foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
182
+						foreach ($objphoto->liste_photos($dir, 1) as $key => $obj)
183 183
 						{
184 184
 							if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES))		// If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
185 185
 							{
186 186
 								if ($obj['photo_vignette'])
187 187
 								{
188
-									$filename= $obj['photo_vignette'];
188
+									$filename = $obj['photo_vignette'];
189 189
 								}
190 190
 								else
191 191
 								{
192
-									$filename=$obj['photo'];
192
+									$filename = $obj['photo'];
193 193
 								}
194 194
 							}
195 195
 							else
196 196
 							{
197
-								$filename=$obj['photo'];
197
+								$filename = $obj['photo'];
198 198
 							}
199 199
 
200 200
 							$realpath = $dir.$filename;
@@ -204,11 +204,11 @@  discard block
 block discarded – undo
204 204
 					}
205 205
 				}
206 206
 
207
-				if ($realpath && $arephoto) $realpatharray[$i]=$realpath;
207
+				if ($realpath && $arephoto) $realpatharray[$i] = $realpath;
208 208
 			}
209 209
 		}
210 210
 
211
-		if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
211
+		if (count($realpatharray) == 0) $this->posxpicture = $this->posxtva;
212 212
 
213 213
 		if ($conf->propal->multidir_output[$conf->entity])
214 214
 		{
@@ -220,20 +220,20 @@  discard block
 block discarded – undo
220 220
 			if ($object->specimen)
221 221
 			{
222 222
 				$dir = $conf->propal->multidir_output[$conf->entity];
223
-				$file = $dir . "/SPECIMEN.pdf";
223
+				$file = $dir."/SPECIMEN.pdf";
224 224
 			}
225 225
 			else
226 226
 			{
227 227
 				$objectref = dol_sanitizeFileName($object->ref);
228
-				$dir = $conf->propal->multidir_output[$object->entity] . "/" . $objectref;
229
-				$file = $dir . "/" . $objectref . ".pdf";
228
+				$dir = $conf->propal->multidir_output[$object->entity]."/".$objectref;
229
+				$file = $dir."/".$objectref.".pdf";
230 230
 			}
231 231
 
232
-			if (! file_exists($dir))
232
+			if (!file_exists($dir))
233 233
 			{
234 234
 				if (dol_mkdir($dir) < 0)
235 235
 				{
236
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
236
+					$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
237 237
 					return 0;
238 238
 				}
239 239
 			}
@@ -241,20 +241,20 @@  discard block
 block discarded – undo
241 241
 			if (file_exists($dir))
242 242
 			{
243 243
 				// Add pdfgeneration hook
244
-				if (! is_object($hookmanager))
244
+				if (!is_object($hookmanager))
245 245
 				{
246 246
 					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
247
-					$hookmanager=new HookManager($this->db);
247
+					$hookmanager = new HookManager($this->db);
248 248
 				}
249 249
 				$hookmanager->initHooks(array('pdfgeneration'));
250
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
250
+				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
251 251
 				global $action;
252
-				$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
252
+				$reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
253 253
 
254 254
 				// Create pdf instance
255
-                $pdf=pdf_getInstance($this->format);
256
-                $default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
257
-	            $pdf->SetAutoPageBreak(1,0);
255
+                $pdf = pdf_getInstance($this->format);
256
+                $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
257
+	            $pdf->SetAutoPageBreak(1, 0);
258 258
 
259 259
                 if (class_exists('TCPDF'))
260 260
                 {
@@ -263,28 +263,28 @@  discard block
 block discarded – undo
263 263
                 }
264 264
                 $pdf->SetFont(pdf_getPDFFont($outputlangs));
265 265
                 // Set path to the background PDF File
266
-                if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
266
+                if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
267 267
                 {
268 268
                     $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
269 269
                     $tplidx = $pdf->importPage(1);
270 270
                 }
271 271
 
272 272
 				$pdf->Open();
273
-				$pagenb=0;
274
-				$pdf->SetDrawColor(128,128,128);
273
+				$pagenb = 0;
274
+				$pdf->SetDrawColor(128, 128, 128);
275 275
 
276 276
 				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
277 277
 				$pdf->SetSubject($outputlangs->transnoentities("PdfCommercialProposalTitle"));
278 278
 				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
279 279
 				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
280 280
 				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfCommercialProposalTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
281
-				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
281
+				if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
282 282
 
283
-				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
283
+				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
284 284
 
285 285
 				// Does we have at least one line with discount $this->atleastonediscount
286 286
 				foreach ($object->lines as $line) {
287
-				    if ($line->remise_percent){
287
+				    if ($line->remise_percent) {
288 288
 				        $this->atleastonediscount = true;
289 289
 				        break;
290 290
 				    }
@@ -294,23 +294,23 @@  discard block
 block discarded – undo
294 294
 
295 295
 				// New page
296 296
 				$pdf->AddPage();
297
-				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
297
+				if (!empty($tplidx)) $pdf->useTemplate($tplidx);
298 298
 				$pagenb++;
299 299
 
300
-                $heightforinfotot = 40;	// Height reserved to output the info and total part
301
-                $heightforsignature = empty($conf->global->PROPAL_DISABLE_SIGNATURE)?(pdfGetHeightForHtmlContent($pdf, $outputlangs->transnoentities("ProposalCustomerSignature"))+10):0;
302
-                $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5);	// Height reserved to output the free text on last page
303
-                $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)?12:22);	// Height reserved to output the footer (value include bottom margin)
300
+                $heightforinfotot = 40; // Height reserved to output the info and total part
301
+                $heightforsignature = empty($conf->global->PROPAL_DISABLE_SIGNATURE) ? (pdfGetHeightForHtmlContent($pdf, $outputlangs->transnoentities("ProposalCustomerSignature")) + 10) : 0;
302
+                $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page
303
+                $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 12 : 22); // Height reserved to output the footer (value include bottom margin)
304 304
                 //print $heightforinfotot + $heightforsignature + $heightforfreetext + $heightforfooter;exit;
305 305
 
306 306
 				$top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
307
-				$pdf->SetFont('','', $default_font_size - 1);
308
-				$pdf->MultiCell(0, 3, '');		// Set interline to 3
309
-				$pdf->SetTextColor(0,0,0);
307
+				$pdf->SetFont('', '', $default_font_size - 1);
308
+				$pdf->MultiCell(0, 3, ''); // Set interline to 3
309
+				$pdf->SetTextColor(0, 0, 0);
310 310
 
311 311
 
312
-	            $tab_top = 90+$top_shift;
313
-				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10);
312
+	            $tab_top = 90 + $top_shift;
313
+				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 + $top_shift : 10);
314 314
 
315 315
 
316 316
 				// Incoterm
@@ -322,39 +322,39 @@  discard block
 block discarded – undo
322 322
 					{
323 323
 						$tab_top -= 2;
324 324
 
325
-						$pdf->SetFont('','', $default_font_size - 1);
326
-						$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
325
+						$pdf->SetFont('', '', $default_font_size - 1);
326
+						$pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
327 327
 						$nexY = $pdf->GetY();
328
-						$height_incoterms=$nexY-$tab_top;
328
+						$height_incoterms = $nexY - $tab_top;
329 329
 
330 330
 						// Rect prend une longueur en 3eme param
331
-						$pdf->SetDrawColor(192,192,192);
332
-						$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
331
+						$pdf->SetDrawColor(192, 192, 192);
332
+						$pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
333 333
 
334
-						$tab_top = $nexY+6;
334
+						$tab_top = $nexY + 6;
335 335
 					}
336 336
 				}
337 337
 
338 338
 				// Affiche notes
339
-				$notetoshow=empty($object->note_public)?'':$object->note_public;
340
-				if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
339
+				$notetoshow = empty($object->note_public) ? '' : $object->note_public;
340
+				if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
341 341
 				{
342 342
 					// Get first sale rep
343 343
 					if (is_object($object->thirdparty))
344 344
 					{
345
-						$salereparray=$object->thirdparty->getSalesRepresentatives($user);
346
-						$salerepobj=new User($this->db);
345
+						$salereparray = $object->thirdparty->getSalesRepresentatives($user);
346
+						$salerepobj = new User($this->db);
347 347
 						$salerepobj->fetch($salereparray[0]['id']);
348
-						if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
348
+						if (!empty($salerepobj->signature)) $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
349 349
 					}
350 350
 				}
351
-				if (! empty($conf->global->MAIN_ADD_CREATOR_IN_NOTE) && $object->user_author_id > 0)
351
+				if (!empty($conf->global->MAIN_ADD_CREATOR_IN_NOTE) && $object->user_author_id > 0)
352 352
 				{
353
-				    $tmpuser=new User($this->db);
353
+				    $tmpuser = new User($this->db);
354 354
 				    $tmpuser->fetch($object->user_author_id);
355
-				    $notetoshow.='Affaire suivi par '.$tmpuser->getFullName($langs);
356
-				    if ($tmpuser->email) $notetoshow.=',  Mail: '.$tmpuser->email;
357
-				    if ($tmpuser->office_phone) $notetoshow.=', Tel: '.$tmpuser->office_phone;
355
+				    $notetoshow .= 'Affaire suivi par '.$tmpuser->getFullName($langs);
356
+				    if ($tmpuser->email) $notetoshow .= ',  Mail: '.$tmpuser->email;
357
+				    if ($tmpuser->office_phone) $notetoshow .= ', Tel: '.$tmpuser->office_phone;
358 358
 				}
359 359
 
360 360
 				$pagenb = $pdf->getPage();
@@ -362,23 +362,23 @@  discard block
 block discarded – undo
362 362
 				{
363 363
 					$tab_top -= 2;
364 364
 
365
-				    $tab_width = $this->page_largeur-$this->marge_gauche-$this->marge_droite;
365
+				    $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
366 366
 				    $pageposbeforenote = $pagenb;
367 367
 
368
-					$substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
368
+					$substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
369 369
 					complete_substitutions_array($substitutionarray, $outputlangs, $object);
370 370
 					$notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
371 371
 
372 372
 
373 373
 					$pdf->startTransaction();
374 374
 
375
-					$pdf->SetFont('','', $default_font_size - 1);
376
-					$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
375
+					$pdf->SetFont('', '', $default_font_size - 1);
376
+					$pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
377 377
 					// Description
378
-					$pageposafternote=$pdf->getPage();
378
+					$pageposafternote = $pdf->getPage();
379 379
 					$posyafter = $pdf->GetY();
380 380
 
381
-					if($pageposafternote>$pageposbeforenote )
381
+					if ($pageposafternote > $pageposbeforenote)
382 382
 					{
383 383
 					    $pdf->rollbackTransaction(true);
384 384
 
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 					    while ($pagenb < $pageposafternote) {
387 387
 					        $pdf->AddPage();
388 388
 					        $pagenb++;
389
-					        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
389
+					        if (!empty($tplidx)) $pdf->useTemplate($tplidx);
390 390
 					        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
391 391
 					        // $this->_pagefoot($pdf,$object,$outputlangs,1);
392 392
 					        $pdf->setTopMargin($tab_top_newpage);
@@ -397,15 +397,15 @@  discard block
 block discarded – undo
397 397
 					    // back to start
398 398
 					    $pdf->setPage($pageposbeforenote);
399 399
 					    $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
400
-					    $pdf->SetFont('','', $default_font_size - 1);
401
-					    $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
402
-					    $pageposafternote=$pdf->getPage();
400
+					    $pdf->SetFont('', '', $default_font_size - 1);
401
+					    $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
402
+					    $pageposafternote = $pdf->getPage();
403 403
 
404 404
 					    $posyafter = $pdf->GetY();
405 405
 
406
-					    if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20)))	// There is no space left for total+free text
406
+					    if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20)))	// There is no space left for total+free text
407 407
 					    {
408
-					        $pdf->AddPage('','',true);
408
+					        $pdf->AddPage('', '', true);
409 409
 					        $pagenb++;
410 410
 					        $pageposafternote++;
411 411
 					        $pdf->setPage($pageposafternote);
@@ -422,47 +422,47 @@  discard block
 block discarded – undo
422 422
 					        $pdf->setPage($i);
423 423
 
424 424
 
425
-					        $pdf->SetDrawColor(128,128,128);
425
+					        $pdf->SetDrawColor(128, 128, 128);
426 426
 					        // Draw note frame
427
-					        if($i>$pageposbeforenote){
427
+					        if ($i > $pageposbeforenote) {
428 428
 					            $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
429
-					            $pdf->Rect($this->marge_gauche, $tab_top_newpage-1, $tab_width, $height_note + 1);
429
+					            $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
430 430
 					        }
431
-					        else{
431
+					        else {
432 432
 					            $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
433
-					            $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note + 1);
433
+					            $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
434 434
 					        }
435 435
 
436 436
 					        // Add footer
437
-					        $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
438
-					        $this->_pagefoot($pdf,$object,$outputlangs,1);
437
+					        $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
438
+					        $this->_pagefoot($pdf, $object, $outputlangs, 1);
439 439
 
440 440
 					        $i++;
441 441
 					    }
442 442
 
443 443
 					    // apply note frame to last page
444 444
 					    $pdf->setPage($pageposafternote);
445
-					    if (! empty($tplidx)) $pdf->useTemplate($tplidx);
445
+					    if (!empty($tplidx)) $pdf->useTemplate($tplidx);
446 446
 					    if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
447
-					    $height_note=$posyafter-$tab_top_newpage;
448
-					    $pdf->Rect($this->marge_gauche, $tab_top_newpage-1, $tab_width, $height_note+1);
447
+					    $height_note = $posyafter - $tab_top_newpage;
448
+					    $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
449 449
 					}
450 450
 					else // No pagebreak
451 451
 					{
452 452
 					    $pdf->commitTransaction();
453 453
 					    $posyafter = $pdf->GetY();
454
-					    $height_note=$posyafter-$tab_top;
455
-					    $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note+1);
454
+					    $height_note = $posyafter - $tab_top;
455
+					    $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
456 456
 
457 457
 
458
-					    if($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20)) )
458
+					    if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20)))
459 459
 					    {
460 460
 					        // not enough space, need to add page
461
-					        $pdf->AddPage('','',true);
461
+					        $pdf->AddPage('', '', true);
462 462
 					        $pagenb++;
463 463
 					        $pageposafternote++;
464 464
 					        $pdf->setPage($pageposafternote);
465
-					        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
465
+					        if (!empty($tplidx)) $pdf->useTemplate($tplidx);
466 466
 					        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
467 467
 
468 468
 					        $posyafter = $tab_top_newpage;
@@ -470,11 +470,11 @@  discard block
 block discarded – undo
470 470
 					}
471 471
 
472 472
 					$tab_height = $tab_height - $height_note;
473
-					$tab_top = $posyafter +6;
473
+					$tab_top = $posyafter + 6;
474 474
 				}
475 475
 				else
476 476
 				{
477
-					$height_note=0;
477
+					$height_note = 0;
478 478
 				}
479 479
 
480 480
 				$iniY = $tab_top + 7;
@@ -482,112 +482,112 @@  discard block
 block discarded – undo
482 482
 				$nexY = $tab_top + 7;
483 483
 
484 484
 				// Use new auto collum system
485
-				$this->prepareArrayColumnField($object,$outputlangs,$hidedetails,$hidedesc,$hideref);
485
+				$this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
486 486
 
487 487
 				// Loop on each lines
488
-				$pageposbeforeprintlines=$pdf->getPage();
488
+				$pageposbeforeprintlines = $pdf->getPage();
489 489
 				$pagenb = $pageposbeforeprintlines;
490 490
 				for ($i = 0; $i < $nblignes; $i++)
491 491
 				{
492 492
 					$curY = $nexY;
493
-					$pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
494
-					$pdf->SetTextColor(0,0,0);
493
+					$pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
494
+					$pdf->SetTextColor(0, 0, 0);
495 495
 
496 496
 					// Define size of image if we need it
497
-					$imglinesize=array();
498
-					if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
497
+					$imglinesize = array();
498
+					if (!empty($realpatharray[$i])) $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
499 499
 
500 500
 					$pdf->setTopMargin($tab_top_newpage);
501
-					$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
502
-					$pageposbefore=$pdf->getPage();
501
+					$pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
502
+					$pageposbefore = $pdf->getPage();
503 503
 
504
-					$showpricebeforepagebreak=1;
505
-					$posYAfterImage=0;
506
-					$posYAfterDescription=0;
504
+					$showpricebeforepagebreak = 1;
505
+					$posYAfterImage = 0;
506
+					$posYAfterDescription = 0;
507 507
 
508
-					if($this->getColumnStatus('photo'))
508
+					if ($this->getColumnStatus('photo'))
509 509
 					{
510 510
     					// We start with Photo of product line
511
-    					if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot)))	// If photo too high, we moved completely on new page
511
+    					if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot)))	// If photo too high, we moved completely on new page
512 512
     					{
513
-    						$pdf->AddPage('','',true);
514
-    						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
513
+    						$pdf->AddPage('', '', true);
514
+    						if (!empty($tplidx)) $pdf->useTemplate($tplidx);
515 515
     						//if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
516
-    						$pdf->setPage($pageposbefore+1);
516
+    						$pdf->setPage($pageposbefore + 1);
517 517
 
518 518
     						$curY = $tab_top_newpage;
519
-    						$showpricebeforepagebreak=0;
519
+    						$showpricebeforepagebreak = 0;
520 520
     					}
521 521
 
522 522
 
523 523
     					if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height']))
524 524
     					{
525
-    						$pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);	// Use 300 dpi
525
+    						$pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
526 526
     						// $pdf->Image does not increase value return by getY, so we save it manually
527
-    						$posYAfterImage=$curY+$imglinesize['height'];
527
+    						$posYAfterImage = $curY + $imglinesize['height'];
528 528
     					}
529 529
 					}
530 530
 
531 531
 					// Description of product line
532
-					if($this->getColumnStatus('desc'))
532
+					if ($this->getColumnStatus('desc'))
533 533
 					{
534 534
     					$pdf->startTransaction();
535
-    					pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->getColumnContentWidth('desc'),3,$this->getColumnContentXStart('desc'),$curY,$hideref,$hidedesc);
536
-    					$pageposafter=$pdf->getPage();
535
+    					pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->getColumnContentWidth('desc'), 3, $this->getColumnContentXStart('desc'), $curY, $hideref, $hidedesc);
536
+    					$pageposafter = $pdf->getPage();
537 537
     					if ($pageposafter > $pageposbefore)	// There is a pagebreak
538 538
     					{
539 539
     						$pdf->rollbackTransaction(true);
540
-    						$pageposafter=$pageposbefore;
540
+    						$pageposafter = $pageposbefore;
541 541
     						//print $pageposafter.'-'.$pageposbefore;exit;
542
-    						$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
543
-    						pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->getColumnContentWidth('desc'),3,$this->getColumnContentXStart('desc'),$curY,$hideref,$hidedesc);
542
+    						$pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
543
+    						pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->getColumnContentWidth('desc'), 3, $this->getColumnContentXStart('desc'), $curY, $hideref, $hidedesc);
544 544
 
545
-    						$pageposafter=$pdf->getPage();
546
-    						$posyafter=$pdf->GetY();
545
+    						$pageposafter = $pdf->getPage();
546
+    						$posyafter = $pdf->GetY();
547 547
     						//var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
548
-    						if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot)))	// There is no space left for total+free text
548
+    						if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot)))	// There is no space left for total+free text
549 549
     						{
550
-    							if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
550
+    							if ($i == ($nblignes - 1))	// No more lines, and no space left to show total, so we create a new page
551 551
     							{
552
-    								$pdf->AddPage('','',true);
553
-    								if (! empty($tplidx)) $pdf->useTemplate($tplidx);
552
+    								$pdf->AddPage('', '', true);
553
+    								if (!empty($tplidx)) $pdf->useTemplate($tplidx);
554 554
     								//if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
555
-    								$pdf->setPage($pageposafter+1);
555
+    								$pdf->setPage($pageposafter + 1);
556 556
     							}
557 557
     						}
558 558
     						else
559 559
     						{
560 560
     							// We found a page break
561
-    							$showpricebeforepagebreak=0;
561
+    							$showpricebeforepagebreak = 0;
562 562
     						}
563 563
     					}
564 564
     					else	// No pagebreak
565 565
     					{
566 566
     						$pdf->commitTransaction();
567 567
     					}
568
-    					$posYAfterDescription=$pdf->GetY();
568
+    					$posYAfterDescription = $pdf->GetY();
569 569
 					}
570 570
 
571 571
 					$nexY = $pdf->GetY();
572
-					$pageposafter=$pdf->getPage();
572
+					$pageposafter = $pdf->getPage();
573 573
 
574 574
 					$pdf->setPage($pageposbefore);
575 575
 					$pdf->setTopMargin($this->marge_haute);
576
-					$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
576
+					$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
577 577
 
578 578
 					// We suppose that a too long description or photo were moved completely on next page
579 579
 					if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
580 580
 						$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
581 581
 					}
582 582
 
583
-					$pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
583
+					$pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
584 584
 
585 585
 					// VAT Rate
586 586
 					if ($this->getColumnStatus('vat'))
587 587
 					{
588 588
 					    $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
589 589
 					    $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
590
-					    $nexY = max($pdf->GetY(),$nexY);
590
+					    $nexY = max($pdf->GetY(), $nexY);
591 591
 					}
592 592
 
593 593
 					// Unit price before discount
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
 					{
596 596
 					    $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
597 597
 					    $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
598
-					    $nexY = max($pdf->GetY(),$nexY);
598
+					    $nexY = max($pdf->GetY(), $nexY);
599 599
 					}
600 600
 
601 601
 					// Quantity
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
 					{
605 605
 					    $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
606 606
 					    $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
607
-					    $nexY = max($pdf->GetY(),$nexY);
607
+					    $nexY = max($pdf->GetY(), $nexY);
608 608
 					}
609 609
 
610 610
 
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
 					{
614 614
 					    $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
615 615
 					    $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
616
-					    $nexY = max($pdf->GetY(),$nexY);
616
+					    $nexY = max($pdf->GetY(), $nexY);
617 617
 					}
618 618
 
619 619
 					// Discount on line
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
 					{
622 622
 					    $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
623 623
 					    $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
624
-					    $nexY = max($pdf->GetY(),$nexY);
624
+					    $nexY = max($pdf->GetY(), $nexY);
625 625
 					}
626 626
 
627 627
 					// Total HT line
@@ -629,11 +629,11 @@  discard block
 block discarded – undo
629 629
 					{
630 630
 					    $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
631 631
 					    $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
632
-					    $nexY = max($pdf->GetY(),$nexY);
632
+					    $nexY = max($pdf->GetY(), $nexY);
633 633
 					}
634 634
 
635 635
 
636
-					$parameters=array(
636
+					$parameters = array(
637 637
 					    'object' => $object,
638 638
 					    'i' => $i,
639 639
 					    'pdf' =>& $pdf,
@@ -642,59 +642,59 @@  discard block
 block discarded – undo
642 642
 					    'outputlangs' => $outputlangs,
643 643
 					    'hidedetails' => $hidedetails
644 644
 					);
645
-					$reshook=$hookmanager->executeHooks('printPDFline',$parameters,$this);    // Note that $object may have been modified by hook
645
+					$reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
646 646
 
647 647
 
648 648
 
649 649
 					// Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
650
-					if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
651
-					else $tvaligne=$object->lines[$i]->total_tva;
650
+					if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne = $object->lines[$i]->multicurrency_total_tva;
651
+					else $tvaligne = $object->lines[$i]->total_tva;
652 652
 
653
-					$localtax1ligne=$object->lines[$i]->total_localtax1;
654
-					$localtax2ligne=$object->lines[$i]->total_localtax2;
655
-					$localtax1_rate=$object->lines[$i]->localtax1_tx;
656
-					$localtax2_rate=$object->lines[$i]->localtax2_tx;
657
-					$localtax1_type=$object->lines[$i]->localtax1_type;
658
-					$localtax2_type=$object->lines[$i]->localtax2_type;
653
+					$localtax1ligne = $object->lines[$i]->total_localtax1;
654
+					$localtax2ligne = $object->lines[$i]->total_localtax2;
655
+					$localtax1_rate = $object->lines[$i]->localtax1_tx;
656
+					$localtax2_rate = $object->lines[$i]->localtax2_tx;
657
+					$localtax1_type = $object->lines[$i]->localtax1_type;
658
+					$localtax2_type = $object->lines[$i]->localtax2_type;
659 659
 
660
-					if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
661
-					if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
662
-					if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
660
+					if ($object->remise_percent) $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
661
+					if ($object->remise_percent) $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
662
+					if ($object->remise_percent) $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
663 663
 
664
-					$vatrate=(string) $object->lines[$i]->tva_tx;
664
+					$vatrate = (string) $object->lines[$i]->tva_tx;
665 665
 
666 666
 					// Retrieve type from database for backward compatibility with old records
667
-					if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
668
-					&& (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
667
+					if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
668
+					&& (!empty($localtax1_rate) || !empty($localtax2_rate))) // and there is local tax
669 669
 					{
670
-						$localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc);
670
+						$localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
671 671
 						$localtax1_type = $localtaxtmp_array[0];
672 672
 						$localtax2_type = $localtaxtmp_array[2];
673 673
 					}
674 674
 
675 675
 				    // retrieve global local tax
676 676
 					if ($localtax1_type && $localtax1ligne != 0)
677
-						$this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
677
+						$this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
678 678
 					if ($localtax2_type && $localtax2ligne != 0)
679
-						$this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
679
+						$this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
680 680
 
681
-					if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
682
-					if (! isset($this->tva[$vatrate]))				$this->tva[$vatrate]=0;
681
+					if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate .= '*';
682
+					if (!isset($this->tva[$vatrate]))				$this->tva[$vatrate] = 0;
683 683
 					$this->tva[$vatrate] += $tvaligne;
684 684
 
685
-					if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
685
+					if ($posYAfterImage > $posYAfterDescription) $nexY = $posYAfterImage;
686 686
 
687 687
 					// Add line
688
-					if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
688
+					if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
689 689
 					{
690 690
 						$pdf->setPage($pageposafter);
691
-						$pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
691
+						$pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
692 692
 						//$pdf->SetDrawColor(190,190,200);
693
-						$pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
693
+						$pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
694 694
 						$pdf->SetLineStyle(array('dash'=>0));
695 695
 					}
696 696
 
697
-					$nexY+=2;    // Passe espace entre les lignes
697
+					$nexY += 2; // Passe espace entre les lignes
698 698
 
699 699
 					// Detect if some page were added automatically and output _tableau for past pages
700 700
 					while ($pagenb < $pageposafter)
@@ -708,13 +708,13 @@  discard block
 block discarded – undo
708 708
 						{
709 709
 							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
710 710
 						}
711
-						$this->_pagefoot($pdf,$object,$outputlangs,1);
711
+						$this->_pagefoot($pdf, $object, $outputlangs, 1);
712 712
 						$pagenb++;
713 713
 						$pdf->setPage($pagenb);
714
-						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
714
+						$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
715 715
 						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
716 716
 					}
717
-					if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
717
+					if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak)
718 718
 					{
719 719
 					    if ($pagenb == $pageposafter)
720 720
 						{
@@ -724,10 +724,10 @@  discard block
 block discarded – undo
724 724
 						{
725 725
 							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
726 726
 						}
727
-						$this->_pagefoot($pdf,$object,$outputlangs,1);
727
+						$this->_pagefoot($pdf, $object, $outputlangs, 1);
728 728
 						// New page
729 729
 						$pdf->AddPage();
730
-						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
730
+						if (!empty($tplidx)) $pdf->useTemplate($tplidx);
731 731
 						$pagenb++;
732 732
 						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
733 733
 					}
@@ -737,19 +737,19 @@  discard block
 block discarded – undo
737 737
 				if ($pagenb == $pageposbeforeprintlines)
738 738
 				{
739 739
 					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
740
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
740
+					$bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
741 741
 				}
742 742
 				else
743 743
 				{
744 744
 					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
745
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
745
+					$bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
746 746
 				}
747 747
 
748 748
 				// Affiche zone infos
749
-				$posy=$this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
749
+				$posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
750 750
 
751 751
 				// Affiche zone totaux
752
-				$posy=$this->drawTotalTable($pdf, $object, 0, $bottomlasttab, $outputlangs);
752
+				$posy = $this->drawTotalTable($pdf, $object, 0, $bottomlasttab, $outputlangs);
753 753
 
754 754
 				// Affiche zone versements
755 755
 				/*
@@ -762,21 +762,21 @@  discard block
 block discarded – undo
762 762
 				// Customer signature area
763 763
 				if (empty($conf->global->PROPAL_DISABLE_SIGNATURE))
764 764
 				{
765
-				    $posy=$this->drawSignatureArea($pdf, $object, $posy, $outputlangs);
765
+				    $posy = $this->drawSignatureArea($pdf, $object, $posy, $outputlangs);
766 766
 				}
767 767
 
768 768
 				// Pied de page
769
-				$this->_pagefoot($pdf,$object,$outputlangs);
770
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
769
+				$this->_pagefoot($pdf, $object, $outputlangs);
770
+				if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
771 771
 
772 772
 				//If propal merge product PDF is active
773 773
 				if (!empty($conf->global->PRODUIT_PDF_MERGE_PROPAL))
774 774
 				{
775 775
 					require_once DOL_DOCUMENT_ROOT.'/product/class/propalmergepdfproduct.class.php';
776 776
 
777
-					$already_merged = array ();
778
-					foreach ( $object->lines as $line ) {
779
-						if (! empty($line->fk_product) && ! (in_array($line->fk_product, $already_merged))) {
777
+					$already_merged = array();
778
+					foreach ($object->lines as $line) {
779
+						if (!empty($line->fk_product) && !(in_array($line->fk_product, $already_merged))) {
780 780
 							// Find the desire PDF
781 781
 							$filetomerge = new Propalmergepdfproduct($this->db);
782 782
 
@@ -791,48 +791,48 @@  discard block
 block discarded – undo
791 791
 							$product = new Product($this->db);
792 792
 							$product->fetch($line->fk_product);
793 793
 
794
-							if ($product->entity!=$conf->entity) {
795
-								$entity_product_file=$product->entity;
794
+							if ($product->entity != $conf->entity) {
795
+								$entity_product_file = $product->entity;
796 796
 							} else {
797
-								$entity_product_file=$conf->entity;
797
+								$entity_product_file = $conf->entity;
798 798
 							}
799 799
 
800 800
 							// If PDF is selected and file is not empty
801 801
 							if (count($filetomerge->lines) > 0) {
802
-								foreach ( $filetomerge->lines as $linefile ) {
803
-									if (! empty($linefile->id) && ! empty($linefile->file_name)) {
802
+								foreach ($filetomerge->lines as $linefile) {
803
+									if (!empty($linefile->id) && !empty($linefile->file_name)) {
804 804
 
805 805
 
806
-										if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
806
+										if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
807 807
 										{
808
-											if (! empty($conf->product->enabled)) {
809
-												$filetomerge_dir = $conf->product->multidir_output[$entity_product_file] . '/' . get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos";
810
-											} elseif (! empty($conf->service->enabled)) {
811
-												$filetomerge_dir = $conf->service->multidir_output[$entity_product_file] . '/' . get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos";
808
+											if (!empty($conf->product->enabled)) {
809
+												$filetomerge_dir = $conf->product->multidir_output[$entity_product_file].'/'.get_exdir($product->id, 2, 0, 0, $product, 'product').$product->id."/photos";
810
+											} elseif (!empty($conf->service->enabled)) {
811
+												$filetomerge_dir = $conf->service->multidir_output[$entity_product_file].'/'.get_exdir($product->id, 2, 0, 0, $product, 'product').$product->id."/photos";
812 812
 											}
813 813
 										}
814 814
 										else
815 815
 										{
816
-											if (! empty($conf->product->enabled)) {
817
-												$filetomerge_dir = $conf->product->multidir_output[$entity_product_file] . '/' . get_exdir(0,0,0,0,$product,'product') . dol_sanitizeFileName($product->ref);
818
-											} elseif (! empty($conf->service->enabled)) {
819
-												$filetomerge_dir = $conf->service->multidir_output[$entity_product_file] . '/' . get_exdir(0,0,0,0,$product,'product') . dol_sanitizeFileName($product->ref);
816
+											if (!empty($conf->product->enabled)) {
817
+												$filetomerge_dir = $conf->product->multidir_output[$entity_product_file].'/'.get_exdir(0, 0, 0, 0, $product, 'product').dol_sanitizeFileName($product->ref);
818
+											} elseif (!empty($conf->service->enabled)) {
819
+												$filetomerge_dir = $conf->service->multidir_output[$entity_product_file].'/'.get_exdir(0, 0, 0, 0, $product, 'product').dol_sanitizeFileName($product->ref);
820 820
 											}
821 821
 										}
822 822
 
823
-										dol_syslog(get_class($this) . ':: upload_dir=' . $filetomerge_dir, LOG_DEBUG);
823
+										dol_syslog(get_class($this).':: upload_dir='.$filetomerge_dir, LOG_DEBUG);
824 824
 
825
-										$infile = $filetomerge_dir . '/' . $linefile->file_name;
825
+										$infile = $filetomerge_dir.'/'.$linefile->file_name;
826 826
 										if (file_exists($infile) && is_readable($infile)) {
827 827
 											$pagecount = $pdf->setSourceFile($infile);
828
-											for($i = 1; $i <= $pagecount; $i ++) {
828
+											for ($i = 1; $i <= $pagecount; $i++) {
829 829
 												$tplIdx = $pdf->importPage($i);
830
-												if ($tplIdx!==false) {
830
+												if ($tplIdx !== false) {
831 831
 													$s = $pdf->getTemplatesize($tplIdx);
832 832
 													$pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
833 833
 													$pdf->useTemplate($tplIdx);
834 834
 												} else {
835
-													setEventMessages(null, array($infile.' cannot be added, probably protected PDF'),'warnings');
835
+													setEventMessages(null, array($infile.' cannot be added, probably protected PDF'), 'warnings');
836 836
 												}
837 837
 											}
838 838
 										}
@@ -845,30 +845,30 @@  discard block
 block discarded – undo
845 845
 
846 846
 				$pdf->Close();
847 847
 
848
-				$pdf->Output($file,'F');
848
+				$pdf->Output($file, 'F');
849 849
 
850 850
 				//Add pdfgeneration hook
851 851
 				$hookmanager->initHooks(array('pdfgeneration'));
852
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
852
+				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
853 853
 				global $action;
854
-				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
854
+				$reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
855 855
 
856
-				if (! empty($conf->global->MAIN_UMASK))
856
+				if (!empty($conf->global->MAIN_UMASK))
857 857
 				@chmod($file, octdec($conf->global->MAIN_UMASK));
858 858
 
859 859
 				$this->result = array('fullpath'=>$file);
860 860
 
861
-				return 1;   // Pas d'erreur
861
+				return 1; // Pas d'erreur
862 862
 			}
863 863
 			else
864 864
 			{
865
-				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
865
+				$this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
866 866
 				return 0;
867 867
 			}
868 868
 		}
869 869
 		else
870 870
 		{
871
-			$this->error=$langs->trans("ErrorConstantNotDefined","PROP_OUTPUTDIR");
871
+			$this->error = $langs->trans("ErrorConstantNotDefined", "PROP_OUTPUTDIR");
872 872
 			return 0;
873 873
 		}
874 874
 	}
@@ -900,66 +900,66 @@  discard block
 block discarded – undo
900 900
 		global $conf;
901 901
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
902 902
 
903
-		$pdf->SetFont('','', $default_font_size - 1);
903
+		$pdf->SetFont('', '', $default_font_size - 1);
904 904
 
905 905
 		// If France, show VAT mention if not applicable
906 906
 		if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
907 907
 		{
908
-			$pdf->SetFont('','B', $default_font_size - 2);
908
+			$pdf->SetFont('', 'B', $default_font_size - 2);
909 909
 			$pdf->SetXY($this->marge_gauche, $posy);
910 910
 			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
911 911
 
912
-			$posy=$pdf->GetY()+4;
912
+			$posy = $pdf->GetY() + 4;
913 913
 		}
914 914
 
915
-		$posxval=52;
915
+		$posxval = 52;
916 916
 
917 917
         // Show shipping date
918
-        if (! empty($object->date_livraison))
918
+        if (!empty($object->date_livraison))
919 919
 		{
920 920
             $outputlangs->load("sendings");
921
-			$pdf->SetFont('','B', $default_font_size - 2);
921
+			$pdf->SetFont('', 'B', $default_font_size - 2);
922 922
 			$pdf->SetXY($this->marge_gauche, $posy);
923 923
 			$titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
924 924
 			$pdf->MultiCell(80, 4, $titre, 0, 'L');
925
-			$pdf->SetFont('','', $default_font_size - 2);
925
+			$pdf->SetFont('', '', $default_font_size - 2);
926 926
 			$pdf->SetXY($posxval, $posy);
927
-			$dlp=dol_print_date($object->date_livraison,"daytext",false,$outputlangs,true);
927
+			$dlp = dol_print_date($object->date_livraison, "daytext", false, $outputlangs, true);
928 928
 			$pdf->MultiCell(80, 4, $dlp, 0, 'L');
929 929
 
930
-            $posy=$pdf->GetY()+1;
930
+            $posy = $pdf->GetY() + 1;
931 931
 		}
932 932
         elseif ($object->availability_code || $object->availability)    // Show availability conditions
933 933
 		{
934
-			$pdf->SetFont('','B', $default_font_size - 2);
934
+			$pdf->SetFont('', 'B', $default_font_size - 2);
935 935
 			$pdf->SetXY($this->marge_gauche, $posy);
936 936
 			$titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
937 937
 			$pdf->MultiCell(80, 4, $titre, 0, 'L');
938
-			$pdf->SetTextColor(0,0,0);
939
-			$pdf->SetFont('','', $default_font_size - 2);
938
+			$pdf->SetTextColor(0, 0, 0);
939
+			$pdf->SetFont('', '', $default_font_size - 2);
940 940
 			$pdf->SetXY($posxval, $posy);
941
-			$lib_availability=$outputlangs->transnoentities("AvailabilityType".$object->availability_code)!=('AvailabilityType'.$object->availability_code)?$outputlangs->transnoentities("AvailabilityType".$object->availability_code):$outputlangs->convToOutputCharset($object->availability);
942
-			$lib_availability=str_replace('\n',"\n",$lib_availability);
941
+			$lib_availability = $outputlangs->transnoentities("AvailabilityType".$object->availability_code) != ('AvailabilityType'.$object->availability_code) ? $outputlangs->transnoentities("AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset($object->availability);
942
+			$lib_availability = str_replace('\n', "\n", $lib_availability);
943 943
 			$pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
944 944
 
945
-			$posy=$pdf->GetY()+1;
945
+			$posy = $pdf->GetY() + 1;
946 946
 		}
947 947
 
948 948
 		// Show payments conditions
949 949
 		if (empty($conf->global->PROPALE_PDF_HIDE_PAYMENTTERMCOND) && ($object->cond_reglement_code || $object->cond_reglement))
950 950
 		{
951
-			$pdf->SetFont('','B', $default_font_size - 2);
951
+			$pdf->SetFont('', 'B', $default_font_size - 2);
952 952
 			$pdf->SetXY($this->marge_gauche, $posy);
953 953
 			$titre = $outputlangs->transnoentities("PaymentConditions").':';
954 954
 			$pdf->MultiCell(43, 4, $titre, 0, 'L');
955 955
 
956
-			$pdf->SetFont('','', $default_font_size - 2);
956
+			$pdf->SetFont('', '', $default_font_size - 2);
957 957
 			$pdf->SetXY($posxval, $posy);
958
-			$lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc);
959
-			$lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
960
-			$pdf->MultiCell(67, 4, $lib_condition_paiement,0,'L');
958
+			$lib_condition_paiement = $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) != ('PaymentCondition'.$object->cond_reglement_code) ? $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc);
959
+			$lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
960
+			$pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
961 961
 
962
-			$posy=$pdf->GetY()+3;
962
+			$posy = $pdf->GetY() + 3;
963 963
 		}
964 964
 
965 965
 		if (empty($conf->global->PROPALE_PDF_HIDE_PAYMENTTERMMODE))
@@ -985,25 +985,25 @@  discard block
 block discarded – undo
985 985
 			&& $object->mode_reglement_code != 'CHQ'
986 986
 			&& $object->mode_reglement_code != 'VIR')
987 987
 			{
988
-				$pdf->SetFont('','B', $default_font_size - 2);
988
+				$pdf->SetFont('', 'B', $default_font_size - 2);
989 989
 				$pdf->SetXY($this->marge_gauche, $posy);
990 990
 				$titre = $outputlangs->transnoentities("PaymentMode").':';
991 991
 				$pdf->MultiCell(80, 5, $titre, 0, 'L');
992
-				$pdf->SetFont('','', $default_font_size - 2);
992
+				$pdf->SetFont('', '', $default_font_size - 2);
993 993
 				$pdf->SetXY($posxval, $posy);
994
-				$lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement);
995
-				$pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
994
+				$lib_mode_reg = $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) != ('PaymentType'.$object->mode_reglement_code) ? $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) : $outputlangs->convToOutputCharset($object->mode_reglement);
995
+				$pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
996 996
 
997
-				$posy=$pdf->GetY()+2;
997
+				$posy = $pdf->GetY() + 2;
998 998
 			}
999 999
 
1000 1000
 			// Show payment mode CHQ
1001 1001
 			if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
1002 1002
 			{
1003 1003
 				// Si mode reglement non force ou si force a CHQ
1004
-				if (! empty($conf->global->FACTURE_CHQ_NUMBER))
1004
+				if (!empty($conf->global->FACTURE_CHQ_NUMBER))
1005 1005
 				{
1006
-					$diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
1006
+					$diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1007 1007
 
1008 1008
 					if ($conf->global->FACTURE_CHQ_NUMBER > 0)
1009 1009
 					{
@@ -1011,31 +1011,31 @@  discard block
 block discarded – undo
1011 1011
 						$account->fetch($conf->global->FACTURE_CHQ_NUMBER);
1012 1012
 
1013 1013
 						$pdf->SetXY($this->marge_gauche, $posy);
1014
-						$pdf->SetFont('','B', $default_font_size - $diffsizetitle);
1015
-						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio),0,'L',0);
1016
-						$posy=$pdf->GetY()+1;
1014
+						$pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1015
+						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0);
1016
+						$posy = $pdf->GetY() + 1;
1017 1017
 
1018 1018
 			            if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1019 1019
 			            {
1020 1020
 							$pdf->SetXY($this->marge_gauche, $posy);
1021
-							$pdf->SetFont('','', $default_font_size - $diffsizetitle);
1021
+							$pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1022 1022
 							$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
1023
-							$posy=$pdf->GetY()+2;
1023
+							$posy = $pdf->GetY() + 2;
1024 1024
 			            }
1025 1025
 					}
1026 1026
 					if ($conf->global->FACTURE_CHQ_NUMBER == -1)
1027 1027
 					{
1028 1028
 						$pdf->SetXY($this->marge_gauche, $posy);
1029
-						$pdf->SetFont('','B', $default_font_size - $diffsizetitle);
1030
-						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$this->emetteur->name),0,'L',0);
1031
-						$posy=$pdf->GetY()+1;
1029
+						$pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1030
+						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
1031
+						$posy = $pdf->GetY() + 1;
1032 1032
 
1033 1033
 			            if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1034 1034
 			            {
1035 1035
 							$pdf->SetXY($this->marge_gauche, $posy);
1036
-							$pdf->SetFont('','', $default_font_size - $diffsizetitle);
1036
+							$pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1037 1037
 							$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1038
-							$posy=$pdf->GetY()+2;
1038
+							$posy = $pdf->GetY() + 2;
1039 1039
 			            }
1040 1040
 					}
1041 1041
 				}
@@ -1044,19 +1044,19 @@  discard block
 block discarded – undo
1044 1044
 			// If payment mode not forced or forced to VIR, show payment with BAN
1045 1045
 			if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
1046 1046
 			{
1047
-				if (! empty($object->fk_account) || ! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
1047
+				if (!empty($object->fk_account) || !empty($object->fk_bank) || !empty($conf->global->FACTURE_RIB_NUMBER))
1048 1048
 				{
1049
-					$bankid=(empty($object->fk_account)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_account);
1050
-					if (! empty($object->fk_bank)) $bankid=$object->fk_bank;   // For backward compatibility when object->fk_account is forced with object->fk_bank
1049
+					$bankid = (empty($object->fk_account) ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1050
+					if (!empty($object->fk_bank)) $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1051 1051
 					$account = new Account($this->db);
1052 1052
 					$account->fetch($bankid);
1053 1053
 
1054
-					$curx=$this->marge_gauche;
1055
-					$cury=$posy;
1054
+					$curx = $this->marge_gauche;
1055
+					$cury = $posy;
1056 1056
 
1057
-					$posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size);
1057
+					$posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1058 1058
 
1059
-					$posy+=2;
1059
+					$posy += 2;
1060 1060
 				}
1061 1061
 			}
1062 1062
 		}
@@ -1077,43 +1077,43 @@  discard block
 block discarded – undo
1077 1077
 	 */
1078 1078
 	private function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs)
1079 1079
 	{
1080
-		global $conf,$mysoc;
1080
+		global $conf, $mysoc;
1081 1081
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
1082 1082
 
1083 1083
 		$tab2_top = $posy;
1084 1084
 		$tab2_hl = 4;
1085
-		$pdf->SetFont('','', $default_font_size - 1);
1085
+		$pdf->SetFont('', '', $default_font_size - 1);
1086 1086
 
1087 1087
 		// Tableau total
1088 1088
 		$col1x = 120; $col2x = 170;
1089 1089
 		if ($this->page_largeur < 210) // To work with US executive format
1090 1090
 		{
1091
-			$col2x-=20;
1091
+			$col2x -= 20;
1092 1092
 		}
1093 1093
 		$largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1094 1094
 
1095
-		$useborder=0;
1095
+		$useborder = 0;
1096 1096
 		$index = 0;
1097 1097
 
1098 1098
 		// Total HT
1099
-		$pdf->SetFillColor(255,255,255);
1099
+		$pdf->SetFillColor(255, 255, 255);
1100 1100
 		$pdf->SetXY($col1x, $tab2_top + 0);
1101
-		$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1101
+		$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1102 1102
 
1103 1103
 		$total_ht = ($conf->multicurrency->enabled && $object->mylticurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1104 1104
 		$pdf->SetXY($col2x, $tab2_top + 0);
1105
-		$pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (! empty($object->remise)?$object->remise:0), 0, $outputlangs), 0, 'R', 1);
1105
+		$pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0, 'R', 1);
1106 1106
 
1107 1107
 		// Show VAT by rates and total
1108
-		$pdf->SetFillColor(248,248,248);
1108
+		$pdf->SetFillColor(248, 248, 248);
1109 1109
 
1110 1110
 		$total_ttc = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1111 1111
 
1112
-		$this->atleastoneratenotnull=0;
1112
+		$this->atleastoneratenotnull = 0;
1113 1113
 		if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1114 1114
 		{
1115
-			$tvaisnull=((! empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1116
-			if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1115
+			$tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1116
+			if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1117 1117
 			{
1118 1118
 				// Nothing to do
1119 1119
 			}
@@ -1122,28 +1122,28 @@  discard block
 block discarded – undo
1122 1122
 				//Local tax 1 before VAT
1123 1123
 				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1124 1124
 				//{
1125
-					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1125
+					foreach ($this->localtax1 as $localtax_type => $localtax_rate)
1126 1126
 					{
1127
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1127
+						if (in_array((string) $localtax_type, array('1', '3', '5'))) continue;
1128 1128
 
1129
-						foreach( $localtax_rate as $tvakey => $tvaval )
1129
+						foreach ($localtax_rate as $tvakey => $tvaval)
1130 1130
 						{
1131
-							if ($tvakey!=0)    // On affiche pas taux 0
1131
+							if ($tvakey != 0)    // On affiche pas taux 0
1132 1132
 							{
1133 1133
 								//$this->atleastoneratenotnull++;
1134 1134
 
1135 1135
 								$index++;
1136 1136
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1137 1137
 
1138
-								$tvacompl='';
1139
-								if (preg_match('/\*/',$tvakey))
1138
+								$tvacompl = '';
1139
+								if (preg_match('/\*/', $tvakey))
1140 1140
 								{
1141
-									$tvakey=str_replace('*','',$tvakey);
1141
+									$tvakey = str_replace('*', '', $tvakey);
1142 1142
 									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1143 1143
 								}
1144
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1145
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1146
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1144
+								$totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
1145
+								$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1146
+								$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1147 1147
 
1148 1148
 								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1149 1149
 								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
@@ -1154,13 +1154,13 @@  discard block
 block discarded – undo
1154 1154
 				//Local tax 2 before VAT
1155 1155
 				//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1156 1156
 				//{
1157
-					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1157
+					foreach ($this->localtax2 as $localtax_type => $localtax_rate)
1158 1158
 					{
1159
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1159
+						if (in_array((string) $localtax_type, array('1', '3', '5'))) continue;
1160 1160
 
1161
-						foreach( $localtax_rate as $tvakey => $tvaval )
1161
+						foreach ($localtax_rate as $tvakey => $tvaval)
1162 1162
 						{
1163
-							if ($tvakey!=0)    // On affiche pas taux 0
1163
+							if ($tvakey != 0)    // On affiche pas taux 0
1164 1164
 							{
1165 1165
 								//$this->atleastoneratenotnull++;
1166 1166
 
@@ -1169,15 +1169,15 @@  discard block
 block discarded – undo
1169 1169
 								$index++;
1170 1170
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1171 1171
 
1172
-								$tvacompl='';
1173
-								if (preg_match('/\*/',$tvakey))
1172
+								$tvacompl = '';
1173
+								if (preg_match('/\*/', $tvakey))
1174 1174
 								{
1175
-									$tvakey=str_replace('*','',$tvakey);
1175
+									$tvakey = str_replace('*', '', $tvakey);
1176 1176
 									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1177 1177
 								}
1178 1178
 								$totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1179
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1180
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1179
+								$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1180
+								$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1181 1181
 
1182 1182
 								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1183 1183
 								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
@@ -1186,7 +1186,7 @@  discard block
 block discarded – undo
1186 1186
 					}
1187 1187
 				//}
1188 1188
 				// VAT
1189
-				foreach($this->tva as $tvakey => $tvaval)
1189
+				foreach ($this->tva as $tvakey => $tvaval)
1190 1190
 				{
1191 1191
 					if ($tvakey != 0)    // On affiche pas taux 0
1192 1192
 					{
@@ -1195,15 +1195,15 @@  discard block
 block discarded – undo
1195 1195
 						$index++;
1196 1196
 						$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1197 1197
 
1198
-						$tvacompl='';
1199
-						if (preg_match('/\*/',$tvakey))
1198
+						$tvacompl = '';
1199
+						if (preg_match('/\*/', $tvakey))
1200 1200
 						{
1201
-							$tvakey=str_replace('*','',$tvakey);
1201
+							$tvakey = str_replace('*', '', $tvakey);
1202 1202
 							$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1203 1203
 						}
1204
-						$totalvat =$outputlangs->transcountrynoentities("TotalVAT",$mysoc->country_code).' ';
1205
-						$totalvat.=vatrate($tvakey,1).$tvacompl;
1206
-						$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1204
+						$totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
1205
+						$totalvat .= vatrate($tvakey, 1).$tvacompl;
1206
+						$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1207 1207
 
1208 1208
 						$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1209 1209
 						$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
@@ -1213,11 +1213,11 @@  discard block
 block discarded – undo
1213 1213
 				//Local tax 1 after VAT
1214 1214
 				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1215 1215
 				//{
1216
-					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1216
+					foreach ($this->localtax1 as $localtax_type => $localtax_rate)
1217 1217
 					{
1218
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1218
+						if (in_array((string) $localtax_type, array('2', '4', '6'))) continue;
1219 1219
 
1220
-						foreach( $localtax_rate as $tvakey => $tvaval )
1220
+						foreach ($localtax_rate as $tvakey => $tvaval)
1221 1221
 						{
1222 1222
 							if ($tvakey != 0)    // On affiche pas taux 0
1223 1223
 							{
@@ -1226,16 +1226,16 @@  discard block
 block discarded – undo
1226 1226
 								$index++;
1227 1227
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1228 1228
 
1229
-								$tvacompl='';
1230
-								if (preg_match('/\*/',$tvakey))
1229
+								$tvacompl = '';
1230
+								if (preg_match('/\*/', $tvakey))
1231 1231
 								{
1232
-									$tvakey=str_replace('*','',$tvakey);
1232
+									$tvakey = str_replace('*', '', $tvakey);
1233 1233
 									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1234 1234
 								}
1235
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1235
+								$totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
1236 1236
 
1237
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1238
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1237
+								$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1238
+								$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1239 1239
 								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1240 1240
 								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1241 1241
 							}
@@ -1245,11 +1245,11 @@  discard block
 block discarded – undo
1245 1245
 				//Local tax 2 after VAT
1246 1246
 				//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1247 1247
 				//{
1248
-					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1248
+					foreach ($this->localtax2 as $localtax_type => $localtax_rate)
1249 1249
 					{
1250
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1250
+						if (in_array((string) $localtax_type, array('2', '4', '6'))) continue;
1251 1251
 
1252
-						foreach( $localtax_rate as $tvakey => $tvaval )
1252
+						foreach ($localtax_rate as $tvakey => $tvaval)
1253 1253
 						{
1254 1254
 						    // retrieve global local tax
1255 1255
 							if ($tvakey != 0)    // On affiche pas taux 0
@@ -1259,16 +1259,16 @@  discard block
 block discarded – undo
1259 1259
 								$index++;
1260 1260
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1261 1261
 
1262
-								$tvacompl='';
1263
-								if (preg_match('/\*/',$tvakey))
1262
+								$tvacompl = '';
1263
+								if (preg_match('/\*/', $tvakey))
1264 1264
 								{
1265
-									$tvakey=str_replace('*','',$tvakey);
1265
+									$tvakey = str_replace('*', '', $tvakey);
1266 1266
 									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1267 1267
 								}
1268
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1268
+								$totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1269 1269
 
1270
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1271
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1270
+								$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1271
+								$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1272 1272
 
1273 1273
 								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1274 1274
 								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
@@ -1280,16 +1280,16 @@  discard block
 block discarded – undo
1280 1280
 				// Total TTC
1281 1281
 				$index++;
1282 1282
 				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1283
-				$pdf->SetTextColor(0,0,60);
1284
-				$pdf->SetFillColor(224,224,224);
1285
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1283
+				$pdf->SetTextColor(0, 0, 60);
1284
+				$pdf->SetFillColor(224, 224, 224);
1285
+				$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1286 1286
 
1287 1287
 				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1288 1288
 				$pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1289 1289
 			}
1290 1290
 		}
1291 1291
 
1292
-		$pdf->SetTextColor(0,0,0);
1292
+		$pdf->SetTextColor(0, 0, 0);
1293 1293
 
1294 1294
 		/*
1295 1295
 		$resteapayer = $object->total_ttc - $deja_regle;
@@ -1301,7 +1301,7 @@  discard block
 block discarded – undo
1301 1301
 			$index++;
1302 1302
 
1303 1303
 			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1304
-			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
1304
+			$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
1305 1305
 
1306 1306
 			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1307 1307
 			$pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
@@ -1323,16 +1323,16 @@  discard block
 block discarded – undo
1323 1323
 			*/
1324 1324
 
1325 1325
 			$index++;
1326
-			$pdf->SetTextColor(0,0,60);
1327
-			$pdf->SetFillColor(224,224,224);
1326
+			$pdf->SetTextColor(0, 0, 60);
1327
+			$pdf->SetFillColor(224, 224, 224);
1328 1328
 			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1329
-			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1329
+			$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1330 1330
 
1331 1331
 			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1332 1332
 			$pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1333 1333
 
1334
-			$pdf->SetFont('','', $default_font_size - 1);
1335
-			$pdf->SetTextColor(0,0,0);
1334
+			$pdf->SetFont('', '', $default_font_size - 1);
1335
+			$pdf->SetTextColor(0, 0, 0);
1336 1336
 		}
1337 1337
 
1338 1338
 		$index++;
@@ -1352,61 +1352,61 @@  discard block
 block discarded – undo
1352 1352
 	 *   @param		string		$currency		Currency code
1353 1353
 	 *   @return	void
1354 1354
 	 */
1355
-	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
1355
+	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1356 1356
 	{
1357 1357
 		global $conf;
1358 1358
 
1359 1359
 		// Force to disable hidetop and hidebottom
1360
-		$hidebottom=0;
1361
-		if ($hidetop) $hidetop=-1;
1360
+		$hidebottom = 0;
1361
+		if ($hidetop) $hidetop = -1;
1362 1362
 
1363 1363
 		$currency = !empty($currency) ? $currency : $conf->currency;
1364 1364
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
1365 1365
 
1366 1366
 		// Amount in (at tab_top - 1)
1367
-		$pdf->SetTextColor(0,0,0);
1368
-		$pdf->SetFont('','', $default_font_size - 2);
1367
+		$pdf->SetTextColor(0, 0, 0);
1368
+		$pdf->SetFont('', '', $default_font_size - 2);
1369 1369
 
1370 1370
 		if (empty($hidetop))
1371 1371
 		{
1372
-			$titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
1373
-			$pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
1372
+			$titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1373
+			$pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1374 1374
 			$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1375 1375
 
1376 1376
 			//$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1377
-			if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1377
+			if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1378 1378
 		}
1379 1379
 
1380
-		$pdf->SetDrawColor(128,128,128);
1381
-		$pdf->SetFont('','', $default_font_size - 1);
1380
+		$pdf->SetDrawColor(128, 128, 128);
1381
+		$pdf->SetFont('', '', $default_font_size - 1);
1382 1382
 
1383 1383
 		// Output Rect
1384
-		$this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom);	// Rect prend une longueur en 3eme param et 4eme param
1384
+		$this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect prend une longueur en 3eme param et 4eme param
1385 1385
 
1386 1386
 
1387 1387
 		foreach ($this->cols as $colKey => $colDef)
1388 1388
 		{
1389
-		    if(!$this->getColumnStatus($colKey)) continue;
1389
+		    if (!$this->getColumnStatus($colKey)) continue;
1390 1390
 
1391 1391
 		    // get title label
1392
-		    $colDef['title']['label'] = !empty($colDef['title']['label'])?$colDef['title']['label']:$outputlangs->transnoentities($colDef['title']['textkey']);
1392
+		    $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
1393 1393
 
1394 1394
 		    // Add column separator
1395
-		    if(!empty($colDef['border-left'])){
1395
+		    if (!empty($colDef['border-left'])) {
1396 1396
 		        $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
1397 1397
 		    }
1398 1398
 
1399 1399
 		    if (empty($hidetop))
1400 1400
 		    {
1401
-		      $pdf->SetXY($colDef['xStartPos'] + $colDef['title']['padding'][3], $tab_top + $colDef['title']['padding'][0] );
1401
+		      $pdf->SetXY($colDef['xStartPos'] + $colDef['title']['padding'][3], $tab_top + $colDef['title']['padding'][0]);
1402 1402
 
1403
-		      $textWidth = $colDef['width'] - $colDef['title']['padding'][3] -$colDef['title']['padding'][1];
1404
-		      $pdf->MultiCell($textWidth,2,$colDef['title']['label'],'',$colDef['title']['align']);
1403
+		      $textWidth = $colDef['width'] - $colDef['title']['padding'][3] - $colDef['title']['padding'][1];
1404
+		      $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $colDef['title']['align']);
1405 1405
 		    }
1406 1406
 		}
1407 1407
 
1408
-		if (empty($hidetop)){
1409
-			$pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);	// line prend une position y en 2eme param et 4eme param
1408
+		if (empty($hidetop)) {
1409
+			$pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5); // line prend une position y en 2eme param et 4eme param
1410 1410
 		}
1411 1411
 	}
1412 1412
 
@@ -1421,7 +1421,7 @@  discard block
 block discarded – undo
1421 1421
 	 */
1422 1422
 	function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1423 1423
 	{
1424
-		global $conf,$langs;
1424
+		global $conf, $langs;
1425 1425
 
1426 1426
 		$outputlangs->load("main");
1427 1427
 		$outputlangs->load("bills");
@@ -1430,106 +1430,106 @@  discard block
 block discarded – undo
1430 1430
 
1431 1431
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
1432 1432
 
1433
-		pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1433
+		pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
1434 1434
 
1435 1435
 		//  Show Draft Watermark
1436
-		if($object->statut==0 && (! empty($conf->global->PROPALE_DRAFT_WATERMARK)) )
1436
+		if ($object->statut == 0 && (!empty($conf->global->PROPALE_DRAFT_WATERMARK)))
1437 1437
 		{
1438
-            pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->PROPALE_DRAFT_WATERMARK);
1438
+            pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->PROPALE_DRAFT_WATERMARK);
1439 1439
 		}
1440 1440
 
1441
-		$pdf->SetTextColor(0,0,60);
1442
-		$pdf->SetFont('','B', $default_font_size + 3);
1441
+		$pdf->SetTextColor(0, 0, 60);
1442
+		$pdf->SetFont('', 'B', $default_font_size + 3);
1443 1443
 
1444
-		$posy=$this->marge_haute;
1445
-		$posx=$this->page_largeur-$this->marge_droite-100;
1444
+		$posy = $this->marge_haute;
1445
+		$posx = $this->page_largeur - $this->marge_droite - 100;
1446 1446
 
1447
-		$pdf->SetXY($this->marge_gauche,$posy);
1447
+		$pdf->SetXY($this->marge_gauche, $posy);
1448 1448
 
1449 1449
 		// Logo
1450 1450
 		if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO))
1451 1451
 		{
1452
-			$logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1452
+			$logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1453 1453
 			if ($this->emetteur->logo)
1454 1454
 			{
1455 1455
 				if (is_readable($logo))
1456 1456
 				{
1457
-				    $height=pdf_getHeightForLogo($logo);
1458
-				    $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
1457
+				    $height = pdf_getHeightForLogo($logo);
1458
+				    $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1459 1459
 				}
1460 1460
 				else
1461 1461
 				{
1462
-					$pdf->SetTextColor(200,0,0);
1463
-					$pdf->SetFont('','B',$default_font_size - 2);
1464
-					$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1462
+					$pdf->SetTextColor(200, 0, 0);
1463
+					$pdf->SetFont('', 'B', $default_font_size - 2);
1464
+					$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1465 1465
 					$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1466 1466
 				}
1467 1467
 			}
1468 1468
 			else
1469 1469
 			{
1470
-				$text=$this->emetteur->name;
1470
+				$text = $this->emetteur->name;
1471 1471
 				$pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1472 1472
 			}
1473 1473
 		}
1474 1474
 
1475
-		$pdf->SetFont('','B',$default_font_size + 3);
1476
-		$pdf->SetXY($posx,$posy);
1477
-		$pdf->SetTextColor(0,0,60);
1478
-		$title=$outputlangs->transnoentities("PdfCommercialProposalTitle");
1475
+		$pdf->SetFont('', 'B', $default_font_size + 3);
1476
+		$pdf->SetXY($posx, $posy);
1477
+		$pdf->SetTextColor(0, 0, 60);
1478
+		$title = $outputlangs->transnoentities("PdfCommercialProposalTitle");
1479 1479
 		$pdf->MultiCell(100, 4, $title, '', 'R');
1480 1480
 
1481
-		$pdf->SetFont('','B',$default_font_size);
1481
+		$pdf->SetFont('', 'B', $default_font_size);
1482 1482
 
1483
-		$posy+=5;
1484
-		$pdf->SetXY($posx,$posy);
1485
-		$pdf->SetTextColor(0,0,60);
1486
-		$pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
1483
+		$posy += 5;
1484
+		$pdf->SetXY($posx, $posy);
1485
+		$pdf->SetTextColor(0, 0, 60);
1486
+		$pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
1487 1487
 
1488
-		$posy+=1;
1489
-		$pdf->SetFont('','', $default_font_size - 2);
1488
+		$posy += 1;
1489
+		$pdf->SetFont('', '', $default_font_size - 2);
1490 1490
 
1491 1491
 		if ($object->ref_client)
1492 1492
 		{
1493
-			$posy+=4;
1494
-			$pdf->SetXY($posx,$posy);
1495
-			$pdf->SetTextColor(0,0,60);
1496
-			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1493
+			$posy += 4;
1494
+			$pdf->SetXY($posx, $posy);
1495
+			$pdf->SetTextColor(0, 0, 60);
1496
+			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1497 1497
 		}
1498 1498
 
1499
-		$posy+=4;
1500
-		$pdf->SetXY($posx,$posy);
1501
-		$pdf->SetTextColor(0,0,60);
1502
-		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date,"day",false,$outputlangs,true), '', 'R');
1499
+		$posy += 4;
1500
+		$pdf->SetXY($posx, $posy);
1501
+		$pdf->SetTextColor(0, 0, 60);
1502
+		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
1503 1503
 
1504
-		$posy+=4;
1505
-		$pdf->SetXY($posx,$posy);
1506
-		$pdf->SetTextColor(0,0,60);
1507
-		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateEndPropal")." : " . dol_print_date($object->fin_validite,"day",false,$outputlangs,true), '', 'R');
1504
+		$posy += 4;
1505
+		$pdf->SetXY($posx, $posy);
1506
+		$pdf->SetTextColor(0, 0, 60);
1507
+		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateEndPropal")." : ".dol_print_date($object->fin_validite, "day", false, $outputlangs, true), '', 'R');
1508 1508
 
1509 1509
 		if ($object->thirdparty->code_client)
1510 1510
 		{
1511
-			$posy+=4;
1512
-			$pdf->SetXY($posx,$posy);
1513
-			$pdf->SetTextColor(0,0,60);
1514
-			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1511
+			$posy += 4;
1512
+			$pdf->SetXY($posx, $posy);
1513
+			$pdf->SetTextColor(0, 0, 60);
1514
+			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1515 1515
 		}
1516 1516
 
1517 1517
 		// Get contact
1518 1518
 		if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1519 1519
 		{
1520
-		    $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1520
+		    $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1521 1521
 		    if (count($arrayidcontact) > 0)
1522 1522
 		    {
1523
-		        $usertmp=new User($this->db);
1523
+		        $usertmp = new User($this->db);
1524 1524
 		        $usertmp->fetch($arrayidcontact[0]);
1525
-                $posy+=4;
1526
-                $pdf->SetXY($posx,$posy);
1527
-		        $pdf->SetTextColor(0,0,60);
1525
+                $posy += 4;
1526
+                $pdf->SetXY($posx, $posy);
1527
+		        $pdf->SetTextColor(0, 0, 60);
1528 1528
 		        $pdf->MultiCell(100, 3, $langs->trans("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1529 1529
 		    }
1530 1530
 		}
1531 1531
 
1532
-		$posy+=2;
1532
+		$posy += 2;
1533 1533
 
1534 1534
 		$top_shift = 0;
1535 1535
 		// Show list of linked objects
@@ -1543,53 +1543,53 @@  discard block
 block discarded – undo
1543 1543
 		if ($showaddress)
1544 1544
 		{
1545 1545
 			// Sender properties
1546
-			$carac_emetteur='';
1546
+			$carac_emetteur = '';
1547 1547
 		 	// Add internal contact of proposal if defined
1548
-			$arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1548
+			$arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1549 1549
 		 	if (count($arrayidcontact) > 0)
1550 1550
 		 	{
1551 1551
 		 		$object->fetch_user($arrayidcontact[0]);
1552
-		 		$labelbeforecontactname=($outputlangs->transnoentities("FromContactName")!='FromContactName'?$outputlangs->transnoentities("FromContactName"):$outputlangs->transnoentities("Name"));
1553
-		 		$carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1552
+		 		$labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
1553
+		 		$carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1554 1554
 		 	}
1555 1555
 
1556 1556
 		 	$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1557 1557
 
1558 1558
 			// Show sender
1559
-			$posy=42+$top_shift;
1560
-		 	$posx=$this->marge_gauche;
1561
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1562
-			$hautcadre=40;
1559
+			$posy = 42 + $top_shift;
1560
+		 	$posx = $this->marge_gauche;
1561
+			if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->page_largeur - $this->marge_droite - 80;
1562
+			$hautcadre = 40;
1563 1563
 
1564 1564
 			// Show sender frame
1565
-			$pdf->SetTextColor(0,0,0);
1566
-			$pdf->SetFont('','', $default_font_size - 2);
1567
-			$pdf->SetXY($posx,$posy-5);
1568
-			$pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1569
-			$pdf->SetXY($posx,$posy);
1570
-			$pdf->SetFillColor(230,230,230);
1565
+			$pdf->SetTextColor(0, 0, 0);
1566
+			$pdf->SetFont('', '', $default_font_size - 2);
1567
+			$pdf->SetXY($posx, $posy - 5);
1568
+			$pdf->MultiCell(66, 5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1569
+			$pdf->SetXY($posx, $posy);
1570
+			$pdf->SetFillColor(230, 230, 230);
1571 1571
 			$pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1572
-			$pdf->SetTextColor(0,0,60);
1572
+			$pdf->SetTextColor(0, 0, 60);
1573 1573
 
1574 1574
 			// Show sender name
1575
-			$pdf->SetXY($posx+2,$posy+3);
1576
-			$pdf->SetFont('','B', $default_font_size);
1575
+			$pdf->SetXY($posx + 2, $posy + 3);
1576
+			$pdf->SetFont('', 'B', $default_font_size);
1577 1577
 			$pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1578
-			$posy=$pdf->getY();
1578
+			$posy = $pdf->getY();
1579 1579
 
1580 1580
 			// Show sender information
1581
-			$pdf->SetXY($posx+2,$posy);
1582
-			$pdf->SetFont('','', $default_font_size - 1);
1581
+			$pdf->SetXY($posx + 2, $posy);
1582
+			$pdf->SetFont('', '', $default_font_size - 1);
1583 1583
 			$pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1584 1584
 
1585 1585
 
1586 1586
 			// If CUSTOMER contact defined, we use it
1587
-			$usecontact=false;
1588
-			$arrayidcontact=$object->getIdContact('external','CUSTOMER');
1587
+			$usecontact = false;
1588
+			$arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
1589 1589
 			if (count($arrayidcontact) > 0)
1590 1590
 			{
1591
-				$usecontact=true;
1592
-				$result=$object->fetch_contact($arrayidcontact[0]);
1591
+				$usecontact = true;
1592
+				$result = $object->fetch_contact($arrayidcontact[0]);
1593 1593
 			}
1594 1594
 
1595 1595
 			//Recipient name
@@ -1600,38 +1600,38 @@  discard block
 block discarded – undo
1600 1600
 				$thirdparty = $object->thirdparty;
1601 1601
 			}
1602 1602
 
1603
-			$carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
1603
+			$carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1604 1604
 
1605
-			$carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target',$object);
1605
+			$carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, 'target', $object);
1606 1606
 
1607 1607
 			// Show recipient
1608
-			$widthrecbox=100;
1609
-			if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1610
-			$posy=42+$top_shift;
1611
-			$posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1612
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1608
+			$widthrecbox = 100;
1609
+			if ($this->page_largeur < 210) $widthrecbox = 84; // To work with US executive format
1610
+			$posy = 42 + $top_shift;
1611
+			$posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1612
+			if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->marge_gauche;
1613 1613
 
1614 1614
 			// Show recipient frame
1615
-			$pdf->SetTextColor(0,0,0);
1616
-			$pdf->SetFont('','', $default_font_size - 2);
1617
-			$pdf->SetXY($posx+2,$posy-5);
1615
+			$pdf->SetTextColor(0, 0, 0);
1616
+			$pdf->SetFont('', '', $default_font_size - 2);
1617
+			$pdf->SetXY($posx + 2, $posy - 5);
1618 1618
 			$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":", 0, 'L');
1619 1619
 			$pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1620 1620
 
1621 1621
 			// Show recipient name
1622
-			$pdf->SetXY($posx+2,$posy+3);
1623
-			$pdf->SetFont('','B', $default_font_size);
1622
+			$pdf->SetXY($posx + 2, $posy + 3);
1623
+			$pdf->SetFont('', 'B', $default_font_size);
1624 1624
 			$pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1625 1625
 
1626 1626
 			$posy = $pdf->getY();
1627 1627
 
1628 1628
 			// Show recipient information
1629
-			$pdf->SetFont('','', $default_font_size - 1);
1630
-			$pdf->SetXY($posx+2,$posy);
1629
+			$pdf->SetFont('', '', $default_font_size - 1);
1630
+			$pdf->SetXY($posx + 2, $posy);
1631 1631
 			$pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1632 1632
 		}
1633 1633
 
1634
-		$pdf->SetTextColor(0,0,0);
1634
+		$pdf->SetTextColor(0, 0, 0);
1635 1635
 		return $top_shift;
1636 1636
 	}
1637 1637
 
@@ -1644,11 +1644,11 @@  discard block
 block discarded – undo
1644 1644
 	 *      @param	int			$hidefreetext		1=Hide free text
1645 1645
 	 *      @return	int								Return height of bottom margin including footer text
1646 1646
 	 */
1647
-	function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1647
+	function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1648 1648
 	{
1649 1649
 		global $conf;
1650
-		$showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1651
-		return pdf_pagefoot($pdf,$outputlangs,'PROPOSAL_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1650
+		$showdetails = $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1651
+		return pdf_pagefoot($pdf, $outputlangs, 'PROPOSAL_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1652 1652
 	}
1653 1653
 
1654 1654
 	/**
@@ -1669,21 +1669,21 @@  discard block
 block discarded – undo
1669 1669
 
1670 1670
 		$posx = 120;
1671 1671
 		$largcol = ($this->page_largeur - $this->marge_droite - $posx);
1672
-		$useborder=0;
1672
+		$useborder = 0;
1673 1673
 		$index = 0;
1674 1674
 		// Total HT
1675
-		$pdf->SetFillColor(255,255,255);
1675
+		$pdf->SetFillColor(255, 255, 255);
1676 1676
 		$pdf->SetXY($posx, $tab_top + 0);
1677
-		$pdf->SetFont('','', $default_font_size - 2);
1677
+		$pdf->SetFont('', '', $default_font_size - 2);
1678 1678
 		$pdf->MultiCell($largcol, $tab_hl, $outputlangs->transnoentities("ProposalCustomerSignature"), 0, 'L', 1);
1679 1679
 
1680 1680
 		$pdf->SetXY($posx, $tab_top + $tab_hl);
1681
-		$pdf->MultiCell($largcol, $tab_hl*3, '', 1, 'R');
1682
-		if (! empty($conf->global->MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING)) {
1683
-			$pdf->addEmptySignatureAppearance($posx, $tab_top + $tab_hl, $largcol, $tab_hl*3);
1681
+		$pdf->MultiCell($largcol, $tab_hl * 3, '', 1, 'R');
1682
+		if (!empty($conf->global->MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING)) {
1683
+			$pdf->addEmptySignatureAppearance($posx, $tab_top + $tab_hl, $largcol, $tab_hl * 3);
1684 1684
 		}
1685 1685
 
1686
-		return ($tab_hl*7);
1686
+		return ($tab_hl * 7);
1687 1687
 	}
1688 1688
 
1689 1689
 
@@ -1697,20 +1697,20 @@  discard block
 block discarded – undo
1697 1697
 	 *      @param	int				$hideref		Do not show ref
1698 1698
 	 *      @return	null
1699 1699
 	 */
1700
-    function defineColumnField($object,$outputlangs,$hidedetails=0,$hidedesc=0,$hideref=0)
1700
+    function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1701 1701
     {
1702 1702
 	    global $conf, $hookmanager;
1703 1703
 
1704 1704
 	    // Default field style for content
1705 1705
 	    $this->defaultContentsFieldsStyle = array(
1706 1706
 	        'align' => 'R', // R,C,L
1707
-	        'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1707
+	        'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1708 1708
 	    );
1709 1709
 
1710 1710
 	    // Default field style for content
1711 1711
 	    $this->defaultTitlesFieldsStyle = array(
1712 1712
 	        'align' => 'C', // R,C,L
1713
-	        'padding' => array(0.5,0,0.5,0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1713
+	        'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1714 1714
 	    );
1715 1715
 
1716 1716
 	    /*
@@ -1731,7 +1731,7 @@  discard block
 block discarded – undo
1731 1731
 	     );
1732 1732
 	     */
1733 1733
 
1734
-	    $rank=0; // do not use negative rank
1734
+	    $rank = 0; // do not use negative rank
1735 1735
 	    $this->cols['desc'] = array(
1736 1736
 	        'rank' => $rank,
1737 1737
 	        'width' => false, // only for desc
@@ -1741,7 +1741,7 @@  discard block
 block discarded – undo
1741 1741
 	            'align' => 'L',
1742 1742
 	            // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1743 1743
 	            // 'label' => ' ', // the final label
1744
-	            'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1744
+	            'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1745 1745
 	        ),
1746 1746
 	        'content' => array(
1747 1747
 	            'align' => 'L',
@@ -1751,19 +1751,19 @@  discard block
 block discarded – undo
1751 1751
 	    $rank = $rank + 10;
1752 1752
 	    $this->cols['photo'] = array(
1753 1753
 	        'rank' => $rank,
1754
-	        'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
1754
+	        'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
1755 1755
 	        'status' => false,
1756 1756
 	        'title' => array(
1757 1757
 	            'textkey' => 'Photo',
1758 1758
 	            'label' => ' '
1759 1759
 	        ),
1760 1760
 	        'content' => array(
1761
-	            'padding' => array(0,0,0,0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1761
+	            'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1762 1762
 	        ),
1763 1763
 	        'border-left' => false, // remove left line separator
1764 1764
 	    );
1765 1765
 
1766
-	    if (! empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE) && !empty($this->atleastonephoto))
1766
+	    if (!empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE) && !empty($this->atleastonephoto))
1767 1767
 	    {
1768 1768
 	        $this->cols['photo']['status'] = true;
1769 1769
 	    }
@@ -1818,7 +1818,7 @@  discard block
 block discarded – undo
1818 1818
 	        'border-left' => false, // add left line separator
1819 1819
 	    );
1820 1820
 
1821
-	    if($this->situationinvoice)
1821
+	    if ($this->situationinvoice)
1822 1822
 	    {
1823 1823
 	        $this->cols['progress']['status'] = true;
1824 1824
 	    }
@@ -1833,7 +1833,7 @@  discard block
 block discarded – undo
1833 1833
 	        ),
1834 1834
 	        'border-left' => true, // add left line separator
1835 1835
 	    );
1836
-	    if($conf->global->PRODUCT_USE_UNITS){
1836
+	    if ($conf->global->PRODUCT_USE_UNITS) {
1837 1837
 	        $this->cols['unit']['status'] = true;
1838 1838
 	    }
1839 1839
 
@@ -1847,7 +1847,7 @@  discard block
 block discarded – undo
1847 1847
 	        ),
1848 1848
 	        'border-left' => true, // add left line separator
1849 1849
 	    );
1850
-	    if ($this->atleastonediscount){
1850
+	    if ($this->atleastonediscount) {
1851 1851
 	        $this->cols['discount']['status'] = true;
1852 1852
 	    }
1853 1853
 
@@ -1863,7 +1863,7 @@  discard block
 block discarded – undo
1863 1863
 	    );
1864 1864
 
1865 1865
 
1866
-	    $parameters=array(
1866
+	    $parameters = array(
1867 1867
 	        'object' => $object,
1868 1868
 	        'outputlangs' => $outputlangs,
1869 1869
 	        'hidedetails' => $hidedetails,
@@ -1871,7 +1871,7 @@  discard block
 block discarded – undo
1871 1871
 	        'hideref' => $hideref
1872 1872
 	    );
1873 1873
 
1874
-	    $reshook=$hookmanager->executeHooks('defineColumnField',$parameters,$this);    // Note that $object may have been modified by hook
1874
+	    $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
1875 1875
 	    if ($reshook < 0)
1876 1876
 	    {
1877 1877
 	        setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
Please login to merge, or discard this patch.
Braces   +199 added lines, -103 removed lines patch added patch discarded remove patch
@@ -104,7 +104,10 @@  discard block
 block discarded – undo
104 104
 
105 105
 		// Get source company
106 106
 		$this->emetteur=$mysoc;
107
-		if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
107
+		if (empty($this->emetteur->country_code)) {
108
+		    $this->emetteur->country_code=substr($langs->defaultlang,-2);
109
+		}
110
+		// By default, if was not defined
108 111
 
109 112
 		// Define position of columns
110 113
 		$this->posxdesc=$this->marge_gauche+1;
@@ -135,9 +138,13 @@  discard block
 block discarded – undo
135 138
 	  // phpcs:enable
136 139
 		global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
137 140
 
138
-		if (! is_object($outputlangs)) $outputlangs=$langs;
141
+		if (! is_object($outputlangs)) {
142
+		    $outputlangs=$langs;
143
+		}
139 144
 		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
140
-		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
145
+		if (! empty($conf->global->MAIN_USE_FPDF)) {
146
+		    $outputlangs->charset_output='ISO-8859-1';
147
+		}
141 148
 
142 149
 		$outputlangs->load("main");
143 150
 		$outputlangs->load("dict");
@@ -157,7 +164,9 @@  discard block
 block discarded – undo
157 164
 
158 165
 			for ($i = 0 ; $i < $nblignes ; $i++)
159 166
 			{
160
-				if (empty($object->lines[$i]->fk_product)) continue;
167
+				if (empty($object->lines[$i]->fk_product)) {
168
+				    continue;
169
+				}
161 170
 
162 171
 				$objphoto->fetch($object->lines[$i]->fk_product);
163 172
                 //var_dump($objphoto->ref);exit;
@@ -165,8 +174,7 @@  discard block
 block discarded – undo
165 174
 				{
166 175
 					$pdir[0] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";
167 176
 					$pdir[1] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';
168
-				}
169
-				else
177
+				} else
170 178
 				{
171 179
 					$pdir[0] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';				// default
172 180
 					$pdir[1] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";	// alternative
@@ -181,18 +189,18 @@  discard block
 block discarded – undo
181 189
 
182 190
 						foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
183 191
 						{
184
-							if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES))		// If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
192
+							if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) {
193
+							    // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
185 194
 							{
186 195
 								if ($obj['photo_vignette'])
187 196
 								{
188 197
 									$filename= $obj['photo_vignette'];
189
-								}
190
-								else
198
+							}
199
+								} else
191 200
 								{
192 201
 									$filename=$obj['photo'];
193 202
 								}
194
-							}
195
-							else
203
+							} else
196 204
 							{
197 205
 								$filename=$obj['photo'];
198 206
 							}
@@ -204,11 +212,15 @@  discard block
 block discarded – undo
204 212
 					}
205 213
 				}
206 214
 
207
-				if ($realpath && $arephoto) $realpatharray[$i]=$realpath;
215
+				if ($realpath && $arephoto) {
216
+				    $realpatharray[$i]=$realpath;
217
+				}
208 218
 			}
209 219
 		}
210 220
 
211
-		if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
221
+		if (count($realpatharray) == 0) {
222
+		    $this->posxpicture=$this->posxtva;
223
+		}
212 224
 
213 225
 		if ($conf->propal->multidir_output[$conf->entity])
214 226
 		{
@@ -221,8 +233,7 @@  discard block
 block discarded – undo
221 233
 			{
222 234
 				$dir = $conf->propal->multidir_output[$conf->entity];
223 235
 				$file = $dir . "/SPECIMEN.pdf";
224
-			}
225
-			else
236
+			} else
226 237
 			{
227 238
 				$objectref = dol_sanitizeFileName($object->ref);
228 239
 				$dir = $conf->propal->multidir_output[$object->entity] . "/" . $objectref;
@@ -278,7 +289,9 @@  discard block
 block discarded – undo
278 289
 				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
279 290
 				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
280 291
 				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfCommercialProposalTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
281
-				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
292
+				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
293
+				    $pdf->SetCompression(false);
294
+				}
282 295
 
283 296
 				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
284 297
 
@@ -294,7 +307,9 @@  discard block
 block discarded – undo
294 307
 
295 308
 				// New page
296 309
 				$pdf->AddPage();
297
-				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
310
+				if (! empty($tplidx)) {
311
+				    $pdf->useTemplate($tplidx);
312
+				}
298 313
 				$pagenb++;
299 314
 
300 315
                 $heightforinfotot = 40;	// Height reserved to output the info and total part
@@ -345,7 +360,9 @@  discard block
 block discarded – undo
345 360
 						$salereparray=$object->thirdparty->getSalesRepresentatives($user);
346 361
 						$salerepobj=new User($this->db);
347 362
 						$salerepobj->fetch($salereparray[0]['id']);
348
-						if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
363
+						if (! empty($salerepobj->signature)) {
364
+						    $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
365
+						}
349 366
 					}
350 367
 				}
351 368
 				if (! empty($conf->global->MAIN_ADD_CREATOR_IN_NOTE) && $object->user_author_id > 0)
@@ -353,8 +370,12 @@  discard block
 block discarded – undo
353 370
 				    $tmpuser=new User($this->db);
354 371
 				    $tmpuser->fetch($object->user_author_id);
355 372
 				    $notetoshow.='Affaire suivi par '.$tmpuser->getFullName($langs);
356
-				    if ($tmpuser->email) $notetoshow.=',  Mail: '.$tmpuser->email;
357
-				    if ($tmpuser->office_phone) $notetoshow.=', Tel: '.$tmpuser->office_phone;
373
+				    if ($tmpuser->email) {
374
+				        $notetoshow.=',  Mail: '.$tmpuser->email;
375
+				    }
376
+				    if ($tmpuser->office_phone) {
377
+				        $notetoshow.=', Tel: '.$tmpuser->office_phone;
378
+				    }
358 379
 				}
359 380
 
360 381
 				$pagenb = $pdf->getPage();
@@ -386,8 +407,12 @@  discard block
 block discarded – undo
386 407
 					    while ($pagenb < $pageposafternote) {
387 408
 					        $pdf->AddPage();
388 409
 					        $pagenb++;
389
-					        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
390
-					        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
410
+					        if (! empty($tplidx)) {
411
+					            $pdf->useTemplate($tplidx);
412
+					        }
413
+					        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
414
+					            $this->_pagehead($pdf, $object, 0, $outputlangs);
415
+					        }
391 416
 					        // $this->_pagefoot($pdf,$object,$outputlangs,1);
392 417
 					        $pdf->setTopMargin($tab_top_newpage);
393 418
 					        // The only function to edit the bottom margin of current page to set it.
@@ -403,9 +428,11 @@  discard block
 block discarded – undo
403 428
 
404 429
 					    $posyafter = $pdf->GetY();
405 430
 
406
-					    if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20)))	// There is no space left for total+free text
431
+					    if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20))) {
432
+					        // There is no space left for total+free text
407 433
 					    {
408 434
 					        $pdf->AddPage('','',true);
435
+					    }
409 436
 					        $pagenb++;
410 437
 					        $pageposafternote++;
411 438
 					        $pdf->setPage($pageposafternote);
@@ -427,8 +454,7 @@  discard block
 block discarded – undo
427 454
 					        if($i>$pageposbeforenote){
428 455
 					            $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
429 456
 					            $pdf->Rect($this->marge_gauche, $tab_top_newpage-1, $tab_width, $height_note + 1);
430
-					        }
431
-					        else{
457
+					        } else{
432 458
 					            $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
433 459
 					            $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note + 1);
434 460
 					        }
@@ -442,12 +468,15 @@  discard block
 block discarded – undo
442 468
 
443 469
 					    // apply note frame to last page
444 470
 					    $pdf->setPage($pageposafternote);
445
-					    if (! empty($tplidx)) $pdf->useTemplate($tplidx);
446
-					    if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
471
+					    if (! empty($tplidx)) {
472
+					        $pdf->useTemplate($tplidx);
473
+					    }
474
+					    if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
475
+					        $this->_pagehead($pdf, $object, 0, $outputlangs);
476
+					    }
447 477
 					    $height_note=$posyafter-$tab_top_newpage;
448 478
 					    $pdf->Rect($this->marge_gauche, $tab_top_newpage-1, $tab_width, $height_note+1);
449
-					}
450
-					else // No pagebreak
479
+					} else // No pagebreak
451 480
 					{
452 481
 					    $pdf->commitTransaction();
453 482
 					    $posyafter = $pdf->GetY();
@@ -462,8 +491,12 @@  discard block
 block discarded – undo
462 491
 					        $pagenb++;
463 492
 					        $pageposafternote++;
464 493
 					        $pdf->setPage($pageposafternote);
465
-					        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
466
-					        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
494
+					        if (! empty($tplidx)) {
495
+					            $pdf->useTemplate($tplidx);
496
+					        }
497
+					        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
498
+					            $this->_pagehead($pdf, $object, 0, $outputlangs);
499
+					        }
467 500
 
468 501
 					        $posyafter = $tab_top_newpage;
469 502
 					    }
@@ -471,8 +504,7 @@  discard block
 block discarded – undo
471 504
 
472 505
 					$tab_height = $tab_height - $height_note;
473 506
 					$tab_top = $posyafter +6;
474
-				}
475
-				else
507
+				} else
476 508
 				{
477 509
 					$height_note=0;
478 510
 				}
@@ -495,7 +527,9 @@  discard block
 block discarded – undo
495 527
 
496 528
 					// Define size of image if we need it
497 529
 					$imglinesize=array();
498
-					if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
530
+					if (! empty($realpatharray[$i])) {
531
+					    $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
532
+					}
499 533
 
500 534
 					$pdf->setTopMargin($tab_top_newpage);
501 535
 					$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
@@ -508,10 +542,14 @@  discard block
 block discarded – undo
508 542
 					if($this->getColumnStatus('photo'))
509 543
 					{
510 544
     					// We start with Photo of product line
511
-    					if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot)))	// If photo too high, we moved completely on new page
545
+    					if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot))) {
546
+    					    // If photo too high, we moved completely on new page
512 547
     					{
513 548
     						$pdf->AddPage('','',true);
514
-    						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
549
+    					}
550
+    						if (! empty($tplidx)) {
551
+    						    $pdf->useTemplate($tplidx);
552
+    						}
515 553
     						//if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
516 554
     						$pdf->setPage($pageposbefore+1);
517 555
 
@@ -534,9 +572,11 @@  discard block
 block discarded – undo
534 572
     					$pdf->startTransaction();
535 573
     					pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->getColumnContentWidth('desc'),3,$this->getColumnContentXStart('desc'),$curY,$hideref,$hidedesc);
536 574
     					$pageposafter=$pdf->getPage();
537
-    					if ($pageposafter > $pageposbefore)	// There is a pagebreak
575
+    					if ($pageposafter > $pageposbefore) {
576
+    					    // There is a pagebreak
538 577
     					{
539 578
     						$pdf->rollbackTransaction(true);
579
+    					}
540 580
     						$pageposafter=$pageposbefore;
541 581
     						//print $pageposafter.'-'.$pageposbefore;exit;
542 582
     						$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
@@ -545,23 +585,25 @@  discard block
 block discarded – undo
545 585
     						$pageposafter=$pdf->getPage();
546 586
     						$posyafter=$pdf->GetY();
547 587
     						//var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
548
-    						if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot)))	// There is no space left for total+free text
588
+    						if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot))) {
589
+    						    // There is no space left for total+free text
549 590
     						{
550 591
     							if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
551 592
     							{
552 593
     								$pdf->AddPage('','',true);
553
-    								if (! empty($tplidx)) $pdf->useTemplate($tplidx);
594
+    						}
595
+    								if (! empty($tplidx)) {
596
+    								    $pdf->useTemplate($tplidx);
597
+    								}
554 598
     								//if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
555 599
     								$pdf->setPage($pageposafter+1);
556 600
     							}
557
-    						}
558
-    						else
601
+    						} else
559 602
     						{
560 603
     							// We found a page break
561 604
     							$showpricebeforepagebreak=0;
562 605
     						}
563
-    					}
564
-    					else	// No pagebreak
606
+    					} else	// No pagebreak
565 607
     					{
566 608
     						$pdf->commitTransaction();
567 609
     					}
@@ -647,8 +689,11 @@  discard block
 block discarded – undo
647 689
 
648 690
 
649 691
 					// Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
650
-					if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
651
-					else $tvaligne=$object->lines[$i]->total_tva;
692
+					if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) {
693
+					    $tvaligne=$object->lines[$i]->multicurrency_total_tva;
694
+					} else {
695
+					    $tvaligne=$object->lines[$i]->total_tva;
696
+					}
652 697
 
653 698
 					$localtax1ligne=$object->lines[$i]->total_localtax1;
654 699
 					$localtax2ligne=$object->lines[$i]->total_localtax2;
@@ -657,32 +702,48 @@  discard block
 block discarded – undo
657 702
 					$localtax1_type=$object->lines[$i]->localtax1_type;
658 703
 					$localtax2_type=$object->lines[$i]->localtax2_type;
659 704
 
660
-					if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
661
-					if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
662
-					if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
705
+					if ($object->remise_percent) {
706
+					    $tvaligne-=($tvaligne*$object->remise_percent)/100;
707
+					}
708
+					if ($object->remise_percent) {
709
+					    $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
710
+					}
711
+					if ($object->remise_percent) {
712
+					    $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
713
+					}
663 714
 
664 715
 					$vatrate=(string) $object->lines[$i]->tva_tx;
665 716
 
666 717
 					// Retrieve type from database for backward compatibility with old records
667 718
 					if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
668
-					&& (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
719
+					&& (! empty($localtax1_rate) || ! empty($localtax2_rate))) {
720
+					    // and there is local tax
669 721
 					{
670 722
 						$localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc);
723
+					}
671 724
 						$localtax1_type = $localtaxtmp_array[0];
672 725
 						$localtax2_type = $localtaxtmp_array[2];
673 726
 					}
674 727
 
675 728
 				    // retrieve global local tax
676
-					if ($localtax1_type && $localtax1ligne != 0)
677
-						$this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
678
-					if ($localtax2_type && $localtax2ligne != 0)
679
-						$this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
729
+					if ($localtax1_type && $localtax1ligne != 0) {
730
+											$this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
731
+					}
732
+					if ($localtax2_type && $localtax2ligne != 0) {
733
+											$this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
734
+					}
680 735
 
681
-					if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
682
-					if (! isset($this->tva[$vatrate]))				$this->tva[$vatrate]=0;
736
+					if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
737
+					    $vatrate.='*';
738
+					}
739
+					if (! isset($this->tva[$vatrate])) {
740
+					    $this->tva[$vatrate]=0;
741
+					}
683 742
 					$this->tva[$vatrate] += $tvaligne;
684 743
 
685
-					if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
744
+					if ($posYAfterImage > $posYAfterDescription) {
745
+					    $nexY=$posYAfterImage;
746
+					}
686 747
 
687 748
 					// Add line
688 749
 					if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
@@ -703,8 +764,7 @@  discard block
 block discarded – undo
703 764
 						if ($pagenb == $pageposbeforeprintlines)
704 765
 						{
705 766
 							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
706
-						}
707
-						else
767
+						} else
708 768
 						{
709 769
 							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
710 770
 						}
@@ -712,24 +772,29 @@  discard block
 block discarded – undo
712 772
 						$pagenb++;
713 773
 						$pdf->setPage($pagenb);
714 774
 						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
715
-						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
775
+						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
776
+						    $this->_pagehead($pdf, $object, 0, $outputlangs);
777
+						}
716 778
 					}
717 779
 					if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
718 780
 					{
719 781
 					    if ($pagenb == $pageposafter)
720 782
 						{
721 783
 							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
722
-						}
723
-						else
784
+						} else
724 785
 						{
725 786
 							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
726 787
 						}
727 788
 						$this->_pagefoot($pdf,$object,$outputlangs,1);
728 789
 						// New page
729 790
 						$pdf->AddPage();
730
-						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
791
+						if (! empty($tplidx)) {
792
+						    $pdf->useTemplate($tplidx);
793
+						}
731 794
 						$pagenb++;
732
-						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
795
+						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
796
+						    $this->_pagehead($pdf, $object, 0, $outputlangs);
797
+						}
733 798
 					}
734 799
 				}
735 800
 
@@ -738,8 +803,7 @@  discard block
 block discarded – undo
738 803
 				{
739 804
 					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
740 805
 					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
741
-				}
742
-				else
806
+				} else
743 807
 				{
744 808
 					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
745 809
 					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
@@ -767,7 +831,9 @@  discard block
 block discarded – undo
767 831
 
768 832
 				// Pied de page
769 833
 				$this->_pagefoot($pdf,$object,$outputlangs);
770
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
834
+				if (method_exists($pdf,'AliasNbPages')) {
835
+				    $pdf->AliasNbPages();
836
+				}
771 837
 
772 838
 				//If propal merge product PDF is active
773 839
 				if (!empty($conf->global->PRODUIT_PDF_MERGE_PROPAL))
@@ -810,8 +876,7 @@  discard block
 block discarded – undo
810 876
 											} elseif (! empty($conf->service->enabled)) {
811 877
 												$filetomerge_dir = $conf->service->multidir_output[$entity_product_file] . '/' . get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos";
812 878
 											}
813
-										}
814
-										else
879
+										} else
815 880
 										{
816 881
 											if (! empty($conf->product->enabled)) {
817 882
 												$filetomerge_dir = $conf->product->multidir_output[$entity_product_file] . '/' . get_exdir(0,0,0,0,$product,'product') . dol_sanitizeFileName($product->ref);
@@ -853,20 +918,19 @@  discard block
 block discarded – undo
853 918
 				global $action;
854 919
 				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
855 920
 
856
-				if (! empty($conf->global->MAIN_UMASK))
857
-				@chmod($file, octdec($conf->global->MAIN_UMASK));
921
+				if (! empty($conf->global->MAIN_UMASK)) {
922
+								@chmod($file, octdec($conf->global->MAIN_UMASK));
923
+				}
858 924
 
859 925
 				$this->result = array('fullpath'=>$file);
860 926
 
861 927
 				return 1;   // Pas d'erreur
862
-			}
863
-			else
928
+			} else
864 929
 			{
865 930
 				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
866 931
 				return 0;
867 932
 			}
868
-		}
869
-		else
933
+		} else
870 934
 		{
871 935
 			$this->error=$langs->trans("ErrorConstantNotDefined","PROP_OUTPUTDIR");
872 936
 			return 0;
@@ -928,10 +992,11 @@  discard block
 block discarded – undo
928 992
 			$pdf->MultiCell(80, 4, $dlp, 0, 'L');
929 993
 
930 994
             $posy=$pdf->GetY()+1;
931
-		}
932
-        elseif ($object->availability_code || $object->availability)    // Show availability conditions
995
+		} elseif ($object->availability_code || $object->availability) {
996
+            // Show availability conditions
933 997
 		{
934 998
 			$pdf->SetFont('','B', $default_font_size - 2);
999
+        }
935 1000
 			$pdf->SetXY($this->marge_gauche, $posy);
936 1001
 			$titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
937 1002
 			$pdf->MultiCell(80, 4, $titre, 0, 'L');
@@ -1047,7 +1112,10 @@  discard block
 block discarded – undo
1047 1112
 				if (! empty($object->fk_account) || ! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
1048 1113
 				{
1049 1114
 					$bankid=(empty($object->fk_account)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_account);
1050
-					if (! empty($object->fk_bank)) $bankid=$object->fk_bank;   // For backward compatibility when object->fk_account is forced with object->fk_bank
1115
+					if (! empty($object->fk_bank)) {
1116
+					    $bankid=$object->fk_bank;
1117
+					}
1118
+					// For backward compatibility when object->fk_account is forced with object->fk_bank
1051 1119
 					$account = new Account($this->db);
1052 1120
 					$account->fetch($bankid);
1053 1121
 
@@ -1086,10 +1154,12 @@  discard block
 block discarded – undo
1086 1154
 
1087 1155
 		// Tableau total
1088 1156
 		$col1x = 120; $col2x = 170;
1089
-		if ($this->page_largeur < 210) // To work with US executive format
1157
+		if ($this->page_largeur < 210) {
1158
+		    // To work with US executive format
1090 1159
 		{
1091 1160
 			$col2x-=20;
1092 1161
 		}
1162
+		}
1093 1163
 		$largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1094 1164
 
1095 1165
 		$useborder=0;
@@ -1116,23 +1186,26 @@  discard block
 block discarded – undo
1116 1186
 			if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1117 1187
 			{
1118 1188
 				// Nothing to do
1119
-			}
1120
-			else
1189
+			} else
1121 1190
 			{
1122 1191
 				//Local tax 1 before VAT
1123 1192
 				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1124 1193
 				//{
1125 1194
 					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1126 1195
 					{
1127
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1196
+						if (in_array((string) $localtax_type, array('1','3','5'))) {
1197
+						    continue;
1198
+						}
1128 1199
 
1129 1200
 						foreach( $localtax_rate as $tvakey => $tvaval )
1130 1201
 						{
1131
-							if ($tvakey!=0)    // On affiche pas taux 0
1202
+							if ($tvakey!=0) {
1203
+							    // On affiche pas taux 0
1132 1204
 							{
1133 1205
 								//$this->atleastoneratenotnull++;
1134 1206
 
1135 1207
 								$index++;
1208
+							}
1136 1209
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1137 1210
 
1138 1211
 								$tvacompl='';
@@ -1156,17 +1229,21 @@  discard block
 block discarded – undo
1156 1229
 				//{
1157 1230
 					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1158 1231
 					{
1159
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1232
+						if (in_array((string) $localtax_type, array('1','3','5'))) {
1233
+						    continue;
1234
+						}
1160 1235
 
1161 1236
 						foreach( $localtax_rate as $tvakey => $tvaval )
1162 1237
 						{
1163
-							if ($tvakey!=0)    // On affiche pas taux 0
1238
+							if ($tvakey!=0) {
1239
+							    // On affiche pas taux 0
1164 1240
 							{
1165 1241
 								//$this->atleastoneratenotnull++;
1166 1242
 
1167 1243
 
1168 1244
 
1169 1245
 								$index++;
1246
+							}
1170 1247
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1171 1248
 
1172 1249
 								$tvacompl='';
@@ -1188,9 +1265,11 @@  discard block
 block discarded – undo
1188 1265
 				// VAT
1189 1266
 				foreach($this->tva as $tvakey => $tvaval)
1190 1267
 				{
1191
-					if ($tvakey != 0)    // On affiche pas taux 0
1268
+					if ($tvakey != 0) {
1269
+					    // On affiche pas taux 0
1192 1270
 					{
1193 1271
 						$this->atleastoneratenotnull++;
1272
+					}
1194 1273
 
1195 1274
 						$index++;
1196 1275
 						$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
@@ -1215,15 +1294,19 @@  discard block
 block discarded – undo
1215 1294
 				//{
1216 1295
 					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1217 1296
 					{
1218
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1297
+						if (in_array((string) $localtax_type, array('2','4','6'))) {
1298
+						    continue;
1299
+						}
1219 1300
 
1220 1301
 						foreach( $localtax_rate as $tvakey => $tvaval )
1221 1302
 						{
1222
-							if ($tvakey != 0)    // On affiche pas taux 0
1303
+							if ($tvakey != 0) {
1304
+							    // On affiche pas taux 0
1223 1305
 							{
1224 1306
 								//$this->atleastoneratenotnull++;
1225 1307
 
1226 1308
 								$index++;
1309
+							}
1227 1310
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1228 1311
 
1229 1312
 								$tvacompl='';
@@ -1247,16 +1330,20 @@  discard block
 block discarded – undo
1247 1330
 				//{
1248 1331
 					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1249 1332
 					{
1250
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1333
+						if (in_array((string) $localtax_type, array('2','4','6'))) {
1334
+						    continue;
1335
+						}
1251 1336
 
1252 1337
 						foreach( $localtax_rate as $tvakey => $tvaval )
1253 1338
 						{
1254 1339
 						    // retrieve global local tax
1255
-							if ($tvakey != 0)    // On affiche pas taux 0
1340
+							if ($tvakey != 0) {
1341
+							    // On affiche pas taux 0
1256 1342
 							{
1257 1343
 								//$this->atleastoneratenotnull++;
1258 1344
 
1259 1345
 								$index++;
1346
+							}
1260 1347
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1261 1348
 
1262 1349
 								$tvacompl='';
@@ -1358,7 +1445,9 @@  discard block
 block discarded – undo
1358 1445
 
1359 1446
 		// Force to disable hidetop and hidebottom
1360 1447
 		$hidebottom=0;
1361
-		if ($hidetop) $hidetop=-1;
1448
+		if ($hidetop) {
1449
+		    $hidetop=-1;
1450
+		}
1362 1451
 
1363 1452
 		$currency = !empty($currency) ? $currency : $conf->currency;
1364 1453
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
@@ -1374,7 +1463,9 @@  discard block
 block discarded – undo
1374 1463
 			$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1375 1464
 
1376 1465
 			//$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1377
-			if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1466
+			if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1467
+			    $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1468
+			}
1378 1469
 		}
1379 1470
 
1380 1471
 		$pdf->SetDrawColor(128,128,128);
@@ -1386,7 +1477,9 @@  discard block
 block discarded – undo
1386 1477
 
1387 1478
 		foreach ($this->cols as $colKey => $colDef)
1388 1479
 		{
1389
-		    if(!$this->getColumnStatus($colKey)) continue;
1480
+		    if(!$this->getColumnStatus($colKey)) {
1481
+		        continue;
1482
+		    }
1390 1483
 
1391 1484
 		    // get title label
1392 1485
 		    $colDef['title']['label'] = !empty($colDef['title']['label'])?$colDef['title']['label']:$outputlangs->transnoentities($colDef['title']['textkey']);
@@ -1456,16 +1549,14 @@  discard block
 block discarded – undo
1456 1549
 				{
1457 1550
 				    $height=pdf_getHeightForLogo($logo);
1458 1551
 				    $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
1459
-				}
1460
-				else
1552
+				} else
1461 1553
 				{
1462 1554
 					$pdf->SetTextColor(200,0,0);
1463 1555
 					$pdf->SetFont('','B',$default_font_size - 2);
1464 1556
 					$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1465 1557
 					$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1466 1558
 				}
1467
-			}
1468
-			else
1559
+			} else
1469 1560
 			{
1470 1561
 				$text=$this->emetteur->name;
1471 1562
 				$pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
@@ -1558,7 +1649,9 @@  discard block
 block discarded – undo
1558 1649
 			// Show sender
1559 1650
 			$posy=42+$top_shift;
1560 1651
 		 	$posx=$this->marge_gauche;
1561
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1652
+			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1653
+			    $posx=$this->page_largeur-$this->marge_droite-80;
1654
+			}
1562 1655
 			$hautcadre=40;
1563 1656
 
1564 1657
 			// Show sender frame
@@ -1606,10 +1699,15 @@  discard block
 block discarded – undo
1606 1699
 
1607 1700
 			// Show recipient
1608 1701
 			$widthrecbox=100;
1609
-			if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1702
+			if ($this->page_largeur < 210) {
1703
+			    $widthrecbox=84;
1704
+			}
1705
+			// To work with US executive format
1610 1706
 			$posy=42+$top_shift;
1611 1707
 			$posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1612
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1708
+			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1709
+			    $posx=$this->marge_gauche;
1710
+			}
1613 1711
 
1614 1712
 			// Show recipient frame
1615 1713
 			$pdf->SetTextColor(0,0,0);
@@ -1875,12 +1973,10 @@  discard block
 block discarded – undo
1875 1973
 	    if ($reshook < 0)
1876 1974
 	    {
1877 1975
 	        setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1878
-	    }
1879
-	    elseif (empty($reshook))
1976
+	    } elseif (empty($reshook))
1880 1977
 	    {
1881 1978
 	        $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
1882
-	    }
1883
-	    else
1979
+	    } else
1884 1980
 	    {
1885 1981
 	        $this->cols = $hookmanager->resArray;
1886 1982
 	    }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/propale/modules_propale.php 3 patches
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -36,33 +36,33 @@  discard block
 block discarded – undo
36 36
  */
37 37
 abstract class ModelePDFPropales extends CommonDocGenerator
38 38
 {
39
-	/**
40
-	 * @var string Error code (or message)
41
-	 */
42
-	public $error='';
39
+    /**
40
+     * @var string Error code (or message)
41
+     */
42
+    public $error='';
43 43
 
44 44
 
45 45
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
46
-	/**
47
-	 *  Return list of active generation modules
48
-	 *
46
+    /**
47
+     *  Return list of active generation modules
48
+     *
49 49
      *  @param	DoliDB	$db     			Database handler
50 50
      *  @param  integer	$maxfilenamelength  Max length of value to show
51 51
      *  @return	array						List of templates
52
-	 */
53
-	static function liste_modeles($db,$maxfilenamelength=0)
54
-	{
52
+     */
53
+    static function liste_modeles($db,$maxfilenamelength=0)
54
+    {
55 55
         // phpcs:enable
56
-		global $conf;
56
+        global $conf;
57 57
 
58
-		$type='propal';
59
-		$liste=array();
58
+        $type='propal';
59
+        $liste=array();
60 60
 
61
-		include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
62
-		$liste=getListOfModels($db,$type,$maxfilenamelength);
61
+        include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
62
+        $liste=getListOfModels($db,$type,$maxfilenamelength);
63 63
 
64
-		return $liste;
65
-	}
64
+        return $liste;
65
+    }
66 66
 }
67 67
 
68 68
 
@@ -71,83 +71,83 @@  discard block
 block discarded – undo
71 71
  */
72 72
 abstract class ModeleNumRefPropales
73 73
 {
74
-	/**
75
-	 * @var string Error code (or message)
76
-	 */
77
-	public $error='';
78
-
79
-	/**
80
-	 * Return if a module can be used or not
81
-	 *
82
-	 * @return	boolean     true if module can be used
83
-	 */
84
-	function isEnabled()
85
-	{
86
-		return true;
87
-	}
88
-
89
-	/**
90
-	 *  Renvoi la description par defaut du modele de numerotation
91
-	 *
92
-	 * 	@return     string      Texte descripif
93
-	 */
94
-	function info()
95
-	{
96
-		global $langs;
97
-		$langs->load("propale");
98
-		return $langs->trans("NoDescription");
99
-	}
100
-
101
-	/**
102
-	 * 	Renvoi un exemple de numerotation
103
-	 *
104
-	 *  @return     string      Example
105
-	 */
106
-	function getExample()
107
-	{
108
-		global $langs;
109
-		$langs->load("propale");
110
-		return $langs->trans("NoExample");
111
-	}
112
-
113
-	/**
114
-	 *  Test si les numeros deja en vigueur dans la base ne provoquent pas de
115
-	 *  de conflits qui empechera cette numerotation de fonctionner.
116
-	 *
117
-	 *  @return     boolean     false si conflit, true si ok
118
-	 */
119
-	function canBeActivated()
120
-	{
121
-		return true;
122
-	}
123
-
124
-	/**
125
-	 * 	Renvoi prochaine valeur attribuee
126
-	 *
127
-	 *	@param		Societe		$objsoc     Object third party
128
-	 *	@param		Propal		$propal		Object commercial proposal
129
-	 *	@return     string      Valeur
130
-	 */
131
-	function getNextValue($objsoc,$propal)
132
-	{
133
-		global $langs;
134
-		return $langs->trans("NotAvailable");
135
-	}
136
-
137
-	/**
138
-	 *  Renvoi version du module numerotation
139
-	 *
140
-	 *  @return     string      Valeur
141
-	 */
142
-	function getVersion()
143
-	{
144
-		global $langs;
145
-		$langs->load("admin");
146
-
147
-		if ($this->version == 'development') return $langs->trans("VersionDevelopment");
148
-		if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
149
-		if ($this->version == 'dolibarr') return DOL_VERSION;
150
-		if ($this->version) return $this->version;
151
-		return $langs->trans("NotAvailable");
152
-	}
74
+    /**
75
+     * @var string Error code (or message)
76
+     */
77
+    public $error='';
78
+
79
+    /**
80
+     * Return if a module can be used or not
81
+     *
82
+     * @return	boolean     true if module can be used
83
+     */
84
+    function isEnabled()
85
+    {
86
+        return true;
87
+    }
88
+
89
+    /**
90
+     *  Renvoi la description par defaut du modele de numerotation
91
+     *
92
+     * 	@return     string      Texte descripif
93
+     */
94
+    function info()
95
+    {
96
+        global $langs;
97
+        $langs->load("propale");
98
+        return $langs->trans("NoDescription");
99
+    }
100
+
101
+    /**
102
+     * 	Renvoi un exemple de numerotation
103
+     *
104
+     *  @return     string      Example
105
+     */
106
+    function getExample()
107
+    {
108
+        global $langs;
109
+        $langs->load("propale");
110
+        return $langs->trans("NoExample");
111
+    }
112
+
113
+    /**
114
+     *  Test si les numeros deja en vigueur dans la base ne provoquent pas de
115
+     *  de conflits qui empechera cette numerotation de fonctionner.
116
+     *
117
+     *  @return     boolean     false si conflit, true si ok
118
+     */
119
+    function canBeActivated()
120
+    {
121
+        return true;
122
+    }
123
+
124
+    /**
125
+     * 	Renvoi prochaine valeur attribuee
126
+     *
127
+     *	@param		Societe		$objsoc     Object third party
128
+     *	@param		Propal		$propal		Object commercial proposal
129
+     *	@return     string      Valeur
130
+     */
131
+    function getNextValue($objsoc,$propal)
132
+    {
133
+        global $langs;
134
+        return $langs->trans("NotAvailable");
135
+    }
136
+
137
+    /**
138
+     *  Renvoi version du module numerotation
139
+     *
140
+     *  @return     string      Valeur
141
+     */
142
+    function getVersion()
143
+    {
144
+        global $langs;
145
+        $langs->load("admin");
146
+
147
+        if ($this->version == 'development') return $langs->trans("VersionDevelopment");
148
+        if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
149
+        if ($this->version == 'dolibarr') return DOL_VERSION;
150
+        if ($this->version) return $this->version;
151
+        return $langs->trans("NotAvailable");
152
+    }
153 153
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
  */
29 29
 
30 30
 require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
31
-require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';   // Requis car utilise dans les classes qui heritent
31
+require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Requis car utilise dans les classes qui heritent
32 32
 
33 33
 
34 34
 /**
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	/**
40 40
 	 * @var string Error code (or message)
41 41
 	 */
42
-	public $error='';
42
+	public $error = '';
43 43
 
44 44
 
45 45
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -50,16 +50,16 @@  discard block
 block discarded – undo
50 50
      *  @param  integer	$maxfilenamelength  Max length of value to show
51 51
      *  @return	array						List of templates
52 52
 	 */
53
-	static function liste_modeles($db,$maxfilenamelength=0)
53
+	static function liste_modeles($db, $maxfilenamelength = 0)
54 54
 	{
55 55
         // phpcs:enable
56 56
 		global $conf;
57 57
 
58
-		$type='propal';
59
-		$liste=array();
58
+		$type = 'propal';
59
+		$liste = array();
60 60
 
61 61
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
62
-		$liste=getListOfModels($db,$type,$maxfilenamelength);
62
+		$liste = getListOfModels($db, $type, $maxfilenamelength);
63 63
 
64 64
 		return $liste;
65 65
 	}
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	/**
75 75
 	 * @var string Error code (or message)
76 76
 	 */
77
-	public $error='';
77
+	public $error = '';
78 78
 
79 79
 	/**
80 80
 	 * Return if a module can be used or not
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 *	@param		Propal		$propal		Object commercial proposal
129 129
 	 *	@return     string      Valeur
130 130
 	 */
131
-	function getNextValue($objsoc,$propal)
131
+	function getNextValue($objsoc, $propal)
132 132
 	{
133 133
 		global $langs;
134 134
 		return $langs->trans("NotAvailable");
Please login to merge, or discard this patch.
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -142,10 +142,18 @@
 block discarded – undo
142 142
 		global $langs;
143 143
 		$langs->load("admin");
144 144
 
145
-		if ($this->version == 'development') return $langs->trans("VersionDevelopment");
146
-		if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
147
-		if ($this->version == 'dolibarr') return DOL_VERSION;
148
-		if ($this->version) return $this->version;
145
+		if ($this->version == 'development') {
146
+		    return $langs->trans("VersionDevelopment");
147
+		}
148
+		if ($this->version == 'experimental') {
149
+		    return $langs->trans("VersionExperimental");
150
+		}
151
+		if ($this->version == 'dolibarr') {
152
+		    return DOL_VERSION;
153
+		}
154
+		if ($this->version) {
155
+		    return $this->version;
156
+		}
149 157
 		return $langs->trans("NotAvailable");
150 158
 	}
151 159
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/propale/mod_propale_saphir.php 2 patches
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -33,28 +33,28 @@  discard block
 block discarded – undo
33 33
  */
34 34
 class mod_propale_saphir extends ModeleNumRefPropales
35 35
 {
36
-	/**
36
+    /**
37 37
      * Dolibarr version of the loaded document
38 38
      * @public string
39 39
      */
40
-	public $version = 'dolibarr';		// 'development', 'experimental', 'dolibarr'
40
+    public $version = 'dolibarr';		// 'development', 'experimental', 'dolibarr'
41 41
 
42
-	/**
42
+    /**
43 43
      * @var string Error code (or message)
44 44
      */
45 45
     public $error = '';
46 46
 
47
-	/**
48
-	 * @var string Nom du modele
49
-	 * @deprecated
50
-	 * @see name
51
-	 */
52
-	public $nom='Saphir';
47
+    /**
48
+     * @var string Nom du modele
49
+     * @deprecated
50
+     * @see name
51
+     */
52
+    public $nom='Saphir';
53 53
 
54
-	/**
55
-	 * @var string model name
56
-	 */
57
-	public $name='Saphir';
54
+    /**
55
+     * @var string model name
56
+     */
57
+    public $name='Saphir';
58 58
 
59 59
 
60 60
     /**
@@ -62,39 +62,39 @@  discard block
 block discarded – undo
62 62
      *
63 63
      *  @return     string      Texte descripif
64 64
      */
65
-	function info()
65
+    function info()
66 66
     {
67
-    	global $conf, $langs;
67
+        global $conf, $langs;
68 68
 
69
-		$langs->load("bills");
69
+        $langs->load("bills");
70 70
 
71
-		$form = new Form($this->db);
71
+        $form = new Form($this->db);
72 72
 
73
-		$texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
74
-		$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
75
-		$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
76
-		$texte.= '<input type="hidden" name="action" value="updateMask">';
77
-		$texte.= '<input type="hidden" name="maskconstpropal" value="PROPALE_SAPHIR_MASK">';
78
-		$texte.= '<table class="nobordernopadding" width="100%">';
73
+        $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
74
+        $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
75
+        $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
76
+        $texte.= '<input type="hidden" name="action" value="updateMask">';
77
+        $texte.= '<input type="hidden" name="maskconstpropal" value="PROPALE_SAPHIR_MASK">';
78
+        $texte.= '<table class="nobordernopadding" width="100%">';
79 79
 
80
-		$tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Proposal"),$langs->transnoentities("Proposal"));
81
-		$tooltip.=$langs->trans("GenericMaskCodes2");
82
-		$tooltip.=$langs->trans("GenericMaskCodes3");
83
-		$tooltip.=$langs->trans("GenericMaskCodes4a",$langs->transnoentities("Proposal"),$langs->transnoentities("Proposal"));
84
-		$tooltip.=$langs->trans("GenericMaskCodes5");
80
+        $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Proposal"),$langs->transnoentities("Proposal"));
81
+        $tooltip.=$langs->trans("GenericMaskCodes2");
82
+        $tooltip.=$langs->trans("GenericMaskCodes3");
83
+        $tooltip.=$langs->trans("GenericMaskCodes4a",$langs->transnoentities("Proposal"),$langs->transnoentities("Proposal"));
84
+        $tooltip.=$langs->trans("GenericMaskCodes5");
85 85
 
86
-		// Parametrage du prefix
87
-		$texte.= '<tr><td>'.$langs->trans("Mask").':</td>';
88
-		$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskpropal" value="'.$conf->global->PROPALE_SAPHIR_MASK.'">',$tooltip,1,1).'</td>';
86
+        // Parametrage du prefix
87
+        $texte.= '<tr><td>'.$langs->trans("Mask").':</td>';
88
+        $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskpropal" value="'.$conf->global->PROPALE_SAPHIR_MASK.'">',$tooltip,1,1).'</td>';
89 89
 
90
-		$texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
90
+        $texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
91 91
 
92
-		$texte.= '</tr>';
92
+        $texte.= '</tr>';
93 93
 
94
-		$texte.= '</table>';
95
-		$texte.= '</form>';
94
+        $texte.= '</table>';
95
+        $texte.= '</form>';
96 96
 
97
-		return $texte;
97
+        return $texte;
98 98
     }
99 99
 
100 100
     /**
@@ -104,52 +104,52 @@  discard block
 block discarded – undo
104 104
      */
105 105
     function getExample()
106 106
     {
107
-     	global $conf,$langs,$mysoc;
108
-
109
-    	$old_code_client=$mysoc->code_client;
110
-    	$old_code_type=$mysoc->typent_code;
111
-    	$mysoc->code_client='CCCCCCCCCC';
112
-    	$mysoc->typent_code='TTTTTTTTTT';
113
-     	$numExample = $this->getNextValue($mysoc,'');
114
-		$mysoc->code_client=$old_code_client;
115
-		$mysoc->typent_code=$old_code_type;
116
-
117
-		if (! $numExample)
118
-		{
119
-			$numExample = 'NotConfigured';
120
-		}
121
-		return $numExample;
107
+            global $conf,$langs,$mysoc;
108
+
109
+        $old_code_client=$mysoc->code_client;
110
+        $old_code_type=$mysoc->typent_code;
111
+        $mysoc->code_client='CCCCCCCCCC';
112
+        $mysoc->typent_code='TTTTTTTTTT';
113
+            $numExample = $this->getNextValue($mysoc,'');
114
+        $mysoc->code_client=$old_code_client;
115
+        $mysoc->typent_code=$old_code_type;
116
+
117
+        if (! $numExample)
118
+        {
119
+            $numExample = 'NotConfigured';
120
+        }
121
+        return $numExample;
122 122
     }
123 123
 
124
-	/**
125
-	 *  Return next value
126
-	 *
127
-	 *  @param	Societe		$objsoc     Object third party
128
-	 * 	@param	Propal		$propal		Object commercial proposal
129
-	 *  @return string      			Value if OK, 0 if KO
130
-	 */
131
-	function getNextValue($objsoc,$propal)
132
-	{
133
-		global $db,$conf;
124
+    /**
125
+     *  Return next value
126
+     *
127
+     *  @param	Societe		$objsoc     Object third party
128
+     * 	@param	Propal		$propal		Object commercial proposal
129
+     *  @return string      			Value if OK, 0 if KO
130
+     */
131
+    function getNextValue($objsoc,$propal)
132
+    {
133
+        global $db,$conf;
134 134
 
135
-		require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
135
+        require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
136 136
 
137
-		// On defini critere recherche compteur
138
-		$mask = $conf->global->PROPALE_SAPHIR_MASK;
137
+        // On defini critere recherche compteur
138
+        $mask = $conf->global->PROPALE_SAPHIR_MASK;
139 139
 
140
-		if (! $mask)
141
-		{
142
-			$this->error='NotConfigured';
143
-			return 0;
144
-		}
140
+        if (! $mask)
141
+        {
142
+            $this->error='NotConfigured';
143
+            return 0;
144
+        }
145 145
 
146
-		// Get entities
147
-		$entity = getEntity('proposalnumber', 1, $propal);
146
+        // Get entities
147
+        $entity = getEntity('proposalnumber', 1, $propal);
148 148
 
149
-		$date = $propal->date;
149
+        $date = $propal->date;
150 150
 
151
-		$numFinal=get_next_value($db,$mask,'propal','ref','',$objsoc,$date,'next',false,null,$entity);
151
+        $numFinal=get_next_value($db,$mask,'propal','ref','',$objsoc,$date,'next',false,null,$entity);
152 152
 
153
-		return  $numFinal;
154
-	}
153
+        return  $numFinal;
154
+    }
155 155
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  * \brief      File that contains the numbering module rules Saphir
26 26
  */
27 27
 
28
-require_once DOL_DOCUMENT_ROOT .'/core/modules/propale/modules_propale.php';
28
+require_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
29 29
 
30 30
 
31 31
 /**
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      * Dolibarr version of the loaded document
38 38
      * @public string
39 39
      */
40
-	public $version = 'dolibarr';		// 'development', 'experimental', 'dolibarr'
40
+	public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
41 41
 
42 42
 	/**
43 43
      * @var string Error code (or message)
@@ -49,12 +49,12 @@  discard block
 block discarded – undo
49 49
 	 * @deprecated
50 50
 	 * @see name
51 51
 	 */
52
-	public $nom='Saphir';
52
+	public $nom = 'Saphir';
53 53
 
54 54
 	/**
55 55
 	 * @var string model name
56 56
 	 */
57
-	public $name='Saphir';
57
+	public $name = 'Saphir';
58 58
 
59 59
 
60 60
     /**
@@ -71,28 +71,28 @@  discard block
 block discarded – undo
71 71
 		$form = new Form($this->db);
72 72
 
73 73
 		$texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
74
-		$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
75
-		$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
76
-		$texte.= '<input type="hidden" name="action" value="updateMask">';
77
-		$texte.= '<input type="hidden" name="maskconstpropal" value="PROPALE_SAPHIR_MASK">';
78
-		$texte.= '<table class="nobordernopadding" width="100%">';
79
-
80
-		$tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Proposal"),$langs->transnoentities("Proposal"));
81
-		$tooltip.=$langs->trans("GenericMaskCodes2");
82
-		$tooltip.=$langs->trans("GenericMaskCodes3");
83
-		$tooltip.=$langs->trans("GenericMaskCodes4a",$langs->transnoentities("Proposal"),$langs->transnoentities("Proposal"));
84
-		$tooltip.=$langs->trans("GenericMaskCodes5");
74
+		$texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
75
+		$texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
76
+		$texte .= '<input type="hidden" name="action" value="updateMask">';
77
+		$texte .= '<input type="hidden" name="maskconstpropal" value="PROPALE_SAPHIR_MASK">';
78
+		$texte .= '<table class="nobordernopadding" width="100%">';
79
+
80
+		$tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Proposal"), $langs->transnoentities("Proposal"));
81
+		$tooltip .= $langs->trans("GenericMaskCodes2");
82
+		$tooltip .= $langs->trans("GenericMaskCodes3");
83
+		$tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Proposal"), $langs->transnoentities("Proposal"));
84
+		$tooltip .= $langs->trans("GenericMaskCodes5");
85 85
 
86 86
 		// Parametrage du prefix
87
-		$texte.= '<tr><td>'.$langs->trans("Mask").':</td>';
88
-		$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskpropal" value="'.$conf->global->PROPALE_SAPHIR_MASK.'">',$tooltip,1,1).'</td>';
87
+		$texte .= '<tr><td>'.$langs->trans("Mask").':</td>';
88
+		$texte .= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskpropal" value="'.$conf->global->PROPALE_SAPHIR_MASK.'">', $tooltip, 1, 1).'</td>';
89 89
 
90
-		$texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
90
+		$texte .= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
91 91
 
92
-		$texte.= '</tr>';
92
+		$texte .= '</tr>';
93 93
 
94
-		$texte.= '</table>';
95
-		$texte.= '</form>';
94
+		$texte .= '</table>';
95
+		$texte .= '</form>';
96 96
 
97 97
 		return $texte;
98 98
     }
@@ -104,17 +104,17 @@  discard block
 block discarded – undo
104 104
      */
105 105
     function getExample()
106 106
     {
107
-     	global $conf,$langs,$mysoc;
107
+     	global $conf, $langs, $mysoc;
108 108
 
109
-    	$old_code_client=$mysoc->code_client;
110
-    	$old_code_type=$mysoc->typent_code;
111
-    	$mysoc->code_client='CCCCCCCCCC';
112
-    	$mysoc->typent_code='TTTTTTTTTT';
113
-     	$numExample = $this->getNextValue($mysoc,'');
114
-		$mysoc->code_client=$old_code_client;
115
-		$mysoc->typent_code=$old_code_type;
109
+    	$old_code_client = $mysoc->code_client;
110
+    	$old_code_type = $mysoc->typent_code;
111
+    	$mysoc->code_client = 'CCCCCCCCCC';
112
+    	$mysoc->typent_code = 'TTTTTTTTTT';
113
+     	$numExample = $this->getNextValue($mysoc, '');
114
+		$mysoc->code_client = $old_code_client;
115
+		$mysoc->typent_code = $old_code_type;
116 116
 
117
-		if (! $numExample)
117
+		if (!$numExample)
118 118
 		{
119 119
 			$numExample = 'NotConfigured';
120 120
 		}
@@ -128,18 +128,18 @@  discard block
 block discarded – undo
128 128
 	 * 	@param	Propal		$propal		Object commercial proposal
129 129
 	 *  @return string      			Value if OK, 0 if KO
130 130
 	 */
131
-	function getNextValue($objsoc,$propal)
131
+	function getNextValue($objsoc, $propal)
132 132
 	{
133
-		global $db,$conf;
133
+		global $db, $conf;
134 134
 
135
-		require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
135
+		require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
136 136
 
137 137
 		// On defini critere recherche compteur
138 138
 		$mask = $conf->global->PROPALE_SAPHIR_MASK;
139 139
 
140
-		if (! $mask)
140
+		if (!$mask)
141 141
 		{
142
-			$this->error='NotConfigured';
142
+			$this->error = 'NotConfigured';
143 143
 			return 0;
144 144
 		}
145 145
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 
149 149
 		$date = $propal->date;
150 150
 
151
-		$numFinal=get_next_value($db,$mask,'propal','ref','',$objsoc,$date,'next',false,null,$entity);
151
+		$numFinal = get_next_value($db, $mask, 'propal', 'ref', '', $objsoc, $date, 'next', false, null, $entity);
152 152
 
153 153
 		return  $numFinal;
154 154
 	}
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/propale/mod_propale_marbre.php 3 patches
Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -31,30 +31,30 @@  discard block
 block discarded – undo
31 31
  */
32 32
 class mod_propale_marbre extends ModeleNumRefPropales
33 33
 {
34
-	/**
34
+    /**
35 35
      * Dolibarr version of the loaded document
36 36
      * @public string
37 37
      */
38
-	public $version = 'dolibarr';		// 'development', 'experimental', 'dolibarr'
38
+    public $version = 'dolibarr';		// 'development', 'experimental', 'dolibarr'
39 39
 
40
-	public $prefix='PR';
40
+    public $prefix='PR';
41 41
 
42
-	/**
43
-	 * @var string Error code (or message)
44
-	 */
45
-	public $error='';
42
+    /**
43
+     * @var string Error code (or message)
44
+     */
45
+    public $error='';
46 46
 
47
-	/**
48
-	 * @var string Nom du modele
49
-	 * @deprecated
50
-	 * @see name
51
-	 */
52
-	public $nom='Marbre';
47
+    /**
48
+     * @var string Nom du modele
49
+     * @deprecated
50
+     * @see name
51
+     */
52
+    public $nom='Marbre';
53 53
 
54
-	/**
55
-	 * @var string model name
56
-	 */
57
-	public $name='Marbre';
54
+    /**
55
+     * @var string model name
56
+     */
57
+    public $name='Marbre';
58 58
 
59 59
 
60 60
     /**
@@ -64,109 +64,109 @@  discard block
 block discarded – undo
64 64
      */
65 65
     function info()
66 66
     {
67
-    	global $langs;
68
-      	return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
67
+        global $langs;
68
+            return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
69
+    }
70
+
71
+
72
+    /**
73
+     *  Return an example of numbering module values
74
+     *
75
+     *  @return     string      Example
76
+     */
77
+    function getExample()
78
+    {
79
+        return $this->prefix."0501-0001";
69 80
     }
70 81
 
71 82
 
72
-	/**
73
-	 *  Return an example of numbering module values
74
-	 *
75
-	 *  @return     string      Example
76
-	 */
77
-	function getExample()
78
-	{
79
-		return $this->prefix."0501-0001";
80
-	}
81
-
82
-
83
-	/**
84
-	 *  Test si les numeros deje en vigueur dans la base ne provoquent pas de
85
-	 *  de conflits qui empechera cette numerotation de fonctionner.
86
-	 *
87
-	 *  @return     boolean     false si conflit, true si ok
88
-	 */
89
-	function canBeActivated()
90
-	{
91
-		global $conf,$langs,$db;
92
-
93
-		$pryymm=''; $max='';
94
-
95
-		$posindice=8;
96
-		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
97
-		$sql.= " FROM ".MAIN_DB_PREFIX."propal";
98
-		$sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
99
-		$sql.= " AND entity = ".$conf->entity;
100
-
101
-		$resql=$db->query($sql);
102
-		if ($resql)
103
-		{
104
-			$row = $db->fetch_row($resql);
105
-			if ($row) { $pryymm = substr($row[0],0,6); $max=$row[0]; }
106
-		}
107
-
108
-		if (! $pryymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$pryymm))
109
-		{
110
-			return true;
111
-		}
112
-		else
113
-		{
114
-			$langs->load("errors");
115
-			$this->error=$langs->trans('ErrorNumRefModel',$max);
116
-			return false;
117
-		}
118
-	}
119
-
120
-	/**
121
-	 *  Return next value
122
-	 *
123
-	 *  @param	Societe		$objsoc     Object third party
124
-	 * 	@param	Propal		$propal		Object commercial proposal
125
-	 *  @return string      			Next value
126
-	 */
127
-	function getNextValue($objsoc,$propal)
128
-	{
129
-		global $db,$conf;
130
-
131
-		// D'abord on recupere la valeur max
132
-		$posindice=8;
133
-		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";	// This is standard SQL
134
-		$sql.= " FROM ".MAIN_DB_PREFIX."propal";
135
-		$sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
136
-		$sql.= " AND entity IN (".getEntity('proposalnumber', 1, $propal).")";
137
-
138
-		$resql=$db->query($sql);
139
-		if ($resql)
140
-		{
141
-			$obj = $db->fetch_object($resql);
142
-			if ($obj) $max = intval($obj->max);
143
-			else $max=0;
144
-		}
145
-		else
146
-		{
147
-			dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
148
-			return -1;
149
-		}
150
-
151
-		$date = time();
152
-		$yymm = strftime("%y%m",$date);
153
-
154
-		if ($max >= (pow(10, 4) - 1)) $num=$max+1;	// If counter > 9999, we do not format on 4 chars, we take number as it is
155
-		else $num = sprintf("%04s",$max+1);
156
-
157
-		dol_syslog(get_class($this)."::getNextValue return ".$this->prefix.$yymm."-".$num);
158
-		return $this->prefix.$yymm."-".$num;
159
-	}
160
-
161
-	/**
162
-	 *  Return next free value
163
-	 *
164
-	 *  @param	Societe		$objsoc      	Object third party
165
-	 * 	@param	Object		$objforref		Object for number to search
166
-	 *  @return string      				Next free value
167
-	 */
168
-	function getNumRef($objsoc,$objforref)
169
-	{
170
-		return $this->getNextValue($objsoc,$objforref);
171
-	}
83
+    /**
84
+     *  Test si les numeros deje en vigueur dans la base ne provoquent pas de
85
+     *  de conflits qui empechera cette numerotation de fonctionner.
86
+     *
87
+     *  @return     boolean     false si conflit, true si ok
88
+     */
89
+    function canBeActivated()
90
+    {
91
+        global $conf,$langs,$db;
92
+
93
+        $pryymm=''; $max='';
94
+
95
+        $posindice=8;
96
+        $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
97
+        $sql.= " FROM ".MAIN_DB_PREFIX."propal";
98
+        $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
99
+        $sql.= " AND entity = ".$conf->entity;
100
+
101
+        $resql=$db->query($sql);
102
+        if ($resql)
103
+        {
104
+            $row = $db->fetch_row($resql);
105
+            if ($row) { $pryymm = substr($row[0],0,6); $max=$row[0]; }
106
+        }
107
+
108
+        if (! $pryymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$pryymm))
109
+        {
110
+            return true;
111
+        }
112
+        else
113
+        {
114
+            $langs->load("errors");
115
+            $this->error=$langs->trans('ErrorNumRefModel',$max);
116
+            return false;
117
+        }
118
+    }
119
+
120
+    /**
121
+     *  Return next value
122
+     *
123
+     *  @param	Societe		$objsoc     Object third party
124
+     * 	@param	Propal		$propal		Object commercial proposal
125
+     *  @return string      			Next value
126
+     */
127
+    function getNextValue($objsoc,$propal)
128
+    {
129
+        global $db,$conf;
130
+
131
+        // D'abord on recupere la valeur max
132
+        $posindice=8;
133
+        $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";	// This is standard SQL
134
+        $sql.= " FROM ".MAIN_DB_PREFIX."propal";
135
+        $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
136
+        $sql.= " AND entity IN (".getEntity('proposalnumber', 1, $propal).")";
137
+
138
+        $resql=$db->query($sql);
139
+        if ($resql)
140
+        {
141
+            $obj = $db->fetch_object($resql);
142
+            if ($obj) $max = intval($obj->max);
143
+            else $max=0;
144
+        }
145
+        else
146
+        {
147
+            dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
148
+            return -1;
149
+        }
150
+
151
+        $date = time();
152
+        $yymm = strftime("%y%m",$date);
153
+
154
+        if ($max >= (pow(10, 4) - 1)) $num=$max+1;	// If counter > 9999, we do not format on 4 chars, we take number as it is
155
+        else $num = sprintf("%04s",$max+1);
156
+
157
+        dol_syslog(get_class($this)."::getNextValue return ".$this->prefix.$yymm."-".$num);
158
+        return $this->prefix.$yymm."-".$num;
159
+    }
160
+
161
+    /**
162
+     *  Return next free value
163
+     *
164
+     *  @param	Societe		$objsoc      	Object third party
165
+     * 	@param	Object		$objforref		Object for number to search
166
+     *  @return string      				Next free value
167
+     */
168
+    function getNumRef($objsoc,$objforref)
169
+    {
170
+        return $this->getNextValue($objsoc,$objforref);
171
+    }
172 172
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  *		\brief      File of class to manage commercial proposal numbering rules Marbre
24 24
  */
25 25
 
26
-require_once DOL_DOCUMENT_ROOT .'/core/modules/propale/modules_propale.php';
26
+require_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
27 27
 
28 28
 
29 29
 /**
@@ -35,26 +35,26 @@  discard block
 block discarded – undo
35 35
      * Dolibarr version of the loaded document
36 36
      * @public string
37 37
      */
38
-	public $version = 'dolibarr';		// 'development', 'experimental', 'dolibarr'
38
+	public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
39 39
 
40
-	public $prefix='PR';
40
+	public $prefix = 'PR';
41 41
 
42 42
 	/**
43 43
 	 * @var string Error code (or message)
44 44
 	 */
45
-	public $error='';
45
+	public $error = '';
46 46
 
47 47
 	/**
48 48
 	 * @var string Nom du modele
49 49
 	 * @deprecated
50 50
 	 * @see name
51 51
 	 */
52
-	public $nom='Marbre';
52
+	public $nom = 'Marbre';
53 53
 
54 54
 	/**
55 55
 	 * @var string model name
56 56
 	 */
57
-	public $name='Marbre';
57
+	public $name = 'Marbre';
58 58
 
59 59
 
60 60
     /**
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
     function info()
66 66
     {
67 67
     	global $langs;
68
-      	return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
68
+      	return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
69 69
     }
70 70
 
71 71
 
@@ -88,31 +88,31 @@  discard block
 block discarded – undo
88 88
 	 */
89 89
 	function canBeActivated()
90 90
 	{
91
-		global $conf,$langs,$db;
91
+		global $conf, $langs, $db;
92 92
 
93
-		$pryymm=''; $max='';
93
+		$pryymm = ''; $max = '';
94 94
 
95
-		$posindice=8;
95
+		$posindice = 8;
96 96
 		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
97
-		$sql.= " FROM ".MAIN_DB_PREFIX."propal";
98
-		$sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
99
-		$sql.= " AND entity = ".$conf->entity;
97
+		$sql .= " FROM ".MAIN_DB_PREFIX."propal";
98
+		$sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
99
+		$sql .= " AND entity = ".$conf->entity;
100 100
 
101
-		$resql=$db->query($sql);
101
+		$resql = $db->query($sql);
102 102
 		if ($resql)
103 103
 		{
104 104
 			$row = $db->fetch_row($resql);
105
-			if ($row) { $pryymm = substr($row[0],0,6); $max=$row[0]; }
105
+			if ($row) { $pryymm = substr($row[0], 0, 6); $max = $row[0]; }
106 106
 		}
107 107
 
108
-		if (! $pryymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$pryymm))
108
+		if (!$pryymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $pryymm))
109 109
 		{
110 110
 			return true;
111 111
 		}
112 112
 		else
113 113
 		{
114 114
 			$langs->load("errors");
115
-			$this->error=$langs->trans('ErrorNumRefModel',$max);
115
+			$this->error = $langs->trans('ErrorNumRefModel', $max);
116 116
 			return false;
117 117
 		}
118 118
 	}
@@ -124,23 +124,23 @@  discard block
 block discarded – undo
124 124
 	 * 	@param	Propal		$propal		Object commercial proposal
125 125
 	 *  @return string      			Next value
126 126
 	 */
127
-	function getNextValue($objsoc,$propal)
127
+	function getNextValue($objsoc, $propal)
128 128
 	{
129
-		global $db,$conf;
129
+		global $db, $conf;
130 130
 
131 131
 		// D'abord on recupere la valeur max
132
-		$posindice=8;
133
-		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";	// This is standard SQL
134
-		$sql.= " FROM ".MAIN_DB_PREFIX."propal";
135
-		$sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
136
-		$sql.= " AND entity IN (".getEntity('proposalnumber', 1, $propal).")";
132
+		$posindice = 8;
133
+		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
134
+		$sql .= " FROM ".MAIN_DB_PREFIX."propal";
135
+		$sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
136
+		$sql .= " AND entity IN (".getEntity('proposalnumber', 1, $propal).")";
137 137
 
138
-		$resql=$db->query($sql);
138
+		$resql = $db->query($sql);
139 139
 		if ($resql)
140 140
 		{
141 141
 			$obj = $db->fetch_object($resql);
142 142
 			if ($obj) $max = intval($obj->max);
143
-			else $max=0;
143
+			else $max = 0;
144 144
 		}
145 145
 		else
146 146
 		{
@@ -149,10 +149,10 @@  discard block
 block discarded – undo
149 149
 		}
150 150
 
151 151
 		$date = time();
152
-		$yymm = strftime("%y%m",$date);
152
+		$yymm = strftime("%y%m", $date);
153 153
 
154
-		if ($max >= (pow(10, 4) - 1)) $num=$max+1;	// If counter > 9999, we do not format on 4 chars, we take number as it is
155
-		else $num = sprintf("%04s",$max+1);
154
+		if ($max >= (pow(10, 4) - 1)) $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
155
+		else $num = sprintf("%04s", $max + 1);
156 156
 
157 157
 		dol_syslog(get_class($this)."::getNextValue return ".$this->prefix.$yymm."-".$num);
158 158
 		return $this->prefix.$yymm."-".$num;
@@ -165,8 +165,8 @@  discard block
 block discarded – undo
165 165
 	 * 	@param	Object		$objforref		Object for number to search
166 166
 	 *  @return string      				Next free value
167 167
 	 */
168
-	function getNumRef($objsoc,$objforref)
168
+	function getNumRef($objsoc, $objforref)
169 169
 	{
170
-		return $this->getNextValue($objsoc,$objforref);
170
+		return $this->getNextValue($objsoc, $objforref);
171 171
 	}
172 172
 }
Please login to merge, or discard this patch.
Braces   +14 added lines, -8 removed lines patch added patch discarded remove patch
@@ -108,8 +108,7 @@  discard block
 block discarded – undo
108 108
 		if (! $pryymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$pryymm))
109 109
 		{
110 110
 			return true;
111
-		}
112
-		else
111
+		} else
113 112
 		{
114 113
 			$langs->load("errors");
115 114
 			$this->error=$langs->trans('ErrorNumRefModel',$max);
@@ -139,10 +138,12 @@  discard block
 block discarded – undo
139 138
 		if ($resql)
140 139
 		{
141 140
 			$obj = $db->fetch_object($resql);
142
-			if ($obj) $max = intval($obj->max);
143
-			else $max=0;
144
-		}
145
-		else
141
+			if ($obj) {
142
+			    $max = intval($obj->max);
143
+			} else {
144
+			    $max=0;
145
+			}
146
+		} else
146 147
 		{
147 148
 			dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
148 149
 			return -1;
@@ -151,8 +152,13 @@  discard block
 block discarded – undo
151 152
 		$date = time();
152 153
 		$yymm = strftime("%y%m",$date);
153 154
 
154
-		if ($max >= (pow(10, 4) - 1)) $num=$max+1;	// If counter > 9999, we do not format on 4 chars, we take number as it is
155
-		else $num = sprintf("%04s",$max+1);
155
+		if ($max >= (pow(10, 4) - 1)) {
156
+		    $num=$max+1;
157
+		}
158
+		// If counter > 9999, we do not format on 4 chars, we take number as it is
159
+		else {
160
+		    $num = sprintf("%04s",$max+1);
161
+		}
156 162
 
157 163
 		dol_syslog(get_class($this)."::getNextValue return ".$this->prefix.$yymm."-".$num);
158 164
 		return $this->prefix.$yymm."-".$num;
Please login to merge, or discard this patch.