Passed
Push — master ( a56e33...222e44 )
by Alxarafe
36:56
created
dolibarr/htdocs/core/modules/modProduct.class.php 3 patches
Indentation   +357 added lines, -357 removed lines patch added patch discarded remove patch
@@ -37,114 +37,114 @@  discard block
 block discarded – undo
37 37
  */
38 38
 class modProduct extends DolibarrModules
39 39
 {
40
-	/**
41
-	 *   Constructor. Define names, constants, directories, boxes, permissions
42
-	 *
43
-	 *   @param      DoliDB		$db      Database handler
44
-	 */
45
-	function __construct($db)
46
-	{
47
-		global $conf, $mysoc;
48
-
49
-		$this->db = $db;
50
-		$this->numero = 50;
51
-
52
-		$this->family = "products";
53
-		$this->module_position = '20';
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 = "Product management";
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='product';
63
-
64
-		// Data directories to create when module is enabled
65
-		$this->dirs = array("/product/temp");
66
-
67
-		// Dependencies
68
-		$this->hidden = false;			// A condition to hide module
69
-		$this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
70
-		$this->requiredby = array("modStock","modBarcode","modProductBatch");	// List of module ids to disable if this one is disabled
71
-		$this->conflictwith = array();	// List of module class names as string this module is in conflict with
72
-		$this->phpmin = array(5,4);		// Minimum version of PHP required by module
73
-
74
-		// Config pages
75
-		$this->config_page_url = array("product.php@product");
76
-		$this->langfiles = array("products","companies","stocks","bills");
77
-
78
-		// Constants
79
-		$this->const = array();
80
-		$r=0;
81
-
82
-		$this->const[$r][0] = "PRODUCT_CODEPRODUCT_ADDON";
83
-		$this->const[$r][1] = "chaine";
84
-		$this->const[$r][2] = "mod_codeproduct_leopard";
85
-		$this->const[$r][3] = 'Module to control product codes';
86
-		$this->const[$r][4] = 0;
87
-		$r++;
40
+    /**
41
+     *   Constructor. Define names, constants, directories, boxes, permissions
42
+     *
43
+     *   @param      DoliDB		$db      Database handler
44
+     */
45
+    function __construct($db)
46
+    {
47
+        global $conf, $mysoc;
48
+
49
+        $this->db = $db;
50
+        $this->numero = 50;
51
+
52
+        $this->family = "products";
53
+        $this->module_position = '20';
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 = "Product management";
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='product';
63
+
64
+        // Data directories to create when module is enabled
65
+        $this->dirs = array("/product/temp");
66
+
67
+        // Dependencies
68
+        $this->hidden = false;			// A condition to hide module
69
+        $this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
70
+        $this->requiredby = array("modStock","modBarcode","modProductBatch");	// List of module ids to disable if this one is disabled
71
+        $this->conflictwith = array();	// List of module class names as string this module is in conflict with
72
+        $this->phpmin = array(5,4);		// Minimum version of PHP required by module
73
+
74
+        // Config pages
75
+        $this->config_page_url = array("product.php@product");
76
+        $this->langfiles = array("products","companies","stocks","bills");
77
+
78
+        // Constants
79
+        $this->const = array();
80
+        $r=0;
81
+
82
+        $this->const[$r][0] = "PRODUCT_CODEPRODUCT_ADDON";
83
+        $this->const[$r][1] = "chaine";
84
+        $this->const[$r][2] = "mod_codeproduct_leopard";
85
+        $this->const[$r][3] = 'Module to control product codes';
86
+        $this->const[$r][4] = 0;
87
+        $r++;
88 88
 
89
-		/*$this->const[$r][0] = "PRODUCT_ADDON_PDF";
89
+        /*$this->const[$r][0] = "PRODUCT_ADDON_PDF";
90 90
 		$this->const[$r][1] = "chaine";
91 91
 		$this->const[$r][2] = "standard";
92 92
 		$this->const[$r][3] = 'Default module for document generation';
93 93
 		$this->const[$r][4] = 0;
94 94
 		$r++;*/
95 95
 
96
-		// Boxes
97
-		$this->boxes = array(
98
-			0=>array('file'=>'box_produits.php','enabledbydefaulton'=>'Home'),
99
-			1=>array('file'=>'box_produits_alerte_stock.php','enabledbydefaulton'=>''),
100
-			2=>array('file'=>'box_graph_product_distribution.php','enabledbydefaulton'=>'Home')
101
-		);
102
-
103
-		// Permissions
104
-		$this->rights = array();
105
-		$this->rights_class = 'produit';
106
-		$r=0;
107
-
108
-		$this->rights[$r][0] = 31; // id de la permission
109
-		$this->rights[$r][1] = 'Read products'; // libelle de la permission
110
-		$this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
111
-		$this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
112
-		$this->rights[$r][4] = 'lire';
113
-		$r++;
96
+        // Boxes
97
+        $this->boxes = array(
98
+            0=>array('file'=>'box_produits.php','enabledbydefaulton'=>'Home'),
99
+            1=>array('file'=>'box_produits_alerte_stock.php','enabledbydefaulton'=>''),
100
+            2=>array('file'=>'box_graph_product_distribution.php','enabledbydefaulton'=>'Home')
101
+        );
102
+
103
+        // Permissions
104
+        $this->rights = array();
105
+        $this->rights_class = 'produit';
106
+        $r=0;
107
+
108
+        $this->rights[$r][0] = 31; // id de la permission
109
+        $this->rights[$r][1] = 'Read products'; // libelle de la permission
110
+        $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
111
+        $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
112
+        $this->rights[$r][4] = 'lire';
113
+        $r++;
114 114
 
115
-		$this->rights[$r][0] = 32; // id de la permission
116
-		$this->rights[$r][1] = 'Create/modify products'; // libelle de la permission
117
-		$this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
118
-		$this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
119
-		$this->rights[$r][4] = 'creer';
120
-		$r++;
115
+        $this->rights[$r][0] = 32; // id de la permission
116
+        $this->rights[$r][1] = 'Create/modify products'; // libelle de la permission
117
+        $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
118
+        $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
119
+        $this->rights[$r][4] = 'creer';
120
+        $r++;
121 121
 
122
-		$this->rights[$r][0] = 34; // id de la permission
123
-		$this->rights[$r][1] = 'Delete products'; // libelle de la permission
124
-		$this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
125
-		$this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
126
-		$this->rights[$r][4] = 'supprimer';
122
+        $this->rights[$r][0] = 34; // id de la permission
123
+        $this->rights[$r][1] = 'Delete products'; // libelle de la permission
124
+        $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
125
+        $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
126
+        $this->rights[$r][4] = 'supprimer';
127 127
         $r++;
128 128
 
129
-		$this->rights[$r][0] = 38;	// Must be same permission than in service module
130
-		$this->rights[$r][1] = 'Export products';
131
-		$this->rights[$r][2] = 'r';
132
-		$this->rights[$r][3] = 0;
133
-		$this->rights[$r][4] = 'export';
129
+        $this->rights[$r][0] = 38;	// Must be same permission than in service module
130
+        $this->rights[$r][1] = 'Export products';
131
+        $this->rights[$r][2] = 'r';
132
+        $this->rights[$r][3] = 0;
133
+        $this->rights[$r][4] = 'export';
134 134
         $r++;
135 135
 
136
-		$this->rights[$r][0] = 39;
137
-		$this->rights[$r][1] = 'Ignore minimum price';
138
-		$this->rights[$r][2] = 'r';
139
-		$this->rights[$r][3] = 0;
140
-		$this->rights[$r][4] = 'ignore_price_min_advance';
136
+        $this->rights[$r][0] = 39;
137
+        $this->rights[$r][1] = 'Ignore minimum price';
138
+        $this->rights[$r][2] = 'r';
139
+        $this->rights[$r][3] = 0;
140
+        $this->rights[$r][4] = 'ignore_price_min_advance';
141 141
         $r++;
142 142
 
143 143
         // Menus
144 144
         //-------
145 145
 
146 146
         $this->menu = 1;        // This module add menu entries. They are coded into menu manager.
147
-		/* We can't enable this here because it must be enabled in both product and service module and this create duplicate insert
147
+        /* We can't enable this here because it must be enabled in both product and service module and this create duplicate insert
148 148
 		$r=0;
149 149
 		$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
150 150
 								'type'=>'left',			                // This is a Left menu entry
@@ -159,279 +159,279 @@  discard block
 block discarded – undo
159 159
 		$r++;
160 160
 		*/
161 161
 
162
-		// Exports
163
-		//--------
164
-		$r=0;
162
+        // Exports
163
+        //--------
164
+        $r=0;
165 165
 
166
-		$r++;
167
-		$this->export_code[$r]=$this->rights_class.'_'.$r;
168
-		$this->export_label[$r]="Products";	// Translation key (used only if key ExportDataset_xxx_z not found)
169
-		$this->export_permission[$r]=array(array("produit","export"));
170
-		$this->export_fields_array[$r]=array(
171
-			'p.rowid'=>"Id",'p.ref'=>"Ref",'p.label'=>"Label",'p.description'=>"Description",'p.url'=>"PublicUrl",'p.accountancy_code_sell'=>"ProductAccountancySellCode",
172
-			'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.length'=>"Length",'p.width'=>"Width",'p.height'=>"Height",'p.surface'=>"Surface",
173
-			'p.volume'=>"Volume",'p.weight'=>"Weight",'p.customcode'=>'CustomCode','p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC",
174
-			'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell",'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification'
175
-		);
176
-		if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['p.recuperableonly']='NPR';
177
-		if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue'));
178
-		if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode'));
179
-		if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.cost_price'=>'CostPrice'));
180
-		$keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra';
181
-		include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
182
-		if (! empty($conf->fournisseur->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('s.nom'=>'Supplier','pf.ref_fourn'=>'SupplierRef','pf.quantity'=>'QtyMin','pf.remise_percent'=>'DiscountQtyMin','pf.unitprice'=>'BuyingPrice','pf.delivery_time_days'=>'NbDaysToDelivery'));
183
-		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('group_concat(cat.label)'=>'Categories'));
184
-		if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('l.lang'=>'Language', 'l.label'=>'TranslatedLabel','l.description'=>'TranslatedDescription','l.note'=>'TranslatedNote'));
185
-		if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->export_fields_array[$r]['p.fk_unit'] = 'Unit';
186
-		$this->export_TypeFields_array[$r]=array(
187
-			'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
188
-			'p.note'=>"Text",'p.length'=>"Numeric",'p.width'=>"Numeric",'p.height'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",
189
-			'p.customcode'=>'Text','p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",
190
-			'p.tobuy'=>"Boolean",'p.datec'=>'Date','p.tms'=>'Date'
191
-		);
192
-		if (! empty($conf->stock->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric'));
193
-		if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text'));
194
-		if (! empty($conf->fournisseur->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('s.nom'=>'Text','pf.ref_fourn'=>'Text','pf.unitprice'=>'Numeric','pf.quantity'=>'Numeric','pf.remise_percent'=>'Numeric','pf.delivery_time_days'=>'Numeric'));
195
-		if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('l.lang'=>'Text', 'l.label'=>'Text','l.description'=>'Text','l.note'=>'Text'));
196
-		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array("group_concat(cat.label)"=>'Text'));
197
-		$this->export_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
198
-		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array("group_concat(cat.label)"=>'category'));
199
-		if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'product','p.pmp'=>'product'));
200
-		if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'product'));
201
-		if (! empty($conf->fournisseur->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('s.nom'=>'product_supplier_ref','pf.ref_fourn'=>'product_supplier_ref','pf.unitprice'=>'product_supplier_ref','pf.quantity'=>'product_supplier_ref','pf.remise_percent'=>'product_supplier_ref','pf.delivery_time_days'=>'product_supplier_ref'));
202
-		if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('l.lang'=>'translation', 'l.label'=>'translation','l.description'=>'translation','l.note'=>'translation'));
203
-		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_dependencies_array[$r]=array('category'=>'p.rowid');
204
-		$this->export_sql_start[$r]='SELECT DISTINCT ';
205
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p';
206
-		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'categorie as cat ON cp.fk_categorie = cat.rowid';
207
-		if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_lang as l ON l.fk_product = p.rowid';
208
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object';
209
-		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';
210
-		$this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
211
-		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_order[$r] =' GROUP BY p.rowid'; 	// FIXME The group by used a generic value to say "all fields in select except function fields"
212
-
213
-		if (! empty($conf->global->PRODUIT_MULTIPRICES))
214
-		{
215
-			// Exports product multiprice
216
-			$r++;
217
-			$this->export_code[$r]=$this->rights_class.'_'.$r;
218
-			$this->export_label[$r]="ProductsMultiPrice";	// Translation key (used only if key ExportDataset_xxx_z not found)
219
-			$this->export_permission[$r]=array(array("produit","export"));
220
-			$this->export_fields_array[$r]=array('p.rowid'=>"Id",'p.ref'=>"Ref",
221
-				'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel",
222
-				'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
223
-				'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
224
-				'pr.tva_tx'=>'PriceLevelVATRate',
225
-				'pr.date_price'=>'DateCreation');
226
-			if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['pr.recuperableonly']='NPR';
227
-			//$this->export_TypeFields_array[$r]=array(
228
-			//	'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
229
-			//	'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text',
230
-			//	'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",
231
-			//	'p.datec'=>'Date','p.tms'=>'Date'
232
-			//);
233
-			$this->export_entities_array[$r]=array('p.rowid'=>"product",'p.ref'=>"product",
234
-				'pr.price_base_type'=>"product",'pr.price_level'=>"product",'pr.price'=>"product",
235
-				'pr.price_ttc'=>"product",
236
-				'pr.price_min'=>"product",'pr.price_min_ttc'=>"product",
237
-				'pr.tva_tx'=>'product',
238
-				'pr.recuperableonly'=>'product',
239
-				'pr.date_price'=>"product");
240
-			$this->export_sql_start[$r]='SELECT DISTINCT ';
241
-			$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p';
242
-			$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_price as pr ON p.rowid = pr.fk_product AND pr.entity = '.$conf->entity; // export prices only for the current entity
243
-			$this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
244
-		}
245
-
246
-		if (! empty($conf->global->PRODUIT_SOUSPRODUITS))
247
-		{
248
-			// Exports virtual products
249
-        	$r++;
250
-    		$this->export_code[$r]=$this->rights_class.'_'.$r;
251
-    		$this->export_label[$r]="AssociatedProducts";	// Translation key (used only if key ExportDataset_xxx_z not found)
252
-    		$this->export_permission[$r]=array(array("produit","export"));
253
-    		$this->export_fields_array[$r]=array(
254
-				'p.rowid'=>"Id",'p.ref'=>"Ref",'p.label'=>"Label",'p.description'=>"Description",'p.url'=>"PublicUrl",
255
-				'p.accountancy_code_sell'=>"ProductAccountancySellCode",'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",
256
-				'p.length'=>"Length",'p.surface'=>"Surface",'p.volume'=>"Volume",'p.weight'=>"Weight",'p.customcode'=>'CustomCode',
257
-				'p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC",'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell",
258
-				'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification'
259
-			);
260
-    		if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue'));
261
-    		if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode'));
262
-    		$this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('pa.qty'=>'Qty','pa.incdec'=>'ComposedProductIncDecStock'));
263
-    		$this->export_TypeFields_array[$r]=array(
264
-				'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
265
-				'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text',
266
-				'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",
267
-				'p.datec'=>'Date','p.tms'=>'Date'
268
-			);
269
-    		if (! empty($conf->stock->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric'));
270
-    		if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text'));
271
-    		$this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('pa.qty'=>'Numeric'));
272
-    		$this->export_entities_array[$r]=array(
273
-				'p.rowid'=>"virtualproduct",'p.ref'=>"virtualproduct",'p.label'=>"virtualproduct",'p.description'=>"virtualproduct",'p.url'=>"virtualproduct",
274
-				'p.accountancy_code_sell'=>'virtualproduct','p.accountancy_code_buy'=>'virtualproduct','p.note'=>"virtualproduct",'p.length'=>"virtualproduct",
275
-				'p.surface'=>"virtualproduct",'p.volume'=>"virtualproduct",'p.weight'=>"virtualproduct",'p.customcode'=>'virtualproduct',
276
-				'p.price_base_type'=>"virtualproduct",'p.price'=>"virtualproduct",'p.price_ttc'=>"virtualproduct",'p.tva_tx'=>"virtualproduct",
277
-				'p.tosell'=>"virtualproduct",'p.tobuy'=>"virtualproduct",'p.datec'=>"virtualproduct",'p.tms'=>"virtualproduct"
278
-			);
279
-    		if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'virtualproduct','p.seuil_stock_alerte'=>'virtualproduct','p.desiredstock'=>'virtualproduct','p.pmp'=>'virtualproduct'));
280
-    		if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'virtualproduct'));
166
+        $r++;
167
+        $this->export_code[$r]=$this->rights_class.'_'.$r;
168
+        $this->export_label[$r]="Products";	// Translation key (used only if key ExportDataset_xxx_z not found)
169
+        $this->export_permission[$r]=array(array("produit","export"));
170
+        $this->export_fields_array[$r]=array(
171
+            'p.rowid'=>"Id",'p.ref'=>"Ref",'p.label'=>"Label",'p.description'=>"Description",'p.url'=>"PublicUrl",'p.accountancy_code_sell'=>"ProductAccountancySellCode",
172
+            'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.length'=>"Length",'p.width'=>"Width",'p.height'=>"Height",'p.surface'=>"Surface",
173
+            'p.volume'=>"Volume",'p.weight'=>"Weight",'p.customcode'=>'CustomCode','p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC",
174
+            'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell",'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification'
175
+        );
176
+        if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['p.recuperableonly']='NPR';
177
+        if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue'));
178
+        if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode'));
179
+        if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.cost_price'=>'CostPrice'));
180
+        $keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra';
181
+        include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
182
+        if (! empty($conf->fournisseur->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('s.nom'=>'Supplier','pf.ref_fourn'=>'SupplierRef','pf.quantity'=>'QtyMin','pf.remise_percent'=>'DiscountQtyMin','pf.unitprice'=>'BuyingPrice','pf.delivery_time_days'=>'NbDaysToDelivery'));
183
+        if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('group_concat(cat.label)'=>'Categories'));
184
+        if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('l.lang'=>'Language', 'l.label'=>'TranslatedLabel','l.description'=>'TranslatedDescription','l.note'=>'TranslatedNote'));
185
+        if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->export_fields_array[$r]['p.fk_unit'] = 'Unit';
186
+        $this->export_TypeFields_array[$r]=array(
187
+            'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
188
+            'p.note'=>"Text",'p.length'=>"Numeric",'p.width'=>"Numeric",'p.height'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",
189
+            'p.customcode'=>'Text','p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",
190
+            'p.tobuy'=>"Boolean",'p.datec'=>'Date','p.tms'=>'Date'
191
+        );
192
+        if (! empty($conf->stock->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric'));
193
+        if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text'));
194
+        if (! empty($conf->fournisseur->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('s.nom'=>'Text','pf.ref_fourn'=>'Text','pf.unitprice'=>'Numeric','pf.quantity'=>'Numeric','pf.remise_percent'=>'Numeric','pf.delivery_time_days'=>'Numeric'));
195
+        if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('l.lang'=>'Text', 'l.label'=>'Text','l.description'=>'Text','l.note'=>'Text'));
196
+        if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array("group_concat(cat.label)"=>'Text'));
197
+        $this->export_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
198
+        if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array("group_concat(cat.label)"=>'category'));
199
+        if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'product','p.pmp'=>'product'));
200
+        if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'product'));
201
+        if (! empty($conf->fournisseur->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('s.nom'=>'product_supplier_ref','pf.ref_fourn'=>'product_supplier_ref','pf.unitprice'=>'product_supplier_ref','pf.quantity'=>'product_supplier_ref','pf.remise_percent'=>'product_supplier_ref','pf.delivery_time_days'=>'product_supplier_ref'));
202
+        if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('l.lang'=>'translation', 'l.label'=>'translation','l.description'=>'translation','l.note'=>'translation'));
203
+        if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_dependencies_array[$r]=array('category'=>'p.rowid');
204
+        $this->export_sql_start[$r]='SELECT DISTINCT ';
205
+        $this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p';
206
+        if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'categorie as cat ON cp.fk_categorie = cat.rowid';
207
+        if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_lang as l ON l.fk_product = p.rowid';
208
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object';
209
+        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';
210
+        $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
211
+        if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_order[$r] =' GROUP BY p.rowid'; 	// FIXME The group by used a generic value to say "all fields in select except function fields"
212
+
213
+        if (! empty($conf->global->PRODUIT_MULTIPRICES))
214
+        {
215
+            // Exports product multiprice
216
+            $r++;
217
+            $this->export_code[$r]=$this->rights_class.'_'.$r;
218
+            $this->export_label[$r]="ProductsMultiPrice";	// Translation key (used only if key ExportDataset_xxx_z not found)
219
+            $this->export_permission[$r]=array(array("produit","export"));
220
+            $this->export_fields_array[$r]=array('p.rowid'=>"Id",'p.ref'=>"Ref",
221
+                'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel",
222
+                'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
223
+                'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
224
+                'pr.tva_tx'=>'PriceLevelVATRate',
225
+                'pr.date_price'=>'DateCreation');
226
+            if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['pr.recuperableonly']='NPR';
227
+            //$this->export_TypeFields_array[$r]=array(
228
+            //	'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
229
+            //	'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text',
230
+            //	'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",
231
+            //	'p.datec'=>'Date','p.tms'=>'Date'
232
+            //);
233
+            $this->export_entities_array[$r]=array('p.rowid'=>"product",'p.ref'=>"product",
234
+                'pr.price_base_type'=>"product",'pr.price_level'=>"product",'pr.price'=>"product",
235
+                'pr.price_ttc'=>"product",
236
+                'pr.price_min'=>"product",'pr.price_min_ttc'=>"product",
237
+                'pr.tva_tx'=>'product',
238
+                'pr.recuperableonly'=>'product',
239
+                'pr.date_price'=>"product");
240
+            $this->export_sql_start[$r]='SELECT DISTINCT ';
241
+            $this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p';
242
+            $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_price as pr ON p.rowid = pr.fk_product AND pr.entity = '.$conf->entity; // export prices only for the current entity
243
+            $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
244
+        }
245
+
246
+        if (! empty($conf->global->PRODUIT_SOUSPRODUITS))
247
+        {
248
+            // Exports virtual products
249
+            $r++;
250
+            $this->export_code[$r]=$this->rights_class.'_'.$r;
251
+            $this->export_label[$r]="AssociatedProducts";	// Translation key (used only if key ExportDataset_xxx_z not found)
252
+            $this->export_permission[$r]=array(array("produit","export"));
253
+            $this->export_fields_array[$r]=array(
254
+                'p.rowid'=>"Id",'p.ref'=>"Ref",'p.label'=>"Label",'p.description'=>"Description",'p.url'=>"PublicUrl",
255
+                'p.accountancy_code_sell'=>"ProductAccountancySellCode",'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",
256
+                'p.length'=>"Length",'p.surface'=>"Surface",'p.volume'=>"Volume",'p.weight'=>"Weight",'p.customcode'=>'CustomCode',
257
+                'p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC",'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell",
258
+                'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification'
259
+            );
260
+            if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue'));
261
+            if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode'));
262
+            $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('pa.qty'=>'Qty','pa.incdec'=>'ComposedProductIncDecStock'));
263
+            $this->export_TypeFields_array[$r]=array(
264
+                'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
265
+                'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text',
266
+                'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",
267
+                'p.datec'=>'Date','p.tms'=>'Date'
268
+            );
269
+            if (! empty($conf->stock->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric'));
270
+            if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text'));
271
+            $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('pa.qty'=>'Numeric'));
272
+            $this->export_entities_array[$r]=array(
273
+                'p.rowid'=>"virtualproduct",'p.ref'=>"virtualproduct",'p.label'=>"virtualproduct",'p.description'=>"virtualproduct",'p.url'=>"virtualproduct",
274
+                'p.accountancy_code_sell'=>'virtualproduct','p.accountancy_code_buy'=>'virtualproduct','p.note'=>"virtualproduct",'p.length'=>"virtualproduct",
275
+                'p.surface'=>"virtualproduct",'p.volume'=>"virtualproduct",'p.weight'=>"virtualproduct",'p.customcode'=>'virtualproduct',
276
+                'p.price_base_type'=>"virtualproduct",'p.price'=>"virtualproduct",'p.price_ttc'=>"virtualproduct",'p.tva_tx'=>"virtualproduct",
277
+                'p.tosell'=>"virtualproduct",'p.tobuy'=>"virtualproduct",'p.datec'=>"virtualproduct",'p.tms'=>"virtualproduct"
278
+            );
279
+            if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'virtualproduct','p.seuil_stock_alerte'=>'virtualproduct','p.desiredstock'=>'virtualproduct','p.pmp'=>'virtualproduct'));
280
+            if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'virtualproduct'));
281 281
             $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('pa.qty'=>"subproduct",'pa.incdec'=>'subproduct'));
282
-    		$keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra';
283
-    		include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
282
+            $keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra';
283
+            include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
284 284
             $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p2.rowid'=>"Id",'p2.ref'=>"Ref",'p2.label'=>"Label",'p2.description'=>"Description"));
285
-    		$this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p2.rowid'=>"subproduct",'p2.ref'=>"subproduct",'p2.label'=>"subproduct",'p2.description'=>"subproduct"));
286
-    		$this->export_sql_start[$r]='SELECT DISTINCT ';
287
-    		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p';
288
-    		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object,';
289
-    		$this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'product_association as pa, '.MAIN_DB_PREFIX.'product as p2';
290
-    		$this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
291
-    		$this->export_sql_end[$r] .=' AND p.rowid = pa.fk_product_pere AND p2.rowid = pa.fk_product_fils';
292
-		}
293
-
294
-		// Imports
295
-		//--------
296
-		$r=0;
285
+            $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p2.rowid'=>"subproduct",'p2.ref'=>"subproduct",'p2.label'=>"subproduct",'p2.description'=>"subproduct"));
286
+            $this->export_sql_start[$r]='SELECT DISTINCT ';
287
+            $this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p';
288
+            $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object,';
289
+            $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'product_association as pa, '.MAIN_DB_PREFIX.'product as p2';
290
+            $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
291
+            $this->export_sql_end[$r] .=' AND p.rowid = pa.fk_product_pere AND p2.rowid = pa.fk_product_fils';
292
+        }
293
+
294
+        // Imports
295
+        //--------
296
+        $r=0;
297 297
 
