Passed
Pull Request — master (#2)
by
unknown
26:19
created
dolibarr/htdocs/core/modules/stock/modules_stock.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -24,9 +24,9 @@
 block discarded – undo
24 24
 abstract class ModelePDFStock extends CommonDocGenerator
25 25
 {
26 26
     /**
27
-	 * @var string Error code (or message)
28
-	 */
29
-	public $error='';
27
+     * @var string Error code (or message)
28
+     */
29
+    public $error='';
30 30
 
31 31
 
32 32
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/stock/doc/doc_generic_stock_odt.modules.php 1 patch
Indentation   +435 added lines, -435 removed lines patch added patch discarded remove patch
@@ -37,136 +37,136 @@  discard block
 block discarded – undo
37 37
  */
38 38
 class doc_generic_stock_odt extends ModelePDFStock
39 39
 {
40
-	/**
41
-	 * Issuer
42
-	 * @var Societe
43
-	 */
44
-	public $emetteur;
45
-
46
-	/**
47
-   * @var array() Minimum version of PHP required by module.
48
-	 * e.g.: PHP ≥ 5.4 = array(5, 4)
49
-   */
50
-	public $phpmin = array(5, 4);
51
-
52
-	/**
40
+    /**
41
+     * Issuer
42
+     * @var Societe
43
+     */
44
+    public $emetteur;
45
+
46
+    /**
47
+     * @var array() Minimum version of PHP required by module.
48
+     * e.g.: PHP ≥ 5.4 = array(5, 4)
49
+     */
50
+    public $phpmin = array(5, 4);
51
+
52
+    /**
53 53
      * Dolibarr version of the loaded document
54 54
      * @public string
55 55
      */
56
-	public $version = 'dolibarr';
56
+    public $version = 'dolibarr';
57 57
 
58 58
 
59
-	/**
60
-	 *	Constructor
61
-	 *
62
-	 *  @param		DoliDB		$db      Database handler
63
-	 */
64
-	function __construct($db)
65
-	{
66
-		global $conf, $langs, $mysoc;
59
+    /**
60
+     *	Constructor
61
+     *
62
+     *  @param		DoliDB		$db      Database handler
63
+     */
64
+    function __construct($db)
65
+    {
66
+        global $conf, $langs, $mysoc;
67 67
 
68
-		// Load translation files required by the page
68
+        // Load translation files required by the page
69 69
         $langs->loadLangs(array("main","companies"));
70 70
 
71
-		$this->db = $db;
72
-		$this->name = "ODT templates";
73
-		$this->description = $langs->trans("DocumentModelOdt");
74
-		$this->scandir = 'STOCK_ADDON_PDF_ODT_PATH';	// Name of constant that is used to save list of directories to scan
75
-
76
-		// Dimension page pour format A4
77
-		$this->type = 'odt';
78
-		$this->page_largeur = 0;
79
-		$this->page_hauteur = 0;
80
-		$this->format = array($this->page_largeur,$this->page_hauteur);
81
-		$this->marge_gauche=0;
82
-		$this->marge_droite=0;
83
-		$this->marge_haute=0;
84
-		$this->marge_basse=0;
85
-
86
-		$this->option_logo = 1;                    // Affiche logo
87
-		$this->option_tva = 0;                     // Gere option tva STOCK_TVAOPTION
88
-		$this->option_modereg = 0;                 // Affiche mode reglement
89
-		$this->option_condreg = 0;                 // Affiche conditions reglement
90
-		$this->option_codeproduitservice = 0;      // Affiche code produit-service
91
-		$this->option_multilang = 1;               // Dispo en plusieurs langues
92
-		$this->option_escompte = 0;                // Affiche si il y a eu escompte
93
-		$this->option_credit_note = 0;             // Support credit notes
94
-		$this->option_freetext = 1;				   // Support add of a personalised text
95
-		$this->option_draft_watermark = 0;		   // Support add of a watermark on drafts
96
-
97
-		// Recupere emetteur
98
-		$this->emetteur=$mysoc;
99
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
100
-	}
101
-
102
-
103
-	/**
104
-	 *	Return description of a module
105
-	 *
106
-	 *	@param	Translate	$langs      Lang object to use for output
107
-	 *	@return string       			Description
108
-	 */
109
-	function info($langs)
110
-	{
111
-		global $conf, $langs;
112
-
113
-		// Load translation files required by the page
71
+        $this->db = $db;
72
+        $this->name = "ODT templates";
73
+        $this->description = $langs->trans("DocumentModelOdt");
74
+        $this->scandir = 'STOCK_ADDON_PDF_ODT_PATH';	// Name of constant that is used to save list of directories to scan
75
+
76
+        // Dimension page pour format A4
77
+        $this->type = 'odt';
78
+        $this->page_largeur = 0;
79
+        $this->page_hauteur = 0;
80
+        $this->format = array($this->page_largeur,$this->page_hauteur);
81
+        $this->marge_gauche=0;
82
+        $this->marge_droite=0;
83
+        $this->marge_haute=0;
84
+        $this->marge_basse=0;
85
+
86
+        $this->option_logo = 1;                    // Affiche logo
87
+        $this->option_tva = 0;                     // Gere option tva STOCK_TVAOPTION
88
+        $this->option_modereg = 0;                 // Affiche mode reglement
89
+        $this->option_condreg = 0;                 // Affiche conditions reglement
90
+        $this->option_codeproduitservice = 0;      // Affiche code produit-service
91
+        $this->option_multilang = 1;               // Dispo en plusieurs langues
92
+        $this->option_escompte = 0;                // Affiche si il y a eu escompte
93
+        $this->option_credit_note = 0;             // Support credit notes
94
+        $this->option_freetext = 1;				   // Support add of a personalised text
95
+        $this->option_draft_watermark = 0;		   // Support add of a watermark on drafts
96
+
97
+        // Recupere emetteur
98
+        $this->emetteur=$mysoc;
99
+        if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
100
+    }
101
+
102
+
103
+    /**
104
+     *	Return description of a module
105
+     *
106
+     *	@param	Translate	$langs      Lang object to use for output
107
+     *	@return string       			Description
108
+     */
109
+    function info($langs)
110
+    {
111
+        global $conf, $langs;
112
+
113
+        // Load translation files required by the page
114 114
         $langs->loadLangs(array("errors","companies"));
115 115
 
116
-		$form = new Form($this->db);
117
-
118
-		$texte = $this->description.".<br>\n";
119
-		$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
120
-		$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
121
-		$texte.= '<input type="hidden" name="action" value="setModuleOptions">';
122
-		$texte.= '<input type="hidden" name="param1" value="STOCK_ADDON_PDF_ODT_PATH">';
123
-		if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0)
124
-		{
125
-			$texte.= '<input type="hidden" name="param2" value="STOCK_ADDON_PDF_ODT_DEFAULT">';
126
-			$texte.= '<input type="hidden" name="param3" value="STOCK_ADDON_PDF_ODT_TOBILL">';
127
-			$texte.= '<input type="hidden" name="param4" value="STOCK_ADDON_PDF_ODT_CLOSED">';
128
-		}
129
-		$texte.= '<table class="nobordernopadding" width="100%">';
130
-
131
-		// List of directories area
132
-		$texte.= '<tr><td>';
133
-		$texttitle=$langs->trans("ListOfDirectories");
134
-		$listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->STOCK_ADDON_PDF_ODT_PATH)));
135
-		$listoffiles=array();
136
-		foreach($listofdir as $key=>$tmpdir)
137
-		{
138
-			$tmpdir=trim($tmpdir);
139
-			$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
140
-			if (! $tmpdir) {
141
-				unset($listofdir[$key]); continue;
142
-			}
143
-			if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
144
-			else
145
-			{
146
-				$tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
147
-				if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
148
-			}
149
-		}
150
-		$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
151
-		// Add list of substitution keys
152
-		$texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
153
-		$texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation");    // This contains an url, we don't modify it
154
-
155
-		$texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
156
-		$texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
157
-		$texte.= '<textarea class="flat" cols="60" name="value1">';
158
-		$texte.=$conf->global->STOCK_ADDON_PDF_ODT_PATH;
159
-		$texte.= '</textarea>';
160
-		$texte.= '</div><div style="display: inline-block; vertical-align: middle;">';
161
-		$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
162
-		$texte.= '<br></div></div>';
163
-
164
-		// Scan directories
165
-		if (count($listofdir))
166
-		{
167
-			$texte.=$langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>';
168
-
169
-			/*if ($conf->global->MAIN_STOCK_CHOOSE_ODT_DOCUMENT > 0)
116
+        $form = new Form($this->db);
117
+
118
+        $texte = $this->description.".<br>\n";
119
+        $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
120
+        $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
121
+        $texte.= '<input type="hidden" name="action" value="setModuleOptions">';
122
+        $texte.= '<input type="hidden" name="param1" value="STOCK_ADDON_PDF_ODT_PATH">';
123
+        if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0)
124
+        {
125
+            $texte.= '<input type="hidden" name="param2" value="STOCK_ADDON_PDF_ODT_DEFAULT">';
126
+            $texte.= '<input type="hidden" name="param3" value="STOCK_ADDON_PDF_ODT_TOBILL">';
127
+            $texte.= '<input type="hidden" name="param4" value="STOCK_ADDON_PDF_ODT_CLOSED">';
128
+        }
129
+        $texte.= '<table class="nobordernopadding" width="100%">';
130
+
131
+        // List of directories area
132
+        $texte.= '<tr><td>';
133
+        $texttitle=$langs->trans("ListOfDirectories");
134
+        $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->STOCK_ADDON_PDF_ODT_PATH)));
135
+        $listoffiles=array();
136
+        foreach($listofdir as $key=>$tmpdir)
137
+        {
138
+            $tmpdir=trim($tmpdir);
139
+            $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
140
+            if (! $tmpdir) {
141
+                unset($listofdir[$key]); continue;
142
+            }
143
+            if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
144
+            else
145
+            {
146
+                $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
147
+                if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
148
+            }
149
+        }
150
+        $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
151
+        // Add list of substitution keys
152
+        $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
153
+        $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation");    // This contains an url, we don't modify it
154
+
155
+        $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
156
+        $texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
157
+        $texte.= '<textarea class="flat" cols="60" name="value1">';
158
+        $texte.=$conf->global->STOCK_ADDON_PDF_ODT_PATH;
159
+        $texte.= '</textarea>';
160
+        $texte.= '</div><div style="display: inline-block; vertical-align: middle;">';
161
+        $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
162
+        $texte.= '<br></div></div>';
163
+
164
+        // Scan directories
165
+        if (count($listofdir))
166
+        {
167
+            $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>';
168
+
169
+            /*if ($conf->global->MAIN_STOCK_CHOOSE_ODT_DOCUMENT > 0)
170 170
 			{
171 171
 				// Model for creation
172 172
 				$liste=ModelePDFStock::liste_modeles($this->db);
@@ -190,336 +190,336 @@  discard block
 block discarded – undo
190 190
 				$texte.= "</td></tr>";
191 191
 				$texte.= '</table>';
192 192
 			}*/
193
-		}
193
+        }
194 194
 
195
-		$texte.= '</td>';
195
+        $texte.= '</td>';
196 196
 
197
-		$texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">';
198
-		$texte.= $langs->trans("ExampleOfDirectoriesForModelGen");
199
-		$texte.= '</td>';
200
-		$texte.= '</tr>';
197
+        $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">';
198
+        $texte.= $langs->trans("ExampleOfDirectoriesForModelGen");
199
+        $texte.= '</td>';
200
+        $texte.= '</tr>';
201 201
 
202
-		$texte.= '</table>';
203
-		$texte.= '</form>';
202
+        $texte.= '</table>';
203
+        $texte.= '</form>';
204 204
 
205
-		return $texte;
206
-	}
205
+        return $texte;
206
+    }
207 207
 
208 208
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
209
-	/**
210
-	 *	Function to build a document on disk using the generic odt module.
211
-	 *
212
-	 *	@param		Stock		$object				Object source to build document
213
-	 *	@param		Translate	$outputlangs		Lang output object
214
-	 * 	@param		string		$srctemplatepath	Full path of source filename for generator using a template file
215
-	 *  @param		int			$hidedetails		Do not show line details
216
-	 *  @param		int			$hidedesc			Do not show desc
217
-	 *  @param		int			$hideref			Do not show ref
218
-	 *	@return		int         					1 if OK, <=0 if KO
219
-	 */
220
-	function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
221
-	{
209
+    /**
210
+     *	Function to build a document on disk using the generic odt module.
211
+     *
212
+     *	@param		Stock		$object				Object source to build document
213
+     *	@param		Translate	$outputlangs		Lang output object
214
+     * 	@param		string		$srctemplatepath	Full path of source filename for generator using a template file
215
+     *  @param		int			$hidedetails		Do not show line details
216
+     *  @param		int			$hidedesc			Do not show desc
217
+     *  @param		int			$hideref			Do not show ref
218
+     *	@return		int         					1 if OK, <=0 if KO
219
+     */
220
+    function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
221
+    {
222 222
         // phpcs:enable
223
-		global $stock,$langs,$conf,$mysoc,$hookmanager,$user;
224
-
225
-		if (empty($srctemplatepath))
226
-		{
227
-			dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
228
-			return -1;
229
-		}
230
-
231
-		// Add odtgeneration hook
232
-		if (! is_object($hookmanager))
233
-		{
234
-			include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
235
-			$hookmanager=new HookManager($this->db);
236
-		}
237
-		$hookmanager->initHooks(array('odtgeneration'));
238
-		global $action;
239
-
240
-		if (! is_object($outputlangs)) $outputlangs=$langs;
241
-		$sav_charset_output=$outputlangs->charset_output;
242
-		$outputlangs->charset_output='UTF-8';
243
-
244
-		// Load translation files required by the page
245
-		$outputlangs->loadLangs(array("main", "dict", "companies", "bills"));
246
-
247
-		if ($conf->produit->dir_output)
248
-		{
249
-			// If $object is id instead of object
250
-			if (! is_object($object))
251
-			{
252
-				$id = $object;
253
-				$object = new Stock($this->db);
254
-				$result=$object->fetch($id);
255
-				if ($result < 0)
256
-				{
257
-					dol_print_error($this->db,$object->error);
258
-					return -1;
259
-				}
260
-			}
261
-			$stockFournisseur = new StockFournisseur($this->db);
262
-			$supplierprices = $stockFournisseur->list_stock_fournisseur_price($object->id);
263
-			$object->supplierprices = $supplierprices;
264
-
265
-			$dir = $conf->produit->dir_output;
266
-			$objectref = dol_sanitizeFileName($object->ref);
267
-			if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
268
-			$file = $dir . "/" . $objectref . ".odt";
269
-
270
-			if (! file_exists($dir))
271
-			{
272
-				if (dol_mkdir($dir) < 0)
273
-				{
274
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
275
-					return -1;
276
-				}
277
-			}
278
-
279
-			if (file_exists($dir))
280
-			{
281
-				//print "srctemplatepath=".$srctemplatepath;	// Src filename
282
-				$newfile=basename($srctemplatepath);
283
-				$newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile);
284
-				$newfiletmp=preg_replace('/template_/i','',$newfiletmp);
285
-				$newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
286
-
287
-				$newfiletmp=$objectref.'_'.$newfiletmp;
288
-
289
-				// Get extension (ods or odt)
290
-				$newfileformat=substr($newfile, strrpos($newfile, '.')+1);
291
-				if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
292
-				{
293
-				    $format=$conf->global->MAIN_DOC_USE_TIMING;
294
-				    if ($format == '1') $format='%Y%m%d%H%M%S';
295
-					$filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
296
-				}
297
-				else
298
-				{
299
-					$filename=$newfiletmp.'.'.$newfileformat;
300
-				}
301
-				$file=$dir.'/'.$filename;
302
-				//print "newdir=".$dir;
303
-				//print "newfile=".$newfile;
304
-				//print "file=".$file;
305
-				//print "conf->produit->dir_temp=".$conf->produit->dir_temp;
306
-
307
-				dol_mkdir($conf->produit->dir_temp);
308
-
309
-
310
-				// If CUSTOMER contact defined on stock, we use it
311
-				$usecontact=false;
312
-				$arrayidcontact=$object->getIdContact('external','CUSTOMER');
313
-				if (count($arrayidcontact) > 0)
314
-				{
315
-					$usecontact=true;
316
-					$result=$object->fetch_contact($arrayidcontact[0]);
317
-				}
318
-
319
-				// Recipient name
320
-				$contactobject=null;
321
-				if (! empty($usecontact))
322
-				{
323
-					// On peut utiliser le nom de la societe du contact
324
-					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
325
-					else {
326
-                        			$socobject = $object->thirdparty;
327
-                        			// if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use
328
-                        			$contactobject = $object->contact;
329
-                    			}
330
-				}
331
-				else
332
-				{
333
-					$socobject=$object->thirdparty;
334
-				}
335
-				// Make substitution
336
-				$substitutionarray=array(
337
-				'__FROM_NAME__' => $this->emetteur->name,
338
-				'__FROM_EMAIL__' => $this->emetteur->email,
339
-				'__TOTAL_TTC__' => $object->total_ttc,
340
-				'__TOTAL_HT__' => $object->total_ht,
341
-				'__TOTAL_VAT__' => $object->total_vat
342
-				);
343
-				complete_substitutions_array($substitutionarray, $langs, $object);
344
-				// Call the ODTSubstitution hook
345
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
346
-				$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
347
-
348
-				// Line of free text
349
-				$newfreetext='';
350
-				$paramfreetext='stock_FREE_TEXT';
351
-				if (! empty($conf->global->$paramfreetext))
352
-				{
353
-					$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
354
-				}
355
-
356
-				// Open and load template
357
-				require_once ODTPHP_PATH.'odf.php';
358
-				try {
359
-					$odfHandler = new odf(
360
-						$srctemplatepath,
361
-						array(
362
-						'PATH_TO_TMP'	  => $conf->produit->dir_temp,
363
-						'ZIP_PROXY'		  => 'PclZipProxy',	// PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
364
-						'DELIMITER_LEFT'  => '{',
365
-						'DELIMITER_RIGHT' => '}'
366
-						)
367
-					);
368
-				}
369
-				catch(Exception $e)
370
-				{
371
-					$this->error=$e->getMessage();
372
-					dol_syslog($e->getMessage(), LOG_INFO);
373
-					return -1;
374
-				}
375
-				// After construction $odfHandler->contentXml contains content and
376
-				// [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
377
-				// [!-- BEGIN lines --]*[!-- END lines --]
378
-				//print html_entity_decode($odfHandler->__toString());
379
-				//print exit;
380
-
381
-				$object->fetch_optionals();
382
-
383
-				// Make substitutions into odt of freetext
384
-				try {
385
-					$odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
386
-				}
387
-				catch (OdfException $e)
388
-				{
389
-					dol_syslog($e->getMessage(), LOG_INFO);
390
-				}
391
-
392
-				// Define substitution array
393
-				$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
394
-				$array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs);
395
-				//$array_objet=$this->get_substitutionarray_object($object,$outputlangs);
396
-				$array_user=$this->get_substitutionarray_user($user,$outputlangs);
397
-				$array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
398
-				$array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
399
-				$array_other=$this->get_substitutionarray_other($outputlangs);
400
-				// retrieve contact information for use in stock as contact_xxx tags
401
-				$array_thirdparty_contact = array();
402
-				if ($usecontact && is_object($contactobject)) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
403
-
404
-				$tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_other,$array_thirdparty_contact);
405
-				complete_substitutions_array($tmparray, $outputlangs, $object);
406
-
407
-				// Call the ODTSubstitution hook
408
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
409
-				$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
410
-
411
-				foreach($tmparray as $key=>$value)
412
-				{
413
-					try {
414
-						if (preg_match('/logo$/',$key)) // Image
415
-						{
416
-							if (file_exists($value)) $odfHandler->setImage($key, $value);
417
-							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
418
-						}
419
-						else    // Text
420
-						{
421
-							$odfHandler->setVars($key, $value, true, 'UTF-8');
422
-						}
423
-					}
424
-					catch (OdfException $e)
425
-					{
223
+        global $stock,$langs,$conf,$mysoc,$hookmanager,$user;
224
+
225
+        if (empty($srctemplatepath))
226
+        {
227
+            dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
228
+            return -1;
229
+        }
230
+
231
+        // Add odtgeneration hook
232
+        if (! is_object($hookmanager))
233
+        {
234
+            include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
235
+            $hookmanager=new HookManager($this->db);
236
+        }
237
+        $hookmanager->initHooks(array('odtgeneration'));
238
+        global $action;
239
+
240
+        if (! is_object($outputlangs)) $outputlangs=$langs;
241
+        $sav_charset_output=$outputlangs->charset_output;
242
+        $outputlangs->charset_output='UTF-8';
243
+
244
+        // Load translation files required by the page
245
+        $outputlangs->loadLangs(array("main", "dict", "companies", "bills"));
246
+
247
+        if ($conf->produit->dir_output)
248
+        {
249
+            // If $object is id instead of object
250
+            if (! is_object($object))
251
+            {
252
+                $id = $object;
253
+                $object = new Stock($this->db);
254
+                $result=$object->fetch($id);
255
+                if ($result < 0)
256
+                {
257
+                    dol_print_error($this->db,$object->error);
258
+                    return -1;
259
+                }
260
+            }
261
+            $stockFournisseur = new StockFournisseur($this->db);
262
+            $supplierprices = $stockFournisseur->list_stock_fournisseur_price($object->id);
263
+            $object->supplierprices = $supplierprices;
264
+
265
+            $dir = $conf->produit->dir_output;
266
+            $objectref = dol_sanitizeFileName($object->ref);
267
+            if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
268
+            $file = $dir . "/" . $objectref . ".odt";
269
+
270
+            if (! file_exists($dir))
271
+            {
272
+                if (dol_mkdir($dir) < 0)
273
+                {
274
+                    $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
275
+                    return -1;
276
+                }
277
+            }
278
+
279
+            if (file_exists($dir))
280
+            {
281
+                //print "srctemplatepath=".$srctemplatepath;	// Src filename
282
+                $newfile=basename($srctemplatepath);
283
+                $newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile);
284
+                $newfiletmp=preg_replace('/template_/i','',$newfiletmp);
285
+                $newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
286
+
287
+                $newfiletmp=$objectref.'_'.$newfiletmp;
288
+
289
+                // Get extension (ods or odt)
290
+                $newfileformat=substr($newfile, strrpos($newfile, '.')+1);
291
+                if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
292
+                {
293
+                    $format=$conf->global->MAIN_DOC_USE_TIMING;
294
+                    if ($format == '1') $format='%Y%m%d%H%M%S';
295
+                    $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
296
+                }
297
+                else
298
+                {
299
+                    $filename=$newfiletmp.'.'.$newfileformat;
300
+                }
301
+                $file=$dir.'/'.$filename;
302
+                //print "newdir=".$dir;
303
+                //print "newfile=".$newfile;
304
+                //print "file=".$file;
305
+                //print "conf->produit->dir_temp=".$conf->produit->dir_temp;
306
+
307
+                dol_mkdir($conf->produit->dir_temp);
308
+
309
+
310
+                // If CUSTOMER contact defined on stock, we use it
311
+                $usecontact=false;
312
+                $arrayidcontact=$object->getIdContact('external','CUSTOMER');
313
+                if (count($arrayidcontact) > 0)
314
+                {
315
+                    $usecontact=true;
316
+                    $result=$object->fetch_contact($arrayidcontact[0]);
317
+                }
318
+
319
+                // Recipient name
320
+                $contactobject=null;
321
+                if (! empty($usecontact))
322
+                {
323
+                    // On peut utiliser le nom de la societe du contact
324
+                    if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
325
+                    else {
326
+                                    $socobject = $object->thirdparty;
327
+                                    // if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use
328
+                                    $contactobject = $object->contact;
329
+                                }
330
+                }
331
+                else
332
+                {
333
+                    $socobject=$object->thirdparty;
334
+                }
335
+                // Make substitution
336
+                $substitutionarray=array(
337
+                '__FROM_NAME__' => $this->emetteur->name,
338
+                '__FROM_EMAIL__' => $this->emetteur->email,
339
+                '__TOTAL_TTC__' => $object->total_ttc,
340
+                '__TOTAL_HT__' => $object->total_ht,
341
+                '__TOTAL_VAT__' => $object->total_vat
342
+                );
343
+                complete_substitutions_array($substitutionarray, $langs, $object);
344
+                // Call the ODTSubstitution hook
345
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
346
+                $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
347
+
348
+                // Line of free text
349
+                $newfreetext='';
350
+                $paramfreetext='stock_FREE_TEXT';
351
+                if (! empty($conf->global->$paramfreetext))
352
+                {
353
+                    $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
354
+                }
355
+
356
+                // Open and load template
357
+                require_once ODTPHP_PATH.'odf.php';
358
+                try {
359
+                    $odfHandler = new odf(
360
+                        $srctemplatepath,
361
+                        array(
362
+                        'PATH_TO_TMP'	  => $conf->produit->dir_temp,
363
+                        'ZIP_PROXY'		  => 'PclZipProxy',	// PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
364
+                        'DELIMITER_LEFT'  => '{',
365
+                        'DELIMITER_RIGHT' => '}'
366
+                        )
367
+                    );
368
+                }
369
+                catch(Exception $e)
370
+                {
371
+                    $this->error=$e->getMessage();
372
+                    dol_syslog($e->getMessage(), LOG_INFO);
373
+                    return -1;
374
+                }
375
+                // After construction $odfHandler->contentXml contains content and
376
+                // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
377
+                // [!-- BEGIN lines --]*[!-- END lines --]
378
+                //print html_entity_decode($odfHandler->__toString());
379
+                //print exit;
380
+
381
+                $object->fetch_optionals();
382
+
383
+                // Make substitutions into odt of freetext
384
+                try {
385
+                    $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
386
+                }
387
+                catch (OdfException $e)
388
+                {
389
+                    dol_syslog($e->getMessage(), LOG_INFO);
390
+                }
391
+
392
+                // Define substitution array
393
+                $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
394
+                $array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs);
395
+                //$array_objet=$this->get_substitutionarray_object($object,$outputlangs);
396
+                $array_user=$this->get_substitutionarray_user($user,$outputlangs);
397
+                $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
398
+                $array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
399
+                $array_other=$this->get_substitutionarray_other($outputlangs);
400
+                // retrieve contact information for use in stock as contact_xxx tags
401
+                $array_thirdparty_contact = array();
402
+                if ($usecontact && is_object($contactobject)) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
403
+
404
+                $tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_other,$array_thirdparty_contact);
405
+                complete_substitutions_array($tmparray, $outputlangs, $object);
406
+
407
+                // Call the ODTSubstitution hook
408
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
409
+                $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
410
+
411
+                foreach($tmparray as $key=>$value)
412
+                {
413
+                    try {
414
+                        if (preg_match('/logo$/',$key)) // Image
415
+                        {
416
+                            if (file_exists($value)) $odfHandler->setImage($key, $value);
417
+                            else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
418
+                        }
419
+                        else    // Text
420
+                        {
421
+                            $odfHandler->setVars($key, $value, true, 'UTF-8');
422
+                        }
423
+                    }
424
+                    catch (OdfException $e)
425
+                    {
426 426
                         dol_syslog($e->getMessage(), LOG_INFO);
427
-					}
428
-				}
429
-				// Replace tags of lines
430
-				try
431
-				{
432
-					$listlines = $odfHandler->setSegment('supplierprices');
433
-					if(!empty($object->supplierprices)){
434
-						foreach ($object->supplierprices as $supplierprice)
435
-						{
436
-							$array_lines = $this->get_substitutionarray_each_var_object($supplierprice, $outputlangs);
437
-							complete_substitutions_array($array_lines, $outputlangs, $object, $supplierprice, "completesubstitutionarray_lines");
438
-							// Call the ODTSubstitutionLine hook
439
-							$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$array_lines,'line'=>$supplierprice);
440
-							$reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
441
-							foreach($array_lines as $key => $val)
442
-							{
443
-								try
444
-								{
445
-									$listlines->setVars($key, $val, true, 'UTF-8');
446
-								}
447
-								catch(OdfException $e)
448
-								{
449
-									dol_syslog($e->getMessage(), LOG_INFO);
450
-								}
451
-								catch(SegmentException $e)
452
-								{
453
-									dol_syslog($e->getMessage(), LOG_INFO);
454
-								}
455
-							}
456
-							$listlines->merge();
457
-						}
458
-					}
459
-					$odfHandler->mergeSegment($listlines);
460
-				}
461
-				catch(OdfException $e)
462
-				{
463
-					$this->error=$e->getMessage();
464
-					dol_syslog($this->error, LOG_WARNING);
465
-					return -1;
466
-				}
467
-
468
-				// Replace labels translated
469
-				$tmparray=$outputlangs->get_translations_for_substitutions();
470
-				foreach($tmparray as $key=>$value)
471
-				{
472
-					try {
473
-						$odfHandler->setVars($key, $value, true, 'UTF-8');
474
-					}
475
-					catch(OdfException $e)
476
-					{
427
+                    }
428
+                }
429
+                // Replace tags of lines
430
+                try
431
+                {
432
+                    $listlines = $odfHandler->setSegment('supplierprices');
433
+                    if(!empty($object->supplierprices)){
434
+                        foreach ($object->supplierprices as $supplierprice)
435
+                        {
436
+                            $array_lines = $this->get_substitutionarray_each_var_object($supplierprice, $outputlangs);
437
+                            complete_substitutions_array($array_lines, $outputlangs, $object, $supplierprice, "completesubstitutionarray_lines");
438
+                            // Call the ODTSubstitutionLine hook
439
+                            $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$array_lines,'line'=>$supplierprice);
440
+                            $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
441
+                            foreach($array_lines as $key => $val)
442
+                            {
443
+                                try
444
+                                {
445
+                                    $listlines->setVars($key, $val, true, 'UTF-8');
446
+                                }
447
+                                catch(OdfException $e)
448
+                                {
449
+                                    dol_syslog($e->getMessage(), LOG_INFO);
450
+                                }
451
+                                catch(SegmentException $e)
452
+                                {
453
+                                    dol_syslog($e->getMessage(), LOG_INFO);
454
+                                }
455
+                            }
456
+                            $listlines->merge();
457
+                        }
458
+                    }
459
+                    $odfHandler->mergeSegment($listlines);
460
+                }
461
+                catch(OdfException $e)
462
+                {
463
+                    $this->error=$e->getMessage();
464
+                    dol_syslog($this->error, LOG_WARNING);
465
+                    return -1;
466
+                }
467
+
468
+                // Replace labels translated
469
+                $tmparray=$outputlangs->get_translations_for_substitutions();
470
+                foreach($tmparray as $key=>$value)
471
+                {
472
+                    try {
473
+                        $odfHandler->setVars($key, $value, true, 'UTF-8');
474
+                    }
475
+                    catch(OdfException $e)
476
+                    {
477 477
                         dol_syslog($e->getMessage(), LOG_INFO);
478
-					}
479
-				}
480
-
481
-				// Call the beforeODTSave hook
482
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
483
-				$reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
484
-
485
-				// Write new file
486
-				if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
487
-					try {
488
-						$odfHandler->exportAsAttachedPDF($file);
489
-					} catch (Exception $e) {
490
-						$this->error=$e->getMessage();
478
+                    }
479
+                }
480
+
481
+                // Call the beforeODTSave hook
482
+                $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
483
+                $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
484
+
485
+                // Write new file
486
+                if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
487
+                    try {
488
+                        $odfHandler->exportAsAttachedPDF($file);
489
+                    } catch (Exception $e) {
490
+                        $this->error=$e->getMessage();
491 491
                         dol_syslog($e->getMessage(), LOG_INFO);
492
-						return -1;
493
-					}
494
-				}
495
-				else {
496
-					try {
497
-					$odfHandler->saveToDisk($file);
498
-					} catch (Exception $e) {
499
-						$this->error=$e->getMessage();
492
+                        return -1;
493
+                    }
494
+                }
495
+                else {
496
+                    try {
497
+                    $odfHandler->saveToDisk($file);
498
+                    } catch (Exception $e) {
499
+                        $this->error=$e->getMessage();
500 500
                         dol_syslog($e->getMessage(), LOG_INFO);
501
-						return -1;
502
-					}
503
-				}
501
+                        return -1;
502
+                    }
503
+                }
504 504
 
505
-				$reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
505
+                $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
506 506
 
507
-				if (! empty($conf->global->MAIN_UMASK))
508
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
507
+                if (! empty($conf->global->MAIN_UMASK))
508
+                    @chmod($file, octdec($conf->global->MAIN_UMASK));
509 509
 
510
-				$odfHandler=null;	// Destroy object
510
+                $odfHandler=null;	// Destroy object
511 511
 
512
-				$this->result = array('fullpath'=>$file);
512
+                $this->result = array('fullpath'=>$file);
513 513
 
514
-				return 1;   // Success
515
-			}
516
-			else
517
-			{
518
-				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
519
-				return -1;
520
-			}
521
-		}
514
+                return 1;   // Success
515
+            }
516
+            else
517
+            {
518
+                $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
519
+                return -1;
520
+            }
521
+        }
522 522
 
523
-		return -1;
524
-	}
523
+        return -1;
524
+    }
525 525
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/stock/doc/pdf_standard.modules.php 1 patch
Indentation   +795 added lines, -795 removed lines patch added patch discarded remove patch
@@ -41,32 +41,32 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public $db;
43 43
 
44
-	/**
44
+    /**
45 45
      * @var string model name
46 46
      */
47 47
     public $name;
48 48
 
49
-	/**
49
+    /**
50 50
      * @var string model description (short text)
51 51
      */
52 52
     public $description;
53 53
 
54
-	/**
54
+    /**
55 55
      * @var string document type
56 56
      */
57 57
     public $type;
58 58
 
59
-	/**
59
+    /**
60 60
      * @var array() Minimum version of PHP required by module.
61
-	 * e.g.: PHP ≥ 5.4 = array(5, 4)
61
+     * e.g.: PHP ≥ 5.4 = array(5, 4)
62 62
      */
63
-	public $phpmin = array(5, 4);
63
+    public $phpmin = array(5, 4);
64 64
 
65
-	/**
65
+    /**
66 66
      * Dolibarr version of the loaded document
67 67
      * @public string
68 68
      */
69
-	public $version = 'dolibarr';
69
+    public $version = 'dolibarr';
70 70
 
71 71
     /**
72 72
      * @var int page_largeur
@@ -83,177 +83,177 @@  discard block
 block discarded – undo
83 83
      */
84 84
     public $format;
85 85
 
86
-	/**
86
+    /**
87 87
      * @var int marge_gauche
88 88
      */
89
-	public $marge_gauche;
89
+    public $marge_gauche;
90 90
 
91
-	/**
91
+    /**
92 92
      * @var int marge_droite
93 93
      */
94
-	public $marge_droite;
94
+    public $marge_droite;
95 95
 
96
-	/**
96
+    /**
97 97
      * @var int marge_haute
98 98
      */
99
-	public $marge_haute;
99
+    public $marge_haute;
100 100
 
101
-	/**
101
+    /**
102 102
      * @var int marge_basse
103 103
      */
104
-	public $marge_basse;
104
+    public $marge_basse;
105
+
106
+    /**
107
+     * Issuer
108
+     * @var Societe
109
+     */
110
+    public $emetteur;
111
+
105 112
 
106 113
     /**
107
-	 * Issuer
108
-	 * @var Societe
109
-	 */
110
-	public $emetteur;
111
-
112
-
113
-	/**
114
-	 *	Constructor
115
-	 *
116
-	 *  @param		DoliDB		$db      Database handler
117
-	 */
118
-	public function __construct($db)
119
-	{
120
-		global $conf,$langs,$mysoc;
121
-
122
-		// Load traductions files requiredby by page
123
-		$langs->loadLangs(array("main", "companies"));
124
-
125
-		$this->db = $db;
126
-		$this->name = "standard";
127
-		$this->description = $langs->trans("DocumentModelStandardPDF");
128
-
129
-		// Dimension page pour format A4
130
-		$this->type = 'pdf';
131
-		$formatarray=pdf_getFormat();
132
-		$this->page_largeur = $formatarray['width'];
133
-		$this->page_hauteur = $formatarray['height'];
134
-		$this->format = array($this->page_largeur,$this->page_hauteur);
135
-		$this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
136
-		$this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
137
-		$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
138
-		$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
139
-
140
-		$this->option_logo = 1;                    // Affiche logo
141
-		$this->option_codestockservice = 0;      // Affiche code stock-service
142
-		$this->option_multilang = 1;               // Dispo en plusieurs langues
143
-		$this->option_freetext = 0;				   // Support add of a personalised text
144
-
145
-		// Recupere emetteur
146
-		$this->emetteur=$mysoc;
147
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
148
-
149
-		// Define position of columns
150
-		$this->wref = 15;
151
-		$this->posxdesc=$this->marge_gauche+1;
152
-		$this->posxlabel=$this->posxdesc+$this->wref;
153
-		$this->posxtva=80;
154
-		$this->posxqty=95;
155
-		$this->posxup=115;
156
-		$this->posxunit=135;
157
-		$this->posxdiscount=155;
158
-		$this->postotalht=175;
159
-
160
-		if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup;
161
-		$this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);	// width of images
162
-		if ($this->page_largeur < 210) // To work with US executive format
163
-		{
164
-			$this->posxpicture-=20;
165
-			$this->posxtva-=20;
166
-			$this->posxup-=20;
167
-			$this->posxqty-=20;
168
-			$this->posxunit-=20;
169
-			$this->posxdiscount-=20;
170
-			$this->postotalht-=20;
171
-		}
172
-		$this->tva=array();
173
-		$this->localtax1=array();
174
-		$this->localtax2=array();
175
-		$this->atleastoneratenotnull=0;
176
-		$this->atleastonediscount=0;
177
-	}
114
+     *	Constructor
115
+     *
116
+     *  @param		DoliDB		$db      Database handler
117
+     */
118
+    public function __construct($db)
119
+    {
120
+        global $conf,$langs,$mysoc;
121
+
122
+        // Load traductions files requiredby by page
123
+        $langs->loadLangs(array("main", "companies"));
124
+
125
+        $this->db = $db;
126
+        $this->name = "standard";
127
+        $this->description = $langs->trans("DocumentModelStandardPDF");
128
+
129
+        // Dimension page pour format A4
130
+        $this->type = 'pdf';
131
+        $formatarray=pdf_getFormat();
132
+        $this->page_largeur = $formatarray['width'];
133
+        $this->page_hauteur = $formatarray['height'];
134
+        $this->format = array($this->page_largeur,$this->page_hauteur);
135
+        $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
136
+        $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
137
+        $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
138
+        $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
139
+
140
+        $this->option_logo = 1;                    // Affiche logo
141
+        $this->option_codestockservice = 0;      // Affiche code stock-service
142
+        $this->option_multilang = 1;               // Dispo en plusieurs langues
143
+        $this->option_freetext = 0;				   // Support add of a personalised text
144
+
145
+        // Recupere emetteur
146
+        $this->emetteur=$mysoc;
147
+        if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
148
+
149
+        // Define position of columns
150
+        $this->wref = 15;
151
+        $this->posxdesc=$this->marge_gauche+1;
152
+        $this->posxlabel=$this->posxdesc+$this->wref;
153
+        $this->posxtva=80;
154
+        $this->posxqty=95;
155
+        $this->posxup=115;
156
+        $this->posxunit=135;
157
+        $this->posxdiscount=155;
158
+        $this->postotalht=175;
159
+
160
+        if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup;
161
+        $this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);	// width of images
162
+        if ($this->page_largeur < 210) // To work with US executive format
163
+        {
164
+            $this->posxpicture-=20;
165
+            $this->posxtva-=20;
166
+            $this->posxup-=20;
167
+            $this->posxqty-=20;
168
+            $this->posxunit-=20;
169
+            $this->posxdiscount-=20;
170
+            $this->postotalht-=20;
171
+        }
172
+        $this->tva=array();
173
+        $this->localtax1=array();
174
+        $this->localtax2=array();
175
+        $this->atleastoneratenotnull=0;
176
+        $this->atleastonediscount=0;
177
+    }
178 178
 
179 179
 
180 180
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
181
-	/**
182
-	 *	Function to build a document on disk using the generic odt module.
183
-	 *
184
-	 *	@param		Stock		$object				Object source to build document
185
-	 *	@param		Translate	$outputlangs		Lang output object
186
-	 * 	@param		string		$srctemplatepath	Full path of source filename for generator using a template file
187
-	 *  @param		int			$hidedetails		Do not show line details
188
-	 *  @param		int			$hidedesc			Do not show desc
189
-	 *  @param		int			$hideref			Do not show ref
190
-	 *	@return		int         					1 if OK, <=0 if KO
191
-	 */
192
-	function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
193
-	{
181
+    /**
182
+     *	Function to build a document on disk using the generic odt module.
183
+     *
184
+     *	@param		Stock		$object				Object source to build document
185
+     *	@param		Translate	$outputlangs		Lang output object
186
+     * 	@param		string		$srctemplatepath	Full path of source filename for generator using a template file
187
+     *  @param		int			$hidedetails		Do not show line details
188
+     *  @param		int			$hidedesc			Do not show desc
189
+     *  @param		int			$hideref			Do not show ref
190
+     *	@return		int         					1 if OK, <=0 if KO
191
+     */
192
+    function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
193
+    {
194 194
         // phpcs:enable
195
-		global $user,$langs,$conf,$mysoc,$db,$hookmanager;
196
-
197
-		if (! is_object($outputlangs)) $outputlangs=$langs;
198
-		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
199
-		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
200
-
201
-		// Load traductions files requiredby by page
202
-		$outputlangs->loadLangs(array("main", "dict", "companies", "bills", "stocks", "orders", "deliveries"));
203
-
204
-		$nblignes = count($object->lines);
205
-
206
-		if ($conf->stock->dir_output)
207
-		{
208
-		    // Definition of $dir and $file
209
-			if ($object->specimen)
210
-			{
211
-				$dir = $conf->stock->dir_output;
212
-				$file = $dir . "/SPECIMEN.pdf";
213
-			}
214
-			else
215
-			{
216
-				$objectref = dol_sanitizeFileName($object->ref);
217
-				$dir = $conf->stock->dir_output . "/" . $objectref;
218
-				$file = $dir . "/" . $objectref . ".pdf";
219
-			}
220
-
221
-			$stockFournisseur = new ProductFournisseur($this->db);
222
-			$supplierprices = $stockFournisseur->list_product_fournisseur_price($object->id);
223
-			$object->supplierprices = $supplierprices;
224
-
225
-			$productstatic=new Product($db);
226
-
227
-			if (! file_exists($dir))
228
-			{
229
-				if (dol_mkdir($dir) < 0)
230
-				{
231
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
232
-					return -1;
233
-				}
234
-			}
195
+        global $user,$langs,$conf,$mysoc,$db,$hookmanager;
196
+
197
+        if (! is_object($outputlangs)) $outputlangs=$langs;
198
+        // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
199
+        if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
200
+
201
+        // Load traductions files requiredby by page
202
+        $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "stocks", "orders", "deliveries"));
203
+
204
+        $nblignes = count($object->lines);
205
+
206
+        if ($conf->stock->dir_output)
207
+        {
208
+            // Definition of $dir and $file
209
+            if ($object->specimen)
210
+            {
211
+                $dir = $conf->stock->dir_output;
212
+                $file = $dir . "/SPECIMEN.pdf";
213
+            }
214
+            else
215
+            {
216
+                $objectref = dol_sanitizeFileName($object->ref);
217
+                $dir = $conf->stock->dir_output . "/" . $objectref;
218
+                $file = $dir . "/" . $objectref . ".pdf";
219
+            }
220
+
221
+            $stockFournisseur = new ProductFournisseur($this->db);
222
+            $supplierprices = $stockFournisseur->list_product_fournisseur_price($object->id);
223
+            $object->supplierprices = $supplierprices;
224
+
225
+            $productstatic=new Product($db);
226
+
227
+            if (! file_exists($dir))
228
+            {
229
+                if (dol_mkdir($dir) < 0)
230
+                {
231
+                    $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
232
+                    return -1;
233
+                }
234
+            }
235 235
 
236
-			if (file_exists($dir))
237
-			{
238
-				// Add pdfgeneration hook
239
-				if (! is_object($hookmanager))
240
-				{
241
-					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
242
-					$hookmanager=new HookManager($this->db);
243
-				}
244
-				$hookmanager->initHooks(array('pdfgeneration'));
245
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
246
-				global $action;
247
-				$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
236
+            if (file_exists($dir))
237
+            {
238
+                // Add pdfgeneration hook
239
+                if (! is_object($hookmanager))
240
+                {
241
+                    include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
242
+                    $hookmanager=new HookManager($this->db);
243
+                }
244
+                $hookmanager->initHooks(array('pdfgeneration'));
245
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
246
+                global $action;
247
+                $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
248 248
 
249
-				// Create pdf instance
250
-				$pdf=pdf_getInstance($this->format);
251
-				$default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
252
-				$pdf->SetAutoPageBreak(1,0);
249
+                // Create pdf instance
250
+                $pdf=pdf_getInstance($this->format);
251
+                $default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
252
+                $pdf->SetAutoPageBreak(1,0);
253 253
 
254
-				$heightforinfotot = 40;	// Height reserved to output the info and total part
255
-		        $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
256
-	            $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
254
+                $heightforinfotot = 40;	// Height reserved to output the info and total part
255
+                $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
256
+                $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
257 257
 
258 258
                 if (class_exists('TCPDF'))
259 259
                 {
@@ -268,313 +268,313 @@  discard block
 block discarded – undo
268 268
                     $tplidx = $pdf->importPage(1);
269 269
                 }
270 270
 
271
-				$pdf->Open();
272
-				$pagenb=0;
273
-				$pdf->SetDrawColor(128,128,128);
274
-
275
-				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
276
-				$pdf->SetSubject($outputlangs->transnoentities("Stock"));
277
-				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
278
-				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
279
-				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Stock")." ".$outputlangs->convToOutputCharset($object->libelle));
280
-				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
281
-
282
-				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
283
-
284
-
285
-				// New page
286
-				$pdf->AddPage();
287
-				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
288
-				$pagenb++;
289
-				$this->_pagehead($pdf, $object, 1, $outputlangs);
290
-				$pdf->SetFont('','', $default_font_size - 1);
291
-				$pdf->MultiCell(0, 3, '');		// Set interline to 3
292
-				$pdf->SetTextColor(0,0,0);
293
-
294
-				$tab_top = 42;
295
-				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
296
-				$tab_height = 130;
297
-				$tab_height_newpage = 150;
298
-
299
-				/* ************************************************************************** */
300
-				/*                                                                            */
301
-				/* Affichage de la liste des produits de l'entrepot                           */
302
-				/*                                                                            */
303
-				/* ************************************************************************** */
304
-
305
-				$nexY+=5;
306
-				$nexY = $pdf->GetY();
307
-				$nexY+=10;
308
-
309
-				$totalunit=0;
310
-				$totalvalue=$totalvaluesell=0;
311
-
312
-				$sql = "SELECT p.rowid as rowid, p.ref, p.label as produit, p.tobatch, p.fk_product_type as type, p.pmp as ppmp, p.price, p.price_ttc, p.entity,";
313
-				$sql.= " ps.reel as value";
314
-				$sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps, ".MAIN_DB_PREFIX."product as p";
315
-				$sql.= " WHERE ps.fk_product = p.rowid";
316
-				$sql.= " AND ps.reel <> 0";	// We do not show if stock is 0 (no product in this warehouse)
317
-				$sql.= " AND ps.fk_entrepot = ".$object->id;
318
-				$sql.= $db->order($sortfield,$sortorder);
319
-
320
-				//dol_syslog('List products', LOG_DEBUG);
321
-				$resql = $db->query($sql);
322
-				if ($resql)
323
-				{
324
-					$num = $db->num_rows($resql);
325
-					$i = 0;
326
-					$nblignes = $num;
327
-					for ($i = 0 ; $i < $nblignes ; $i++)
328
-					{
329
-						$objp = $db->fetch_object($resql);
330
-
331
-						// Multilangs
332
-						if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
333
-						{
334
-							$sql = "SELECT label";
335
-							$sql.= " FROM ".MAIN_DB_PREFIX."product_lang";
336
-							$sql.= " WHERE fk_product=".$objp->rowid;
337
-							$sql.= " AND lang='". $langs->getDefaultLang() ."'";
338
-							$sql.= " LIMIT 1";
339
-
340
-							$result = $db->query($sql);
341
-							if ($result)
342
-							{
343
-								$objtp = $db->fetch_object($result);
344
-								if ($objtp->label != '') $objp->produit = $objtp->label;
345
-							}
346
-						}
347
-
348
-						$curY = $nexY;
349
-						$pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
350
-						$pdf->SetTextColor(0,0,0);
351
-
352
-						$pdf->setTopMargin($tab_top_newpage);
353
-						$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
354
-						$pageposbefore=$pdf->getPage();
355
-
356
-						// Description of product line
357
-						$curX = $this->posxdesc-1;
358
-
359
-						$showpricebeforepagebreak=1;
360
-
361
-						$pdf->startTransaction();
362
-						pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc);
363
-						$pageposafter=$pdf->getPage();
364
-						if ($pageposafter > $pageposbefore)	// There is a pagebreak
365
-						{
366
-							$pdf->rollbackTransaction(true);
367
-							$pageposafter=$pageposbefore;
368
-							//print $pageposafter.'-'.$pageposbefore;exit;
369
-							$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
370
-							pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc);
371
-							$pageposafter=$pdf->getPage();
372
-							$posyafter=$pdf->GetY();
373
-							if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
374
-							{
375
-								if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
376
-								{
377
-									$pdf->AddPage('','',true);
378
-									if (! empty($tplidx)) $pdf->useTemplate($tplidx);
379
-									if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
380
-									$pdf->setPage($pageposafter+1);
381
-								}
382
-							}
383
-							else
384
-							{
385
-								// We found a page break
386
-								$showpricebeforepagebreak=0;
387
-							}
388
-						}
389
-						else	// No pagebreak
390
-						{
391
-							$pdf->commitTransaction();
392
-						}
393
-						$posYAfterDescription=$pdf->GetY();
394
-
395
-						$nexY = $pdf->GetY();
396
-						$pageposafter=$pdf->getPage();
397
-
398
-						$pdf->setPage($pageposbefore);
399
-						$pdf->setTopMargin($this->marge_haute);
400
-						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
401
-
402
-						// We suppose that a too long description is moved completely on next page
403
-						if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
404
-							$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
405
-						}
406
-
407
-						$pdf->SetFont('','',  $default_font_size - 1);   // On repositionne la police par defaut
408
-
409
-						$productstatic->id=$objp->rowid;
410
-						$productstatic->ref = $objp->ref;
411
-						$productstatic->label = $objp->produit;
412
-						$productstatic->type=$objp->type;
413
-						$productstatic->entity=$objp->entity;
414
-						$productstatic->status_batch=$objp->tobatch;
415
-
416
-						// Ref.
417
-						$pdf->SetXY($this->posxdesc, $curY);
418
-						$pdf->MultiCell($this->wref, 3, $productstatic->ref, 0, 'L');
419
-
420
-						// Label
421
-						$pdf->SetXY($this->posxlabel+0.8, $curY);
422
-						$pdf->MultiCell($this->posxqty-$this->posxlabel-0.8, 3, $objp->produit, 0, 'L');
423
-
424
-						// Quantity
425
-						$valtoshow=price2num($objp->value, 'MS');
426
-						$towrite = (empty($valtoshow)?'0':$valtoshow);
427
-
428
-						$pdf->SetXY($this->posxqty, $curY);
429
-						$pdf->MultiCell($this->posxup-$this->posxqty-0.8, 3, $towrite, 0, 'R');
430
-
431
-						$totalunit+=$objp->value;
432
-
433
-						$pdf->SetXY($this->posxup, $curY);
434
-						$pdf->MultiCell($this->posxunit-$this->posxup-0.8, 3, price(price2num($objp->ppmp,'MU'), 0, $outputlangs), 0, 'R');
435
-
436
-						// Total PMP
437
-						$pdf->SetXY($this->posxunit, $curY);
438
-						$pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 3, price(price2num($objp->ppmp*$objp->value,'MT'), 0, $outputlangs), 0, 'R');
439
-						$totalvalue+=price2num($objp->ppmp*$objp->value,'MT');
440
-
441
-						// Price sell min
442
-						if (empty($conf->global->PRODUIT_MULTIPRICES))
443
-						{
444
-							$pricemin=$objp->price;
445
-							$pdf->SetXY($this->posxdiscount, $curY);
446
-							$pdf->MultiCell($this->postotalht-$this->posxdiscount, 3, price(price2num($pricemin,'MU'), 0, $outputlangs), 0, 'R', 0);
447
-
448
-							// Total sell min
449
-							$pdf->SetXY($this->postotalht, $curY);
450
-							$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, price(price2num($pricemin*$objp->value,'MT'), 0, $outputlangs), 0, 'R', 0);
451
-						}
452
-						$totalvaluesell+=price2num($pricemin*$objp->value,'MT');
453
-
454
-						// Add line
455
-						if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
456
-						{
457
-							$pdf->setPage($pageposafter);
458
-							$pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
459
-							//$pdf->SetDrawColor(190,190,200);
460
-							$pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
461
-							$pdf->SetLineStyle(array('dash'=>0));
462
-						}
463
-
464
-						$nexY+=2;    // Passe espace entre les lignes
465
-
466
-						// Detect if some page were added automatically and output _tableau for past pages
467
-						while ($pagenb < $pageposafter)
468
-						{
469
-							$pdf->setPage($pagenb);
470
-							if ($pagenb == 1)
471
-							{
472
-								$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
473
-							}
474
-							else
475
-							{
476
-								$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
477
-							}
478
-							$this->_pagefoot($pdf,$object,$outputlangs,1);
479
-							$pagenb++;
480
-							$pdf->setPage($pagenb);
481
-							$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
482
-							if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
483
-						}
484
-						if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
485
-						{
486
-							if ($pagenb == 1)
487
-							{
488
-								$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
489
-							}
490
-							else
491
-							{
492
-								$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
493
-							}
494
-							$this->_pagefoot($pdf,$object,$outputlangs,1);
495
-							// New page
496
-							$pdf->AddPage();
497
-							if (! empty($tplidx)) $pdf->useTemplate($tplidx);
498
-							$pagenb++;
499
-							if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
500
-						}
501
-					}
502
-
503
-					$db->free($resql);
504
-
505
-					/**
506
-					 * footer table
507
-					 */
508
-					$nexY = $pdf->GetY();
509
-					$nexY+=2;
510
-					$curY = $nexY;
511
-
512
-					$pdf->SetLineStyle(array('dash'=>'0','color'=>array(220,26,26)));
513
-					$pdf->line($this->marge_gauche, $curY-1, $this->page_largeur-$this->marge_droite, $curY-1);
514
-					$pdf->SetLineStyle(array('dash'=>0));
515
-
516
-					$pdf->SetFont('','B',$default_font_size-1);
517
-					$pdf->SetTextColor(0,0,120);
518
-
519
-					// Ref.
520
-					$pdf->SetXY($this->posxdesc, $curY);
521
-					$pdf->MultiCell($this->wref, 3, $langs->trans("Total"), 0, 'L');
522
-
523
-					// Quantity
524
-					$valtoshow=price2num($totalunit, 'MS');
525
-					$towrite = empty($valtoshow)?'0':$valtoshow;
526
-
527
-					$pdf->SetXY($this->posxqty, $curY);
528
-					$pdf->MultiCell($this->posxup-$this->posxqty-0.8, 3, $towrite, 0, 'R');
529
-
530
-					// Total PMP
531
-					$pdf->SetXY($this->posxunit, $curY);
532
-					$pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 3, price(price2num($totalvalue,'MT'), 0, $outputlangs), 0, 'R');
533
-
534
-					// Price sell min
535
-					if (empty($conf->global->PRODUIT_MULTIPRICES))
536
-					{
537
-						// Total sell min
538
-						$pdf->SetXY($this->postotalht, $curY);
539
-						$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, price(price2num($totalvaluesell,'MT'), 0, $outputlangs), 0, 'R', 0);
540
-					}
541
-				}
542
-				else
543
-				{
544
-					dol_print_error($db);
545
-				}
271
+                $pdf->Open();
272
+                $pagenb=0;
273
+                $pdf->SetDrawColor(128,128,128);
274
+
275
+                $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
276
+                $pdf->SetSubject($outputlangs->transnoentities("Stock"));
277
+                $pdf->SetCreator("Dolibarr ".DOL_VERSION);
278
+                $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
279
+                $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Stock")." ".$outputlangs->convToOutputCharset($object->libelle));
280
+                if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
281
+
282
+                $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
283
+
284
+
285
+                // New page
286
+                $pdf->AddPage();
287
+                if (! empty($tplidx)) $pdf->useTemplate($tplidx);
288
+                $pagenb++;
289
+                $this->_pagehead($pdf, $object, 1, $outputlangs);
290
+                $pdf->SetFont('','', $default_font_size - 1);
291
+                $pdf->MultiCell(0, 3, '');		// Set interline to 3
292
+                $pdf->SetTextColor(0,0,0);
293
+
294
+                $tab_top = 42;
295
+                $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
296
+                $tab_height = 130;
297
+                $tab_height_newpage = 150;
298
+
299
+                /* ************************************************************************** */
300
+                /*                                                                            */
301
+                /* Affichage de la liste des produits de l'entrepot                           */
302
+                /*                                                                            */
303
+                /* ************************************************************************** */
304
+
305
+                $nexY+=5;
306
+                $nexY = $pdf->GetY();
307
+                $nexY+=10;
308
+
309
+                $totalunit=0;
310
+                $totalvalue=$totalvaluesell=0;
311
+
312
+                $sql = "SELECT p.rowid as rowid, p.ref, p.label as produit, p.tobatch, p.fk_product_type as type, p.pmp as ppmp, p.price, p.price_ttc, p.entity,";
313
+                $sql.= " ps.reel as value";
314
+                $sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps, ".MAIN_DB_PREFIX."product as p";
315
+                $sql.= " WHERE ps.fk_product = p.rowid";
316
+                $sql.= " AND ps.reel <> 0";	// We do not show if stock is 0 (no product in this warehouse)
317
+                $sql.= " AND ps.fk_entrepot = ".$object->id;
318
+                $sql.= $db->order($sortfield,$sortorder);
319
+
320
+                //dol_syslog('List products', LOG_DEBUG);
321
+                $resql = $db->query($sql);
322
+                if ($resql)
323
+                {
324
+                    $num = $db->num_rows($resql);
325
+                    $i = 0;
326
+                    $nblignes = $num;
327
+                    for ($i = 0 ; $i < $nblignes ; $i++)
328
+                    {
329
+                        $objp = $db->fetch_object($resql);
330
+
331
+                        // Multilangs
332
+                        if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
333
+                        {
334
+                            $sql = "SELECT label";
335
+                            $sql.= " FROM ".MAIN_DB_PREFIX."product_lang";
336
+                            $sql.= " WHERE fk_product=".$objp->rowid;
337
+                            $sql.= " AND lang='". $langs->getDefaultLang() ."'";
338
+                            $sql.= " LIMIT 1";
339
+
340
+                            $result = $db->query($sql);
341
+                            if ($result)
342
+                            {
343
+                                $objtp = $db->fetch_object($result);
344
+                                if ($objtp->label != '') $objp->produit = $objtp->label;
345
+                            }
346
+                        }
347
+
348
+                        $curY = $nexY;
349
+                        $pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
350
+                        $pdf->SetTextColor(0,0,0);
351
+
352
+                        $pdf->setTopMargin($tab_top_newpage);
353
+                        $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
354
+                        $pageposbefore=$pdf->getPage();
355
+
356
+                        // Description of product line
357
+                        $curX = $this->posxdesc-1;
358
+
359
+                        $showpricebeforepagebreak=1;
360
+
361
+                        $pdf->startTransaction();
362
+                        pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc);
363
+                        $pageposafter=$pdf->getPage();
364
+                        if ($pageposafter > $pageposbefore)	// There is a pagebreak
365
+                        {
366
+                            $pdf->rollbackTransaction(true);
367
+                            $pageposafter=$pageposbefore;
368
+                            //print $pageposafter.'-'.$pageposbefore;exit;
369
+                            $pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
370
+                            pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc);
371
+                            $pageposafter=$pdf->getPage();
372
+                            $posyafter=$pdf->GetY();
373
+                            if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
374
+                            {
375
+                                if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
376
+                                {
377
+                                    $pdf->AddPage('','',true);
378
+                                    if (! empty($tplidx)) $pdf->useTemplate($tplidx);
379
+                                    if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
380
+                                    $pdf->setPage($pageposafter+1);
381
+                                }
382
+                            }
383
+                            else
384
+                            {
385
+                                // We found a page break
386
+                                $showpricebeforepagebreak=0;
387
+                            }
388
+                        }
389
+                        else	// No pagebreak
390
+                        {
391
+                            $pdf->commitTransaction();
392
+                        }
393
+                        $posYAfterDescription=$pdf->GetY();
394
+
395
+                        $nexY = $pdf->GetY();
396
+                        $pageposafter=$pdf->getPage();
397
+
398
+                        $pdf->setPage($pageposbefore);
399
+                        $pdf->setTopMargin($this->marge_haute);
400
+                        $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
401
+
402
+                        // We suppose that a too long description is moved completely on next page
403
+                        if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
404
+                            $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
405
+                        }
406
+
407
+                        $pdf->SetFont('','',  $default_font_size - 1);   // On repositionne la police par defaut
408
+
409
+                        $productstatic->id=$objp->rowid;
410
+                        $productstatic->ref = $objp->ref;
411
+                        $productstatic->label = $objp->produit;
412
+                        $productstatic->type=$objp->type;
413
+                        $productstatic->entity=$objp->entity;
414
+                        $productstatic->status_batch=$objp->tobatch;
415
+
416
+                        // Ref.
417
+                        $pdf->SetXY($this->posxdesc, $curY);
418
+                        $pdf->MultiCell($this->wref, 3, $productstatic->ref, 0, 'L');
419
+
420
+                        // Label
421
+                        $pdf->SetXY($this->posxlabel+0.8, $curY);
422
+                        $pdf->MultiCell($this->posxqty-$this->posxlabel-0.8, 3, $objp->produit, 0, 'L');
423
+
424
+                        // Quantity
425
+                        $valtoshow=price2num($objp->value, 'MS');
426
+                        $towrite = (empty($valtoshow)?'0':$valtoshow);
427
+
428
+                        $pdf->SetXY($this->posxqty, $curY);
429
+                        $pdf->MultiCell($this->posxup-$this->posxqty-0.8, 3, $towrite, 0, 'R');
430
+
431
+                        $totalunit+=$objp->value;
432
+
433
+                        $pdf->SetXY($this->posxup, $curY);
434
+                        $pdf->MultiCell($this->posxunit-$this->posxup-0.8, 3, price(price2num($objp->ppmp,'MU'), 0, $outputlangs), 0, 'R');
435
+
436
+                        // Total PMP
437
+                        $pdf->SetXY($this->posxunit, $curY);
438
+                        $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 3, price(price2num($objp->ppmp*$objp->value,'MT'), 0, $outputlangs), 0, 'R');
439
+                        $totalvalue+=price2num($objp->ppmp*$objp->value,'MT');
440
+
441
+                        // Price sell min
442
+                        if (empty($conf->global->PRODUIT_MULTIPRICES))
443
+                        {
444
+                            $pricemin=$objp->price;
445
+                            $pdf->SetXY($this->posxdiscount, $curY);
446
+                            $pdf->MultiCell($this->postotalht-$this->posxdiscount, 3, price(price2num($pricemin,'MU'), 0, $outputlangs), 0, 'R', 0);
447
+
448
+                            // Total sell min
449
+                            $pdf->SetXY($this->postotalht, $curY);
450
+                            $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, price(price2num($pricemin*$objp->value,'MT'), 0, $outputlangs), 0, 'R', 0);
451
+                        }
452
+                        $totalvaluesell+=price2num($pricemin*$objp->value,'MT');
453
+
454
+                        // Add line
455
+                        if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
456
+                        {
457
+                            $pdf->setPage($pageposafter);
458
+                            $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
459
+                            //$pdf->SetDrawColor(190,190,200);
460
+                            $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
461
+                            $pdf->SetLineStyle(array('dash'=>0));
462
+                        }
463
+
464
+                        $nexY+=2;    // Passe espace entre les lignes
465
+
466
+                        // Detect if some page were added automatically and output _tableau for past pages
467
+                        while ($pagenb < $pageposafter)
468
+                        {
469
+                            $pdf->setPage($pagenb);
470
+                            if ($pagenb == 1)
471
+                            {
472
+                                $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
473
+                            }
474
+                            else
475
+                            {
476
+                                $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
477
+                            }
478
+                            $this->_pagefoot($pdf,$object,$outputlangs,1);
479
+                            $pagenb++;
480
+                            $pdf->setPage($pagenb);
481
+                            $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
482
+                            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
483
+                        }
484
+                        if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
485
+                        {
486
+                            if ($pagenb == 1)
487
+                            {
488
+                                $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
489
+                            }
490
+                            else
491
+                            {
492
+                                $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
493
+                            }
494
+                            $this->_pagefoot($pdf,$object,$outputlangs,1);
495
+                            // New page
496
+                            $pdf->AddPage();
497
+                            if (! empty($tplidx)) $pdf->useTemplate($tplidx);
498
+                            $pagenb++;
499
+                            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
500
+                        }
501
+                    }
502
+
503
+                    $db->free($resql);
504
+
505
+                    /**
506
+                     * footer table
507
+                     */
508
+                    $nexY = $pdf->GetY();
509
+                    $nexY+=2;
510
+                    $curY = $nexY;
511
+
512
+                    $pdf->SetLineStyle(array('dash'=>'0','color'=>array(220,26,26)));
513
+                    $pdf->line($this->marge_gauche, $curY-1, $this->page_largeur-$this->marge_droite, $curY-1);
514
+                    $pdf->SetLineStyle(array('dash'=>0));
515
+
516
+                    $pdf->SetFont('','B',$default_font_size-1);
517
+                    $pdf->SetTextColor(0,0,120);
518
+
519
+                    // Ref.
520
+                    $pdf->SetXY($this->posxdesc, $curY);
521
+                    $pdf->MultiCell($this->wref, 3, $langs->trans("Total"), 0, 'L');
522
+
523
+                    // Quantity
524
+                    $valtoshow=price2num($totalunit, 'MS');
525
+                    $towrite = empty($valtoshow)?'0':$valtoshow;
526
+
527
+                    $pdf->SetXY($this->posxqty, $curY);
528
+                    $pdf->MultiCell($this->posxup-$this->posxqty-0.8, 3, $towrite, 0, 'R');
529
+
530
+                    // Total PMP
531
+                    $pdf->SetXY($this->posxunit, $curY);
532
+                    $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 3, price(price2num($totalvalue,'MT'), 0, $outputlangs), 0, 'R');
533
+
534
+                    // Price sell min
535
+                    if (empty($conf->global->PRODUIT_MULTIPRICES))
536
+                    {
537
+                        // Total sell min
538
+                        $pdf->SetXY($this->postotalht, $curY);
539
+                        $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, price(price2num($totalvaluesell,'MT'), 0, $outputlangs), 0, 'R', 0);
540
+                    }
541
+                }
542
+                else
543
+                {
544
+                    dol_print_error($db);
545
+                }
546 546
 
547
-				if ($notetoshow)
548
-				{
549
-					$substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
550
-					complete_substitutions_array($substitutionarray, $outputlangs, $object);
551
-					$notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
547
+                if ($notetoshow)
548
+                {
549
+                    $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
550
+                    complete_substitutions_array($substitutionarray, $outputlangs, $object);
551
+                    $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
552 552
 
553
-					$tab_top = 88;
553
+                    $tab_top = 88;
554 554
 
555
-					$pdf->SetFont('','', $default_font_size - 1);
556
-					$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
557
-					$nexY = $pdf->GetY();
558
-					$height_note=$nexY-$tab_top;
555
+                    $pdf->SetFont('','', $default_font_size - 1);
556
+                    $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
557
+                    $nexY = $pdf->GetY();
558
+                    $height_note=$nexY-$tab_top;
559 559
 
560
-					// Rect prend une longueur en 3eme param
561
-					$pdf->SetDrawColor(192,192,192);
562
-					$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
560
+                    // Rect prend une longueur en 3eme param
561
+                    $pdf->SetDrawColor(192,192,192);
562
+                    $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
563 563
 
564
-					$tab_height = $tab_height - $height_note;
565
-					$tab_top = $nexY+6;
566
-				}
567
-				else
568
-				{
569
-					$height_note=0;
570
-				}
564
+                    $tab_height = $tab_height - $height_note;
565
+                    $tab_top = $nexY+6;
566
+                }
567
+                else
568
+                {
569
+                    $height_note=0;
570
+                }
571 571
 
572
-				$iniY = $tab_top + 7;
573
-				$curY = $tab_top + 7;
574
-				$nexY = $tab_top + 7;
572
+                $iniY = $tab_top + 7;
573
+                $curY = $tab_top + 7;
574
+                $nexY = $tab_top + 7;
575 575
 
576
-				// Loop on each lines
577
-				/*
576
+                // Loop on each lines
577
+                /*
578 578
 				for ($i = 0 ; $i < $nblignes ; $i++)
579 579
 				{
580 580
 					$curY = $nexY;
@@ -769,327 +769,327 @@  discard block
 block discarded – undo
769 769
 					}
770 770
 				}
771 771
 				*/
772
-				$tab_top = $tab_top_newpage+21;
772
+                $tab_top = $tab_top_newpage+21;
773 773
 
774
-				// Show square
775
-				if ($pagenb == 1)
776
-				{
777
-					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
778
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
779
-				}
780
-				else
781
-				{
782
-					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
783
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
784
-				}
785
-
786
-				$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
787
-
788
-				// Affiche zone infos
789
-				//$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
790
-
791
-				// Affiche zone totaux
792
-				//$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
793
-
794
-				// Pied de page
795
-				$this->_pagefoot($pdf,$object,$outputlangs);
796
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
797
-
798
-				$pdf->Close();
799
-
800
-				$pdf->Output($file,'F');
801
-
802
-				// Add pdfgeneration hook
803
-				$hookmanager->initHooks(array('pdfgeneration'));
804
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
805
-				global $action;
806
-				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
807
-
808
-				if (! empty($conf->global->MAIN_UMASK))
809
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
810
-
811
-				$this->result = array('fullpath'=>$file);
812
-
813
-				return 1;   // Pas d'erreur
814
-			}
815
-			else
816
-			{
817
-				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
818
-				return 0;
819
-			}
820
-		}
821
-		else
822
-		{
823
-			$this->error=$langs->trans("ErrorConstantNotDefined","PRODUCT_OUTPUTDIR");
824
-			return 0;
825
-		}
826
-	}
827
-
828
-
829
-	/**
830
-	 *   Show table for lines
831
-	 *
832
-	 *   @param		TCPDF		$pdf     		Object PDF
833
-	 *   @param		string		$tab_top		Top position of table
834
-	 *   @param		string		$tab_height		Height of table (rectangle)
835
-	 *   @param		int			$nexY			Y (not used)
836
-	 *   @param		Translate	$outputlangs	Langs object
837
-	 *   @param		int			$hidetop		1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
838
-	 *   @param		int			$hidebottom		Hide bottom bar of array
839
-	 *   @param		string		$currency		Currency code
840
-	 *   @return	void
841
-	 */
842
-	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
843
-	{
844
-	    global $conf;
845
-
846
-	    // Force to disable hidetop and hidebottom
847
-	    $hidebottom=0;
848
-	    if ($hidetop) $hidetop=-1;
849
-
850
-	    $currency = !empty($currency) ? $currency : $conf->currency;
851
-	    $default_font_size = pdf_getPDFFontSize($outputlangs);
852
-
853
-	    // Amount in (at tab_top - 1)
854
-	    $pdf->SetTextColor(0,0,0);
855
-	    $pdf->SetFont('','', $default_font_size - 2);
856
-
857
-	    if (empty($hidetop))
858
-	    {
859
-	        $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
860
-	        $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
861
-	        $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
862
-
863
-	        //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
864
-	        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));
865
-	    }
866
-
867
-	    $pdf->SetDrawColor(128,128,128);
868
-	    $pdf->SetFont('','B', $default_font_size - 3);
869
-
870
-	    // Output Rect
871
-	    //$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
774
+                // Show square
775
+                if ($pagenb == 1)
776
+                {
777
+                    $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
778
+                    $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
779
+                }
780
+                else
781
+                {
782
+                    $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
783
+                    $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
784
+                }
872 785
 
873
-		$pdf->SetLineStyle(array('dash'=>'0','color'=>array(220,26,26)));
874
-		$pdf->SetDrawColor(220,26,26);
875
-		$pdf->line($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite, $tab_top);
876
-		$pdf->SetLineStyle(array('dash'=>0));
877
-		$pdf->SetDrawColor(128,128,128);
878
-		$pdf->SetTextColor(0,0,120);
786
+                $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
879 787
 
880
-	    if (empty($hidetop))
881
-	    {
882
-	        //$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
883
-	        $pdf->SetXY($this->posxdesc-1, $tab_top+1);
884
-	        $pdf->MultiCell($this->wref,3, $outputlangs->transnoentities("Ref"),'','L');
885
-	    }
886
-
887
-		//$pdf->line($this->posxlabel-1, $tab_top, $this->posxlabel-1, $tab_top + $tab_height);
888
-		if (empty($hidetop))
889
-		{
890
-			$pdf->SetXY($this->posxlabel-3, $tab_top+1);
891
-			$pdf->MultiCell($this->posxqty-$this->posxlabel+3,2, $outputlangs->transnoentities("Label"),'','C');
892
-		}
893
-
894
-	    //$pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
895
-	    if (empty($hidetop))
896
-	    {
897
-	        $pdf->SetXY($this->posxqty-1, $tab_top+1);
898
-	        $pdf->MultiCell($this->posxup-$this->posxqty-1,2, $outputlangs->transnoentities("Units"),'','C');
899
-	    }
788
+                // Affiche zone infos
789
+                //$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
900 790
 
901
-	    //$pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
902
-	    if (empty($hidetop))
903
-	    {
904
-	        $pdf->SetXY($this->posxup-1, $tab_top+1);
905
-			$pdf->MultiCell($this->posxunit-$this->posxup-1,2, $outputlangs->transnoentities("AverageUnitPricePMPShort"),'','C');
906
-	    }
907
-
908
-		//$pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
909
-		if (empty($hidetop))
910
-		{
911
-			$pdf->SetXY($this->posxunit - 1, $tab_top + 1);
912
-			$pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("EstimatedStockValueShort"), '',
913
-				'C');
914
-		}
915
-
916
-	    //$pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
917
-	    if (empty($hidetop))
918
-	    {
919
-			$pdf->SetXY($this->posxdiscount-1, $tab_top+1);
920
-			$pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("SellPriceMin"),'','C');
921
-	    }
791
+                // Affiche zone totaux
792
+                //$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
922 793
 
923
-	    //$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
924
-	    if (empty($hidetop))
925
-	    {
926
-	        $pdf->SetXY($this->postotalht-1, $tab_top+1);
927
-	        $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht,2, $outputlangs->transnoentities("EstimatedStockValueSellShort"),'','C');
928
-	    }
929
-
930
-		$pdf->SetDrawColor(220,26,26);
931
-		$pdf->SetLineStyle(array('dash'=>'0','color'=>array(220,26,26)));
932
-		$pdf->line($this->marge_gauche, $tab_top+11, $this->page_largeur-$this->marge_droite, $tab_top+11);
933
-		$pdf->SetLineStyle(array('dash'=>0));
934
-	}
935
-
936
-	/**
937
-	 *  Show top header of page.
938
-	 *
939
-	 *  @param	TCPDF		$pdf     		Object PDF
940
-	 *  @param  Object		$object     	Object to show
941
-	 *  @param  int	    	$showaddress    0=no, 1=yes
942
-	 *  @param  Translate	$outputlangs	Object lang for output
943
-	 *  @param	string		$titlekey		Translation key to show as title of document
944
-	 *  @return	void
945
-	 */
946
-	function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="")
947
-	{
948
-	    global $conf,$langs,$db,$hookmanager;
949
-
950
-	    // Load traductions files requiredby by page
951
-		$outputlangs->loadLangs(array("main", "propal", "companies", "bills", "orders", "stocks"));
952
-
953
-	    $default_font_size = pdf_getPDFFontSize($outputlangs);
954
-
955
-	    if ($object->type == 1) $titlekey='ServiceSheet';
956
-	    else $titlekey='StockSheet';
957
-
958
-	    pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
959
-
960
-	    // Show Draft Watermark
961
-	    if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
962
-	    {
963
-	        pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
964
-	    }
794
+                // Pied de page
795
+                $this->_pagefoot($pdf,$object,$outputlangs);
796
+                if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
965 797
 
966
-	    $pdf->SetTextColor(0,0,60);
967
-	    $pdf->SetFont('','B', $default_font_size + 3);
798
+                $pdf->Close();
968 799
 
969
-	    $posy=$this->marge_haute;
970
-	    $posx=$this->page_largeur-$this->marge_droite-100;
800
+                $pdf->Output($file,'F');
971 801
 
972
-	    $pdf->SetXY($this->marge_gauche,$posy);
802
+                // Add pdfgeneration hook
803
+                $hookmanager->initHooks(array('pdfgeneration'));
804
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
805
+                global $action;
806
+                $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
973 807
 
974
-	    // Logo
975
-	    $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
976
-	    if ($this->emetteur->logo)
977
-	    {
978
-	        if (is_readable($logo))
979
-	        {
980
-	            $height=pdf_getHeightForLogo($logo);
981
-	            $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
982
-	        }
983
-	        else
984
-	        {
985
-	            $pdf->SetTextColor(200,0,0);
986
-	            $pdf->SetFont('','B', $default_font_size -2);
987
-	            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
988
-	            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
989
-	        }
990
-	    }
991
-	    else
992
-	    {
993
-	        $text=$this->emetteur->name;
994
-	        $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
995
-	    }
808
+                if (! empty($conf->global->MAIN_UMASK))
809
+                    @chmod($file, octdec($conf->global->MAIN_UMASK));
996 810
 
997
-	    $pdf->SetFont('','B', $default_font_size + 3);
998
-	    $pdf->SetXY($posx,$posy);
999
-	    $pdf->SetTextColor(0,0,60);
1000
-	    $title=$outputlangs->transnoentities("Warehouse");
1001
-	    $pdf->MultiCell(100, 3, $title, '', 'R');
811
+                $this->result = array('fullpath'=>$file);
1002 812
 
1003
-	    $pdf->SetFont('','B',$default_font_size);
813
+                return 1;   // Pas d'erreur
814
+            }
815
+            else
816
+            {
817
+                $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
818
+                return 0;
819
+            }
820
+        }
821
+        else
822
+        {
823
+            $this->error=$langs->trans("ErrorConstantNotDefined","PRODUCT_OUTPUTDIR");
824
+            return 0;
825
+        }
826
+    }
1004 827
 
1005
-	    $posy+=5;
1006
-	    $pdf->SetXY($posx,$posy);
1007
-	    $pdf->SetTextColor(0,0,60);
1008 828
 
1009
-	    $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->libelle), '', 'R');
829
+    /**
830
+     *   Show table for lines
831
+     *
832
+     *   @param		TCPDF		$pdf     		Object PDF
833
+     *   @param		string		$tab_top		Top position of table
834
+     *   @param		string		$tab_height		Height of table (rectangle)
835
+     *   @param		int			$nexY			Y (not used)
836
+     *   @param		Translate	$outputlangs	Langs object
837
+     *   @param		int			$hidetop		1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
838
+     *   @param		int			$hidebottom		Hide bottom bar of array
839
+     *   @param		string		$currency		Currency code
840
+     *   @return	void
841
+     */
842
+    function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
843
+    {
844
+        global $conf;
845
+
846
+        // Force to disable hidetop and hidebottom
847
+        $hidebottom=0;
848
+        if ($hidetop) $hidetop=-1;
849
+
850
+        $currency = !empty($currency) ? $currency : $conf->currency;
851
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
852
+
853
+        // Amount in (at tab_top - 1)
854
+        $pdf->SetTextColor(0,0,0);
855
+        $pdf->SetFont('','', $default_font_size - 2);
856
+
857
+        if (empty($hidetop))
858
+        {
859
+            $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
860
+            $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
861
+            $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
862
+
863
+            //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
864
+            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));
865
+        }
866
+
867
+        $pdf->SetDrawColor(128,128,128);
868
+        $pdf->SetFont('','B', $default_font_size - 3);
869
+
870
+        // Output Rect
871
+        //$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
872
+
873
+        $pdf->SetLineStyle(array('dash'=>'0','color'=>array(220,26,26)));
874
+        $pdf->SetDrawColor(220,26,26);
875
+        $pdf->line($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite, $tab_top);
876
+        $pdf->SetLineStyle(array('dash'=>0));
877
+        $pdf->SetDrawColor(128,128,128);
878
+        $pdf->SetTextColor(0,0,120);
879
+
880
+        if (empty($hidetop))
881
+        {
882
+            //$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
883
+            $pdf->SetXY($this->posxdesc-1, $tab_top+1);
884
+            $pdf->MultiCell($this->wref,3, $outputlangs->transnoentities("Ref"),'','L');
885
+        }
886
+
887
+        //$pdf->line($this->posxlabel-1, $tab_top, $this->posxlabel-1, $tab_top + $tab_height);
888
+        if (empty($hidetop))
889
+        {
890
+            $pdf->SetXY($this->posxlabel-3, $tab_top+1);
891
+            $pdf->MultiCell($this->posxqty-$this->posxlabel+3,2, $outputlangs->transnoentities("Label"),'','C');
892
+        }
893
+
894
+        //$pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
895
+        if (empty($hidetop))
896
+        {
897
+            $pdf->SetXY($this->posxqty-1, $tab_top+1);
898
+            $pdf->MultiCell($this->posxup-$this->posxqty-1,2, $outputlangs->transnoentities("Units"),'','C');
899
+        }
900
+
901
+        //$pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
902
+        if (empty($hidetop))
903
+        {
904
+            $pdf->SetXY($this->posxup-1, $tab_top+1);
905
+            $pdf->MultiCell($this->posxunit-$this->posxup-1,2, $outputlangs->transnoentities("AverageUnitPricePMPShort"),'','C');
906
+        }
907
+
908
+        //$pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
909
+        if (empty($hidetop))
910
+        {
911
+            $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
912
+            $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("EstimatedStockValueShort"), '',
913
+                'C');
914
+        }
915
+
916
+        //$pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
917
+        if (empty($hidetop))
918
+        {
919
+            $pdf->SetXY($this->posxdiscount-1, $tab_top+1);
920
+            $pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("SellPriceMin"),'','C');
921
+        }
922
+
923
+        //$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
924
+        if (empty($hidetop))
925
+        {
926
+            $pdf->SetXY($this->postotalht-1, $tab_top+1);
927
+            $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht,2, $outputlangs->transnoentities("EstimatedStockValueSellShort"),'','C');
928
+        }
929
+
930
+        $pdf->SetDrawColor(220,26,26);
931
+        $pdf->SetLineStyle(array('dash'=>'0','color'=>array(220,26,26)));
932
+        $pdf->line($this->marge_gauche, $tab_top+11, $this->page_largeur-$this->marge_droite, $tab_top+11);
933
+        $pdf->SetLineStyle(array('dash'=>0));
934
+    }
1010 935
 
1011
-	    $posy+=5;
1012
-	    $pdf->SetFont('','', $default_font_size - 1);
1013
-		$pdf->SetXY($posx,$posy);
1014
-	    $pdf->SetTextColor(0,0,60);
1015
-	    $pdf->MultiCell(100, 3, $outputlangs->transnoentities("LocationSummary").' :', '', 'R');
1016
-
1017
-		$posy+=4;
1018
-		$pdf->SetXY($posx-50,$posy);
1019
-		$pdf->MultiCell(150, 3, $object->lieu, '', 'R');
1020
-
1021
-
1022
-		// Parent entrepot
1023
-		$posy+=4;
1024
-		$pdf->SetXY($posx,$posy);
1025
-		$pdf->SetTextColor(0,0,60);
1026
-		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ParentWarehouse").' :', '', 'R');
1027
-
1028
-		$posy+=4;
1029
-		$pdf->SetXY($posx-50,$posy);
1030
-		$e = new Entrepot($db);
1031
-		if(!empty($object->fk_parent) && $e->fetch($object->fk_parent) > 0)
1032
-		{
1033
-			$pdf->MultiCell(150, 3, $e->libelle, '', 'R');
1034
-		}
1035
-		else
1036
-		{
1037
-			$pdf->MultiCell(150, 3, $outputlangs->transnoentities("None"), '', 'R');
1038
-		}
1039
-
1040
-		// Description
1041
-		$nexY = $pdf->GetY();
1042
-		$nexY+=5;
1043
-		$pdf->SetXY($posx,$posy);
1044
-		$pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("Description").' : </b>'.nl2br($object->description), 0, 1);
1045
-		$nexY = $pdf->GetY();
1046
-
1047
-		$calcproductsunique=$object->nb_different_products();
1048
-		$calcproducts=$object->nb_products();
1049
-
1050
-		// Total nb of different products
1051
-		$pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("NumberOfDifferentProducts").' : </b>'.(empty($calcproductsunique['nb'])?'0':$calcproductsunique['nb']), 0, 1);
1052
-		$nexY = $pdf->GetY();
1053
-
1054
-		// Nb of products
1055
-		$valtoshow=price2num($calcproducts['nb'], 'MS');
1056
-		$pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("NumberOfProducts").' : </b>'.(empty($valtoshow)?'0':$valtoshow), 0, 1);
1057
-		$nexY = $pdf->GetY();
1058
-
1059
-		// Value
1060
-		$pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("EstimatedStockValueShort").' : </b>'. price((empty($calcproducts['value'])?'0':price2num($calcproducts['value'],'MT')), 0, $langs, 0, -1, -1, $conf->currency), 0, 1);
1061
-		$nexY = $pdf->GetY();
1062
-
1063
-
1064
-		// Last movement
1065
-		$sql = "SELECT max(m.datem) as datem";
1066
-		$sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
1067
-		$sql .= " WHERE m.fk_entrepot = '".$object->id."'";
1068
-		$resqlbis = $db->query($sql);
1069
-		if ($resqlbis)
1070
-		{
1071
-			$obj = $db->fetch_object($resqlbis);
1072
-			$lastmovementdate=$db->jdate($obj->datem);
1073
-		}
1074
-		else
1075
-		{
1076
-			dol_print_error($db);
1077
-		}
1078
-
1079
-		if ($lastmovementdate)
1080
-		{
1081
-			$toWrite = dol_print_date($lastmovementdate,'dayhour').' ';
1082
-		}
1083
-		else
1084
-		{
1085
-			$toWrite = $outputlangs->transnoentities("None");
1086
-		}
1087
-
1088
-		$pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("LastMovement").' : </b>'.$toWrite, 0, 1);
1089
-		$nexY = $pdf->GetY();
1090
-
1091
-
1092
-	    /*if ($object->ref_client)
936
+    /**
937
+     *  Show top header of page.
938
+     *
939
+     *  @param	TCPDF		$pdf     		Object PDF
940
+     *  @param  Object		$object     	Object to show
941
+     *  @param  int	    	$showaddress    0=no, 1=yes
942
+     *  @param  Translate	$outputlangs	Object lang for output
943
+     *  @param	string		$titlekey		Translation key to show as title of document
944
+     *  @return	void
945
+     */
946
+    function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="")
947
+    {
948
+        global $conf,$langs,$db,$hookmanager;
949
+
950
+        // Load traductions files requiredby by page
951
+        $outputlangs->loadLangs(array("main", "propal", "companies", "bills", "orders", "stocks"));
952
+
953
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
954
+
955
+        if ($object->type == 1) $titlekey='ServiceSheet';
956
+        else $titlekey='StockSheet';
957
+
958
+        pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
959
+
960
+        // Show Draft Watermark
961
+        if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
962
+        {
963
+            pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
964
+        }
965
+
966
+        $pdf->SetTextColor(0,0,60);
967
+        $pdf->SetFont('','B', $default_font_size + 3);
968
+
969
+        $posy=$this->marge_haute;
970
+        $posx=$this->page_largeur-$this->marge_droite-100;
971
+
972
+        $pdf->SetXY($this->marge_gauche,$posy);
973
+
974
+        // Logo
975
+        $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
976
+        if ($this->emetteur->logo)
977
+        {
978
+            if (is_readable($logo))
979
+            {
980
+                $height=pdf_getHeightForLogo($logo);
981
+                $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
982
+            }
983
+            else
984
+            {
985
+                $pdf->SetTextColor(200,0,0);
986
+                $pdf->SetFont('','B', $default_font_size -2);
987
+                $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
988
+                $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
989
+            }
990
+        }
991
+        else
992
+        {
993
+            $text=$this->emetteur->name;
994
+            $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
995
+        }
996
+
997
+        $pdf->SetFont('','B', $default_font_size + 3);
998
+        $pdf->SetXY($posx,$posy);
999
+        $pdf->SetTextColor(0,0,60);
1000
+        $title=$outputlangs->transnoentities("Warehouse");
1001
+        $pdf->MultiCell(100, 3, $title, '', 'R');
1002
+
1003
+        $pdf->SetFont('','B',$default_font_size);
1004
+
1005
+        $posy+=5;
1006
+        $pdf->SetXY($posx,$posy);
1007
+        $pdf->SetTextColor(0,0,60);
1008
+
1009
+        $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->libelle), '', 'R');
1010
+
1011
+        $posy+=5;
1012
+        $pdf->SetFont('','', $default_font_size - 1);
1013
+        $pdf->SetXY($posx,$posy);
1014
+        $pdf->SetTextColor(0,0,60);
1015
+        $pdf->MultiCell(100, 3, $outputlangs->transnoentities("LocationSummary").' :', '', 'R');
1016
+
1017
+        $posy+=4;
1018
+        $pdf->SetXY($posx-50,$posy);
1019
+        $pdf->MultiCell(150, 3, $object->lieu, '', 'R');
1020
+
1021
+
1022
+        // Parent entrepot
1023
+        $posy+=4;
1024
+        $pdf->SetXY($posx,$posy);
1025
+        $pdf->SetTextColor(0,0,60);
1026
+        $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ParentWarehouse").' :', '', 'R');
1027
+
1028
+        $posy+=4;
1029
+        $pdf->SetXY($posx-50,$posy);
1030
+        $e = new Entrepot($db);
1031
+        if(!empty($object->fk_parent) && $e->fetch($object->fk_parent) > 0)
1032
+        {
1033
+            $pdf->MultiCell(150, 3, $e->libelle, '', 'R');
1034
+        }
1035
+        else
1036
+        {
1037
+            $pdf->MultiCell(150, 3, $outputlangs->transnoentities("None"), '', 'R');
1038
+        }
1039
+
1040
+        // Description
1041
+        $nexY = $pdf->GetY();
1042
+        $nexY+=5;
1043
+        $pdf->SetXY($posx,$posy);
1044
+        $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("Description").' : </b>'.nl2br($object->description), 0, 1);
1045
+        $nexY = $pdf->GetY();
1046
+
1047
+        $calcproductsunique=$object->nb_different_products();
1048
+        $calcproducts=$object->nb_products();
1049
+
1050
+        // Total nb of different products
1051
+        $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("NumberOfDifferentProducts").' : </b>'.(empty($calcproductsunique['nb'])?'0':$calcproductsunique['nb']), 0, 1);
1052
+        $nexY = $pdf->GetY();
1053
+
1054
+        // Nb of products
1055
+        $valtoshow=price2num($calcproducts['nb'], 'MS');
1056
+        $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("NumberOfProducts").' : </b>'.(empty($valtoshow)?'0':$valtoshow), 0, 1);
1057
+        $nexY = $pdf->GetY();
1058
+
1059
+        // Value
1060
+        $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("EstimatedStockValueShort").' : </b>'. price((empty($calcproducts['value'])?'0':price2num($calcproducts['value'],'MT')), 0, $langs, 0, -1, -1, $conf->currency), 0, 1);
1061
+        $nexY = $pdf->GetY();
1062
+
1063
+
1064
+        // Last movement
1065
+        $sql = "SELECT max(m.datem) as datem";
1066
+        $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
1067
+        $sql .= " WHERE m.fk_entrepot = '".$object->id."'";
1068
+        $resqlbis = $db->query($sql);
1069
+        if ($resqlbis)
1070
+        {
1071
+            $obj = $db->fetch_object($resqlbis);
1072
+            $lastmovementdate=$db->jdate($obj->datem);
1073
+        }
1074
+        else
1075
+        {
1076
+            dol_print_error($db);
1077
+        }
1078
+
1079
+        if ($lastmovementdate)
1080
+        {
1081
+            $toWrite = dol_print_date($lastmovementdate,'dayhour').' ';
1082
+        }
1083
+        else
1084
+        {
1085
+            $toWrite = $outputlangs->transnoentities("None");
1086
+        }
1087
+
1088
+        $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("LastMovement").' : </b>'.$toWrite, 0, 1);
1089
+        $nexY = $pdf->GetY();
1090
+
1091
+
1092
+        /*if ($object->ref_client)
1093 1093
 	    {
1094 1094
 	        $posy+=5;
1095 1095
 	        $pdf->SetXY($posx,$posy);
@@ -1097,14 +1097,14 @@  discard block
 block discarded – undo
1097 1097
 	        $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1098 1098
 	    }*/
1099 1099
 
1100
-	    /*$posy+=4;
1100
+        /*$posy+=4;
1101 1101
 	    $pdf->SetXY($posx,$posy);
1102 1102
 	    $pdf->SetTextColor(0,0,60);
1103 1103
 	    $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderDate")." : " . dol_print_date($object->date,"%d %b %Y",false,$outputlangs,true), '', 'R');
1104 1104
 	    */
1105 1105
 
1106
-	    // Get contact
1107
-	    /*
1106
+        // Get contact
1107
+        /*
1108 1108
 	    if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1109 1109
 	    {
1110 1110
 	        $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
@@ -1119,14 +1119,14 @@  discard block
 block discarded – undo
1119 1119
 	        }
1120 1120
 	    }*/
1121 1121
 
1122
-	    $posy+=2;
1122
+        $posy+=2;
1123 1123
 
1124
-	    // Show list of linked objects
1125
-	    $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1124
+        // Show list of linked objects
1125
+        $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1126 1126
 
1127
-	    if ($showaddress)
1128
-	    {
1129
-	        /*
1127
+        if ($showaddress)
1128
+        {
1129
+            /*
1130 1130
 	        // Sender properties
1131 1131
 	        $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
1132 1132
 
@@ -1157,24 +1157,24 @@  discard block
 block discarded – undo
1157 1157
 	        $pdf->SetFont('','', $default_font_size - 1);
1158 1158
 	        $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1159 1159
 	        */
1160
-	    }
1161
-
1162
-	    $pdf->SetTextColor(0,0,0);
1163
-	}
1164
-
1165
-	/**
1166
-	 *   	Show footer of page. Need this->emetteur object
1167
-	 *
1168
-	 *   	@param	TCPDF		$pdf     			PDF
1169
-	 * 		@param	Object		$object				Object to show
1170
-	 *      @param	Translate	$outputlangs		Object lang for output
1171
-	 *      @param	int			$hidefreetext		1=Hide free text
1172
-	 *      @return	int								Return height of bottom margin including footer text
1173
-	 */
1174
-	function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1175
-	{
1176
-	    global $conf;
1177
-	    $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1178
-	    return pdf_pagefoot($pdf,$outputlangs,'PRODUCT_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1179
-	}
1160
+        }
1161
+
1162
+        $pdf->SetTextColor(0,0,0);
1163
+    }
1164
+
1165
+    /**
1166
+     *   	Show footer of page. Need this->emetteur object
1167
+     *
1168
+     *   	@param	TCPDF		$pdf     			PDF
1169
+     * 		@param	Object		$object				Object to show
1170
+     *      @param	Translate	$outputlangs		Object lang for output
1171
+     *      @param	int			$hidefreetext		1=Hide free text
1172
+     *      @return	int								Return height of bottom margin including footer text
1173
+     */
1174
+    function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1175
+    {
1176
+        global $conf;
1177
+        $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1178
+        return pdf_pagefoot($pdf,$outputlangs,'PRODUCT_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1179
+    }
1180 1180
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/stock/doc/pdf_stdmovement.modules.php 1 patch
Indentation   +992 added lines, -992 removed lines patch added patch discarded remove patch
@@ -42,32 +42,32 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public $db;
44 44
 
45
-	/**
45
+    /**
46 46
      * @var string model name
47 47
      */
48 48
     public $name;
49 49
 
50
-	/**
50
+    /**
51 51
      * @var string model description (short text)
52 52
      */
53 53
     public $description;
54 54
 
55
-	/**
55
+    /**
56 56
      * @var string document type
57 57
      */
58 58
     public $type;
59 59
 
60
-	/**
60
+    /**
61 61
      * @var array() Minimum version of PHP required by module.
62
-	 * e.g.: PHP ≥ 5.4 = array(5, 4)
62
+     * e.g.: PHP ≥ 5.4 = array(5, 4)
63 63
      */
64
-	public $phpmin = array(5, 4);
64
+    public $phpmin = array(5, 4);
65 65
 
66
-	/**
66
+    /**
67 67
      * Dolibarr version of the loaded document
68 68
      * @public string
69 69
      */
70
-	public $version = 'dolibarr';
70
+    public $version = 'dolibarr';
71 71
 
72 72
     /**
73 73
      * @var int page_largeur
@@ -84,342 +84,342 @@  discard block
 block discarded – undo
84 84
      */
85 85
     public $format;
86 86
 
87
-	/**
87
+    /**
88 88
      * @var int marge_gauche
89 89
      */
90
-	public $marge_gauche;
90
+    public $marge_gauche;
91 91
 
92
-	/**
92
+    /**
93 93
      * @var int marge_droite
94 94
      */
95
-	public $marge_droite;
95
+    public $marge_droite;
96 96
 
97
-	/**
97
+    /**
98 98
      * @var int marge_haute
99 99
      */
100
-	public $marge_haute;
100
+    public $marge_haute;
101 101
 
102
-	/**
102
+    /**
103 103
      * @var int marge_basse
104 104
      */
105
-	public $marge_basse;
105
+    public $marge_basse;
106
+
107
+    /**
108
+     * Issuer
109
+     * @var Societe
110
+     */
111
+    public $emetteur;
112
+
106 113
 
107 114
     /**
108
-	 * Issuer
109
-	 * @var Societe
110
-	 */
111
-	public $emetteur;
112
-
113
-
114
-	/**
115
-	 *	Constructor
116
-	 *
117
-	 *  @param		DoliDB		$db      Database handler
118
-	 */
119
-	public function __construct($db)
120
-	{
121
-		global $conf,$langs,$mysoc;
122
-
123
-		// Load traductions files requiredby by page
124
-		$langs->loadLangs(array("main", "companies"));
125
-
126
-		$this->db = $db;
127
-		$this->name = "stdmouvement";
128
-		$this->description = $langs->trans("DocumentModelStandardPDF");
129
-
130
-		// Dimension page pour format A4
131
-		$this->type = 'pdf';
132
-		$formatarray=pdf_getFormat();
133
-		$this->page_largeur = $formatarray['width'];
134
-		$this->page_hauteur = $formatarray['height'];
135
-		$this->format = array($this->page_largeur,$this->page_hauteur);
136
-		$this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
137
-		$this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
138
-		$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
139
-		$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
140
-
141
-		$this->option_logo = 1;                    // Affiche logo
142
-		$this->option_codestockservice = 0;      // Affiche code stock-service
143
-		$this->option_multilang = 1;               // Dispo en plusieurs langues
144
-		$this->option_freetext = 0;				   // Support add of a personalised text
145
-
146
-		// Recupere emetteur
147
-		$this->emetteur=$mysoc;
148
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
149
-
150
-		// Define position of columns
151
-		$this->wref = 15;
152
-		$this->posxidref = $this->marge_gauche;
153
-		$this->posxdatemouv = $this->marge_gauche+8;
154
-		$this->posxdesc=37;
155
-		$this->posxlabel=50;
156
-		$this->posxtva=80;
157
-		$this->posxqty=105;
158
-		$this->posxup=119;
159
-		$this->posxunit=136;
160
-		$this->posxdiscount=167;
161
-		$this->postotalht=180;
162
-
163
-		if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup;
164
-		$this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);	// width of images
165
-		if ($this->page_largeur < 210) // To work with US executive format
166
-		{
167
-			$this->posxpicture-=20;
168
-			$this->posxtva-=20;
169
-			$this->posxup-=20;
170
-			$this->posxqty-=20;
171
-			$this->posxunit-=20;
172
-			$this->posxdiscount-=20;
173
-			$this->postotalht-=20;
174
-		}
175
-		$this->tva=array();
176
-		$this->localtax1=array();
177
-		$this->localtax2=array();
178
-		$this->atleastoneratenotnull=0;
179
-		$this->atleastonediscount=0;
180
-	}
115
+     *	Constructor
116
+     *
117
+     *  @param		DoliDB		$db      Database handler
118
+     */
119
+    public function __construct($db)
120
+    {
121
+        global $conf,$langs,$mysoc;
122
+
123
+        // Load traductions files requiredby by page
124
+        $langs->loadLangs(array("main", "companies"));
125
+
126
+        $this->db = $db;
127
+        $this->name = "stdmouvement";
128
+        $this->description = $langs->trans("DocumentModelStandardPDF");
129
+
130
+        // Dimension page pour format A4
131
+        $this->type = 'pdf';
132
+        $formatarray=pdf_getFormat();
133
+        $this->page_largeur = $formatarray['width'];
134
+        $this->page_hauteur = $formatarray['height'];
135
+        $this->format = array($this->page_largeur,$this->page_hauteur);
136
+        $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
137
+        $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
138
+        $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
139
+        $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
140
+
141
+        $this->option_logo = 1;                    // Affiche logo
142
+        $this->option_codestockservice = 0;      // Affiche code stock-service
143
+        $this->option_multilang = 1;               // Dispo en plusieurs langues
144
+        $this->option_freetext = 0;				   // Support add of a personalised text
145
+
146
+        // Recupere emetteur
147
+        $this->emetteur=$mysoc;
148
+        if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
149
+
150
+        // Define position of columns
151
+        $this->wref = 15;
152
+        $this->posxidref = $this->marge_gauche;
153
+        $this->posxdatemouv = $this->marge_gauche+8;
154
+        $this->posxdesc=37;
155
+        $this->posxlabel=50;
156
+        $this->posxtva=80;
157
+        $this->posxqty=105;
158
+        $this->posxup=119;
159
+        $this->posxunit=136;
160
+        $this->posxdiscount=167;
161
+        $this->postotalht=180;
162
+
163
+        if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup;
164
+        $this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);	// width of images
165
+        if ($this->page_largeur < 210) // To work with US executive format
166
+        {
167
+            $this->posxpicture-=20;
168
+            $this->posxtva-=20;
169
+            $this->posxup-=20;
170
+            $this->posxqty-=20;
171
+            $this->posxunit-=20;
172
+            $this->posxdiscount-=20;
173
+            $this->postotalht-=20;
174
+        }
175
+        $this->tva=array();
176
+        $this->localtax1=array();
177
+        $this->localtax2=array();
178
+        $this->atleastoneratenotnull=0;
179
+        $this->atleastonediscount=0;
180
+    }
181 181
 
182 182
 
183 183
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
184
-	/**
185
-	 *	Function to build a document on disk using the generic odt module.
186
-	 *
187
-	 *	@param		Stock		$object				Object source to build document
188
-	 *	@param		Translate	$outputlangs		Lang output object
189
-	 * 	@param		string		$srctemplatepath	Full path of source filename for generator using a template file
190
-	 *  @param		int			$hidedetails		Do not show line details
191
-	 *  @param		int			$hidedesc			Do not show desc
192
-	 *  @param		int			$hideref			Do not show ref
193
-	 *	@return		int         					1 if OK, <=0 if KO
194
-	 */
195
-	function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
196
-	{
184
+    /**
185
+     *	Function to build a document on disk using the generic odt module.
186
+     *
187
+     *	@param		Stock		$object				Object source to build document
188
+     *	@param		Translate	$outputlangs		Lang output object
189
+     * 	@param		string		$srctemplatepath	Full path of source filename for generator using a template file
190
+     *  @param		int			$hidedetails		Do not show line details
191
+     *  @param		int			$hidedesc			Do not show desc
192
+     *  @param		int			$hideref			Do not show ref
193
+     *	@return		int         					1 if OK, <=0 if KO
194
+     */
195
+    function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
196
+    {
197 197
         // phpcs:enable
198
-		global $user,$langs,$conf,$mysoc,$db,$hookmanager;
199
-
200
-		if (! is_object($outputlangs)) $outputlangs=$langs;
201
-		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
202
-		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
203
-
204
-		// Load traductions files requiredby by page
205
-		$outputlangs->loadLangs(array("main", "dict", "companies", "bills", "stocks", "orders", "deliveries"));
206
-
207
-	/**
208
-	 * TODO: get from object
209
-	 */
210
-
211
-		$id=GETPOST('id','int');
212
-		$ref = GETPOST('ref','alpha');
213
-		$msid=GETPOST('msid','int');
214
-		$product_id=GETPOST("product_id");
215
-		$action=GETPOST('action','aZ09');
216
-		$cancel=GETPOST('cancel','alpha');
217
-		$contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'movementlist';
218
-
219
-		$idproduct = GETPOST('idproduct','int');
220
-		$year = GETPOST("year");
221
-		$month = GETPOST("month");
222
-		$search_ref = GETPOST('search_ref', 'alpha');
223
-		$search_movement = GETPOST("search_movement");
224
-		$search_product_ref = trim(GETPOST("search_product_ref"));
225
-		$search_product = trim(GETPOST("search_product"));
226
-		$search_warehouse = trim(GETPOST("search_warehouse"));
227
-		$search_inventorycode = trim(GETPOST("search_inventorycode"));
228
-		$search_user = trim(GETPOST("search_user"));
229
-		$search_batch = trim(GETPOST("search_batch"));
230
-		$search_qty = trim(GETPOST("search_qty"));
231
-		$search_type_mouvement=GETPOST('search_type_mouvement','int');
232
-
233
-		$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
234
-		$page = GETPOST("page",'int');
235
-		$sortfield = GETPOST("sortfield",'alpha');
236
-		$sortorder = GETPOST("sortorder",'alpha');
237
-		if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
238
-		$offset = $limit * $page;
239
-		if (! $sortfield) $sortfield="m.datem";
240
-		if (! $sortorder) $sortorder="DESC";
241
-
242
-		$pdluoid=GETPOST('pdluoid','int');
243
-
244
-		// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
245
-		$hookmanager->initHooks(array('movementlist'));
246
-		$extrafields = new ExtraFields($db);
247
-
248
-		// fetch optionals attributes and labels
249
-		$extralabels = $extrafields->fetch_name_optionals_label('movement');
250
-		$search_array_options=$extrafields->getOptionalsFromPost('movement','','search_');
251
-
252
-		$productlot=new ProductLot($db);
253
-		$productstatic=new Product($db);
254
-		$warehousestatic=new Entrepot($db);
255
-		$movement=new MouvementStock($db);
256
-		$userstatic=new User($db);
257
-
258
-		$sql = "SELECT p.rowid, p.ref as product_ref, p.label as produit, p.tobatch, p.fk_product_type as type, p.entity,";
259
-		$sql.= " e.ref as stock, e.rowid as entrepot_id, e.lieu,";
260
-		$sql.= " m.rowid as mid, m.value as qty, m.datem, m.fk_user_author, m.label, m.inventorycode, m.fk_origin, m.origintype,";
261
-		$sql.= " m.batch, m.price,";
262
-		$sql.= " m.type_mouvement,";
263
-		$sql.= " pl.rowid as lotid, pl.eatby, pl.sellby,";
264
-		$sql.= " u.login, u.photo, u.lastname, u.firstname";
265
-		// Add fields from extrafields
266
-		foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
267
-		// Add fields from hooks
268
-		$parameters=array();
269
-		$reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters);    // Note that $action and $object may have been modified by hook
270
-		$sql.=$hookmanager->resPrint;
271
-		$sql.= " FROM ".MAIN_DB_PREFIX."entrepot as e,";
272
-		$sql.= " ".MAIN_DB_PREFIX."product as p,";
273
-		$sql.= " ".MAIN_DB_PREFIX."stock_mouvement as m";
274
-		if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."movement_extrafields as ef on (m.rowid = ef.fk_object)";
275
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON m.fk_user_author = u.rowid";
276
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON m.batch = pl.batch AND m.fk_product = pl.fk_product";
277
-		$sql.= " WHERE m.fk_product = p.rowid";
278
-		if ($msid > 0) $sql .= " AND m.rowid = ".$msid;
279
-		$sql.= " AND m.fk_entrepot = e.rowid";
280
-		$sql.= " AND e.entity IN (".getEntity('stock').")";
281
-		if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql.= " AND p.fk_product_type = 0";
282
-		if ($id > 0) $sql.= " AND e.rowid ='".$id."'";
283
-		if ($month > 0)
284
-		{
285
-			if ($year > 0)
286
-			$sql.= " AND m.datem BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
287
-			else
288
-			$sql.= " AND date_format(m.datem, '%m') = '$month'";
289
-		}
290
-		else if ($year > 0)
291
-		{
292
-			$sql.= " AND m.datem BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
293
-		}
294
-		if ($idproduct > 0) $sql.= " AND p.rowid = '".$idproduct."'";
295
-		if (! empty($search_ref))			$sql.= natural_search('m.rowid', $search_ref, 1);
296
-		if (! empty($search_movement))      $sql.= natural_search('m.label', $search_movement);
297
-		if (! empty($search_inventorycode)) $sql.= natural_search('m.inventorycode', $search_inventorycode);
298
-		if (! empty($search_product_ref))   $sql.= natural_search('p.ref', $search_product_ref);
299
-		if (! empty($search_product))       $sql.= natural_search('p.label', $search_product);
300
-		if ($search_warehouse > 0)          $sql.= " AND e.rowid = '".$db->escape($search_warehouse)."'";
301
-		if (! empty($search_user))          $sql.= natural_search('u.login', $search_user);
302
-		if (! empty($search_batch))         $sql.= natural_search('m.batch', $search_batch);
303
-		if ($search_qty != '')				$sql.= natural_search('m.value', $search_qty, 1);
304
-		if ($search_type_mouvement > 0)		$sql.= " AND m.type_mouvement = '".$db->escape($search_type_mouvement)."'";
305
-		// Add where from extra fields
306
-		include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
307
-		// Add where from hooks
308
-		$parameters=array();
309
-		$reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters);    // Note that $action and $object may have been modified by hook
310
-		$sql.=$hookmanager->resPrint;
311
-		$sql.= $db->order($sortfield,$sortorder);
312
-
313
-		$nbtotalofrecords = '';
314
-		if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
315
-		{
316
-			$result = $db->query($sql);
317
-			$nbtotalofrecords = $db->num_rows($result);
318
-			if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0
319
-			{
320
-				$page = 0;
321
-				$offset = 0;
322
-			}
323
-		}
324
-
325
-		if(empty($search_inventorycode)) $sql.= $db->plimit($limit+1, $offset);
326
-
327
-
328
-		$resql = $db->query($sql);
329
-		$nbtotalofrecords = $db->num_rows($result);
330
-
331
-	/*
198
+        global $user,$langs,$conf,$mysoc,$db,$hookmanager;
199
+
200
+        if (! is_object($outputlangs)) $outputlangs=$langs;
201
+        // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
202
+        if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
203
+
204
+        // Load traductions files requiredby by page
205
+        $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "stocks", "orders", "deliveries"));
206
+
207
+    /**
208
+     * TODO: get from object
209
+     */
210
+
211
+        $id=GETPOST('id','int');
212
+        $ref = GETPOST('ref','alpha');
213
+        $msid=GETPOST('msid','int');
214
+        $product_id=GETPOST("product_id");
215
+        $action=GETPOST('action','aZ09');
216
+        $cancel=GETPOST('cancel','alpha');
217
+        $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'movementlist';
218
+
219
+        $idproduct = GETPOST('idproduct','int');
220
+        $year = GETPOST("year");
221
+        $month = GETPOST("month");
222
+        $search_ref = GETPOST('search_ref', 'alpha');
223
+        $search_movement = GETPOST("search_movement");
224
+        $search_product_ref = trim(GETPOST("search_product_ref"));
225
+        $search_product = trim(GETPOST("search_product"));
226
+        $search_warehouse = trim(GETPOST("search_warehouse"));
227
+        $search_inventorycode = trim(GETPOST("search_inventorycode"));
228
+        $search_user = trim(GETPOST("search_user"));
229
+        $search_batch = trim(GETPOST("search_batch"));
230
+        $search_qty = trim(GETPOST("search_qty"));
231
+        $search_type_mouvement=GETPOST('search_type_mouvement','int');
232
+
233
+        $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
234
+        $page = GETPOST("page",'int');
235
+        $sortfield = GETPOST("sortfield",'alpha');
236
+        $sortorder = GETPOST("sortorder",'alpha');
237
+        if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
238
+        $offset = $limit * $page;
239
+        if (! $sortfield) $sortfield="m.datem";
240
+        if (! $sortorder) $sortorder="DESC";
241
+
242
+        $pdluoid=GETPOST('pdluoid','int');
243
+
244
+        // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
245
+        $hookmanager->initHooks(array('movementlist'));
246
+        $extrafields = new ExtraFields($db);
247
+
248
+        // fetch optionals attributes and labels
249
+        $extralabels = $extrafields->fetch_name_optionals_label('movement');
250
+        $search_array_options=$extrafields->getOptionalsFromPost('movement','','search_');
251
+
252
+        $productlot=new ProductLot($db);
253
+        $productstatic=new Product($db);
254
+        $warehousestatic=new Entrepot($db);
255
+        $movement=new MouvementStock($db);
256
+        $userstatic=new User($db);
257
+
258
+        $sql = "SELECT p.rowid, p.ref as product_ref, p.label as produit, p.tobatch, p.fk_product_type as type, p.entity,";
259
+        $sql.= " e.ref as stock, e.rowid as entrepot_id, e.lieu,";
260
+        $sql.= " m.rowid as mid, m.value as qty, m.datem, m.fk_user_author, m.label, m.inventorycode, m.fk_origin, m.origintype,";
261
+        $sql.= " m.batch, m.price,";
262
+        $sql.= " m.type_mouvement,";
263
+        $sql.= " pl.rowid as lotid, pl.eatby, pl.sellby,";
264
+        $sql.= " u.login, u.photo, u.lastname, u.firstname";
265
+        // Add fields from extrafields
266
+        foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
267
+        // Add fields from hooks
268
+        $parameters=array();
269
+        $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters);    // Note that $action and $object may have been modified by hook
270
+        $sql.=$hookmanager->resPrint;
271
+        $sql.= " FROM ".MAIN_DB_PREFIX."entrepot as e,";
272
+        $sql.= " ".MAIN_DB_PREFIX."product as p,";
273
+        $sql.= " ".MAIN_DB_PREFIX."stock_mouvement as m";
274
+        if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."movement_extrafields as ef on (m.rowid = ef.fk_object)";
275
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON m.fk_user_author = u.rowid";
276
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON m.batch = pl.batch AND m.fk_product = pl.fk_product";
277
+        $sql.= " WHERE m.fk_product = p.rowid";
278
+        if ($msid > 0) $sql .= " AND m.rowid = ".$msid;
279
+        $sql.= " AND m.fk_entrepot = e.rowid";
280
+        $sql.= " AND e.entity IN (".getEntity('stock').")";
281
+        if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql.= " AND p.fk_product_type = 0";
282
+        if ($id > 0) $sql.= " AND e.rowid ='".$id."'";
283
+        if ($month > 0)
284
+        {
285
+            if ($year > 0)
286
+            $sql.= " AND m.datem BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
287
+            else
288
+            $sql.= " AND date_format(m.datem, '%m') = '$month'";
289
+        }
290
+        else if ($year > 0)
291
+        {
292
+            $sql.= " AND m.datem BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
293
+        }
294
+        if ($idproduct > 0) $sql.= " AND p.rowid = '".$idproduct."'";
295
+        if (! empty($search_ref))			$sql.= natural_search('m.rowid', $search_ref, 1);
296
+        if (! empty($search_movement))      $sql.= natural_search('m.label', $search_movement);
297
+        if (! empty($search_inventorycode)) $sql.= natural_search('m.inventorycode', $search_inventorycode);
298
+        if (! empty($search_product_ref))   $sql.= natural_search('p.ref', $search_product_ref);
299
+        if (! empty($search_product))       $sql.= natural_search('p.label', $search_product);
300
+        if ($search_warehouse > 0)          $sql.= " AND e.rowid = '".$db->escape($search_warehouse)."'";
301
+        if (! empty($search_user))          $sql.= natural_search('u.login', $search_user);
302
+        if (! empty($search_batch))         $sql.= natural_search('m.batch', $search_batch);
303
+        if ($search_qty != '')				$sql.= natural_search('m.value', $search_qty, 1);
304
+        if ($search_type_mouvement > 0)		$sql.= " AND m.type_mouvement = '".$db->escape($search_type_mouvement)."'";
305
+        // Add where from extra fields
306
+        include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
307
+        // Add where from hooks
308
+        $parameters=array();
309
+        $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters);    // Note that $action and $object may have been modified by hook
310
+        $sql.=$hookmanager->resPrint;
311
+        $sql.= $db->order($sortfield,$sortorder);
312
+
313
+        $nbtotalofrecords = '';
314
+        if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
315
+        {
316
+            $result = $db->query($sql);
317
+            $nbtotalofrecords = $db->num_rows($result);
318
+            if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0
319
+            {
320
+                $page = 0;
321
+                $offset = 0;
322
+            }
323
+        }
324
+
325
+        if(empty($search_inventorycode)) $sql.= $db->plimit($limit+1, $offset);
326
+
327
+
328
+        $resql = $db->query($sql);
329
+        $nbtotalofrecords = $db->num_rows($result);
330
+
331
+    /*
332 332
 	 * END TODO
333 333
 	 **/
334 334
 
335
-		//$nblignes = count($object->lines);
336
-
337
-		if ($conf->stock->dir_output)
338
-		{
339
-
340
-			if ($resql)
341
-			{
342
-				$product = new Product($db);
343
-				$object = new Entrepot($db);
344
-
345
-				if ($idproduct > 0)
346
-				{
347
-					$product->fetch($idproduct);
348
-				}
349
-				if ($id > 0 || $ref)
350
-				{
351
-					$result = $object->fetch($id, $ref);
352
-					if ($result < 0)
353
-					{
354
-						dol_print_error($db);
355
-					}
356
-				}
357
-
358
-				$num = $db->num_rows($resql);
359
-
360
-				$arrayofselected=is_array($toselect)?$toselect:array();
361
-
362
-				$i = 0;
363
-				$help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
364
-				if ($msid) $texte = $langs->trans('StockMovementForId', $msid);
365
-				else
366
-				{
367
-					$texte = $langs->trans("ListOfStockMovements");
368
-					if ($id) $texte.=' ('.$langs->trans("ForThisWarehouse").')';
369
-				}
370
-			}
371
-
372
-			// Definition of $dir and $file
373
-			if ($object->specimen)
374
-			{
375
-				$dir = $conf->stock->dir_output . "/movement";
376
-				$file = $dir . "/SPECIMEN.pdf";
377
-			}
378
-			else
379
-			{
380
-				$objectref = dol_sanitizeFileName($object->ref);
381
-				if(!empty($search_inventorycode)) $objectref.="_".$id."_".$search_inventorycode;
382
-				if($search_type_mouvement) $objectref.="_".$search_type_mouvement;
383
-				$dir = $conf->stock->dir_output . "/movement/" . $objectref;
384
-				$file = $dir . "/" . $objectref . ".pdf";
385
-			}
386
-
387
-			$stockFournisseur = new ProductFournisseur($this->db);
388
-			$supplierprices = $stockFournisseur->list_product_fournisseur_price($object->id);
389
-			$object->supplierprices = $supplierprices;
390
-
391
-			$productstatic=new Product($db);
392
-
393
-			if (! file_exists($dir))
394
-			{
395
-				if (dol_mkdir($dir) < 0)
396
-				{
397
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
398
-					return -1;
399
-				}
400
-			}
401
-
402
-			if (file_exists($dir))
403
-			{
404
-				// Add pdfgeneration hook
405
-				if (! is_object($hookmanager))
406
-				{
407
-					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
408
-					$hookmanager=new HookManager($this->db);
409
-				}
410
-				$hookmanager->initHooks(array('pdfgeneration'));
411
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
412
-				global $action;
413
-				$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
414
-
415
-				// Create pdf instance
416
-				$pdf=pdf_getInstance($this->format);
417
-				$default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
418
-				$pdf->SetAutoPageBreak(1,0);
419
-
420
-				$heightforinfotot = 40;	// Height reserved to output the info and total part
421
-		        $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
422
-	            $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
335
+        //$nblignes = count($object->lines);
336
+
337
+        if ($conf->stock->dir_output)
338
+        {
339
+
340
+            if ($resql)
341
+            {
342
+                $product = new Product($db);
343
+                $object = new Entrepot($db);
344
+
345
+                if ($idproduct > 0)
346
+                {
347
+                    $product->fetch($idproduct);
348
+                }
349
+                if ($id > 0 || $ref)
350
+                {
351
+                    $result = $object->fetch($id, $ref);
352
+                    if ($result < 0)
353
+                    {
354
+                        dol_print_error($db);
355
+                    }
356
+                }
357
+
358
+                $num = $db->num_rows($resql);
359
+
360
+                $arrayofselected=is_array($toselect)?$toselect:array();
361
+
362
+                $i = 0;
363
+                $help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
364
+                if ($msid) $texte = $langs->trans('StockMovementForId', $msid);
365
+                else
366
+                {
367
+                    $texte = $langs->trans("ListOfStockMovements");
368
+                    if ($id) $texte.=' ('.$langs->trans("ForThisWarehouse").')';
369
+                }
370
+            }
371
+
372
+            // Definition of $dir and $file
373
+            if ($object->specimen)
374
+            {
375
+                $dir = $conf->stock->dir_output . "/movement";
376
+                $file = $dir . "/SPECIMEN.pdf";
377
+            }
378
+            else
379
+            {
380
+                $objectref = dol_sanitizeFileName($object->ref);
381
+                if(!empty($search_inventorycode)) $objectref.="_".$id."_".$search_inventorycode;
382
+                if($search_type_mouvement) $objectref.="_".$search_type_mouvement;
383
+                $dir = $conf->stock->dir_output . "/movement/" . $objectref;
384
+                $file = $dir . "/" . $objectref . ".pdf";
385
+            }
386
+
387
+            $stockFournisseur = new ProductFournisseur($this->db);
388
+            $supplierprices = $stockFournisseur->list_product_fournisseur_price($object->id);
389
+            $object->supplierprices = $supplierprices;
390
+
391
+            $productstatic=new Product($db);
392
+
393
+            if (! file_exists($dir))
394
+            {
395
+                if (dol_mkdir($dir) < 0)
396
+                {
397
+                    $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
398
+                    return -1;
399
+                }
400
+            }
401
+
402
+            if (file_exists($dir))
403
+            {
404
+                // Add pdfgeneration hook
405
+                if (! is_object($hookmanager))
406
+                {
407
+                    include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
408
+                    $hookmanager=new HookManager($this->db);
409
+                }
410
+                $hookmanager->initHooks(array('pdfgeneration'));
411
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
412
+                global $action;
413
+                $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
414
+
415
+                // Create pdf instance
416
+                $pdf=pdf_getInstance($this->format);
417
+                $default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
418
+                $pdf->SetAutoPageBreak(1,0);
419
+
420
+                $heightforinfotot = 40;	// Height reserved to output the info and total part
421
+                $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
422
+                $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
423 423
 
424 424
                 if (class_exists('TCPDF'))
425 425
                 {
@@ -434,663 +434,663 @@  discard block
 block discarded – undo
434 434
                     $tplidx = $pdf->importPage(1);
435 435
                 }
436 436
 
437
-				$pdf->Open();
438
-				$pagenb=0;
439
-				$pdf->SetDrawColor(128,128,128);
440
-
441
-				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
442
-				$pdf->SetSubject($outputlangs->transnoentities("Stock"));
443
-				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
444
-				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
445
-				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Stock")." ".$outputlangs->convToOutputCharset($object->libelle));
446
-				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
447
-
448
-				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
449
-
450
-
451
-				// New page
452
-				$pdf->AddPage();
453
-				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
454
-				$pagenb++;
455
-				$this->_pagehead($pdf, $object, 1, $outputlangs);
456
-				$pdf->SetFont('','', $default_font_size - 1);
457
-				$pdf->MultiCell(0, 3, '');		// Set interline to 3
458
-				$pdf->SetTextColor(0,0,0);
459
-
460
-				$tab_top = 42;
461
-				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
462
-				$tab_height = 130;
463
-				$tab_height_newpage = 150;
464
-
465
-				/* ************************************************************************** */
466
-				/*                                                                            */
467
-				/* Affichage de la liste des produits du MouvementStock                           */
468
-				/*                                                                            */
469
-				/* ************************************************************************** */
470
-
471
-				$nexY+=5;
472
-				$nexY = $pdf->GetY();
473
-				$nexY+=10;
474
-
475
-				$totalunit=0;
476
-				$totalvalue=$totalvaluesell=0;
477
-				$arrayofuniqueproduct = array();
478
-
479
-				//dol_syslog('List products', LOG_DEBUG);
480
-				$resql = $db->query($sql);
481
-				if ($resql)
482
-				{
483
-					$num = $db->num_rows($resql);
484
-					$i = 0;
485
-					$nblignes = $num;
486
-					for ($i = 0 ; $i < $nblignes ; $i++)
487
-					{
488
-						$objp = $db->fetch_object($resql);
489
-
490
-						// Multilangs
491
-						if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
492
-						{
493
-							$sql = "SELECT label";
494
-							$sql.= " FROM ".MAIN_DB_PREFIX."product_lang";
495
-							$sql.= " WHERE fk_product=".$objp->rowid;
496
-							$sql.= " AND lang='". $langs->getDefaultLang() ."'";
497
-							$sql.= " LIMIT 1";
498
-
499
-							$result = $db->query($sql);
500
-							if ($result)
501
-							{
502
-								$objtp = $db->fetch_object($result);
503
-								if ($objtp->label != '') $objp->produit = $objtp->label;
504
-							}
505
-						}
506
-
507
-						$curY = $nexY;
508
-						$pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
509
-						$pdf->SetTextColor(0,0,0);
510
-
511
-						$pdf->setTopMargin($tab_top_newpage);
512
-						$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
513
-						$pageposbefore=$pdf->getPage();
514
-
515
-						// Description of product line
516
-						$curX = $this->posxdesc-1;
517
-
518
-						$showpricebeforepagebreak=1;
519
-
520
-						$pdf->startTransaction();
521
-						pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc);
522
-						$pageposafter=$pdf->getPage();
523
-						if ($pageposafter > $pageposbefore)	// There is a pagebreak
524
-						{
525
-							$pdf->rollbackTransaction(true);
526
-							$pageposafter=$pageposbefore;
527
-							//print $pageposafter.'-'.$pageposbefore;exit;
528
-							$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
529
-							pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc);
530
-							$pageposafter=$pdf->getPage();
531
-							$posyafter=$pdf->GetY();
532
-							if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
533
-							{
534
-								if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
535
-								{
536
-									$pdf->AddPage('','',true);
537
-									if (! empty($tplidx)) $pdf->useTemplate($tplidx);
538
-									if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
539
-									$pdf->setPage($pageposafter+1);
540
-								}
541
-							}
542
-							else
543
-							{
544
-								// We found a page break
545
-								$showpricebeforepagebreak=0;
546
-							}
547
-						}
548
-						else	// No pagebreak
549
-						{
550
-							$pdf->commitTransaction();
551
-						}
552
-						$posYAfterDescription=$pdf->GetY();
553
-
554
-						$nexY = $pdf->GetY();
555
-						$pageposafter=$pdf->getPage();
556
-
557
-						$pdf->setPage($pageposbefore);
558
-						$pdf->setTopMargin($this->marge_haute);
559
-						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
560
-
561
-						// We suppose that a too long description is moved completely on next page
562
-						if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
563
-							$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
564
-						}
565
-
566
-						$pdf->SetFont('','',  $default_font_size - 1);   // On repositionne la police par defaut
567
-
568
-						// $objp = $db->fetch_object($resql);
569
-
570
-						$userstatic->id=$objp->fk_user_author;
571
-						$userstatic->login=$objp->login;
572
-						$userstatic->lastname=$objp->lastname;
573
-						$userstatic->firstname=$objp->firstname;
574
-						$userstatic->photo=$objp->photo;
575
-
576
-						$productstatic->id=$objp->rowid;
577
-						$productstatic->ref=$objp->product_ref;
578
-						$productstatic->label=$objp->produit;
579
-						$productstatic->type=$objp->type;
580
-						$productstatic->entity=$objp->entity;
581
-						$productstatic->status_batch=$objp->tobatch;
582
-
583
-						$productlot->id = $objp->lotid;
584
-						$productlot->batch= $objp->batch;
585
-						$productlot->eatby= $objp->eatby;
586
-						$productlot->sellby= $objp->sellby;
587
-
588
-						$warehousestatic->id=$objp->entrepot_id;
589
-						$warehousestatic->libelle=$objp->stock;
590
-						$warehousestatic->lieu=$objp->lieu;
591
-
592
-						$arrayofuniqueproduct[$objp->rowid]=$objp->produit;
593
-						if(!empty($objp->fk_origin)) {
594
-							$origin = $movement->get_origin($objp->fk_origin, $objp->origintype);
595
-						} else {
596
-							$origin = '';
597
-						}
598
-
599
-						// Id movement.
600
-						$pdf->SetXY($this->posxidref, $curY);
601
-						$pdf->MultiCell($this->posxdesc-$this->posxidref-0.8, 3, $objp->mid, 0, 'L');
602
-
603
-						// Date.
604
-						$pdf->SetXY($this->posxdatemouv, $curY);
605
-						$pdf->MultiCell($this->posxdesc-$this->posxdatemouv-0.8, 6, dol_print_date($db->jdate($objp->datem),'dayhour'), 0, 'L');
606
-
607
-						// Ref.
608
-						$pdf->SetXY($this->posxdesc, $curY);
609
-						$pdf->MultiCell($this->posxlabel-$this->posxdesc-0.8, 3, $productstatic->ref, 0, 'L');
610
-
611
-						// Label
612
-						$pdf->SetXY($this->posxlabel+0.8, $curY);
613
-						$pdf->MultiCell($this->posxqty-$this->posxlabel-0.8, 6, $productstatic->label, 0, 'L');
614
-
615
-						// Lot/serie
616
-						$pdf->SetXY($this->posxqty, $curY);
617
-						$pdf->MultiCell($this->posxup-$this->posxqty-0.8, 3, $productlot->batch, 0, 'R');
618
-
619
-						// Inv. code
620
-						$pdf->SetXY($this->posxup, $curY);
621
-						$pdf->MultiCell($this->posxunit-$this->posxup-0.8, 3, $objp->inventorycode, 0, 'R');
622
-
623
-						// Label mouvement
624
-						$pdf->SetXY($this->posxunit, $curY);
625
-						$pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 3, $objp->label, 0, 'R');
626
-						$totalvalue+=price2num($objp->ppmp*$objp->value,'MT');
627
-
628
-						// Origin
629
-						$pricemin=$objp->price;
630
-						$pdf->SetXY($this->posxdiscount, $curY);
631
-						$pdf->MultiCell($this->postotalht-$this->posxdiscount-0.8, 3, $origin, 0, 'R', 0);
632
-
633
-						// Qty
634
-						$valtoshow=price2num($objp->qty, 'MS');
635
-						$towrite = (empty($valtoshow)?'0':$valtoshow);
636
-						$totalunit+=$objp->qty;
637
-
638
-						$pdf->SetXY($this->postotalht, $curY);
639
-						$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $objp->qty, 0, 'R', 0);
640
-
641
-						$totalvaluesell+=price2num($pricemin*$objp->value,'MT');
642
-
643
-						$nexY+=3.5;    // Passe espace entre les lignes
644
-						// Add line
645
-						if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
646
-						{
647
-							$pdf->setPage($pageposafter);
648
-							$pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
649
-							//$pdf->SetDrawColor(190,190,200);
650
-							$pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
651
-							$pdf->SetLineStyle(array('dash'=>0));
652
-						}
653
-
654
-						$nexY+=2;    // Passe espace entre les lignes
655
-
656
-						// Detect if some page were added automatically and output _tableau for past pages
657
-						while ($pagenb < $pageposafter)
658
-						{
659
-							$pdf->setPage($pagenb);
660
-							if ($pagenb == 1)
661
-							{
662
-								$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
663
-							}
664
-							else
665
-							{
666
-								$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
667
-							}
668
-							$this->_pagefoot($pdf,$object,$outputlangs,1);
669
-							$pagenb++;
670
-							$pdf->setPage($pagenb);
671
-							$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
672
-							if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
673
-						}
674
-						if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
675
-						{
676
-							if ($pagenb == 1)
677
-							{
678
-								$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
679
-							}
680
-							else
681
-							{
682
-								$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
683
-							}
684
-							$this->_pagefoot($pdf,$object,$outputlangs,1);
685
-							// New page
686
-							$pdf->AddPage();
687
-							if (! empty($tplidx)) $pdf->useTemplate($tplidx);
688
-							$pagenb++;
689
-							if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
690
-						}
691
-					}
692
-
693
-					$db->free($resql);
694
-
695
-					/**
696
-					 * footer table
697
-					 */
698
-					$nexY = $pdf->GetY();
699
-					$nexY+=5;
700
-					$curY = $nexY;
701
-
702
-					$pdf->SetLineStyle(array('dash'=>'0','color'=>array(220,26,26)));
703
-					$pdf->line($this->marge_gauche, $curY-1, $this->page_largeur-$this->marge_droite, $curY-1);
704
-					$pdf->SetLineStyle(array('dash'=>0));
705
-
706
-					$pdf->SetFont('','B',$default_font_size-1);
707
-					$pdf->SetTextColor(0,0,120);
708
-
709
-					// Total
710
-					$pdf->SetXY($this->posxidref, $curY);
711
-					$pdf->MultiCell($this->posxdesc-$this->posxidref, 3, $langs->trans("Total"), 0, 'L');
712
-
713
-					// Total Qty
714
-					$pdf->SetXY($this->postotalht, $curY);
715
-					$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $totalunit, 0, 'R', 0);
716
-				}
717
-				else
718
-				{
719
-					dol_print_error($db);
720
-				}
721
-
722
-				if ($notetoshow)
723
-				{
724
-					$substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
725
-					complete_substitutions_array($substitutionarray, $outputlangs, $object);
726
-					$notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
727
-
728
-					$tab_top = 88;
729
-
730
-					$pdf->SetFont('','', $default_font_size - 1);
731
-					$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
732
-					$nexY = $pdf->GetY();
733
-					$height_note=$nexY-$tab_top;
734
-
735
-					// Rect prend une longueur en 3eme param
736
-					$pdf->SetDrawColor(192,192,192);
737
-					$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
738
-
739
-					$tab_height = $tab_height - $height_note;
740
-					$tab_top = $nexY+6;
741
-				}
742
-				else
743
-				{
744
-					$height_note=0;
745
-				}
746
-
747
-				$iniY = $tab_top + 7;
748
-				$curY = $tab_top + 7;
749
-				$nexY = $tab_top + 7;
750
-
751
-				$tab_top = $tab_top_newpage+21;
752
-
753
-				// Show square
754
-				if ($pagenb == 1)
755
-				{
756
-					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
757
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
758
-				}
759
-				else
760
-				{
761
-					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
762
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
763
-				}
764
-
765
-				$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
766
-
767
-				// Affiche zone infos
768
-				//$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
769
-
770
-				// Affiche zone totaux
771
-				//$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
772
-
773
-				// Pied de page
774
-				$this->_pagefoot($pdf,$object,$outputlangs);
775
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
776
-
777
-				$pdf->Close();
778
-
779
-				$pdf->Output($file,'F');
780
-
781
-				// Add pdfgeneration hook
782
-				$hookmanager->initHooks(array('pdfgeneration'));
783
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
784
-				global $action;
785
-				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
786
-
787
-				if (! empty($conf->global->MAIN_UMASK))
788
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
789
-
790
-				$this->result = array('fullpath'=>$file);
791
-
792
-				return 1;   // Pas d'erreur
793
-			}
794
-			else
795
-			{
796
-				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
797
-				return 0;
798
-			}
799
-		}
800
-		else
801
-		{
802
-			$this->error=$langs->trans("ErrorConstantNotDefined","PRODUCT_OUTPUTDIR");
803
-			return 0;
804
-		}
805
-	}
806
-
807
-
808
-	/**
809
-	 *   Show table for lines
810
-	 *
811
-	 *   @param		TCPDF		$pdf     		Object PDF
812
-	 *   @param		string		$tab_top		Top position of table
813
-	 *   @param		string		$tab_height		Height of table (rectangle)
814
-	 *   @param		int			$nexY			Y (not used)
815
-	 *   @param		Translate	$outputlangs	Langs object
816
-	 *   @param		int			$hidetop		1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
817
-	 *   @param		int			$hidebottom		Hide bottom bar of array
818
-	 *   @param		string		$currency		Currency code
819
-	 *   @return	void
820
-	 */
821
-	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
822
-	{
823
-	    global $conf;
824
-
825
-	    // Force to disable hidetop and hidebottom
826
-	    $hidebottom=0;
827
-	    if ($hidetop) $hidetop=-1;
828
-
829
-	    $currency = !empty($currency) ? $currency : $conf->currency;
830
-	    $default_font_size = pdf_getPDFFontSize($outputlangs);
831
-
832
-	    // Amount in (at tab_top - 1)
833
-	    $pdf->SetTextColor(0,0,0);
834
-	    $pdf->SetFont('','', $default_font_size - 2);
835
-
836
-	    if (empty($hidetop))
837
-	    {
838
-	        $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
839
-	        $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
840
-	        $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
437
+                $pdf->Open();
438
+                $pagenb=0;
439
+                $pdf->SetDrawColor(128,128,128);
440
+
441
+                $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
442
+                $pdf->SetSubject($outputlangs->transnoentities("Stock"));
443
+                $pdf->SetCreator("Dolibarr ".DOL_VERSION);
444
+                $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
445
+                $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Stock")." ".$outputlangs->convToOutputCharset($object->libelle));
446
+                if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
447
+
448
+                $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
449
+
450
+
451
+                // New page
452
+                $pdf->AddPage();
453
+                if (! empty($tplidx)) $pdf->useTemplate($tplidx);
454
+                $pagenb++;
455
+                $this->_pagehead($pdf, $object, 1, $outputlangs);
456
+                $pdf->SetFont('','', $default_font_size - 1);
457
+                $pdf->MultiCell(0, 3, '');		// Set interline to 3
458
+                $pdf->SetTextColor(0,0,0);
459
+
460
+                $tab_top = 42;
461
+                $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
462
+                $tab_height = 130;
463
+                $tab_height_newpage = 150;
464
+
465
+                /* ************************************************************************** */
466
+                /*                                                                            */
467
+                /* Affichage de la liste des produits du MouvementStock                           */
468
+                /*                                                                            */
469
+                /* ************************************************************************** */
470
+
471
+                $nexY+=5;
472
+                $nexY = $pdf->GetY();
473
+                $nexY+=10;
474
+
475
+                $totalunit=0;
476
+                $totalvalue=$totalvaluesell=0;
477
+                $arrayofuniqueproduct = array();
478
+
479
+                //dol_syslog('List products', LOG_DEBUG);
480
+                $resql = $db->query($sql);
481
+                if ($resql)
482
+                {
483
+                    $num = $db->num_rows($resql);
484
+                    $i = 0;
485
+                    $nblignes = $num;
486
+                    for ($i = 0 ; $i < $nblignes ; $i++)
487
+                    {
488
+                        $objp = $db->fetch_object($resql);
489
+
490
+                        // Multilangs
491
+                        if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
492
+                        {
493
+                            $sql = "SELECT label";
494
+                            $sql.= " FROM ".MAIN_DB_PREFIX."product_lang";
495
+                            $sql.= " WHERE fk_product=".$objp->rowid;
496
+                            $sql.= " AND lang='". $langs->getDefaultLang() ."'";
497
+                            $sql.= " LIMIT 1";
498
+
499
+                            $result = $db->query($sql);
500
+                            if ($result)
501
+                            {
502
+                                $objtp = $db->fetch_object($result);
503
+                                if ($objtp->label != '') $objp->produit = $objtp->label;
504
+                            }
505
+                        }
506
+
507
+                        $curY = $nexY;
508
+                        $pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
509
+                        $pdf->SetTextColor(0,0,0);
510
+
511
+                        $pdf->setTopMargin($tab_top_newpage);
512
+                        $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
513
+                        $pageposbefore=$pdf->getPage();
514
+
515
+                        // Description of product line
516
+                        $curX = $this->posxdesc-1;
517
+
518
+                        $showpricebeforepagebreak=1;
519
+
520
+                        $pdf->startTransaction();
521
+                        pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc);
522
+                        $pageposafter=$pdf->getPage();
523
+                        if ($pageposafter > $pageposbefore)	// There is a pagebreak
524
+                        {
525
+                            $pdf->rollbackTransaction(true);
526
+                            $pageposafter=$pageposbefore;
527
+                            //print $pageposafter.'-'.$pageposbefore;exit;
528
+                            $pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
529
+                            pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc);
530
+                            $pageposafter=$pdf->getPage();
531
+                            $posyafter=$pdf->GetY();
532
+                            if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
533
+                            {
534
+                                if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
535
+                                {
536
+                                    $pdf->AddPage('','',true);
537
+                                    if (! empty($tplidx)) $pdf->useTemplate($tplidx);
538
+                                    if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
539
+                                    $pdf->setPage($pageposafter+1);
540
+                                }
541
+                            }
542
+                            else
543
+                            {
544
+                                // We found a page break
545
+                                $showpricebeforepagebreak=0;
546
+                            }
547
+                        }
548
+                        else	// No pagebreak
549
+                        {
550
+                            $pdf->commitTransaction();
551
+                        }
552
+                        $posYAfterDescription=$pdf->GetY();
553
+
554
+                        $nexY = $pdf->GetY();
555
+                        $pageposafter=$pdf->getPage();
556
+
557
+                        $pdf->setPage($pageposbefore);
558
+                        $pdf->setTopMargin($this->marge_haute);
559
+                        $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
560
+
561
+                        // We suppose that a too long description is moved completely on next page
562
+                        if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
563
+                            $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
564
+                        }
565
+
566
+                        $pdf->SetFont('','',  $default_font_size - 1);   // On repositionne la police par defaut
567
+
568
+                        // $objp = $db->fetch_object($resql);
569
+
570
+                        $userstatic->id=$objp->fk_user_author;
571
+                        $userstatic->login=$objp->login;
572
+                        $userstatic->lastname=$objp->lastname;
573
+                        $userstatic->firstname=$objp->firstname;
574
+                        $userstatic->photo=$objp->photo;
575
+
576
+                        $productstatic->id=$objp->rowid;
577
+                        $productstatic->ref=$objp->product_ref;
578
+                        $productstatic->label=$objp->produit;
579
+                        $productstatic->type=$objp->type;
580
+                        $productstatic->entity=$objp->entity;
581
+                        $productstatic->status_batch=$objp->tobatch;
582
+
583
+                        $productlot->id = $objp->lotid;
584
+                        $productlot->batch= $objp->batch;
585
+                        $productlot->eatby= $objp->eatby;
586
+                        $productlot->sellby= $objp->sellby;
587
+
588
+                        $warehousestatic->id=$objp->entrepot_id;
589
+                        $warehousestatic->libelle=$objp->stock;
590
+                        $warehousestatic->lieu=$objp->lieu;
591
+
592
+                        $arrayofuniqueproduct[$objp->rowid]=$objp->produit;
593
+                        if(!empty($objp->fk_origin)) {
594
+                            $origin = $movement->get_origin($objp->fk_origin, $objp->origintype);
595
+                        } else {
596
+                            $origin = '';
597
+                        }
598
+
599
+                        // Id movement.
600
+                        $pdf->SetXY($this->posxidref, $curY);
601
+                        $pdf->MultiCell($this->posxdesc-$this->posxidref-0.8, 3, $objp->mid, 0, 'L');
602
+
603
+                        // Date.
604
+                        $pdf->SetXY($this->posxdatemouv, $curY);
605
+                        $pdf->MultiCell($this->posxdesc-$this->posxdatemouv-0.8, 6, dol_print_date($db->jdate($objp->datem),'dayhour'), 0, 'L');
606
+
607
+                        // Ref.
608
+                        $pdf->SetXY($this->posxdesc, $curY);
609
+                        $pdf->MultiCell($this->posxlabel-$this->posxdesc-0.8, 3, $productstatic->ref, 0, 'L');
610
+
611
+                        // Label
612
+                        $pdf->SetXY($this->posxlabel+0.8, $curY);
613
+                        $pdf->MultiCell($this->posxqty-$this->posxlabel-0.8, 6, $productstatic->label, 0, 'L');
614
+
615
+                        // Lot/serie
616
+                        $pdf->SetXY($this->posxqty, $curY);
617
+                        $pdf->MultiCell($this->posxup-$this->posxqty-0.8, 3, $productlot->batch, 0, 'R');
618
+
619
+                        // Inv. code
620
+                        $pdf->SetXY($this->posxup, $curY);
621
+                        $pdf->MultiCell($this->posxunit-$this->posxup-0.8, 3, $objp->inventorycode, 0, 'R');
622
+
623
+                        // Label mouvement
624
+                        $pdf->SetXY($this->posxunit, $curY);
625
+                        $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 3, $objp->label, 0, 'R');
626
+                        $totalvalue+=price2num($objp->ppmp*$objp->value,'MT');
627
+
628
+                        // Origin
629
+                        $pricemin=$objp->price;
630
+                        $pdf->SetXY($this->posxdiscount, $curY);
631
+                        $pdf->MultiCell($this->postotalht-$this->posxdiscount-0.8, 3, $origin, 0, 'R', 0);
632
+
633
+                        // Qty
634
+                        $valtoshow=price2num($objp->qty, 'MS');
635
+                        $towrite = (empty($valtoshow)?'0':$valtoshow);
636
+                        $totalunit+=$objp->qty;
637
+
638
+                        $pdf->SetXY($this->postotalht, $curY);
639
+                        $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $objp->qty, 0, 'R', 0);
640
+
641
+                        $totalvaluesell+=price2num($pricemin*$objp->value,'MT');
642
+
643
+                        $nexY+=3.5;    // Passe espace entre les lignes
644
+                        // Add line
645
+                        if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
646
+                        {
647
+                            $pdf->setPage($pageposafter);
648
+                            $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
649
+                            //$pdf->SetDrawColor(190,190,200);
650
+                            $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
651
+                            $pdf->SetLineStyle(array('dash'=>0));
652
+                        }
653
+
654
+                        $nexY+=2;    // Passe espace entre les lignes
655
+
656
+                        // Detect if some page were added automatically and output _tableau for past pages
657
+                        while ($pagenb < $pageposafter)
658
+                        {
659
+                            $pdf->setPage($pagenb);
660
+                            if ($pagenb == 1)
661
+                            {
662
+                                $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
663
+                            }
664
+                            else
665
+                            {
666
+                                $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
667
+                            }
668
+                            $this->_pagefoot($pdf,$object,$outputlangs,1);
669
+                            $pagenb++;
670
+                            $pdf->setPage($pagenb);
671
+                            $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
672
+                            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
673
+                        }
674
+                        if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
675
+                        {
676
+                            if ($pagenb == 1)
677
+                            {
678
+                                $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
679
+                            }
680
+                            else
681
+                            {
682
+                                $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
683
+                            }
684
+                            $this->_pagefoot($pdf,$object,$outputlangs,1);
685
+                            // New page
686
+                            $pdf->AddPage();
687
+                            if (! empty($tplidx)) $pdf->useTemplate($tplidx);
688
+                            $pagenb++;
689
+                            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
690
+                        }
691
+                    }
692
+
693
+                    $db->free($resql);
694
+
695
+                    /**
696
+                     * footer table
697
+                     */
698
+                    $nexY = $pdf->GetY();
699
+                    $nexY+=5;
700
+                    $curY = $nexY;
701
+
702
+                    $pdf->SetLineStyle(array('dash'=>'0','color'=>array(220,26,26)));
703
+                    $pdf->line($this->marge_gauche, $curY-1, $this->page_largeur-$this->marge_droite, $curY-1);
704
+                    $pdf->SetLineStyle(array('dash'=>0));
705
+
706
+                    $pdf->SetFont('','B',$default_font_size-1);
707
+                    $pdf->SetTextColor(0,0,120);
708
+
709
+                    // Total
710
+                    $pdf->SetXY($this->posxidref, $curY);
711
+                    $pdf->MultiCell($this->posxdesc-$this->posxidref, 3, $langs->trans("Total"), 0, 'L');
712
+
713
+                    // Total Qty
714
+                    $pdf->SetXY($this->postotalht, $curY);
715
+                    $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $totalunit, 0, 'R', 0);
716
+                }
717
+                else
718
+                {
719
+                    dol_print_error($db);
720
+                }
841 721
 
842
-	        //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
843
-	        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));
844
-	    }
722
+                if ($notetoshow)
723
+                {
724
+                    $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
725
+                    complete_substitutions_array($substitutionarray, $outputlangs, $object);
726
+                    $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
845 727
 
846
-	    $pdf->SetDrawColor(128,128,128);
847
-	    $pdf->SetFont('','B', $default_font_size - 3);
728
+                    $tab_top = 88;
848 729
 
849
-	    // Output Rect
850
-	    //$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
730
+                    $pdf->SetFont('','', $default_font_size - 1);
731
+                    $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
732
+                    $nexY = $pdf->GetY();
733
+                    $height_note=$nexY-$tab_top;
851 734
 
852
-		$pdf->SetLineStyle(array('dash'=>'0','color'=>array(220,26,26)));
853
-		$pdf->SetDrawColor(220,26,26);
854
-		$pdf->line($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite, $tab_top);
855
-		$pdf->SetLineStyle(array('dash'=>0));
856
-		$pdf->SetDrawColor(128,128,128);
857
-		$pdf->SetTextColor(0,0,120);
735
+                    // Rect prend une longueur en 3eme param
736
+                    $pdf->SetDrawColor(192,192,192);
737
+                    $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
858 738
 
859
-		//Ref mouv
860
-	    if (empty($hidetop))
861
-	    {
862
-	        //$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
863
-	        $pdf->SetXY($this->posxidref, $tab_top+1);
864
-	        $pdf->MultiCell($this->posxdatemouv-$this->posxdatemouv-0.8,3, $outputlangs->transnoentities("Ref"),'','L');
865
-	    }
866
-
867
-		//Date mouv
868
-		//$pdf->line($this->posxlabel-1, $tab_top, $this->posxlabel-1, $tab_top + $tab_height);
869
-		if (empty($hidetop))
870
-		{
871
-			$pdf->SetXY($this->posxdatemouv, $tab_top+1);
872
-			$pdf->MultiCell($this->posxdesc-$this->posxdatemouv,2, $outputlangs->transnoentities("Date"),'','C');
873
-		}
874
-
875
-		//Ref Product
876
-	    //$pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
877
-	    if (empty($hidetop))
878
-	    {
879
-	        $pdf->SetXY($this->posxdesc-1, $tab_top+1);
880
-	        $pdf->MultiCell($this->posxlabel-$this->posxdesc,2, $outputlangs->transnoentities("Ref. Product"),'','C');
881
-	    }
739
+                    $tab_height = $tab_height - $height_note;
740
+                    $tab_top = $nexY+6;
741
+                }
742
+                else
743
+                {
744
+                    $height_note=0;
745
+                }
882 746
 
883
-		//Label Product
884
-	    //$pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
885
-	    if (empty($hidetop))
886
-	    {
887
-	        $pdf->SetXY($this->posxlabel-1, $tab_top+1);
888
-			$pdf->MultiCell($this->posxqty-$this->posxlabel,2, $outputlangs->transnoentities("Label"),'','C');
889
-	    }
890
-
891
-		//Lot/serie Product
892
-		//$pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
893
-		if (empty($hidetop))
894
-		{
895
-			$pdf->SetXY($this->posxqty, $tab_top + 1);
896
-			$pdf->MultiCell($this->posxup - $this->posxqty, 2, $outputlangs->transnoentities("Lot/Série"), '','C');
897
-		}
898
-
899
-		//Code Inv
900
-	    //$pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
901
-	    if (empty($hidetop))
902
-	    {
903
-			$pdf->SetXY($this->posxup-1, $tab_top+1);
904
-			$pdf->MultiCell($this->posxunit-$this->posxup,2, $outputlangs->transnoentities("Inventory Code"),'','C');
905
-	    }
747
+                $iniY = $tab_top + 7;
748
+                $curY = $tab_top + 7;
749
+                $nexY = $tab_top + 7;
906 750
 
907
-		//Label mouvement
908
-	    //$pdf->line($this->posxunit, $tab_top, $this->posxunit, $tab_top + $tab_height);
909
-	    if (empty($hidetop))
910
-	    {
911
-	        $pdf->SetXY($this->posxunit, $tab_top+1);
912
-	        $pdf->MultiCell($this->posxdiscount-$this->posxunit,2, $outputlangs->transnoentities("Label Mouvement"),'','C');
913
-	    }
751
+                $tab_top = $tab_top_newpage+21;
914 752
 
915
-		//Origin
916
-	    //$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
917
-	    if (empty($hidetop))
918
-	    {
919
-	        $pdf->SetXY($this->posxdiscount+2, $tab_top+1);
920
-	        $pdf->MultiCell($this->postotalht-$this->posxdiscount-0.8,2, $outputlangs->transnoentities("Origin"),'','C');
921
-	    }
753
+                // Show square
754
+                if ($pagenb == 1)
755
+                {
756
+                    $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
757
+                    $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
758
+                }
759
+                else
760
+                {
761
+                    $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
762
+                    $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
763
+                }
922 764
 
923
-		//Qty
924
-	    //$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
925
-	    if (empty($hidetop))
926
-	    {
927
-	        $pdf->SetXY($this->postotalht+2, $tab_top+1);
928
-	        $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht,2, $outputlangs->transnoentities("Qty"),'','C');
929
-	    }
930
-
931
-		$pdf->SetDrawColor(220,26,26);
932
-		$pdf->SetLineStyle(array('dash'=>'0','color'=>array(220,26,26)));
933
-		$pdf->line($this->marge_gauche, $tab_top+11, $this->page_largeur-$this->marge_droite, $tab_top+11);
934
-		$pdf->SetLineStyle(array('dash'=>0));
935
-	}
936
-
937
-	/**
938
-	 *  Show top header of page.
939
-	 *
940
-	 *  @param	TCPDF		$pdf     		Object PDF
941
-	 *  @param  Object		$object     	Object to show
942
-	 *  @param  int	    	$showaddress    0=no, 1=yes
943
-	 *  @param  Translate	$outputlangs	Object lang for output
944
-	 *  @param	string		$titlekey		Translation key to show as title of document
945
-	 *  @return	void
946
-	 */
947
-	function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="")
948
-	{
949
-	    global $conf,$langs,$db,$hookmanager;
950
-
951
-	    // Load traductions files requiredby by page
952
-		$outputlangs->loadLangs(array("main", "propal", "companies", "bills", "orders", "stocks"));
953
-
954
-	    $default_font_size = pdf_getPDFFontSize($outputlangs);
955
-
956
-	    if ($object->type == 1) $titlekey='ServiceSheet';
957
-	    else $titlekey='StockSheet';
958
-
959
-	    pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
960
-
961
-	    // Show Draft Watermark
962
-	    if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
963
-	    {
964
-	        pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
965
-	    }
765
+                $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
966 766
 
967
-	    $pdf->SetTextColor(0,0,60);
968
-	    $pdf->SetFont('','B', $default_font_size + 3);
767
+                // Affiche zone infos
768
+                //$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
969 769
 
970
-	    $posy=$this->marge_haute;
971
-	    $posx=$this->page_largeur-$this->marge_droite-100;
770
+                // Affiche zone totaux
771
+                //$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
972 772
 
973
-	    $pdf->SetXY($this->marge_gauche,$posy);
773
+                // Pied de page
774
+                $this->_pagefoot($pdf,$object,$outputlangs);
775
+                if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
974 776
 
975
-	    // Logo
976
-	    $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
977
-	    if ($this->emetteur->logo)
978
-	    {
979
-	        if (is_readable($logo))
980
-	        {
981
-	            $height=pdf_getHeightForLogo($logo);
982
-	            $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
983
-	        }
984
-	        else
985
-	        {
986
-	            $pdf->SetTextColor(200,0,0);
987
-	            $pdf->SetFont('','B', $default_font_size -2);
988
-	            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
989
-	            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
990
-	        }
991
-	    }
992
-	    else
993
-	    {
994
-	        $text=$this->emetteur->name;
995
-	        $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
996
-	    }
777
+                $pdf->Close();
997 778
 
998
-	    $pdf->SetFont('','B', $default_font_size + 3);
999
-	    $pdf->SetXY($posx,$posy);
1000
-	    $pdf->SetTextColor(0,0,60);
1001
-	    $title=$outputlangs->transnoentities("Warehouse");
1002
-	    $pdf->MultiCell(100, 3, $title, '', 'R');
779
+                $pdf->Output($file,'F');
1003 780
 
1004
-	    $pdf->SetFont('','B',$default_font_size);
781
+                // Add pdfgeneration hook
782
+                $hookmanager->initHooks(array('pdfgeneration'));
783
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
784
+                global $action;
785
+                $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
1005 786
 
1006
-	    $posy+=5;
1007
-	    $pdf->SetXY($posx,$posy);
1008
-	    $pdf->SetTextColor(0,0,60);
787
+                if (! empty($conf->global->MAIN_UMASK))
788
+                    @chmod($file, octdec($conf->global->MAIN_UMASK));
1009 789
 
1010
-	    $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->libelle), '', 'R');
790
+                $this->result = array('fullpath'=>$file);
1011 791
 
1012
-	    $posy+=5;
1013
-	    $pdf->SetFont('','', $default_font_size - 1);
1014
-		$pdf->SetXY($posx,$posy);
1015
-	    $pdf->SetTextColor(0,0,60);
1016
-	    $pdf->MultiCell(100, 3, $outputlangs->transnoentities("LocationSummary").' :', '', 'R');
1017
-
1018
-		$posy+=4;
1019
-		$pdf->SetXY($posx-50,$posy);
1020
-		$pdf->MultiCell(150, 3, $object->lieu, '', 'R');
1021
-
1022
-
1023
-		// Parent MouvementStock
1024
-		$posy+=4;
1025
-		$pdf->SetXY($posx,$posy);
1026
-		$pdf->SetTextColor(0,0,60);
1027
-		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ParentWarehouse").' :', '', 'R');
1028
-
1029
-		$posy+=4;
1030
-		$pdf->SetXY($posx-50,$posy);
1031
-		$e = new MouvementStock($db);
1032
-		if(!empty($object->fk_parent) && $e->fetch($object->fk_parent) > 0)
1033
-		{
1034
-			$pdf->MultiCell(150, 3, $e->libelle, '', 'R');
1035
-		}
1036
-		else
1037
-		{
1038
-			$pdf->MultiCell(150, 3, $outputlangs->transnoentities("None"), '', 'R');
1039
-		}
1040
-
1041
-		// Description
1042
-		$nexY = $pdf->GetY();
1043
-		$nexY+=5;
1044
-		$pdf->SetXY($posx,$posy);
1045
-		$pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("Description").' : </b>'.nl2br($object->description), 0, 1);
1046
-		$nexY = $pdf->GetY();
1047
-
1048
-		$calcproductsunique=$object->nb_different_products();
1049
-		$calcproducts=$object->nb_products();
1050
-
1051
-		// Total nb of different products
1052
-		$pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("NumberOfDifferentProducts").' : </b>'.(empty($calcproductsunique['nb'])?'0':$calcproductsunique['nb']), 0, 1);
1053
-		$nexY = $pdf->GetY();
1054
-
1055
-		// Nb of products
1056
-		$valtoshow=price2num($calcproducts['nb'], 'MS');
1057
-		$pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("NumberOfProducts").' : </b>'.(empty($valtoshow)?'0':$valtoshow), 0, 1);
1058
-		$nexY = $pdf->GetY();
1059
-
1060
-		// Value
1061
-		$pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("EstimatedStockValueShort").' : </b>'. price((empty($calcproducts['value'])?'0':price2num($calcproducts['value'],'MT')), 0, $langs, 0, -1, -1, $conf->currency), 0, 1);
1062
-		$nexY = $pdf->GetY();
1063
-
1064
-
1065
-		// Last movement
1066
-		$sql = "SELECT max(m.datem) as datem";
1067
-		$sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
1068
-		$sql .= " WHERE m.fk_entrepot = '".$object->id."'";
1069
-		$resqlbis = $db->query($sql);
1070
-		if ($resqlbis)
1071
-		{
1072
-			$obj = $db->fetch_object($resqlbis);
1073
-			$lastmovementdate=$db->jdate($obj->datem);
1074
-		}
1075
-		else
1076
-		{
1077
-			dol_print_error($db);
1078
-		}
1079
-
1080
-		if ($lastmovementdate)
1081
-		{
1082
-			$toWrite = dol_print_date($lastmovementdate,'dayhour').' ';
1083
-		}
1084
-		else
1085
-		{
1086
-			$toWrite = $outputlangs->transnoentities("None");
1087
-		}
1088
-
1089
-		$pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("LastMovement").' : </b>'.$toWrite, 0, 1);
1090
-		$nexY = $pdf->GetY();
1091
-
1092
-
1093
-	    /*if ($object->ref_client)
792
+                return 1;   // Pas d'erreur
793
+            }
794
+            else
795
+            {
796
+                $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
797
+                return 0;
798
+            }
799
+        }
800
+        else
801
+        {
802
+            $this->error=$langs->trans("ErrorConstantNotDefined","PRODUCT_OUTPUTDIR");
803
+            return 0;
804
+        }
805
+    }
806
+
807
+
808
+    /**
809
+     *   Show table for lines
810
+     *
811
+     *   @param		TCPDF		$pdf     		Object PDF
812
+     *   @param		string		$tab_top		Top position of table
813
+     *   @param		string		$tab_height		Height of table (rectangle)
814
+     *   @param		int			$nexY			Y (not used)
815
+     *   @param		Translate	$outputlangs	Langs object
816
+     *   @param		int			$hidetop		1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
817
+     *   @param		int			$hidebottom		Hide bottom bar of array
818
+     *   @param		string		$currency		Currency code
819
+     *   @return	void
820
+     */
821
+    function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
822
+    {
823
+        global $conf;
824
+
825
+        // Force to disable hidetop and hidebottom
826
+        $hidebottom=0;
827
+        if ($hidetop) $hidetop=-1;
828
+
829
+        $currency = !empty($currency) ? $currency : $conf->currency;
830
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
831
+
832
+        // Amount in (at tab_top - 1)
833
+        $pdf->SetTextColor(0,0,0);
834
+        $pdf->SetFont('','', $default_font_size - 2);
835
+
836
+        if (empty($hidetop))
837
+        {
838
+            $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
839
+            $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
840
+            $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
841
+
842
+            //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
843
+            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));
844
+        }
845
+
846
+        $pdf->SetDrawColor(128,128,128);
847
+        $pdf->SetFont('','B', $default_font_size - 3);
848
+
849
+        // Output Rect
850
+        //$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
851
+
852
+        $pdf->SetLineStyle(array('dash'=>'0','color'=>array(220,26,26)));
853
+        $pdf->SetDrawColor(220,26,26);
854
+        $pdf->line($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite, $tab_top);
855
+        $pdf->SetLineStyle(array('dash'=>0));
856
+        $pdf->SetDrawColor(128,128,128);
857
+        $pdf->SetTextColor(0,0,120);
858
+
859
+        //Ref mouv
860
+        if (empty($hidetop))
861
+        {
862
+            //$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
863
+            $pdf->SetXY($this->posxidref, $tab_top+1);
864
+            $pdf->MultiCell($this->posxdatemouv-$this->posxdatemouv-0.8,3, $outputlangs->transnoentities("Ref"),'','L');
865
+        }
866
+
867
+        //Date mouv
868
+        //$pdf->line($this->posxlabel-1, $tab_top, $this->posxlabel-1, $tab_top + $tab_height);
869
+        if (empty($hidetop))
870
+        {
871
+            $pdf->SetXY($this->posxdatemouv, $tab_top+1);
872
+            $pdf->MultiCell($this->posxdesc-$this->posxdatemouv,2, $outputlangs->transnoentities("Date"),'','C');
873
+        }
874
+
875
+        //Ref Product
876
+        //$pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
877
+        if (empty($hidetop))
878
+        {
879
+            $pdf->SetXY($this->posxdesc-1, $tab_top+1);
880
+            $pdf->MultiCell($this->posxlabel-$this->posxdesc,2, $outputlangs->transnoentities("Ref. Product"),'','C');
881
+        }
882
+
883
+        //Label Product
884
+        //$pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
885
+        if (empty($hidetop))
886
+        {
887
+            $pdf->SetXY($this->posxlabel-1, $tab_top+1);
888
+            $pdf->MultiCell($this->posxqty-$this->posxlabel,2, $outputlangs->transnoentities("Label"),'','C');
889
+        }
890
+
891
+        //Lot/serie Product
892
+        //$pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
893
+        if (empty($hidetop))
894
+        {
895
+            $pdf->SetXY($this->posxqty, $tab_top + 1);
896
+            $pdf->MultiCell($this->posxup - $this->posxqty, 2, $outputlangs->transnoentities("Lot/Série"), '','C');
897
+        }
898
+
899
+        //Code Inv
900
+        //$pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
901
+        if (empty($hidetop))
902
+        {
903
+            $pdf->SetXY($this->posxup-1, $tab_top+1);
904
+            $pdf->MultiCell($this->posxunit-$this->posxup,2, $outputlangs->transnoentities("Inventory Code"),'','C');
905
+        }
906
+
907
+        //Label mouvement
908
+        //$pdf->line($this->posxunit, $tab_top, $this->posxunit, $tab_top + $tab_height);
909
+        if (empty($hidetop))
910
+        {
911
+            $pdf->SetXY($this->posxunit, $tab_top+1);
912
+            $pdf->MultiCell($this->posxdiscount-$this->posxunit,2, $outputlangs->transnoentities("Label Mouvement"),'','C');
913
+        }
914
+
915
+        //Origin
916
+        //$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
917
+        if (empty($hidetop))
918
+        {
919
+            $pdf->SetXY($this->posxdiscount+2, $tab_top+1);
920
+            $pdf->MultiCell($this->postotalht-$this->posxdiscount-0.8,2, $outputlangs->transnoentities("Origin"),'','C');
921
+        }
922
+
923
+        //Qty
924
+        //$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
925
+        if (empty($hidetop))
926
+        {
927
+            $pdf->SetXY($this->postotalht+2, $tab_top+1);
928
+            $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht,2, $outputlangs->transnoentities("Qty"),'','C');
929
+        }
930
+
931
+        $pdf->SetDrawColor(220,26,26);
932
+        $pdf->SetLineStyle(array('dash'=>'0','color'=>array(220,26,26)));
933
+        $pdf->line($this->marge_gauche, $tab_top+11, $this->page_largeur-$this->marge_droite, $tab_top+11);
934
+        $pdf->SetLineStyle(array('dash'=>0));
935
+    }
936
+
937
+    /**
938
+     *  Show top header of page.
939
+     *
940
+     *  @param	TCPDF		$pdf     		Object PDF
941
+     *  @param  Object		$object     	Object to show
942
+     *  @param  int	    	$showaddress    0=no, 1=yes
943
+     *  @param  Translate	$outputlangs	Object lang for output
944
+     *  @param	string		$titlekey		Translation key to show as title of document
945
+     *  @return	void
946
+     */
947
+    function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="")
948
+    {
949
+        global $conf,$langs,$db,$hookmanager;
950
+
951
+        // Load traductions files requiredby by page
952
+        $outputlangs->loadLangs(array("main", "propal", "companies", "bills", "orders", "stocks"));
953
+
954
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
955
+
956
+        if ($object->type == 1) $titlekey='ServiceSheet';
957
+        else $titlekey='StockSheet';
958
+
959
+        pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
960
+
961
+        // Show Draft Watermark
962
+        if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
963
+        {
964
+            pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
965
+        }
966
+
967
+        $pdf->SetTextColor(0,0,60);
968
+        $pdf->SetFont('','B', $default_font_size + 3);
969
+
970
+        $posy=$this->marge_haute;
971
+        $posx=$this->page_largeur-$this->marge_droite-100;
972
+
973
+        $pdf->SetXY($this->marge_gauche,$posy);
974
+
975
+        // Logo
976
+        $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
977
+        if ($this->emetteur->logo)
978
+        {
979
+            if (is_readable($logo))
980
+            {
981
+                $height=pdf_getHeightForLogo($logo);
982
+                $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
983
+            }
984
+            else
985
+            {
986
+                $pdf->SetTextColor(200,0,0);
987
+                $pdf->SetFont('','B', $default_font_size -2);
988
+                $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
989
+                $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
990
+            }
991
+        }
992
+        else
993
+        {
994
+            $text=$this->emetteur->name;
995
+            $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
996
+        }
997
+
998
+        $pdf->SetFont('','B', $default_font_size + 3);
999
+        $pdf->SetXY($posx,$posy);
1000
+        $pdf->SetTextColor(0,0,60);
1001
+        $title=$outputlangs->transnoentities("Warehouse");
1002
+        $pdf->MultiCell(100, 3, $title, '', 'R');
1003
+
1004
+        $pdf->SetFont('','B',$default_font_size);
1005
+
1006
+        $posy+=5;
1007
+        $pdf->SetXY($posx,$posy);
1008
+        $pdf->SetTextColor(0,0,60);
1009
+
1010
+        $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->libelle), '', 'R');
1011
+
1012
+        $posy+=5;
1013
+        $pdf->SetFont('','', $default_font_size - 1);
1014
+        $pdf->SetXY($posx,$posy);
1015
+        $pdf->SetTextColor(0,0,60);
1016
+        $pdf->MultiCell(100, 3, $outputlangs->transnoentities("LocationSummary").' :', '', 'R');
1017
+
1018
+        $posy+=4;
1019
+        $pdf->SetXY($posx-50,$posy);
1020
+        $pdf->MultiCell(150, 3, $object->lieu, '', 'R');
1021
+
1022
+
1023
+        // Parent MouvementStock
1024
+        $posy+=4;
1025
+        $pdf->SetXY($posx,$posy);
1026
+        $pdf->SetTextColor(0,0,60);
1027
+        $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ParentWarehouse").' :', '', 'R');
1028
+
1029
+        $posy+=4;
1030
+        $pdf->SetXY($posx-50,$posy);
1031
+        $e = new MouvementStock($db);
1032
+        if(!empty($object->fk_parent) && $e->fetch($object->fk_parent) > 0)
1033
+        {
1034
+            $pdf->MultiCell(150, 3, $e->libelle, '', 'R');
1035
+        }
1036
+        else
1037
+        {
1038
+            $pdf->MultiCell(150, 3, $outputlangs->transnoentities("None"), '', 'R');
1039
+        }
1040
+
1041
+        // Description
1042
+        $nexY = $pdf->GetY();
1043
+        $nexY+=5;
1044
+        $pdf->SetXY($posx,$posy);
1045
+        $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("Description").' : </b>'.nl2br($object->description), 0, 1);
1046
+        $nexY = $pdf->GetY();
1047
+
1048
+        $calcproductsunique=$object->nb_different_products();
1049
+        $calcproducts=$object->nb_products();
1050
+
1051
+        // Total nb of different products
1052
+        $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("NumberOfDifferentProducts").' : </b>'.(empty($calcproductsunique['nb'])?'0':$calcproductsunique['nb']), 0, 1);
1053
+        $nexY = $pdf->GetY();
1054
+
1055
+        // Nb of products
1056
+        $valtoshow=price2num($calcproducts['nb'], 'MS');
1057
+        $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("NumberOfProducts").' : </b>'.(empty($valtoshow)?'0':$valtoshow), 0, 1);
1058
+        $nexY = $pdf->GetY();
1059
+
1060
+        // Value
1061
+        $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("EstimatedStockValueShort").' : </b>'. price((empty($calcproducts['value'])?'0':price2num($calcproducts['value'],'MT')), 0, $langs, 0, -1, -1, $conf->currency), 0, 1);
1062
+        $nexY = $pdf->GetY();
1063
+
1064
+
1065
+        // Last movement
1066
+        $sql = "SELECT max(m.datem) as datem";
1067
+        $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
1068
+        $sql .= " WHERE m.fk_entrepot = '".$object->id."'";
1069
+        $resqlbis = $db->query($sql);
1070
+        if ($resqlbis)
1071
+        {
1072
+            $obj = $db->fetch_object($resqlbis);
1073
+            $lastmovementdate=$db->jdate($obj->datem);
1074
+        }
1075
+        else
1076
+        {
1077
+            dol_print_error($db);
1078
+        }
1079
+
1080
+        if ($lastmovementdate)
1081
+        {
1082
+            $toWrite = dol_print_date($lastmovementdate,'dayhour').' ';
1083
+        }
1084
+        else
1085
+        {
1086
+            $toWrite = $outputlangs->transnoentities("None");
1087
+        }
1088
+
1089
+        $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("LastMovement").' : </b>'.$toWrite, 0, 1);
1090
+        $nexY = $pdf->GetY();
1091
+
1092
+
1093
+        /*if ($object->ref_client)
1094 1094
 	    {
1095 1095
 	        $posy+=5;
1096 1096
 	        $pdf->SetXY($posx,$posy);
@@ -1098,14 +1098,14 @@  discard block
 block discarded – undo
1098 1098
 	        $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1099 1099
 	    }*/
1100 1100
 
1101
-	    /*$posy+=4;
1101
+        /*$posy+=4;
1102 1102
 	    $pdf->SetXY($posx,$posy);
1103 1103
 	    $pdf->SetTextColor(0,0,60);
1104 1104
 	    $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderDate")." : " . dol_print_date($object->date,"%d %b %Y",false,$outputlangs,true), '', 'R');
1105 1105
 	    */
1106 1106
 
1107
-	    // Get contact
1108
-	    /*
1107
+        // Get contact
1108
+        /*
1109 1109
 	    if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1110 1110
 	    {
1111 1111
 	        $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
@@ -1120,14 +1120,14 @@  discard block
 block discarded – undo
1120 1120
 	        }
1121 1121
 	    }*/
1122 1122
 
1123
-	    $posy+=2;
1123
+        $posy+=2;
1124 1124
 
1125
-	    // Show list of linked objects
1126
-	    //$posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1125
+        // Show list of linked objects
1126
+        //$posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1127 1127
 
1128
-	    if ($showaddress)
1129
-	    {
1130
-	        /*
1128
+        if ($showaddress)
1129
+        {
1130
+            /*
1131 1131
 	        // Sender properties
1132 1132
 	        $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
1133 1133
 
@@ -1158,24 +1158,24 @@  discard block
 block discarded – undo
1158 1158
 	        $pdf->SetFont('','', $default_font_size - 1);
1159 1159
 	        $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1160 1160
 	        */
1161
-	    }
1162
-
1163
-	    $pdf->SetTextColor(0,0,0);
1164
-	}
1165
-
1166
-	/**
1167
-	 *   	Show footer of page. Need this->emetteur object
1168
-	 *
1169
-	 *   	@param	TCPDF		$pdf     			PDF
1170
-	 * 		@param	Object		$object				Object to show
1171
-	 *      @param	Translate	$outputlangs		Object lang for output
1172
-	 *      @param	int			$hidefreetext		1=Hide free text
1173
-	 *      @return	int								Return height of bottom margin including footer text
1174
-	 */
1175
-	function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1176
-	{
1177
-	    global $conf;
1178
-	    $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1179
-	    return pdf_pagefoot($pdf,$outputlangs,'PRODUCT_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1180
-	}
1161
+        }
1162
+
1163
+        $pdf->SetTextColor(0,0,0);
1164
+    }
1165
+
1166
+    /**
1167
+     *   	Show footer of page. Need this->emetteur object
1168
+     *
1169
+     *   	@param	TCPDF		$pdf     			PDF
1170
+     * 		@param	Object		$object				Object to show
1171
+     *      @param	Translate	$outputlangs		Object lang for output
1172
+     *      @param	int			$hidefreetext		1=Hide free text
1173
+     *      @return	int								Return height of bottom margin including footer text
1174
+     */
1175
+    function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1176
+    {
1177
+        global $conf;
1178
+        $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1179
+        return pdf_pagefoot($pdf,$outputlangs,'PRODUCT_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1180
+    }
1181 1181
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/stock/modules_movement.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -30,29 +30,29 @@
 block discarded – undo
30 30
  */
31 31
 abstract class ModelePDFMovement extends CommonDocGenerator
32 32
 {
33
-	/**
34
-	 * @var string Error code (or message)
35
-	 */
36
-	public $error='';
33
+    /**
34
+     * @var string Error code (or message)
35
+     */
36
+    public $error='';
37 37
 
38 38
 
39 39
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
40
-	/**
41
-	 *	Return list of active generation modules
42
-	 *
40
+    /**
41
+     *	Return list of active generation modules
42
+     *
43 43
      *  @param	DoliDB	$db     			Database handler
44 44
      *  @param  integer	$maxfilenamelength  Max length of value to show
45 45
      *  @return	array						List of templates
46
-	 */
47
-	static function liste_modeles($db,$maxfilenamelength=0)
48
-	{
46
+     */
47
+    static function liste_modeles($db,$maxfilenamelength=0)
48
+    {
49 49
         // phpcs:enable
50
-		global $conf;
50
+        global $conf;
51 51
 
52
-		$type='mouvement';
53
-		$liste=array();
54
-		include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
55
-		$liste=getListOfModels($db,$type,$maxfilenamelength);
56
-		return $liste;
57
-	}
52
+        $type='mouvement';
53
+        $liste=array();
54
+        include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
55
+        $liste=getListOfModels($db,$type,$maxfilenamelength);
56
+        return $liste;
57
+    }
58 58
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/modProjet.class.php 1 patch
Indentation   +312 added lines, -312 removed lines patch added patch discarded remove patch
@@ -36,332 +36,332 @@
 block discarded – undo
36 36
  */
37 37
 class modProjet extends DolibarrModules
38 38
 {
39
-	/**
40
-	 *   Constructor. Define names, constants, directories, boxes, permissions
41
-	 *
42
-	 *   @param      DoliDB		$db      Database handler
43
-	 */
44
-	function __construct($db)
45
-	{
46
-		global $conf;
47
-
48
-		$this->db = $db;
49
-		$this->numero = 400;
50
-
51
-		$this->family = "projects";
52
-		$this->module_position = '10';
53
-		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
54
-		$this->name = preg_replace('/^mod/i','',get_class($this));
55
-		$this->description = "Gestion des projets";
56
-		// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
57
-		$this->version = 'dolibarr';
58
-
59
-		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
60
-		$this->config_page_url = array("project.php@projet");
61
-		$this->picto='project';
62
-
63
-		// Data directories to create when module is enabled
64
-		$this->dirs = array("/projet/temp");
65
-
66
-		// Dependencies
67
-		$this->hidden = false;			// A condition to hide module
68
-		$this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
69
-		$this->requiredby = array();	// List of module ids to disable if this one is disabled
70
-		$this->conflictwith = array();	// List of module class names as string this module is in conflict with
71
-		$this->phpmin = array(5,4);		// Minimum version of PHP required by module
72
-		$this->langfiles = array('projects');
73
-
74
-		// Constants
75
-		$this->const = array();
76
-		$r=0;
77
-
78
-		$this->const[$r][0] = "PROJECT_ADDON_PDF";
79
-		$this->const[$r][1] = "chaine";
80
-		$this->const[$r][2] = "baleine";
81
-		$this->const[$r][3] = 'Name of PDF/ODT project manager class';
82
-		$this->const[$r][4] = 0;
83
-		$r++;
84
-
85
-		$this->const[$r][0] = "PROJECT_ADDON";
86
-		$this->const[$r][1] = "chaine";
87
-		$this->const[$r][2] = "mod_project_simple";
88
-		$this->const[$r][3] = 'Name of Numbering Rule project manager class';
89
-		$this->const[$r][4] = 0;
90
-		$r++;
91
-
92
-		$this->const[$r][0] = "PROJECT_ADDON_PDF_ODT_PATH";
93
-		$this->const[$r][1] = "chaine";
94
-		$this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/projects";
95
-		$this->const[$r][3] = "";
96
-		$this->const[$r][4] = 0;
97
-		$r++;
98
-
99
-		$this->const[$r][0] = "PROJECT_TASK_ADDON_PDF";
100
-		$this->const[$r][1] = "chaine";
101
-		$this->const[$r][2] = "";
102
-		$this->const[$r][3] = 'Name of PDF/ODT tasks manager class';
103
-		$this->const[$r][4] = 0;
104
-		$r++;
105
-
106
-		$this->const[$r][0] = "PROJECT_TASK_ADDON";
107
-		$this->const[$r][1] = "chaine";
108
-		$this->const[$r][2] = "mod_task_simple";
109
-		$this->const[$r][3] = 'Name of Numbering Rule task manager class';
110
-		$this->const[$r][4] = 0;
111
-		$r++;
112
-
113
-		$this->const[$r][0] = "PROJECT_TASK_ADDON_PDF_ODT_PATH";
114
-		$this->const[$r][1] = "chaine";
115
-		$this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/tasks";
116
-		$this->const[$r][3] = "";
117
-		$this->const[$r][4] = 0;
118
-		$r++;
119
-
120
-		$this->const[$r][0] = "PROJECT_USE_OPPORTUNITIES";
121
-		$this->const[$r][1] = "chaine";
122
-		$this->const[$r][2] = "1";
123
-		$this->const[$r][3] = "";
124
-		$this->const[$r][4] = 0;
125
-		$r++;
126
-
127
-		$this->const[$r][0] = "MAIN_DELAY_PROJECT_TO_CLOSE";
128
-		$this->const[$r][1] = "chaine";
129
-		$this->const[$r][2] = "7";
130
-		$this->const[$r][3] = "";
131
-		$this->const[$r][4] = 0;
132
-		$r++;
133
-		$this->const[$r][0] = "MAIN_DELAY_TASKS_TODO";
134
-		$this->const[$r][1] = "chaine";
135
-		$this->const[$r][2] = "7";
136
-		$this->const[$r][3] = "";
137
-		$this->const[$r][4] = 0;
138
-		$r++;
139
-
140
-		// Boxes
141
-		$this->boxes = array();
142
-		$r=0;
143
-		$this->boxes[$r][1] = "box_project.php";
144
-		$r++;
145
-		$this->boxes[$r][1] = "box_task.php";
146
-		$r++;
147
-
148
-		// Permissions
149
-		$this->rights = array();
150
-		$this->rights_class = 'projet';
151
-		$r=0;
152
-
153
-		$r++;
154
-		$this->rights[$r][0] = 41; // id de la permission
155
-		$this->rights[$r][1] = "Read projects and tasks (shared projects or projects I am contact for). Can also enter time consumed on assigned tasks (timesheet)"; // libelle de la permission
156
-		$this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
157
-		$this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
158
-		$this->rights[$r][4] = 'lire';
159
-
160
-		$r++;
161
-		$this->rights[$r][0] = 42; // id de la permission
162
-		$this->rights[$r][1] = "Create/modify projects and tasks (shared projects or projects I am contact for)"; // libelle de la permission
163
-		$this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
164
-		$this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
165
-		$this->rights[$r][4] = 'creer';
166
-
167
-		$r++;
168
-		$this->rights[$r][0] = 44; // id de la permission
169
-		$this->rights[$r][1] = "Delete project and tasks (shared projects or projects I am contact for)"; // libelle de la permission
170
-		$this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
171
-		$this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
172
-		$this->rights[$r][4] = 'supprimer';
173
-
174
-		$r++;
175
-		$this->rights[$r][0] = 45; // id de la permission
176
-		$this->rights[$r][1] = "Export projects"; // libelle de la permission
177
-		$this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
178
-		$this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
179
-		$this->rights[$r][4] = 'export';
180
-
181
-		$r++;
182
-		$this->rights[$r][0] = 141; // id de la permission
183
-		$this->rights[$r][1] = "Read all projects and tasks (also private projects I am not contact for)"; // libelle de la permission
184
-		$this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
185
-		$this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
186
-		$this->rights[$r][4] = 'all';
187
-		$this->rights[$r][5] = 'lire';
188
-
189
-		$r++;
190
-		$this->rights[$r][0] = 142; // id de la permission
191
-		$this->rights[$r][1] = "Create/modify all projects and tasks (also private projects I am not contact for). Can also enter time consumed on assigned tasks (timesheet)"; // libelle de la permission
192
-		$this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
193
-		$this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
194
-		$this->rights[$r][4] = 'all';
195
-		$this->rights[$r][5] = 'creer';
196
-
197
-		$r++;
198
-		$this->rights[$r][0] = 144; // id de la permission
199
-		$this->rights[$r][1] = "Delete all projects and tasks (also private projects I am not contact for)"; // libelle de la permission
200
-		$this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
201
-		$this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
202
-		$this->rights[$r][4] = 'all';
203
-		$this->rights[$r][5] = 'supprimer';
204
-
205
-
206
-		// Menus
207
-		//-------
208
-		$this->menu = 1;        // This module add menu entries. They are coded into menu manager.
209
-
210
-
211
-		//Exports
212
-		//--------
213
-		$r=1;
214
-
215
-		$this->export_code[$r]=$this->rights_class.'_'.$r;
216
-		$this->export_label[$r]='ProjectsAndTasksLines';	// Translation key (used only if key ExportDataset_xxx_z not found)
217
-		$this->export_permission[$r]=array(array("projet","export"));
218
-		$this->export_dependencies_array[$r]=array('projecttask'=>'pt.rowid', 'task_time'=>'ptt.rowid');
219
-
220
-		$this->export_TypeFields_array[$r]=array('s.rowid'=>"List:societe:nom",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','s.fk_pays'=>'List:c_country:label',
221
-		's.phone'=>'Text','s.email'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.code_compta'=>'Text','s.code_compta_fournisseur'=>'Text',
222
-		'p.rowid'=>"List:projet:ref",'p.ref'=>"Text",'p.title'=>"Text",'p.datec'=>"Date",'p.dateo'=>"Date",'p.datee'=>"Date",'p.fk_statut'=>'Status','cls.code'=>"Text",'p.opp_percent'=>'Numeric','p.opp_amount'=>'Numeric','p.description'=>"Text",'p.entity'=>'Numeric',
223
-		'pt.rowid'=>'Text','pt.label'=>'Text','pt.dateo'=>"Date",'pt.datee'=>"Date",'pt.duration_effective'=>"Duree",'pt.planned_workload'=>"Numeric",'pt.progress'=>"Numeric",'pt.description'=>"Text",
224
-		'ptt.rowid'=>'Numeric','ptt.task_date'=>'Date','ptt.task_duration'=>"Duree",'ptt.fk_user'=>"List:user:CONCAT(lastname,' ',firstname)",'ptt.note'=>"Text");
225
-		$this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company',
226
-		's.phone'=>'company','s.email'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company');
227
-
228
-		$this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country',
229
-		's.phone'=>'Phone','s.email'=>'Email','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode',
230
-		'p.rowid'=>"ProjectId",'p.ref'=>"RefProject",'p.title'=>'ProjectLabel', 'p.datec'=>"DateCreation",'p.dateo'=>"DateStart",'p.datee'=>"DateEnd",'p.fk_statut'=>'ProjectStatus','cls.code'=>'OpportunityStatus','p.opp_percent'=>'OpportunityProbability','p.opp_amount'=>'OpportunityAmount','p.description'=>"Description");
231
-	    // Add multicompany field
39
+    /**
40
+     *   Constructor. Define names, constants, directories, boxes, permissions
41
+     *
42
+     *   @param      DoliDB		$db      Database handler
43
+     */
44
+    function __construct($db)
45
+    {
46
+        global $conf;
47
+
48
+        $this->db = $db;
49
+        $this->numero = 400;
50
+
51
+        $this->family = "projects";
52
+        $this->module_position = '10';
53
+        // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
54
+        $this->name = preg_replace('/^mod/i','',get_class($this));
55
+        $this->description = "Gestion des projets";
56
+        // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
57
+        $this->version = 'dolibarr';
58
+
59
+        $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
60
+        $this->config_page_url = array("project.php@projet");
61
+        $this->picto='project';
62
+
63
+        // Data directories to create when module is enabled
64
+        $this->dirs = array("/projet/temp");
65
+
66
+        // Dependencies
67
+        $this->hidden = false;			// A condition to hide module
68
+        $this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
69
+        $this->requiredby = array();	// List of module ids to disable if this one is disabled
70
+        $this->conflictwith = array();	// List of module class names as string this module is in conflict with
71
+        $this->phpmin = array(5,4);		// Minimum version of PHP required by module
72
+        $this->langfiles = array('projects');
73
+
74
+        // Constants
75
+        $this->const = array();
76
+        $r=0;
77
+
78
+        $this->const[$r][0] = "PROJECT_ADDON_PDF";
79
+        $this->const[$r][1] = "chaine";
80
+        $this->const[$r][2] = "baleine";
81
+        $this->const[$r][3] = 'Name of PDF/ODT project manager class';
82
+        $this->const[$r][4] = 0;
83
+        $r++;
84
+
85
+        $this->const[$r][0] = "PROJECT_ADDON";
86
+        $this->const[$r][1] = "chaine";
87
+        $this->const[$r][2] = "mod_project_simple";
88
+        $this->const[$r][3] = 'Name of Numbering Rule project manager class';
89
+        $this->const[$r][4] = 0;
90
+        $r++;
91
+
92
+        $this->const[$r][0] = "PROJECT_ADDON_PDF_ODT_PATH";
93
+        $this->const[$r][1] = "chaine";
94
+        $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/projects";
95
+        $this->const[$r][3] = "";
96
+        $this->const[$r][4] = 0;
97
+        $r++;
98
+
99
+        $this->const[$r][0] = "PROJECT_TASK_ADDON_PDF";
100
+        $this->const[$r][1] = "chaine";
101
+        $this->const[$r][2] = "";
102
+        $this->const[$r][3] = 'Name of PDF/ODT tasks manager class';
103
+        $this->const[$r][4] = 0;
104
+        $r++;
105
+
106
+        $this->const[$r][0] = "PROJECT_TASK_ADDON";
107
+        $this->const[$r][1] = "chaine";
108
+        $this->const[$r][2] = "mod_task_simple";
109
+        $this->const[$r][3] = 'Name of Numbering Rule task manager class';
110
+        $this->const[$r][4] = 0;
111
+        $r++;
112
+
113
+        $this->const[$r][0] = "PROJECT_TASK_ADDON_PDF_ODT_PATH";
114
+        $this->const[$r][1] = "chaine";
115
+        $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/tasks";
116
+        $this->const[$r][3] = "";
117
+        $this->const[$r][4] = 0;
118
+        $r++;
119
+
120
+        $this->const[$r][0] = "PROJECT_USE_OPPORTUNITIES";
121
+        $this->const[$r][1] = "chaine";
122
+        $this->const[$r][2] = "1";
123
+        $this->const[$r][3] = "";
124
+        $this->const[$r][4] = 0;
125
+        $r++;
126
+
127
+        $this->const[$r][0] = "MAIN_DELAY_PROJECT_TO_CLOSE";
128
+        $this->const[$r][1] = "chaine";
129
+        $this->const[$r][2] = "7";
130
+        $this->const[$r][3] = "";
131
+        $this->const[$r][4] = 0;
132
+        $r++;
133
+        $this->const[$r][0] = "MAIN_DELAY_TASKS_TODO";
134
+        $this->const[$r][1] = "chaine";
135
+        $this->const[$r][2] = "7";
136
+        $this->const[$r][3] = "";
137
+        $this->const[$r][4] = 0;
138
+        $r++;
139
+
140
+        // Boxes
141
+        $this->boxes = array();
142
+        $r=0;
143
+        $this->boxes[$r][1] = "box_project.php";
144
+        $r++;
145
+        $this->boxes[$r][1] = "box_task.php";
146
+        $r++;
147
+
148
+        // Permissions
149
+        $this->rights = array();
150
+        $this->rights_class = 'projet';
151
+        $r=0;
152
+
153
+        $r++;
154
+        $this->rights[$r][0] = 41; // id de la permission
155
+        $this->rights[$r][1] = "Read projects and tasks (shared projects or projects I am contact for). Can also enter time consumed on assigned tasks (timesheet)"; // libelle de la permission
156
+        $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
157
+        $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
158
+        $this->rights[$r][4] = 'lire';
159
+
160
+        $r++;
161
+        $this->rights[$r][0] = 42; // id de la permission
162
+        $this->rights[$r][1] = "Create/modify projects and tasks (shared projects or projects I am contact for)"; // libelle de la permission
163
+        $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
164
+        $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
165
+        $this->rights[$r][4] = 'creer';
166
+
167
+        $r++;
168
+        $this->rights[$r][0] = 44; // id de la permission
169
+        $this->rights[$r][1] = "Delete project and tasks (shared projects or projects I am contact for)"; // libelle de la permission
170
+        $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
171
+        $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
172
+        $this->rights[$r][4] = 'supprimer';
173
+
174
+        $r++;
175
+        $this->rights[$r][0] = 45; // id de la permission
176
+        $this->rights[$r][1] = "Export projects"; // libelle de la permission
177
+        $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
178
+        $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
179
+        $this->rights[$r][4] = 'export';
180
+
181
+        $r++;
182
+        $this->rights[$r][0] = 141; // id de la permission
183
+        $this->rights[$r][1] = "Read all projects and tasks (also private projects I am not contact for)"; // libelle de la permission
184
+        $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
185
+        $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
186
+        $this->rights[$r][4] = 'all';
187
+        $this->rights[$r][5] = 'lire';
188
+
189
+        $r++;
190
+        $this->rights[$r][0] = 142; // id de la permission
191
+        $this->rights[$r][1] = "Create/modify all projects and tasks (also private projects I am not contact for). Can also enter time consumed on assigned tasks (timesheet)"; // libelle de la permission
192
+        $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
193
+        $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
194
+        $this->rights[$r][4] = 'all';
195
+        $this->rights[$r][5] = 'creer';
196
+
197
+        $r++;
198
+        $this->rights[$r][0] = 144; // id de la permission
199
+        $this->rights[$r][1] = "Delete all projects and tasks (also private projects I am not contact for)"; // libelle de la permission
200
+        $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
201
+        $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
202
+        $this->rights[$r][4] = 'all';
203
+        $this->rights[$r][5] = 'supprimer';
204
+
205
+
206
+        // Menus
207
+        //-------
208
+        $this->menu = 1;        // This module add menu entries. They are coded into menu manager.
209
+
210
+
211
+        //Exports
212
+        //--------
213
+        $r=1;
214
+
215
+        $this->export_code[$r]=$this->rights_class.'_'.$r;
216
+        $this->export_label[$r]='ProjectsAndTasksLines';	// Translation key (used only if key ExportDataset_xxx_z not found)
217
+        $this->export_permission[$r]=array(array("projet","export"));
218
+        $this->export_dependencies_array[$r]=array('projecttask'=>'pt.rowid', 'task_time'=>'ptt.rowid');
219
+
220
+        $this->export_TypeFields_array[$r]=array('s.rowid'=>"List:societe:nom",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','s.fk_pays'=>'List:c_country:label',
221
+        's.phone'=>'Text','s.email'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.code_compta'=>'Text','s.code_compta_fournisseur'=>'Text',
222
+        'p.rowid'=>"List:projet:ref",'p.ref'=>"Text",'p.title'=>"Text",'p.datec'=>"Date",'p.dateo'=>"Date",'p.datee'=>"Date",'p.fk_statut'=>'Status','cls.code'=>"Text",'p.opp_percent'=>'Numeric','p.opp_amount'=>'Numeric','p.description'=>"Text",'p.entity'=>'Numeric',
223
+        'pt.rowid'=>'Text','pt.label'=>'Text','pt.dateo'=>"Date",'pt.datee'=>"Date",'pt.duration_effective'=>"Duree",'pt.planned_workload'=>"Numeric",'pt.progress'=>"Numeric",'pt.description'=>"Text",
224
+        'ptt.rowid'=>'Numeric','ptt.task_date'=>'Date','ptt.task_duration'=>"Duree",'ptt.fk_user'=>"List:user:CONCAT(lastname,' ',firstname)",'ptt.note'=>"Text");
225
+        $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company',
226
+        's.phone'=>'company','s.email'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company');
227
+
228
+        $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country',
229
+        's.phone'=>'Phone','s.email'=>'Email','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode',
230
+        'p.rowid'=>"ProjectId",'p.ref'=>"RefProject",'p.title'=>'ProjectLabel', 'p.datec'=>"DateCreation",'p.dateo'=>"DateStart",'p.datee'=>"DateEnd",'p.fk_statut'=>'ProjectStatus','cls.code'=>'OpportunityStatus','p.opp_percent'=>'OpportunityProbability','p.opp_amount'=>'OpportunityAmount','p.description'=>"Description");
231
+        // Add multicompany field
232 232
         if (! empty($conf->global->MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED))
233 233
         {
234 234
             $nbofallowedentities=count(explode(',',getEntity('project')));    // If project are shared, nb will be > 1
235 235
             if (! empty($conf->multicompany->enabled) && $nbofallowedentities > 1) $this->export_fields_array[$r]+=array('p.entity'=>'Entity');
236 236
         }
237
-		if (empty($conf->global->PROJECT_USE_OPPORTUNITIES))
238
-		{
239
-		    unset($this->export_fields_array[$r]['p.opp_percent']);
240
-		    unset($this->export_fields_array[$r]['p.opp_amount']);
241
-		    unset($this->export_fields_array[$r]['cls.code']);
242
-		}
243
-
244
-		// Add fields for project
245
-		$this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array());
246
-		// Add extra fields for project
247
-		$keyforselect='projet'; $keyforelement='project'; $keyforaliasextra='extra';
248
-		include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
249
-		// Add fields for tasks
237
+        if (empty($conf->global->PROJECT_USE_OPPORTUNITIES))
238
+        {
239
+            unset($this->export_fields_array[$r]['p.opp_percent']);
240
+            unset($this->export_fields_array[$r]['p.opp_amount']);
241
+            unset($this->export_fields_array[$r]['cls.code']);
242
+        }
243
+
244
+        // Add fields for project
245
+        $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array());
246
+        // Add extra fields for project
247
+        $keyforselect='projet'; $keyforelement='project'; $keyforaliasextra='extra';
248
+        include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
249
+        // Add fields for tasks
250 250
         $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array('pt.rowid'=>'RefTask','pt.label'=>'LabelTask','pt.dateo'=>"TaskDateStart",'pt.datee'=>"TaskDateEnd",'pt.duration_effective'=>"DurationEffective",'pt.planned_workload'=>"PlannedWorkload",'pt.progress'=>"Progress",'pt.description'=>"TaskDescription"));
251
-		$this->export_entities_array[$r]=array_merge($this->export_entities_array[$r], array('pt.rowid'=>'projecttask','pt.label'=>'projecttask','pt.dateo'=>"projecttask",'pt.datee'=>"projecttask",'pt.duration_effective'=>"projecttask",'pt.planned_workload'=>"projecttask",'pt.progress'=>"projecttask",'pt.description'=>"projecttask"));
251
+        $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r], array('pt.rowid'=>'projecttask','pt.label'=>'projecttask','pt.dateo'=>"projecttask",'pt.datee'=>"projecttask",'pt.duration_effective'=>"projecttask",'pt.planned_workload'=>"projecttask",'pt.progress'=>"projecttask",'pt.description'=>"projecttask"));
252 252
         // Add extra fields for task
253
-		$keyforselect='projet_task'; $keyforelement='projecttask'; $keyforaliasextra='extra2';
254
-		include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
253
+        $keyforselect='projet_task'; $keyforelement='projecttask'; $keyforaliasextra='extra2';
254
+        include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
255 255
         // End add extra fields
256
-		$this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array('ptt.rowid'=>'IdTaskTime','ptt.task_date'=>'TaskTimeDate','ptt.task_duration'=>"TimesSpent",'ptt.fk_user'=>"TaskTimeUser",'ptt.note'=>"TaskTimeNote"));
256
+        $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array('ptt.rowid'=>'IdTaskTime','ptt.task_date'=>'TaskTimeDate','ptt.task_duration'=>"TimesSpent",'ptt.fk_user'=>"TaskTimeUser",'ptt.note'=>"TaskTimeNote"));
257 257
         $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r], array('ptt.rowid'=>'task_time','ptt.task_date'=>'task_time','ptt.task_duration'=>"task_time",'ptt.fk_user'=>"task_time",'ptt.note'=>"task_time"));
258 258
 
259 259
         $this->export_sql_start[$r]='SELECT DISTINCT ';
260
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'projet as p';
260
+        $this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'projet as p';
261 261
         $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet_extrafields as extra ON p.rowid = extra.fk_object';
262 262
         $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_lead_status as cls ON p.fk_opp_status = cls.rowid';
263 263
         $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX."projet_task as pt ON p.rowid = pt.fk_projet";
264 264
         $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet_task_extrafields as extra2 ON pt.rowid = extra2.fk_object';
265
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX."projet_task_time as ptt ON pt.rowid = ptt.fk_task";
266
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON p.fk_soc = s.rowid';
267
-		$this->export_sql_end[$r] .=" WHERE p.entity IN (".getEntity('project').")";
268
-
269
-
270
-		// Import list of tasks
271
-		if (empty($conf->global->PROJECT_HIDE_TASKS))
272
-		{
273
-    		$r++;
274
-    		$this->import_code[$r]='tasksofprojects';
275
-    		$this->import_label[$r]='ImportDatasetTasks';
276
-    		$this->import_icon[$r]='task';
277
-    		$this->import_entities_array[$r]=array('t.fk_projet'=>'project');	// We define here only fields that use another icon that the one defined into import_icon
278
-    		$this->import_tables_array[$r]=array('t'=>MAIN_DB_PREFIX.'projet_task','extra'=>MAIN_DB_PREFIX.'projet_task_extrafields');	// List of tables to insert into (insert done in same order)
279
-    		$this->import_fields_array[$r]=array('t.fk_projet'=>'ProjectRef*','t.ref'=>'RefTask*','t.label'=>'LabelTask*','t.dateo'=>"DateStart",'t.datee'=>"DateEnd",'t.planned_workload'=>"PlannedWorkload",'t.progress'=>"Progress",'t.note_private'=>"NotePrivate",'t.note_public'=>"NotePublic",'t.datec'=>"DateCreation");
280
-    		// Add extra fields
281
-    		$sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'projet_task' AND entity IN (0,".$conf->entity.")";
282
-    		$resql=$this->db->query($sql);
283
-    		if ($resql)    // This can fail when class is used on old database (during migration for example)
284
-    		{
285
-    		    while ($obj=$this->db->fetch_object($resql))
286
-    		    {
287
-    		        $fieldname='extra.'.$obj->name;
288
-    		        $fieldlabel=ucfirst($obj->label);
289
-    		        $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
290
-    		    }
291
-    		}
292
-    		// End add extra fields
293
-    		$this->import_fieldshidden_array[$r]=array('t.fk_user_creat'=>'user->id','extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'projet_task');    // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
294
-    		$this->import_convertvalue_array[$r]=array(
295
-    		    't.fk_projet'=>array('rule'=>'fetchidfromref','classfile'=>'/projet/class/project.class.php','class'=>'Project','method'=>'fetch','element'=>'Project'),
296
-    		    't.ref'=>array('rule'=>'getrefifauto')
297
-    		);
298
-    		//$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
299
-    		$this->import_regex_array[$r]=array('t.dateo'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','t.datee'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','t.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$');
300
-    		$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");
301
-		}
302
-	}
303
-
304
-
305
-	/**
306
-	 *		Function called when module is enabled.
307
-	 *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
308
-	 *		It also creates data directories
309
-	 *
265
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX."projet_task_time as ptt ON pt.rowid = ptt.fk_task";
266
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON p.fk_soc = s.rowid';
267
+        $this->export_sql_end[$r] .=" WHERE p.entity IN (".getEntity('project').")";
268
+
269
+
270
+        // Import list of tasks
271
+        if (empty($conf->global->PROJECT_HIDE_TASKS))
272
+        {
273
+            $r++;
274
+            $this->import_code[$r]='tasksofprojects';
275
+            $this->import_label[$r]='ImportDatasetTasks';
276
+            $this->import_icon[$r]='task';
277
+            $this->import_entities_array[$r]=array('t.fk_projet'=>'project');	// We define here only fields that use another icon that the one defined into import_icon
278
+            $this->import_tables_array[$r]=array('t'=>MAIN_DB_PREFIX.'projet_task','extra'=>MAIN_DB_PREFIX.'projet_task_extrafields');	// List of tables to insert into (insert done in same order)
279
+            $this->import_fields_array[$r]=array('t.fk_projet'=>'ProjectRef*','t.ref'=>'RefTask*','t.label'=>'LabelTask*','t.dateo'=>"DateStart",'t.datee'=>"DateEnd",'t.planned_workload'=>"PlannedWorkload",'t.progress'=>"Progress",'t.note_private'=>"NotePrivate",'t.note_public'=>"NotePublic",'t.datec'=>"DateCreation");
280
+            // Add extra fields
281
+            $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'projet_task' AND entity IN (0,".$conf->entity.")";
282
+            $resql=$this->db->query($sql);
283
+            if ($resql)    // This can fail when class is used on old database (during migration for example)
284
+            {
285
+                while ($obj=$this->db->fetch_object($resql))
286
+                {
287
+                    $fieldname='extra.'.$obj->name;
288
+                    $fieldlabel=ucfirst($obj->label);
289
+                    $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
290
+                }
291
+            }
292
+            // End add extra fields
293
+            $this->import_fieldshidden_array[$r]=array('t.fk_user_creat'=>'user->id','extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'projet_task');    // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
294
+            $this->import_convertvalue_array[$r]=array(
295
+                't.fk_projet'=>array('rule'=>'fetchidfromref','classfile'=>'/projet/class/project.class.php','class'=>'Project','method'=>'fetch','element'=>'Project'),
296
+                't.ref'=>array('rule'=>'getrefifauto')
297
+            );
298
+            //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
299
+            $this->import_regex_array[$r]=array('t.dateo'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','t.datee'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','t.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$');
300
+            $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");
301
+        }
302
+    }
303
+
304
+
305
+    /**
306
+     *		Function called when module is enabled.
307
+     *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
308
+     *		It also creates data directories
309
+     *
310 310
      *      @param      string	$options    Options when enabling module ('', 'noboxes')
311
-	 *      @return     int             	1 if OK, 0 if KO
312
-	 */
313
-	function init($options='')
314
-	{
315
-		global $conf,$langs;
316
-
317
-		// Permissions
318
-		$this->remove($options);
319
-
320
-		//ODT template for project
321
-		$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/projects/template_project.odt';
322
-		$dirodt=DOL_DATA_ROOT.'/doctemplates/projects';
323
-		$dest=$dirodt.'/template_project.odt';
324
-
325
-		if (file_exists($src) && ! file_exists($dest))
326
-		{
327
-			require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
328
-			dol_mkdir($dirodt);
329
-			$result=dol_copy($src,$dest,0,0);
330
-			if ($result < 0)
331
-			{
332
-				$langs->load("errors");
333
-				$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
334
-				return 0;
335
-			}
336
-		}
337
-
338
-		//ODT template for tasks
339
-		$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/tasks/template_task_summary.odt';
340
-		$dirodt=DOL_DATA_ROOT.'/doctemplates/tasks';
341
-		$dest=$dirodt.'/template_task_summary.odt';
342
-
343
-		if (file_exists($src) && ! file_exists($dest))
344
-		{
345
-			require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
346
-			dol_mkdir($dirodt);
347
-			$result=dol_copy($src,$dest,0,0);
348
-			if ($result < 0)
349
-			{
350
-				$langs->load("errors");
351
-				$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
352
-				return 0;
353
-			}
354
-		}
355
-
356
-		$sql = array();
357
-		$sql[] ="DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[3][2])."' AND type = 'task' AND entity = ".$conf->entity;
358
-		$sql[] ="INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[3][2])."','task',".$conf->entity.")";
359
-		$sql[] ="DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'beluga' AND type = 'project' AND entity = ".$conf->entity;
360
-		$sql[] ="INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('beluga','project',".$conf->entity.")";
361
-		$sql[] ="DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'baleine' AND type = 'project' AND entity = ".$conf->entity;
362
-		$sql[] ="INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('baleine','project',".$conf->entity.")";
363
-
364
-
365
-		return $this->_init($sql,$options);
366
-	}
311
+     *      @return     int             	1 if OK, 0 if KO
312
+     */
313
+    function init($options='')
314
+    {
315
+        global $conf,$langs;
316
+
317
+        // Permissions
318
+        $this->remove($options);
319
+
320
+        //ODT template for project
321
+        $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/projects/template_project.odt';
322
+        $dirodt=DOL_DATA_ROOT.'/doctemplates/projects';
323
+        $dest=$dirodt.'/template_project.odt';
324
+
325
+        if (file_exists($src) && ! file_exists($dest))
326
+        {
327
+            require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
328
+            dol_mkdir($dirodt);
329
+            $result=dol_copy($src,$dest,0,0);
330
+            if ($result < 0)
331
+            {
332
+                $langs->load("errors");
333
+                $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
334
+                return 0;
335
+            }
336
+        }
337
+
338
+        //ODT template for tasks
339
+        $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/tasks/template_task_summary.odt';
340
+        $dirodt=DOL_DATA_ROOT.'/doctemplates/tasks';
341
+        $dest=$dirodt.'/template_task_summary.odt';
342
+
343
+        if (file_exists($src) && ! file_exists($dest))
344
+        {
345
+            require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
346
+            dol_mkdir($dirodt);
347
+            $result=dol_copy($src,$dest,0,0);
348
+            if ($result < 0)
349
+            {
350
+                $langs->load("errors");
351
+                $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
352
+                return 0;
353
+            }
354
+        }
355
+
356
+        $sql = array();
357
+        $sql[] ="DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[3][2])."' AND type = 'task' AND entity = ".$conf->entity;
358
+        $sql[] ="INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[3][2])."','task',".$conf->entity.")";
359
+        $sql[] ="DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'beluga' AND type = 'project' AND entity = ".$conf->entity;
360
+        $sql[] ="INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('beluga','project',".$conf->entity.")";
361
+        $sql[] ="DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'baleine' AND type = 'project' AND entity = ".$conf->entity;
362
+        $sql[] ="INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('baleine','project',".$conf->entity.")";
363
+
364
+
365
+        return $this->_init($sql,$options);
366
+    }
367 367
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/modFournisseur.class.php 1 patch
Indentation   +568 added lines, -568 removed lines patch added patch discarded remove patch
@@ -35,67 +35,67 @@  discard block
 block discarded – undo
35 35
 class modFournisseur extends DolibarrModules
36 36
 {
37 37
 
38
-	/**
39
-	 *   Constructor. Define names, constants, directories, boxes, permissions
40
-	 *
41
-	 *   @param      DoliDB		$db      Database handler
42
-	 */
43
-	function __construct($db)
44
-	{
45
-		global $conf, $user;
46
-
47
-		$this->db = $db;
48
-		$this->numero = 40;
49
-
50
-		// Family can be 'crm','financial','hr','projects','product','ecm','technic','other'
51
-		// It is used to group modules in module setup page
52
-		$this->family = "srm";
53
-		$this->module_position = '10';
54
-		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
55
-		$this->name = preg_replace('/^mod/i','',get_class($this));
56
-		$this->description = "Gestion des fournisseurs";
57
-
58
-		// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
59
-		$this->version = 'dolibarr';
60
-
61
-		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
62
-		$this->picto='company';
63
-
64
-		// Data directories to create when module is enabled
65
-		$this->dirs = array("/fournisseur/temp",
66
-							"/fournisseur/commande",
67
-		                    "/fournisseur/commande/temp",
68
-		                    "/fournisseur/facture",
69
-		                    "/fournisseur/facture/temp"
70
-		                    );
71
-
72
-		// Dependencies
73
-		$this->depends = array("modSociete");
74
-		$this->requiredby = array();
75
-		$this->langfiles = array('bills', 'companies', 'suppliers', 'orders', 'sendings');
76
-
77
-		// Config pages
78
-		$this->config_page_url = array("supplier_order.php");
79
-
80
-		// Constants
81
-		$this->const = array();
82
-		$r=0;
83
-
84
-		$this->const[$r][0] = "COMMANDE_SUPPLIER_ADDON_PDF";
85
-		$this->const[$r][1] = "chaine";
86
-		$this->const[$r][2] = "muscadet";
87
-		$this->const[$r][3] = 'Nom du gestionnaire de generation des bons de commande en PDF';
88
-		$this->const[$r][4] = 0;
89
-		$r++;
90
-
91
-		$this->const[$r][0] = "COMMANDE_SUPPLIER_ADDON_NUMBER";
92
-		$this->const[$r][1] = "chaine";
93
-		$this->const[$r][2] = "mod_commande_fournisseur_muguet";
94
-		$this->const[$r][3] = 'Nom du gestionnaire de numerotation des commandes fournisseur';
95
-		$this->const[$r][4] = 0;
96
-		$r++;
97
-
98
-		/* For supplier invoice, we must not have default pdf template on. In most cases, we need to join PDF from supplier, not have a document generated.
38
+    /**
39
+     *   Constructor. Define names, constants, directories, boxes, permissions
40
+     *
41
+     *   @param      DoliDB		$db      Database handler
42
+     */
43
+    function __construct($db)
44
+    {
45
+        global $conf, $user;
46
+
47
+        $this->db = $db;
48
+        $this->numero = 40;
49
+
50
+        // Family can be 'crm','financial','hr','projects','product','ecm','technic','other'
51
+        // It is used to group modules in module setup page
52
+        $this->family = "srm";
53
+        $this->module_position = '10';
54
+        // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
55
+        $this->name = preg_replace('/^mod/i','',get_class($this));
56
+        $this->description = "Gestion des fournisseurs";
57
+
58
+        // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
59
+        $this->version = 'dolibarr';
60
+
61
+        $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
62
+        $this->picto='company';
63
+
64
+        // Data directories to create when module is enabled
65
+        $this->dirs = array("/fournisseur/temp",
66
+                            "/fournisseur/commande",
67
+                            "/fournisseur/commande/temp",
68
+                            "/fournisseur/facture",
69
+                            "/fournisseur/facture/temp"
70
+                            );
71
+
72
+        // Dependencies
73
+        $this->depends = array("modSociete");
74
+        $this->requiredby = array();
75
+        $this->langfiles = array('bills', 'companies', 'suppliers', 'orders', 'sendings');
76
+
77
+        // Config pages
78
+        $this->config_page_url = array("supplier_order.php");
79
+
80
+        // Constants
81
+        $this->const = array();
82
+        $r=0;
83
+
84
+        $this->const[$r][0] = "COMMANDE_SUPPLIER_ADDON_PDF";
85
+        $this->const[$r][1] = "chaine";
86
+        $this->const[$r][2] = "muscadet";
87
+        $this->const[$r][3] = 'Nom du gestionnaire de generation des bons de commande en PDF';
88
+        $this->const[$r][4] = 0;
89
+        $r++;
90
+
91
+        $this->const[$r][0] = "COMMANDE_SUPPLIER_ADDON_NUMBER";
92
+        $this->const[$r][1] = "chaine";
93
+        $this->const[$r][2] = "mod_commande_fournisseur_muguet";
94
+        $this->const[$r][3] = 'Nom du gestionnaire de numerotation des commandes fournisseur';
95
+        $this->const[$r][4] = 0;
96
+        $r++;
97
+
98
+        /* For supplier invoice, we must not have default pdf template on. In most cases, we need to join PDF from supplier, not have a document generated.
99 99
 		$this->const[$r][0] = "INVOICE_SUPPLIER_ADDON_PDF";
100 100
 		$this->const[$r][1] = "chaine";
101 101
 		$this->const[$r][2] = "canelle";
@@ -104,84 +104,84 @@  discard block
 block discarded – undo
104 104
 		$r++;
105 105
 		*/
106 106
 
107
-		$this->const[$r][0] = "INVOICE_SUPPLIER_ADDON_NUMBER";
108
-		$this->const[$r][1] = "chaine";
109
-		$this->const[$r][2] = "mod_facture_fournisseur_cactus";
110
-		$this->const[$r][3] = 'Nom du gestionnaire de numerotation des factures fournisseur';
111
-		$this->const[$r][4] = 0;
112
-		$r++;
113
-
114
-		// Boxes
115
-		$this->boxes = array(
116
-		0=>array('file'=>'box_graph_invoices_supplier_permonth.php','enabledbydefaulton'=>'Home'),
117
-		1=>array('file'=>'box_graph_orders_supplier_permonth.php','enabledbydefaulton'=>'Home'),
118
-		2=>array('file'=>'box_fournisseurs.php','enabledbydefaulton'=>'Home'),
119
-		3=>array('file'=>'box_factures_fourn_imp.php','enabledbydefaulton'=>'Home'),
120
-		4=>array('file'=>'box_factures_fourn.php','enabledbydefaulton'=>'Home'),
121
-		5=>array('file'=>'box_supplier_orders.php','enabledbydefaulton'=>'Home'),
122
-		);
123
-
124
-		// Permissions
125
-		$this->rights = array();
126
-		$this->rights_class = 'fournisseur';
127
-		$r=0;
128
-
129
-		$r++;
130
-		$this->rights[$r][0] = 1181;
131
-		$this->rights[$r][1] = 'Consulter les fournisseurs';
132
-		$this->rights[$r][2] = 'r';
133
-		$this->rights[$r][3] = 0;
134
-		$this->rights[$r][4] = 'lire';
107
+        $this->const[$r][0] = "INVOICE_SUPPLIER_ADDON_NUMBER";
108
+        $this->const[$r][1] = "chaine";
109
+        $this->const[$r][2] = "mod_facture_fournisseur_cactus";
110
+        $this->const[$r][3] = 'Nom du gestionnaire de numerotation des factures fournisseur';
111
+        $this->const[$r][4] = 0;
112
+        $r++;
113
+
114
+        // Boxes
115
+        $this->boxes = array(
116
+        0=>array('file'=>'box_graph_invoices_supplier_permonth.php','enabledbydefaulton'=>'Home'),
117
+        1=>array('file'=>'box_graph_orders_supplier_permonth.php','enabledbydefaulton'=>'Home'),
118
+        2=>array('file'=>'box_fournisseurs.php','enabledbydefaulton'=>'Home'),
119
+        3=>array('file'=>'box_factures_fourn_imp.php','enabledbydefaulton'=>'Home'),
120
+        4=>array('file'=>'box_factures_fourn.php','enabledbydefaulton'=>'Home'),
121
+        5=>array('file'=>'box_supplier_orders.php','enabledbydefaulton'=>'Home'),
122
+        );
123
+
124
+        // Permissions
125
+        $this->rights = array();
126
+        $this->rights_class = 'fournisseur';
127
+        $r=0;
128
+
129
+        $r++;
130
+        $this->rights[$r][0] = 1181;
131
+        $this->rights[$r][1] = 'Consulter les fournisseurs';
132
+        $this->rights[$r][2] = 'r';
133
+        $this->rights[$r][3] = 0;
134
+        $this->rights[$r][4] = 'lire';
135 135
 
136
-		$r++;
137
-		$this->rights[$r][0] = 1182;
138
-		$this->rights[$r][1] = 'Consulter les commandes fournisseur';
139
-		$this->rights[$r][2] = 'r';
140
-		$this->rights[$r][3] = 0;
141
-		$this->rights[$r][4] = 'commande';
142
-		$this->rights[$r][5] = 'lire';
136
+        $r++;
137
+        $this->rights[$r][0] = 1182;
138
+        $this->rights[$r][1] = 'Consulter les commandes fournisseur';
139
+        $this->rights[$r][2] = 'r';
140
+        $this->rights[$r][3] = 0;
141
+        $this->rights[$r][4] = 'commande';
142
+        $this->rights[$r][5] = 'lire';
143 143
 
144
-		$r++;
145
-		$this->rights[$r][0] = 1183;
146
-		$this->rights[$r][1] = 'Creer une commande fournisseur';
147
-		$this->rights[$r][2] = 'w';
148
-		$this->rights[$r][3] = 0;
149
-		$this->rights[$r][4] = 'commande';
150
-		$this->rights[$r][5] = 'creer';
144
+        $r++;
145
+        $this->rights[$r][0] = 1183;
146
+        $this->rights[$r][1] = 'Creer une commande fournisseur';
147
+        $this->rights[$r][2] = 'w';
148
+        $this->rights[$r][3] = 0;
149
+        $this->rights[$r][4] = 'commande';
150
+        $this->rights[$r][5] = 'creer';
151 151
 
152
-		$r++;
153
-		$this->rights[$r][0] = 1184;
154
-		$this->rights[$r][1] = 'Valider une commande fournisseur';
155
-		$this->rights[$r][2] = 'w';
156
-		$this->rights[$r][3] = 0;
157
-		$this->rights[$r][4] = 'supplier_order_advance';
158
-		$this->rights[$r][5] = 'validate';
152
+        $r++;
153
+        $this->rights[$r][0] = 1184;
154
+        $this->rights[$r][1] = 'Valider une commande fournisseur';
155
+        $this->rights[$r][2] = 'w';
156
+        $this->rights[$r][3] = 0;
157
+        $this->rights[$r][4] = 'supplier_order_advance';
158
+        $this->rights[$r][5] = 'validate';
159 159
 
160
-		$r++;
161
-		$this->rights[$r][0] = 1185;
162
-		$this->rights[$r][1] = 'Approuver une commande fournisseur';
163
-		$this->rights[$r][2] = 'w';
164
-		$this->rights[$r][3] = 0;
165
-		$this->rights[$r][4] = 'commande';
166
-		$this->rights[$r][5] = 'approuver';
160
+        $r++;
161
+        $this->rights[$r][0] = 1185;
162
+        $this->rights[$r][1] = 'Approuver une commande fournisseur';
163
+        $this->rights[$r][2] = 'w';
164
+        $this->rights[$r][3] = 0;
165
+        $this->rights[$r][4] = 'commande';
166
+        $this->rights[$r][5] = 'approuver';
167 167
 
168
-		$r++;
169
-		$this->rights[$r][0] = 1186;
170
-		$this->rights[$r][1] = 'Commander une commande fournisseur';
171
-		$this->rights[$r][2] = 'w';
172
-		$this->rights[$r][3] = 0;
173
-		$this->rights[$r][4] = 'commande';
174
-		$this->rights[$r][5] = 'commander';
168
+        $r++;
169
+        $this->rights[$r][0] = 1186;
170
+        $this->rights[$r][1] = 'Commander une commande fournisseur';
171
+        $this->rights[$r][2] = 'w';
172
+        $this->rights[$r][3] = 0;
173
+        $this->rights[$r][4] = 'commande';
174
+        $this->rights[$r][5] = 'commander';
175 175
 
176
-		$r++;
177
-		$this->rights[$r][0] = 1187;
178
-		$this->rights[$r][1] = 'Receptionner une commande fournisseur';
179
-		$this->rights[$r][2] = 'd';
180
-		$this->rights[$r][3] = 0;
181
-		$this->rights[$r][4] = 'commande';
182
-		$this->rights[$r][5] = 'receptionner';
176
+        $r++;
177
+        $this->rights[$r][0] = 1187;
178
+        $this->rights[$r][1] = 'Receptionner une commande fournisseur';
179
+        $this->rights[$r][2] = 'd';
180
+        $this->rights[$r][3] = 0;
181
+        $this->rights[$r][4] = 'commande';
182
+        $this->rights[$r][5] = 'receptionner';
183 183
 
184
-		$r++;
184
+        $r++;
185 185
         $this->rights[$r][0] = 1189;
186 186
         $this->rights[$r][1] = 'Check/Uncheck a supplier order reception';
187 187
         $this->rights[$r][2] = 'w';
@@ -189,451 +189,451 @@  discard block
 block discarded – undo
189 189
         $this->rights[$r][4] = 'commande_advance';
190 190
         $this->rights[$r][5] = 'check';
191 191
 
192
-		$r++;
193
-		$this->rights[$r][0] = 1188;
194
-		$this->rights[$r][1] = 'Supprimer une commande fournisseur';
195
-		$this->rights[$r][2] = 'd';
196
-		$this->rights[$r][3] = 0;
197
-		$this->rights[$r][4] = 'commande';
198
-		$this->rights[$r][5] = 'supprimer';
199
-
200
-		if (! empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED))
201
-		{
202
-			$r++;
203
-			$this->rights[$r][0] = 1190;
204
-			$this->rights[$r][1] = 'Approve supplier order (second level)';		// $langs->trans("Permission1190");
205
-			$this->rights[$r][2] = 'w';
206
-			$this->rights[$r][3] = 0;
207
-			$this->rights[$r][4] = 'commande';
208
-			$this->rights[$r][5] = 'approve2';
209
-		}
210
-
211
-		$r++;
212
-		$this->rights[$r][0] = 1191;
213
-		$this->rights[$r][1] = 'Exporter les commande fournisseurs, attributs';
214
-		$this->rights[$r][2] = 'r';
215
-		$this->rights[$r][3] = 0;
216
-		$this->rights[$r][4] = 'commande';
217
-		$this->rights[$r][5] = 'export';
218
-
219
-		$r++;
220
-		$this->rights[$r][0] = 1231;
221
-		$this->rights[$r][1] = 'Consulter les factures fournisseur';
222
-		$this->rights[$r][2] = 'r';
223
-		$this->rights[$r][3] = 0;
224
-		$this->rights[$r][4] = 'facture';
225
-		$this->rights[$r][5] = 'lire';
226
-
227
-		$r++;
228
-		$this->rights[$r][0] = 1232;
229
-		$this->rights[$r][1] = 'Creer une facture fournisseur';
230
-		$this->rights[$r][2] = 'w';
231
-		$this->rights[$r][3] = 0;
232
-		$this->rights[$r][4] = 'facture';
233
-		$this->rights[$r][5] = 'creer';
234
-
235
-		$r++;
236
-		$this->rights[$r][0] = 1233;
237
-		$this->rights[$r][1] = 'Valider une facture fournisseur';
238
-		$this->rights[$r][2] = 'w';
239
-		$this->rights[$r][3] = 0;
240
-		$this->rights[$r][4] = 'supplier_invoice_advance';
241
-		$this->rights[$r][5] = 'validate';
242
-
243
-		$r++;
244
-		$this->rights[$r][0] = 1234;
245
-		$this->rights[$r][1] = 'Supprimer une facture fournisseur';
246
-		$this->rights[$r][2] = 'd';
247
-		$this->rights[$r][3] = 0;
248
-		$this->rights[$r][4] = 'facture';
249
-		$this->rights[$r][5] = 'supprimer';
250
-
251
-		$r++;
252
-		$this->rights[$r][0] = 1235;
253
-		$this->rights[$r][1] = 'Envoyer les factures par mail';
254
-		$this->rights[$r][2] = 'a';
255
-		$this->rights[$r][3] = 0;
256
-		$this->rights[$r][4] = 'supplier_invoice_advance';
257
-		$this->rights[$r][5] = 'send';
258
-
259
-		$r++;
260
-		$this->rights[$r][0] = 1236;
261
-		$this->rights[$r][1] = 'Exporter les factures fournisseurs, attributs et reglements';
262
-		$this->rights[$r][2] = 'r';
263
-		$this->rights[$r][3] = 0;
264
-		$this->rights[$r][4] = 'facture';
265
-		$this->rights[$r][5] = 'export';
192
+        $r++;
193
+        $this->rights[$r][0] = 1188;
194
+        $this->rights[$r][1] = 'Supprimer une commande fournisseur';
195
+        $this->rights[$r][2] = 'd';
196
+        $this->rights[$r][3] = 0;
197
+        $this->rights[$r][4] = 'commande';
198
+        $this->rights[$r][5] = 'supprimer';
199
+
200
+        if (! empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED))
201
+        {
202
+            $r++;
203
+            $this->rights[$r][0] = 1190;
204
+            $this->rights[$r][1] = 'Approve supplier order (second level)';		// $langs->trans("Permission1190");
205
+            $this->rights[$r][2] = 'w';
206
+            $this->rights[$r][3] = 0;
207
+            $this->rights[$r][4] = 'commande';
208
+            $this->rights[$r][5] = 'approve2';
209
+        }
210
+
211
+        $r++;
212
+        $this->rights[$r][0] = 1191;
213
+        $this->rights[$r][1] = 'Exporter les commande fournisseurs, attributs';
214
+        $this->rights[$r][2] = 'r';
215
+        $this->rights[$r][3] = 0;
216
+        $this->rights[$r][4] = 'commande';
217
+        $this->rights[$r][5] = 'export';
266 218
 
219
+        $r++;
220
+        $this->rights[$r][0] = 1231;
221
+        $this->rights[$r][1] = 'Consulter les factures fournisseur';
222
+        $this->rights[$r][2] = 'r';
223
+        $this->rights[$r][3] = 0;
224
+        $this->rights[$r][4] = 'facture';
225
+        $this->rights[$r][5] = 'lire';
267 226
 
268
-	    // Menus
269
-	    //-------
270
-	    $this->menu = 1;        // This module add menu entries. They are coded into menu manager.
227
+        $r++;
228
+        $this->rights[$r][0] = 1232;
229
+        $this->rights[$r][1] = 'Creer une facture fournisseur';
230
+        $this->rights[$r][2] = 'w';
231
+        $this->rights[$r][3] = 0;
232
+        $this->rights[$r][4] = 'facture';
233
+        $this->rights[$r][5] = 'creer';
271 234
 
235
+        $r++;
236
+        $this->rights[$r][0] = 1233;
237
+        $this->rights[$r][1] = 'Valider une facture fournisseur';
238
+        $this->rights[$r][2] = 'w';
239
+        $this->rights[$r][3] = 0;
240
+        $this->rights[$r][4] = 'supplier_invoice_advance';
241
+        $this->rights[$r][5] = 'validate';
272 242
 
273
-		// Exports
274
-		//--------
275
-		$r=0;
243
+        $r++;
244
+        $this->rights[$r][0] = 1234;
245
+        $this->rights[$r][1] = 'Supprimer une facture fournisseur';
246
+        $this->rights[$r][2] = 'd';
247
+        $this->rights[$r][3] = 0;
248
+        $this->rights[$r][4] = 'facture';
249
+        $this->rights[$r][5] = 'supprimer';
276 250
 
277
-		$r++;
278
-		$this->export_code[$r]=$this->rights_class.'_'.$r;
279
-		$this->export_label[$r]='Factures fournisseurs et lignes de facture';
280
-		$this->export_icon[$r]='bill';
281
-		$this->export_permission[$r]=array(array("fournisseur","facture","export"));
282
-		$this->export_fields_array[$r]=array(
283
-			's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','c.code'=>'CountryCode','s.phone'=>'Phone',
284
-			's.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.idprof5'=>'ProfId5','s.idprof6'=>'ProfId6','s.tva_intra'=>'VATIntra',
285
-			'f.rowid'=>"InvoiceId",'f.ref'=>"InvoiceRef",'f.ref_supplier'=>"RefSupplier",'f.datec'=>"InvoiceDateCreation",'f.datef'=>"DateInvoice",'f.date_lim_reglement'=>'DateMaxPayment',
286
-			'f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.total_tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus','f.note_public'=>"InvoiceNote",
287
-			'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.tva_tx'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.remise_percent'=>"Discount",'fd.total_ht'=>"LineTotalHT",
288
-			'fd.total_ttc'=>"LineTotalTTC",'fd.tva'=>"LineTotalVAT",'fd.product_type'=>'TypeOfLineServiceOrProduct','fd.fk_product'=>'ProductId',
289
-			'p.ref'=>'ProductRef','p.label'=>'ProductLabel','p.accountancy_code_buy'=>'ProductAccountancyBuyCode','project.rowid'=>'ProjectId',
290
-			'project.ref'=>'ProjectRef','project.title'=>'ProjectLabel'
291
-		);
292
-		//$this->export_TypeFields_array[$r]=array(
293
-		//    's.rowid'=>"List:societe:CompanyName",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text',
294
-		//    's.ape'=>'Text','s.idprof4'=>'Text','s.tva_intra'=>'Text','f.ref'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",
295
-		//    'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",'fd.description'=>"Text",'fd.tva_tx'=>"Text",'fd.qty'=>"Numeric",'fd.total_ht'=>"Numeric",'fd.total_ttc'=>"Numeric",
296
-		//     'fd.tva'=>"Numeric",'fd.product_type'=>'Numeric','fd.fk_product'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text'
297
-		//);
298
-		$this->export_TypeFields_array[$r]=array(
299
-			's.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text',
300
-			's.tva_intra'=>'Text','f.ref'=>"Text",'f.ref_supplier'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",'f.date_lim_reglement'=>'Date','f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",
301
-			'f.total_tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",'fd.description'=>"Text",'fd.tva_tx'=>"Text",'fd.qty'=>"Numeric",'fd.total_ht'=>"Numeric",
302
-			'fd.total_ttc'=>"Numeric",'fd.tva'=>"Numeric",'fd.product_type'=>'Numeric','fd.fk_product'=>'List:product:label',
303
-			'p.ref'=>'Text','p.label'=>'Text','project.ref'=>'Text','project.title'=>'Text'
304
-		);
305
-		$this->export_entities_array[$r]=array(
306
-			's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','c.code'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company',
307
-			's.ape'=>'company','s.idprof4'=>'company','s.idprof5'=>'company','s.idprof6'=>'company','s.tva_intra'=>'company','f.rowid'=>"invoice",'f.ref'=>"invoice",'f.ref_supplier'=>"invoice",
308
-			'f.datec'=>"invoice",'f.datef'=>"invoice",'f.date_lim_reglement'=>'invoice','f.total_ht'=>"invoice",'f.total_ttc'=>"invoice",'f.total_tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice',
309
-			'f.note_public'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",'fd.remise_percent'=>"invoice_line",
310
-			'fd.total_ht'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva'=>"invoice_line",'fd.product_type'=>'invoice_line','fd.fk_product'=>'product',
311
-			'p.ref'=>'product','p.label'=>'product','p.accountancy_code_buy'=>'product','project.rowid'=>'project','project.ref'=>'project','project.title'=>'project'
312
-		);
313
-		$this->export_dependencies_array[$r]=array('invoice_line'=>'fd.rowid','product'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
314
-		// Add extra fields object
315
-		$sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn'";
316
-		$resql=$this->db->query($sql);
317
-		if ($resql)    // This can fail when class is used on old database (during migration for example)
318
-		{
319
-			while ($obj=$this->db->fetch_object($resql))
320
-			{
321
-				$fieldname='extra.'.$obj->name;
322
-				$fieldlabel=ucfirst($obj->label);
323
-				$typeFilter="Text";
324
-				switch($obj->type)
325
-				{
326
-					case 'int':
327
-					case 'double':
328
-					case 'price':
329
-						$typeFilter="Numeric";
330
-						break;
331
-					case 'date':
332
-					case 'datetime':
333
-						$typeFilter="Date";
334
-						break;
335
-					case 'boolean':
336
-						$typeFilter="Boolean";
337
-						break;
338
-					case 'sellist':
339
-						$tmp='';
340
-						$tmpparam=unserialize($obj->param);	// $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
341
-						if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift(array_keys($tmpparam['options']));
342
-						if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
343
-						break;
344
-				}
345
-				$this->export_fields_array[$r][$fieldname]=$fieldlabel;
346
-				$this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
347
-				$this->export_entities_array[$r][$fieldname]='invoice';
348
-			}
349
-		}
350
-		// End add extra fields
351
-		// Add extra fields line
352
-		$sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn_det'";
353
-		$resql=$this->db->query($sql);
354
-		if ($resql)    // This can fail when class is used on old database (during migration for example)
355
-		{
356
-			while ($obj=$this->db->fetch_object($resql))
357
-			{
358
-				$fieldname='extraline.'.$obj->name;
359
-				$fieldlabel=ucfirst($obj->label);
360
-				$typeFilter="Text";
361
-				switch($obj->type)
362
-				{
363
-					case 'int':
364
-					case 'double':
365
-					case 'price':
366
-						$typeFilter="Numeric";
367
-						break;
368
-					case 'date':
369
-					case 'datetime':
370
-						$typeFilter="Date";
371
-						break;
372
-					case 'boolean':
373
-						$typeFilter="Boolean";
374
-						break;
375
-					case 'sellist':
376
-						$tmp='';
377
-						$tmpparam=unserialize($obj->param);	// $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
378
-						if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift(array_keys($tmpparam['options']));
379
-						if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
380
-						break;
381
-				}
382
-				$this->export_fields_array[$r][$fieldname]=$fieldlabel;
383
-				$this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
384
-				$this->export_entities_array[$r][$fieldname]='invoice_line';
385
-			}
386
-		}
387
-		// End add extra fields line
388
-		$this->export_sql_start[$r]='SELECT DISTINCT ';
389
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'societe as s';
390
-		if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
391
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
392
-		$this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture_fourn as f';
393
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
394
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
395
-		$this->export_sql_end[$r] .=' , '.MAIN_DB_PREFIX.'facture_fourn_det as fd';
396
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det_extrafields as extraline ON fd.rowid = extraline.fk_object';
397
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
398
-		$this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn';
399
-		$this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_invoice').')';
400
-		if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
251
+        $r++;
252
+        $this->rights[$r][0] = 1235;
253
+        $this->rights[$r][1] = 'Envoyer les factures par mail';
254
+        $this->rights[$r][2] = 'a';
255
+        $this->rights[$r][3] = 0;
256
+        $this->rights[$r][4] = 'supplier_invoice_advance';
257
+        $this->rights[$r][5] = 'send';
401 258
 
402
-		$r++;
403
-		$this->export_code[$r]=$this->rights_class.'_'.$r;
404
-		$this->export_label[$r]='Factures fournisseurs et reglements';
405
-		$this->export_icon[$r]='bill';
406
-		$this->export_permission[$r]=array(array("fournisseur","facture","export"));
407
-		$this->export_fields_array[$r]=array(
408
-			's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','c.code'=>'CountryCode','s.phone'=>'Phone',
409
-			's.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.idprof5'=>'ProfId5','s.idprof6'=>'ProfId6',
410
-			's.tva_intra'=>'VATIntra','f.rowid'=>"InvoiceId",'f.ref'=>"InvoiceRef",'f.ref_supplier'=>"RefSupplier",'f.datec'=>"InvoiceDateCreation",
411
-			'f.datef'=>"DateInvoice",'f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.total_tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",
412
-			'f.fk_statut'=>'InvoiceStatus','f.note_public'=>"InvoiceNote",'p.rowid'=>'PaymentId','pf.amount'=>'AmountPayment',
413
-			'p.datep'=>'DatePayment','p.num_paiement'=>'PaymentNumber','project.rowid'=>'ProjectId','project.ref'=>'ProjectRef','project.title'=>'ProjectLabel'
414
-		);
415
-		//$this->export_TypeFields_array[$r]=array(
416
-		//	's.rowid'=>"List:societe:CompanyName",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text',
417
-		//	's.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.tva_intra'=>'Text','f.ref'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",
418
-		//	'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",
419
-		//	'pf.amount'=>'Numeric','p.datep'=>'Date','p.num_paiement'=>'Numeric'
420
-		//);
421
-		$this->export_TypeFields_array[$r]=array(
422
-			's.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text',
423
-			's.idprof4'=>'Text','s.tva_intra'=>'Text','f.ref'=>"Text",'f.ref_supplier'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",'f.total_ht'=>"Numeric",
424
-			'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",'pf.amount'=>'Numeric',
425
-			'p.datep'=>'Date','p.num_paiement'=>'Numeric','project.ref'=>'Text','project.title'=>'Text'
426
-		);
427
-		$this->export_entities_array[$r]=array(
428
-			's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','c.code'=>'company','s.phone'=>'company',
429
-			's.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.idprof5'=>'company','s.idprof6'=>'company','s.tva_intra'=>'company',
430
-			'f.rowid'=>"invoice",'f.ref'=>"invoice",'f.ref_supplier'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total_ht'=>"invoice",
431
-			'f.total_ttc'=>"invoice",'f.total_tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note_public'=>"invoice",'p.rowid'=>'payment','pf.amount'=>'payment',
432
-		    'p.datep'=>'payment','p.num_paiement'=>'payment','project.rowid'=>'project','project.ref'=>'project','project.title'=>'project');
433
-		$this->export_dependencies_array[$r]=array('payment'=>'p.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
434
-		// Add extra fields object
435
-		$sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn'";
436
-		$resql=$this->db->query($sql);
437
-		if ($resql)    // This can fail when class is used on old database (during migration for example)
438
-		{
439
-			while ($obj=$this->db->fetch_object($resql))
440
-			{
441
-				$fieldname='extra.'.$obj->name;
442
-				$fieldlabel=ucfirst($obj->label);
443
-				$typeFilter="Text";
444
-				switch($obj->type)
445
-				{
446
-					case 'int':
447
-					case 'double':
448
-					case 'price':
449
-						$typeFilter="Numeric";
450
-						break;
451
-					case 'date':
452
-					case 'datetime':
453
-						$typeFilter="Date";
454
-						break;
455
-					case 'boolean':
456
-						$typeFilter="Boolean";
457
-						break;
458
-					case 'sellist':
459
-						$tmp='';
460
-						$tmpparam=unserialize($obj->param);	// $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
461
-						if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift(array_keys($tmpparam['options']));
462
-						if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
463
-						break;
464
-				}
465
-				$this->export_fields_array[$r][$fieldname]=$fieldlabel;
466
-				$this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
467
-				$this->export_entities_array[$r][$fieldname]='invoice';
468
-			}
469
-		}
470
-		// End add extra fields object
471
-		$this->export_sql_start[$r]='SELECT DISTINCT ';
472
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'societe as s';
473
-		if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
474
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
475
-		$this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture_fourn as f';
476
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
477
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
478
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
479
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn as p ON pf.fk_paiementfourn = p.rowid';
480
-		$this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid';
259
+        $r++;
260
+        $this->rights[$r][0] = 1236;
261
+        $this->rights[$r][1] = 'Exporter les factures fournisseurs, attributs et reglements';
262
+        $this->rights[$r][2] = 'r';
263
+        $this->rights[$r][3] = 0;
264
+        $this->rights[$r][4] = 'facture';
265
+        $this->rights[$r][5] = 'export';
266
+
267
+
268
+        // Menus
269
+        //-------
270
+        $this->menu = 1;        // This module add menu entries. They are coded into menu manager.
271
+
272
+
273
+        // Exports
274
+        //--------
275
+        $r=0;
276
+
277
+        $r++;
278
+        $this->export_code[$r]=$this->rights_class.'_'.$r;
279
+        $this->export_label[$r]='Factures fournisseurs et lignes de facture';
280
+        $this->export_icon[$r]='bill';
281
+        $this->export_permission[$r]=array(array("fournisseur","facture","export"));
282
+        $this->export_fields_array[$r]=array(
283
+            's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','c.code'=>'CountryCode','s.phone'=>'Phone',
284
+            's.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.idprof5'=>'ProfId5','s.idprof6'=>'ProfId6','s.tva_intra'=>'VATIntra',
285
+            'f.rowid'=>"InvoiceId",'f.ref'=>"InvoiceRef",'f.ref_supplier'=>"RefSupplier",'f.datec'=>"InvoiceDateCreation",'f.datef'=>"DateInvoice",'f.date_lim_reglement'=>'DateMaxPayment',
286
+            'f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.total_tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus','f.note_public'=>"InvoiceNote",
287
+            'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.tva_tx'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.remise_percent'=>"Discount",'fd.total_ht'=>"LineTotalHT",
288
+            'fd.total_ttc'=>"LineTotalTTC",'fd.tva'=>"LineTotalVAT",'fd.product_type'=>'TypeOfLineServiceOrProduct','fd.fk_product'=>'ProductId',
289
+            'p.ref'=>'ProductRef','p.label'=>'ProductLabel','p.accountancy_code_buy'=>'ProductAccountancyBuyCode','project.rowid'=>'ProjectId',
290
+            'project.ref'=>'ProjectRef','project.title'=>'ProjectLabel'
291
+        );
292
+        //$this->export_TypeFields_array[$r]=array(
293
+        //    's.rowid'=>"List:societe:CompanyName",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text',
294
+        //    's.ape'=>'Text','s.idprof4'=>'Text','s.tva_intra'=>'Text','f.ref'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",
295
+        //    'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",'fd.description'=>"Text",'fd.tva_tx'=>"Text",'fd.qty'=>"Numeric",'fd.total_ht'=>"Numeric",'fd.total_ttc'=>"Numeric",
296
+        //     'fd.tva'=>"Numeric",'fd.product_type'=>'Numeric','fd.fk_product'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text'
297
+        //);
298
+        $this->export_TypeFields_array[$r]=array(
299
+            's.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text',
300
+            's.tva_intra'=>'Text','f.ref'=>"Text",'f.ref_supplier'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",'f.date_lim_reglement'=>'Date','f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",
301
+            'f.total_tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",'fd.description'=>"Text",'fd.tva_tx'=>"Text",'fd.qty'=>"Numeric",'fd.total_ht'=>"Numeric",
302
+            'fd.total_ttc'=>"Numeric",'fd.tva'=>"Numeric",'fd.product_type'=>'Numeric','fd.fk_product'=>'List:product:label',
303
+            'p.ref'=>'Text','p.label'=>'Text','project.ref'=>'Text','project.title'=>'Text'
304
+        );
305
+        $this->export_entities_array[$r]=array(
306
+            's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','c.code'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company',
307
+            's.ape'=>'company','s.idprof4'=>'company','s.idprof5'=>'company','s.idprof6'=>'company','s.tva_intra'=>'company','f.rowid'=>"invoice",'f.ref'=>"invoice",'f.ref_supplier'=>"invoice",
308
+            'f.datec'=>"invoice",'f.datef'=>"invoice",'f.date_lim_reglement'=>'invoice','f.total_ht'=>"invoice",'f.total_ttc'=>"invoice",'f.total_tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice',
309
+            'f.note_public'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",'fd.remise_percent'=>"invoice_line",
310
+            'fd.total_ht'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva'=>"invoice_line",'fd.product_type'=>'invoice_line','fd.fk_product'=>'product',
311
+            'p.ref'=>'product','p.label'=>'product','p.accountancy_code_buy'=>'product','project.rowid'=>'project','project.ref'=>'project','project.title'=>'project'
312
+        );
313
+        $this->export_dependencies_array[$r]=array('invoice_line'=>'fd.rowid','product'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
314
+        // Add extra fields object
315
+        $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn'";
316
+        $resql=$this->db->query($sql);
317
+        if ($resql)    // This can fail when class is used on old database (during migration for example)
318
+        {
319
+            while ($obj=$this->db->fetch_object($resql))
320
+            {
321
+                $fieldname='extra.'.$obj->name;
322
+                $fieldlabel=ucfirst($obj->label);
323
+                $typeFilter="Text";
324
+                switch($obj->type)
325
+                {
326
+                    case 'int':
327
+                    case 'double':
328
+                    case 'price':
329
+                        $typeFilter="Numeric";
330
+                        break;
331
+                    case 'date':
332
+                    case 'datetime':
333
+                        $typeFilter="Date";
334
+                        break;
335
+                    case 'boolean':
336
+                        $typeFilter="Boolean";
337
+                        break;
338
+                    case 'sellist':
339
+                        $tmp='';
340
+                        $tmpparam=unserialize($obj->param);	// $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
341
+                        if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift(array_keys($tmpparam['options']));
342
+                        if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
343
+                        break;
344
+                }
345
+                $this->export_fields_array[$r][$fieldname]=$fieldlabel;
346
+                $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
347
+                $this->export_entities_array[$r][$fieldname]='invoice';
348
+            }
349
+        }
350
+        // End add extra fields
351
+        // Add extra fields line
352
+        $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn_det'";
353
+        $resql=$this->db->query($sql);
354
+        if ($resql)    // This can fail when class is used on old database (during migration for example)
355
+        {
356
+            while ($obj=$this->db->fetch_object($resql))
357
+            {
358
+                $fieldname='extraline.'.$obj->name;
359
+                $fieldlabel=ucfirst($obj->label);
360
+                $typeFilter="Text";
361
+                switch($obj->type)
362
+                {
363
+                    case 'int':
364
+                    case 'double':
365
+                    case 'price':
366
+                        $typeFilter="Numeric";
367
+                        break;
368
+                    case 'date':
369
+                    case 'datetime':
370
+                        $typeFilter="Date";
371
+                        break;
372
+                    case 'boolean':
373
+                        $typeFilter="Boolean";
374
+                        break;
375
+                    case 'sellist':
376
+                        $tmp='';
377
+                        $tmpparam=unserialize($obj->param);	// $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
378
+                        if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift(array_keys($tmpparam['options']));
379
+                        if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
380
+                        break;
381
+                }
382
+                $this->export_fields_array[$r][$fieldname]=$fieldlabel;
383
+                $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
384
+                $this->export_entities_array[$r][$fieldname]='invoice_line';
385
+            }
386
+        }
387
+        // End add extra fields line
388
+        $this->export_sql_start[$r]='SELECT DISTINCT ';
389
+        $this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'societe as s';
390
+        if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
391
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
392
+        $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture_fourn as f';
393
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
394
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
395
+        $this->export_sql_end[$r] .=' , '.MAIN_DB_PREFIX.'facture_fourn_det as fd';
396
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det_extrafields as extraline ON fd.rowid = extraline.fk_object';
397
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
398
+        $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn';
481 399
         $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_invoice').')';
482
-		if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
483
-
484
-		// Order
485
-		$r++;
486
-		$this->export_code[$r]=$this->rights_class.'_'.$r;
487
-		$this->export_label[$r]='Commandes fournisseurs et lignes de commandes';
488
-		$this->export_icon[$r]='order';
489
-		$this->export_permission[$r]=array(array("fournisseur","commande","export"));
490
-		$this->export_fields_array[$r]=array(
491
-			's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','c.code'=>'CountryCode','s.phone'=>'Phone',
492
-			's.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.idprof5'=>'ProfId5','s.idprof6'=>'ProfId6','s.tva_intra'=>'VATIntra',
493
-			'f.rowid'=>"OrderId",'f.ref'=>"Ref",'f.ref_supplier'=>"RefSupplier",'f.date_creation'=>"DateCreation",'f.date_commande'=>"OrderDate",'f.date_livraison'=>"DateDeliveryPlanned",
494
-			'f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.fk_statut'=>'Status','f.date_approve'=>'DateApprove','f.date_approve2'=>'DateApprove2',
495
-			'f.note_public'=>"NotePublic",'f.note_private'=>"NotePrivate",'ua1.login'=>'ApprovedBy','ua2.login'=>'ApprovedBy2','fd.rowid'=>'LineId','fd.description'=>"LineDescription",
496
-			'fd.tva_tx'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.remise_percent'=>"Discount",'fd.total_ht'=>"LineTotalHT",'fd.total_ttc'=>"LineTotalTTC",
497
-			'fd.total_tva'=>"LineTotalVAT",'fd.product_type'=>'TypeOfLineServiceOrProduct','fd.ref'=>'RefSupplier','fd.fk_product'=>'ProductId',
498
-			'p.ref'=>'ProductRef','p.label'=>'ProductLabel','project.rowid'=>'ProjectId','project.ref'=>'ProjectRef','project.title'=>'ProjectLabel'
499
-		);
500
-		if (empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED))
501
-		{
502
-			unset($this->export_fields_array['f.date_approve2']);
503
-			unset($this->export_fields_array['ua2.login']);
504
-		}
505
-		$this->export_TypeFields_array[$r]=array(
506
-			's.rowid'=>"company",'s.nom'=>'Text','s.address'=>'Text','s.cp'=>'Text','s.ville'=>'Text','c.code'=>'Text','s.tel'=>'Text','s.siren'=>'Text',
507
-			's.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.idprof5'=>'Text','s.idprof6'=>'Text','s.tva_intra'=>'Text','f.ref'=>"Text",'f.ref_supplier'=>"Text",
508
-			'f.date_creation'=>"Date",'f.date_commande'=>"Date",'f.date_livraison'=>"Date",'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.tva'=>"Numeric",
509
-			'f.fk_statut'=>'Status','f.date_approve'=>'Date','f.date_approve2'=>'Date','f.note_public'=>"Text",'f.note_private'=>"Text",'fd.description'=>"Text",
510
-			'fd.tva_tx'=>"Numeric",'fd.qty'=>"Numeric",'fd.remise_percent'=>"Numeric",'fd.total_ht'=>"Numeric",'fd.total_ttc'=>"Numeric",'fd.total_tva'=>"Numeric",
511
-			'fd.product_type'=>'Numeric','fd.ref'=>'Text','fd.fk_product'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text','project.ref'=>'Text','project.title'=>'Text'
512
-		);
513
-		$this->export_entities_array[$r]=array(
514
-			's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','c.code'=>'company','s.phone'=>'company','s.siren'=>'company',
515
-			's.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.idprof5'=>'company','s.idprof6'=>'company','s.tva_intra'=>'company','ua1.login'=>'user',
516
-			'ua2.login'=>'user','fd.rowid'=>'order_line','fd.description'=>"order_line",'fd.tva_tx'=>"order_line",'fd.qty'=>"order_line",'fd.remise_percent'=>"order_line",
517
-			'fd.total_ht'=>"order_line",'fd.total_ttc'=>"order_line",'fd.total_tva'=>"order_line",'fd.product_type'=>'order_line','fd.ref'=>'order_line','fd.fk_product'=>'product',
518
-			'p.ref'=>'product','p.label'=>'product','project.rowid'=>'project','project.ref'=>'project','project.title'=>'project'
519
-		);
520
-		$this->export_dependencies_array[$r]=array('order_line'=>'fd.rowid','product'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
521
-		// Add extra fields object
522
-		$sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'commande_fournisseur'";
523
-		$resql=$this->db->query($sql);
524
-		if ($resql)    // This can fail when class is used on old database (during migration for example)
525
-		{
526
-			while ($obj=$this->db->fetch_object($resql))
527
-			{
528
-				$fieldname='extra.'.$obj->name;
529
-				$fieldlabel=ucfirst($obj->label);
530
-				$typeFilter="Text";
531
-				switch($obj->type)
532
-				{
533
-					case 'int':
534
-					case 'double':
535
-					case 'price':
536
-						$typeFilter="Numeric";
537
-						break;
538
-					case 'date':
539
-					case 'datetime':
540
-						$typeFilter="Date";
541
-						break;
542
-					case 'boolean':
543
-						$typeFilter="Boolean";
544
-						break;
545
-					case 'sellist':
546
-						$tmp='';
547
-						$tmpparam=unserialize($obj->param);	// $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
548
-						$tmpkey=array_keys($tmpparam['options']);
549
-						if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift($tmpkey);
550
-						if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
551
-						break;
552
-				}
553
-				$this->export_fields_array[$r][$fieldname]=$fieldlabel;
554
-				$this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
555
-				$this->export_entities_array[$r][$fieldname]='order';
556
-			}
557
-		}
558
-		// End add extra fields object
559
-		// Add extra fields line
560
-		$sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'commande_fournisseurdet'";
561
-		$resql=$this->db->query($sql);
562
-		if ($resql)    // This can fail when class is used on old database (during migration for example)
563
-		{
564
-			while ($obj=$this->db->fetch_object($resql))
565
-			{
566
-				$fieldname='extraline.'.$obj->name;
567
-				$fieldlabel=ucfirst($obj->label);
568
-				$typeFilter="Text";
569
-				switch($obj->type)
570
-				{
571
-					case 'int':
572
-					case 'double':
573
-					case 'price':
574
-						$typeFilter="Numeric";
575
-						break;
576
-					case 'date':
577
-					case 'datetime':
578
-						$typeFilter="Date";
579
-						break;
580
-					case 'boolean':
581
-						$typeFilter="Boolean";
582
-						break;
583
-					case 'sellist':
584
-						$tmp='';
585
-						$tmpparam=unserialize($obj->param);	// $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
586
-
587
-						if ($tmpparam['options'] && is_array($tmpparam['options'])) {
588
-							$tmpparam_param_key=array_keys($tmpparam['options']);
589
-							$tmp=array_shift($tmpparam_param_key);
590
-						}
591
-						if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
592
-						break;
593
-				}
594
-				$this->export_fields_array[$r][$fieldname]=$fieldlabel;
595
-				$this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
596
-				$this->export_entities_array[$r][$fieldname]='order_line';
597
-			}
598
-		}
599
-		// End add extra fields line
600
-		$this->export_sql_start[$r]='SELECT DISTINCT ';
601
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'societe as s';
602
-		if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
603
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
604
-		$this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'commande_fournisseur as f';
605
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
606
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua1 ON ua1.rowid = f.fk_user_approve';
607
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua2 ON ua2.rowid = f.fk_user_approve2';
608
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseur_extrafields as extra ON f.rowid = extra.fk_object,';
609
-		$this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'commande_fournisseurdet as fd';
610
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet_extrafields as extraline ON fd.rowid = extraline.fk_object';
611
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
612
-		$this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_commande';
613
-		$this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_order').')';
614
-		if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
615
-	}
616
-
617
-
618
-	/**
619
-	 *		Function called when module is enabled.
620
-	 *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
621
-	 *		It also creates data directories
622
-	 *
400
+        if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
401
+
402
+        $r++;
403
+        $this->export_code[$r]=$this->rights_class.'_'.$r;
404
+        $this->export_label[$r]='Factures fournisseurs et reglements';
405
+        $this->export_icon[$r]='bill';
406
+        $this->export_permission[$r]=array(array("fournisseur","facture","export"));
407
+        $this->export_fields_array[$r]=array(
408
+            's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','c.code'=>'CountryCode','s.phone'=>'Phone',
409
+            's.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.idprof5'=>'ProfId5','s.idprof6'=>'ProfId6',
410
+            's.tva_intra'=>'VATIntra','f.rowid'=>"InvoiceId",'f.ref'=>"InvoiceRef",'f.ref_supplier'=>"RefSupplier",'f.datec'=>"InvoiceDateCreation",
411
+            'f.datef'=>"DateInvoice",'f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.total_tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",
412
+            'f.fk_statut'=>'InvoiceStatus','f.note_public'=>"InvoiceNote",'p.rowid'=>'PaymentId','pf.amount'=>'AmountPayment',
413
+            'p.datep'=>'DatePayment','p.num_paiement'=>'PaymentNumber','project.rowid'=>'ProjectId','project.ref'=>'ProjectRef','project.title'=>'ProjectLabel'
414
+        );
415
+        //$this->export_TypeFields_array[$r]=array(
416
+        //	's.rowid'=>"List:societe:CompanyName",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text',
417
+        //	's.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.tva_intra'=>'Text','f.ref'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",
418
+        //	'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",
419
+        //	'pf.amount'=>'Numeric','p.datep'=>'Date','p.num_paiement'=>'Numeric'
420
+        //);
421
+        $this->export_TypeFields_array[$r]=array(
422
+            's.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text',
423
+            's.idprof4'=>'Text','s.tva_intra'=>'Text','f.ref'=>"Text",'f.ref_supplier'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",'f.total_ht'=>"Numeric",
424
+            'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",'pf.amount'=>'Numeric',
425
+            'p.datep'=>'Date','p.num_paiement'=>'Numeric','project.ref'=>'Text','project.title'=>'Text'
426
+        );
427
+        $this->export_entities_array[$r]=array(
428
+            's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','c.code'=>'company','s.phone'=>'company',
429
+            's.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.idprof5'=>'company','s.idprof6'=>'company','s.tva_intra'=>'company',
430
+            'f.rowid'=>"invoice",'f.ref'=>"invoice",'f.ref_supplier'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total_ht'=>"invoice",
431
+            'f.total_ttc'=>"invoice",'f.total_tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note_public'=>"invoice",'p.rowid'=>'payment','pf.amount'=>'payment',
432
+            'p.datep'=>'payment','p.num_paiement'=>'payment','project.rowid'=>'project','project.ref'=>'project','project.title'=>'project');
433
+        $this->export_dependencies_array[$r]=array('payment'=>'p.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
434
+        // Add extra fields object
435
+        $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn'";
436
+        $resql=$this->db->query($sql);
437
+        if ($resql)    // This can fail when class is used on old database (during migration for example)
438
+        {
439
+            while ($obj=$this->db->fetch_object($resql))
440
+            {
441
+                $fieldname='extra.'.$obj->name;
442
+                $fieldlabel=ucfirst($obj->label);
443
+                $typeFilter="Text";
444
+                switch($obj->type)
445
+                {
446
+                    case 'int':
447
+                    case 'double':
448
+                    case 'price':
449
+                        $typeFilter="Numeric";
450
+                        break;
451
+                    case 'date':
452
+                    case 'datetime':
453
+                        $typeFilter="Date";
454
+                        break;
455
+                    case 'boolean':
456
+                        $typeFilter="Boolean";
457
+                        break;
458
+                    case 'sellist':
459
+                        $tmp='';
460
+                        $tmpparam=unserialize($obj->param);	// $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
461
+                        if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift(array_keys($tmpparam['options']));
462
+                        if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
463
+                        break;
464
+                }
465
+                $this->export_fields_array[$r][$fieldname]=$fieldlabel;
466
+                $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
467
+                $this->export_entities_array[$r][$fieldname]='invoice';
468
+            }
469
+        }
470
+        // End add extra fields object
471
+        $this->export_sql_start[$r]='SELECT DISTINCT ';
472
+        $this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'societe as s';
473
+        if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
474
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
475
+        $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture_fourn as f';
476
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
477
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
478
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
479
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn as p ON pf.fk_paiementfourn = p.rowid';
480
+        $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid';
481
+        $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_invoice').')';
482
+        if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
483
+
484
+        // Order
485
+        $r++;
486
+        $this->export_code[$r]=$this->rights_class.'_'.$r;
487
+        $this->export_label[$r]='Commandes fournisseurs et lignes de commandes';
488
+        $this->export_icon[$r]='order';
489
+        $this->export_permission[$r]=array(array("fournisseur","commande","export"));
490
+        $this->export_fields_array[$r]=array(
491
+            's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','c.code'=>'CountryCode','s.phone'=>'Phone',
492
+            's.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.idprof5'=>'ProfId5','s.idprof6'=>'ProfId6','s.tva_intra'=>'VATIntra',
493
+            'f.rowid'=>"OrderId",'f.ref'=>"Ref",'f.ref_supplier'=>"RefSupplier",'f.date_creation'=>"DateCreation",'f.date_commande'=>"OrderDate",'f.date_livraison'=>"DateDeliveryPlanned",
494
+            'f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.fk_statut'=>'Status','f.date_approve'=>'DateApprove','f.date_approve2'=>'DateApprove2',
495
+            'f.note_public'=>"NotePublic",'f.note_private'=>"NotePrivate",'ua1.login'=>'ApprovedBy','ua2.login'=>'ApprovedBy2','fd.rowid'=>'LineId','fd.description'=>"LineDescription",
496
+            'fd.tva_tx'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.remise_percent'=>"Discount",'fd.total_ht'=>"LineTotalHT",'fd.total_ttc'=>"LineTotalTTC",
497
+            'fd.total_tva'=>"LineTotalVAT",'fd.product_type'=>'TypeOfLineServiceOrProduct','fd.ref'=>'RefSupplier','fd.fk_product'=>'ProductId',
498
+            'p.ref'=>'ProductRef','p.label'=>'ProductLabel','project.rowid'=>'ProjectId','project.ref'=>'ProjectRef','project.title'=>'ProjectLabel'
499
+        );
500
+        if (empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED))
501
+        {
502
+            unset($this->export_fields_array['f.date_approve2']);
503
+            unset($this->export_fields_array['ua2.login']);
504
+        }
505
+        $this->export_TypeFields_array[$r]=array(
506
+            's.rowid'=>"company",'s.nom'=>'Text','s.address'=>'Text','s.cp'=>'Text','s.ville'=>'Text','c.code'=>'Text','s.tel'=>'Text','s.siren'=>'Text',
507
+            's.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.idprof5'=>'Text','s.idprof6'=>'Text','s.tva_intra'=>'Text','f.ref'=>"Text",'f.ref_supplier'=>"Text",
508
+            'f.date_creation'=>"Date",'f.date_commande'=>"Date",'f.date_livraison'=>"Date",'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.tva'=>"Numeric",
509
+            'f.fk_statut'=>'Status','f.date_approve'=>'Date','f.date_approve2'=>'Date','f.note_public'=>"Text",'f.note_private'=>"Text",'fd.description'=>"Text",
510
+            'fd.tva_tx'=>"Numeric",'fd.qty'=>"Numeric",'fd.remise_percent'=>"Numeric",'fd.total_ht'=>"Numeric",'fd.total_ttc'=>"Numeric",'fd.total_tva'=>"Numeric",
511
+            'fd.product_type'=>'Numeric','fd.ref'=>'Text','fd.fk_product'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text','project.ref'=>'Text','project.title'=>'Text'
512
+        );
513
+        $this->export_entities_array[$r]=array(
514
+            's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','c.code'=>'company','s.phone'=>'company','s.siren'=>'company',
515
+            's.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.idprof5'=>'company','s.idprof6'=>'company','s.tva_intra'=>'company','ua1.login'=>'user',
516
+            'ua2.login'=>'user','fd.rowid'=>'order_line','fd.description'=>"order_line",'fd.tva_tx'=>"order_line",'fd.qty'=>"order_line",'fd.remise_percent'=>"order_line",
517
+            'fd.total_ht'=>"order_line",'fd.total_ttc'=>"order_line",'fd.total_tva'=>"order_line",'fd.product_type'=>'order_line','fd.ref'=>'order_line','fd.fk_product'=>'product',
518
+            'p.ref'=>'product','p.label'=>'product','project.rowid'=>'project','project.ref'=>'project','project.title'=>'project'
519
+        );
520
+        $this->export_dependencies_array[$r]=array('order_line'=>'fd.rowid','product'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
521
+        // Add extra fields object
522
+        $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'commande_fournisseur'";
523
+        $resql=$this->db->query($sql);
524
+        if ($resql)    // This can fail when class is used on old database (during migration for example)
525
+        {
526
+            while ($obj=$this->db->fetch_object($resql))
527
+            {
528
+                $fieldname='extra.'.$obj->name;
529
+                $fieldlabel=ucfirst($obj->label);
530
+                $typeFilter="Text";
531
+                switch($obj->type)
532
+                {
533
+                    case 'int':
534
+                    case 'double':
535
+                    case 'price':
536
+                        $typeFilter="Numeric";
537
+                        break;
538
+                    case 'date':
539
+                    case 'datetime':
540
+                        $typeFilter="Date";
541
+                        break;
542
+                    case 'boolean':
543
+                        $typeFilter="Boolean";
544
+                        break;
545
+                    case 'sellist':
546
+                        $tmp='';
547
+                        $tmpparam=unserialize($obj->param);	// $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
548
+                        $tmpkey=array_keys($tmpparam['options']);
549
+                        if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift($tmpkey);
550
+                        if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
551
+                        break;
552
+                }
553
+                $this->export_fields_array[$r][$fieldname]=$fieldlabel;
554
+                $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
555
+                $this->export_entities_array[$r][$fieldname]='order';
556
+            }
557
+        }
558
+        // End add extra fields object
559
+        // Add extra fields line
560
+        $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'commande_fournisseurdet'";
561
+        $resql=$this->db->query($sql);
562
+        if ($resql)    // This can fail when class is used on old database (during migration for example)
563
+        {
564
+            while ($obj=$this->db->fetch_object($resql))
565
+            {
566
+                $fieldname='extraline.'.$obj->name;
567
+                $fieldlabel=ucfirst($obj->label);
568
+                $typeFilter="Text";
569
+                switch($obj->type)
570
+                {
571
+                    case 'int':
572
+                    case 'double':
573
+                    case 'price':
574
+                        $typeFilter="Numeric";
575
+                        break;
576
+                    case 'date':
577
+                    case 'datetime':
578
+                        $typeFilter="Date";
579
+                        break;
580
+                    case 'boolean':
581
+                        $typeFilter="Boolean";
582
+                        break;
583
+                    case 'sellist':
584
+                        $tmp='';
585
+                        $tmpparam=unserialize($obj->param);	// $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
586
+
587
+                        if ($tmpparam['options'] && is_array($tmpparam['options'])) {
588
+                            $tmpparam_param_key=array_keys($tmpparam['options']);
589
+                            $tmp=array_shift($tmpparam_param_key);
590
+                        }
591
+                        if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
592
+                        break;
593
+                }
594
+                $this->export_fields_array[$r][$fieldname]=$fieldlabel;
595
+                $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
596
+                $this->export_entities_array[$r][$fieldname]='order_line';
597
+            }
598
+        }
599
+        // End add extra fields line
600
+        $this->export_sql_start[$r]='SELECT DISTINCT ';
601
+        $this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'societe as s';
602
+        if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
603
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
604
+        $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'commande_fournisseur as f';
605
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
606
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua1 ON ua1.rowid = f.fk_user_approve';
607
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua2 ON ua2.rowid = f.fk_user_approve2';
608
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseur_extrafields as extra ON f.rowid = extra.fk_object,';
609
+        $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'commande_fournisseurdet as fd';
610
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet_extrafields as extraline ON fd.rowid = extraline.fk_object';
611
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
612
+        $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_commande';
613
+        $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_order').')';
614
+        if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
615
+    }
616
+
617
+
618
+    /**
619
+     *		Function called when module is enabled.
620
+     *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
621
+     *		It also creates data directories
622
+     *
623 623
      *      @param      string	$options    Options when enabling module ('', 'noboxes')
624
-	 *      @return     int             	1 if OK, 0 if KO
625
-	 */
626
-	function init($options='')
627
-	{
628
-		global $conf;
624
+     *      @return     int             	1 if OK, 0 if KO
625
+     */
626
+    function init($options='')
627
+    {
628
+        global $conf;
629 629
 
630
-		$this->remove($options);
630
+        $this->remove($options);
631 631
 
632
-		$sql = array(
633
-			 "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'order_supplier' AND entity = ".$conf->entity,
634
-			 "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','order_supplier',".$conf->entity.")",
635
-		);
632
+        $sql = array(
633
+                "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'order_supplier' AND entity = ".$conf->entity,
634
+                "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','order_supplier',".$conf->entity.")",
635
+        );
636 636
 
637
-		return $this->_init($sql,$options);
638
-	}
637
+        return $this->_init($sql,$options);
638
+    }
639 639
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/modSalaries.class.php 1 patch
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -38,143 +38,143 @@
 block discarded – undo
38 38
 class modSalaries extends DolibarrModules
39 39
 {
40 40
 
41
-	/**
42
-	 *   Constructor. Define names, constants, directories, boxes, permissions
43
-	 *
44
-	 *   @param      DoliDB		$db      Database handler
45
-	 */
46
-	function __construct($db)
47
-	{
48
-		global $conf;
49
-
50
-		$this->db = $db;
51
-		$this->numero = 510; // Perms from 501..519
52
-
53
-		// Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...'
54
-		// It is used to group modules by family in module setup page
55
-		$this->family = "financial";
56
-		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
57
-		$this->name = preg_replace('/^mod/i','',get_class($this));
58
-		// Module description used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
59
-		$this->description = "Payment of salaries";
60
-
61
-		// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
62
-		$this->version = 'dolibarr';
63
-
64
-		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
65
-		$this->picto='bill';
66
-
67
-		// Data directories to create when module is enabled
68
-		$this->dirs = array("/salaries/temp");
69
-
70
-		// Config pages
71
-		//$this->config_page_url = array('salaries.php');
72
-		$this->config_page_url = array();
73
-
74
-		// Dependencies
75
-		$this->hidden = false;			// A condition to hide module
76
-		$this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
77
-		$this->requiredby = array();	// List of module ids to disable if this one is disabled
78
-		$this->conflictwith = array();	// List of module class names as string this module is in conflict with
79
-		$this->phpmin = array(5,4);		// Minimum version of PHP required by module
80
-		$this->langfiles = array("salaries","bills");
81
-
82
-		// Constants
83
-		$this->const = array();
84
-		$this->const[0] = array(
85
-				"SALARIES_ACCOUNTING_ACCOUNT_PAYMENT",
86
-				"chaine",
87
-				"421"
88
-		);
89
-		$this->const[1] = array(
90
-				"SALARIES_ACCOUNTING_ACCOUNT_CHARGE",
91
-				"chaine",
92
-				"641"
93
-		);
94
-
95
-		// Boxes
96
-		$this->boxes = array();
97
-
98
-		// Permissions
99
-		$this->rights = array();
100
-		$this->rights_class = 'salaries';
101
-		$r=0;
102
-
103
-		$r++;
104
-		$this->rights[$r][0] = 511;
105
-		$this->rights[$r][1] = 'Read payments of employee salaries';
106
-		$this->rights[$r][2] = 'r';
107
-		$this->rights[$r][3] = 0;
108
-		$this->rights[$r][4] = 'read';
109
-		$this->rights[$r][5] = '';
110
-
111
-		$r++;
112
-		$this->rights[$r][0] = 512;
113
-		$this->rights[$r][1] = 'Create/modify payments of empoyee salaries';
114
-		$this->rights[$r][2] = 'w';
115
-		$this->rights[$r][3] = 0;
116
-		$this->rights[$r][4] = 'write';
117
-		$this->rights[$r][5] = '';
118
-
119
-		$r++;
120
-		$this->rights[$r][0] = 514;
121
-		$this->rights[$r][1] = 'Delete payments of employee salary';
122
-		$this->rights[$r][2] = 'd';
123
-		$this->rights[$r][3] = 0;
124
-		$this->rights[$r][4] = 'delete';
125
-		$this->rights[$r][5] = '';
126
-
127
-		$r++;
128
-		$this->rights[$r][0] = 517;
129
-		$this->rights[$r][1] = 'Export payments of employee salaries';
130
-		$this->rights[$r][2] = 'r';
131
-		$this->rights[$r][3] = 0;
132
-		$this->rights[$r][4] = 'export';
133
-		$this->rights[$r][5] = '';
134
-
135
-
136
-		// Menus
137
-		//-------
138
-		$this->menu = 1;        // This module add menu entries. They are coded into menu manager.
139
-
140
-
141
-		// Exports
142
-		//--------
143
-		$r=0;
144
-
145
-		$r++;
146
-		$this->export_code[$r]=$this->rights_class.'_'.$r;
147
-		$this->export_label[$r]='Salaries and payments';
148
-		$this->export_permission[$r]=array(array("salaries","export"));
149
-		$this->export_fields_array[$r]=array('u.firstname'=>"Firstname",'u.lastname'=>"Lastname",'u.login'=>"Login",'u.salary'=>'CurrentSalary','p.datep'=>'DatePayment','p.datesp'=>'DateStartPeriod','p.dateep'=>'DateEndPeriod','p.amount'=>'AmountPayment','p.num_payment'=>'Numero','p.label'=>'Label','p.note'=>'Note');
150
-		$this->export_TypeFields_array[$r]=array('u.firstname'=>"Text",'u.lastname'=>"Text",'u.login'=>'Text','u.salary'=>"Numeric",'p.datep'=>'Date','p.datesp'=>'Date','p.dateep'=>'Date','p.amount'=>'Numeric','p.num_payment'=>'Numeric','p.label'=>'Text');
151
-		$this->export_entities_array[$r]=array('u.firstname'=>'user','u.lastname'=>'user','u.login'=>'user','u.salary'=>'user','p.datep'=>'payment','p.datesp'=>'payment','p.dateep'=>'payment','p.amount'=>'payment','p.label'=>'payment','p.note'=>'payment','p.num_payment'=>'payment');
152
-
153
-		$this->export_sql_start[$r]='SELECT DISTINCT ';
154
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'user as u';
155
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'payment_salary as p ON p.fk_user = u.rowid';
156
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_typepayment = cp.id';
157
-		$this->export_sql_end[$r] .=' AND u.entity IN ('.getEntity('user').')';
158
-	}
159
-
160
-
161
-	/**
162
-	 *		Function called when module is enabled.
163
-	 *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
164
-	 *		It also creates data directories
165
-	 *
166
-	 *      @param      string	$options    Options when enabling module ('', 'noboxes')
167
-	 *      @return     int             	1 if OK, 0 if KO
168
-	 */
169
-	function init($options='')
170
-	{
171
-		global $conf;
172
-
173
-		// Clean before activation
174
-		$this->remove($options);
175
-
176
-		$sql = array();
177
-
178
-		return $this->_init($sql,$options);
179
-	}
41
+    /**
42
+     *   Constructor. Define names, constants, directories, boxes, permissions
43
+     *
44
+     *   @param      DoliDB		$db      Database handler
45
+     */
46
+    function __construct($db)
47
+    {
48
+        global $conf;
49
+
50
+        $this->db = $db;
51
+        $this->numero = 510; // Perms from 501..519
52
+
53
+        // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...'
54
+        // It is used to group modules by family in module setup page
55
+        $this->family = "financial";
56
+        // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
57
+        $this->name = preg_replace('/^mod/i','',get_class($this));
58
+        // Module description used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
59
+        $this->description = "Payment of salaries";
60
+
61
+        // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
62
+        $this->version = 'dolibarr';
63
+
64
+        $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
65
+        $this->picto='bill';
66
+
67
+        // Data directories to create when module is enabled
68
+        $this->dirs = array("/salaries/temp");
69
+
70
+        // Config pages
71
+        //$this->config_page_url = array('salaries.php');
72
+        $this->config_page_url = array();
73
+
74
+        // Dependencies
75
+        $this->hidden = false;			// A condition to hide module
76
+        $this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
77
+        $this->requiredby = array();	// List of module ids to disable if this one is disabled
78
+        $this->conflictwith = array();	// List of module class names as string this module is in conflict with
79
+        $this->phpmin = array(5,4);		// Minimum version of PHP required by module
80
+        $this->langfiles = array("salaries","bills");
81
+
82
+        // Constants
83
+        $this->const = array();
84
+        $this->const[0] = array(
85
+                "SALARIES_ACCOUNTING_ACCOUNT_PAYMENT",
86
+                "chaine",
87
+                "421"
88
+        );
89
+        $this->const[1] = array(
90
+                "SALARIES_ACCOUNTING_ACCOUNT_CHARGE",
91
+                "chaine",
92
+                "641"
93
+        );
94
+
95
+        // Boxes
96
+        $this->boxes = array();
97
+
98
+        // Permissions
99
+        $this->rights = array();
100
+        $this->rights_class = 'salaries';
101
+        $r=0;
102
+
103
+        $r++;
104
+        $this->rights[$r][0] = 511;
105
+        $this->rights[$r][1] = 'Read payments of employee salaries';
106
+        $this->rights[$r][2] = 'r';
107
+        $this->rights[$r][3] = 0;
108
+        $this->rights[$r][4] = 'read';
109
+        $this->rights[$r][5] = '';
110
+
111
+        $r++;
112
+        $this->rights[$r][0] = 512;
113
+        $this->rights[$r][1] = 'Create/modify payments of empoyee salaries';
114
+        $this->rights[$r][2] = 'w';
115
+        $this->rights[$r][3] = 0;
116
+        $this->rights[$r][4] = 'write';
117
+        $this->rights[$r][5] = '';
118
+
119
+        $r++;
120
+        $this->rights[$r][0] = 514;
121
+        $this->rights[$r][1] = 'Delete payments of employee salary';
122
+        $this->rights[$r][2] = 'd';
123
+        $this->rights[$r][3] = 0;
124
+        $this->rights[$r][4] = 'delete';
125
+        $this->rights[$r][5] = '';
126
+
127
+        $r++;
128
+        $this->rights[$r][0] = 517;
129
+        $this->rights[$r][1] = 'Export payments of employee salaries';
130
+        $this->rights[$r][2] = 'r';
131
+        $this->rights[$r][3] = 0;
132
+        $this->rights[$r][4] = 'export';
133
+        $this->rights[$r][5] = '';
134
+
135
+
136
+        // Menus
137
+        //-------
138
+        $this->menu = 1;        // This module add menu entries. They are coded into menu manager.
139
+
140
+
141
+        // Exports
142
+        //--------
143
+        $r=0;
144
+
145
+        $r++;
146
+        $this->export_code[$r]=$this->rights_class.'_'.$r;
147
+        $this->export_label[$r]='Salaries and payments';
148
+        $this->export_permission[$r]=array(array("salaries","export"));
149
+        $this->export_fields_array[$r]=array('u.firstname'=>"Firstname",'u.lastname'=>"Lastname",'u.login'=>"Login",'u.salary'=>'CurrentSalary','p.datep'=>'DatePayment','p.datesp'=>'DateStartPeriod','p.dateep'=>'DateEndPeriod','p.amount'=>'AmountPayment','p.num_payment'=>'Numero','p.label'=>'Label','p.note'=>'Note');
150
+        $this->export_TypeFields_array[$r]=array('u.firstname'=>"Text",'u.lastname'=>"Text",'u.login'=>'Text','u.salary'=>"Numeric",'p.datep'=>'Date','p.datesp'=>'Date','p.dateep'=>'Date','p.amount'=>'Numeric','p.num_payment'=>'Numeric','p.label'=>'Text');
151
+        $this->export_entities_array[$r]=array('u.firstname'=>'user','u.lastname'=>'user','u.login'=>'user','u.salary'=>'user','p.datep'=>'payment','p.datesp'=>'payment','p.dateep'=>'payment','p.amount'=>'payment','p.label'=>'payment','p.note'=>'payment','p.num_payment'=>'payment');
152
+
153
+        $this->export_sql_start[$r]='SELECT DISTINCT ';
154
+        $this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'user as u';
155
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'payment_salary as p ON p.fk_user = u.rowid';
156
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_typepayment = cp.id';
157
+        $this->export_sql_end[$r] .=' AND u.entity IN ('.getEntity('user').')';
158
+    }
159
+
160
+
161
+    /**
162
+     *		Function called when module is enabled.
163
+     *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
164
+     *		It also creates data directories
165
+     *
166
+     *      @param      string	$options    Options when enabling module ('', 'noboxes')
167
+     *      @return     int             	1 if OK, 0 if KO
168
+     */
169
+    function init($options='')
170
+    {
171
+        global $conf;
172
+
173
+        // Clean before activation
174
+        $this->remove($options);
175
+
176
+        $sql = array();
177
+
178
+        return $this->_init($sql,$options);
179
+    }
180 180
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/modService.class.php 1 patch
Indentation   +298 added lines, -298 removed lines patch added patch discarded remove patch
@@ -35,88 +35,88 @@  discard block
 block discarded – undo
35 35
 class modService extends DolibarrModules
36 36
 {
37 37
 
38
-	/**
39
-	 *   Constructor. Define names, constants, directories, boxes, permissions
40
-	 *
41
-	 *   @param      DoliDB		$db      Database handler
42
-	 */
43
-	function __construct($db)
44
-	{
45
-		global $conf, $mysoc;
46
-
47
-		$this->db = $db;
48
-		$this->numero = 53;
49
-
50
-		$this->family = "products";
51
-		$this->module_position = '30';
52
-		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
53
-		$this->name = preg_replace('/^mod/i','',get_class($this));
54
-		$this->description = "Service management";
55
-
56
-		// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
57
-		$this->version = 'dolibarr';
58
-
59
-		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
60
-		$this->picto='service';
61
-
62
-		// Data directories to create when module is enabled
63
-		$this->dirs = array("/product/temp");
64
-
65
-		// Dependencies
66
-		$this->hidden = false;			// A condition to hide module
67
-		$this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
68
-		$this->requiredby = array();	// List of module ids to disable if this one is disabled
69
-		$this->conflictwith = array();	// List of module class names as string this module is in conflict with
70
-		$this->phpmin = array(5,4);		// Minimum version of PHP required by module
71
-
72
-		// Config pages
73
-		$this->config_page_url = array("product.php@product");
74
-		$this->langfiles = array("products","companies","bills");
75
-
76
-		// Constants
77
-		$this->const = array();
78
-
79
-		// Boxes
80
-		$this->boxes = array(
81
-			0=>array('file'=>'box_services_contracts.php','enabledbydefaulton'=>'Home'),
82
-			1=>array('file'=>'box_graph_product_distribution.php','enabledbydefaulton'=>'Home')
83
-		);
84
-
85
-		// Permissions
86
-		$this->rights = array();
87
-		$this->rights_class = 'service';
88
-		$r=0;
89
-
90
-		$this->rights[$r][0] = 531; // id de la permission
91
-		$this->rights[$r][1] = 'Read services'; // libelle de la permission
92
-		$this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
93
-		$this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
94
-		$this->rights[$r][4] = 'lire';
38
+    /**
39
+     *   Constructor. Define names, constants, directories, boxes, permissions
40
+     *
41
+     *   @param      DoliDB		$db      Database handler
42
+     */
43
+    function __construct($db)
44
+    {
45
+        global $conf, $mysoc;
46
+
47
+        $this->db = $db;
48
+        $this->numero = 53;
49
+
50
+        $this->family = "products";
51
+        $this->module_position = '30';
52
+        // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
53
+        $this->name = preg_replace('/^mod/i','',get_class($this));
54
+        $this->description = "Service management";
55
+
56
+        // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
57
+        $this->version = 'dolibarr';
58
+
59
+        $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
60
+        $this->picto='service';
61
+
62
+        // Data directories to create when module is enabled
63
+        $this->dirs = array("/product/temp");
64
+
65
+        // Dependencies
66
+        $this->hidden = false;			// A condition to hide module
67
+        $this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
68
+        $this->requiredby = array();	// List of module ids to disable if this one is disabled
69
+        $this->conflictwith = array();	// List of module class names as string this module is in conflict with
70
+        $this->phpmin = array(5,4);		// Minimum version of PHP required by module
71
+
72
+        // Config pages
73
+        $this->config_page_url = array("product.php@product");
74
+        $this->langfiles = array("products","companies","bills");
75
+
76
+        // Constants
77
+        $this->const = array();
78
+
79
+        // Boxes
80
+        $this->boxes = array(
81
+            0=>array('file'=>'box_services_contracts.php','enabledbydefaulton'=>'Home'),
82
+            1=>array('file'=>'box_graph_product_distribution.php','enabledbydefaulton'=>'Home')
83
+        );
84
+
85
+        // Permissions
86
+        $this->rights = array();
87
+        $this->rights_class = 'service';
88
+        $r=0;
89
+
90
+        $this->rights[$r][0] = 531; // id de la permission
91
+        $this->rights[$r][1] = 'Read services'; // libelle de la permission
92
+        $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
93
+        $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
94
+        $this->rights[$r][4] = 'lire';
95 95
         $r++;
96 96
 
97
-		$this->rights[$r][0] = 532; // id de la permission
98
-		$this->rights[$r][1] = 'Create/modify services'; // libelle de la permission
99
-		$this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
100
-		$this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
101
-		$this->rights[$r][4] = 'creer';
97
+        $this->rights[$r][0] = 532; // id de la permission
98
+        $this->rights[$r][1] = 'Create/modify services'; // libelle de la permission
99
+        $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
100
+        $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
101
+        $this->rights[$r][4] = 'creer';
102 102
         $r++;
103 103
 
104
-		$this->rights[$r][0] = 534; // id de la permission
105
-		$this->rights[$r][1] = 'Delete les services'; // libelle de la permission
106
-		$this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
107
-		$this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
108
-		$this->rights[$r][4] = 'supprimer';
104
+        $this->rights[$r][0] = 534; // id de la permission
105
+        $this->rights[$r][1] = 'Delete les services'; // libelle de la permission
106
+        $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
107
+        $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
108
+        $this->rights[$r][4] = 'supprimer';
109 109
         $r++;
110 110
 
111
-		$this->rights[$r][0] = 538;	// Must be same permission than in product module
112
-		$this->rights[$r][1] = 'Export services';
113
-		$this->rights[$r][2] = 'r';
114
-		$this->rights[$r][3] = 0;
115
-		$this->rights[$r][4] = 'export';
111
+        $this->rights[$r][0] = 538;	// Must be same permission than in product module
112
+        $this->rights[$r][1] = 'Export services';
113
+        $this->rights[$r][2] = 'r';
114
+        $this->rights[$r][3] = 0;
115
+        $this->rights[$r][4] = 'export';
116 116
         $r++;
117 117
 
118 118
 
119
-		/* We can't enable this here because it must be enabled in both product and service module and this create duplicate insert
119
+        /* We can't enable this here because it must be enabled in both product and service module and this create duplicate insert
120 120
 		$r=0;
121 121
 		$this->menu[$r]=array(	'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=admintools',		    // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
122 122
 								'type'=>'left',			                // This is a Left menu entry
@@ -132,243 +132,243 @@  discard block
 block discarded – undo
132 132
 		*/
133 133
 
134 134
 
135
-		// Menus
136
-		//-------
137
-		$this->menu = 1;        // This module add menu entries. They are coded into menu manager.
135
+        // Menus
136
+        //-------
137
+        $this->menu = 1;        // This module add menu entries. They are coded into menu manager.
138 138
 
139 139
 
140 140
         // Exports
141
-		//--------
142
-		$r=0;
141
+        //--------
142
+        $r=0;
143 143
 
144
-		$r++;
145
-		$this->export_code[$r]=$this->rights_class.'_'.$r;
146
-		$this->export_label[$r]="Services";	// Translation key (used only if key ExportDataset_xxx_z not found)
147
-		$this->export_permission[$r]=array(array("service","export"));
148
-		$this->export_fields_array[$r]=array('p.rowid'=>"Id",'p.ref'=>"Ref",'p.label'=>"Label",'p.description'=>"Description",'p.accountancy_code_sell'=>"ProductAccountancySellCode",'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC",'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell",'p.tobuy'=>"OnBuy",'p.duration'=>"Duration",'p.datec'=>'DateCreation','p.tms'=>'DateModification');
149
-		if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock'));
150
-		if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->export_fields_array[$r]['p.fk_unit'] = 'Unit';
151
-		//$this->export_TypeFields_array[$r]=array('p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",'p.note'=>"Text",'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.duration'=>"Duree",'p.datec'=>'Date','p.tms'=>'Date');
152
-		$this->export_TypeFields_array[$r]=array('p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",'p.note'=>"Text",'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",'p.duration'=>"Duree",'p.datec'=>'Date','p.tms'=>'Date');
153
-		if (! empty($conf->stock->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric'));
154
-		if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text'));
155
-		$this->export_entities_array[$r]=array('p.rowid'=>"service",'p.ref'=>"service",'p.label'=>"service",'p.description'=>"service",'p.accountancy_code_sell'=>'service','p.note'=>"service",'p.price_base_type'=>"service",'p.price'=>"service",'p.price_ttc'=>"service",'p.tva_tx'=>"service",'p.tosell'=>"service",'p.tobuy'=>"service",'p.duration'=>"service",'p.datec'=>"service",'p.tms'=>"service");
156
-		if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'service'));
157
-		if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'service'));
158
-		// Add extra fields
159
-		$sql="SELECT name, label, type FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product'";
160
-		$resql=$this->db->query($sql);
161
-		if ($resql)    // This can fail when class is used on old database (during migration for example)
162
-		{
163
-		    while ($obj=$this->db->fetch_object($resql))
164
-		    {
165
-		        $fieldname='extra.'.$obj->name;
166
-		        $fieldlabel=ucfirst($obj->label);
167
-		    	$typeFilter="Text";
168
-				switch($obj->type)
169
-				{
170
-					case 'int':
171
-					case 'double':
172
-					case 'price':
173
-						$typeFilter="Numeric";
174
-						break;
175
-					case 'date':
176
-					case 'datetime':
177
-						$typeFilter="Date";
178
-						break;
179
-					case 'boolean':
180
-						$typeFilter="Boolean";
181
-						break;
182
-					case 'sellist':
183
-						$tmp='';
184
-						$tmpparam=unserialize($obj->param);	// $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
185
-						if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift(array_keys($tmpparam['options']));
186
-						if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
187
-						break;
188
-				}
189
-				$this->export_fields_array[$r][$fieldname]=$fieldlabel;
190
-				$this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
191
-				$this->export_entities_array[$r][$fieldname]='product';
192
-		    }
193
-		}
194
-		// End add extra fields
195
-
196
-		$this->export_sql_start[$r]='SELECT DISTINCT ';
197
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p';
144
+        $r++;
145
+        $this->export_code[$r]=$this->rights_class.'_'.$r;
146
+        $this->export_label[$r]="Services";	// Translation key (used only if key ExportDataset_xxx_z not found)
147
+        $this->export_permission[$r]=array(array("service","export"));
148
+        $this->export_fields_array[$r]=array('p.rowid'=>"Id",'p.ref'=>"Ref",'p.label'=>"Label",'p.description'=>"Description",'p.accountancy_code_sell'=>"ProductAccountancySellCode",'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC",'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell",'p.tobuy'=>"OnBuy",'p.duration'=>"Duration",'p.datec'=>'DateCreation','p.tms'=>'DateModification');
149
+        if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock'));
150
+        if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->export_fields_array[$r]['p.fk_unit'] = 'Unit';
151
+        //$this->export_TypeFields_array[$r]=array('p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",'p.note'=>"Text",'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.duration'=>"Duree",'p.datec'=>'Date','p.tms'=>'Date');
152
+        $this->export_TypeFields_array[$r]=array('p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",'p.note'=>"Text",'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",'p.duration'=>"Duree",'p.datec'=>'Date','p.tms'=>'Date');
153
+        if (! empty($conf->stock->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric'));
154
+        if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text'));
155
+        $this->export_entities_array[$r]=array('p.rowid'=>"service",'p.ref'=>"service",'p.label'=>"service",'p.description'=>"service",'p.accountancy_code_sell'=>'service','p.note'=>"service",'p.price_base_type'=>"service",'p.price'=>"service",'p.price_ttc'=>"service",'p.tva_tx'=>"service",'p.tosell'=>"service",'p.tobuy'=>"service",'p.duration'=>"service",'p.datec'=>"service",'p.tms'=>"service");
156
+        if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'service'));
157
+        if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'service'));
158
+        // Add extra fields
159
+        $sql="SELECT name, label, type FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product'";
160
+        $resql=$this->db->query($sql);
161
+        if ($resql)    // This can fail when class is used on old database (during migration for example)
162
+        {
163
+            while ($obj=$this->db->fetch_object($resql))
164
+            {
165
+                $fieldname='extra.'.$obj->name;
166
+                $fieldlabel=ucfirst($obj->label);
167
+                $typeFilter="Text";
168
+                switch($obj->type)
169
+                {
170
+                    case 'int':
171
+                    case 'double':
172
+                    case 'price':
173
+                        $typeFilter="Numeric";
174
+                        break;
175
+                    case 'date':
176
+                    case 'datetime':
177
+                        $typeFilter="Date";
178
+                        break;
179
+                    case 'boolean':
180
+                        $typeFilter="Boolean";
181
+                        break;
182
+                    case 'sellist':
183
+                        $tmp='';
184
+                        $tmpparam=unserialize($obj->param);	// $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
185
+                        if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift(array_keys($tmpparam['options']));
186
+                        if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
187
+                        break;
188
+                }
189
+                $this->export_fields_array[$r][$fieldname]=$fieldlabel;
190
+                $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
191
+                $this->export_entities_array[$r][$fieldname]='product';
192
+            }
193
+        }
194
+        // End add extra fields
195
+
196
+        $this->export_sql_start[$r]='SELECT DISTINCT ';
197
+        $this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p';
198 198
         $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object';
199
-		if (! empty($conf->fournisseur->enabled)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price as pf ON pf.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'societe s ON s.rowid = pf.fk_soc';
199
+        if (! empty($conf->fournisseur->enabled)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price as pf ON pf.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'societe s ON s.rowid = pf.fk_soc';
200 200
         $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 1 AND p.entity IN ('.getEntity('product').')';
201 201
 
202 202
 
203
-		if (empty($conf->product->enabled))	// We enable next import templates only if module product not already enabled (to avoid duplicate entries)
204
-		{
205
-			if (! empty($conf->global->PRODUIT_MULTIPRICES))
206
-			{
207
-				// Exports product multiprice
208
-				$r++;
209
-				$this->export_code[$r]=$this->rights_class.'_'.$r;
210
-				$this->export_label[$r]="ProductsMultiPrice";	// Translation key (used only if key ExportDataset_xxx_z not found)
211
-				$this->export_permission[$r]=array(array("produit","export"));
212
-				$this->export_fields_array[$r]=array('p.rowid'=>"Id",'p.ref'=>"Ref",
213
-					'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel",
214
-					'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
215
-					'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
216
-					'pr.tva_tx'=>'PriceLevelVATRate',
217
-					'pr.date_price'=>'DateCreation');
218
-				//$this->export_TypeFields_array[$r]=array(
219
-				//	'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
220
-				//	'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text',
221
-				//	'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",
222
-				//	'p.datec'=>'Date','p.tms'=>'Date'
223
-				//);
224
-				$this->export_entities_array[$r]=array('p.rowid'=>"product",'p.ref'=>"product",
225
-					'pr.price_base_type'=>"product",'pr.price_level'=>"product",'pr.price'=>"product",
226
-					'pr.price_ttc'=>"product",
227
-					'pr.price_min'=>"product",'pr.price_min_ttc'=>"product",
228
-					'pr.tva_tx'=>'product',
229
-					'pr.date_price'=>"product");
230
-				$this->export_sql_start[$r]='SELECT DISTINCT ';
231
-				$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p';
232
-				$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_price as pr ON p.rowid = pr.fk_product';
233
-				$this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
234
-			}
235
-		}
236
-
237
-
238
-		// Imports
239
-		//--------
240
-		$r=0;
203
+        if (empty($conf->product->enabled))	// We enable next import templates only if module product not already enabled (to avoid duplicate entries)
204
+        {
205
+            if (! empty($conf->global->PRODUIT_MULTIPRICES))
206
+            {
207
+                // Exports product multiprice
208
+                $r++;
209
+                $this->export_code[$r]=$this->rights_class.'_'.$r;
210
+                $this->export_label[$r]="ProductsMultiPrice";	// Translation key (used only if key ExportDataset_xxx_z not found)
211
+                $this->export_permission[$r]=array(array("produit","export"));
212
+                $this->export_fields_array[$r]=array('p.rowid'=>"Id",'p.ref'=>"Ref",
213
+                    'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel",
214
+                    'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
215
+                    'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
216
+                    'pr.tva_tx'=>'PriceLevelVATRate',
217
+                    'pr.date_price'=>'DateCreation');
218
+                //$this->export_TypeFields_array[$r]=array(
219
+                //	'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
220
+                //	'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text',
221
+                //	'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",
222
+                //	'p.datec'=>'Date','p.tms'=>'Date'
223
+                //);
224
+                $this->export_entities_array[$r]=array('p.rowid'=>"product",'p.ref'=>"product",
225
+                    'pr.price_base_type'=>"product",'pr.price_level'=>"product",'pr.price'=>"product",
226
+                    'pr.price_ttc'=>"product",
227
+                    'pr.price_min'=>"product",'pr.price_min_ttc'=>"product",
228
+                    'pr.tva_tx'=>'product',
229
+                    'pr.date_price'=>"product");
230
+                $this->export_sql_start[$r]='SELECT DISTINCT ';
231
+                $this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p';
232
+                $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_price as pr ON p.rowid = pr.fk_product';
233
+                $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
234
+            }
235
+        }
236
+
237
+
238
+        // Imports
239
+        //--------
240
+        $r=0;
241 241
 
242
-		$r++;
243
-		$this->import_code[$r]=$this->rights_class.'_'.$r;
244
-		$this->import_label[$r]="Products";	// Translation key
245
-		$this->import_icon[$r]=$this->picto;
246
-		$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
247
-		$this->import_tables_array[$r]=array('p'=>MAIN_DB_PREFIX.'product','extra'=>MAIN_DB_PREFIX.'product_extrafields');
248
-		$this->import_tables_creator_array[$r]=array('p'=>'fk_user_author');	// Fields to store import user id
242
+        $r++;
243
+        $this->import_code[$r]=$this->rights_class.'_'.$r;
244
+        $this->import_label[$r]="Products";	// Translation key
245
+        $this->import_icon[$r]=$this->picto;
246
+        $this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
247
+        $this->import_tables_array[$r]=array('p'=>MAIN_DB_PREFIX.'product','extra'=>MAIN_DB_PREFIX.'product_extrafields');
248
+        $this->import_tables_creator_array[$r]=array('p'=>'fk_user_author');	// Fields to store import user id
249 249
         $this->import_fields_array[$r]=array(
250
-			'p.ref'=>"Ref*",'p.label'=>"Label*",'p.description'=>"Description",'p.url'=>"PublicUrl",'p.accountancy_code_sell'=>"ProductAccountancySellCode",
251
-			'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.length'=>"Length",'p.surface'=>"Surface",'p.volume'=>"Volume",
252
-			'p.weight'=>"Weight",'p.duration'=>"Duration",'p.customcode'=>'CustomCode','p.price'=>"SellingPriceHT",'p.price_ttc'=>"SellingPriceTTC",
253
-			'p.tva_tx'=>'VAT','p.tosell'=>"OnSell*",'p.tobuy'=>"OnBuy*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.datec'=>'DateCreation'
254
-		);
255
-		if (! empty($conf->barcode->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.barcode'=>'BarCode'));
256
-		if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->import_fields_array[$r]['p.fk_unit'] = 'Unit';
250
+            'p.ref'=>"Ref*",'p.label'=>"Label*",'p.description'=>"Description",'p.url'=>"PublicUrl",'p.accountancy_code_sell'=>"ProductAccountancySellCode",
251
+            'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.length'=>"Length",'p.surface'=>"Surface",'p.volume'=>"Volume",
252
+            'p.weight'=>"Weight",'p.duration'=>"Duration",'p.customcode'=>'CustomCode','p.price'=>"SellingPriceHT",'p.price_ttc'=>"SellingPriceTTC",
253
+            'p.tva_tx'=>'VAT','p.tosell'=>"OnSell*",'p.tobuy'=>"OnBuy*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.datec'=>'DateCreation'
254
+        );
255
+        if (! empty($conf->barcode->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.barcode'=>'BarCode'));
256
+        if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->import_fields_array[$r]['p.fk_unit'] = 'Unit';
257 257
         // Add extra fields
258
-		$sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' AND entity IN (0,".$conf->entity.")";
259
-		$resql=$this->db->query($sql);
260
-		if ($resql)    // This can fail when class is used on old database (during migration for example)
261
-		{
262
-		    while ($obj=$this->db->fetch_object($resql))
263
-		    {
264
-		        $fieldname='extra.'.$obj->name;
265
-		        $fieldlabel=ucfirst($obj->label);
266
-		        $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
267
-		    }
268
-		}
269
-		// End add extra fields
270
-		$this->import_fieldshidden_array[$r]=array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'product');    // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
271
-		$this->import_regex_array[$r]=array('p.ref'=>'[^ ]','p.tosell'=>'^[0|1]$','p.tobuy'=>'^[0|1]$','p.fk_product_type'=>'^[0|1]$','p.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$');
272
-		$this->import_examplevalues_array[$r]=array('p.ref'=>"PREF123456",'p.label'=>"My product",'p.description'=>"This is a description example for record",'p.note'=>"Some note",'p.price'=>"100",'p.price_ttc'=>"110",'p.tva_tx'=>'10','p.tosell'=>"0 or 1",'p.tobuy'=>"0 or 1",'p.fk_product_type'=>"0 for product/1 for service",'p.finished'=>'','p.duration'=>"1y",'p.datec'=>'2008-12-31');
273
-
274
-
275
-		if (empty($conf->product->enabled))	// We enable next import templates only if module product not already enabled (to avoid duplicate entries)
276
-		{
277
-			if (! empty($conf->fournisseur->enabled))
278
-			{
279
-				// Import suppliers prices (note: this code is duplicated into module product)
280
-				$r++;
281
-				$this->import_code[$r]=$this->rights_class.'_supplierprices';
282
-				$this->import_label[$r]="SuppliersPricesOfProductsOrServices";	// Translation key
283
-				$this->import_icon[$r]=$this->picto;
284
-				$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
285
-				$this->import_tables_array[$r]=array('sp'=>MAIN_DB_PREFIX.'product_fournisseur_price');
286
-				$this->import_tables_creator_array[$r]=array('sp'=>'fk_user');
287
-				$this->import_fields_array[$r]=array(
288
-					'sp.fk_product'=>"ProductOrService*",
289
-					'sp.fk_soc'=>"Supplier*", 'sp.ref_fourn'=>'SupplierRef', 'sp.quantity'=>"QtyMin*", 'sp.tva_tx'=>'VATRate', 'sp.default_vat_code'=>'VATCode'
290
-				);
291
-				if (is_object($mysoc) && $mysoc->useNPR())       $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.recuperableonly'=>'VATNPR'));
292
-				if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.localtax1_tx'=>'LT1', 'sp.localtax1_type'=>'LT1Type'));
293
-				if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.localtax2_tx'=>'LT2', 'sp.localtax2_type'=>'LT2Type'));
294
-				$this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array(
295
-					'sp.price'=>"PriceQtyMinHT*",
296
-					'sp.unitprice'=>'UnitPriceHT*',	// TODO Make this field not required and calculate it from price and qty
297
-					'sp.remise_percent'=>'DiscountQtyMin'
298
-				));
299
-
300
-				$this->import_convertvalue_array[$r]=array(
301
-						'sp.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'),
302
-						'sp.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'Product')
303
-				);
304
-				$this->import_examplevalues_array[$r]=array('sp.fk_product'=>"PREF123456",
305
-						'sp.fk_soc'=>"My Supplier",'sp.ref_fourn'=>"SupplierRef", 'sp.quantity'=>"1", 'sp.tva_tx'=>'21',
306
-						'sp.price'=>"50",
307
-						'sp.unitprice'=>'50',
308
-						'sp.remise_percent'=>'0'
309
-				);
310
-			}
311
-
312
-			if (! empty($conf->global->PRODUIT_MULTIPRICES))
313
-			{
314
-				// Import product multiprice
315
-				$r++;
316
-				$this->import_code[$r]=$this->rights_class.'_multiprice';
317
-				$this->import_label[$r]="ProductsOrServiceMultiPrice";	// Translation key
318
-				$this->import_icon[$r]=$this->picto;
319
-				$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
320
-				$this->import_tables_array[$r]=array('pr'=>MAIN_DB_PREFIX.'product_price');
321
-				$this->import_tables_creator_array[$r]=array('pr'=>'fk_user_author');	// Fields to store import user id
322
-				$this->import_fields_array[$r]=array('pr.fk_product'=>"ProductRowid*",
323
-					'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel",
324
-					'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
325
-					'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
326
-					'pr.tva_tx'=>'PriceLevelVATRate',
327
-					'pr.date_price'=>'DateCreation*');
328
-				$this->import_regex_array[$r]=array('pr.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$');
329
-				$this->import_examplevalues_array[$r]=array('pr.fk_product'=>"1",
330
-					'pr.price_base_type'=>"HT",'pr.price_level'=>"1",
331
-					'pr.price'=>"100",'pr.price_ttc'=>"110",
332
-					'pr.price_min'=>"100",'pr.price_min_ttc'=>"110",
333
-					'pr.tva_tx'=>'19.6',
334
-					'pr.date_price'=>'2013-04-10');
335
-			}
336
-
337
-			if (! empty($conf->global->MAIN_MULTILANGS))
338
-			{
339
-				$r++;
340
-				$this->import_code[$r]=$this->rights_class.'_languages';
341
-				$this->import_label[$r]="ProductsOrServicesTranslations";
342
-				$this->import_icon[$r]=$this->picto;
343
-				$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
344
-				$this->import_tables_array[$r]=array('l'=>MAIN_DB_PREFIX.'product_lang');
345
-				// multiline translation, one line per translation
346
-				$this->import_fields_array[$r]=array('l.fk_product'=>'Ref', 'l.lang'=>'Language', 'l.label'=>'TranslatedLabel', 'l.description'=>'TranslatedDescription');
347
-				//$this->import_fields_array[$r]['l.note']='TranslatedNote';
348
-				$this->import_convertvalue_array[$r]=array(
349
-				'l.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'Product')
350
-				);
351
-				$this->import_examplevalues_array[$r]=array('l.fk_product'=>'MyProductRef','l.lang'=>'en_US','l.label'=>'Label in en_US','l.description'=>'Desc in en_US');
352
-				$this->import_updatekeys_array[$r]=array('l.fk_product'=>'Ref','l.lang'=>'Language');
353
-			}
354
-		}
355
-	}
356
-
357
-
358
-	/**
359
-	 *		Function called when module is enabled.
360
-	 *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
361
-	 *		It also creates data directories
362
-	 *
258
+        $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' AND entity IN (0,".$conf->entity.")";
259
+        $resql=$this->db->query($sql);
260
+        if ($resql)    // This can fail when class is used on old database (during migration for example)
261
+        {
262
+            while ($obj=$this->db->fetch_object($resql))
263
+            {
264
+                $fieldname='extra.'.$obj->name;
265
+                $fieldlabel=ucfirst($obj->label);
266
+                $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
267
+            }
268
+        }
269
+        // End add extra fields
270
+        $this->import_fieldshidden_array[$r]=array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'product');    // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
271
+        $this->import_regex_array[$r]=array('p.ref'=>'[^ ]','p.tosell'=>'^[0|1]$','p.tobuy'=>'^[0|1]$','p.fk_product_type'=>'^[0|1]$','p.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$');
272
+        $this->import_examplevalues_array[$r]=array('p.ref'=>"PREF123456",'p.label'=>"My product",'p.description'=>"This is a description example for record",'p.note'=>"Some note",'p.price'=>"100",'p.price_ttc'=>"110",'p.tva_tx'=>'10','p.tosell'=>"0 or 1",'p.tobuy'=>"0 or 1",'p.fk_product_type'=>"0 for product/1 for service",'p.finished'=>'','p.duration'=>"1y",'p.datec'=>'2008-12-31');
273
+
274
+
275
+        if (empty($conf->product->enabled))	// We enable next import templates only if module product not already enabled (to avoid duplicate entries)
276
+        {
277
+            if (! empty($conf->fournisseur->enabled))
278
+            {
279
+                // Import suppliers prices (note: this code is duplicated into module product)
280
+                $r++;
281
+                $this->import_code[$r]=$this->rights_class.'_supplierprices';
282
+                $this->import_label[$r]="SuppliersPricesOfProductsOrServices";	// Translation key
283
+                $this->import_icon[$r]=$this->picto;
284
+                $this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
285
+                $this->import_tables_array[$r]=array('sp'=>MAIN_DB_PREFIX.'product_fournisseur_price');
286
+                $this->import_tables_creator_array[$r]=array('sp'=>'fk_user');
287
+                $this->import_fields_array[$r]=array(
288
+                    'sp.fk_product'=>"ProductOrService*",
289
+                    'sp.fk_soc'=>"Supplier*", 'sp.ref_fourn'=>'SupplierRef', 'sp.quantity'=>"QtyMin*", 'sp.tva_tx'=>'VATRate', 'sp.default_vat_code'=>'VATCode'
290
+                );
291
+                if (is_object($mysoc) && $mysoc->useNPR())       $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.recuperableonly'=>'VATNPR'));
292
+                if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.localtax1_tx'=>'LT1', 'sp.localtax1_type'=>'LT1Type'));
293
+                if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.localtax2_tx'=>'LT2', 'sp.localtax2_type'=>'LT2Type'));
294
+                $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array(
295
+                    'sp.price'=>"PriceQtyMinHT*",
296
+                    'sp.unitprice'=>'UnitPriceHT*',	// TODO Make this field not required and calculate it from price and qty
297
+                    'sp.remise_percent'=>'DiscountQtyMin'
298
+                ));
299
+
300
+                $this->import_convertvalue_array[$r]=array(
301
+                        'sp.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'),
302
+                        'sp.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'Product')
303
+                );
304
+                $this->import_examplevalues_array[$r]=array('sp.fk_product'=>"PREF123456",
305
+                        'sp.fk_soc'=>"My Supplier",'sp.ref_fourn'=>"SupplierRef", 'sp.quantity'=>"1", 'sp.tva_tx'=>'21',
306
+                        'sp.price'=>"50",
307
+                        'sp.unitprice'=>'50',
308
+                        'sp.remise_percent'=>'0'
309
+                );
310
+            }
311
+
312
+            if (! empty($conf->global->PRODUIT_MULTIPRICES))
313
+            {
314
+                // Import product multiprice
315
+                $r++;
316
+                $this->import_code[$r]=$this->rights_class.'_multiprice';
317
+                $this->import_label[$r]="ProductsOrServiceMultiPrice";	// Translation key
318
+                $this->import_icon[$r]=$this->picto;
319
+                $this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
320
+                $this->import_tables_array[$r]=array('pr'=>MAIN_DB_PREFIX.'product_price');
321
+                $this->import_tables_creator_array[$r]=array('pr'=>'fk_user_author');	// Fields to store import user id
322
+                $this->import_fields_array[$r]=array('pr.fk_product'=>"ProductRowid*",
323
+                    'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel",
324
+                    'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
325
+                    'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
326
+                    'pr.tva_tx'=>'PriceLevelVATRate',
327
+                    'pr.date_price'=>'DateCreation*');
328
+                $this->import_regex_array[$r]=array('pr.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$');
329
+                $this->import_examplevalues_array[$r]=array('pr.fk_product'=>"1",
330
+                    'pr.price_base_type'=>"HT",'pr.price_level'=>"1",
331
+                    'pr.price'=>"100",'pr.price_ttc'=>"110",
332
+                    'pr.price_min'=>"100",'pr.price_min_ttc'=>"110",
333
+                    'pr.tva_tx'=>'19.6',
334
+                    'pr.date_price'=>'2013-04-10');
335
+            }
336
+
337
+            if (! empty($conf->global->MAIN_MULTILANGS))
338
+            {
339
+                $r++;
340
+                $this->import_code[$r]=$this->rights_class.'_languages';
341
+                $this->import_label[$r]="ProductsOrServicesTranslations";
342
+                $this->import_icon[$r]=$this->picto;
343
+                $this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
344
+                $this->import_tables_array[$r]=array('l'=>MAIN_DB_PREFIX.'product_lang');
345
+                // multiline translation, one line per translation
346
+                $this->import_fields_array[$r]=array('l.fk_product'=>'Ref', 'l.lang'=>'Language', 'l.label'=>'TranslatedLabel', 'l.description'=>'TranslatedDescription');
347
+                //$this->import_fields_array[$r]['l.note']='TranslatedNote';
348
+                $this->import_convertvalue_array[$r]=array(
349
+                'l.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'Product')
350
+                );
351
+                $this->import_examplevalues_array[$r]=array('l.fk_product'=>'MyProductRef','l.lang'=>'en_US','l.label'=>'Label in en_US','l.description'=>'Desc in en_US');
352
+                $this->import_updatekeys_array[$r]=array('l.fk_product'=>'Ref','l.lang'=>'Language');
353
+            }
354
+        }
355
+    }
356
+
357
+
358
+    /**
359
+     *		Function called when module is enabled.
360
+     *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
361
+     *		It also creates data directories
362
+     *
363 363
      *      @param      string	$options    Options when enabling module ('', 'newboxdefonly', 'noboxes')
364
-	 *      @return     int             	1 if OK, 0 if KO
365
-	 */
366
-	function init($options='')
367
-	{
368
-		$this->remove($options);
364
+     *      @return     int             	1 if OK, 0 if KO
365
+     */
366
+    function init($options='')
367
+    {
368
+        $this->remove($options);
369 369
 
370
-		$sql = array();
370
+        $sql = array();
371 371
 
372
-		return $this->_init($sql,$options);
373
-	}
372
+        return $this->_init($sql,$options);
373
+    }
374 374
 }
Please login to merge, or discard this patch.