298
-		$r++;
299
-		$this->import_code[$r]=$this->rights_class.'_'.$r;
300
-		$this->import_label[$r]="Products";	// Translation key
301
-		$this->import_icon[$r]=$this->picto;
302
-		$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
303
-		$this->import_tables_array[$r]=array('p'=>MAIN_DB_PREFIX.'product','extra'=>MAIN_DB_PREFIX.'product_extrafields');
304
-		$this->import_tables_creator_array[$r]=array('p'=>'fk_user_author');	// Fields to store import user id
305
-		$this->import_fields_array[$r]=array(
306
-			'p.ref'=>"Ref*",'p.label'=>"Label*",'p.description'=>"Description",'p.url'=>"PublicUrl",'p.accountancy_code_sell'=>"ProductAccountancySellCode",
307
-			'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.length'=>"Length",'p.surface'=>"Surface",'p.volume'=>"Volume",
308
-			'p.weight'=>"Weight",'p.duration'=>"Duration",'p.customcode'=>'CustomCode','p.price'=>"SellingPriceHT",'p.price_ttc'=>"SellingPriceTTC",
309
-			'p.tva_tx'=>'VATRate', 'p.tosell'=>"OnSell*",'p.tobuy'=>"OnBuy*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.datec'=>'DateCreation'
310
-		);
311
-		if (! empty($conf->stock->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue'));
312
-		if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.cost_price'=>'CostPrice'));
313
-		if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.recuperableonly'=>'NPR'));
314
-		if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax1_tx'=>'LT1', 'p.localtax1_type'=>'LT1Type'));
315
-		if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax2_tx'=>'LT2', 'p.localtax2_type'=>'LT2Type'));
316
-		if (! empty($conf->barcode->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.barcode'=>'BarCode'));
317
-		if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->import_fields_array[$r]['p.fk_unit'] = 'Unit';
318
-		// Add extra fields
319
-		$import_extrafield_sample=array();
320
-		$sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' AND entity IN (0, ".$conf->entity.")";
321
-		$resql=$this->db->query($sql);
322
-		if ($resql)    // This can fail when class is used on old database (during migration for example)
323
-		{
324
-		    while ($obj=$this->db->fetch_object($resql))
325
-		    {
326
-		        $fieldname='extra.'.$obj->name;
327
-		        $fieldlabel=ucfirst($obj->label);
328
-		        $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
329
-		        $import_extrafield_sample[$fieldname]=$fieldlabel;
330
-		    }
331
-		}
332
-		// End add extra fields
333
-		$this->import_fieldshidden_array[$r]=array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'product');    // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
334
-		$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]$','p.recuperableonly'=>'^[0|1]$');
335
-		$import_sample=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','p.recuperableonly'=>'0 or 1');
336
-		$this->import_examplevalues_array[$r]=array_merge($import_sample,$import_extrafield_sample);
337
-		$this->import_updatekeys_array[$r]=array('p.ref'=>'Ref','p.barcode'=>'BarCode');
338
-
339
-		if (! empty($conf->fournisseur->enabled))
340
-		{
341
-			// Import suppliers prices (note: this code is duplicated into module service)
342
-			$r++;
343
-			$this->import_code[$r]=$this->rights_class.'_supplierprices';
344
-			$this->import_label[$r]="SuppliersPricesOfProductsOrServices";	// Translation key
345
-			$this->import_icon[$r]=$this->picto;
346
-			$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
347
-			$this->import_tables_array[$r]=array('sp'=>MAIN_DB_PREFIX.'product_fournisseur_price');
348
-			$this->import_tables_creator_array[$r]=array('sp'=>'fk_user');
349
-			$this->import_fields_array[$r]=array(
350
-					'sp.fk_product'=>"ProductOrService*",
351
-					'sp.fk_soc'=>"Supplier*", 'sp.ref_fourn'=>'SupplierRef', 'sp.quantity'=>"QtyMin*", 'sp.tva_tx'=>'VATRate', 'sp.default_vat_code'=>'VATCode'
352
-			);
353
-			if (is_object($mysoc) && $mysoc->useNPR())       $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.recuperableonly'=>'VATNPR'));
354
-			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'));
355
-			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'));
356
-			$this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array(
357
-					'sp.price'=>"PriceQtyMinHT*",
358
-					'sp.unitprice'=>'UnitPriceHT*',	// TODO Make this field not required and calculate it from price and qty
359
-					'sp.remise_percent'=>'DiscountQtyMin'
360
-			));
361
-			$this->import_convertvalue_array[$r]=array(
362
-					'sp.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'),
363
-					'sp.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'Product')
364
-			);
365
-			$this->import_examplevalues_array[$r]=array('sp.fk_product'=>"PREF123456",
366
-					'sp.fk_soc'=>"My Supplier",'sp.ref_fourn'=>"SupplierRef", 'sp.quantity'=>"1", 'sp.tva_tx'=>'21',
367
-					'sp.price'=>"50",
368
-					'sp.unitprice'=>'50',
369
-					'sp.remise_percent'=>'0'
370
-			);
371
-			$this->import_updatekeys_array[$r]=array('sp.fk_product'=>'ProductOrService','sp.ref_fourn'=>'SupplierRef','sp.fk_soc'=>'Supplier');
372
-		}
373
-
374
-		if (! empty($conf->global->PRODUIT_MULTIPRICES))
375
-		{
376
-			// Import product multiprice
377
-			$r++;
378
-			$this->import_code[$r]=$this->rights_class.'_multiprice';
379
-			$this->import_label[$r]="ProductsOrServiceMultiPrice";	// Translation key
380
-			$this->import_icon[$r]=$this->picto;
381
-			$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
382
-			$this->import_tables_array[$r]=array('pr'=>MAIN_DB_PREFIX.'product_price');
383
-			$this->import_tables_creator_array[$r]=array('pr'=>'fk_user_author');	// Fields to store import user id
384
-			$this->import_fields_array[$r]=array('pr.fk_product'=>"ProductRowid*",
385
-				'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel",
386
-				'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
387
-				'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
388
-				'pr.tva_tx'=>'PriceLevelVATRate',
389
-				'pr.date_price'=>'DateCreation*');
390
-			if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('pr.recuperableonly'=>'NPR'));
391
-			$this->import_regex_array[$r]=array('pr.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','pr.recuperableonly'=>'^[0|1]$');
392
-			$this->import_examplevalues_array[$r]=array('pr.fk_product'=>"1",
393
-				'pr.price_base_type'=>"HT",'pr.price_level'=>"1",
394
-				'pr.price'=>"100",'pr.price_ttc'=>"110",
395
-				'pr.price_min'=>"100",'pr.price_min_ttc'=>"110",
396
-				'pr.tva_tx'=>'20',
397
-			    'pr.recuperableonly'=>'0',
398
-				'pr.date_price'=>'2013-04-10');
399
-		}
400
-
401
-		if (! empty($conf->global->MAIN_MULTILANGS))
402
-		{
403
-		    $r++;
404
-		    $this->import_code[$r]=$this->rights_class.'_languages';
405
-		    $this->import_label[$r]="ProductsOrServicesTranslations";
406
-			$this->import_icon[$r]=$this->picto;
407
-			$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
408
-		    $this->import_tables_array[$r]=array('l'=>MAIN_DB_PREFIX.'product_lang');
409
-			// multiline translation, one line per translation
410
-			$this->import_fields_array[$r]=array('l.fk_product'=>'Ref', 'l.lang'=>'Language', 'l.label'=>'TranslatedLabel', 'l.description'=>'TranslatedDescription');
411
-			//$this->import_fields_array[$r]['l.note']='TranslatedNote';
412
-			$this->import_convertvalue_array[$r]=array(
413
-					'l.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'Product')
414
-			);
415
-			$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');
416
-			$this->import_updatekeys_array[$r]=array('l.fk_product'=>'Ref','l.lang'=>'Language');
417
-		}
418
-	}
419
-
420
-
421
-	/**
422
-	 *		Function called when module is enabled.
423
-	 *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
424
-	 *		It also creates data directories
425
-	 *
298
+        $r++;
299
+        $this->import_code[$r]=$this->rights_class.'_'.$r;
300
+        $this->import_label[$r]="Products";	// Translation key
301
+        $this->import_icon[$r]=$this->picto;
302
+        $this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
303
+        $this->import_tables_array[$r]=array('p'=>MAIN_DB_PREFIX.'product','extra'=>MAIN_DB_PREFIX.'product_extrafields');
304
+        $this->import_tables_creator_array[$r]=array('p'=>'fk_user_author');	// Fields to store import user id
305
+        $this->import_fields_array[$r]=array(
306
+            'p.ref'=>"Ref*",'p.label'=>"Label*",'p.description'=>"Description",'p.url'=>"PublicUrl",'p.accountancy_code_sell'=>"ProductAccountancySellCode",
307
+            'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.length'=>"Length",'p.surface'=>"Surface",'p.volume'=>"Volume",
308
+            'p.weight'=>"Weight",'p.duration'=>"Duration",'p.customcode'=>'CustomCode','p.price'=>"SellingPriceHT",'p.price_ttc'=>"SellingPriceTTC",
309
+            'p.tva_tx'=>'VATRate', 'p.tosell'=>"OnSell*",'p.tobuy'=>"OnBuy*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.datec'=>'DateCreation'
310
+        );
311
+        if (! empty($conf->stock->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue'));
312
+        if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.cost_price'=>'CostPrice'));
313
+        if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.recuperableonly'=>'NPR'));
314
+        if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax1_tx'=>'LT1', 'p.localtax1_type'=>'LT1Type'));
315
+        if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax2_tx'=>'LT2', 'p.localtax2_type'=>'LT2Type'));
316
+        if (! empty($conf->barcode->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.barcode'=>'BarCode'));
317
+        if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->import_fields_array[$r]['p.fk_unit'] = 'Unit';
318
+        // Add extra fields
319
+        $import_extrafield_sample=array();
320
+        $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' AND entity IN (0, ".$conf->entity.")";
321
+        $resql=$this->db->query($sql);
322
+        if ($resql)    // This can fail when class is used on old database (during migration for example)
323
+        {
324
+            while ($obj=$this->db->fetch_object($resql))
325
+            {
326
+                $fieldname='extra.'.$obj->name;
327
+                $fieldlabel=ucfirst($obj->label);
328
+                $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
329
+                $import_extrafield_sample[$fieldname]=$fieldlabel;
330
+            }
331
+        }
332
+        // End add extra fields
333
+        $this->import_fieldshidden_array[$r]=array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'product');    // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
334
+        $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]$','p.recuperableonly'=>'^[0|1]$');
335
+        $import_sample=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','p.recuperableonly'=>'0 or 1');
336
+        $this->import_examplevalues_array[$r]=array_merge($import_sample,$import_extrafield_sample);
337
+        $this->import_updatekeys_array[$r]=array('p.ref'=>'Ref','p.barcode'=>'BarCode');
338
+
339
+        if (! empty($conf->fournisseur->enabled))
340
+        {
341
+            // Import suppliers prices (note: this code is duplicated into module service)
342
+            $r++;
343
+            $this->import_code[$r]=$this->rights_class.'_supplierprices';
344
+            $this->import_label[$r]="SuppliersPricesOfProductsOrServices";	// Translation key
345
+            $this->import_icon[$r]=$this->picto;
346
+            $this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
347
+            $this->import_tables_array[$r]=array('sp'=>MAIN_DB_PREFIX.'product_fournisseur_price');
348
+            $this->import_tables_creator_array[$r]=array('sp'=>'fk_user');
349
+            $this->import_fields_array[$r]=array(
350
+                    'sp.fk_product'=>"ProductOrService*",
351
+                    'sp.fk_soc'=>"Supplier*", 'sp.ref_fourn'=>'SupplierRef', 'sp.quantity'=>"QtyMin*", 'sp.tva_tx'=>'VATRate', 'sp.default_vat_code'=>'VATCode'
352
+            );
353
+            if (is_object($mysoc) && $mysoc->useNPR())       $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.recuperableonly'=>'VATNPR'));
354
+            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'));
355
+            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'));
356
+            $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array(
357
+                    'sp.price'=>"PriceQtyMinHT*",
358
+                    'sp.unitprice'=>'UnitPriceHT*',	// TODO Make this field not required and calculate it from price and qty
359
+                    'sp.remise_percent'=>'DiscountQtyMin'
360
+            ));
361
+            $this->import_convertvalue_array[$r]=array(
362
+                    'sp.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'),
363
+                    'sp.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'Product')
364
+            );
365
+            $this->import_examplevalues_array[$r]=array('sp.fk_product'=>"PREF123456",
366
+                    'sp.fk_soc'=>"My Supplier",'sp.ref_fourn'=>"SupplierRef", 'sp.quantity'=>"1", 'sp.tva_tx'=>'21',
367
+                    'sp.price'=>"50",
368
+                    'sp.unitprice'=>'50',
369
+                    'sp.remise_percent'=>'0'
370
+            );
371
+            $this->import_updatekeys_array[$r]=array('sp.fk_product'=>'ProductOrService','sp.ref_fourn'=>'SupplierRef','sp.fk_soc'=>'Supplier');
372
+        }
373
+
374
+        if (! empty($conf->global->PRODUIT_MULTIPRICES))
375
+        {
376
+            // Import product multiprice
377
+            $r++;
378
+            $this->import_code[$r]=$this->rights_class.'_multiprice';
379
+            $this->import_label[$r]="ProductsOrServiceMultiPrice";	// Translation key
380
+            $this->import_icon[$r]=$this->picto;
381
+            $this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
382
+            $this->import_tables_array[$r]=array('pr'=>MAIN_DB_PREFIX.'product_price');
383
+            $this->import_tables_creator_array[$r]=array('pr'=>'fk_user_author');	// Fields to store import user id
384
+            $this->import_fields_array[$r]=array('pr.fk_product'=>"ProductRowid*",
385
+                'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel",
386
+                'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
387
+                'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
388
+                'pr.tva_tx'=>'PriceLevelVATRate',
389
+                'pr.date_price'=>'DateCreation*');
390
+            if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('pr.recuperableonly'=>'NPR'));
391
+            $this->import_regex_array[$r]=array('pr.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','pr.recuperableonly'=>'^[0|1]$');
392
+            $this->import_examplevalues_array[$r]=array('pr.fk_product'=>"1",
393
+                'pr.price_base_type'=>"HT",'pr.price_level'=>"1",
394
+                'pr.price'=>"100",'pr.price_ttc'=>"110",
395
+                'pr.price_min'=>"100",'pr.price_min_ttc'=>"110",
396
+                'pr.tva_tx'=>'20',
397
+                'pr.recuperableonly'=>'0',
398
+                'pr.date_price'=>'2013-04-10');
399
+        }
400
+
401
+        if (! empty($conf->global->MAIN_MULTILANGS))
402
+        {
403
+            $r++;
404
+            $this->import_code[$r]=$this->rights_class.'_languages';
405
+            $this->import_label[$r]="ProductsOrServicesTranslations";
406
+            $this->import_icon[$r]=$this->picto;
407
+            $this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
408
+            $this->import_tables_array[$r]=array('l'=>MAIN_DB_PREFIX.'product_lang');
409
+            // multiline translation, one line per translation
410
+            $this->import_fields_array[$r]=array('l.fk_product'=>'Ref', 'l.lang'=>'Language', 'l.label'=>'TranslatedLabel', 'l.description'=>'TranslatedDescription');
411
+            //$this->import_fields_array[$r]['l.note']='TranslatedNote';
412
+            $this->import_convertvalue_array[$r]=array(
413
+                    'l.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'Product')
414
+            );
415
+            $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');
416
+            $this->import_updatekeys_array[$r]=array('l.fk_product'=>'Ref','l.lang'=>'Language');
417
+        }
418
+    }
419
+
420
+
421
+    /**
422
+     *		Function called when module is enabled.
423
+     *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
424
+     *		It also creates data directories
425
+     *
426 426
      *      @param      string	$options    Options when enabling module ('', 'newboxdefonly', 'noboxes')
427
-	 *      @return     int             	1 if OK, 0 if KO
428
-	 */
429
-	function init($options='')
430
-	{
431
-		$this->remove($options);
427
+     *      @return     int             	1 if OK, 0 if KO
428
+     */
429
+    function init($options='')
430
+    {
431
+        $this->remove($options);
432 432
 
433
-		$sql = array();
433
+        $sql = array();
434 434
 
435
-		return $this->_init($sql,$options);
436
-	}
435
+        return $this->_init($sql,$options);
436
+    }
437 437
 }
Please login to merge, or discard this patch.
Spacing   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
  *	\ingroup    produit
30 30
  *	\brief      File to describe module to manage catalog of predefined products
31 31
  */
32
-include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
32
+include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
33 33
 
34 34
 
35 35
 /**
@@ -52,32 +52,32 @@  discard block
 block discarded – undo
52 52
 		$this->family = "products";
53 53
 		$this->module_position = '20';
54 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));
55
+		$this->name = preg_replace('/^mod/i', '', get_class($this));
56 56
 		$this->description = "Product management";
57 57
 
58 58
 		// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
59 59
 		$this->version = 'dolibarr';
60 60
 
61 61
 		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
62
-		$this->picto='product';
62
+		$this->picto = 'product';
63 63
 
64 64
 		// Data directories to create when module is enabled
65 65
 		$this->dirs = array("/product/temp");
66 66
 
67 67
 		// Dependencies
68
-		$this->hidden = false;			// A condition to hide module
69
-		$this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
70
-		$this->requiredby = array("modStock","modBarcode","modProductBatch");	// List of module ids to disable if this one is disabled
71
-		$this->conflictwith = array();	// List of module class names as string this module is in conflict with
72
-		$this->phpmin = array(5,4);		// Minimum version of PHP required by module
68
+		$this->hidden = false; // A condition to hide module
69
+		$this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
70
+		$this->requiredby = array("modStock", "modBarcode", "modProductBatch"); // List of module ids to disable if this one is disabled
71
+		$this->conflictwith = array(); // List of module class names as string this module is in conflict with
72
+		$this->phpmin = array(5, 4); // Minimum version of PHP required by module
73 73
 
74 74
 		// Config pages
75 75
 		$this->config_page_url = array("product.php@product");
76
-		$this->langfiles = array("products","companies","stocks","bills");
76
+		$this->langfiles = array("products", "companies", "stocks", "bills");
77 77
 
78 78
 		// Constants
79 79
 		$this->const = array();
80
-		$r=0;
80
+		$r = 0;
81 81
 
82 82
 		$this->const[$r][0] = "PRODUCT_CODEPRODUCT_ADDON";
83 83
 		$this->const[$r][1] = "chaine";
@@ -95,15 +95,15 @@  discard block
 block discarded – undo
95 95
 
96 96
 		// Boxes
97 97
 		$this->boxes = array(
98
-			0=>array('file'=>'box_produits.php','enabledbydefaulton'=>'Home'),
99
-			1=>array('file'=>'box_produits_alerte_stock.php','enabledbydefaulton'=>''),
100
-			2=>array('file'=>'box_graph_product_distribution.php','enabledbydefaulton'=>'Home')
98
+			0=>array('file'=>'box_produits.php', 'enabledbydefaulton'=>'Home'),
99
+			1=>array('file'=>'box_produits_alerte_stock.php', 'enabledbydefaulton'=>''),
100
+			2=>array('file'=>'box_graph_product_distribution.php', 'enabledbydefaulton'=>'Home')
101 101
 		);
102 102
 
103 103
 		// Permissions
104 104
 		$this->rights = array();
105 105
 		$this->rights_class = 'produit';
106
-		$r=0;
106
+		$r = 0;
107 107
 
108 108
 		$this->rights[$r][0] = 31; // id de la permission
109 109
 		$this->rights[$r][1] = 'Read products'; // libelle de la permission
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 		$this->rights[$r][4] = 'supprimer';
127 127
         $r++;
128 128
 
129
-		$this->rights[$r][0] = 38;	// Must be same permission than in service module
129
+		$this->rights[$r][0] = 38; // Must be same permission than in service module
130 130
 		$this->rights[$r][1] = 'Export products';
131 131
 		$this->rights[$r][2] = 'r';
132 132
 		$this->rights[$r][3] = 0;
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
         // Menus
144 144
         //-------
145 145
 
146
-        $this->menu = 1;        // This module add menu entries. They are coded into menu manager.
146
+        $this->menu = 1; // This module add menu entries. They are coded into menu manager.
147 147
 		/* We can't enable this here because it must be enabled in both product and service module and this create duplicate insert
148 148
 		$r=0;
149 149
 		$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
@@ -161,259 +161,259 @@  discard block
 block discarded – undo
161 161
 
162 162
 		// Exports
163 163
 		//--------
164
-		$r=0;
164
+		$r = 0;
165 165
 
166 166
 		$r++;
167
-		$this->export_code[$r]=$this->rights_class.'_'.$r;
168
-		$this->export_label[$r]="Products";	// Translation key (used only if key ExportDataset_xxx_z not found)
169
-		$this->export_permission[$r]=array(array("produit","export"));
170
-		$this->export_fields_array[$r]=array(
171
-			'p.rowid'=>"Id",'p.ref'=>"Ref",'p.label'=>"Label",'p.description'=>"Description",'p.url'=>"PublicUrl",'p.accountancy_code_sell'=>"ProductAccountancySellCode",
172
-			'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.length'=>"Length",'p.width'=>"Width",'p.height'=>"Height",'p.surface'=>"Surface",
173
-			'p.volume'=>"Volume",'p.weight'=>"Weight",'p.customcode'=>'CustomCode','p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC",
174
-			'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell",'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification'
167
+		$this->export_code[$r] = $this->rights_class.'_'.$r;
168
+		$this->export_label[$r] = "Products"; // Translation key (used only if key ExportDataset_xxx_z not found)
169
+		$this->export_permission[$r] = array(array("produit", "export"));
170
+		$this->export_fields_array[$r] = array(
171
+			'p.rowid'=>"Id", 'p.ref'=>"Ref", 'p.label'=>"Label", 'p.description'=>"Description", 'p.url'=>"PublicUrl", 'p.accountancy_code_sell'=>"ProductAccountancySellCode",
172
+			'p.accountancy_code_buy'=>"ProductAccountancyBuyCode", 'p.note'=>"Note", 'p.length'=>"Length", 'p.width'=>"Width", 'p.height'=>"Height", 'p.surface'=>"Surface",
173
+			'p.volume'=>"Volume", 'p.weight'=>"Weight", 'p.customcode'=>'CustomCode', 'p.price_base_type'=>"PriceBase", 'p.price'=>"UnitPriceHT", 'p.price_ttc'=>"UnitPriceTTC",
174
+			'p.tva_tx'=>'VATRate', 'p.tosell'=>"OnSell", 'p.tobuy'=>"OnBuy", 'p.datec'=>'DateCreation', 'p.tms'=>'DateModification'
175 175
 		);
176
-		if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['p.recuperableonly']='NPR';
177
-		if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue'));
178
-		if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode'));
179
-		if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.cost_price'=>'CostPrice'));
180
-		$keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra';
176
+		if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['p.recuperableonly'] = 'NPR';
177
+		if (!empty($conf->stock->enabled)) $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.stock'=>'Stock', 'p.seuil_stock_alerte'=>'StockLimit', 'p.desiredstock'=>'DesiredStock', 'p.pmp'=>'PMPValue'));
178
+		if (!empty($conf->barcode->enabled)) $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.barcode'=>'BarCode'));
179
+		if (!empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.cost_price'=>'CostPrice'));
180
+		$keyforselect = 'product'; $keyforelement = 'product'; $keyforaliasextra = 'extra';
181 181
 		include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
182
-		if (! empty($conf->fournisseur->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('s.nom'=>'Supplier','pf.ref_fourn'=>'SupplierRef','pf.quantity'=>'QtyMin','pf.remise_percent'=>'DiscountQtyMin','pf.unitprice'=>'BuyingPrice','pf.delivery_time_days'=>'NbDaysToDelivery'));
183
-		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('group_concat(cat.label)'=>'Categories'));
184
-		if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('l.lang'=>'Language', 'l.label'=>'TranslatedLabel','l.description'=>'TranslatedDescription','l.note'=>'TranslatedNote'));
185
-		if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->export_fields_array[$r]['p.fk_unit'] = 'Unit';
186
-		$this->export_TypeFields_array[$r]=array(
187
-			'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
188
-			'p.note'=>"Text",'p.length'=>"Numeric",'p.width'=>"Numeric",'p.height'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",
189
-			'p.customcode'=>'Text','p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",
190
-			'p.tobuy'=>"Boolean",'p.datec'=>'Date','p.tms'=>'Date'
182
+		if (!empty($conf->fournisseur->enabled)) $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('s.nom'=>'Supplier', 'pf.ref_fourn'=>'SupplierRef', 'pf.quantity'=>'QtyMin', 'pf.remise_percent'=>'DiscountQtyMin', 'pf.unitprice'=>'BuyingPrice', 'pf.delivery_time_days'=>'NbDaysToDelivery'));
183
+		if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('group_concat(cat.label)'=>'Categories'));
184
+		if (!empty($conf->global->MAIN_MULTILANGS)) $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('l.lang'=>'Language', 'l.label'=>'TranslatedLabel', 'l.description'=>'TranslatedDescription', 'l.note'=>'TranslatedNote'));
185
+		if (!empty($conf->global->PRODUCT_USE_UNITS)) $this->export_fields_array[$r]['p.fk_unit'] = 'Unit';
186
+		$this->export_TypeFields_array[$r] = array(
187
+			'p.ref'=>"Text", 'p.label'=>"Text", 'p.description'=>"Text", 'p.url'=>"Text", 'p.accountancy_code_sell'=>"Text", 'p.accountancy_code_buy'=>"Text",
188
+			'p.note'=>"Text", 'p.length'=>"Numeric", 'p.width'=>"Numeric", 'p.height'=>"Numeric", 'p.surface'=>"Numeric", 'p.volume'=>"Numeric", 'p.weight'=>"Numeric",
189
+			'p.customcode'=>'Text', 'p.price_base_type'=>"Text", 'p.price'=>"Numeric", 'p.price_ttc'=>"Numeric", 'p.tva_tx'=>'Numeric', 'p.tosell'=>"Boolean",
190
+			'p.tobuy'=>"Boolean", 'p.datec'=>'Date', 'p.tms'=>'Date'
191 191
 		);
192
-		if (! empty($conf->stock->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric'));
193
-		if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text'));
194
-		if (! empty($conf->fournisseur->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('s.nom'=>'Text','pf.ref_fourn'=>'Text','pf.unitprice'=>'Numeric','pf.quantity'=>'Numeric','pf.remise_percent'=>'Numeric','pf.delivery_time_days'=>'Numeric'));
195
-		if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('l.lang'=>'Text', 'l.label'=>'Text','l.description'=>'Text','l.note'=>'Text'));
196
-		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array("group_concat(cat.label)"=>'Text'));
197
-		$this->export_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
198
-		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array("group_concat(cat.label)"=>'category'));
199
-		if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'product','p.pmp'=>'product'));
200
-		if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'product'));
201
-		if (! empty($conf->fournisseur->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('s.nom'=>'product_supplier_ref','pf.ref_fourn'=>'product_supplier_ref','pf.unitprice'=>'product_supplier_ref','pf.quantity'=>'product_supplier_ref','pf.remise_percent'=>'product_supplier_ref','pf.delivery_time_days'=>'product_supplier_ref'));
202
-		if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('l.lang'=>'translation', 'l.label'=>'translation','l.description'=>'translation','l.note'=>'translation'));
203
-		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_dependencies_array[$r]=array('category'=>'p.rowid');
204
-		$this->export_sql_start[$r]='SELECT DISTINCT ';
205
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p';
206
-		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'categorie as cat ON cp.fk_categorie = cat.rowid';
207
-		if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_lang as l ON l.fk_product = p.rowid';
208
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object';
209
-		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';
210
-		$this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
211
-		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_order[$r] =' GROUP BY p.rowid'; 	// FIXME The group by used a generic value to say "all fields in select except function fields"
212
-
213
-		if (! empty($conf->global->PRODUIT_MULTIPRICES))
192
+		if (!empty($conf->stock->enabled)) $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('p.stock'=>'Numeric', 'p.seuil_stock_alerte'=>'Numeric', 'p.desiredstock'=>'Numeric', 'p.pmp'=>'Numeric', 'p.cost_price'=>'Numeric'));
193
+		if (!empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('p.barcode'=>'Text'));
194
+		if (!empty($conf->fournisseur->enabled)) $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('s.nom'=>'Text', 'pf.ref_fourn'=>'Text', 'pf.unitprice'=>'Numeric', 'pf.quantity'=>'Numeric', 'pf.remise_percent'=>'Numeric', 'pf.delivery_time_days'=>'Numeric'));
195
+		if (!empty($conf->global->MAIN_MULTILANGS)) $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('l.lang'=>'Text', 'l.label'=>'Text', 'l.description'=>'Text', 'l.note'=>'Text'));
196
+		if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array("group_concat(cat.label)"=>'Text'));
197
+		$this->export_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
198
+		if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array("group_concat(cat.label)"=>'category'));
199
+		if (!empty($conf->stock->enabled)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.stock'=>'product', 'p.pmp'=>'product'));
200
+		if (!empty($conf->barcode->enabled)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.barcode'=>'product'));
201
+		if (!empty($conf->fournisseur->enabled)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('s.nom'=>'product_supplier_ref', 'pf.ref_fourn'=>'product_supplier_ref', 'pf.unitprice'=>'product_supplier_ref', 'pf.quantity'=>'product_supplier_ref', 'pf.remise_percent'=>'product_supplier_ref', 'pf.delivery_time_days'=>'product_supplier_ref'));
202
+		if (!empty($conf->global->MAIN_MULTILANGS)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('l.lang'=>'translation', 'l.label'=>'translation', 'l.description'=>'translation', 'l.note'=>'translation'));
203
+		if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_dependencies_array[$r] = array('category'=>'p.rowid');
204
+		$this->export_sql_start[$r] = 'SELECT DISTINCT ';
205
+		$this->export_sql_end[$r]  = ' FROM '.MAIN_DB_PREFIX.'product as p';
206
+		if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'categorie as cat ON cp.fk_categorie = cat.rowid';
207
+		if (!empty($conf->global->MAIN_MULTILANGS)) $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_lang as l ON l.fk_product = p.rowid';
208
+		$this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object';
209
+		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';
210
+		$this->export_sql_end[$r] .= ' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
211
+		if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_order[$r] = ' GROUP BY p.rowid'; // FIXME The group by used a generic value to say "all fields in select except function fields"
212
+
213
+		if (!empty($conf->global->PRODUIT_MULTIPRICES))
214 214
 		{
215 215
 			// Exports product multiprice
216 216
 			$r++;
217
-			$this->export_code[$r]=$this->rights_class.'_'.$r;
218
-			$this->export_label[$r]="ProductsMultiPrice";	// Translation key (used only if key ExportDataset_xxx_z not found)
219
-			$this->export_permission[$r]=array(array("produit","export"));
220
-			$this->export_fields_array[$r]=array('p.rowid'=>"Id",'p.ref'=>"Ref",
221
-				'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel",
222
-				'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
223
-				'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
217
+			$this->export_code[$r] = $this->rights_class.'_'.$r;
218
+			$this->export_label[$r] = "ProductsMultiPrice"; // Translation key (used only if key ExportDataset_xxx_z not found)
219
+			$this->export_permission[$r] = array(array("produit", "export"));
220
+			$this->export_fields_array[$r] = array('p.rowid'=>"Id", 'p.ref'=>"Ref",
221
+				'pr.price_base_type'=>"PriceLevelPriceBase", 'pr.price_level'=>"PriceLevel",
222
+				'pr.price'=>"PriceLevelUnitPriceHT", 'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
223
+				'pr.price_min'=>"MinPriceLevelUnitPriceHT", 'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
224 224
 				'pr.tva_tx'=>'PriceLevelVATRate',
225 225
 				'pr.date_price'=>'DateCreation');
226
-			if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['pr.recuperableonly']='NPR';
226
+			if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['pr.recuperableonly'] = 'NPR';
227 227
 			//$this->export_TypeFields_array[$r]=array(
228 228
 			//	'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
229 229
 			//	'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text',
230 230
 			//	'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",
231 231
 			//	'p.datec'=>'Date','p.tms'=>'Date'
232 232
 			//);
233
-			$this->export_entities_array[$r]=array('p.rowid'=>"product",'p.ref'=>"product",
234
-				'pr.price_base_type'=>"product",'pr.price_level'=>"product",'pr.price'=>"product",
233
+			$this->export_entities_array[$r] = array('p.rowid'=>"product", 'p.ref'=>"product",
234
+				'pr.price_base_type'=>"product", 'pr.price_level'=>"product", 'pr.price'=>"product",
235 235
 				'pr.price_ttc'=>"product",
236
-				'pr.price_min'=>"product",'pr.price_min_ttc'=>"product",
236
+				'pr.price_min'=>"product", 'pr.price_min_ttc'=>"product",
237 237
 				'pr.tva_tx'=>'product',
238 238
 				'pr.recuperableonly'=>'product',
239 239
 				'pr.date_price'=>"product");
240
-			$this->export_sql_start[$r]='SELECT DISTINCT ';
241
-			$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p';
242
-			$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_price as pr ON p.rowid = pr.fk_product AND pr.entity = '.$conf->entity; // export prices only for the current entity
243
-			$this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
240
+			$this->export_sql_start[$r] = 'SELECT DISTINCT ';
241
+			$this->export_sql_end[$r]  = ' FROM '.MAIN_DB_PREFIX.'product as p';
242
+			$this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_price as pr ON p.rowid = pr.fk_product AND pr.entity = '.$conf->entity; // export prices only for the current entity
243
+			$this->export_sql_end[$r] .= ' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
244 244
 		}
245 245
 
246
-		if (! empty($conf->global->PRODUIT_SOUSPRODUITS))
246
+		if (!empty($conf->global->PRODUIT_SOUSPRODUITS))
247 247
 		{
248 248
 			// Exports virtual products
249 249
         	$r++;
250
-    		$this->export_code[$r]=$this->rights_class.'_'.$r;
251
-    		$this->export_label[$r]="AssociatedProducts";	// Translation key (used only if key ExportDataset_xxx_z not found)
252
-    		$this->export_permission[$r]=array(array("produit","export"));
253
-    		$this->export_fields_array[$r]=array(
254
-				'p.rowid'=>"Id",'p.ref'=>"Ref",'p.label'=>"Label",'p.description'=>"Description",'p.url'=>"PublicUrl",
255
-				'p.accountancy_code_sell'=>"ProductAccountancySellCode",'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",
256
-				'p.length'=>"Length",'p.surface'=>"Surface",'p.volume'=>"Volume",'p.weight'=>"Weight",'p.customcode'=>'CustomCode',
257
-				'p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC",'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell",
258
-				'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification'
250
+    		$this->export_code[$r] = $this->rights_class.'_'.$r;
251
+    		$this->export_label[$r] = "AssociatedProducts"; // Translation key (used only if key ExportDataset_xxx_z not found)
252
+    		$this->export_permission[$r] = array(array("produit", "export"));
253
+    		$this->export_fields_array[$r] = array(
254
+				'p.rowid'=>"Id", 'p.ref'=>"Ref", 'p.label'=>"Label", 'p.description'=>"Description", 'p.url'=>"PublicUrl",
255
+				'p.accountancy_code_sell'=>"ProductAccountancySellCode", 'p.accountancy_code_buy'=>"ProductAccountancyBuyCode", 'p.note'=>"Note",
256
+				'p.length'=>"Length", 'p.surface'=>"Surface", 'p.volume'=>"Volume", 'p.weight'=>"Weight", 'p.customcode'=>'CustomCode',
257
+				'p.price_base_type'=>"PriceBase", 'p.price'=>"UnitPriceHT", 'p.price_ttc'=>"UnitPriceTTC", 'p.tva_tx'=>'VATRate', 'p.tosell'=>"OnSell",
258
+				'p.tobuy'=>"OnBuy", 'p.datec'=>'DateCreation', 'p.tms'=>'DateModification'
259 259
 			);
260
-    		if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue'));
261
-    		if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode'));
262
-    		$this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('pa.qty'=>'Qty','pa.incdec'=>'ComposedProductIncDecStock'));
263
-    		$this->export_TypeFields_array[$r]=array(
264
-				'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
265
-				'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text',
266
-				'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",
267
-				'p.datec'=>'Date','p.tms'=>'Date'
260
+    		if (!empty($conf->stock->enabled)) $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.stock'=>'Stock', 'p.seuil_stock_alerte'=>'StockLimit', 'p.desiredstock'=>'DesiredStock', 'p.pmp'=>'PMPValue'));
261
+    		if (!empty($conf->barcode->enabled)) $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.barcode'=>'BarCode'));
262
+    		$this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('pa.qty'=>'Qty', 'pa.incdec'=>'ComposedProductIncDecStock'));
263
+    		$this->export_TypeFields_array[$r] = array(
264
+				'p.ref'=>"Text", 'p.label'=>"Text", 'p.description'=>"Text", 'p.url'=>"Text", 'p.accountancy_code_sell'=>"Text", 'p.accountancy_code_buy'=>"Text",
265
+				'p.note'=>"Text", 'p.length'=>"Numeric", 'p.surface'=>"Numeric", 'p.volume'=>"Numeric", 'p.weight'=>"Numeric", 'p.customcode'=>'Text',
266
+				'p.price_base_type'=>"Text", 'p.price'=>"Numeric", 'p.price_ttc'=>"Numeric", 'p.tva_tx'=>'Numeric', 'p.tosell'=>"Boolean", 'p.tobuy'=>"Boolean",
267
+				'p.datec'=>'Date', 'p.tms'=>'Date'
268 268
 			);
269
-    		if (! empty($conf->stock->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric'));
270
-    		if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text'));
271
-    		$this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('pa.qty'=>'Numeric'));
272
-    		$this->export_entities_array[$r]=array(
273
-				'p.rowid'=>"virtualproduct",'p.ref'=>"virtualproduct",'p.label'=>"virtualproduct",'p.description'=>"virtualproduct",'p.url'=>"virtualproduct",
274
-				'p.accountancy_code_sell'=>'virtualproduct','p.accountancy_code_buy'=>'virtualproduct','p.note'=>"virtualproduct",'p.length'=>"virtualproduct",
275
-				'p.surface'=>"virtualproduct",'p.volume'=>"virtualproduct",'p.weight'=>"virtualproduct",'p.customcode'=>'virtualproduct',
276
-				'p.price_base_type'=>"virtualproduct",'p.price'=>"virtualproduct",'p.price_ttc'=>"virtualproduct",'p.tva_tx'=>"virtualproduct",
277
-				'p.tosell'=>"virtualproduct",'p.tobuy'=>"virtualproduct",'p.datec'=>"virtualproduct",'p.tms'=>"virtualproduct"
269
+    		if (!empty($conf->stock->enabled)) $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('p.stock'=>'Numeric', 'p.seuil_stock_alerte'=>'Numeric', 'p.desiredstock'=>'Numeric', 'p.pmp'=>'Numeric', 'p.cost_price'=>'Numeric'));
270
+    		if (!empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('p.barcode'=>'Text'));
271
+    		$this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('pa.qty'=>'Numeric'));
272
+    		$this->export_entities_array[$r] = array(
273
+				'p.rowid'=>"virtualproduct", 'p.ref'=>"virtualproduct", 'p.label'=>"virtualproduct", 'p.description'=>"virtualproduct", 'p.url'=>"virtualproduct",
274
+				'p.accountancy_code_sell'=>'virtualproduct', 'p.accountancy_code_buy'=>'virtualproduct', 'p.note'=>"virtualproduct", 'p.length'=>"virtualproduct",
275
+				'p.surface'=>"virtualproduct", 'p.volume'=>"virtualproduct", 'p.weight'=>"virtualproduct", 'p.customcode'=>'virtualproduct',
276
+				'p.price_base_type'=>"virtualproduct", 'p.price'=>"virtualproduct", 'p.price_ttc'=>"virtualproduct", 'p.tva_tx'=>"virtualproduct",
277
+				'p.tosell'=>"virtualproduct", 'p.tobuy'=>"virtualproduct", 'p.datec'=>"virtualproduct", 'p.tms'=>"virtualproduct"
278 278
 			);
279
-    		if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'virtualproduct','p.seuil_stock_alerte'=>'virtualproduct','p.desiredstock'=>'virtualproduct','p.pmp'=>'virtualproduct'));
280
-    		if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'virtualproduct'));
281
-            $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('pa.qty'=>"subproduct",'pa.incdec'=>'subproduct'));
282
-    		$keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra';
279
+    		if (!empty($conf->stock->enabled)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.stock'=>'virtualproduct', 'p.seuil_stock_alerte'=>'virtualproduct', 'p.desiredstock'=>'virtualproduct', 'p.pmp'=>'virtualproduct'));
280
+    		if (!empty($conf->barcode->enabled)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.barcode'=>'virtualproduct'));
281
+            $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('pa.qty'=>"subproduct", 'pa.incdec'=>'subproduct'));
282
+    		$keyforselect = 'product'; $keyforelement = 'product'; $keyforaliasextra = 'extra';
283 283
     		include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
284
-            $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p2.rowid'=>"Id",'p2.ref'=>"Ref",'p2.label'=>"Label",'p2.description'=>"Description"));
285
-    		$this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p2.rowid'=>"subproduct",'p2.ref'=>"subproduct",'p2.label'=>"subproduct",'p2.description'=>"subproduct"));
286
-    		$this->export_sql_start[$r]='SELECT DISTINCT ';
287
-    		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p';
288
-    		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object,';
289
-    		$this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'product_association as pa, '.MAIN_DB_PREFIX.'product as p2';
290
-    		$this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
291
-    		$this->export_sql_end[$r] .=' AND p.rowid = pa.fk_product_pere AND p2.rowid = pa.fk_product_fils';
284
+            $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p2.rowid'=>"Id", 'p2.ref'=>"Ref", 'p2.label'=>"Label", 'p2.description'=>"Description"));
285
+    		$this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p2.rowid'=>"subproduct", 'p2.ref'=>"subproduct", 'p2.label'=>"subproduct", 'p2.description'=>"subproduct"));
286
+    		$this->export_sql_start[$r] = 'SELECT DISTINCT ';
287
+    		$this->export_sql_end[$r]  = ' FROM '.MAIN_DB_PREFIX.'product as p';
288
+    		$this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object,';
289
+    		$this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'product_association as pa, '.MAIN_DB_PREFIX.'product as p2';
290
+    		$this->export_sql_end[$r] .= ' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
291
+    		$this->export_sql_end[$r] .= ' AND p.rowid = pa.fk_product_pere AND p2.rowid = pa.fk_product_fils';
292 292
 		}
293 293
 
294 294
 		// Imports
295 295
 		//--------
296
-		$r=0;
296
+		$r = 0;
297 297
 
298 298
 		$r++;
299
-		$this->import_code[$r]=$this->rights_class.'_'.$r;
300
-		$this->import_label[$r]="Products";	// Translation key
301
-		$this->import_icon[$r]=$this->picto;
302
-		$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
303
-		$this->import_tables_array[$r]=array('p'=>MAIN_DB_PREFIX.'product','extra'=>MAIN_DB_PREFIX.'product_extrafields');
304
-		$this->import_tables_creator_array[$r]=array('p'=>'fk_user_author');	// Fields to store import user id
305
-		$this->import_fields_array[$r]=array(
306
-			'p.ref'=>"Ref*",'p.label'=>"Label*",'p.description'=>"Description",'p.url'=>"PublicUrl",'p.accountancy_code_sell'=>"ProductAccountancySellCode",
307
-			'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.length'=>"Length",'p.surface'=>"Surface",'p.volume'=>"Volume",
308
-			'p.weight'=>"Weight",'p.duration'=>"Duration",'p.customcode'=>'CustomCode','p.price'=>"SellingPriceHT",'p.price_ttc'=>"SellingPriceTTC",
309
-			'p.tva_tx'=>'VATRate', 'p.tosell'=>"OnSell*",'p.tobuy'=>"OnBuy*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.datec'=>'DateCreation'
299
+		$this->import_code[$r] = $this->rights_class.'_'.$r;
300
+		$this->import_label[$r] = "Products"; // Translation key
301
+		$this->import_icon[$r] = $this->picto;
302
+		$this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
303
+		$this->import_tables_array[$r] = array('p'=>MAIN_DB_PREFIX.'product', 'extra'=>MAIN_DB_PREFIX.'product_extrafields');
304
+		$this->import_tables_creator_array[$r] = array('p'=>'fk_user_author'); // Fields to store import user id
305
+		$this->import_fields_array[$r] = array(
306
+			'p.ref'=>"Ref*", 'p.label'=>"Label*", 'p.description'=>"Description", 'p.url'=>"PublicUrl", 'p.accountancy_code_sell'=>"ProductAccountancySellCode",
307
+			'p.accountancy_code_buy'=>"ProductAccountancyBuyCode", 'p.note'=>"Note", 'p.length'=>"Length", 'p.surface'=>"Surface", 'p.volume'=>"Volume",
308
+			'p.weight'=>"Weight", 'p.duration'=>"Duration", 'p.customcode'=>'CustomCode', 'p.price'=>"SellingPriceHT", 'p.price_ttc'=>"SellingPriceTTC",
309
+			'p.tva_tx'=>'VATRate', 'p.tosell'=>"OnSell*", 'p.tobuy'=>"OnBuy*", 'p.fk_product_type'=>"Type*", 'p.finished'=>'Nature', 'p.datec'=>'DateCreation'
310 310
 		);
311
-		if (! empty($conf->stock->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue'));
312
-		if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.cost_price'=>'CostPrice'));
313
-		if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.recuperableonly'=>'NPR'));
314
-		if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax1_tx'=>'LT1', 'p.localtax1_type'=>'LT1Type'));
315
-		if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax2_tx'=>'LT2', 'p.localtax2_type'=>'LT2Type'));
316
-		if (! empty($conf->barcode->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.barcode'=>'BarCode'));
317
-		if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->import_fields_array[$r]['p.fk_unit'] = 'Unit';
311
+		if (!empty($conf->stock->enabled)) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.seuil_stock_alerte'=>'StockLimit', 'p.desiredstock'=>'DesiredStock', 'p.pmp'=>'PMPValue'));
312
+		if (!empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.cost_price'=>'CostPrice'));
313
+		if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.recuperableonly'=>'NPR'));
314
+		if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.localtax1_tx'=>'LT1', 'p.localtax1_type'=>'LT1Type'));
315
+		if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.localtax2_tx'=>'LT2', 'p.localtax2_type'=>'LT2Type'));
316
+		if (!empty($conf->barcode->enabled)) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.barcode'=>'BarCode'));
317
+		if (!empty($conf->global->PRODUCT_USE_UNITS)) $this->import_fields_array[$r]['p.fk_unit'] = 'Unit';
318 318
 		// Add extra fields
319
-		$import_extrafield_sample=array();
320
-		$sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' AND entity IN (0, ".$conf->entity.")";
321
-		$resql=$this->db->query($sql);
319
+		$import_extrafield_sample = array();
320
+		$sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' AND entity IN (0, ".$conf->entity.")";
321
+		$resql = $this->db->query($sql);
322 322
 		if ($resql)    // This can fail when class is used on old database (during migration for example)
323 323
 		{
324
-		    while ($obj=$this->db->fetch_object($resql))
324
+		    while ($obj = $this->db->fetch_object($resql))
325 325
 		    {
326
-		        $fieldname='extra.'.$obj->name;
327
-		        $fieldlabel=ucfirst($obj->label);
328
-		        $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
329
-		        $import_extrafield_sample[$fieldname]=$fieldlabel;
326
+		        $fieldname = 'extra.'.$obj->name;
327
+		        $fieldlabel = ucfirst($obj->label);
328
+		        $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
329
+		        $import_extrafield_sample[$fieldname] = $fieldlabel;
330 330
 		    }
331 331
 		}
332 332
 		// End add extra fields
333
-		$this->import_fieldshidden_array[$r]=array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'product');    // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
334
-		$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]$','p.recuperableonly'=>'^[0|1]$');
335
-		$import_sample=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','p.recuperableonly'=>'0 or 1');
336
-		$this->import_examplevalues_array[$r]=array_merge($import_sample,$import_extrafield_sample);
337
-		$this->import_updatekeys_array[$r]=array('p.ref'=>'Ref','p.barcode'=>'BarCode');
333
+		$this->import_fieldshidden_array[$r] = array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'product'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
334
+		$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]$', 'p.recuperableonly'=>'^[0|1]$');
335
+		$import_sample = 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', 'p.recuperableonly'=>'0 or 1');
336
+		$this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
337
+		$this->import_updatekeys_array[$r] = array('p.ref'=>'Ref', 'p.barcode'=>'BarCode');
338 338
 
339
-		if (! empty($conf->fournisseur->enabled))
339
+		if (!empty($conf->fournisseur->enabled))
340 340
 		{
341 341
 			// Import suppliers prices (note: this code is duplicated into module service)
342 342
 			$r++;
343
-			$this->import_code[$r]=$this->rights_class.'_supplierprices';
344
-			$this->import_label[$r]="SuppliersPricesOfProductsOrServices";	// Translation key
345
-			$this->import_icon[$r]=$this->picto;
346
-			$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
347
-			$this->import_tables_array[$r]=array('sp'=>MAIN_DB_PREFIX.'product_fournisseur_price');
348
-			$this->import_tables_creator_array[$r]=array('sp'=>'fk_user');
349
-			$this->import_fields_array[$r]=array(
343
+			$this->import_code[$r] = $this->rights_class.'_supplierprices';
344
+			$this->import_label[$r] = "SuppliersPricesOfProductsOrServices"; // Translation key
345
+			$this->import_icon[$r] = $this->picto;
346
+			$this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
347
+			$this->import_tables_array[$r] = array('sp'=>MAIN_DB_PREFIX.'product_fournisseur_price');
348
+			$this->import_tables_creator_array[$r] = array('sp'=>'fk_user');
349
+			$this->import_fields_array[$r] = array(
350 350
 					'sp.fk_product'=>"ProductOrService*",
351 351
 					'sp.fk_soc'=>"Supplier*", 'sp.ref_fourn'=>'SupplierRef', 'sp.quantity'=>"QtyMin*", 'sp.tva_tx'=>'VATRate', 'sp.default_vat_code'=>'VATCode'
352 352
 			);
353
-			if (is_object($mysoc) && $mysoc->useNPR())       $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.recuperableonly'=>'VATNPR'));
354
-			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'));
355
-			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'));
356
-			$this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array(
353
+			if (is_object($mysoc) && $mysoc->useNPR())       $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('sp.recuperableonly'=>'VATNPR'));
354
+			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'));
355
+			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'));
356
+			$this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array(
357 357
 					'sp.price'=>"PriceQtyMinHT*",
358
-					'sp.unitprice'=>'UnitPriceHT*',	// TODO Make this field not required and calculate it from price and qty
358
+					'sp.unitprice'=>'UnitPriceHT*', // TODO Make this field not required and calculate it from price and qty
359 359
 					'sp.remise_percent'=>'DiscountQtyMin'
360 360
 			));
361
-			$this->import_convertvalue_array[$r]=array(
362
-					'sp.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'),
363
-					'sp.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'Product')
361
+			$this->import_convertvalue_array[$r] = array(
362
+					'sp.fk_soc'=>array('rule'=>'fetchidfromref', 'classfile'=>'/societe/class/societe.class.php', 'class'=>'Societe', 'method'=>'fetch', 'element'=>'ThirdParty'),
363
+					'sp.fk_product'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/class/product.class.php', 'class'=>'Product', 'method'=>'fetch', 'element'=>'Product')
364 364
 			);
365
-			$this->import_examplevalues_array[$r]=array('sp.fk_product'=>"PREF123456",
366
-					'sp.fk_soc'=>"My Supplier",'sp.ref_fourn'=>"SupplierRef", 'sp.quantity'=>"1", 'sp.tva_tx'=>'21',
365
+			$this->import_examplevalues_array[$r] = array('sp.fk_product'=>"PREF123456",
366
+					'sp.fk_soc'=>"My Supplier", 'sp.ref_fourn'=>"SupplierRef", 'sp.quantity'=>"1", 'sp.tva_tx'=>'21',
367 367
 					'sp.price'=>"50",
368 368
 					'sp.unitprice'=>'50',
369 369
 					'sp.remise_percent'=>'0'
370 370
 			);
371
-			$this->import_updatekeys_array[$r]=array('sp.fk_product'=>'ProductOrService','sp.ref_fourn'=>'SupplierRef','sp.fk_soc'=>'Supplier');
371
+			$this->import_updatekeys_array[$r] = array('sp.fk_product'=>'ProductOrService', 'sp.ref_fourn'=>'SupplierRef', 'sp.fk_soc'=>'Supplier');
372 372
 		}
373 373
 
374
-		if (! empty($conf->global->PRODUIT_MULTIPRICES))
374
+		if (!empty($conf->global->PRODUIT_MULTIPRICES))
375 375
 		{
376 376
 			// Import product multiprice
377 377
 			$r++;
378
-			$this->import_code[$r]=$this->rights_class.'_multiprice';
379
-			$this->import_label[$r]="ProductsOrServiceMultiPrice";	// Translation key
380
-			$this->import_icon[$r]=$this->picto;
381
-			$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
382
-			$this->import_tables_array[$r]=array('pr'=>MAIN_DB_PREFIX.'product_price');
383
-			$this->import_tables_creator_array[$r]=array('pr'=>'fk_user_author');	// Fields to store import user id
384
-			$this->import_fields_array[$r]=array('pr.fk_product'=>"ProductRowid*",
385
-				'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel",
386
-				'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
387
-				'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
378
+			$this->import_code[$r] = $this->rights_class.'_multiprice';
379
+			$this->import_label[$r] = "ProductsOrServiceMultiPrice"; // Translation key
380
+			$this->import_icon[$r] = $this->picto;
381
+			$this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
382
+			$this->import_tables_array[$r] = array('pr'=>MAIN_DB_PREFIX.'product_price');
383
+			$this->import_tables_creator_array[$r] = array('pr'=>'fk_user_author'); // Fields to store import user id
384
+			$this->import_fields_array[$r] = array('pr.fk_product'=>"ProductRowid*",
385
+				'pr.price_base_type'=>"PriceLevelPriceBase", 'pr.price_level'=>"PriceLevel",
386
+				'pr.price'=>"PriceLevelUnitPriceHT", 'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
387
+				'pr.price_min'=>"MinPriceLevelUnitPriceHT", 'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
388 388
 				'pr.tva_tx'=>'PriceLevelVATRate',
389 389
 				'pr.date_price'=>'DateCreation*');
390
-			if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('pr.recuperableonly'=>'NPR'));
391
-			$this->import_regex_array[$r]=array('pr.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','pr.recuperableonly'=>'^[0|1]$');
392
-			$this->import_examplevalues_array[$r]=array('pr.fk_product'=>"1",
393
-				'pr.price_base_type'=>"HT",'pr.price_level'=>"1",
394
-				'pr.price'=>"100",'pr.price_ttc'=>"110",
395
-				'pr.price_min'=>"100",'pr.price_min_ttc'=>"110",
390
+			if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('pr.recuperableonly'=>'NPR'));
391
+			$this->import_regex_array[$r] = array('pr.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$', 'pr.recuperableonly'=>'^[0|1]$');
392
+			$this->import_examplevalues_array[$r] = array('pr.fk_product'=>"1",
393
+				'pr.price_base_type'=>"HT", 'pr.price_level'=>"1",
394
+				'pr.price'=>"100", 'pr.price_ttc'=>"110",
395
+				'pr.price_min'=>"100", 'pr.price_min_ttc'=>"110",
396 396
 				'pr.tva_tx'=>'20',
397 397
 			    'pr.recuperableonly'=>'0',
398 398
 				'pr.date_price'=>'2013-04-10');
399 399
 		}
400 400
 
401
-		if (! empty($conf->global->MAIN_MULTILANGS))
401
+		if (!empty($conf->global->MAIN_MULTILANGS))
402 402
 		{
403 403
 		    $r++;
404
-		    $this->import_code[$r]=$this->rights_class.'_languages';
405
-		    $this->import_label[$r]="ProductsOrServicesTranslations";
406
-			$this->import_icon[$r]=$this->picto;
407
-			$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
408
-		    $this->import_tables_array[$r]=array('l'=>MAIN_DB_PREFIX.'product_lang');
404
+		    $this->import_code[$r] = $this->rights_class.'_languages';
405
+		    $this->import_label[$r] = "ProductsOrServicesTranslations";
406
+			$this->import_icon[$r] = $this->picto;
407
+			$this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
408
+		    $this->import_tables_array[$r] = array('l'=>MAIN_DB_PREFIX.'product_lang');
409 409
 			// multiline translation, one line per translation
410
-			$this->import_fields_array[$r]=array('l.fk_product'=>'Ref', 'l.lang'=>'Language', 'l.label'=>'TranslatedLabel', 'l.description'=>'TranslatedDescription');
410
+			$this->import_fields_array[$r] = array('l.fk_product'=>'Ref', 'l.lang'=>'Language', 'l.label'=>'TranslatedLabel', 'l.description'=>'TranslatedDescription');
411 411
 			//$this->import_fields_array[$r]['l.note']='TranslatedNote';
412
-			$this->import_convertvalue_array[$r]=array(
413
-					'l.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'Product')
412
+			$this->import_convertvalue_array[$r] = array(
413
+					'l.fk_product'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/class/product.class.php', 'class'=>'Product', 'method'=>'fetch', 'element'=>'Product')
414 414
 			);
415
-			$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');
416
-			$this->import_updatekeys_array[$r]=array('l.fk_product'=>'Ref','l.lang'=>'Language');
415
+			$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');
416
+			$this->import_updatekeys_array[$r] = array('l.fk_product'=>'Ref', 'l.lang'=>'Language');
417 417
 		}
418 418
 	}
419 419
 
@@ -426,12 +426,12 @@  discard block
 block discarded – undo
426 426
      *      @param      string	$options    Options when enabling module ('', 'newboxdefonly', 'noboxes')
427 427
 	 *      @return     int             	1 if OK, 0 if KO
428 428
 	 */
429
-	function init($options='')
429
+	function init($options = '')
430 430
 	{
431 431
 		$this->remove($options);
432 432
 
433 433
 		$sql = array();
434 434
 
435
-		return $this->_init($sql,$options);
435
+		return $this->_init($sql, $options);
436 436
 	}
437 437
 }
Please login to merge, or discard this patch.
Braces   +127 added lines, -42 removed lines patch added patch discarded remove patch
@@ -173,42 +173,89 @@  discard block
 block discarded – undo
173 173
 			'p.volume'=>"Volume",'p.weight'=>"Weight",'p.customcode'=>'CustomCode','p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC",
174 174
 			'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell",'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification'
175 175
 		);
176
-		if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['p.recuperableonly']='NPR';
177
-		if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue'));
178
-		if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode'));
179
-		if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.cost_price'=>'CostPrice'));
176
+		if (is_object($mysoc) && $mysoc->useNPR()) {
177
+		    $this->export_fields_array[$r]['p.recuperableonly']='NPR';
178
+		}
179
+		if (! empty($conf->stock->enabled)) {
180
+		    $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue'));
181
+		}
182
+		if (! empty($conf->barcode->enabled)) {
183
+		    $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode'));
184
+		}
185
+		if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) {
186
+		    $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.cost_price'=>'CostPrice'));
187
+		}
180 188
 		$keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra';
181 189
 		include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
182
-		if (! empty($conf->fournisseur->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('s.nom'=>'Supplier','pf.ref_fourn'=>'SupplierRef','pf.quantity'=>'QtyMin','pf.remise_percent'=>'DiscountQtyMin','pf.unitprice'=>'BuyingPrice','pf.delivery_time_days'=>'NbDaysToDelivery'));
183
-		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('group_concat(cat.label)'=>'Categories'));
184
-		if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('l.lang'=>'Language', 'l.label'=>'TranslatedLabel','l.description'=>'TranslatedDescription','l.note'=>'TranslatedNote'));
185
-		if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->export_fields_array[$r]['p.fk_unit'] = 'Unit';
190
+		if (! empty($conf->fournisseur->enabled)) {
191
+		    $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('s.nom'=>'Supplier','pf.ref_fourn'=>'SupplierRef','pf.quantity'=>'QtyMin','pf.remise_percent'=>'DiscountQtyMin','pf.unitprice'=>'BuyingPrice','pf.delivery_time_days'=>'NbDaysToDelivery'));
192
+		}
193
+		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) {
194
+		    $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('group_concat(cat.label)'=>'Categories'));
195
+		}
196
+		if (! empty($conf->global->MAIN_MULTILANGS)) {
197
+		    $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('l.lang'=>'Language', 'l.label'=>'TranslatedLabel','l.description'=>'TranslatedDescription','l.note'=>'TranslatedNote'));
198
+		}
199
+		if (! empty($conf->global->PRODUCT_USE_UNITS)) {
200
+		    $this->export_fields_array[$r]['p.fk_unit'] = 'Unit';
201
+		}
186 202
 		$this->export_TypeFields_array[$r]=array(
187 203
 			'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
188 204
 			'p.note'=>"Text",'p.length'=>"Numeric",'p.width'=>"Numeric",'p.height'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",
189 205
 			'p.customcode'=>'Text','p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",
190 206
 			'p.tobuy'=>"Boolean",'p.datec'=>'Date','p.tms'=>'Date'
191 207
 		);
192
-		if (! empty($conf->stock->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric'));
193
-		if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text'));
194
-		if (! empty($conf->fournisseur->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('s.nom'=>'Text','pf.ref_fourn'=>'Text','pf.unitprice'=>'Numeric','pf.quantity'=>'Numeric','pf.remise_percent'=>'Numeric','pf.delivery_time_days'=>'Numeric'));
195
-		if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('l.lang'=>'Text', 'l.label'=>'Text','l.description'=>'Text','l.note'=>'Text'));
196
-		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array("group_concat(cat.label)"=>'Text'));
208
+		if (! empty($conf->stock->enabled)) {
209
+		    $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric'));
210
+		}
211
+		if (! empty($conf->barcode->enabled)) {
212
+		    $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text'));
213
+		}
214
+		if (! empty($conf->fournisseur->enabled)) {
215
+		    $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('s.nom'=>'Text','pf.ref_fourn'=>'Text','pf.unitprice'=>'Numeric','pf.quantity'=>'Numeric','pf.remise_percent'=>'Numeric','pf.delivery_time_days'=>'Numeric'));
216
+		}
217
+		if (! empty($conf->global->MAIN_MULTILANGS)) {
218
+		    $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('l.lang'=>'Text', 'l.label'=>'Text','l.description'=>'Text','l.note'=>'Text'));
219
+		}
220
+		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) {
221
+		    $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array("group_concat(cat.label)"=>'Text'));
222
+		}
197 223
 		$this->export_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
198
-		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array("group_concat(cat.label)"=>'category'));
199
-		if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'product','p.pmp'=>'product'));
200
-		if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'product'));
201
-		if (! empty($conf->fournisseur->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('s.nom'=>'product_supplier_ref','pf.ref_fourn'=>'product_supplier_ref','pf.unitprice'=>'product_supplier_ref','pf.quantity'=>'product_supplier_ref','pf.remise_percent'=>'product_supplier_ref','pf.delivery_time_days'=>'product_supplier_ref'));
202
-		if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('l.lang'=>'translation', 'l.label'=>'translation','l.description'=>'translation','l.note'=>'translation'));
203
-		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_dependencies_array[$r]=array('category'=>'p.rowid');
224
+		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) {
225
+		    $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array("group_concat(cat.label)"=>'category'));
226
+		}
227
+		if (! empty($conf->stock->enabled)) {
228
+		    $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'product','p.pmp'=>'product'));
229
+		}
230
+		if (! empty($conf->barcode->enabled)) {
231
+		    $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'product'));
232
+		}
233
+		if (! empty($conf->fournisseur->enabled)) {
234
+		    $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('s.nom'=>'product_supplier_ref','pf.ref_fourn'=>'product_supplier_ref','pf.unitprice'=>'product_supplier_ref','pf.quantity'=>'product_supplier_ref','pf.remise_percent'=>'product_supplier_ref','pf.delivery_time_days'=>'product_supplier_ref'));
235
+		}
236
+		if (! empty($conf->global->MAIN_MULTILANGS)) {
237
+		    $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('l.lang'=>'translation', 'l.label'=>'translation','l.description'=>'translation','l.note'=>'translation'));
238
+		}
239
+		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) {
240
+		    $this->export_dependencies_array[$r]=array('category'=>'p.rowid');
241
+		}
204 242
 		$this->export_sql_start[$r]='SELECT DISTINCT ';
205 243
 		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p';
206
-		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'categorie as cat ON cp.fk_categorie = cat.rowid';
207
-		if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_lang as l ON l.fk_product = p.rowid';
244
+		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) {
245
+		    $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'categorie as cat ON cp.fk_categorie = cat.rowid';
246
+		}
247
+		if (! empty($conf->global->MAIN_MULTILANGS)) {
248
+		    $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_lang as l ON l.fk_product = p.rowid';
249
+		}
208 250
 		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object';
209
-		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';
251
+		if (! empty($conf->fournisseur->enabled)) {
252
+		    $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';
253
+		}
210 254
 		$this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
211
-		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_order[$r] =' GROUP BY p.rowid'; 	// FIXME The group by used a generic value to say "all fields in select except function fields"
255
+		if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) {
256
+		    $this->export_sql_order[$r] =' GROUP BY p.rowid';
257
+		}
258
+		// FIXME The group by used a generic value to say "all fields in select except function fields"
212 259
 
213 260
 		if (! empty($conf->global->PRODUIT_MULTIPRICES))
214 261
 		{
@@ -223,7 +270,9 @@  discard block
 block discarded – undo
223 270
 				'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
224 271
 				'pr.tva_tx'=>'PriceLevelVATRate',
225 272
 				'pr.date_price'=>'DateCreation');
226
-			if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['pr.recuperableonly']='NPR';
273
+			if (is_object($mysoc) && $mysoc->useNPR()) {
274
+			    $this->export_fields_array[$r]['pr.recuperableonly']='NPR';
275
+			}
227 276
 			//$this->export_TypeFields_array[$r]=array(
228 277
 			//	'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
229 278
 			//	'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text',
@@ -257,8 +306,12 @@  discard block
 block discarded – undo
257 306
 				'p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC",'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell",
258 307
 				'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification'
259 308
 			);
260
-    		if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue'));
261
-    		if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode'));
309
+    		if (! empty($conf->stock->enabled)) {
310
+    		    $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue'));
311
+    		}
312
+    		if (! empty($conf->barcode->enabled)) {
313
+    		    $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode'));
314
+    		}
262 315
     		$this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('pa.qty'=>'Qty','pa.incdec'=>'ComposedProductIncDecStock'));
263 316
     		$this->export_TypeFields_array[$r]=array(
264 317
 				'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
@@ -266,8 +319,12 @@  discard block
 block discarded – undo
266 319
 				'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",
267 320
 				'p.datec'=>'Date','p.tms'=>'Date'
268 321
 			);
269
-    		if (! empty($conf->stock->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric'));
270
-    		if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text'));
322
+    		if (! empty($conf->stock->enabled)) {
323
+    		    $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric'));
324
+    		}
325
+    		if (! empty($conf->barcode->enabled)) {
326
+    		    $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text'));
327
+    		}
271 328
     		$this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('pa.qty'=>'Numeric'));
272 329
     		$this->export_entities_array[$r]=array(
273 330
 				'p.rowid'=>"virtualproduct",'p.ref'=>"virtualproduct",'p.label'=>"virtualproduct",'p.description'=>"virtualproduct",'p.url'=>"virtualproduct",
@@ -276,8 +333,12 @@  discard block
 block discarded – undo
276 333
 				'p.price_base_type'=>"virtualproduct",'p.price'=>"virtualproduct",'p.price_ttc'=>"virtualproduct",'p.tva_tx'=>"virtualproduct",
277 334
 				'p.tosell'=>"virtualproduct",'p.tobuy'=>"virtualproduct",'p.datec'=>"virtualproduct",'p.tms'=>"virtualproduct"
278 335
 			);
279
-    		if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'virtualproduct','p.seuil_stock_alerte'=>'virtualproduct','p.desiredstock'=>'virtualproduct','p.pmp'=>'virtualproduct'));
280
-    		if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'virtualproduct'));
336
+    		if (! empty($conf->stock->enabled)) {
337
+    		    $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'virtualproduct','p.seuil_stock_alerte'=>'virtualproduct','p.desiredstock'=>'virtualproduct','p.pmp'=>'virtualproduct'));
338
+    		}
339
+    		if (! empty($conf->barcode->enabled)) {
340
+    		    $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'virtualproduct'));
341
+    		}
281 342
             $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('pa.qty'=>"subproduct",'pa.incdec'=>'subproduct'));
282 343
     		$keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra';
283 344
     		include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
@@ -308,22 +369,38 @@  discard block
 block discarded – undo
308 369
 			'p.weight'=>"Weight",'p.duration'=>"Duration",'p.customcode'=>'CustomCode','p.price'=>"SellingPriceHT",'p.price_ttc'=>"SellingPriceTTC",
309 370
 			'p.tva_tx'=>'VATRate', 'p.tosell'=>"OnSell*",'p.tobuy'=>"OnBuy*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.datec'=>'DateCreation'
310 371
 		);
311
-		if (! empty($conf->stock->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue'));
312
-		if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.cost_price'=>'CostPrice'));
313
-		if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.recuperableonly'=>'NPR'));
314
-		if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax1_tx'=>'LT1', 'p.localtax1_type'=>'LT1Type'));
315
-		if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax2_tx'=>'LT2', 'p.localtax2_type'=>'LT2Type'));
316
-		if (! empty($conf->barcode->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.barcode'=>'BarCode'));
317
-		if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->import_fields_array[$r]['p.fk_unit'] = 'Unit';
372
+		if (! empty($conf->stock->enabled)) {
373
+		    $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue'));
374
+		}
375
+		if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) {
376
+		    $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.cost_price'=>'CostPrice'));
377
+		}
378
+		if (is_object($mysoc) && $mysoc->useNPR()) {
379
+		    $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.recuperableonly'=>'NPR'));
380
+		}
381
+		if (is_object($mysoc) && $mysoc->useLocalTax(1)) {
382
+		    $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax1_tx'=>'LT1', 'p.localtax1_type'=>'LT1Type'));
383
+		}
384
+		if (is_object($mysoc) && $mysoc->useLocalTax(2)) {
385
+		    $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax2_tx'=>'LT2', 'p.localtax2_type'=>'LT2Type'));
386
+		}
387
+		if (! empty($conf->barcode->enabled)) {
388
+		    $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.barcode'=>'BarCode'));
389
+		}
390
+		if (! empty($conf->global->PRODUCT_USE_UNITS)) {
391
+		    $this->import_fields_array[$r]['p.fk_unit'] = 'Unit';
392
+		}
318 393
 		// Add extra fields
319 394
 		$import_extrafield_sample=array();
320 395
 		$sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' AND entity IN (0, ".$conf->entity.")";
321 396
 		$resql=$this->db->query($sql);
322
-		if ($resql)    // This can fail when class is used on old database (during migration for example)
397
+		if ($resql) {
398
+		    // This can fail when class is used on old database (during migration for example)
323 399
 		{
324 400
 		    while ($obj=$this->db->fetch_object($resql))
325 401
 		    {
326 402
 		        $fieldname='extra.'.$obj->name;
403
+		}
327 404
 		        $fieldlabel=ucfirst($obj->label);
328 405
 		        $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
329 406
 		        $import_extrafield_sample[$fieldname]=$fieldlabel;
@@ -350,9 +427,15 @@  discard block
 block discarded – undo
350 427
 					'sp.fk_product'=>"ProductOrService*",
351 428
 					'sp.fk_soc'=>"Supplier*", 'sp.ref_fourn'=>'SupplierRef', 'sp.quantity'=>"QtyMin*", 'sp.tva_tx'=>'VATRate', 'sp.default_vat_code'=>'VATCode'
352 429
 			);
353
-			if (is_object($mysoc) && $mysoc->useNPR())       $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.recuperableonly'=>'VATNPR'));
354
-			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'));
355
-			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'));
430
+			if (is_object($mysoc) && $mysoc->useNPR()) {
431
+			    $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.recuperableonly'=>'VATNPR'));
432
+			}
433
+			if (is_object($mysoc) && $mysoc->useLocalTax(1)) {
434
+			    $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.localtax1_tx'=>'LT1', 'sp.localtax1_type'=>'LT1Type'));
435
+			}
436
+			if (is_object($mysoc) && $mysoc->useLocalTax(2)) {
437
+			    $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.localtax2_tx'=>'LT2', 'sp.localtax2_type'=>'LT2Type'));
438
+			}
356 439
 			$this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array(
357 440
 					'sp.price'=>"PriceQtyMinHT*",
358 441
 					'sp.unitprice'=>'UnitPriceHT*',	// TODO Make this field not required and calculate it from price and qty
@@ -387,7 +470,9 @@  discard block
 block discarded – undo
387 470
 				'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
388 471
 				'pr.tva_tx'=>'PriceLevelVATRate',
389 472
 				'pr.date_price'=>'DateCreation*');
390
-			if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('pr.recuperableonly'=>'NPR'));
473
+			if (is_object($mysoc) && $mysoc->useNPR()) {
474
+			    $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('pr.recuperableonly'=>'NPR'));
475
+			}
391 476
 			$this->import_regex_array[$r]=array('pr.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','pr.recuperableonly'=>'^[0|1]$');
392 477
 			$this->import_examplevalues_array[$r]=array('pr.fk_product'=>"1",
393 478
 				'pr.price_base_type'=>"HT",'pr.price_level'=>"1",
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/stock/modules_stock.php 2 patches
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.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
     /**
27 27
 	 * @var string Error code (or message)
28 28
 	 */
29
-	public $error='';
29
+	public $error = '';
30 30
 
31 31
 
32 32
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -37,16 +37,16 @@  discard block
 block discarded – undo
37 37
      *  @param	integer		$maxfilenamelength  Max length of value to show
38 38
      * 	@return	array							List of templates
39 39
      */
40
-    static function liste_modeles($db,$maxfilenamelength=0)
40
+    static function liste_modeles($db, $maxfilenamelength = 0)
41 41
     {
42 42
         // phpcs:enable
43 43
         global $conf;
44 44
 
45
-        $type='stock';
46
-        $liste=array();
45
+        $type = 'stock';
46
+        $liste = array();
47 47
 
48 48
         include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
49
-        $liste=getListOfModels($db,$type,$maxfilenamelength);
49
+        $liste = getListOfModels($db, $type, $maxfilenamelength);
50 50
 
51 51
         return $liste;
52 52
     }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/stock/doc/doc_generic_stock_odt.modules.php 3 patches
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.
Spacing   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -66,37 +66,37 @@  discard block
 block discarded – undo
66 66
 		global $conf, $langs, $mysoc;
67 67
 
68 68
 		// Load translation files required by the page
69
-        $langs->loadLangs(array("main","companies"));
69
+        $langs->loadLangs(array("main", "companies"));
70 70
 
71 71
 		$this->db = $db;
72 72
 		$this->name = "ODT templates";
73 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
74
+		$this->scandir = 'STOCK_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan
75 75
 
76 76
 		// Dimension page pour format A4
77 77
 		$this->type = 'odt';
78 78
 		$this->page_largeur = 0;
79 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
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 96
 
97 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
98
+		$this->emetteur = $mysoc;
99
+		if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
100 100
 	}
101 101
 
102 102
 
@@ -111,60 +111,60 @@  discard block
 block discarded – undo
111 111
 		global $conf, $langs;
112 112
 
113 113
 		// Load translation files required by the page
114
-        $langs->loadLangs(array("errors","companies"));
114
+        $langs->loadLangs(array("errors", "companies"));
115 115
 
116 116
 		$form = new Form($this->db);
117 117
 
118 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">';
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 123
 		if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0)
124 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">';
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 128
 		}
129
-		$texte.= '<table class="nobordernopadding" width="100%">';
129
+		$texte .= '<table class="nobordernopadding" width="100%">';
130 130
 
131 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)
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 137
 		{
138
-			$tmpdir=trim($tmpdir);
139
-			$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
140
-			if (! $tmpdir) {
138
+			$tmpdir = trim($tmpdir);
139
+			$tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
140
+			if (!$tmpdir) {
141 141
 				unset($listofdir[$key]); continue;
142 142
 			}
143
-			if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
143
+			if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0);
144 144
 			else
145 145
 			{
146
-				$tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
147
-				if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
146
+				$tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)');
147
+				if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles);
148 148
 			}
149 149
 		}
150
-		$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
150
+		$texthelp = $langs->trans("ListOfDirectoriesForModelGenODT");
151 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>';
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 163
 
164 164
 		// Scan directories
165 165
 		if (count($listofdir))
166 166
 		{
167
-			$texte.=$langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>';
167
+			$texte .= $langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>';
168 168
 
169 169
 			/*if ($conf->global->MAIN_STOCK_CHOOSE_ODT_DOCUMENT > 0)
170 170
 			{
@@ -192,15 +192,15 @@  discard block
 block discarded – undo
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 205
 		return $texte;
206 206
 	}
@@ -217,10 +217,10 @@  discard block
 block discarded – undo
217 217
 	 *  @param		int			$hideref			Do not show ref
218 218
 	 *	@return		int         					1 if OK, <=0 if KO
219 219
 	 */
220
-	function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
220
+	function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
221 221
 	{
222 222
         // phpcs:enable
223
-		global $stock,$langs,$conf,$mysoc,$hookmanager,$user;
223
+		global $stock, $langs, $conf, $mysoc, $hookmanager, $user;
224 224
 
225 225
 		if (empty($srctemplatepath))
226 226
 		{
@@ -229,17 +229,17 @@  discard block
 block discarded – undo
229 229
 		}
230 230
 
231 231
 		// Add odtgeneration hook
232
-		if (! is_object($hookmanager))
232
+		if (!is_object($hookmanager))
233 233
 		{
234 234
 			include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
235
-			$hookmanager=new HookManager($this->db);
235
+			$hookmanager = new HookManager($this->db);
236 236
 		}
237 237
 		$hookmanager->initHooks(array('odtgeneration'));
238 238
 		global $action;
239 239
 
240
-		if (! is_object($outputlangs)) $outputlangs=$langs;
241
-		$sav_charset_output=$outputlangs->charset_output;
242
-		$outputlangs->charset_output='UTF-8';
240
+		if (!is_object($outputlangs)) $outputlangs = $langs;
241
+		$sav_charset_output = $outputlangs->charset_output;
242
+		$outputlangs->charset_output = 'UTF-8';
243 243
 
244 244
 		// Load translation files required by the page
245 245
 		$outputlangs->loadLangs(array("main", "dict", "companies", "bills"));
@@ -247,14 +247,14 @@  discard block
 block discarded – undo
247 247
 		if ($conf->produit->dir_output)
248 248
 		{
249 249
 			// If $object is id instead of object
250
-			if (! is_object($object))
250
+			if (!is_object($object))
251 251
 			{
252 252
 				$id = $object;
253 253
 				$object = new Stock($this->db);
254
-				$result=$object->fetch($id);
254
+				$result = $object->fetch($id);
255 255
 				if ($result < 0)
256 256
 				{
257
-					dol_print_error($this->db,$object->error);
257
+					dol_print_error($this->db, $object->error);
258 258
 					return -1;
259 259
 				}
260 260
 			}
@@ -264,14 +264,14 @@  discard block
 block discarded – undo
264 264
 
265 265
 			$dir = $conf->produit->dir_output;
266 266
 			$objectref = dol_sanitizeFileName($object->ref);
267
-			if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
268
-			$file = $dir . "/" . $objectref . ".odt";
267
+			if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref;
268
+			$file = $dir."/".$objectref.".odt";
269 269
 
270
-			if (! file_exists($dir))
270
+			if (!file_exists($dir))
271 271
 			{
272 272
 				if (dol_mkdir($dir) < 0)
273 273
 				{
274
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
274
+					$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
275 275
 					return -1;
276 276
 				}
277 277
 			}
@@ -279,26 +279,26 @@  discard block
 block discarded – undo
279 279
 			if (file_exists($dir))
280 280
 			{
281 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);
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 286
 
287
-				$newfiletmp=$objectref.'_'.$newfiletmp;
287
+				$newfiletmp = $objectref.'_'.$newfiletmp;
288 288
 
289 289
 				// Get extension (ods or odt)
290
-				$newfileformat=substr($newfile, strrpos($newfile, '.')+1);
291
-				if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
290
+				$newfileformat = substr($newfile, strrpos($newfile, '.') + 1);
291
+				if (!empty($conf->global->MAIN_DOC_USE_TIMING))
292 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;
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 296
 				}
297 297
 				else
298 298
 				{
299
-					$filename=$newfiletmp.'.'.$newfileformat;
299
+					$filename = $newfiletmp.'.'.$newfileformat;
300 300
 				}
301
-				$file=$dir.'/'.$filename;
301
+				$file = $dir.'/'.$filename;
302 302
 				//print "newdir=".$dir;
303 303
 				//print "newfile=".$newfile;
304 304
 				//print "file=".$file;
@@ -308,20 +308,20 @@  discard block
 block discarded – undo
308 308
 
309 309
 
310 310
 				// If CUSTOMER contact defined on stock, we use it
311
-				$usecontact=false;
312
-				$arrayidcontact=$object->getIdContact('external','CUSTOMER');
311
+				$usecontact = false;
312
+				$arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
313 313
 				if (count($arrayidcontact) > 0)
314 314
 				{
315
-					$usecontact=true;
316
-					$result=$object->fetch_contact($arrayidcontact[0]);
315
+					$usecontact = true;
316
+					$result = $object->fetch_contact($arrayidcontact[0]);
317 317
 				}
318 318
 
319 319
 				// Recipient name
320
-				$contactobject=null;
321
-				if (! empty($usecontact))
320
+				$contactobject = null;
321
+				if (!empty($usecontact))
322 322
 				{
323 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;
324
+					if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
325 325
 					else {
326 326
                         			$socobject = $object->thirdparty;
327 327
                         			// if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use
@@ -330,10 +330,10 @@  discard block
 block discarded – undo
330 330
 				}
331 331
 				else
332 332
 				{
333
-					$socobject=$object->thirdparty;
333
+					$socobject = $object->thirdparty;
334 334
 				}
335 335
 				// Make substitution
336
-				$substitutionarray=array(
336
+				$substitutionarray = array(
337 337
 				'__FROM_NAME__' => $this->emetteur->name,
338 338
 				'__FROM_EMAIL__' => $this->emetteur->email,
339 339
 				'__TOTAL_TTC__' => $object->total_ttc,
@@ -342,15 +342,15 @@  discard block
 block discarded – undo
342 342
 				);
343 343
 				complete_substitutions_array($substitutionarray, $langs, $object);
344 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
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 347
 
348 348
 				// Line of free text
349
-				$newfreetext='';
350
-				$paramfreetext='stock_FREE_TEXT';
351
-				if (! empty($conf->global->$paramfreetext))
349
+				$newfreetext = '';
350
+				$paramfreetext = 'stock_FREE_TEXT';
351
+				if (!empty($conf->global->$paramfreetext))
352 352
 				{
353
-					$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
353
+					$newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray);
354 354
 				}
355 355
 
356 356
 				// Open and load template
@@ -360,15 +360,15 @@  discard block
 block discarded – undo
360 360
 						$srctemplatepath,
361 361
 						array(
362 362
 						'PATH_TO_TMP'	  => $conf->produit->dir_temp,
363
-						'ZIP_PROXY'		  => 'PclZipProxy',	// PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
363
+						'ZIP_PROXY'		  => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
364 364
 						'DELIMITER_LEFT'  => '{',
365 365
 						'DELIMITER_RIGHT' => '}'
366 366
 						)
367 367
 					);
368 368
 				}
369
-				catch(Exception $e)
369
+				catch (Exception $e)
370 370
 				{
371
-					$this->error=$e->getMessage();
371
+					$this->error = $e->getMessage();
372 372
 					dol_syslog($e->getMessage(), LOG_INFO);
373 373
 					return -1;
374 374
 				}
@@ -393,25 +393,25 @@  discard block
 block discarded – undo
393 393
 				$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
394 394
 				$array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs);
395 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);
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 400
 				// retrieve contact information for use in stock as contact_xxx tags
401 401
 				$array_thirdparty_contact = array();
402
-				if ($usecontact && is_object($contactobject)) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
402
+				if ($usecontact && is_object($contactobject)) $array_thirdparty_contact = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact');
403 403
 
404
-				$tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_other,$array_thirdparty_contact);
404
+				$tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_other, $array_thirdparty_contact);
405 405
 				complete_substitutions_array($tmparray, $outputlangs, $object);
406 406
 
407 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
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 410
 
411
-				foreach($tmparray as $key=>$value)
411
+				foreach ($tmparray as $key=>$value)
412 412
 				{
413 413
 					try {
414
-						if (preg_match('/logo$/',$key)) // Image
414
+						if (preg_match('/logo$/', $key)) // Image
415 415
 						{
416 416
 							if (file_exists($value)) $odfHandler->setImage($key, $value);
417 417
 							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
@@ -430,25 +430,25 @@  discard block
 block discarded – undo
430 430
 				try
431 431
 				{
432 432
 					$listlines = $odfHandler->setSegment('supplierprices');
433
-					if(!empty($object->supplierprices)){
433
+					if (!empty($object->supplierprices)) {
434 434
 						foreach ($object->supplierprices as $supplierprice)
435 435
 						{
436 436
 							$array_lines = $this->get_substitutionarray_each_var_object($supplierprice, $outputlangs);
437 437
 							complete_substitutions_array($array_lines, $outputlangs, $object, $supplierprice, "completesubstitutionarray_lines");
438 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)
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 442
 							{
443 443
 								try
444 444
 								{
445 445
 									$listlines->setVars($key, $val, true, 'UTF-8');
446 446
 								}
447
-								catch(OdfException $e)
447
+								catch (OdfException $e)
448 448
 								{
449 449
 									dol_syslog($e->getMessage(), LOG_INFO);
450 450
 								}
451
-								catch(SegmentException $e)
451
+								catch (SegmentException $e)
452 452
 								{
453 453
 									dol_syslog($e->getMessage(), LOG_INFO);
454 454
 								}
@@ -458,36 +458,36 @@  discard block
 block discarded – undo
458 458
 					}
459 459
 					$odfHandler->mergeSegment($listlines);
460 460
 				}
461
-				catch(OdfException $e)
461
+				catch (OdfException $e)
462 462
 				{
463
-					$this->error=$e->getMessage();
463
+					$this->error = $e->getMessage();
464 464
 					dol_syslog($this->error, LOG_WARNING);
465 465
 					return -1;
466 466
 				}
467 467
 
468 468
 				// Replace labels translated
469
-				$tmparray=$outputlangs->get_translations_for_substitutions();
470
-				foreach($tmparray as $key=>$value)
469
+				$tmparray = $outputlangs->get_translations_for_substitutions();
470
+				foreach ($tmparray as $key=>$value)
471 471
 				{
472 472
 					try {
473 473
 						$odfHandler->setVars($key, $value, true, 'UTF-8');
474 474
 					}
475
-					catch(OdfException $e)
475
+					catch (OdfException $e)
476 476
 					{
477 477
                         dol_syslog($e->getMessage(), LOG_INFO);
478 478
 					}
479 479
 				}
480 480
 
481 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
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 484
 
485 485
 				// Write new file
486 486
 				if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
487 487
 					try {
488 488
 						$odfHandler->exportAsAttachedPDF($file);
489 489
 					} catch (Exception $e) {
490
-						$this->error=$e->getMessage();
490
+						$this->error = $e->getMessage();
491 491
                         dol_syslog($e->getMessage(), LOG_INFO);
492 492
 						return -1;
493 493
 					}
@@ -496,26 +496,26 @@  discard block
 block discarded – undo
496 496
 					try {
497 497
 					$odfHandler->saveToDisk($file);
498 498
 					} catch (Exception $e) {
499
-						$this->error=$e->getMessage();
499
+						$this->error = $e->getMessage();
500 500
                         dol_syslog($e->getMessage(), LOG_INFO);
501 501
 						return -1;
502 502
 					}
503 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))
507
+				if (!empty($conf->global->MAIN_UMASK))
508 508
 					@chmod($file, octdec($conf->global->MAIN_UMASK));
509 509
 
510
-				$odfHandler=null;	// Destroy object
510
+				$odfHandler = null; // Destroy object
511 511
 
512 512
 				$this->result = array('fullpath'=>$file);
513 513
 
514
-				return 1;   // Success
514
+				return 1; // Success
515 515
 			}
516 516
 			else
517 517
 			{
518
-				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
518
+				$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
519 519
 				return -1;
520 520
 			}
521 521
 		}
Please login to merge, or discard this patch.
Braces   +45 added lines, -38 removed lines patch added patch discarded remove patch
@@ -96,7 +96,10 @@  discard block
 block discarded – undo
96 96
 
97 97
 		// Recupere emetteur
98 98
 		$this->emetteur=$mysoc;
99
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
99
+		if (! $this->emetteur->country_code) {
100
+		    $this->emetteur->country_code=substr($langs->defaultlang,-2);
101
+		}
102
+		// By default if not defined
100 103
 	}
101 104
 
102 105
 
@@ -140,11 +143,14 @@  discard block
 block discarded – undo
140 143
 			if (! $tmpdir) {
141 144
 				unset($listofdir[$key]); continue;
142 145
 			}
143
-			if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
144
-			else
146
+			if (! is_dir($tmpdir)) {
147
+			    $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
148
+			} else
145 149
 			{
146 150
 				$tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
147
-				if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
151
+				if (count($tmpfiles)) {
152
+				    $listoffiles=array_merge($listoffiles,$tmpfiles);
153
+				}
148 154
 			}
149 155
 		}
150 156
 		$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
@@ -237,7 +243,9 @@  discard block
 block discarded – undo
237 243
 		$hookmanager->initHooks(array('odtgeneration'));
238 244
 		global $action;
239 245
 
240
-		if (! is_object($outputlangs)) $outputlangs=$langs;
246
+		if (! is_object($outputlangs)) {
247
+		    $outputlangs=$langs;
248
+		}
241 249
 		$sav_charset_output=$outputlangs->charset_output;
242 250
 		$outputlangs->charset_output='UTF-8';
243 251
 
@@ -264,7 +272,9 @@  discard block
 block discarded – undo
264 272
 
265 273
 			$dir = $conf->produit->dir_output;
266 274
 			$objectref = dol_sanitizeFileName($object->ref);
267
-			if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
275
+			if (! preg_match('/specimen/i',$objectref)) {
276
+			    $dir.= "/" . $objectref;
277
+			}
268 278
 			$file = $dir . "/" . $objectref . ".odt";
269 279
 
270 280
 			if (! file_exists($dir))
@@ -291,10 +301,11 @@  discard block
 block discarded – undo
291 301
 				if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
292 302
 				{
293 303
 				    $format=$conf->global->MAIN_DOC_USE_TIMING;
294
-				    if ($format == '1') $format='%Y%m%d%H%M%S';
304
+				    if ($format == '1') {
305
+				        $format='%Y%m%d%H%M%S';
306
+				    }
295 307
 					$filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
296
-				}
297
-				else
308
+				} else
298 309
 				{
299 310
 					$filename=$newfiletmp.'.'.$newfileformat;
300 311
 				}
@@ -321,14 +332,14 @@  discard block
 block discarded – undo
321 332
 				if (! empty($usecontact))
322 333
 				{
323 334
 					// 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 {
335
+					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
336
+					    $socobject = $object->contact;
337
+					} else {
326 338
                         			$socobject = $object->thirdparty;
327 339
                         			// if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use
328 340
                         			$contactobject = $object->contact;
329 341
                     			}
330
-				}
331
-				else
342
+				} else
332 343
 				{
333 344
 					$socobject=$object->thirdparty;
334 345
 				}
@@ -365,8 +376,7 @@  discard block
 block discarded – undo
365 376
 						'DELIMITER_RIGHT' => '}'
366 377
 						)
367 378
 					);
368
-				}
369
-				catch(Exception $e)
379
+				} catch(Exception $e)
370 380
 				{
371 381
 					$this->error=$e->getMessage();
372 382
 					dol_syslog($e->getMessage(), LOG_INFO);
@@ -383,8 +393,7 @@  discard block
 block discarded – undo
383 393
 				// Make substitutions into odt of freetext
384 394
 				try {
385 395
 					$odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
386
-				}
387
-				catch (OdfException $e)
396
+				} catch (OdfException $e)
388 397
 				{
389 398
 					dol_syslog($e->getMessage(), LOG_INFO);
390 399
 				}
@@ -399,7 +408,9 @@  discard block
 block discarded – undo
399 408
 				$array_other=$this->get_substitutionarray_other($outputlangs);
400 409
 				// retrieve contact information for use in stock as contact_xxx tags
401 410
 				$array_thirdparty_contact = array();
402
-				if ($usecontact && is_object($contactobject)) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
411
+				if ($usecontact && is_object($contactobject)) {
412
+				    $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
413
+				}
403 414
 
404 415
 				$tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_other,$array_thirdparty_contact);
405 416
 				complete_substitutions_array($tmparray, $outputlangs, $object);
@@ -411,17 +422,18 @@  discard block
 block discarded – undo
411 422
 				foreach($tmparray as $key=>$value)
412 423
 				{
413 424
 					try {
414
-						if (preg_match('/logo$/',$key)) // Image
425
+						if (preg_match('/logo$/',$key)) {
426
+						    // Image
415 427
 						{
416 428
 							if (file_exists($value)) $odfHandler->setImage($key, $value);
417
-							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
418
-						}
419
-						else    // Text
429
+						} else {
430
+							    $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
431
+							}
432
+						} else    // Text
420 433
 						{
421 434
 							$odfHandler->setVars($key, $value, true, 'UTF-8');
422 435
 						}
423
-					}
424
-					catch (OdfException $e)
436
+					} catch (OdfException $e)
425 437
 					{
426 438
                         dol_syslog($e->getMessage(), LOG_INFO);
427 439
 					}
@@ -443,12 +455,10 @@  discard block
 block discarded – undo
443 455
 								try
444 456
 								{
445 457
 									$listlines->setVars($key, $val, true, 'UTF-8');
446
-								}
447
-								catch(OdfException $e)
458
+								} catch(OdfException $e)
448 459
 								{
449 460
 									dol_syslog($e->getMessage(), LOG_INFO);
450
-								}
451
-								catch(SegmentException $e)
461
+								} catch(SegmentException $e)
452 462
 								{
453 463
 									dol_syslog($e->getMessage(), LOG_INFO);
454 464
 								}
@@ -457,8 +467,7 @@  discard block
 block discarded – undo
457 467
 						}
458 468
 					}
459 469
 					$odfHandler->mergeSegment($listlines);
460
-				}
461
-				catch(OdfException $e)
470
+				} catch(OdfException $e)
462 471
 				{
463 472
 					$this->error=$e->getMessage();
464 473
 					dol_syslog($this->error, LOG_WARNING);
@@ -471,8 +480,7 @@  discard block
 block discarded – undo
471 480
 				{
472 481
 					try {
473 482
 						$odfHandler->setVars($key, $value, true, 'UTF-8');
474
-					}
475
-					catch(OdfException $e)
483
+					} catch(OdfException $e)
476 484
 					{
477 485
                         dol_syslog($e->getMessage(), LOG_INFO);
478 486
 					}
@@ -491,8 +499,7 @@  discard block
 block discarded – undo
491 499
                         dol_syslog($e->getMessage(), LOG_INFO);
492 500
 						return -1;
493 501
 					}
494
-				}
495
-				else {
502
+				} else {
496 503
 					try {
497 504
 					$odfHandler->saveToDisk($file);
498 505
 					} catch (Exception $e) {
@@ -504,16 +511,16 @@  discard block
 block discarded – undo
504 511
 
505 512
 				$reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
506 513
 
507
-				if (! empty($conf->global->MAIN_UMASK))
508
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
514
+				if (! empty($conf->global->MAIN_UMASK)) {
515
+									@chmod($file, octdec($conf->global->MAIN_UMASK));
516
+				}
509 517
 
510 518
 				$odfHandler=null;	// Destroy object
511 519
 
512 520
 				$this->result = array('fullpath'=>$file);
513 521
 
514 522
 				return 1;   // Success
515
-			}
516
-			else
523
+			} else
517 524
 			{
518 525
 				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
519 526
 				return -1;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/stock/doc/pdf_standard.modules.php 3 patches
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.
Spacing   +247 added lines, -247 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	public function __construct($db)
119 119
 	{
120
-		global $conf,$langs,$mysoc;
120
+		global $conf, $langs, $mysoc;
121 121
 
122 122
 		// Load traductions files requiredby by page
123 123
 		$langs->loadLangs(array("main", "companies"));
@@ -128,52 +128,52 @@  discard block
 block discarded – undo
128 128
 
129 129
 		// Dimension page pour format A4
130 130
 		$this->type = 'pdf';
131
-		$formatarray=pdf_getFormat();
131
+		$formatarray = pdf_getFormat();
132 132
 		$this->page_largeur = $formatarray['width'];
133 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;
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 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
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 144
 
145 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
146
+		$this->emetteur = $mysoc;
147
+		if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
148 148
 
149 149
 		// Define position of columns
150 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
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 162
 		if ($this->page_largeur < 210) // To work with US executive format
163 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;
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 171
 		}
172
-		$this->tva=array();
173
-		$this->localtax1=array();
174
-		$this->localtax2=array();
175
-		$this->atleastoneratenotnull=0;
176
-		$this->atleastonediscount=0;
172
+		$this->tva = array();
173
+		$this->localtax1 = array();
174
+		$this->localtax2 = array();
175
+		$this->atleastoneratenotnull = 0;
176
+		$this->atleastonediscount = 0;
177 177
 	}
178 178
 
179 179
 
@@ -189,14 +189,14 @@  discard block
 block discarded – undo
189 189
 	 *  @param		int			$hideref			Do not show ref
190 190
 	 *	@return		int         					1 if OK, <=0 if KO
191 191
 	 */
192
-	function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
192
+	function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
193 193
 	{
194 194
         // phpcs:enable
195
-		global $user,$langs,$conf,$mysoc,$db,$hookmanager;
195
+		global $user, $langs, $conf, $mysoc, $db, $hookmanager;
196 196
 
197
-		if (! is_object($outputlangs)) $outputlangs=$langs;
197
+		if (!is_object($outputlangs)) $outputlangs = $langs;
198 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';
199
+		if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1';
200 200
 
201 201
 		// Load traductions files requiredby by page
202 202
 		$outputlangs->loadLangs(array("main", "dict", "companies", "bills", "stocks", "orders", "deliveries"));
@@ -209,26 +209,26 @@  discard block
 block discarded – undo
209 209
 			if ($object->specimen)
210 210
 			{
211 211
 				$dir = $conf->stock->dir_output;
212
-				$file = $dir . "/SPECIMEN.pdf";
212
+				$file = $dir."/SPECIMEN.pdf";
213 213
 			}
214 214
 			else
215 215
 			{
216 216
 				$objectref = dol_sanitizeFileName($object->ref);
217
-				$dir = $conf->stock->dir_output . "/" . $objectref;
218
-				$file = $dir . "/" . $objectref . ".pdf";
217
+				$dir = $conf->stock->dir_output."/".$objectref;
218
+				$file = $dir."/".$objectref.".pdf";
219 219
 			}
220 220
 
221 221
 			$stockFournisseur = new ProductFournisseur($this->db);
222 222
 			$supplierprices = $stockFournisseur->list_product_fournisseur_price($object->id);
223 223
 			$object->supplierprices = $supplierprices;
224 224
 
225
-			$productstatic=new Product($db);
225
+			$productstatic = new Product($db);
226 226
 
227
-			if (! file_exists($dir))
227
+			if (!file_exists($dir))
228 228
 			{
229 229
 				if (dol_mkdir($dir) < 0)
230 230
 				{
231
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
231
+					$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
232 232
 					return -1;
233 233
 				}
234 234
 			}
@@ -236,24 +236,24 @@  discard block
 block discarded – undo
236 236
 			if (file_exists($dir))
237 237
 			{
238 238
 				// Add pdfgeneration hook
239
-				if (! is_object($hookmanager))
239
+				if (!is_object($hookmanager))
240 240
 				{
241 241
 					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
242
-					$hookmanager=new HookManager($this->db);
242
+					$hookmanager = new HookManager($this->db);
243 243
 				}
244 244
 				$hookmanager->initHooks(array('pdfgeneration'));
245
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
245
+				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
246 246
 				global $action;
247
-				$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
247
+				$reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
248 248
 
249 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);
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
                 {
@@ -262,37 +262,37 @@  discard block
 block discarded – undo
262 262
                 }
263 263
                 $pdf->SetFont(pdf_getPDFFont($outputlangs));
264 264
                 // Set path to the background PDF File
265
-                if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
265
+                if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
266 266
                 {
267 267
                     $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
268 268
                     $tplidx = $pdf->importPage(1);
269 269
                 }
270 270
 
271 271
 				$pdf->Open();
272
-				$pagenb=0;
273
-				$pdf->SetDrawColor(128,128,128);
272
+				$pagenb = 0;
273
+				$pdf->SetDrawColor(128, 128, 128);
274 274
 
275 275
 				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
276 276
 				$pdf->SetSubject($outputlangs->transnoentities("Stock"));
277 277
 				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
278 278
 				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
279 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);
280
+				if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
281 281
 
282
-				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
282
+				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
283 283
 
284 284
 
285 285
 				// New page
286 286
 				$pdf->AddPage();
287
-				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
287
+				if (!empty($tplidx)) $pdf->useTemplate($tplidx);
288 288
 				$pagenb++;
289 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);
290
+				$pdf->SetFont('', '', $default_font_size - 1);
291
+				$pdf->MultiCell(0, 3, ''); // Set interline to 3
292
+				$pdf->SetTextColor(0, 0, 0);
293 293
 
294 294
 				$tab_top = 42;
295
-				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
295
+				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10);
296 296
 				$tab_height = 130;
297 297
 				$tab_height_newpage = 150;
298 298
 
@@ -302,20 +302,20 @@  discard block
 block discarded – undo
302 302
 				/*                                                                            */
303 303
 				/* ************************************************************************** */
304 304
 
305
-				$nexY+=5;
305
+				$nexY += 5;
306 306
 				$nexY = $pdf->GetY();
307
-				$nexY+=10;
307
+				$nexY += 10;
308 308
 
309
-				$totalunit=0;
310
-				$totalvalue=$totalvaluesell=0;
309
+				$totalunit = 0;
310
+				$totalvalue = $totalvaluesell = 0;
311 311
 
312 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);
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 319
 
320 320
 				//dol_syslog('List products', LOG_DEBUG);
321 321
 				$resql = $db->query($sql);
@@ -324,18 +324,18 @@  discard block
 block discarded – undo
324 324
 					$num = $db->num_rows($resql);
325 325
 					$i = 0;
326 326
 					$nblignes = $num;
327
-					for ($i = 0 ; $i < $nblignes ; $i++)
327
+					for ($i = 0; $i < $nblignes; $i++)
328 328
 					{
329 329
 						$objp = $db->fetch_object($resql);
330 330
 
331 331
 						// Multilangs
332
-						if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
332
+						if (!empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
333 333
 						{
334 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";
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 339
 
340 340
 							$result = $db->query($sql);
341 341
 							if ($result)
@@ -346,122 +346,122 @@  discard block
 block discarded – undo
346 346
 						}
347 347
 
348 348
 						$curY = $nexY;
349
-						$pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
350
-						$pdf->SetTextColor(0,0,0);
349
+						$pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
350
+						$pdf->SetTextColor(0, 0, 0);
351 351
 
352 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();
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 355
 
356 356
 						// Description of product line
357
-						$curX = $this->posxdesc-1;
357
+						$curX = $this->posxdesc - 1;
358 358
 
359
-						$showpricebeforepagebreak=1;
359
+						$showpricebeforepagebreak = 1;
360 360
 
361 361
 						$pdf->startTransaction();
362
-						pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc);
363
-						$pageposafter=$pdf->getPage();
362
+						pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc);
363
+						$pageposafter = $pdf->getPage();
364 364
 						if ($pageposafter > $pageposbefore)	// There is a pagebreak
365 365
 						{
366 366
 							$pdf->rollbackTransaction(true);
367
-							$pageposafter=$pageposbefore;
367
+							$pageposafter = $pageposbefore;
368 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
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 374
 							{
375
-								if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
375
+								if ($i == ($nblignes - 1))	// No more lines, and no space left to show total, so we create a new page
376 376
 								{
377
-									$pdf->AddPage('','',true);
378
-									if (! empty($tplidx)) $pdf->useTemplate($tplidx);
377
+									$pdf->AddPage('', '', true);
378
+									if (!empty($tplidx)) $pdf->useTemplate($tplidx);
379 379
 									if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
380
-									$pdf->setPage($pageposafter+1);
380
+									$pdf->setPage($pageposafter + 1);
381 381
 								}
382 382
 							}
383 383
 							else
384 384
 							{
385 385
 								// We found a page break
386
-								$showpricebeforepagebreak=0;
386
+								$showpricebeforepagebreak = 0;
387 387
 							}
388 388
 						}
389 389
 						else	// No pagebreak
390 390
 						{
391 391
 							$pdf->commitTransaction();
392 392
 						}
393
-						$posYAfterDescription=$pdf->GetY();
393
+						$posYAfterDescription = $pdf->GetY();
394 394
 
395 395
 						$nexY = $pdf->GetY();
396
-						$pageposafter=$pdf->getPage();
396
+						$pageposafter = $pdf->getPage();
397 397
 
398 398
 						$pdf->setPage($pageposbefore);
399 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.
400
+						$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
401 401
 
402 402
 						// We suppose that a too long description is moved completely on next page
403 403
 						if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
404 404
 							$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
405 405
 						}
406 406
 
407
-						$pdf->SetFont('','',  $default_font_size - 1);   // On repositionne la police par defaut
407
+						$pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
408 408
 
409
-						$productstatic->id=$objp->rowid;
409
+						$productstatic->id = $objp->rowid;
410 410
 						$productstatic->ref = $objp->ref;
411 411
 						$productstatic->label = $objp->produit;
412
-						$productstatic->type=$objp->type;
413
-						$productstatic->entity=$objp->entity;
414
-						$productstatic->status_batch=$objp->tobatch;
412
+						$productstatic->type = $objp->type;
413
+						$productstatic->entity = $objp->entity;
414
+						$productstatic->status_batch = $objp->tobatch;
415 415
 
416 416
 						// Ref.
417 417
 						$pdf->SetXY($this->posxdesc, $curY);
418 418
 						$pdf->MultiCell($this->wref, 3, $productstatic->ref, 0, 'L');
419 419
 
420 420
 						// Label
421
-						$pdf->SetXY($this->posxlabel+0.8, $curY);
422
-						$pdf->MultiCell($this->posxqty-$this->posxlabel-0.8, 3, $objp->produit, 0, 'L');
421
+						$pdf->SetXY($this->posxlabel + 0.8, $curY);
422
+						$pdf->MultiCell($this->posxqty - $this->posxlabel - 0.8, 3, $objp->produit, 0, 'L');
423 423
 
424 424
 						// Quantity
425
-						$valtoshow=price2num($objp->value, 'MS');
426
-						$towrite = (empty($valtoshow)?'0':$valtoshow);
425
+						$valtoshow = price2num($objp->value, 'MS');
426
+						$towrite = (empty($valtoshow) ? '0' : $valtoshow);
427 427
 
428 428
 						$pdf->SetXY($this->posxqty, $curY);
429
-						$pdf->MultiCell($this->posxup-$this->posxqty-0.8, 3, $towrite, 0, 'R');
429
+						$pdf->MultiCell($this->posxup - $this->posxqty - 0.8, 3, $towrite, 0, 'R');
430 430
 
431
-						$totalunit+=$objp->value;
431
+						$totalunit += $objp->value;
432 432
 
433 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');
434
+						$pdf->MultiCell($this->posxunit - $this->posxup - 0.8, 3, price(price2num($objp->ppmp, 'MU'), 0, $outputlangs), 0, 'R');
435 435
 
436 436
 						// Total PMP
437 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');
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 440
 
441 441
 						// Price sell min
442 442
 						if (empty($conf->global->PRODUIT_MULTIPRICES))
443 443
 						{
444
-							$pricemin=$objp->price;
444
+							$pricemin = $objp->price;
445 445
 							$pdf->SetXY($this->posxdiscount, $curY);
446
-							$pdf->MultiCell($this->postotalht-$this->posxdiscount, 3, price(price2num($pricemin,'MU'), 0, $outputlangs), 0, 'R', 0);
446
+							$pdf->MultiCell($this->postotalht - $this->posxdiscount, 3, price(price2num($pricemin, 'MU'), 0, $outputlangs), 0, 'R', 0);
447 447
 
448 448
 							// Total sell min
449 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);
450
+							$pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, price(price2num($pricemin * $objp->value, 'MT'), 0, $outputlangs), 0, 'R', 0);
451 451
 						}
452
-						$totalvaluesell+=price2num($pricemin*$objp->value,'MT');
452
+						$totalvaluesell += price2num($pricemin * $objp->value, 'MT');
453 453
 
454 454
 						// Add line
455
-						if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
455
+						if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
456 456
 						{
457 457
 							$pdf->setPage($pageposafter);
458
-							$pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
458
+							$pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
459 459
 							//$pdf->SetDrawColor(190,190,200);
460
-							$pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
460
+							$pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
461 461
 							$pdf->SetLineStyle(array('dash'=>0));
462 462
 						}
463 463
 
464
-						$nexY+=2;    // Passe espace entre les lignes
464
+						$nexY += 2; // Passe espace entre les lignes
465 465
 
466 466
 						// Detect if some page were added automatically and output _tableau for past pages
467 467
 						while ($pagenb < $pageposafter)
@@ -475,13 +475,13 @@  discard block
 block discarded – undo
475 475
 							{
476 476
 								$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
477 477
 							}
478
-							$this->_pagefoot($pdf,$object,$outputlangs,1);
478
+							$this->_pagefoot($pdf, $object, $outputlangs, 1);
479 479
 							$pagenb++;
480 480
 							$pdf->setPage($pagenb);
481
-							$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
481
+							$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
482 482
 							if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
483 483
 						}
484
-						if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
484
+						if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak)
485 485
 						{
486 486
 							if ($pagenb == 1)
487 487
 							{
@@ -491,10 +491,10 @@  discard block
 block discarded – undo
491 491
 							{
492 492
 								$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
493 493
 							}
494
-							$this->_pagefoot($pdf,$object,$outputlangs,1);
494
+							$this->_pagefoot($pdf, $object, $outputlangs, 1);
495 495
 							// New page
496 496
 							$pdf->AddPage();
497
-							if (! empty($tplidx)) $pdf->useTemplate($tplidx);
497
+							if (!empty($tplidx)) $pdf->useTemplate($tplidx);
498 498
 							$pagenb++;
499 499
 							if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
500 500
 						}
@@ -506,37 +506,37 @@  discard block
 block discarded – undo
506 506
 					 * footer table
507 507
 					 */
508 508
 					$nexY = $pdf->GetY();
509
-					$nexY+=2;
509
+					$nexY += 2;
510 510
 					$curY = $nexY;
511 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);
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 514
 					$pdf->SetLineStyle(array('dash'=>0));
515 515
 
516
-					$pdf->SetFont('','B',$default_font_size-1);
517
-					$pdf->SetTextColor(0,0,120);
516
+					$pdf->SetFont('', 'B', $default_font_size - 1);
517
+					$pdf->SetTextColor(0, 0, 120);
518 518
 
519 519
 					// Ref.
520 520
 					$pdf->SetXY($this->posxdesc, $curY);
521 521
 					$pdf->MultiCell($this->wref, 3, $langs->trans("Total"), 0, 'L');
522 522
 
523 523
 					// Quantity
524
-					$valtoshow=price2num($totalunit, 'MS');
525
-					$towrite = empty($valtoshow)?'0':$valtoshow;
524
+					$valtoshow = price2num($totalunit, 'MS');
525
+					$towrite = empty($valtoshow) ? '0' : $valtoshow;
526 526
 
527 527
 					$pdf->SetXY($this->posxqty, $curY);
528
-					$pdf->MultiCell($this->posxup-$this->posxqty-0.8, 3, $towrite, 0, 'R');
528
+					$pdf->MultiCell($this->posxup - $this->posxqty - 0.8, 3, $towrite, 0, 'R');
529 529
 
530 530
 					// Total PMP
531 531
 					$pdf->SetXY($this->posxunit, $curY);
532
-					$pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 3, price(price2num($totalvalue,'MT'), 0, $outputlangs), 0, 'R');
532
+					$pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 3, price(price2num($totalvalue, 'MT'), 0, $outputlangs), 0, 'R');
533 533
 
534 534
 					// Price sell min
535 535
 					if (empty($conf->global->PRODUIT_MULTIPRICES))
536 536
 					{
537 537
 						// Total sell min
538 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);
539
+						$pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, price(price2num($totalvaluesell, 'MT'), 0, $outputlangs), 0, 'R', 0);
540 540
 					}
541 541
 				}
542 542
 				else
@@ -546,27 +546,27 @@  discard block
 block discarded – undo
546 546
 
547 547
 				if ($notetoshow)
548 548
 				{
549
-					$substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
549
+					$substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
550 550
 					complete_substitutions_array($substitutionarray, $outputlangs, $object);
551 551
 					$notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
552 552
 
553 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);
555
+					$pdf->SetFont('', '', $default_font_size - 1);
556
+					$pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
557 557
 					$nexY = $pdf->GetY();
558
-					$height_note=$nexY-$tab_top;
558
+					$height_note = $nexY - $tab_top;
559 559
 
560 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);
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 564
 					$tab_height = $tab_height - $height_note;
565
-					$tab_top = $nexY+6;
565
+					$tab_top = $nexY + 6;
566 566
 				}
567 567
 				else
568 568
 				{
569
-					$height_note=0;
569
+					$height_note = 0;
570 570
 				}
571 571
 
572 572
 				$iniY = $tab_top + 7;
@@ -769,21 +769,21 @@  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 774
 				// Show square
775 775
 				if ($pagenb == 1)
776 776
 				{
777 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;
778
+					$bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
779 779
 				}
780 780
 				else
781 781
 				{
782 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;
783
+					$bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
784 784
 				}
785 785
 
786
-				$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
786
+				$bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
787 787
 
788 788
 				// Affiche zone infos
789 789
 				//$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
@@ -792,35 +792,35 @@  discard block
 block discarded – undo
792 792
 				//$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
793 793
 
794 794
 				// Pied de page
795
-				$this->_pagefoot($pdf,$object,$outputlangs);
796
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
795
+				$this->_pagefoot($pdf, $object, $outputlangs);
796
+				if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
797 797
 
798 798
 				$pdf->Close();
799 799
 
800
-				$pdf->Output($file,'F');
800
+				$pdf->Output($file, 'F');
801 801
 
802 802
 				// Add pdfgeneration hook
803 803
 				$hookmanager->initHooks(array('pdfgeneration'));
804
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
804
+				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
805 805
 				global $action;
806
-				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
806
+				$reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
807 807
 
808
-				if (! empty($conf->global->MAIN_UMASK))
808
+				if (!empty($conf->global->MAIN_UMASK))
809 809
 					@chmod($file, octdec($conf->global->MAIN_UMASK));
810 810
 
811 811
 				$this->result = array('fullpath'=>$file);
812 812
 
813
-				return 1;   // Pas d'erreur
813
+				return 1; // Pas d'erreur
814 814
 			}
815 815
 			else
816 816
 			{
817
-				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
817
+				$this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
818 818
 				return 0;
819 819
 			}
820 820
 		}
821 821
 		else
822 822
 		{
823
-			$this->error=$langs->trans("ErrorConstantNotDefined","PRODUCT_OUTPUTDIR");
823
+			$this->error = $langs->trans("ErrorConstantNotDefined", "PRODUCT_OUTPUTDIR");
824 824
 			return 0;
825 825
 		}
826 826
 	}
@@ -839,70 +839,70 @@  discard block
 block discarded – undo
839 839
 	 *   @param		string		$currency		Currency code
840 840
 	 *   @return	void
841 841
 	 */
842
-	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
842
+	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
843 843
 	{
844 844
 	    global $conf;
845 845
 
846 846
 	    // Force to disable hidetop and hidebottom
847
-	    $hidebottom=0;
848
-	    if ($hidetop) $hidetop=-1;
847
+	    $hidebottom = 0;
848
+	    if ($hidetop) $hidetop = -1;
849 849
 
850 850
 	    $currency = !empty($currency) ? $currency : $conf->currency;
851 851
 	    $default_font_size = pdf_getPDFFontSize($outputlangs);
852 852
 
853 853
 	    // Amount in (at tab_top - 1)
854
-	    $pdf->SetTextColor(0,0,0);
855
-	    $pdf->SetFont('','', $default_font_size - 2);
854
+	    $pdf->SetTextColor(0, 0, 0);
855
+	    $pdf->SetFont('', '', $default_font_size - 2);
856 856
 
857 857
 	    if (empty($hidetop))
858 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);
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 861
 	        $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
862 862
 
863 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));
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 865
 	    }
866 866
 
867
-	    $pdf->SetDrawColor(128,128,128);
868
-	    $pdf->SetFont('','B', $default_font_size - 3);
867
+	    $pdf->SetDrawColor(128, 128, 128);
868
+	    $pdf->SetFont('', 'B', $default_font_size - 3);
869 869
 
870 870
 	    // Output Rect
871 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 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);
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 876
 		$pdf->SetLineStyle(array('dash'=>0));
877
-		$pdf->SetDrawColor(128,128,128);
878
-		$pdf->SetTextColor(0,0,120);
877
+		$pdf->SetDrawColor(128, 128, 128);
878
+		$pdf->SetTextColor(0, 0, 120);
879 879
 
880 880
 	    if (empty($hidetop))
881 881
 	    {
882 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');
883
+	        $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
884
+	        $pdf->MultiCell($this->wref, 3, $outputlangs->transnoentities("Ref"), '', 'L');
885 885
 	    }
886 886
 
887 887
 		//$pdf->line($this->posxlabel-1, $tab_top, $this->posxlabel-1, $tab_top + $tab_height);
888 888
 		if (empty($hidetop))
889 889
 		{
890
-			$pdf->SetXY($this->posxlabel-3, $tab_top+1);
891
-			$pdf->MultiCell($this->posxqty-$this->posxlabel+3,2, $outputlangs->transnoentities("Label"),'','C');
890
+			$pdf->SetXY($this->posxlabel - 3, $tab_top + 1);
891
+			$pdf->MultiCell($this->posxqty - $this->posxlabel + 3, 2, $outputlangs->transnoentities("Label"), '', 'C');
892 892
 		}
893 893
 
894 894
 	    //$pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
895 895
 	    if (empty($hidetop))
896 896
 	    {
897
-	        $pdf->SetXY($this->posxqty-1, $tab_top+1);
898
-	        $pdf->MultiCell($this->posxup-$this->posxqty-1,2, $outputlangs->transnoentities("Units"),'','C');
897
+	        $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
898
+	        $pdf->MultiCell($this->posxup - $this->posxqty - 1, 2, $outputlangs->transnoentities("Units"), '', 'C');
899 899
 	    }
900 900
 
901 901
 	    //$pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
902 902
 	    if (empty($hidetop))
903 903
 	    {
904
-	        $pdf->SetXY($this->posxup-1, $tab_top+1);
905
-			$pdf->MultiCell($this->posxunit-$this->posxup-1,2, $outputlangs->transnoentities("AverageUnitPricePMPShort"),'','C');
904
+	        $pdf->SetXY($this->posxup - 1, $tab_top + 1);
905
+			$pdf->MultiCell($this->posxunit - $this->posxup - 1, 2, $outputlangs->transnoentities("AverageUnitPricePMPShort"), '', 'C');
906 906
 	    }
907 907
 
908 908
 		//$pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
@@ -916,20 +916,20 @@  discard block
 block discarded – undo
916 916
 	    //$pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
917 917
 	    if (empty($hidetop))
918 918
 	    {
919
-			$pdf->SetXY($this->posxdiscount-1, $tab_top+1);
920
-			$pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("SellPriceMin"),'','C');
919
+			$pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
920
+			$pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("SellPriceMin"), '', 'C');
921 921
 	    }
922 922
 
923 923
 	    //$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
924 924
 	    if (empty($hidetop))
925 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');
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 928
 	    }
929 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);
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 933
 		$pdf->SetLineStyle(array('dash'=>0));
934 934
 	}
935 935
 
@@ -943,92 +943,92 @@  discard block
 block discarded – undo
943 943
 	 *  @param	string		$titlekey		Translation key to show as title of document
944 944
 	 *  @return	void
945 945
 	 */
946
-	function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="")
946
+	function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey = "")
947 947
 	{
948
-	    global $conf,$langs,$db,$hookmanager;
948
+	    global $conf, $langs, $db, $hookmanager;
949 949
 
950 950
 	    // Load traductions files requiredby by page
951 951
 		$outputlangs->loadLangs(array("main", "propal", "companies", "bills", "orders", "stocks"));
952 952
 
953 953
 	    $default_font_size = pdf_getPDFFontSize($outputlangs);
954 954
 
955
-	    if ($object->type == 1) $titlekey='ServiceSheet';
956
-	    else $titlekey='StockSheet';
955
+	    if ($object->type == 1) $titlekey = 'ServiceSheet';
956
+	    else $titlekey = 'StockSheet';
957 957
 
958
-	    pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
958
+	    pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
959 959
 
960 960
 	    // Show Draft Watermark
961
-	    if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
961
+	    if ($object->statut == 0 && (!empty($conf->global->COMMANDE_DRAFT_WATERMARK)))
962 962
 	    {
963
-	        pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
963
+	        pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->COMMANDE_DRAFT_WATERMARK);
964 964
 	    }
965 965
 
966
-	    $pdf->SetTextColor(0,0,60);
967
-	    $pdf->SetFont('','B', $default_font_size + 3);
966
+	    $pdf->SetTextColor(0, 0, 60);
967
+	    $pdf->SetFont('', 'B', $default_font_size + 3);
968 968
 
969
-	    $posy=$this->marge_haute;
970
-	    $posx=$this->page_largeur-$this->marge_droite-100;
969
+	    $posy = $this->marge_haute;
970
+	    $posx = $this->page_largeur - $this->marge_droite - 100;
971 971
 
972
-	    $pdf->SetXY($this->marge_gauche,$posy);
972
+	    $pdf->SetXY($this->marge_gauche, $posy);
973 973
 
974 974
 	    // Logo
975
-	    $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
975
+	    $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
976 976
 	    if ($this->emetteur->logo)
977 977
 	    {
978 978
 	        if (is_readable($logo))
979 979
 	        {
980
-	            $height=pdf_getHeightForLogo($logo);
981
-	            $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
980
+	            $height = pdf_getHeightForLogo($logo);
981
+	            $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
982 982
 	        }
983 983
 	        else
984 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');
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 988
 	            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
989 989
 	        }
990 990
 	    }
991 991
 	    else
992 992
 	    {
993
-	        $text=$this->emetteur->name;
993
+	        $text = $this->emetteur->name;
994 994
 	        $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
995 995
 	    }
996 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");
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 1001
 	    $pdf->MultiCell(100, 3, $title, '', 'R');
1002 1002
 
1003
-	    $pdf->SetFont('','B',$default_font_size);
1003
+	    $pdf->SetFont('', 'B', $default_font_size);
1004 1004
 
1005
-	    $posy+=5;
1006
-	    $pdf->SetXY($posx,$posy);
1007
-	    $pdf->SetTextColor(0,0,60);
1005
+	    $posy += 5;
1006
+	    $pdf->SetXY($posx, $posy);
1007
+	    $pdf->SetTextColor(0, 0, 60);
1008 1008
 
1009
-	    $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->libelle), '', 'R');
1009
+	    $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->libelle), '', 'R');
1010 1010
 
1011
-	    $posy+=5;
1012
-	    $pdf->SetFont('','', $default_font_size - 1);
1013
-		$pdf->SetXY($posx,$posy);
1014
-	    $pdf->SetTextColor(0,0,60);
1011
+	    $posy += 5;
1012
+	    $pdf->SetFont('', '', $default_font_size - 1);
1013
+		$pdf->SetXY($posx, $posy);
1014
+	    $pdf->SetTextColor(0, 0, 60);
1015 1015
 	    $pdf->MultiCell(100, 3, $outputlangs->transnoentities("LocationSummary").' :', '', 'R');
1016 1016
 
1017
-		$posy+=4;
1018
-		$pdf->SetXY($posx-50,$posy);
1017
+		$posy += 4;
1018
+		$pdf->SetXY($posx - 50, $posy);
1019 1019
 		$pdf->MultiCell(150, 3, $object->lieu, '', 'R');
1020 1020
 
1021 1021
 
1022 1022
 		// Parent entrepot
1023
-		$posy+=4;
1024
-		$pdf->SetXY($posx,$posy);
1025
-		$pdf->SetTextColor(0,0,60);
1023
+		$posy += 4;
1024
+		$pdf->SetXY($posx, $posy);
1025
+		$pdf->SetTextColor(0, 0, 60);
1026 1026
 		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ParentWarehouse").' :', '', 'R');
1027 1027
 
1028
-		$posy+=4;
1029
-		$pdf->SetXY($posx-50,$posy);
1028
+		$posy += 4;
1029
+		$pdf->SetXY($posx - 50, $posy);
1030 1030
 		$e = new Entrepot($db);
1031
-		if(!empty($object->fk_parent) && $e->fetch($object->fk_parent) > 0)
1031
+		if (!empty($object->fk_parent) && $e->fetch($object->fk_parent) > 0)
1032 1032
 		{
1033 1033
 			$pdf->MultiCell(150, 3, $e->libelle, '', 'R');
1034 1034
 		}
@@ -1039,25 +1039,25 @@  discard block
 block discarded – undo
1039 1039
 
1040 1040
 		// Description
1041 1041
 		$nexY = $pdf->GetY();
1042
-		$nexY+=5;
1043
-		$pdf->SetXY($posx,$posy);
1042
+		$nexY += 5;
1043
+		$pdf->SetXY($posx, $posy);
1044 1044
 		$pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("Description").' : </b>'.nl2br($object->description), 0, 1);
1045 1045
 		$nexY = $pdf->GetY();
1046 1046
 
1047
-		$calcproductsunique=$object->nb_different_products();
1048
-		$calcproducts=$object->nb_products();
1047
+		$calcproductsunique = $object->nb_different_products();
1048
+		$calcproducts = $object->nb_products();
1049 1049
 
1050 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);
1051
+		$pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("NumberOfDifferentProducts").' : </b>'.(empty($calcproductsunique['nb']) ? '0' : $calcproductsunique['nb']), 0, 1);
1052 1052
 		$nexY = $pdf->GetY();
1053 1053
 
1054 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);
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 1057
 		$nexY = $pdf->GetY();
1058 1058
 
1059 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);
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 1061
 		$nexY = $pdf->GetY();
1062 1062
 
1063 1063
 
@@ -1069,7 +1069,7 @@  discard block
 block discarded – undo
1069 1069
 		if ($resqlbis)
1070 1070
 		{
1071 1071
 			$obj = $db->fetch_object($resqlbis);
1072
-			$lastmovementdate=$db->jdate($obj->datem);
1072
+			$lastmovementdate = $db->jdate($obj->datem);
1073 1073
 		}
1074 1074
 		else
1075 1075
 		{
@@ -1078,7 +1078,7 @@  discard block
 block discarded – undo
1078 1078
 
1079 1079
 		if ($lastmovementdate)
1080 1080
 		{
1081
-			$toWrite = dol_print_date($lastmovementdate,'dayhour').' ';
1081
+			$toWrite = dol_print_date($lastmovementdate, 'dayhour').' ';
1082 1082
 		}
1083 1083
 		else
1084 1084
 		{
@@ -1119,7 +1119,7 @@  discard block
 block discarded – undo
1119 1119
 	        }
1120 1120
 	    }*/
1121 1121
 
1122
-	    $posy+=2;
1122
+	    $posy += 2;
1123 1123
 
1124 1124
 	    // Show list of linked objects
1125 1125
 	    $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
@@ -1159,7 +1159,7 @@  discard block
 block discarded – undo
1159 1159
 	        */
1160 1160
 	    }
1161 1161
 
1162
-	    $pdf->SetTextColor(0,0,0);
1162
+	    $pdf->SetTextColor(0, 0, 0);
1163 1163
 	}
1164 1164
 
1165 1165
 	/**
@@ -1171,10 +1171,10 @@  discard block
 block discarded – undo
1171 1171
 	 *      @param	int			$hidefreetext		1=Hide free text
1172 1172
 	 *      @return	int								Return height of bottom margin including footer text
1173 1173
 	 */
1174
-	function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1174
+	function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1175 1175
 	{
1176 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);
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 1179
 	}
1180 1180
 }
Please login to merge, or discard this patch.
Braces   +81 added lines, -53 removed lines patch added patch discarded remove patch
@@ -144,7 +144,10 @@  discard block
 block discarded – undo
144 144
 
145 145
 		// Recupere emetteur
146 146
 		$this->emetteur=$mysoc;
147
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
147
+		if (! $this->emetteur->country_code) {
148
+		    $this->emetteur->country_code=substr($langs->defaultlang,-2);
149
+		}
150
+		// By default if not defined
148 151
 
149 152
 		// Define position of columns
150 153
 		$this->wref = 15;
@@ -157,11 +160,15 @@  discard block
 block discarded – undo
157 160
 		$this->posxdiscount=155;
158 161
 		$this->postotalht=175;
159 162
 
160
-		if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup;
163
+		if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
164
+		    $this->posxtva=$this->posxup;
165
+		}
161 166
 		$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
167
+		if ($this->page_largeur < 210) {
168
+		    // To work with US executive format
163 169
 		{
164 170
 			$this->posxpicture-=20;
171
+		}
165 172
 			$this->posxtva-=20;
166 173
 			$this->posxup-=20;
167 174
 			$this->posxqty-=20;
@@ -194,9 +201,13 @@  discard block
 block discarded – undo
194 201
         // phpcs:enable
195 202
 		global $user,$langs,$conf,$mysoc,$db,$hookmanager;
196 203
 
197
-		if (! is_object($outputlangs)) $outputlangs=$langs;
204
+		if (! is_object($outputlangs)) {
205
+		    $outputlangs=$langs;
206
+		}
198 207
 		// 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';
208
+		if (! empty($conf->global->MAIN_USE_FPDF)) {
209
+		    $outputlangs->charset_output='ISO-8859-1';
210
+		}
200 211
 
201 212
 		// Load traductions files requiredby by page
202 213
 		$outputlangs->loadLangs(array("main", "dict", "companies", "bills", "stocks", "orders", "deliveries"));
@@ -210,8 +221,7 @@  discard block
 block discarded – undo
210 221
 			{
211 222
 				$dir = $conf->stock->dir_output;
212 223
 				$file = $dir . "/SPECIMEN.pdf";
213
-			}
214
-			else
224
+			} else
215 225
 			{
216 226
 				$objectref = dol_sanitizeFileName($object->ref);
217 227
 				$dir = $conf->stock->dir_output . "/" . $objectref;
@@ -277,14 +287,18 @@  discard block
 block discarded – undo
277 287
 				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
278 288
 				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
279 289
 				$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);
290
+				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
291
+				    $pdf->SetCompression(false);
292
+				}
281 293
 
282 294
 				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
283 295
 
284 296
 
285 297
 				// New page
286 298
 				$pdf->AddPage();
287
-				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
299
+				if (! empty($tplidx)) {
300
+				    $pdf->useTemplate($tplidx);
301
+				}
288 302
 				$pagenb++;
289 303
 				$this->_pagehead($pdf, $object, 1, $outputlangs);
290 304
 				$pdf->SetFont('','', $default_font_size - 1);
@@ -329,9 +343,11 @@  discard block
 block discarded – undo
329 343
 						$objp = $db->fetch_object($resql);
330 344
 
331 345
 						// Multilangs
332
-						if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
346
+						if (! empty($conf->global->MAIN_MULTILANGS)) {
347
+						    // si l'option est active
333 348
 						{
334 349
 							$sql = "SELECT label";
350
+						}
335 351
 							$sql.= " FROM ".MAIN_DB_PREFIX."product_lang";
336 352
 							$sql.= " WHERE fk_product=".$objp->rowid;
337 353
 							$sql.= " AND lang='". $langs->getDefaultLang() ."'";
@@ -341,7 +357,9 @@  discard block
 block discarded – undo
341 357
 							if ($result)
342 358
 							{
343 359
 								$objtp = $db->fetch_object($result);
344
-								if ($objtp->label != '') $objp->produit = $objtp->label;
360
+								if ($objtp->label != '') {
361
+								    $objp->produit = $objtp->label;
362
+								}
345 363
 							}
346 364
 						}
347 365
 
@@ -361,32 +379,38 @@  discard block
 block discarded – undo
361 379
 						$pdf->startTransaction();
362 380
 						pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc);
363 381
 						$pageposafter=$pdf->getPage();
364
-						if ($pageposafter > $pageposbefore)	// There is a pagebreak
382
+						if ($pageposafter > $pageposbefore) {
383
+						    // There is a pagebreak
365 384
 						{
366 385
 							$pdf->rollbackTransaction(true);
386
+						}
367 387
 							$pageposafter=$pageposbefore;
368 388
 							//print $pageposafter.'-'.$pageposbefore;exit;
369 389
 							$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
370 390
 							pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc);
371 391
 							$pageposafter=$pdf->getPage();
372 392
 							$posyafter=$pdf->GetY();
373
-							if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
393
+							if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) {
394
+							    // There is no space left for total+free text
374 395
 							{
375 396
 								if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
376 397
 								{
377 398
 									$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);
399
+							}
400
+									if (! empty($tplidx)) {
401
+									    $pdf->useTemplate($tplidx);
402
+									}
403
+									if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
404
+									    $this->_pagehead($pdf, $object, 0, $outputlangs);
405
+									}
380 406
 									$pdf->setPage($pageposafter+1);
381 407
 								}
382
-							}
383
-							else
408
+							} else
384 409
 							{
385 410
 								// We found a page break
386 411
 								$showpricebeforepagebreak=0;
387 412
 							}
388
-						}
389
-						else	// No pagebreak
413
+						} else	// No pagebreak
390 414
 						{
391 415
 							$pdf->commitTransaction();
392 416
 						}
@@ -470,8 +494,7 @@  discard block
 block discarded – undo
470 494
 							if ($pagenb == 1)
471 495
 							{
472 496
 								$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
473
-							}
474
-							else
497
+							} else
475 498
 							{
476 499
 								$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
477 500
 							}
@@ -479,24 +502,29 @@  discard block
 block discarded – undo
479 502
 							$pagenb++;
480 503
 							$pdf->setPage($pagenb);
481 504
 							$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);
505
+							if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
506
+							    $this->_pagehead($pdf, $object, 0, $outputlangs);
507
+							}
483 508
 						}
484 509
 						if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
485 510
 						{
486 511
 							if ($pagenb == 1)
487 512
 							{
488 513
 								$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
489
-							}
490
-							else
514
+							} else
491 515
 							{
492 516
 								$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
493 517
 							}
494 518
 							$this->_pagefoot($pdf,$object,$outputlangs,1);
495 519
 							// New page
496 520
 							$pdf->AddPage();
497
-							if (! empty($tplidx)) $pdf->useTemplate($tplidx);
521
+							if (! empty($tplidx)) {
522
+							    $pdf->useTemplate($tplidx);
523
+							}
498 524
 							$pagenb++;
499
-							if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
525
+							if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
526
+							    $this->_pagehead($pdf, $object, 0, $outputlangs);
527
+							}
500 528
 						}
501 529
 					}
502 530
 
@@ -538,8 +566,7 @@  discard block
 block discarded – undo
538 566
 						$pdf->SetXY($this->postotalht, $curY);
539 567
 						$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, price(price2num($totalvaluesell,'MT'), 0, $outputlangs), 0, 'R', 0);
540 568
 					}
541
-				}
542
-				else
569
+				} else
543 570
 				{
544 571
 					dol_print_error($db);
545 572
 				}
@@ -563,8 +590,7 @@  discard block
 block discarded – undo
563 590
 
564 591
 					$tab_height = $tab_height - $height_note;
565 592
 					$tab_top = $nexY+6;
566
-				}
567
-				else
593
+				} else
568 594
 				{
569 595
 					$height_note=0;
570 596
 				}
@@ -776,8 +802,7 @@  discard block
 block discarded – undo
776 802
 				{
777 803
 					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
778 804
 					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
779
-				}
780
-				else
805
+				} else
781 806
 				{
782 807
 					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
783 808
 					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
@@ -793,7 +818,9 @@  discard block
 block discarded – undo
793 818
 
794 819
 				// Pied de page
795 820
 				$this->_pagefoot($pdf,$object,$outputlangs);
796
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
821
+				if (method_exists($pdf,'AliasNbPages')) {
822
+				    $pdf->AliasNbPages();
823
+				}
797 824
 
798 825
 				$pdf->Close();
799 826
 
@@ -805,20 +832,19 @@  discard block
 block discarded – undo
805 832
 				global $action;
806 833
 				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
807 834
 
808
-				if (! empty($conf->global->MAIN_UMASK))
809
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
835
+				if (! empty($conf->global->MAIN_UMASK)) {
836
+									@chmod($file, octdec($conf->global->MAIN_UMASK));
837
+				}
810 838
 
811 839
 				$this->result = array('fullpath'=>$file);
812 840
 
813 841
 				return 1;   // Pas d'erreur
814
-			}
815
-			else
842
+			} else
816 843
 			{
817 844
 				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
818 845
 				return 0;
819 846
 			}
820
-		}
821
-		else
847
+		} else
822 848
 		{
823 849
 			$this->error=$langs->trans("ErrorConstantNotDefined","PRODUCT_OUTPUTDIR");
824 850
 			return 0;
@@ -845,7 +871,9 @@  discard block
 block discarded – undo
845 871
 
846 872
 	    // Force to disable hidetop and hidebottom
847 873
 	    $hidebottom=0;
848
-	    if ($hidetop) $hidetop=-1;
874
+	    if ($hidetop) {
875
+	        $hidetop=-1;
876
+	    }
849 877
 
850 878
 	    $currency = !empty($currency) ? $currency : $conf->currency;
851 879
 	    $default_font_size = pdf_getPDFFontSize($outputlangs);
@@ -861,7 +889,9 @@  discard block
 block discarded – undo
861 889
 	        $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
862 890
 
863 891
 	        //$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));
892
+	        if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
893
+	            $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));
894
+	        }
865 895
 	    }
866 896
 
867 897
 	    $pdf->SetDrawColor(128,128,128);
@@ -952,8 +982,11 @@  discard block
 block discarded – undo
952 982
 
953 983
 	    $default_font_size = pdf_getPDFFontSize($outputlangs);
954 984
 
955
-	    if ($object->type == 1) $titlekey='ServiceSheet';
956
-	    else $titlekey='StockSheet';
985
+	    if ($object->type == 1) {
986
+	        $titlekey='ServiceSheet';
987
+	    } else {
988
+	        $titlekey='StockSheet';
989
+	    }
957 990
 
958 991
 	    pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
959 992
 
@@ -979,16 +1012,14 @@  discard block
 block discarded – undo
979 1012
 	        {
980 1013
 	            $height=pdf_getHeightForLogo($logo);
981 1014
 	            $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
982
-	        }
983
-	        else
1015
+	        } else
984 1016
 	        {
985 1017
 	            $pdf->SetTextColor(200,0,0);
986 1018
 	            $pdf->SetFont('','B', $default_font_size -2);
987 1019
 	            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
988 1020
 	            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
989 1021
 	        }
990
-	    }
991
-	    else
1022
+	    } else
992 1023
 	    {
993 1024
 	        $text=$this->emetteur->name;
994 1025
 	        $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
@@ -1031,8 +1062,7 @@  discard block
 block discarded – undo
1031 1062
 		if(!empty($object->fk_parent) && $e->fetch($object->fk_parent) > 0)
1032 1063
 		{
1033 1064
 			$pdf->MultiCell(150, 3, $e->libelle, '', 'R');
1034
-		}
1035
-		else
1065
+		} else
1036 1066
 		{
1037 1067
 			$pdf->MultiCell(150, 3, $outputlangs->transnoentities("None"), '', 'R');
1038 1068
 		}
@@ -1070,8 +1100,7 @@  discard block
 block discarded – undo
1070 1100
 		{
1071 1101
 			$obj = $db->fetch_object($resqlbis);
1072 1102
 			$lastmovementdate=$db->jdate($obj->datem);
1073
-		}
1074
-		else
1103
+		} else
1075 1104
 		{
1076 1105
 			dol_print_error($db);
1077 1106
 		}
@@ -1079,8 +1108,7 @@  discard block
 block discarded – undo
1079 1108
 		if ($lastmovementdate)
1080 1109
 		{
1081 1110
 			$toWrite = dol_print_date($lastmovementdate,'dayhour').' ';
1082
-		}
1083
-		else
1111
+		} else
1084 1112
 		{
1085 1113
 			$toWrite = $outputlangs->transnoentities("None");
1086 1114
 		}
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/stock/doc/pdf_stdmovement.modules.php 3 patches
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.
Spacing   +331 added lines, -331 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 */
119 119
 	public function __construct($db)
120 120
 	{
121
-		global $conf,$langs,$mysoc;
121
+		global $conf, $langs, $mysoc;
122 122
 
123 123
 		// Load traductions files requiredby by page
124 124
 		$langs->loadLangs(array("main", "companies"));
@@ -129,54 +129,54 @@  discard block
 block discarded – undo
129 129
 
130 130
 		// Dimension page pour format A4
131 131
 		$this->type = 'pdf';
132
-		$formatarray=pdf_getFormat();
132
+		$formatarray = pdf_getFormat();
133 133
 		$this->page_largeur = $formatarray['width'];
134 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;
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 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
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 145
 
146 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
147
+		$this->emetteur = $mysoc;
148
+		if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
149 149
 
150 150
 		// Define position of columns
151 151
 		$this->wref = 15;
152 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
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 165
 		if ($this->page_largeur < 210) // To work with US executive format
166 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;
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 174
 		}
175
-		$this->tva=array();
176
-		$this->localtax1=array();
177
-		$this->localtax2=array();
178
-		$this->atleastoneratenotnull=0;
179
-		$this->atleastonediscount=0;
175
+		$this->tva = array();
176
+		$this->localtax1 = array();
177
+		$this->localtax2 = array();
178
+		$this->atleastoneratenotnull = 0;
179
+		$this->atleastonediscount = 0;
180 180
 	}
181 181
 
182 182
 
@@ -192,14 +192,14 @@  discard block
 block discarded – undo
192 192
 	 *  @param		int			$hideref			Do not show ref
193 193
 	 *	@return		int         					1 if OK, <=0 if KO
194 194
 	 */
195
-	function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
195
+	function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
196 196
 	{
197 197
         // phpcs:enable
198
-		global $user,$langs,$conf,$mysoc,$db,$hookmanager;
198
+		global $user, $langs, $conf, $mysoc, $db, $hookmanager;
199 199
 
200
-		if (! is_object($outputlangs)) $outputlangs=$langs;
200
+		if (!is_object($outputlangs)) $outputlangs = $langs;
201 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';
202
+		if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1';
203 203
 
204 204
 		// Load traductions files requiredby by page
205 205
 		$outputlangs->loadLangs(array("main", "dict", "companies", "bills", "stocks", "orders", "deliveries"));
@@ -208,15 +208,15 @@  discard block
 block discarded – undo
208 208
 	 * TODO: get from object
209 209
 	 */
210 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';
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 218
 
219
-		$idproduct = GETPOST('idproduct','int');
219
+		$idproduct = GETPOST('idproduct', 'int');
220 220
 		$year = GETPOST("year");
221 221
 		$month = GETPOST("month");
222 222
 		$search_ref = GETPOST('search_ref', 'alpha');
@@ -228,18 +228,18 @@  discard block
 block discarded – undo
228 228
 		$search_user = trim(GETPOST("search_user"));
229 229
 		$search_batch = trim(GETPOST("search_batch"));
230 230
 		$search_qty = trim(GETPOST("search_qty"));
231
-		$search_type_mouvement=GETPOST('search_type_mouvement','int');
231
+		$search_type_mouvement = GETPOST('search_type_mouvement', 'int');
232 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');
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 237
 		if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
238 238
 		$offset = $limit * $page;
239
-		if (! $sortfield) $sortfield="m.datem";
240
-		if (! $sortorder) $sortorder="DESC";
239
+		if (!$sortfield) $sortfield = "m.datem";
240
+		if (!$sortorder) $sortorder = "DESC";
241 241
 
242
-		$pdluoid=GETPOST('pdluoid','int');
242
+		$pdluoid = GETPOST('pdluoid', 'int');
243 243
 
244 244
 		// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
245 245
 		$hookmanager->initHooks(array('movementlist'));
@@ -247,68 +247,68 @@  discard block
 block discarded – undo
247 247
 
248 248
 		// fetch optionals attributes and labels
249 249
 		$extralabels = $extrafields->fetch_name_optionals_label('movement');
250
-		$search_array_options=$extrafields->getOptionalsFromPost('movement','','search_');
250
+		$search_array_options = $extrafields->getOptionalsFromPost('movement', '', 'search_');
251 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);
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 257
 
258 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";
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 265
 		// Add fields from extrafields
266
-		foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
266
+		foreach ($extrafields->attribute_label as $key => $val) $sql .= ($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
267 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";
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 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."'";
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 283
 		if ($month > 0)
284 284
 		{
285 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))."'";
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 287
 			else
288
-			$sql.= " AND date_format(m.datem, '%m') = '$month'";
288
+			$sql .= " AND date_format(m.datem, '%m') = '$month'";
289 289
 		}
290 290
 		else if ($year > 0)
291 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))."'";
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 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)."'";
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 305
 		// Add where from extra fields
306 306
 		include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
307 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);
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 312
 
313 313
 		$nbtotalofrecords = '';
314 314
 		if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 			}
323 323
 		}
324 324
 
325
-		if(empty($search_inventorycode)) $sql.= $db->plimit($limit+1, $offset);
325
+		if (empty($search_inventorycode)) $sql .= $db->plimit($limit + 1, $offset);
326 326
 
327 327
 
328 328
 		$resql = $db->query($sql);
@@ -357,44 +357,44 @@  discard block
 block discarded – undo
357 357
 
358 358
 				$num = $db->num_rows($resql);
359 359
 
360
-				$arrayofselected=is_array($toselect)?$toselect:array();
360
+				$arrayofselected = is_array($toselect) ? $toselect : array();
361 361
 
362 362
 				$i = 0;
363
-				$help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
363
+				$help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
364 364
 				if ($msid) $texte = $langs->trans('StockMovementForId', $msid);
365 365
 				else
366 366
 				{
367 367
 					$texte = $langs->trans("ListOfStockMovements");
368
-					if ($id) $texte.=' ('.$langs->trans("ForThisWarehouse").')';
368
+					if ($id) $texte .= ' ('.$langs->trans("ForThisWarehouse").')';
369 369
 				}
370 370
 			}
371 371
 
372 372
 			// Definition of $dir and $file
373 373
 			if ($object->specimen)
374 374
 			{
375
-				$dir = $conf->stock->dir_output . "/movement";
376
-				$file = $dir . "/SPECIMEN.pdf";
375
+				$dir = $conf->stock->dir_output."/movement";
376
+				$file = $dir."/SPECIMEN.pdf";
377 377
 			}
378 378
 			else
379 379
 			{
380 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";
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 385
 			}
386 386
 
387 387
 			$stockFournisseur = new ProductFournisseur($this->db);
388 388
 			$supplierprices = $stockFournisseur->list_product_fournisseur_price($object->id);
389 389
 			$object->supplierprices = $supplierprices;
390 390
 
391
-			$productstatic=new Product($db);
391
+			$productstatic = new Product($db);
392 392
 
393
-			if (! file_exists($dir))
393
+			if (!file_exists($dir))
394 394
 			{
395 395
 				if (dol_mkdir($dir) < 0)
396 396
 				{
397
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
397
+					$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
398 398
 					return -1;
399 399
 				}
400 400
 			}
@@ -402,24 +402,24 @@  discard block
 block discarded – undo
402 402
 			if (file_exists($dir))
403 403
 			{
404 404
 				// Add pdfgeneration hook
405
-				if (! is_object($hookmanager))
405
+				if (!is_object($hookmanager))
406 406
 				{
407 407
 					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
408
-					$hookmanager=new HookManager($this->db);
408
+					$hookmanager = new HookManager($this->db);
409 409
 				}
410 410
 				$hookmanager->initHooks(array('pdfgeneration'));
411
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
411
+				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
412 412
 				global $action;
413
-				$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
413
+				$reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
414 414
 
415 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);
416
+				$pdf = pdf_getInstance($this->format);
417
+				$default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
418
+				$pdf->SetAutoPageBreak(1, 0);
419 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)
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
                 {
@@ -428,37 +428,37 @@  discard block
 block discarded – undo
428 428
                 }
429 429
                 $pdf->SetFont(pdf_getPDFFont($outputlangs));
430 430
                 // Set path to the background PDF File
431
-                if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
431
+                if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
432 432
                 {
433 433
                     $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
434 434
                     $tplidx = $pdf->importPage(1);
435 435
                 }
436 436
 
437 437
 				$pdf->Open();
438
-				$pagenb=0;
439
-				$pdf->SetDrawColor(128,128,128);
438
+				$pagenb = 0;
439
+				$pdf->SetDrawColor(128, 128, 128);
440 440
 
441 441
 				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
442 442
 				$pdf->SetSubject($outputlangs->transnoentities("Stock"));
443 443
 				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
444 444
 				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
445 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);
446
+				if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
447 447
 
448
-				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
448
+				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
449 449
 
450 450
 
451 451
 				// New page
452 452
 				$pdf->AddPage();
453
-				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
453
+				if (!empty($tplidx)) $pdf->useTemplate($tplidx);
454 454
 				$pagenb++;
455 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);
456
+				$pdf->SetFont('', '', $default_font_size - 1);
457
+				$pdf->MultiCell(0, 3, ''); // Set interline to 3
458
+				$pdf->SetTextColor(0, 0, 0);
459 459
 
460 460
 				$tab_top = 42;
461
-				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
461
+				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10);
462 462
 				$tab_height = 130;
463 463
 				$tab_height_newpage = 150;
464 464
 
@@ -468,12 +468,12 @@  discard block
 block discarded – undo
468 468
 				/*                                                                            */
469 469
 				/* ************************************************************************** */
470 470
 
471
-				$nexY+=5;
471
+				$nexY += 5;
472 472
 				$nexY = $pdf->GetY();
473
-				$nexY+=10;
473
+				$nexY += 10;
474 474
 
475
-				$totalunit=0;
476
-				$totalvalue=$totalvaluesell=0;
475
+				$totalunit = 0;
476
+				$totalvalue = $totalvaluesell = 0;
477 477
 				$arrayofuniqueproduct = array();
478 478
 
479 479
 				//dol_syslog('List products', LOG_DEBUG);
@@ -483,18 +483,18 @@  discard block
 block discarded – undo
483 483
 					$num = $db->num_rows($resql);
484 484
 					$i = 0;
485 485
 					$nblignes = $num;
486
-					for ($i = 0 ; $i < $nblignes ; $i++)
486
+					for ($i = 0; $i < $nblignes; $i++)
487 487
 					{
488 488
 						$objp = $db->fetch_object($resql);
489 489
 
490 490
 						// Multilangs
491
-						if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
491
+						if (!empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
492 492
 						{
493 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";
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 498
 
499 499
 							$result = $db->query($sql);
500 500
 							if ($result)
@@ -505,92 +505,92 @@  discard block
 block discarded – undo
505 505
 						}
506 506
 
507 507
 						$curY = $nexY;
508
-						$pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
509
-						$pdf->SetTextColor(0,0,0);
508
+						$pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
509
+						$pdf->SetTextColor(0, 0, 0);
510 510
 
511 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();
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 514
 
515 515
 						// Description of product line
516
-						$curX = $this->posxdesc-1;
516
+						$curX = $this->posxdesc - 1;
517 517
 
518
-						$showpricebeforepagebreak=1;
518
+						$showpricebeforepagebreak = 1;
519 519
 
520 520
 						$pdf->startTransaction();
521
-						pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc);
522
-						$pageposafter=$pdf->getPage();
521
+						pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc);
522
+						$pageposafter = $pdf->getPage();
523 523
 						if ($pageposafter > $pageposbefore)	// There is a pagebreak
524 524
 						{
525 525
 							$pdf->rollbackTransaction(true);
526
-							$pageposafter=$pageposbefore;
526
+							$pageposafter = $pageposbefore;
527 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
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 533
 							{
534
-								if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
534
+								if ($i == ($nblignes - 1))	// No more lines, and no space left to show total, so we create a new page
535 535
 								{
536
-									$pdf->AddPage('','',true);
537
-									if (! empty($tplidx)) $pdf->useTemplate($tplidx);
536
+									$pdf->AddPage('', '', true);
537
+									if (!empty($tplidx)) $pdf->useTemplate($tplidx);
538 538
 									if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
539
-									$pdf->setPage($pageposafter+1);
539
+									$pdf->setPage($pageposafter + 1);
540 540
 								}
541 541
 							}
542 542
 							else
543 543
 							{
544 544
 								// We found a page break
545
-								$showpricebeforepagebreak=0;
545
+								$showpricebeforepagebreak = 0;
546 546
 							}
547 547
 						}
548 548
 						else	// No pagebreak
549 549
 						{
550 550
 							$pdf->commitTransaction();
551 551
 						}
552
-						$posYAfterDescription=$pdf->GetY();
552
+						$posYAfterDescription = $pdf->GetY();
553 553
 
554 554
 						$nexY = $pdf->GetY();
555
-						$pageposafter=$pdf->getPage();
555
+						$pageposafter = $pdf->getPage();
556 556
 
557 557
 						$pdf->setPage($pageposbefore);
558 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.
559
+						$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
560 560
 
561 561
 						// We suppose that a too long description is moved completely on next page
562 562
 						if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
563 563
 							$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
564 564
 						}
565 565
 
566
-						$pdf->SetFont('','',  $default_font_size - 1);   // On repositionne la police par defaut
566
+						$pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
567 567
 
568 568
 						// $objp = $db->fetch_object($resql);
569 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;
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 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;
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 582
 
583 583
 						$productlot->id = $objp->lotid;
584
-						$productlot->batch= $objp->batch;
585
-						$productlot->eatby= $objp->eatby;
586
-						$productlot->sellby= $objp->sellby;
584
+						$productlot->batch = $objp->batch;
585
+						$productlot->eatby = $objp->eatby;
586
+						$productlot->sellby = $objp->sellby;
587 587
 
588
-						$warehousestatic->id=$objp->entrepot_id;
589
-						$warehousestatic->libelle=$objp->stock;
590
-						$warehousestatic->lieu=$objp->lieu;
588
+						$warehousestatic->id = $objp->entrepot_id;
589
+						$warehousestatic->libelle = $objp->stock;
590
+						$warehousestatic->lieu = $objp->lieu;
591 591
 
592
-						$arrayofuniqueproduct[$objp->rowid]=$objp->produit;
593
-						if(!empty($objp->fk_origin)) {
592
+						$arrayofuniqueproduct[$objp->rowid] = $objp->produit;
593
+						if (!empty($objp->fk_origin)) {
594 594
 							$origin = $movement->get_origin($objp->fk_origin, $objp->origintype);
595 595
 						} else {
596 596
 							$origin = '';
@@ -598,60 +598,60 @@  discard block
 block discarded – undo
598 598
 
599 599
 						// Id movement.
600 600
 						$pdf->SetXY($this->posxidref, $curY);
601
-						$pdf->MultiCell($this->posxdesc-$this->posxidref-0.8, 3, $objp->mid, 0, 'L');
601
+						$pdf->MultiCell($this->posxdesc - $this->posxidref - 0.8, 3, $objp->mid, 0, 'L');
602 602
 
603 603
 						// Date.
604 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');
605
+						$pdf->MultiCell($this->posxdesc - $this->posxdatemouv - 0.8, 6, dol_print_date($db->jdate($objp->datem), 'dayhour'), 0, 'L');
606 606
 
607 607
 						// Ref.
608 608
 						$pdf->SetXY($this->posxdesc, $curY);
609
-						$pdf->MultiCell($this->posxlabel-$this->posxdesc-0.8, 3, $productstatic->ref, 0, 'L');
609
+						$pdf->MultiCell($this->posxlabel - $this->posxdesc - 0.8, 3, $productstatic->ref, 0, 'L');
610 610
 
611 611
 						// Label
612
-						$pdf->SetXY($this->posxlabel+0.8, $curY);
613
-						$pdf->MultiCell($this->posxqty-$this->posxlabel-0.8, 6, $productstatic->label, 0, 'L');
612
+						$pdf->SetXY($this->posxlabel + 0.8, $curY);
613
+						$pdf->MultiCell($this->posxqty - $this->posxlabel - 0.8, 6, $productstatic->label, 0, 'L');
614 614
 
615 615
 						// Lot/serie
616 616
 						$pdf->SetXY($this->posxqty, $curY);
617
-						$pdf->MultiCell($this->posxup-$this->posxqty-0.8, 3, $productlot->batch, 0, 'R');
617
+						$pdf->MultiCell($this->posxup - $this->posxqty - 0.8, 3, $productlot->batch, 0, 'R');
618 618
 
619 619
 						// Inv. code
620 620
 						$pdf->SetXY($this->posxup, $curY);
621
-						$pdf->MultiCell($this->posxunit-$this->posxup-0.8, 3, $objp->inventorycode, 0, 'R');
621
+						$pdf->MultiCell($this->posxunit - $this->posxup - 0.8, 3, $objp->inventorycode, 0, 'R');
622 622
 
623 623
 						// Label mouvement
624 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');
625
+						$pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 3, $objp->label, 0, 'R');
626
+						$totalvalue += price2num($objp->ppmp * $objp->value, 'MT');
627 627
 
628 628
 						// Origin
629
-						$pricemin=$objp->price;
629
+						$pricemin = $objp->price;
630 630
 						$pdf->SetXY($this->posxdiscount, $curY);
631
-						$pdf->MultiCell($this->postotalht-$this->posxdiscount-0.8, 3, $origin, 0, 'R', 0);
631
+						$pdf->MultiCell($this->postotalht - $this->posxdiscount - 0.8, 3, $origin, 0, 'R', 0);
632 632
 
633 633
 						// Qty
634
-						$valtoshow=price2num($objp->qty, 'MS');
635
-						$towrite = (empty($valtoshow)?'0':$valtoshow);
636
-						$totalunit+=$objp->qty;
634
+						$valtoshow = price2num($objp->qty, 'MS');
635
+						$towrite = (empty($valtoshow) ? '0' : $valtoshow);
636
+						$totalunit += $objp->qty;
637 637
 
638 638
 						$pdf->SetXY($this->postotalht, $curY);
639
-						$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $objp->qty, 0, 'R', 0);
639
+						$pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $objp->qty, 0, 'R', 0);
640 640
 
641
-						$totalvaluesell+=price2num($pricemin*$objp->value,'MT');
641
+						$totalvaluesell += price2num($pricemin * $objp->value, 'MT');
642 642
 
643
-						$nexY+=3.5;    // Passe espace entre les lignes
643
+						$nexY += 3.5; // Passe espace entre les lignes
644 644
 						// Add line
645
-						if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
645
+						if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
646 646
 						{
647 647
 							$pdf->setPage($pageposafter);
648
-							$pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
648
+							$pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
649 649
 							//$pdf->SetDrawColor(190,190,200);
650
-							$pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
650
+							$pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
651 651
 							$pdf->SetLineStyle(array('dash'=>0));
652 652
 						}
653 653
 
654
-						$nexY+=2;    // Passe espace entre les lignes
654
+						$nexY += 2; // Passe espace entre les lignes
655 655
 
656 656
 						// Detect if some page were added automatically and output _tableau for past pages
657 657
 						while ($pagenb < $pageposafter)
@@ -665,13 +665,13 @@  discard block
 block discarded – undo
665 665
 							{
666 666
 								$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
667 667
 							}
668
-							$this->_pagefoot($pdf,$object,$outputlangs,1);
668
+							$this->_pagefoot($pdf, $object, $outputlangs, 1);
669 669
 							$pagenb++;
670 670
 							$pdf->setPage($pagenb);
671
-							$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
671
+							$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
672 672
 							if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
673 673
 						}
674
-						if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
674
+						if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak)
675 675
 						{
676 676
 							if ($pagenb == 1)
677 677
 							{
@@ -681,10 +681,10 @@  discard block
 block discarded – undo
681 681
 							{
682 682
 								$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
683 683
 							}
684
-							$this->_pagefoot($pdf,$object,$outputlangs,1);
684
+							$this->_pagefoot($pdf, $object, $outputlangs, 1);
685 685
 							// New page
686 686
 							$pdf->AddPage();
687
-							if (! empty($tplidx)) $pdf->useTemplate($tplidx);
687
+							if (!empty($tplidx)) $pdf->useTemplate($tplidx);
688 688
 							$pagenb++;
689 689
 							if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
690 690
 						}
@@ -696,23 +696,23 @@  discard block
 block discarded – undo
696 696
 					 * footer table
697 697
 					 */
698 698
 					$nexY = $pdf->GetY();
699
-					$nexY+=5;
699
+					$nexY += 5;
700 700
 					$curY = $nexY;
701 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);
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 704
 					$pdf->SetLineStyle(array('dash'=>0));
705 705
 
706
-					$pdf->SetFont('','B',$default_font_size-1);
707
-					$pdf->SetTextColor(0,0,120);
706
+					$pdf->SetFont('', 'B', $default_font_size - 1);
707
+					$pdf->SetTextColor(0, 0, 120);
708 708
 
709 709
 					// Total
710 710
 					$pdf->SetXY($this->posxidref, $curY);
711
-					$pdf->MultiCell($this->posxdesc-$this->posxidref, 3, $langs->trans("Total"), 0, 'L');
711
+					$pdf->MultiCell($this->posxdesc - $this->posxidref, 3, $langs->trans("Total"), 0, 'L');
712 712
 
713 713
 					// Total Qty
714 714
 					$pdf->SetXY($this->postotalht, $curY);
715
-					$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $totalunit, 0, 'R', 0);
715
+					$pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $totalunit, 0, 'R', 0);
716 716
 				}
717 717
 				else
718 718
 				{
@@ -721,48 +721,48 @@  discard block
 block discarded – undo
721 721
 
722 722
 				if ($notetoshow)
723 723
 				{
724
-					$substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
724
+					$substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
725 725
 					complete_substitutions_array($substitutionarray, $outputlangs, $object);
726 726
 					$notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
727 727
 
728 728
 					$tab_top = 88;
729 729
 
730
-					$pdf->SetFont('','', $default_font_size - 1);
731
-					$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
730
+					$pdf->SetFont('', '', $default_font_size - 1);
731
+					$pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
732 732
 					$nexY = $pdf->GetY();
733
-					$height_note=$nexY-$tab_top;
733
+					$height_note = $nexY - $tab_top;
734 734
 
735 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);
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 738
 
739 739
 					$tab_height = $tab_height - $height_note;
740
-					$tab_top = $nexY+6;
740
+					$tab_top = $nexY + 6;
741 741
 				}
742 742
 				else
743 743
 				{
744
-					$height_note=0;
744
+					$height_note = 0;
745 745
 				}
746 746
 
747 747
 				$iniY = $tab_top + 7;
748 748
 				$curY = $tab_top + 7;
749 749
 				$nexY = $tab_top + 7;
750 750
 
751
-				$tab_top = $tab_top_newpage+21;
751
+				$tab_top = $tab_top_newpage + 21;
752 752
 
753 753
 				// Show square
754 754
 				if ($pagenb == 1)
755 755
 				{
756 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;
757
+					$bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
758 758
 				}
759 759
 				else
760 760
 				{
761 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;
762
+					$bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
763 763
 				}
764 764
 
765
-				$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
765
+				$bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
766 766
 
767 767
 				// Affiche zone infos
768 768
 				//$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
@@ -771,35 +771,35 @@  discard block
 block discarded – undo
771 771
 				//$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
772 772
 
773 773
 				// Pied de page
774
-				$this->_pagefoot($pdf,$object,$outputlangs);
775
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
774
+				$this->_pagefoot($pdf, $object, $outputlangs);
775
+				if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
776 776
 
777 777
 				$pdf->Close();
778 778
 
779
-				$pdf->Output($file,'F');
779
+				$pdf->Output($file, 'F');
780 780
 
781 781
 				// Add pdfgeneration hook
782 782
 				$hookmanager->initHooks(array('pdfgeneration'));
783
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
783
+				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
784 784
 				global $action;
785
-				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
785
+				$reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
786 786
 
787
-				if (! empty($conf->global->MAIN_UMASK))
787
+				if (!empty($conf->global->MAIN_UMASK))
788 788
 					@chmod($file, octdec($conf->global->MAIN_UMASK));
789 789
 
790 790
 				$this->result = array('fullpath'=>$file);
791 791
 
792
-				return 1;   // Pas d'erreur
792
+				return 1; // Pas d'erreur
793 793
 			}
794 794
 			else
795 795
 			{
796
-				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
796
+				$this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
797 797
 				return 0;
798 798
 			}
799 799
 		}
800 800
 		else
801 801
 		{
802
-			$this->error=$langs->trans("ErrorConstantNotDefined","PRODUCT_OUTPUTDIR");
802
+			$this->error = $langs->trans("ErrorConstantNotDefined", "PRODUCT_OUTPUTDIR");
803 803
 			return 0;
804 804
 		}
805 805
 	}
@@ -818,74 +818,74 @@  discard block
 block discarded – undo
818 818
 	 *   @param		string		$currency		Currency code
819 819
 	 *   @return	void
820 820
 	 */
821
-	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
821
+	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
822 822
 	{
823 823
 	    global $conf;
824 824
 
825 825
 	    // Force to disable hidetop and hidebottom
826
-	    $hidebottom=0;
827
-	    if ($hidetop) $hidetop=-1;
826
+	    $hidebottom = 0;
827
+	    if ($hidetop) $hidetop = -1;
828 828
 
829 829
 	    $currency = !empty($currency) ? $currency : $conf->currency;
830 830
 	    $default_font_size = pdf_getPDFFontSize($outputlangs);
831 831
 
832 832
 	    // Amount in (at tab_top - 1)
833
-	    $pdf->SetTextColor(0,0,0);
834
-	    $pdf->SetFont('','', $default_font_size - 2);
833
+	    $pdf->SetTextColor(0, 0, 0);
834
+	    $pdf->SetFont('', '', $default_font_size - 2);
835 835
 
836 836
 	    if (empty($hidetop))
837 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);
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 840
 	        $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
841 841
 
842 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));
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 844
 	    }
845 845
 
846
-	    $pdf->SetDrawColor(128,128,128);
847
-	    $pdf->SetFont('','B', $default_font_size - 3);
846
+	    $pdf->SetDrawColor(128, 128, 128);
847
+	    $pdf->SetFont('', 'B', $default_font_size - 3);
848 848
 
849 849
 	    // Output Rect
850 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 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);
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 855
 		$pdf->SetLineStyle(array('dash'=>0));
856
-		$pdf->SetDrawColor(128,128,128);
857
-		$pdf->SetTextColor(0,0,120);
856
+		$pdf->SetDrawColor(128, 128, 128);
857
+		$pdf->SetTextColor(0, 0, 120);
858 858
 
859 859
 		//Ref mouv
860 860
 	    if (empty($hidetop))
861 861
 	    {
862 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');
863
+	        $pdf->SetXY($this->posxidref, $tab_top + 1);
864
+	        $pdf->MultiCell($this->posxdatemouv - $this->posxdatemouv - 0.8, 3, $outputlangs->transnoentities("Ref"), '', 'L');
865 865
 	    }
866 866
 
867 867
 		//Date mouv
868 868
 		//$pdf->line($this->posxlabel-1, $tab_top, $this->posxlabel-1, $tab_top + $tab_height);
869 869
 		if (empty($hidetop))
870 870
 		{
871
-			$pdf->SetXY($this->posxdatemouv, $tab_top+1);
872
-			$pdf->MultiCell($this->posxdesc-$this->posxdatemouv,2, $outputlangs->transnoentities("Date"),'','C');
871
+			$pdf->SetXY($this->posxdatemouv, $tab_top + 1);
872
+			$pdf->MultiCell($this->posxdesc - $this->posxdatemouv, 2, $outputlangs->transnoentities("Date"), '', 'C');
873 873
 		}
874 874
 
875 875
 		//Ref Product
876 876
 	    //$pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
877 877
 	    if (empty($hidetop))
878 878
 	    {
879
-	        $pdf->SetXY($this->posxdesc-1, $tab_top+1);
880
-	        $pdf->MultiCell($this->posxlabel-$this->posxdesc,2, $outputlangs->transnoentities("Ref. Product"),'','C');
879
+	        $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
880
+	        $pdf->MultiCell($this->posxlabel - $this->posxdesc, 2, $outputlangs->transnoentities("Ref. Product"), '', 'C');
881 881
 	    }
882 882
 
883 883
 		//Label Product
884 884
 	    //$pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
885 885
 	    if (empty($hidetop))
886 886
 	    {
887
-	        $pdf->SetXY($this->posxlabel-1, $tab_top+1);
888
-			$pdf->MultiCell($this->posxqty-$this->posxlabel,2, $outputlangs->transnoentities("Label"),'','C');
887
+	        $pdf->SetXY($this->posxlabel - 1, $tab_top + 1);
888
+			$pdf->MultiCell($this->posxqty - $this->posxlabel, 2, $outputlangs->transnoentities("Label"), '', 'C');
889 889
 	    }
890 890
 
891 891
 		//Lot/serie Product
@@ -893,44 +893,44 @@  discard block
 block discarded – undo
893 893
 		if (empty($hidetop))
894 894
 		{
895 895
 			$pdf->SetXY($this->posxqty, $tab_top + 1);
896
-			$pdf->MultiCell($this->posxup - $this->posxqty, 2, $outputlangs->transnoentities("Lot/Série"), '','C');
896
+			$pdf->MultiCell($this->posxup - $this->posxqty, 2, $outputlangs->transnoentities("Lot/Série"), '', 'C');
897 897
 		}
898 898
 
899 899
 		//Code Inv
900 900
 	    //$pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
901 901
 	    if (empty($hidetop))
902 902
 	    {
903
-			$pdf->SetXY($this->posxup-1, $tab_top+1);
904
-			$pdf->MultiCell($this->posxunit-$this->posxup,2, $outputlangs->transnoentities("Inventory Code"),'','C');
903
+			$pdf->SetXY($this->posxup - 1, $tab_top + 1);
904
+			$pdf->MultiCell($this->posxunit - $this->posxup, 2, $outputlangs->transnoentities("Inventory Code"), '', 'C');
905 905
 	    }
906 906
 
907 907
 		//Label mouvement
908 908
 	    //$pdf->line($this->posxunit, $tab_top, $this->posxunit, $tab_top + $tab_height);
909 909
 	    if (empty($hidetop))
910 910
 	    {
911
-	        $pdf->SetXY($this->posxunit, $tab_top+1);
912
-	        $pdf->MultiCell($this->posxdiscount-$this->posxunit,2, $outputlangs->transnoentities("Label Mouvement"),'','C');
911
+	        $pdf->SetXY($this->posxunit, $tab_top + 1);
912
+	        $pdf->MultiCell($this->posxdiscount - $this->posxunit, 2, $outputlangs->transnoentities("Label Mouvement"), '', 'C');
913 913
 	    }
914 914
 
915 915
 		//Origin
916 916
 	    //$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
917 917
 	    if (empty($hidetop))
918 918
 	    {
919
-	        $pdf->SetXY($this->posxdiscount+2, $tab_top+1);
920
-	        $pdf->MultiCell($this->postotalht-$this->posxdiscount-0.8,2, $outputlangs->transnoentities("Origin"),'','C');
919
+	        $pdf->SetXY($this->posxdiscount + 2, $tab_top + 1);
920
+	        $pdf->MultiCell($this->postotalht - $this->posxdiscount - 0.8, 2, $outputlangs->transnoentities("Origin"), '', 'C');
921 921
 	    }
922 922
 
923 923
 		//Qty
924 924
 	    //$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
925 925
 	    if (empty($hidetop))
926 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');
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 929
 	    }
930 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);
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 934
 		$pdf->SetLineStyle(array('dash'=>0));
935 935
 	}
936 936
 
@@ -944,92 +944,92 @@  discard block
 block discarded – undo
944 944
 	 *  @param	string		$titlekey		Translation key to show as title of document
945 945
 	 *  @return	void
946 946
 	 */
947
-	function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="")
947
+	function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey = "")
948 948
 	{
949
-	    global $conf,$langs,$db,$hookmanager;
949
+	    global $conf, $langs, $db, $hookmanager;
950 950
 
951 951
 	    // Load traductions files requiredby by page
952 952
 		$outputlangs->loadLangs(array("main", "propal", "companies", "bills", "orders", "stocks"));
953 953
 
954 954
 	    $default_font_size = pdf_getPDFFontSize($outputlangs);
955 955
 
956
-	    if ($object->type == 1) $titlekey='ServiceSheet';
957
-	    else $titlekey='StockSheet';
956
+	    if ($object->type == 1) $titlekey = 'ServiceSheet';
957
+	    else $titlekey = 'StockSheet';
958 958
 
959
-	    pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
959
+	    pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
960 960
 
961 961
 	    // Show Draft Watermark
962
-	    if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
962
+	    if ($object->statut == 0 && (!empty($conf->global->COMMANDE_DRAFT_WATERMARK)))
963 963
 	    {
964
-	        pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
964
+	        pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->COMMANDE_DRAFT_WATERMARK);
965 965
 	    }
966 966
 
967
-	    $pdf->SetTextColor(0,0,60);
968
-	    $pdf->SetFont('','B', $default_font_size + 3);
967
+	    $pdf->SetTextColor(0, 0, 60);
968
+	    $pdf->SetFont('', 'B', $default_font_size + 3);
969 969
 
970
-	    $posy=$this->marge_haute;
971
-	    $posx=$this->page_largeur-$this->marge_droite-100;
970
+	    $posy = $this->marge_haute;
971
+	    $posx = $this->page_largeur - $this->marge_droite - 100;
972 972
 
973
-	    $pdf->SetXY($this->marge_gauche,$posy);
973
+	    $pdf->SetXY($this->marge_gauche, $posy);
974 974
 
975 975
 	    // Logo
976
-	    $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
976
+	    $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
977 977
 	    if ($this->emetteur->logo)
978 978
 	    {
979 979
 	        if (is_readable($logo))
980 980
 	        {
981
-	            $height=pdf_getHeightForLogo($logo);
982
-	            $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
981
+	            $height = pdf_getHeightForLogo($logo);
982
+	            $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
983 983
 	        }
984 984
 	        else
985 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');
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 989
 	            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
990 990
 	        }
991 991
 	    }
992 992
 	    else
993 993
 	    {
994
-	        $text=$this->emetteur->name;
994
+	        $text = $this->emetteur->name;
995 995
 	        $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
996 996
 	    }
997 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");
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 1002
 	    $pdf->MultiCell(100, 3, $title, '', 'R');
1003 1003
 
1004
-	    $pdf->SetFont('','B',$default_font_size);
1004
+	    $pdf->SetFont('', 'B', $default_font_size);
1005 1005
 
1006
-	    $posy+=5;
1007
-	    $pdf->SetXY($posx,$posy);
1008
-	    $pdf->SetTextColor(0,0,60);
1006
+	    $posy += 5;
1007
+	    $pdf->SetXY($posx, $posy);
1008
+	    $pdf->SetTextColor(0, 0, 60);
1009 1009
 
1010
-	    $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->libelle), '', 'R');
1010
+	    $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->libelle), '', 'R');
1011 1011
 
1012
-	    $posy+=5;
1013
-	    $pdf->SetFont('','', $default_font_size - 1);
1014
-		$pdf->SetXY($posx,$posy);
1015
-	    $pdf->SetTextColor(0,0,60);
1012
+	    $posy += 5;
1013
+	    $pdf->SetFont('', '', $default_font_size - 1);
1014
+		$pdf->SetXY($posx, $posy);
1015
+	    $pdf->SetTextColor(0, 0, 60);
1016 1016
 	    $pdf->MultiCell(100, 3, $outputlangs->transnoentities("LocationSummary").' :', '', 'R');
1017 1017
 
1018
-		$posy+=4;
1019
-		$pdf->SetXY($posx-50,$posy);
1018
+		$posy += 4;
1019
+		$pdf->SetXY($posx - 50, $posy);
1020 1020
 		$pdf->MultiCell(150, 3, $object->lieu, '', 'R');
1021 1021
 
1022 1022
 
1023 1023
 		// Parent MouvementStock
1024
-		$posy+=4;
1025
-		$pdf->SetXY($posx,$posy);
1026
-		$pdf->SetTextColor(0,0,60);
1024
+		$posy += 4;
1025
+		$pdf->SetXY($posx, $posy);
1026
+		$pdf->SetTextColor(0, 0, 60);
1027 1027
 		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ParentWarehouse").' :', '', 'R');
1028 1028
 
1029
-		$posy+=4;
1030
-		$pdf->SetXY($posx-50,$posy);
1029
+		$posy += 4;
1030
+		$pdf->SetXY($posx - 50, $posy);
1031 1031
 		$e = new MouvementStock($db);
1032
-		if(!empty($object->fk_parent) && $e->fetch($object->fk_parent) > 0)
1032
+		if (!empty($object->fk_parent) && $e->fetch($object->fk_parent) > 0)
1033 1033
 		{
1034 1034
 			$pdf->MultiCell(150, 3, $e->libelle, '', 'R');
1035 1035
 		}
@@ -1040,25 +1040,25 @@  discard block
 block discarded – undo
1040 1040
 
1041 1041
 		// Description
1042 1042
 		$nexY = $pdf->GetY();
1043
-		$nexY+=5;
1044
-		$pdf->SetXY($posx,$posy);
1043
+		$nexY += 5;
1044
+		$pdf->SetXY($posx, $posy);
1045 1045
 		$pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("Description").' : </b>'.nl2br($object->description), 0, 1);
1046 1046
 		$nexY = $pdf->GetY();
1047 1047
 
1048
-		$calcproductsunique=$object->nb_different_products();
1049
-		$calcproducts=$object->nb_products();
1048
+		$calcproductsunique = $object->nb_different_products();
1049
+		$calcproducts = $object->nb_products();
1050 1050
 
1051 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);
1052
+		$pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("NumberOfDifferentProducts").' : </b>'.(empty($calcproductsunique['nb']) ? '0' : $calcproductsunique['nb']), 0, 1);
1053 1053
 		$nexY = $pdf->GetY();
1054 1054
 
1055 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);
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 1058
 		$nexY = $pdf->GetY();
1059 1059
 
1060 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);
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 1062
 		$nexY = $pdf->GetY();
1063 1063
 
1064 1064
 
@@ -1070,7 +1070,7 @@  discard block
 block discarded – undo
1070 1070
 		if ($resqlbis)
1071 1071
 		{
1072 1072
 			$obj = $db->fetch_object($resqlbis);
1073
-			$lastmovementdate=$db->jdate($obj->datem);
1073
+			$lastmovementdate = $db->jdate($obj->datem);
1074 1074
 		}
1075 1075
 		else
1076 1076
 		{
@@ -1079,7 +1079,7 @@  discard block
 block discarded – undo
1079 1079
 
1080 1080
 		if ($lastmovementdate)
1081 1081
 		{
1082
-			$toWrite = dol_print_date($lastmovementdate,'dayhour').' ';
1082
+			$toWrite = dol_print_date($lastmovementdate, 'dayhour').' ';
1083 1083
 		}
1084 1084
 		else
1085 1085
 		{
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
 	        }
1121 1121
 	    }*/
1122 1122
 
1123
-	    $posy+=2;
1123
+	    $posy += 2;
1124 1124
 
1125 1125
 	    // Show list of linked objects
1126 1126
 	    //$posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
@@ -1160,7 +1160,7 @@  discard block
 block discarded – undo
1160 1160
 	        */
1161 1161
 	    }
1162 1162
 
1163
-	    $pdf->SetTextColor(0,0,0);
1163
+	    $pdf->SetTextColor(0, 0, 0);
1164 1164
 	}
1165 1165
 
1166 1166
 	/**
@@ -1172,10 +1172,10 @@  discard block
 block discarded – undo
1172 1172
 	 *      @param	int			$hidefreetext		1=Hide free text
1173 1173
 	 *      @return	int								Return height of bottom margin including footer text
1174 1174
 	 */
1175
-	function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1175
+	function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1176 1176
 	{
1177 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);
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 1180
 	}
1181 1181
 }
Please login to merge, or discard this patch.
Braces   +159 added lines, -84 removed lines patch added patch discarded remove patch
@@ -145,7 +145,10 @@  discard block
 block discarded – undo
145 145
 
146 146
 		// Recupere emetteur
147 147
 		$this->emetteur=$mysoc;
148
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
148
+		if (! $this->emetteur->country_code) {
149
+		    $this->emetteur->country_code=substr($langs->defaultlang,-2);
150
+		}
151
+		// By default if not defined
149 152
 
150 153
 		// Define position of columns
151 154
 		$this->wref = 15;
@@ -160,11 +163,15 @@  discard block
 block discarded – undo
160 163
 		$this->posxdiscount=167;
161 164
 		$this->postotalht=180;
162 165
 
163
-		if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup;
166
+		if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
167
+		    $this->posxtva=$this->posxup;
168
+		}
164 169
 		$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
170
+		if ($this->page_largeur < 210) {
171
+		    // To work with US executive format
166 172
 		{
167 173
 			$this->posxpicture-=20;
174
+		}
168 175
 			$this->posxtva-=20;
169 176
 			$this->posxup-=20;
170 177
 			$this->posxqty-=20;
@@ -197,9 +204,13 @@  discard block
 block discarded – undo
197 204
         // phpcs:enable
198 205
 		global $user,$langs,$conf,$mysoc,$db,$hookmanager;
199 206
 
200
-		if (! is_object($outputlangs)) $outputlangs=$langs;
207
+		if (! is_object($outputlangs)) {
208
+		    $outputlangs=$langs;
209
+		}
201 210
 		// 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';
211
+		if (! empty($conf->global->MAIN_USE_FPDF)) {
212
+		    $outputlangs->charset_output='ISO-8859-1';
213
+		}
203 214
 
204 215
 		// Load traductions files requiredby by page
205 216
 		$outputlangs->loadLangs(array("main", "dict", "companies", "bills", "stocks", "orders", "deliveries"));
@@ -236,8 +247,12 @@  discard block
 block discarded – undo
236 247
 		$sortorder = GETPOST("sortorder",'alpha');
237 248
 		if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
238 249
 		$offset = $limit * $page;
239
-		if (! $sortfield) $sortfield="m.datem";
240
-		if (! $sortorder) $sortorder="DESC";
250
+		if (! $sortfield) {
251
+		    $sortfield="m.datem";
252
+		}
253
+		if (! $sortorder) {
254
+		    $sortorder="DESC";
255
+		}
241 256
 
242 257
 		$pdluoid=GETPOST('pdluoid','int');
243 258
 
@@ -263,7 +278,9 @@  discard block
 block discarded – undo
263 278
 		$sql.= " pl.rowid as lotid, pl.eatby, pl.sellby,";
264 279
 		$sql.= " u.login, u.photo, u.lastname, u.firstname";
265 280
 		// Add fields from extrafields
266
-		foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
281
+		foreach ($extrafields->attribute_label as $key => $val) {
282
+		    $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
283
+		}
267 284
 		// Add fields from hooks
268 285
 		$parameters=array();
269 286
 		$reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters);    // Note that $action and $object may have been modified by hook
@@ -271,37 +288,67 @@  discard block
 block discarded – undo
271 288
 		$sql.= " FROM ".MAIN_DB_PREFIX."entrepot as e,";
272 289
 		$sql.= " ".MAIN_DB_PREFIX."product as p,";
273 290
 		$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)";
291
+		if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) {
292
+		    $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."movement_extrafields as ef on (m.rowid = ef.fk_object)";
293
+		}
275 294
 		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON m.fk_user_author = u.rowid";
276 295
 		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON m.batch = pl.batch AND m.fk_product = pl.fk_product";
277 296
 		$sql.= " WHERE m.fk_product = p.rowid";
278
-		if ($msid > 0) $sql .= " AND m.rowid = ".$msid;
297
+		if ($msid > 0) {
298
+		    $sql .= " AND m.rowid = ".$msid;
299
+		}
279 300
 		$sql.= " AND m.fk_entrepot = e.rowid";
280 301
 		$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."'";
302
+		if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
303
+		    $sql.= " AND p.fk_product_type = 0";
304
+		}
305
+		if ($id > 0) {
306
+		    $sql.= " AND e.rowid ='".$id."'";
307
+		}
283 308
 		if ($month > 0)
284 309
 		{
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)
310
+			if ($year > 0) {
311
+						$sql.= " AND m.datem BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
312
+			} else {
313
+						$sql.= " AND date_format(m.datem, '%m') = '$month'";
314
+			}
315
+		} else if ($year > 0)
291 316
 		{
292 317
 			$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 318
 		}
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)."'";
319
+		if ($idproduct > 0) {
320
+		    $sql.= " AND p.rowid = '".$idproduct."'";
321
+		}
322
+		if (! empty($search_ref)) {
323
+		    $sql.= natural_search('m.rowid', $search_ref, 1);
324
+		}
325
+		if (! empty($search_movement)) {
326
+		    $sql.= natural_search('m.label', $search_movement);
327
+		}
328
+		if (! empty($search_inventorycode)) {
329
+		    $sql.= natural_search('m.inventorycode', $search_inventorycode);
330
+		}
331
+		if (! empty($search_product_ref)) {
332
+		    $sql.= natural_search('p.ref', $search_product_ref);
333
+		}
334
+		if (! empty($search_product)) {
335
+		    $sql.= natural_search('p.label', $search_product);
336
+		}
337
+		if ($search_warehouse > 0) {
338
+		    $sql.= " AND e.rowid = '".$db->escape($search_warehouse)."'";
339
+		}
340
+		if (! empty($search_user)) {
341
+		    $sql.= natural_search('u.login', $search_user);
342
+		}
343
+		if (! empty($search_batch)) {
344
+		    $sql.= natural_search('m.batch', $search_batch);
345
+		}
346
+		if ($search_qty != '') {
347
+		    $sql.= natural_search('m.value', $search_qty, 1);
348
+		}
349
+		if ($search_type_mouvement > 0) {
350
+		    $sql.= " AND m.type_mouvement = '".$db->escape($search_type_mouvement)."'";
351
+		}
305 352
 		// Add where from extra fields
306 353
 		include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
307 354
 		// Add where from hooks
@@ -315,14 +362,18 @@  discard block
 block discarded – undo
315 362
 		{
316 363
 			$result = $db->query($sql);
317 364
 			$nbtotalofrecords = $db->num_rows($result);
318
-			if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0
365
+			if (($page * $limit) > $nbtotalofrecords) {
366
+			    // if total resultset is smaller then paging size (filtering), goto and load page 0
319 367
 			{
320 368
 				$page = 0;
369
+			}
321 370
 				$offset = 0;
322 371
 			}
323 372
 		}
324 373
 
325
-		if(empty($search_inventorycode)) $sql.= $db->plimit($limit+1, $offset);
374
+		if(empty($search_inventorycode)) {
375
+		    $sql.= $db->plimit($limit+1, $offset);
376
+		}
326 377
 
327 378
 
328 379
 		$resql = $db->query($sql);
@@ -361,11 +412,14 @@  discard block
 block discarded – undo
361 412
 
362 413
 				$i = 0;
363 414
 				$help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
364
-				if ($msid) $texte = $langs->trans('StockMovementForId', $msid);
365
-				else
415
+				if ($msid) {
416
+				    $texte = $langs->trans('StockMovementForId', $msid);
417
+				} else
366 418
 				{
367 419
 					$texte = $langs->trans("ListOfStockMovements");
368
-					if ($id) $texte.=' ('.$langs->trans("ForThisWarehouse").')';
420
+					if ($id) {
421
+					    $texte.=' ('.$langs->trans("ForThisWarehouse").')';
422
+					}
369 423
 				}
370 424
 			}
371 425
 
@@ -374,12 +428,15 @@  discard block
 block discarded – undo
374 428
 			{
375 429
 				$dir = $conf->stock->dir_output . "/movement";
376 430
 				$file = $dir . "/SPECIMEN.pdf";
377
-			}
378
-			else
431
+			} else
379 432
 			{
380 433
 				$objectref = dol_sanitizeFileName($object->ref);
381
-				if(!empty($search_inventorycode)) $objectref.="_".$id."_".$search_inventorycode;
382
-				if($search_type_mouvement) $objectref.="_".$search_type_mouvement;
434
+				if(!empty($search_inventorycode)) {
435
+				    $objectref.="_".$id."_".$search_inventorycode;
436
+				}
437
+				if($search_type_mouvement) {
438
+				    $objectref.="_".$search_type_mouvement;
439
+				}
383 440
 				$dir = $conf->stock->dir_output . "/movement/" . $objectref;
384 441
 				$file = $dir . "/" . $objectref . ".pdf";
385 442
 			}
@@ -443,14 +500,18 @@  discard block
 block discarded – undo
443 500
 				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
444 501
 				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
445 502
 				$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);
503
+				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
504
+				    $pdf->SetCompression(false);
505
+				}
447 506
 
448 507
 				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
449 508
 
450 509
 
451 510
 				// New page
452 511
 				$pdf->AddPage();
453
-				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
512
+				if (! empty($tplidx)) {
513
+				    $pdf->useTemplate($tplidx);
514
+				}
454 515
 				$pagenb++;
455 516
 				$this->_pagehead($pdf, $object, 1, $outputlangs);
456 517
 				$pdf->SetFont('','', $default_font_size - 1);
@@ -488,9 +549,11 @@  discard block
 block discarded – undo
488 549
 						$objp = $db->fetch_object($resql);
489 550
 
490 551
 						// Multilangs
491
-						if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
552
+						if (! empty($conf->global->MAIN_MULTILANGS)) {
553
+						    // si l'option est active
492 554
 						{
493 555
 							$sql = "SELECT label";
556
+						}
494 557
 							$sql.= " FROM ".MAIN_DB_PREFIX."product_lang";
495 558
 							$sql.= " WHERE fk_product=".$objp->rowid;
496 559
 							$sql.= " AND lang='". $langs->getDefaultLang() ."'";
@@ -500,7 +563,9 @@  discard block
 block discarded – undo
500 563
 							if ($result)
501 564
 							{
502 565
 								$objtp = $db->fetch_object($result);
503
-								if ($objtp->label != '') $objp->produit = $objtp->label;
566
+								if ($objtp->label != '') {
567
+								    $objp->produit = $objtp->label;
568
+								}
504 569
 							}
505 570
 						}
506 571
 
@@ -520,32 +585,38 @@  discard block
 block discarded – undo
520 585
 						$pdf->startTransaction();
521 586
 						pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc);
522 587
 						$pageposafter=$pdf->getPage();
523
-						if ($pageposafter > $pageposbefore)	// There is a pagebreak
588
+						if ($pageposafter > $pageposbefore) {
589
+						    // There is a pagebreak
524 590
 						{
525 591
 							$pdf->rollbackTransaction(true);
592
+						}
526 593
 							$pageposafter=$pageposbefore;
527 594
 							//print $pageposafter.'-'.$pageposbefore;exit;
528 595
 							$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
529 596
 							pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc);
530 597
 							$pageposafter=$pdf->getPage();
531 598
 							$posyafter=$pdf->GetY();
532
-							if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
599
+							if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) {
600
+							    // There is no space left for total+free text
533 601
 							{
534 602
 								if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
535 603
 								{
536 604
 									$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);
605
+							}
606
+									if (! empty($tplidx)) {
607
+									    $pdf->useTemplate($tplidx);
608
+									}
609
+									if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
610
+									    $this->_pagehead($pdf, $object, 0, $outputlangs);
611
+									}
539 612
 									$pdf->setPage($pageposafter+1);
540 613
 								}
541
-							}
542
-							else
614
+							} else
543 615
 							{
544 616
 								// We found a page break
545 617
 								$showpricebeforepagebreak=0;
546 618
 							}
547
-						}
548
-						else	// No pagebreak
619
+						} else	// No pagebreak
549 620
 						{
550 621
 							$pdf->commitTransaction();
551 622
 						}
@@ -660,8 +731,7 @@  discard block
 block discarded – undo
660 731
 							if ($pagenb == 1)
661 732
 							{
662 733
 								$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
663
-							}
664
-							else
734
+							} else
665 735
 							{
666 736
 								$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
667 737
 							}
@@ -669,24 +739,29 @@  discard block
 block discarded – undo
669 739
 							$pagenb++;
670 740
 							$pdf->setPage($pagenb);
671 741
 							$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);
742
+							if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
743
+							    $this->_pagehead($pdf, $object, 0, $outputlangs);
744
+							}
673 745
 						}
674 746
 						if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
675 747
 						{
676 748
 							if ($pagenb == 1)
677 749
 							{
678 750
 								$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
679
-							}
680
-							else
751
+							} else
681 752
 							{
682 753
 								$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
683 754
 							}
684 755
 							$this->_pagefoot($pdf,$object,$outputlangs,1);
685 756
 							// New page
686 757
 							$pdf->AddPage();
687
-							if (! empty($tplidx)) $pdf->useTemplate($tplidx);
758
+							if (! empty($tplidx)) {
759
+							    $pdf->useTemplate($tplidx);
760
+							}
688 761
 							$pagenb++;
689
-							if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
762
+							if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
763
+							    $this->_pagehead($pdf, $object, 0, $outputlangs);
764
+							}
690 765
 						}
691 766
 					}
692 767
 
@@ -713,8 +788,7 @@  discard block
 block discarded – undo
713 788
 					// Total Qty
714 789
 					$pdf->SetXY($this->postotalht, $curY);
715 790
 					$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $totalunit, 0, 'R', 0);
716
-				}
717
-				else
791
+				} else
718 792
 				{
719 793
 					dol_print_error($db);
720 794
 				}
@@ -738,8 +812,7 @@  discard block
 block discarded – undo
738 812
 
739 813
 					$tab_height = $tab_height - $height_note;
740 814
 					$tab_top = $nexY+6;
741
-				}
742
-				else
815
+				} else
743 816
 				{
744 817
 					$height_note=0;
745 818
 				}
@@ -755,8 +828,7 @@  discard block
 block discarded – undo
755 828
 				{
756 829
 					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
757 830
 					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
758
-				}
759
-				else
831
+				} else
760 832
 				{
761 833
 					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
762 834
 					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
@@ -772,7 +844,9 @@  discard block
 block discarded – undo
772 844
 
773 845
 				// Pied de page
774 846
 				$this->_pagefoot($pdf,$object,$outputlangs);
775
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
847
+				if (method_exists($pdf,'AliasNbPages')) {
848
+				    $pdf->AliasNbPages();
849
+				}
776 850
 
777 851
 				$pdf->Close();
778 852
 
@@ -784,20 +858,19 @@  discard block
 block discarded – undo
784 858
 				global $action;
785 859
 				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
786 860
 
787
-				if (! empty($conf->global->MAIN_UMASK))
788
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
861
+				if (! empty($conf->global->MAIN_UMASK)) {
862
+									@chmod($file, octdec($conf->global->MAIN_UMASK));
863
+				}
789 864
 
790 865
 				$this->result = array('fullpath'=>$file);
791 866
 
792 867
 				return 1;   // Pas d'erreur
793
-			}
794
-			else
868
+			} else
795 869
 			{
796 870
 				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
797 871
 				return 0;
798 872
 			}
799
-		}
800
-		else
873
+		} else
801 874
 		{
802 875
 			$this->error=$langs->trans("ErrorConstantNotDefined","PRODUCT_OUTPUTDIR");
803 876
 			return 0;
@@ -824,7 +897,9 @@  discard block
 block discarded – undo
824 897
 
825 898
 	    // Force to disable hidetop and hidebottom
826 899
 	    $hidebottom=0;
827
-	    if ($hidetop) $hidetop=-1;
900
+	    if ($hidetop) {
901
+	        $hidetop=-1;
902
+	    }
828 903
 
829 904
 	    $currency = !empty($currency) ? $currency : $conf->currency;
830 905
 	    $default_font_size = pdf_getPDFFontSize($outputlangs);
@@ -840,7 +915,9 @@  discard block
 block discarded – undo
840 915
 	        $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
841 916
 
842 917
 	        //$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));
918
+	        if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
919
+	            $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));
920
+	        }
844 921
 	    }
845 922
 
846 923
 	    $pdf->SetDrawColor(128,128,128);
@@ -953,8 +1030,11 @@  discard block
 block discarded – undo
953 1030
 
954 1031
 	    $default_font_size = pdf_getPDFFontSize($outputlangs);
955 1032
 
956
-	    if ($object->type == 1) $titlekey='ServiceSheet';
957
-	    else $titlekey='StockSheet';
1033
+	    if ($object->type == 1) {
1034
+	        $titlekey='ServiceSheet';
1035
+	    } else {
1036
+	        $titlekey='StockSheet';
1037
+	    }
958 1038
 
959 1039
 	    pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
960 1040
 
@@ -980,16 +1060,14 @@  discard block
 block discarded – undo
980 1060
 	        {
981 1061
 	            $height=pdf_getHeightForLogo($logo);
982 1062
 	            $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
983
-	        }
984
-	        else
1063
+	        } else
985 1064
 	        {
986 1065
 	            $pdf->SetTextColor(200,0,0);
987 1066
 	            $pdf->SetFont('','B', $default_font_size -2);
988 1067
 	            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
989 1068
 	            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
990 1069
 	        }
991
-	    }
992
-	    else
1070
+	    } else
993 1071
 	    {
994 1072
 	        $text=$this->emetteur->name;
995 1073
 	        $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
@@ -1032,8 +1110,7 @@  discard block
 block discarded – undo
1032 1110
 		if(!empty($object->fk_parent) && $e->fetch($object->fk_parent) > 0)
1033 1111
 		{
1034 1112
 			$pdf->MultiCell(150, 3, $e->libelle, '', 'R');
1035
-		}
1036
-		else
1113
+		} else
1037 1114
 		{
1038 1115
 			$pdf->MultiCell(150, 3, $outputlangs->transnoentities("None"), '', 'R');
1039 1116
 		}
@@ -1071,8 +1148,7 @@  discard block
 block discarded – undo
1071 1148
 		{
1072 1149
 			$obj = $db->fetch_object($resqlbis);
1073 1150
 			$lastmovementdate=$db->jdate($obj->datem);
1074
-		}
1075
-		else
1151
+		} else
1076 1152
 		{
1077 1153
 			dol_print_error($db);
1078 1154
 		}
@@ -1080,8 +1156,7 @@  discard block
 block discarded – undo
1080 1156
 		if ($lastmovementdate)
1081 1157
 		{
1082 1158
 			$toWrite = dol_print_date($lastmovementdate,'dayhour').' ';
1083
-		}
1084
-		else
1159
+		} else
1085 1160
 		{
1086 1161
 			$toWrite = $outputlangs->transnoentities("None");
1087 1162
 		}
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/stock/modules_movement.php 2 patches
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.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	/**
34 34
 	 * @var string Error code (or message)
35 35
 	 */
36
-	public $error='';
36
+	public $error = '';
37 37
 
38 38
 
39 39
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -44,15 +44,15 @@  discard block
 block discarded – undo
44 44
      *  @param  integer	$maxfilenamelength  Max length of value to show
45 45
      *  @return	array						List of templates
46 46
 	 */
47
-	static function liste_modeles($db,$maxfilenamelength=0)
47
+	static function liste_modeles($db, $maxfilenamelength = 0)
48 48
 	{
49 49
         // phpcs:enable
50 50
 		global $conf;
51 51
 
52
-		$type='mouvement';
53
-		$liste=array();
52
+		$type = 'mouvement';
53
+		$liste = array();
54 54
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
55
-		$liste=getListOfModels($db,$type,$maxfilenamelength);
55
+		$liste = getListOfModels($db, $type, $maxfilenamelength);
56 56
 		return $liste;
57 57
 	}
58 58
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/modProjet.class.php 3 patches
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.
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
  *	\ingroup    projet
29 29
  *	\brief      Fichier de description et activation du module Projet
30 30
  */
31
-include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
31
+include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
32 32
 
33 33
 
34 34
 /**
@@ -51,29 +51,29 @@  discard block
 block discarded – undo
51 51
 		$this->family = "projects";
52 52
 		$this->module_position = '10';
53 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));
54
+		$this->name = preg_replace('/^mod/i', '', get_class($this));
55 55
 		$this->description = "Gestion des projets";
56 56
 		// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
57 57
 		$this->version = 'dolibarr';
58 58
 
59 59
 		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
60 60
 		$this->config_page_url = array("project.php@projet");
61
-		$this->picto='project';
61
+		$this->picto = 'project';
62 62
 
63 63
 		// Data directories to create when module is enabled
64 64
 		$this->dirs = array("/projet/temp");
65 65
 
66 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
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 72
 		$this->langfiles = array('projects');
73 73
 
74 74
 		// Constants
75 75
 		$this->const = array();
76
-		$r=0;
76
+		$r = 0;
77 77
 
78 78
 		$this->const[$r][0] = "PROJECT_ADDON_PDF";
79 79
 		$this->const[$r][1] = "chaine";
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 
140 140
 		// Boxes
141 141
 		$this->boxes = array();
142
-		$r=0;
142
+		$r = 0;
143 143
 		$this->boxes[$r][1] = "box_project.php";
144 144
 		$r++;
145 145
 		$this->boxes[$r][1] = "box_task.php";
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 		// Permissions
149 149
 		$this->rights = array();
150 150
 		$this->rights_class = 'projet';
151
-		$r=0;
151
+		$r = 0;
152 152
 
153 153
 		$r++;
154 154
 		$this->rights[$r][0] = 41; // id de la permission
@@ -205,34 +205,34 @@  discard block
 block discarded – undo
205 205
 
206 206
 		// Menus
207 207
 		//-------
208
-		$this->menu = 1;        // This module add menu entries. They are coded into menu manager.
208
+		$this->menu = 1; // This module add menu entries. They are coded into menu manager.
209 209
 
210 210
 
211 211
 		//Exports
212 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");
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 231
 	    // Add multicompany field
232
-        if (! empty($conf->global->MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED))
232
+        if (!empty($conf->global->MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED))
233 233
         {
234
-            $nbofallowedentities=count(explode(',',getEntity('project')));    // If project are shared, nb will be > 1
235
-            if (! empty($conf->multicompany->enabled) && $nbofallowedentities > 1) $this->export_fields_array[$r]+=array('p.entity'=>'Entity');
234
+            $nbofallowedentities = count(explode(',', getEntity('project'))); // If project are shared, nb will be > 1
235
+            if (!empty($conf->multicompany->enabled) && $nbofallowedentities > 1) $this->export_fields_array[$r] += array('p.entity'=>'Entity');
236 236
         }
237 237
 		if (empty($conf->global->PROJECT_USE_OPPORTUNITIES))
238 238
 		{
@@ -242,62 +242,62 @@  discard block
 block discarded – undo
242 242
 		}
243 243
 
244 244
 		// Add fields for project
245
-		$this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array());
245
+		$this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array());
246 246
 		// Add extra fields for project
247
-		$keyforselect='projet'; $keyforelement='project'; $keyforaliasextra='extra';
247
+		$keyforselect = 'projet'; $keyforelement = 'project'; $keyforaliasextra = 'extra';
248 248
 		include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
249 249
 		// Add fields for tasks
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"));
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"));
252 252
         // Add extra fields for task
253
-		$keyforselect='projet_task'; $keyforelement='projecttask'; $keyforaliasextra='extra2';
253
+		$keyforselect = 'projet_task'; $keyforelement = 'projecttask'; $keyforaliasextra = 'extra2';
254 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"));
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"));
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
+        $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
-        $this->export_sql_start[$r]='SELECT DISTINCT ';
260
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'projet as p';
261
-        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet_extrafields as extra ON p.rowid = extra.fk_object';
262
-        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_lead_status as cls ON p.fk_opp_status = cls.rowid';
263
-        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX."projet_task as pt ON p.rowid = pt.fk_projet";
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').")";
259
+        $this->export_sql_start[$r] = 'SELECT DISTINCT ';
260
+		$this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'projet as p';
261
+        $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet_extrafields as extra ON p.rowid = extra.fk_object';
262
+        $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_lead_status as cls ON p.fk_opp_status = cls.rowid';
263
+        $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX."projet_task as pt ON p.rowid = pt.fk_projet";
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 268
 
269 269
 
270 270
 		// Import list of tasks
271 271
 		if (empty($conf->global->PROJECT_HIDE_TASKS))
272 272
 		{
273 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");
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 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);
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 283
     		if ($resql)    // This can fail when class is used on old database (during migration for example)
284 284
     		{
285
-    		    while ($obj=$this->db->fetch_object($resql))
285
+    		    while ($obj = $this->db->fetch_object($resql))
286 286
     		    {
287
-    		        $fieldname='extra.'.$obj->name;
288
-    		        $fieldlabel=ucfirst($obj->label);
289
-    		        $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
287
+    		        $fieldname = 'extra.'.$obj->name;
288
+    		        $fieldlabel = ucfirst($obj->label);
289
+    		        $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
290 290
     		    }
291 291
     		}
292 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'),
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 296
     		    't.ref'=>array('rule'=>'getrefifauto')
297 297
     		);
298 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");
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 301
 		}
302 302
 	}
303 303
 
@@ -310,58 +310,58 @@  discard block
 block discarded – undo
310 310
      *      @param      string	$options    Options when enabling module ('', 'noboxes')
311 311
 	 *      @return     int             	1 if OK, 0 if KO
312 312
 	 */
313
-	function init($options='')
313
+	function init($options = '')
314 314
 	{
315
-		global $conf,$langs;
315
+		global $conf, $langs;
316 316
 
317 317
 		// Permissions
318 318
 		$this->remove($options);
319 319
 
320 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';
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 324
 
325
-		if (file_exists($src) && ! file_exists($dest))
325
+		if (file_exists($src) && !file_exists($dest))
326 326
 		{
327 327
 			require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
328 328
 			dol_mkdir($dirodt);
329
-			$result=dol_copy($src,$dest,0,0);
329
+			$result = dol_copy($src, $dest, 0, 0);
330 330
 			if ($result < 0)
331 331
 			{
332 332
 				$langs->load("errors");
333
-				$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
333
+				$this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
334 334
 				return 0;
335 335
 			}
336 336
 		}
337 337
 
338 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';
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 342
 
343
-		if (file_exists($src) && ! file_exists($dest))
343
+		if (file_exists($src) && !file_exists($dest))
344 344
 		{
345 345
 			require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
346 346
 			dol_mkdir($dirodt);
347
-			$result=dol_copy($src,$dest,0,0);
347
+			$result = dol_copy($src, $dest, 0, 0);
348 348
 			if ($result < 0)
349 349
 			{
350 350
 				$langs->load("errors");
351
-				$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
351
+				$this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
352 352
 				return 0;
353 353
 			}
354 354
 		}
355 355
 
356 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.")";
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 363
 
364 364
 
365
-		return $this->_init($sql,$options);
365
+		return $this->_init($sql, $options);
366 366
 	}
367 367
 }
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -232,7 +232,9 @@  discard block
 block discarded – undo
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
-            if (! empty($conf->multicompany->enabled) && $nbofallowedentities > 1) $this->export_fields_array[$r]+=array('p.entity'=>'Entity');
235
+            if (! empty($conf->multicompany->enabled) && $nbofallowedentities > 1) {
236
+                $this->export_fields_array[$r]+=array('p.entity'=>'Entity');
237
+            }
236 238
         }
237 239
 		if (empty($conf->global->PROJECT_USE_OPPORTUNITIES))
238 240
 		{
@@ -280,11 +282,13 @@  discard block
 block discarded – undo
280 282
     		// Add extra fields
281 283
     		$sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'projet_task' AND entity IN (0,".$conf->entity.")";
282 284
     		$resql=$this->db->query($sql);
283
-    		if ($resql)    // This can fail when class is used on old database (during migration for example)
285
+    		if ($resql) {
286
+    		    // This can fail when class is used on old database (during migration for example)
284 287
     		{
285 288
     		    while ($obj=$this->db->fetch_object($resql))
286 289
     		    {
287 290
     		        $fieldname='extra.'.$obj->name;
291
+    		}
288 292
     		        $fieldlabel=ucfirst($obj->label);
289 293
     		        $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
290 294
     		    }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/modFournisseur.class.php 3 patches
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.
Spacing   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
  *		\ingroup    fournisseur
27 27
  *		\brief      Description and activation file for module Fournisseur
28 28
  */
29
-include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
29
+include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
30 30
 
31 31
 
32 32
 /**
@@ -52,14 +52,14 @@  discard block
 block discarded – undo
52 52
 		$this->family = "srm";
53 53
 		$this->module_position = '10';
54 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));
55
+		$this->name = preg_replace('/^mod/i', '', get_class($this));
56 56
 		$this->description = "Gestion des fournisseurs";
57 57
 
58 58
 		// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
59 59
 		$this->version = 'dolibarr';
60 60
 
61 61
 		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
62
-		$this->picto='company';
62
+		$this->picto = 'company';
63 63
 
64 64
 		// Data directories to create when module is enabled
65 65
 		$this->dirs = array("/fournisseur/temp",
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 
80 80
 		// Constants
81 81
 		$this->const = array();
82
-		$r=0;
82
+		$r = 0;
83 83
 
84 84
 		$this->const[$r][0] = "COMMANDE_SUPPLIER_ADDON_PDF";
85 85
 		$this->const[$r][1] = "chaine";
@@ -113,18 +113,18 @@  discard block
 block discarded – undo
113 113
 
114 114
 		// Boxes
115 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'),
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 122
 		);
123 123
 
124 124
 		// Permissions
125 125
 		$this->rights = array();
126 126
 		$this->rights_class = 'fournisseur';
127
-		$r=0;
127
+		$r = 0;
128 128
 
129 129
 		$r++;
130 130
 		$this->rights[$r][0] = 1181;
@@ -197,11 +197,11 @@  discard block
 block discarded – undo
197 197
 		$this->rights[$r][4] = 'commande';
198 198
 		$this->rights[$r][5] = 'supprimer';
199 199
 
200
-		if (! empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED))
200
+		if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED))
201 201
 		{
202 202
 			$r++;
203 203
 			$this->rights[$r][0] = 1190;
204
-			$this->rights[$r][1] = 'Approve supplier order (second level)';		// $langs->trans("Permission1190");
204
+			$this->rights[$r][1] = 'Approve supplier order (second level)'; // $langs->trans("Permission1190");
205 205
 			$this->rights[$r][2] = 'w';
206 206
 			$this->rights[$r][3] = 0;
207 207
 			$this->rights[$r][4] = 'commande';
@@ -267,27 +267,27 @@  discard block
 block discarded – undo
267 267
 
268 268
 	    // Menus
269 269
 	    //-------
270
-	    $this->menu = 1;        // This module add menu entries. They are coded into menu manager.
270
+	    $this->menu = 1; // This module add menu entries. They are coded into menu manager.
271 271
 
272 272
 
273 273
 		// Exports
274 274
 		//--------
275
-		$r=0;
275
+		$r = 0;
276 276
 
277 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'
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 291
 		);
292 292
 		//$this->export_TypeFields_array[$r]=array(
293 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',
@@ -295,122 +295,122 @@  discard block
 block discarded – undo
295 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 296
 		//     'fd.tva'=>"Numeric",'fd.product_type'=>'Numeric','fd.fk_product'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text'
297 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'
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 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'
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 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
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 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);
315
+		$sql = "SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn'";
316
+		$resql = $this->db->query($sql);
317 317
 		if ($resql)    // This can fail when class is used on old database (during migration for example)
318 318
 		{
319
-			while ($obj=$this->db->fetch_object($resql))
319
+			while ($obj = $this->db->fetch_object($resql))
320 320
 			{
321
-				$fieldname='extra.'.$obj->name;
322
-				$fieldlabel=ucfirst($obj->label);
323
-				$typeFilter="Text";
324
-				switch($obj->type)
321
+				$fieldname = 'extra.'.$obj->name;
322
+				$fieldlabel = ucfirst($obj->label);
323
+				$typeFilter = "Text";
324
+				switch ($obj->type)
325 325
 				{
326 326
 					case 'int':
327 327
 					case 'double':
328 328
 					case 'price':
329
-						$typeFilter="Numeric";
329
+						$typeFilter = "Numeric";
330 330
 						break;
331 331
 					case 'date':
332 332
 					case 'datetime':
333
-						$typeFilter="Date";
333
+						$typeFilter = "Date";
334 334
 						break;
335 335
 					case 'boolean':
336
-						$typeFilter="Boolean";
336
+						$typeFilter = "Boolean";
337 337
 						break;
338 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;
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 343
 						break;
344 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';
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 348
 			}
349 349
 		}
350 350
 		// End add extra fields
351 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);
352
+		$sql = "SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn_det'";
353
+		$resql = $this->db->query($sql);
354 354
 		if ($resql)    // This can fail when class is used on old database (during migration for example)
355 355
 		{
356
-			while ($obj=$this->db->fetch_object($resql))
356
+			while ($obj = $this->db->fetch_object($resql))
357 357
 			{
358
-				$fieldname='extraline.'.$obj->name;
359
-				$fieldlabel=ucfirst($obj->label);
360
-				$typeFilter="Text";
361
-				switch($obj->type)
358
+				$fieldname = 'extraline.'.$obj->name;
359
+				$fieldlabel = ucfirst($obj->label);
360
+				$typeFilter = "Text";
361
+				switch ($obj->type)
362 362
 				{
363 363
 					case 'int':
364 364
 					case 'double':
365 365
 					case 'price':
366
-						$typeFilter="Numeric";
366
+						$typeFilter = "Numeric";
367 367
 						break;
368 368
 					case 'date':
369 369
 					case 'datetime':
370
-						$typeFilter="Date";
370
+						$typeFilter = "Date";
371 371
 						break;
372 372
 					case 'boolean':
373
-						$typeFilter="Boolean";
373
+						$typeFilter = "Boolean";
374 374
 						break;
375 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;
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 380
 						break;
381 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';
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 385
 			}
386 386
 		}
387 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;
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;
401 401
 
402 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'
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 414
 		);
415 415
 		//$this->export_TypeFields_array[$r]=array(
416 416
 		//	's.rowid'=>"List:societe:CompanyName",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text',
@@ -418,200 +418,200 @@  discard block
 block discarded – undo
418 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 419
 		//	'pf.amount'=>'Numeric','p.datep'=>'Date','p.num_paiement'=>'Numeric'
420 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'
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 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
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 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);
435
+		$sql = "SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn'";
436
+		$resql = $this->db->query($sql);
437 437
 		if ($resql)    // This can fail when class is used on old database (during migration for example)
438 438
 		{
439
-			while ($obj=$this->db->fetch_object($resql))
439
+			while ($obj = $this->db->fetch_object($resql))
440 440
 			{
441
-				$fieldname='extra.'.$obj->name;
442
-				$fieldlabel=ucfirst($obj->label);
443
-				$typeFilter="Text";
444
-				switch($obj->type)
441
+				$fieldname = 'extra.'.$obj->name;
442
+				$fieldlabel = ucfirst($obj->label);
443
+				$typeFilter = "Text";
444
+				switch ($obj->type)
445 445
 				{
446 446
 					case 'int':
447 447
 					case 'double':
448 448
 					case 'price':
449
-						$typeFilter="Numeric";
449
+						$typeFilter = "Numeric";
450 450
 						break;
451 451
 					case 'date':
452 452
 					case 'datetime':
453
-						$typeFilter="Date";
453
+						$typeFilter = "Date";
454 454
 						break;
455 455
 					case 'boolean':
456
-						$typeFilter="Boolean";
456
+						$typeFilter = "Boolean";
457 457
 						break;
458 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;
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 463
 						break;
464 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';
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 468
 			}
469 469
 		}
470 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;
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 483
 
484 484
 		// Order
485 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'
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 499
 		);
500 500
 		if (empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED))
501 501
 		{
502 502
 			unset($this->export_fields_array['f.date_approve2']);
503 503
 			unset($this->export_fields_array['ua2.login']);
504 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'
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 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'
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 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
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 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);
522
+		$sql = "SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'commande_fournisseur'";
523
+		$resql = $this->db->query($sql);
524 524
 		if ($resql)    // This can fail when class is used on old database (during migration for example)
525 525
 		{
526
-			while ($obj=$this->db->fetch_object($resql))
526
+			while ($obj = $this->db->fetch_object($resql))
527 527
 			{
528
-				$fieldname='extra.'.$obj->name;
529
-				$fieldlabel=ucfirst($obj->label);
530
-				$typeFilter="Text";
531
-				switch($obj->type)
528
+				$fieldname = 'extra.'.$obj->name;
529
+				$fieldlabel = ucfirst($obj->label);
530
+				$typeFilter = "Text";
531
+				switch ($obj->type)
532 532
 				{
533 533
 					case 'int':
534 534
 					case 'double':
535 535
 					case 'price':
536
-						$typeFilter="Numeric";
536
+						$typeFilter = "Numeric";
537 537
 						break;
538 538
 					case 'date':
539 539
 					case 'datetime':
540
-						$typeFilter="Date";
540
+						$typeFilter = "Date";
541 541
 						break;
542 542
 					case 'boolean':
543
-						$typeFilter="Boolean";
543
+						$typeFilter = "Boolean";
544 544
 						break;
545 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;
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 551
 						break;
552 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';
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 556
 			}
557 557
 		}
558 558
 		// End add extra fields object
559 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);
560
+		$sql = "SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'commande_fournisseurdet'";
561
+		$resql = $this->db->query($sql);
562 562
 		if ($resql)    // This can fail when class is used on old database (during migration for example)
563 563
 		{
564
-			while ($obj=$this->db->fetch_object($resql))
564
+			while ($obj = $this->db->fetch_object($resql))
565 565
 			{
566
-				$fieldname='extraline.'.$obj->name;
567
-				$fieldlabel=ucfirst($obj->label);
568
-				$typeFilter="Text";
569
-				switch($obj->type)
566
+				$fieldname = 'extraline.'.$obj->name;
567
+				$fieldlabel = ucfirst($obj->label);
568
+				$typeFilter = "Text";
569
+				switch ($obj->type)
570 570
 				{
571 571
 					case 'int':
572 572
 					case 'double':
573 573
 					case 'price':
574
-						$typeFilter="Numeric";
574
+						$typeFilter = "Numeric";
575 575
 						break;
576 576
 					case 'date':
577 577
 					case 'datetime':
578
-						$typeFilter="Date";
578
+						$typeFilter = "Date";
579 579
 						break;
580 580
 					case 'boolean':
581
-						$typeFilter="Boolean";
581
+						$typeFilter = "Boolean";
582 582
 						break;
583 583
 					case 'sellist':
584
-						$tmp='';
585
-						$tmpparam=unserialize($obj->param);	// $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
584
+						$tmp = '';
585
+						$tmpparam = unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
586 586
 
587 587
 						if ($tmpparam['options'] && is_array($tmpparam['options'])) {
588
-							$tmpparam_param_key=array_keys($tmpparam['options']);
589
-							$tmp=array_shift($tmpparam_param_key);
588
+							$tmpparam_param_key = array_keys($tmpparam['options']);
589
+							$tmp = array_shift($tmpparam_param_key);
590 590
 						}
591
-						if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
591
+						if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter = "List:".$tmp;
592 592
 						break;
593 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';
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 597
 			}
598 598
 		}
599 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;
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 615
 	}
616 616
 
617 617
 
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
      *      @param      string	$options    Options when enabling module ('', 'noboxes')
624 624
 	 *      @return     int             	1 if OK, 0 if KO
625 625
 	 */
626
-	function init($options='')
626
+	function init($options = '')
627 627
 	{
628 628
 		global $conf;
629 629
 
@@ -634,6 +634,6 @@  discard block
 block discarded – undo
634 634
 			 "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','order_supplier',".$conf->entity.")",
635 635
 		);
636 636
 
637
-		return $this->_init($sql,$options);
637
+		return $this->_init($sql, $options);
638 638
 	}
639 639
 }
Please login to merge, or discard this patch.
Braces   +60 added lines, -20 removed lines patch added patch discarded remove patch
@@ -314,11 +314,13 @@  discard block
 block discarded – undo
314 314
 		// Add extra fields object
315 315
 		$sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn'";
316 316
 		$resql=$this->db->query($sql);
317
-		if ($resql)    // This can fail when class is used on old database (during migration for example)
317
+		if ($resql) {
318
+		    // This can fail when class is used on old database (during migration for example)
318 319
 		{
319 320
 			while ($obj=$this->db->fetch_object($resql))
320 321
 			{
321 322
 				$fieldname='extra.'.$obj->name;
323
+		}
322 324
 				$fieldlabel=ucfirst($obj->label);
323 325
 				$typeFilter="Text";
324 326
 				switch($obj->type)
@@ -338,8 +340,12 @@  discard block
 block discarded – undo
338 340
 					case 'sellist':
339 341
 						$tmp='';
340 342
 						$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
+						if ($tmpparam['options'] && is_array($tmpparam['options'])) {
344
+						    $tmp=array_shift(array_keys($tmpparam['options']));
345
+						}
346
+						if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) {
347
+						    $typeFilter="List:".$tmp;
348
+						}
343 349
 						break;
344 350
 				}
345 351
 				$this->export_fields_array[$r][$fieldname]=$fieldlabel;
@@ -351,11 +357,13 @@  discard block
 block discarded – undo
351 357
 		// Add extra fields line
352 358
 		$sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn_det'";
353 359
 		$resql=$this->db->query($sql);
354
-		if ($resql)    // This can fail when class is used on old database (during migration for example)
360
+		if ($resql) {
361
+		    // This can fail when class is used on old database (during migration for example)
355 362
 		{
356 363
 			while ($obj=$this->db->fetch_object($resql))
357 364
 			{
358 365
 				$fieldname='extraline.'.$obj->name;
366
+		}
359 367
 				$fieldlabel=ucfirst($obj->label);
360 368
 				$typeFilter="Text";
361 369
 				switch($obj->type)
@@ -375,8 +383,12 @@  discard block
 block discarded – undo
375 383
 					case 'sellist':
376 384
 						$tmp='';
377 385
 						$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;
386
+						if ($tmpparam['options'] && is_array($tmpparam['options'])) {
387
+						    $tmp=array_shift(array_keys($tmpparam['options']));
388
+						}
389
+						if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) {
390
+						    $typeFilter="List:".$tmp;
391
+						}
380 392
 						break;
381 393
 				}
382 394
 				$this->export_fields_array[$r][$fieldname]=$fieldlabel;
@@ -387,7 +399,9 @@  discard block
 block discarded – undo
387 399
 		// End add extra fields line
388 400
 		$this->export_sql_start[$r]='SELECT DISTINCT ';
389 401
 		$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';
402
+		if (is_object($user) && empty($user->rights->societe->client->voir)) {
403
+		    $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
404
+		}
391 405
 		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
392 406
 		$this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture_fourn as f';
393 407
 		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
@@ -397,7 +411,9 @@  discard block
 block discarded – undo
397 411
 		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
398 412
 		$this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn';
399 413
 		$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;
414
+		if (is_object($user) && empty($user->rights->societe->client->voir)) {
415
+		    $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
416
+		}
401 417
 
402 418
 		$r++;
403 419
 		$this->export_code[$r]=$this->rights_class.'_'.$r;
@@ -434,11 +450,13 @@  discard block
 block discarded – undo
434 450
 		// Add extra fields object
435 451
 		$sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn'";
436 452
 		$resql=$this->db->query($sql);
437
-		if ($resql)    // This can fail when class is used on old database (during migration for example)
453
+		if ($resql) {
454
+		    // This can fail when class is used on old database (during migration for example)
438 455
 		{
439 456
 			while ($obj=$this->db->fetch_object($resql))
440 457
 			{
441 458
 				$fieldname='extra.'.$obj->name;
459
+		}
442 460
 				$fieldlabel=ucfirst($obj->label);
443 461
 				$typeFilter="Text";
444 462
 				switch($obj->type)
@@ -458,8 +476,12 @@  discard block
 block discarded – undo
458 476
 					case 'sellist':
459 477
 						$tmp='';
460 478
 						$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;
479
+						if ($tmpparam['options'] && is_array($tmpparam['options'])) {
480
+						    $tmp=array_shift(array_keys($tmpparam['options']));
481
+						}
482
+						if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) {
483
+						    $typeFilter="List:".$tmp;
484
+						}
463 485
 						break;
464 486
 				}
465 487
 				$this->export_fields_array[$r][$fieldname]=$fieldlabel;
@@ -470,7 +492,9 @@  discard block
 block discarded – undo
470 492
 		// End add extra fields object
471 493
 		$this->export_sql_start[$r]='SELECT DISTINCT ';
472 494
 		$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';
495
+		if (is_object($user) && empty($user->rights->societe->client->voir)) {
496
+		    $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
497
+		}
474 498
 		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
475 499
 		$this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture_fourn as f';
476 500
 		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
@@ -479,7 +503,9 @@  discard block
 block discarded – undo
479 503
 		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn as p ON pf.fk_paiementfourn = p.rowid';
480 504
 		$this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid';
481 505
         $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;
506
+		if (is_object($user) && empty($user->rights->societe->client->voir)) {
507
+		    $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
508
+		}
483 509
 
484 510
 		// Order
485 511
 		$r++;
@@ -521,11 +547,13 @@  discard block
 block discarded – undo
521 547
 		// Add extra fields object
522 548
 		$sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'commande_fournisseur'";
523 549
 		$resql=$this->db->query($sql);
524
-		if ($resql)    // This can fail when class is used on old database (during migration for example)
550
+		if ($resql) {
551
+		    // This can fail when class is used on old database (during migration for example)
525 552
 		{
526 553
 			while ($obj=$this->db->fetch_object($resql))
527 554
 			{
528 555
 				$fieldname='extra.'.$obj->name;
556
+		}
529 557
 				$fieldlabel=ucfirst($obj->label);
530 558
 				$typeFilter="Text";
531 559
 				switch($obj->type)
@@ -546,8 +574,12 @@  discard block
 block discarded – undo
546 574
 						$tmp='';
547 575
 						$tmpparam=unserialize($obj->param);	// $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
548 576
 						$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;
577
+						if ($tmpparam['options'] && is_array($tmpparam['options'])) {
578
+						    $tmp=array_shift($tmpkey);
579
+						}
580
+						if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) {
581
+						    $typeFilter="List:".$tmp;
582
+						}
551 583
 						break;
552 584
 				}
553 585
 				$this->export_fields_array[$r][$fieldname]=$fieldlabel;
@@ -559,11 +591,13 @@  discard block
 block discarded – undo
559 591
 		// Add extra fields line
560 592
 		$sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'commande_fournisseurdet'";
561 593
 		$resql=$this->db->query($sql);
562
-		if ($resql)    // This can fail when class is used on old database (during migration for example)
594
+		if ($resql) {
595
+		    // This can fail when class is used on old database (during migration for example)
563 596
 		{
564 597
 			while ($obj=$this->db->fetch_object($resql))
565 598
 			{
566 599
 				$fieldname='extraline.'.$obj->name;
600
+		}
567 601
 				$fieldlabel=ucfirst($obj->label);
568 602
 				$typeFilter="Text";
569 603
 				switch($obj->type)
@@ -588,7 +622,9 @@  discard block
 block discarded – undo
588 622
 							$tmpparam_param_key=array_keys($tmpparam['options']);
589 623
 							$tmp=array_shift($tmpparam_param_key);
590 624
 						}
591
-						if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
625
+						if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) {
626
+						    $typeFilter="List:".$tmp;
627
+						}
592 628
 						break;
593 629
 				}
594 630
 				$this->export_fields_array[$r][$fieldname]=$fieldlabel;
@@ -599,7 +635,9 @@  discard block
 block discarded – undo
599 635
 		// End add extra fields line
600 636
 		$this->export_sql_start[$r]='SELECT DISTINCT ';
601 637
 		$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';
638
+		if (is_object($user) && empty($user->rights->societe->client->voir)) {
639
+		    $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
640
+		}
603 641
 		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
604 642
 		$this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'commande_fournisseur as f';
605 643
 		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
@@ -611,7 +649,9 @@  discard block
 block discarded – undo
611 649
 		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
612 650
 		$this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_commande';
613 651
 		$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;
652
+		if (is_object($user) && empty($user->rights->societe->client->voir)) {
653
+		    $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
654
+		}
615 655
 	}
616 656
 
617 657
 
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/modSalaries.class.php 2 patches
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.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
  *  \ingroup    salaries
30 30
  *  \brief      File to activate module salaries
31 31
  */
32
-include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
32
+include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
33 33
 
34 34
 
35 35
 /**
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 		// It is used to group modules by family in module setup page
55 55
 		$this->family = "financial";
56 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));
57
+		$this->name = preg_replace('/^mod/i', '', get_class($this));
58 58
 		// Module description used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
59 59
 		$this->description = "Payment of salaries";
60 60
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 		$this->version = 'dolibarr';
63 63
 
64 64
 		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
65
-		$this->picto='bill';
65
+		$this->picto = 'bill';
66 66
 
67 67
 		// Data directories to create when module is enabled
68 68
 		$this->dirs = array("/salaries/temp");
@@ -72,12 +72,12 @@  discard block
 block discarded – undo
72 72
 		$this->config_page_url = array();
73 73
 
74 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");
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 81
 
82 82
 		// Constants
83 83
 		$this->const = array();
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 		// Permissions
99 99
 		$this->rights = array();
100 100
 		$this->rights_class = 'salaries';
101
-		$r=0;
101
+		$r = 0;
102 102
 
103 103
 		$r++;
104 104
 		$this->rights[$r][0] = 511;
@@ -135,26 +135,26 @@  discard block
 block discarded – undo
135 135
 
136 136
 		// Menus
137 137
 		//-------
138
-		$this->menu = 1;        // This module add menu entries. They are coded into menu manager.
138
+		$this->menu = 1; // This module add menu entries. They are coded into menu manager.
139 139
 
140 140
 
141 141
 		// Exports
142 142
 		//--------
143
-		$r=0;
143
+		$r = 0;
144 144
 
145 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').')';
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 158
 	}
159 159
 
160 160
 
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 	 *      @param      string	$options    Options when enabling module ('', 'noboxes')
167 167
 	 *      @return     int             	1 if OK, 0 if KO
168 168
 	 */
169
-	function init($options='')
169
+	function init($options = '')
170 170
 	{
171 171
 		global $conf;
172 172
 
@@ -175,6 +175,6 @@  discard block
 block discarded – undo
175 175
 
176 176
 		$sql = array();
177 177
 
178
-		return $this->_init($sql,$options);
178
+		return $this->_init($sql, $options);
179 179
 	}
180 180
 }
Please login to merge, or discard this patch.