Passed
Push — master ( 65bdac...4e88da )
by Alxarafe
32:38
created
dolibarr/htdocs/core/modules/modContrat.class.php 2 patches
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -34,214 +34,214 @@
 block discarded – undo
34 34
 class modContrat extends DolibarrModules
35 35
 {
36 36
 
37
-	/**
38
-	 *   Constructor. Define names, constants, directories, boxes, permissions
39
-	 *
40
-	 *   @param      DoliDB		$db      Database handler
41
-	 */
42
-	function __construct($db)
43
-	{
44
-		global $conf, $langs;
45
-
46
-		$this->db = $db;
47
-		$this->numero = 54;
48
-
49
-		$this->family = "crm";
50
-		$this->module_position = '35';
51
-		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
52
-		$this->name = preg_replace('/^mod/i','',get_class($this));
53
-		$this->description = "Gestion des contrats de services";
54
-
55
-		// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
56
-		$this->version = 'dolibarr';
57
-
58
-		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
59
-		$this->picto='contract';
60
-
61
-		// Data directories to create when module is enabled
62
-		$this->dirs = array("/contract/temp");
63
-
64
-		// Dependencies
65
-		$this->depends = array("modSociete");
66
-		$this->requiredby = array();
67
-
68
-		// Config pages
69
-		$this->config_page_url = array("contract.php");
70
-
71
-		// Constants
72
-		$this->const = array();
73
-		$r=0;
74
-
75
-		$this->const[$r][0] = "CONTRACT_ADDON";
76
-		$this->const[$r][1] = "chaine";
77
-		$this->const[$r][2] = "mod_contract_serpis";
78
-		$this->const[$r][3] = 'Nom du gestionnaire de numerotation des contrats';
79
-		$this->const[$r][4] = 0;
80
-		$r++;
81
-
82
-		$this->const[$r][0] = "CONTRACT_ADDON_PDF";
83
-		$this->const[$r][1] = "chaine";
84
-		$this->const[$r][2] = "strato";
85
-		$this->const[$r][3] = 'Name of PDF model of contract';
86
-		$this->const[$r][4] = 0;
87
-		$r++;
88
-
89
-		$this->const[$r][0] = "CONTRACT_ADDON_PDF_ODT_PATH";
90
-		$this->const[$r][1] = "chaine";
91
-		$this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/contracts";
92
-		$this->const[$r][3] = "";
93
-		$this->const[$r][4] = 0;
94
-		$r++;
95
-
96
-		// Boxes
97
-		$this->boxes = array(
98
-			0=>array('file'=>'box_contracts.php','enabledbydefaulton'=>'Home'),
99
-			1=>array('file'=>'box_services_expired.php','enabledbydefaulton'=>'Home')
100
-		);
101
-
102
-		// Permissions
103
-		$this->rights = array();
104
-		$this->rights_class = 'contrat';
105
-		$r=0;
106
-
107
-		$r++;
108
-		$this->rights[$r][0] = 161;
109
-		$this->rights[$r][1] = 'Lire les contrats';
110
-		$this->rights[$r][2] = 'r';
111
-		$this->rights[$r][3] = 0;
112
-		$this->rights[$r][4] = 'lire';
113
-
114
-		$r++;
115
-		$this->rights[$r][0] = 162;
116
-		$this->rights[$r][1] = 'Creer / modifier les contrats';
117
-		$this->rights[$r][2] = 'w';
118
-		$this->rights[$r][3] = 0;
119
-		$this->rights[$r][4] = 'creer';
120
-
121
-		$r++;
122
-		$this->rights[$r][0] = 163;
123
-		$this->rights[$r][1] = 'Activer un service d\'un contrat';
124
-		$this->rights[$r][2] = 'w';
125
-		$this->rights[$r][3] = 0;
126
-		$this->rights[$r][4] = 'activer';
127
-
128
-		$r++;
129
-		$this->rights[$r][0] = 164;
130
-		$this->rights[$r][1] = 'Desactiver un service d\'un contrat';
131
-		$this->rights[$r][2] = 'w';
132
-		$this->rights[$r][3] = 0;
133
-		$this->rights[$r][4] = 'desactiver';
134
-
135
-		$r++;
136
-		$this->rights[$r][0] = 165;
137
-		$this->rights[$r][1] = 'Supprimer un contrat';
138
-		$this->rights[$r][2] = 'd';
139
-		$this->rights[$r][3] = 0;
140
-		$this->rights[$r][4] = 'supprimer';
141
-
142
-		$r++;
143
-		$this->rights[$r][0] = 167;
144
-		$this->rights[$r][1] = 'Export contracts';
145
-		$this->rights[$r][2] = 'r';
146
-		$this->rights[$r][3] = 0;
147
-		$this->rights[$r][4] = 'export';
148
-
149
-
150
-		// Menus
151
-		//-------
152
-		$this->menu = 1;        // This module add menu entries. They are coded into menu manager.
153
-
154
-
155
-		// Exports
156
-		//--------
157
-		$langs->load("contracts");
158
-
159
-		$r=1;
160
-
161
-		$this->export_code[$r]=$this->rights_class.'_'.$r;
162
-		$this->export_label[$r]='ContractsAndLine';	// Translation key (used only if key ExportDataset_xxx_z not found)
163
-		$this->export_icon[$r]='contract';
164
-		$this->export_permission[$r]=array(array("contrat","export"));
165
-		$this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','c.code'=>'CountryCode',
166
-		's.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode',
167
-		's.code_compta_fournisseur'=>'SupplierAccountancyCode','s.tva_intra'=>'VATIntra',
168
-		'co.rowid'=>"Id",'co.ref'=>"Ref",'co.datec'=>"DateCreation",'co.date_contrat'=>"DateContract",'co.mise_en_service'=>"ContractStartDate",
169
-		'co.fin_validite'=>"ContractEndDate",'co.date_cloture'=>"Closing",'co.note_private'=>"NotePrivate",'co.note_public'=>"NotePublic",
170
-		'cod.rowid'=>'LineId','cod.label'=>"LineLabel",'cod.description'=>"LineDescription",'cod.price_ht'=>"LineUnitPrice",'cod.tva_tx'=>"LineVATRate",
171
-		'cod.qty'=>"LineQty",'cod.total_ht'=>"LineTotalHT",'cod.total_tva'=>"LineTotalVAT",'cod.total_ttc'=>"LineTotalTTC",
172
-		'cod.date_ouverture'=>"DateStart",'cod.date_ouverture_prevue'=>"DateStartPlanned",'cod.date_fin_validite'=>"DateEndPlanned",'cod.date_cloture'=>"DateEnd",
173
-		'p.rowid'=>'ProductId','p.ref'=>'ProductRef','p.label'=>'ProductLabel');
174
-
175
-		$this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company',
176
-		's.town'=>'company','c.code'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company',
177
-		's.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','s.tva_intra'=>'company',
178
-		'co.rowid'=>"contract",'co.ref'=>"contract",'co.datec'=>"contract",'co.date_contrat'=>"contract",'co.mise_en_service'=>"contract",
179
-		'co.fin_validite'=>"contract",'co.date_cloture'=>"contract",'co.note_private'=>"contract",'co.note_public'=>"contract",
180
-		'cod.rowid'=>'contract_line','cod.label'=>"contract_line",'cod.description'=>"contract_line",'cod.price_ht'=>"contract_line",'cod.tva_tx'=>"contract_line",
181
-		'cod.qty'=>"contract_line",'cod.total_ht'=>"contract_line",'cod.total_tva'=>"contract_line",'cod.total_ttc'=>"contract_line",
182
-		'cod.date_ouverture'=>"contract_line",'cod.date_ouverture_prevue'=>"contract_line",'cod.date_fin_validite'=>"contract_line",'cod.date_cloture'=>"contract_line",
183
-		'p.rowid'=>'product','p.ref'=>'product','p.label'=>'product');
184
-
185
-		$this->export_TypeFields_array[$r]=array('s.rowid'=>"List:societe:nom",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text',
186
-		's.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.code_compta'=>'Text',
187
-		's.code_compta_fournisseur'=>'Text','s.tva_intra'=>'Text',
188
-		'co.ref'=>"Text",'co.datec'=>"Date",'co.date_contrat'=>"Date",'co.mise_en_service'=>"Date",
189
-		'co.fin_validite'=>"Date",'co.date_cloture'=>"Date",'co.note_private'=>"Text",'co.note_public'=>"Text",
190
-		'cod.label'=>"Text",'cod.description'=>"Text",'cod.price_ht'=>"Numeric",'cod.tva_tx'=>"Numeric",
191
-		'cod.qty'=>"Numeric",'cod.total_ht'=>"Numeric",'cod.total_tva'=>"Numeric",'cod.total_ttc'=>"Numeric",
192
-		'cod.date_ouverture'=>"Date",'cod.date_ouverture_prevue'=>"Date",'cod.date_fin_validite'=>"Date",'cod.date_cloture'=>"Date",
193
-		'p.rowid'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text');
194
-
195
-
196
-		$this->export_sql_start[$r]='SELECT DISTINCT ';
197
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'societe as s';
198
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,';
199
-		$this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'contrat as co,';
200
-		$this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'contratdet as cod';
201
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (cod.fk_product = p.rowid)';
202
-		$this->export_sql_end[$r] .=' WHERE co.fk_soc = s.rowid and co.rowid = cod.fk_contrat';
203
-		$this->export_sql_end[$r] .=' AND co.entity IN ('.getEntity('contract').')';
204
-	}
205
-
206
-
207
-	/**
208
-	 *		Function called when module is enabled.
209
-	 *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
210
-	 *		It also creates data directories
211
-	 *
37
+    /**
38
+     *   Constructor. Define names, constants, directories, boxes, permissions
39
+     *
40
+     *   @param      DoliDB		$db      Database handler
41
+     */
42
+    function __construct($db)
43
+    {
44
+        global $conf, $langs;
45
+
46
+        $this->db = $db;
47
+        $this->numero = 54;
48
+
49
+        $this->family = "crm";
50
+        $this->module_position = '35';
51
+        // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
52
+        $this->name = preg_replace('/^mod/i','',get_class($this));
53
+        $this->description = "Gestion des contrats de services";
54
+
55
+        // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
56
+        $this->version = 'dolibarr';
57
+
58
+        $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
59
+        $this->picto='contract';
60
+
61
+        // Data directories to create when module is enabled
62
+        $this->dirs = array("/contract/temp");
63
+
64
+        // Dependencies
65
+        $this->depends = array("modSociete");
66
+        $this->requiredby = array();
67
+
68
+        // Config pages
69
+        $this->config_page_url = array("contract.php");
70
+
71
+        // Constants
72
+        $this->const = array();
73
+        $r=0;
74
+
75
+        $this->const[$r][0] = "CONTRACT_ADDON";
76
+        $this->const[$r][1] = "chaine";
77
+        $this->const[$r][2] = "mod_contract_serpis";
78
+        $this->const[$r][3] = 'Nom du gestionnaire de numerotation des contrats';
79
+        $this->const[$r][4] = 0;
80
+        $r++;
81
+
82
+        $this->const[$r][0] = "CONTRACT_ADDON_PDF";
83
+        $this->const[$r][1] = "chaine";
84
+        $this->const[$r][2] = "strato";
85
+        $this->const[$r][3] = 'Name of PDF model of contract';
86
+        $this->const[$r][4] = 0;
87
+        $r++;
88
+
89
+        $this->const[$r][0] = "CONTRACT_ADDON_PDF_ODT_PATH";
90
+        $this->const[$r][1] = "chaine";
91
+        $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/contracts";
92
+        $this->const[$r][3] = "";
93
+        $this->const[$r][4] = 0;
94
+        $r++;
95
+
96
+        // Boxes
97
+        $this->boxes = array(
98
+            0=>array('file'=>'box_contracts.php','enabledbydefaulton'=>'Home'),
99
+            1=>array('file'=>'box_services_expired.php','enabledbydefaulton'=>'Home')
100
+        );
101
+
102
+        // Permissions
103
+        $this->rights = array();
104
+        $this->rights_class = 'contrat';
105
+        $r=0;
106
+
107
+        $r++;
108
+        $this->rights[$r][0] = 161;
109
+        $this->rights[$r][1] = 'Lire les contrats';
110
+        $this->rights[$r][2] = 'r';
111
+        $this->rights[$r][3] = 0;
112
+        $this->rights[$r][4] = 'lire';
113
+
114
+        $r++;
115
+        $this->rights[$r][0] = 162;
116
+        $this->rights[$r][1] = 'Creer / modifier les contrats';
117
+        $this->rights[$r][2] = 'w';
118
+        $this->rights[$r][3] = 0;
119
+        $this->rights[$r][4] = 'creer';
120
+
121
+        $r++;
122
+        $this->rights[$r][0] = 163;
123
+        $this->rights[$r][1] = 'Activer un service d\'un contrat';
124
+        $this->rights[$r][2] = 'w';
125
+        $this->rights[$r][3] = 0;
126
+        $this->rights[$r][4] = 'activer';
127
+
128
+        $r++;
129
+        $this->rights[$r][0] = 164;
130
+        $this->rights[$r][1] = 'Desactiver un service d\'un contrat';
131
+        $this->rights[$r][2] = 'w';
132
+        $this->rights[$r][3] = 0;
133
+        $this->rights[$r][4] = 'desactiver';
134
+
135
+        $r++;
136
+        $this->rights[$r][0] = 165;
137
+        $this->rights[$r][1] = 'Supprimer un contrat';
138
+        $this->rights[$r][2] = 'd';
139
+        $this->rights[$r][3] = 0;
140
+        $this->rights[$r][4] = 'supprimer';
141
+
142
+        $r++;
143
+        $this->rights[$r][0] = 167;
144
+        $this->rights[$r][1] = 'Export contracts';
145
+        $this->rights[$r][2] = 'r';
146
+        $this->rights[$r][3] = 0;
147
+        $this->rights[$r][4] = 'export';
148
+
149
+
150
+        // Menus
151
+        //-------
152
+        $this->menu = 1;        // This module add menu entries. They are coded into menu manager.
153
+
154
+
155
+        // Exports
156
+        //--------
157
+        $langs->load("contracts");
158
+
159
+        $r=1;
160
+
161
+        $this->export_code[$r]=$this->rights_class.'_'.$r;
162
+        $this->export_label[$r]='ContractsAndLine';	// Translation key (used only if key ExportDataset_xxx_z not found)
163
+        $this->export_icon[$r]='contract';
164
+        $this->export_permission[$r]=array(array("contrat","export"));
165
+        $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','c.code'=>'CountryCode',
166
+        's.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode',
167
+        's.code_compta_fournisseur'=>'SupplierAccountancyCode','s.tva_intra'=>'VATIntra',
168
+        'co.rowid'=>"Id",'co.ref'=>"Ref",'co.datec'=>"DateCreation",'co.date_contrat'=>"DateContract",'co.mise_en_service'=>"ContractStartDate",
169
+        'co.fin_validite'=>"ContractEndDate",'co.date_cloture'=>"Closing",'co.note_private'=>"NotePrivate",'co.note_public'=>"NotePublic",
170
+        'cod.rowid'=>'LineId','cod.label'=>"LineLabel",'cod.description'=>"LineDescription",'cod.price_ht'=>"LineUnitPrice",'cod.tva_tx'=>"LineVATRate",
171
+        'cod.qty'=>"LineQty",'cod.total_ht'=>"LineTotalHT",'cod.total_tva'=>"LineTotalVAT",'cod.total_ttc'=>"LineTotalTTC",
172
+        'cod.date_ouverture'=>"DateStart",'cod.date_ouverture_prevue'=>"DateStartPlanned",'cod.date_fin_validite'=>"DateEndPlanned",'cod.date_cloture'=>"DateEnd",
173
+        'p.rowid'=>'ProductId','p.ref'=>'ProductRef','p.label'=>'ProductLabel');
174
+
175
+        $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company',
176
+        's.town'=>'company','c.code'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company',
177
+        's.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','s.tva_intra'=>'company',
178
+        'co.rowid'=>"contract",'co.ref'=>"contract",'co.datec'=>"contract",'co.date_contrat'=>"contract",'co.mise_en_service'=>"contract",
179
+        'co.fin_validite'=>"contract",'co.date_cloture'=>"contract",'co.note_private'=>"contract",'co.note_public'=>"contract",
180
+        'cod.rowid'=>'contract_line','cod.label'=>"contract_line",'cod.description'=>"contract_line",'cod.price_ht'=>"contract_line",'cod.tva_tx'=>"contract_line",
181
+        'cod.qty'=>"contract_line",'cod.total_ht'=>"contract_line",'cod.total_tva'=>"contract_line",'cod.total_ttc'=>"contract_line",
182
+        'cod.date_ouverture'=>"contract_line",'cod.date_ouverture_prevue'=>"contract_line",'cod.date_fin_validite'=>"contract_line",'cod.date_cloture'=>"contract_line",
183
+        'p.rowid'=>'product','p.ref'=>'product','p.label'=>'product');
184
+
185
+        $this->export_TypeFields_array[$r]=array('s.rowid'=>"List:societe:nom",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text',
186
+        's.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.code_compta'=>'Text',
187
+        's.code_compta_fournisseur'=>'Text','s.tva_intra'=>'Text',
188
+        'co.ref'=>"Text",'co.datec'=>"Date",'co.date_contrat'=>"Date",'co.mise_en_service'=>"Date",
189
+        'co.fin_validite'=>"Date",'co.date_cloture'=>"Date",'co.note_private'=>"Text",'co.note_public'=>"Text",
190
+        'cod.label'=>"Text",'cod.description'=>"Text",'cod.price_ht'=>"Numeric",'cod.tva_tx'=>"Numeric",
191
+        'cod.qty'=>"Numeric",'cod.total_ht'=>"Numeric",'cod.total_tva'=>"Numeric",'cod.total_ttc'=>"Numeric",
192
+        'cod.date_ouverture'=>"Date",'cod.date_ouverture_prevue'=>"Date",'cod.date_fin_validite'=>"Date",'cod.date_cloture'=>"Date",
193
+        'p.rowid'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text');
194
+
195
+
196
+        $this->export_sql_start[$r]='SELECT DISTINCT ';
197
+        $this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'societe as s';
198
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,';
199
+        $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'contrat as co,';
200
+        $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'contratdet as cod';
201
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (cod.fk_product = p.rowid)';
202
+        $this->export_sql_end[$r] .=' WHERE co.fk_soc = s.rowid and co.rowid = cod.fk_contrat';
203
+        $this->export_sql_end[$r] .=' AND co.entity IN ('.getEntity('contract').')';
204
+    }
205
+
206
+
207
+    /**
208
+     *		Function called when module is enabled.
209
+     *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
210
+     *		It also creates data directories
211
+     *
212 212
      *      @param      string	$options    Options when enabling module ('', 'noboxes')
213
-	 *      @return     int             	1 if OK, 0 if KO
214
-	 */
215
-	function init($options='')
216
-	{
217
-		global $conf;
218
-
219
-		// Nettoyage avant activation
220
-		$this->remove($options);
221
-
222
-		//ODT template
223
-		$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/contracts/template_contract.odt';
224
-		$dirodt=DOL_DATA_ROOT.'/doctemplates/contracts';
225
-		$dest=$dirodt.'/template_contract.odt';
226
-
227
-		if (file_exists($src) && ! file_exists($dest))
228
-		{
229
-		    require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
230
-		    dol_mkdir($dirodt);
231
-		    $result=dol_copy($src,$dest,0,0);
232
-		    if ($result < 0)
233
-		    {
234
-		        $langs->load("errors");
235
-		        $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
236
-		        return 0;
237
-		    }
238
-		}
239
-
240
-		$sql = array(
241
-		    "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[1][2])."' AND type = 'contract' AND entity = ".$conf->entity,
242
-		    "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[1][2])."','contract',".$conf->entity.")"
243
-		);
244
-
245
-		return $this->_init($sql,$options);
246
-	}
213
+     *      @return     int             	1 if OK, 0 if KO
214
+     */
215
+    function init($options='')
216
+    {
217
+        global $conf;
218
+
219
+        // Nettoyage avant activation
220
+        $this->remove($options);
221
+
222
+        //ODT template
223
+        $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/contracts/template_contract.odt';
224
+        $dirodt=DOL_DATA_ROOT.'/doctemplates/contracts';
225
+        $dest=$dirodt.'/template_contract.odt';
226
+
227
+        if (file_exists($src) && ! file_exists($dest))
228
+        {
229
+            require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
230
+            dol_mkdir($dirodt);
231
+            $result=dol_copy($src,$dest,0,0);
232
+            if ($result < 0)
233
+            {
234
+                $langs->load("errors");
235
+                $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
236
+                return 0;
237
+            }
238
+        }
239
+
240
+        $sql = array(
241
+            "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[1][2])."' AND type = 'contract' AND entity = ".$conf->entity,
242
+            "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[1][2])."','contract',".$conf->entity.")"
243
+        );
244
+
245
+        return $this->_init($sql,$options);
246
+    }
247 247
 }
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  *	\brief      Fichier de description et activation du module Contrat
26 26
  */
27 27
 
28
-include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
28
+include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
29 29
 
30 30
 
31 31
 /**
@@ -49,14 +49,14 @@  discard block
 block discarded – undo
49 49
 		$this->family = "crm";
50 50
 		$this->module_position = '35';
51 51
 		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
52
-		$this->name = preg_replace('/^mod/i','',get_class($this));
52
+		$this->name = preg_replace('/^mod/i', '', get_class($this));
53 53
 		$this->description = "Gestion des contrats de services";
54 54
 
55 55
 		// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
56 56
 		$this->version = 'dolibarr';
57 57
 
58 58
 		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
59
-		$this->picto='contract';
59
+		$this->picto = 'contract';
60 60
 
61 61
 		// Data directories to create when module is enabled
62 62
 		$this->dirs = array("/contract/temp");
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 
71 71
 		// Constants
72 72
 		$this->const = array();
73
-		$r=0;
73
+		$r = 0;
74 74
 
75 75
 		$this->const[$r][0] = "CONTRACT_ADDON";
76 76
 		$this->const[$r][1] = "chaine";
@@ -95,14 +95,14 @@  discard block
 block discarded – undo
95 95
 
96 96
 		// Boxes
97 97
 		$this->boxes = array(
98
-			0=>array('file'=>'box_contracts.php','enabledbydefaulton'=>'Home'),
99
-			1=>array('file'=>'box_services_expired.php','enabledbydefaulton'=>'Home')
98
+			0=>array('file'=>'box_contracts.php', 'enabledbydefaulton'=>'Home'),
99
+			1=>array('file'=>'box_services_expired.php', 'enabledbydefaulton'=>'Home')
100 100
 		);
101 101
 
102 102
 		// Permissions
103 103
 		$this->rights = array();
104 104
 		$this->rights_class = 'contrat';
105
-		$r=0;
105
+		$r = 0;
106 106
 
107 107
 		$r++;
108 108
 		$this->rights[$r][0] = 161;
@@ -149,58 +149,58 @@  discard block
 block discarded – undo
149 149
 
150 150
 		// Menus
151 151
 		//-------
152
-		$this->menu = 1;        // This module add menu entries. They are coded into menu manager.
152
+		$this->menu = 1; // This module add menu entries. They are coded into menu manager.
153 153
 
154 154
 
155 155
 		// Exports
156 156
 		//--------
157 157
 		$langs->load("contracts");
158 158
 
159
-		$r=1;
160
-
161
-		$this->export_code[$r]=$this->rights_class.'_'.$r;
162
-		$this->export_label[$r]='ContractsAndLine';	// Translation key (used only if key ExportDataset_xxx_z not found)
163
-		$this->export_icon[$r]='contract';
164
-		$this->export_permission[$r]=array(array("contrat","export"));
165
-		$this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','c.code'=>'CountryCode',
166
-		's.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode',
167
-		's.code_compta_fournisseur'=>'SupplierAccountancyCode','s.tva_intra'=>'VATIntra',
168
-		'co.rowid'=>"Id",'co.ref'=>"Ref",'co.datec'=>"DateCreation",'co.date_contrat'=>"DateContract",'co.mise_en_service'=>"ContractStartDate",
169
-		'co.fin_validite'=>"ContractEndDate",'co.date_cloture'=>"Closing",'co.note_private'=>"NotePrivate",'co.note_public'=>"NotePublic",
170
-		'cod.rowid'=>'LineId','cod.label'=>"LineLabel",'cod.description'=>"LineDescription",'cod.price_ht'=>"LineUnitPrice",'cod.tva_tx'=>"LineVATRate",
171
-		'cod.qty'=>"LineQty",'cod.total_ht'=>"LineTotalHT",'cod.total_tva'=>"LineTotalVAT",'cod.total_ttc'=>"LineTotalTTC",
172
-		'cod.date_ouverture'=>"DateStart",'cod.date_ouverture_prevue'=>"DateStartPlanned",'cod.date_fin_validite'=>"DateEndPlanned",'cod.date_cloture'=>"DateEnd",
173
-		'p.rowid'=>'ProductId','p.ref'=>'ProductRef','p.label'=>'ProductLabel');
174
-
175
-		$this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company',
176
-		's.town'=>'company','c.code'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company',
177
-		's.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','s.tva_intra'=>'company',
178
-		'co.rowid'=>"contract",'co.ref'=>"contract",'co.datec'=>"contract",'co.date_contrat'=>"contract",'co.mise_en_service'=>"contract",
179
-		'co.fin_validite'=>"contract",'co.date_cloture'=>"contract",'co.note_private'=>"contract",'co.note_public'=>"contract",
180
-		'cod.rowid'=>'contract_line','cod.label'=>"contract_line",'cod.description'=>"contract_line",'cod.price_ht'=>"contract_line",'cod.tva_tx'=>"contract_line",
181
-		'cod.qty'=>"contract_line",'cod.total_ht'=>"contract_line",'cod.total_tva'=>"contract_line",'cod.total_ttc'=>"contract_line",
182
-		'cod.date_ouverture'=>"contract_line",'cod.date_ouverture_prevue'=>"contract_line",'cod.date_fin_validite'=>"contract_line",'cod.date_cloture'=>"contract_line",
183
-		'p.rowid'=>'product','p.ref'=>'product','p.label'=>'product');
184
-
185
-		$this->export_TypeFields_array[$r]=array('s.rowid'=>"List:societe:nom",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text',
186
-		's.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.code_compta'=>'Text',
187
-		's.code_compta_fournisseur'=>'Text','s.tva_intra'=>'Text',
188
-		'co.ref'=>"Text",'co.datec'=>"Date",'co.date_contrat'=>"Date",'co.mise_en_service'=>"Date",
189
-		'co.fin_validite'=>"Date",'co.date_cloture'=>"Date",'co.note_private'=>"Text",'co.note_public'=>"Text",
190
-		'cod.label'=>"Text",'cod.description'=>"Text",'cod.price_ht'=>"Numeric",'cod.tva_tx'=>"Numeric",
191
-		'cod.qty'=>"Numeric",'cod.total_ht'=>"Numeric",'cod.total_tva'=>"Numeric",'cod.total_ttc'=>"Numeric",
192
-		'cod.date_ouverture'=>"Date",'cod.date_ouverture_prevue'=>"Date",'cod.date_fin_validite'=>"Date",'cod.date_cloture'=>"Date",
193
-		'p.rowid'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text');
194
-
195
-
196
-		$this->export_sql_start[$r]='SELECT DISTINCT ';
197
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'societe as s';
198
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,';
199
-		$this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'contrat as co,';
200
-		$this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'contratdet as cod';
201
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (cod.fk_product = p.rowid)';
202
-		$this->export_sql_end[$r] .=' WHERE co.fk_soc = s.rowid and co.rowid = cod.fk_contrat';
203
-		$this->export_sql_end[$r] .=' AND co.entity IN ('.getEntity('contract').')';
159
+		$r = 1;
160
+
161
+		$this->export_code[$r] = $this->rights_class.'_'.$r;
162
+		$this->export_label[$r] = 'ContractsAndLine'; // Translation key (used only if key ExportDataset_xxx_z not found)
163
+		$this->export_icon[$r] = 'contract';
164
+		$this->export_permission[$r] = array(array("contrat", "export"));
165
+		$this->export_fields_array[$r] = array('s.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode',
166
+		's.phone'=>'Phone', 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.code_compta'=>'CustomerAccountancyCode',
167
+		's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra',
168
+		'co.rowid'=>"Id", 'co.ref'=>"Ref", 'co.datec'=>"DateCreation", 'co.date_contrat'=>"DateContract", 'co.mise_en_service'=>"ContractStartDate",
169
+		'co.fin_validite'=>"ContractEndDate", 'co.date_cloture'=>"Closing", 'co.note_private'=>"NotePrivate", 'co.note_public'=>"NotePublic",
170
+		'cod.rowid'=>'LineId', 'cod.label'=>"LineLabel", 'cod.description'=>"LineDescription", 'cod.price_ht'=>"LineUnitPrice", 'cod.tva_tx'=>"LineVATRate",
171
+		'cod.qty'=>"LineQty", 'cod.total_ht'=>"LineTotalHT", 'cod.total_tva'=>"LineTotalVAT", 'cod.total_ttc'=>"LineTotalTTC",
172
+		'cod.date_ouverture'=>"DateStart", 'cod.date_ouverture_prevue'=>"DateStartPlanned", 'cod.date_fin_validite'=>"DateEndPlanned", 'cod.date_cloture'=>"DateEnd",
173
+		'p.rowid'=>'ProductId', 'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel');
174
+
175
+		$this->export_entities_array[$r] = array('s.rowid'=>"company", 's.nom'=>'company', 's.address'=>'company', 's.zip'=>'company',
176
+		's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company', 's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company',
177
+		's.idprof4'=>'company', 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company', 's.tva_intra'=>'company',
178
+		'co.rowid'=>"contract", 'co.ref'=>"contract", 'co.datec'=>"contract", 'co.date_contrat'=>"contract", 'co.mise_en_service'=>"contract",
179
+		'co.fin_validite'=>"contract", 'co.date_cloture'=>"contract", 'co.note_private'=>"contract", 'co.note_public'=>"contract",
180
+		'cod.rowid'=>'contract_line', 'cod.label'=>"contract_line", 'cod.description'=>"contract_line", 'cod.price_ht'=>"contract_line", 'cod.tva_tx'=>"contract_line",
181
+		'cod.qty'=>"contract_line", 'cod.total_ht'=>"contract_line", 'cod.total_tva'=>"contract_line", 'cod.total_ttc'=>"contract_line",
182
+		'cod.date_ouverture'=>"contract_line", 'cod.date_ouverture_prevue'=>"contract_line", 'cod.date_fin_validite'=>"contract_line", 'cod.date_cloture'=>"contract_line",
183
+		'p.rowid'=>'product', 'p.ref'=>'product', 'p.label'=>'product');
184
+
185
+		$this->export_TypeFields_array[$r] = array('s.rowid'=>"List:societe:nom", 's.nom'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'c.code'=>'Text',
186
+		's.phone'=>'Text', 's.siren'=>'Text', 's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.code_compta'=>'Text',
187
+		's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text',
188
+		'co.ref'=>"Text", 'co.datec'=>"Date", 'co.date_contrat'=>"Date", 'co.mise_en_service'=>"Date",
189
+		'co.fin_validite'=>"Date", 'co.date_cloture'=>"Date", 'co.note_private'=>"Text", 'co.note_public'=>"Text",
190
+		'cod.label'=>"Text", 'cod.description'=>"Text", 'cod.price_ht'=>"Numeric", 'cod.tva_tx'=>"Numeric",
191
+		'cod.qty'=>"Numeric", 'cod.total_ht'=>"Numeric", 'cod.total_tva'=>"Numeric", 'cod.total_ttc'=>"Numeric",
192
+		'cod.date_ouverture'=>"Date", 'cod.date_ouverture_prevue'=>"Date", 'cod.date_fin_validite'=>"Date", 'cod.date_cloture'=>"Date",
193
+		'p.rowid'=>'List:product:label', 'p.ref'=>'Text', 'p.label'=>'Text');
194
+
195
+
196
+		$this->export_sql_start[$r] = 'SELECT DISTINCT ';
197
+		$this->export_sql_end[$r]  = ' FROM '.MAIN_DB_PREFIX.'societe as s';
198
+		$this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,';
199
+		$this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'contrat as co,';
200
+		$this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'contratdet as cod';
201
+		$this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (cod.fk_product = p.rowid)';
202
+		$this->export_sql_end[$r] .= ' WHERE co.fk_soc = s.rowid and co.rowid = cod.fk_contrat';
203
+		$this->export_sql_end[$r] .= ' AND co.entity IN ('.getEntity('contract').')';
204 204
 	}
205 205
 
206 206
 
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
      *      @param      string	$options    Options when enabling module ('', 'noboxes')
213 213
 	 *      @return     int             	1 if OK, 0 if KO
214 214
 	 */
215
-	function init($options='')
215
+	function init($options = '')
216 216
 	{
217 217
 		global $conf;
218 218
 
@@ -220,19 +220,19 @@  discard block
 block discarded – undo
220 220
 		$this->remove($options);
221 221
 
222 222
 		//ODT template
223
-		$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/contracts/template_contract.odt';
224
-		$dirodt=DOL_DATA_ROOT.'/doctemplates/contracts';
225
-		$dest=$dirodt.'/template_contract.odt';
223
+		$src = DOL_DOCUMENT_ROOT.'/install/doctemplates/contracts/template_contract.odt';
224
+		$dirodt = DOL_DATA_ROOT.'/doctemplates/contracts';
225
+		$dest = $dirodt.'/template_contract.odt';
226 226
 
227
-		if (file_exists($src) && ! file_exists($dest))
227
+		if (file_exists($src) && !file_exists($dest))
228 228
 		{
229 229
 		    require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
230 230
 		    dol_mkdir($dirodt);
231
-		    $result=dol_copy($src,$dest,0,0);
231
+		    $result = dol_copy($src, $dest, 0, 0);
232 232
 		    if ($result < 0)
233 233
 		    {
234 234
 		        $langs->load("errors");
235
-		        $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
235
+		        $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
236 236
 		        return 0;
237 237
 		    }
238 238
 		}
@@ -242,6 +242,6 @@  discard block
 block discarded – undo
242 242
 		    "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[1][2])."','contract',".$conf->entity.")"
243 243
 		);
244 244
 
245
-		return $this->_init($sql,$options);
245
+		return $this->_init($sql, $options);
246 246
 	}
247 247
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/modPaybox.class.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -70,10 +70,10 @@
 block discarded – undo
70 70
 
71 71
         // Dependencies
72 72
         $this->hidden = false;			// A condition to hide module
73
-		$this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
74
-		$this->requiredby = array();	// List of module ids to disable if this one is disabled
75
-		$this->conflictwith = array();	// List of module class names as string this module is in conflict with
76
-		$this->phpmin = array(5,4);		// Minimum version of PHP required by module
73
+        $this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
74
+        $this->requiredby = array();	// List of module ids to disable if this one is disabled
75
+        $this->conflictwith = array();	// List of module class names as string this module is in conflict with
76
+        $this->phpmin = array(5,4);		// Minimum version of PHP required by module
77 77
         $this->need_dolibarr_version = array(2,6);	// Minimum version of Dolibarr required by module
78 78
         $this->langfiles = array("paybox");
79 79
 
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  *  \ingroup    paybox
24 24
  *  \brief      Description and activation file for module Paybox
25 25
  */
26
-include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
26
+include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
27 27
 
28 28
 
29 29
 /**
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
         // It is used to group modules in module setup page
51 51
         $this->family = "interface";
52 52
         // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
53
-        $this->name = preg_replace('/^mod/i','',get_class($this));
53
+        $this->name = preg_replace('/^mod/i', '', get_class($this));
54 54
         // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
55 55
         $this->description = "Module to offer an online payment page by credit card with PayBox";
56 56
         // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
         // Name of image file used for this module.
61 61
         // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
62 62
         // If file is in module/img directory, use this->picto=DOL_URL_ROOT.'/module/img/file.png'
63
-        $this->picto='paybox@paybox';
63
+        $this->picto = 'paybox@paybox';
64 64
 
65 65
         // Data directories to create when module is enabled.
66 66
         $this->dirs = array('/paybox/temp');
@@ -69,16 +69,16 @@  discard block
 block discarded – undo
69 69
         $this->config_page_url = array("paybox.php@paybox");
70 70
 
71 71
         // Dependencies
72
-        $this->hidden = false;			// A condition to hide module
73
-		$this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
74
-		$this->requiredby = array();	// List of module ids to disable if this one is disabled
75
-		$this->conflictwith = array();	// List of module class names as string this module is in conflict with
76
-		$this->phpmin = array(5,4);		// Minimum version of PHP required by module
77
-        $this->need_dolibarr_version = array(2,6);	// Minimum version of Dolibarr required by module
72
+        $this->hidden = false; // A condition to hide module
73
+		$this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
74
+		$this->requiredby = array(); // List of module ids to disable if this one is disabled
75
+		$this->conflictwith = array(); // List of module class names as string this module is in conflict with
76
+		$this->phpmin = array(5, 4); // Minimum version of PHP required by module
77
+        $this->need_dolibarr_version = array(2, 6); // Minimum version of Dolibarr required by module
78 78
         $this->langfiles = array("paybox");
79 79
 
80 80
         // Constants
81
-        $this->const = array();			// List of particular constants to add when module is enabled
81
+        $this->const = array(); // List of particular constants to add when module is enabled
82 82
         //Example: $this->const=array(0=>array('MODULE_MY_NEW_CONST1','chaine','myvalue','This is a constant to add',0),
83 83
         //                            1=>array('MODULE_MY_NEW_CONST2','chaine','myvalue','This is another constant to add',0) );
84 84
 
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
 
88 88
 
89 89
         // Boxes
90
-        $this->boxes = array();			// List of boxes
91
-        $r=0;
90
+        $this->boxes = array(); // List of boxes
91
+        $r = 0;
92 92
 
93 93
         // Add here list of php file(s) stored in core/boxes that contains class to show a box.
94 94
         // Example:
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
 
100 100
 
101 101
         // Permissions
102
-        $this->rights = array();		// Permission array used by this module
103
-        $r=0;
102
+        $this->rights = array(); // Permission array used by this module
103
+        $r = 0;
104 104
 
105 105
         // Add here list of permission defined by an id, a label, a boolean and two constant strings.
106 106
         // Example:
@@ -113,8 +113,8 @@  discard block
 block discarded – undo
113 113
 
114 114
 
115 115
         // Main menu entries
116
-        $this->menus = array();			// List of menus to add
117
-        $r=0;
116
+        $this->menus = array(); // List of menus to add
117
+        $r = 0;
118 118
 
119 119
         // Add here entries to declare new menus
120 120
         // Example to declare the Top Menu entry:
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 
159 159
 
160 160
         // Exports
161
-        $r=1;
161
+        $r = 1;
162 162
 
163 163
         // Example:
164 164
         // $this->export_code[$r]=$this->rights_class.'_'.$r;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/modStock.class.php 2 patches
Indentation   +359 added lines, -359 removed lines patch added patch discarded remove patch
@@ -35,363 +35,363 @@
 block discarded – undo
35 35
 class modStock 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, $langs;
46
-
47
-		$this->db = $db;
48
-		$this->numero = 52;
49
-
50
-		$this->family = "products";
51
-		$this->module_position = '40';
52
-		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
53
-		$this->name = preg_replace('/^mod/i','',get_class($this));
54
-		$this->description = "Gestion des stocks";
55
-
56
-		// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
57
-		$this->version = 'dolibarr';
58
-
59
-		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
60
-		$this->picto='stock';
61
-
62
-		// Data directories to create when module is enabled
63
-		$this->dirs = array("/stock/temp");
64
-
65
-		$this->config_page_url = array("stock.php");
66
-
67
-		// Dependencies
68
-		$this->hidden = false;			// A condition to hide module
69
-		$this->depends = array("modProduct");		// List of module class names as string that must be enabled if this module is enabled
70
-		$this->requiredby = array("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
-		$this->langfiles = array("stocks");
74
-
75
-		// Constants
76
-		$this->const = array();
77
-		$r=0;
78
-
79
-		$this->const[$r] = array('STOCK_ALLOW_NEGATIVE_TRANSFER','chaine','1','',1);
80
-
81
-		$r++;
82
-		$this->const[$r][0] = "STOCK_ADDON_PDF";
83
-		$this->const[$r][1] = "chaine";
84
-		$this->const[$r][2] = "Standard";
85
-		$this->const[$r][3] = 'Name of PDF model of stock';
86
-		$this->const[$r][4] = 0;
87
-
88
-		$r++;
89
-		$this->const[$r][0] = "MOUVEMENT_ADDON_PDF";
90
-		$this->const[$r][1] = "chaine";
91
-		$this->const[$r][2] = "StdMouvement";
92
-		$this->const[$r][3] = 'Name of PDF model of stock mouvement';
93
-		$this->const[$r][4] = 0;
94
-
95
-		$r++;
96
-		$this->const[$r][0] = "STOCK_ADDON_PDF_ODT_PATH";
97
-		$this->const[$r][1] = "chaine";
98
-		$this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/stocks";
99
-		$this->const[$r][3] = "";
100
-		$this->const[$r][4] = 0;
101
-
102
-		$r++;
103
-		$this->const[$r][0] = "MOUVEMENT_ADDON_PDF_ODT_PATH";
104
-		$this->const[$r][1] = "chaine";
105
-		$this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/stocks/mouvements";
106
-		$this->const[$r][3] = "";
107
-		$this->const[$r][4] = 0;
108
-
109
-		// Boxes
110
-		$this->boxes = array();
111
-
112
-		// Permissions
113
-		$this->rights = array();
114
-		$this->rights_class = 'stock';
115
-
116
-		$this->rights[0][0] = 1001;
117
-		$this->rights[0][1] = 'Lire les stocks';
118
-		$this->rights[0][2] = 'r';
119
-		$this->rights[0][3] = 0;
120
-		$this->rights[0][4] = 'lire';
121
-		$this->rights[0][5] = '';
122
-
123
-		$this->rights[1][0] = 1002;
124
-		$this->rights[1][1] = 'Creer/Modifier les stocks';
125
-		$this->rights[1][2] = 'w';
126
-		$this->rights[1][3] = 0;
127
-		$this->rights[1][4] = 'creer';
128
-		$this->rights[1][5] = '';
129
-
130
-		$this->rights[2][0] = 1003;
131
-		$this->rights[2][1] = 'Supprimer les stocks';
132
-		$this->rights[2][2] = 'd';
133
-		$this->rights[2][3] = 0;
134
-		$this->rights[2][4] = 'supprimer';
135
-		$this->rights[2][5] = '';
136
-
137
-		$this->rights[3][0] = 1004;
138
-		$this->rights[3][1] = 'Lire mouvements de stocks';
139
-		$this->rights[3][2] = 'r';
140
-		$this->rights[3][3] = 0;
141
-		$this->rights[3][4] = 'mouvement';
142
-		$this->rights[3][5] = 'lire';
143
-
144
-		$this->rights[4][0] = 1005;
145
-		$this->rights[4][1] = 'Creer/modifier mouvements de stocks';
146
-		$this->rights[4][2] = 'w';
147
-		$this->rights[4][3] = 0;
148
-		$this->rights[4][4] = 'mouvement';
149
-		$this->rights[4][5] = 'creer';
150
-
151
-		if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
152
-
153
-		$this->rights[5][0] = 1011;
154
-		$this->rights[5][1] = 'inventoryReadPermission';	// Permission label
155
-		$this->rights[5][3] = 0; 					// Permission by default for new user (0/1)
156
-		$this->rights[5][4] = 'inventory_advance';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
157
-		$this->rights[5][5] = 'read';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
158
-
159
-		$this->rights[6][0] = 1012;
160
-		$this->rights[6][1] = 'inventoryCreatePermission';	// Permission label
161
-		$this->rights[6][3] = 0; 					// Permission by default for new user (0/1)
162
-		$this->rights[6][4] = 'inventory_advance';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
163
-		$this->rights[6][5] = 'write';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
164
-
165
-		$this->rights[8][0] = 1014;
166
-		$this->rights[8][1] = 'inventoryValidatePermission';	// Permission label
167
-		$this->rights[8][3] = 0; 					// Permission by default for new user (0/1)
168
-		$this->rights[8][4] = 'inventory_advance';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
169
-		$this->rights[8][5] = 'validate';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
170
-
171
-		$this->rights[9][0] = 1015;
172
-		$this->rights[9][1] = 'inventoryChangePMPPermission';	// Permission label
173
-		$this->rights[9][3] = 0; 					// Permission by default for new user (0/1)
174
-		$this->rights[9][4] = 'inventory_advance';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
175
-		$this->rights[9][5] = 'changePMP';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
176
-		}
177
-
178
-		// Main menu entries
179
-		$this->menu = array();			// List of menus to add
180
-		$r=0;
181
-
182
-		// Menus
183
-		//-------
184
-		$this->menu = 1;        // This module add menu entries. They are coded into menu manager.
185
-
186
-
187
-		// Exports
188
-		//--------
189
-		$r=0;
190
-
191
-		$r++;
192
-		$this->export_code[$r]=$this->rights_class;
193
-		$this->export_label[$r]="WarehousesAndProducts";	// Translation key (used only if key ExportDataset_xxx_z not found)
194
-		$this->export_permission[$r]=array(array("stock","lire"));
195
-		$this->export_fields_array[$r]=array(
196
-			'e.rowid'=>'IdWarehouse','e.ref'=>'LocationSummary','e.description'=>'DescWareHouse','e.lieu'=>'LieuWareHouse','e.address'=>'Address',
197
-			'e.zip'=>'Zip','e.town'=>'Town','p.rowid'=>"ProductId",'p.ref'=>"Ref",'p.fk_product_type'=>"Type",'p.label'=>"Label",'p.description'=>"Description",
198
-			'p.note'=>"Note",'p.price'=>"Price",'p.tva_tx'=>'VAT','p.tosell'=>"OnSell",'p.tobuy'=>'OnBuy','p.duration'=>"Duration",'p.datec'=>'DateCreation',
199
-			'p.tms'=>'DateModification','p.pmp'=>'PMPValue','p.cost_price'=>'CostPrice'
200
-		);
201
-		$this->export_TypeFields_array[$r]=array(
202
-			'e.rowid'=>'List:entrepot:ref','e.ref'=>'Text','e.lieu'=>'Text','e.address'=>'Text','e.zip'=>'Text','e.town'=>'Text','p.rowid'=>"List:product:label",
203
-			'p.ref'=>"Text",'p.fk_product_type'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.note'=>"Text",'p.price'=>"Numeric",'p.tva_tx'=>'Numeric',
204
-			'p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",'p.duration'=>"Duree",'p.datec'=>'Date','p.tms'=>'Date','p.pmp'=>'Numeric','p.cost_price'=>'Numeric',
205
-			'ps.reel'=>'Numeric'
206
-		);
207
-		$this->export_entities_array[$r]=array(
208
-			'e.rowid'=>'warehouse','e.ref'=>'warehouse','e.description'=>'warehouse','e.lieu'=>'warehouse','e.address'=>'warehouse','e.zip'=>'warehouse',
209
-			'e.town'=>'warehouse','p.rowid'=>"product",'p.ref'=>"product",'p.fk_product_type'=>"product",'p.label'=>"product",'p.description'=>"product",
210
-			'p.note'=>"product",'p.price'=>"product",'p.tva_tx'=>'product','p.tosell'=>"product",'p.tobuy'=>"product",'p.duration'=>"product",
211
-			'p.datec'=>'product','p.tms'=>'product','p.pmp'=>'product','p.cost_price'=>'product','ps.reel'=>'stock'
212
-		);
213
-		$this->export_aggregate_array[$r]=array('ps.reel'=>'SUM');    // TODO Not used yet
214
-		$this->export_dependencies_array[$r]=array('stock'=>array('p.rowid','e.rowid')); // We must keep this until the aggregate_array is used. To add unique key if we ask a field of a child to avoid the DISTINCT to discard them.
215
-		$keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra';
216
-		include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
217
-		$this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('ps.reel'=>'Stock'));
218
-
219
-		$this->export_sql_start[$r]='SELECT DISTINCT ';
220
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON extra.fk_object = p.rowid, '.MAIN_DB_PREFIX.'product_stock as ps, '.MAIN_DB_PREFIX.'entrepot as e';
221
-		$this->export_sql_end[$r] .=' WHERE p.rowid = ps.fk_product AND ps.fk_entrepot = e.rowid';
222
-		$this->export_sql_end[$r] .=' AND e.entity IN ('.getEntity('stock').')';
223
-		if ($conf->productbatch->enabled)
224
-		{
225
-			// Export of stock including lot number
226
-			$langs->load("productbatch");
227
-
228
-			// This request is same than previous but without field ps.stock (real stock in warehouse) and with link to subtable productbatch
229
-			$r++;
230
-
231
-			$this->export_code[$r]=$this->rights_class.'_lot';
232
-			$this->export_label[$r]="WarehousesAndProductsBatchDetail";	// Translation key (used only if key ExportDataset_xxx_z not found)
233
-			$this->export_permission[$r]=array(array("stock","lire"));
234
-			$this->export_fields_array[$r]=array(
235
-				'e.rowid'=>'IdWarehouse','e.ref'=>'LocationSummary','e.description'=>'DescWareHouse','e.lieu'=>'LieuWareHouse','e.address'=>'Address',
236
-				'e.zip'=>'Zip','e.town'=>'Town','p.rowid'=>"ProductId",'p.ref'=>"Ref",'p.fk_product_type'=>"Type",'p.label'=>"Label",'p.description'=>"Description",
237
-				'p.note'=>"Note",'p.price'=>"Price",'p.tva_tx'=>'VAT','p.tosell'=>"OnSell",'p.tobuy'=>'OnBuy','p.duration'=>"Duration",'p.datec'=>'DateCreation',
238
-				'p.tms'=>'DateModification','pb.rowid'=>'Id','pb.batch'=>'Batch','pb.qty'=>'Qty','pl.eatby'=>'EatByDate','pl.sellby'=>'SellByDate'
239
-			);
240
-			$this->export_TypeFields_array[$r]=array(
241
-				'e.rowid'=>'List:entrepot:ref','e.ref'=>'Text','e.lieu'=>'Text','e.description'=>'Text','e.address'=>'Text','e.zip'=>'Text','e.town'=>'Text',
242
-				'p.rowid'=>"List:product:label",'p.ref'=>"Text",'p.fk_product_type'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.note'=>"Text",
243
-				'p.price'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",'p.duration'=>"Duree",'p.datec'=>'Date','p.tms'=>'Date',
244
-				'pb.batch'=>'Text','pb.qty'=>'Numeric','pl.eatby'=>'Date','pl.sellby'=>'Date'
245
-			);
246
-			$this->export_entities_array[$r]=array(
247
-				'e.rowid'=>'warehouse','e.ref'=>'warehouse','e.description'=>'warehouse','e.lieu'=>'warehouse','e.address'=>'warehouse','e.zip'=>'warehouse',
248
-				'e.town'=>'warehouse','p.rowid'=>"product",'p.ref'=>"product",'p.fk_product_type'=>"product",'p.label'=>"product",'p.description'=>"product",
249
-				'p.note'=>"product",'p.price'=>"product",'p.tva_tx'=>'product','p.tosell'=>"product",'p.tobuy'=>"product",'p.duration'=>"product",
250
-				'p.datec'=>'product','p.tms'=>'product','pb.rowid'=>'stockbatch','pb.batch'=>'stockbatch','pb.qty'=>'stockbatch','pl.eatby'=>'batch',
251
-				'pl.sellby'=>'batch'
252
-			);
253
-			$this->export_aggregate_array[$r]=array('ps.reel'=>'SUM');    // TODO Not used yet
254
-			$this->export_dependencies_array[$r]=array('stockbatch'=>array('pb.rowid'),'batch'=>array('pb.rowid')); // We must keep this until the aggregate_array is used. To add unique key if we ask a field of a child to avoid the DISTINCT to discard them.
255
-			$keyforselect='product_lot'; $keyforelement='batch'; $keyforaliasextra='extra';
256
-			include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
257
-			$this->export_sql_start[$r]='SELECT DISTINCT ';
258
-			$this->export_sql_end[$r]  =' FROM ('.MAIN_DB_PREFIX.'product as p, '.MAIN_DB_PREFIX.'product_stock as ps, '.MAIN_DB_PREFIX.'product_batch as pb)';
259
-			$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_lot as pl ON pl.fk_product = p.rowid AND pl.batch = pb.batch';
260
-			$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_lot_extrafields as extra ON extra.fk_object = pl.rowid,';
261
-			$this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'entrepot as e';
262
-			$this->export_sql_end[$r] .=' WHERE p.rowid = ps.fk_product AND ps.fk_entrepot = e.rowid AND ps.rowid = pb.fk_product_stock';
263
-			$this->export_sql_end[$r] .=' AND e.entity IN ('.getEntity('stock').')';
264
-		}
265
-
266
-		// Export of stock movement
267
-		$r++;
268
-		$this->export_code[$r]=$this->rights_class.'_movement';
269
-		$this->export_label[$r]="StockMovements";	// Translation key (used only if key ExportDataset_xxx_z not found)
270
-		$this->export_permission[$r]=array(array("stock","lire"));
271
-		$this->export_fields_array[$r]=array(
272
-			'e.rowid'=>'IdWarehouse','e.ref'=>'LocationSummary','e.description'=>'DescWareHouse','e.lieu'=>'LieuWareHouse','e.address'=>'Address','e.zip'=>'Zip',
273
-			'e.town'=>'Town','p.rowid'=>"ProductId",'p.ref'=>"Ref",'p.fk_product_type'=>"Type",'p.label'=>"Label",'p.description'=>"Description",'p.note'=>"Note",
274
-			'p.price'=>"Price",'p.tva_tx'=>'VAT','p.tosell'=>"OnSell",'p.tobuy'=>'OnBuy','p.duration'=>"Duration",'p.datec'=>'DateCreation',
275
-			'p.tms'=>'DateModification','sm.rowid'=>'MovementId','sm.value'=>'Qty','sm.datem'=>'DateMovement','sm.label'=>'MovementLabel',
276
-			'sm.inventorycode'=>'InventoryCode'
277
-		);
278
-		$this->export_TypeFields_array[$r]=array(
279
-			'e.rowid'=>'List:entrepot:ref','e.ref'=>'Text','e.description'=>'Text','e.lieu'=>'Text','e.address'=>'Text','e.zip'=>'Text','e.town'=>'Text',
280
-			'p.rowid'=>"List:product:label",'p.ref'=>"Text",'p.fk_product_type'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.note'=>"Text",
281
-			'p.price'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",'p.duration'=>"Duree",'p.datec'=>'Date','p.tms'=>'Date',
282
-			'sm.rowid'=>'Numeric','sm.value'=>'Numeric','sm.datem'=>'Date','sm.batch'=>'Text','sm.label'=>'Text','sm.inventorycode'=>'Text'
283
-		);
284
-		$this->export_entities_array[$r]=array(
285
-			'e.rowid'=>'warehouse','e.ref'=>'warehouse','e.description'=>'warehouse','e.lieu'=>'warehouse','e.address'=>'warehouse','e.zip'=>'warehouse',
286
-			'e.town'=>'warehouse','p.rowid'=>"product",'p.ref'=>"product",'p.fk_product_type'=>"product",'p.label'=>"product",'p.description'=>"product",
287
-			'p.note'=>"product",'p.price'=>"product",'p.tva_tx'=>'product','p.tosell'=>"product",'p.tobuy'=>"product",'p.duration'=>"product",'p.datec'=>'product',
288
-			'p.tms'=>'product','sm.rowid'=>'movement','sm.value'=>'movement','sm.datem'=>'movement','sm.label'=>'movement','sm.inventorycode'=>'movement'
289
-		);
290
-		if ($conf->productbatch->enabled)
291
-		{
292
-			$this->export_fields_array[$r]['sm.batch']='Batch';
293
-			$this->export_TypeFields_array[$r]['sm.batch']='Text';
294
-			$this->export_entities_array[$r]['sm.batch']='movement';
295
-		}
296
-		$this->export_aggregate_array[$r]=array('sm.value'=>'SUM');    // TODO Not used yet
297
-		$this->export_dependencies_array[$r]=array('movement'=>array('sm.rowid')); // We must keep this until the aggregate_array is used. To add unique key if we ask a field of a child to avoid the DISTINCT to discard them.
298
-		$this->export_sql_start[$r]='SELECT DISTINCT ';
299
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p, '.MAIN_DB_PREFIX.'stock_mouvement as sm, '.MAIN_DB_PREFIX.'entrepot as e';
300
-		$this->export_sql_end[$r] .=' WHERE p.rowid = sm.fk_product AND sm.fk_entrepot = e.rowid';
301
-		$this->export_sql_end[$r] .=' AND e.entity IN ('.getEntity('stock').')';
302
-
303
-		// Imports
304
-		//--------
305
-
306
-		$r=0;
307
-
308
-		// Import warehouses
309
-		$r++;
310
-		$this->import_code[$r]=$this->rights_class.'_'.$r;
311
-		$this->import_label[$r]="Warehouses";	// Translation key
312
-		$this->import_icon[$r]=$this->picto;
313
-		$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
314
-		$this->import_tables_array[$r]=array('e'=>MAIN_DB_PREFIX.'entrepot');
315
-		$this->import_tables_creator_array[$r]=array('e'=>'fk_user_author');
316
-		$this->import_fields_array[$r]=array('e.ref'=>"LocationSummary*",
317
-				'e.description'=>"DescWareHouse",'e.lieu'=>"LieuWareHouse",
318
-				'e.address'=>"Address",'e.zip'=>'Zip','e.fk_pays'=>'CountryCode',
319
-				'e.statut'=>'Status'
320
-		);
321
-
322
-		$this->import_convertvalue_array[$r]=array(
323
-				'e.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ccountry.class.php','class'=>'Ccountry','method'=>'fetch','dict'=>'DictionaryCountry')
324
-		);
325
-		$this->import_regex_array[$r]=array('e.statut'=>'^[0|1]');
326
-		$this->import_examplevalues_array[$r]=array('e.ref'=>"ALM001",
327
-				'e.description'=>"Central Warehouse",'e.lieu'=>"Central",
328
-				'e.address'=>"Route 66",'e.zip'=>'28080','e.fk_pays'=>'US',
329
-				'e.statut'=>'1');
330
-
331
-		// Import stocks
332
-		$r++;
333
-		$this->import_code[$r]=$this->rights_class.'_'.$r;
334
-		$this->import_label[$r]="Stocks";	// Translation key
335
-		$this->import_icon[$r]=$this->picto;
336
-		$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
337
-		$this->import_tables_array[$r]=array('ps'=>MAIN_DB_PREFIX.'product_stock');
338
-		$this->import_fields_array[$r]=array('ps.fk_product'=>"Product*",'ps.fk_entrepot'=>"Warehouse*",'ps.reel'=>"Stock*");
339
-
340
-		$this->import_convertvalue_array[$r]=array(
341
-			'ps.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'product'),
342
-			'ps.fk_entrepot'=>array('rule'=>'fetchidfromref','classfile'=>'/product/stock/class/entrepot.class.php','class'=>'Entrepot','method'=>'fetch','element'=>'ref')
343
-		  );
344
-		$this->import_examplevalues_array[$r]=array(
345
-		    'ps.fk_product'=>"PREF123456",'ps.fk_entrepot'=>"ALM001",'ps.reel'=>"10"
346
-		);
347
-		$this->import_run_sql_after_array[$r]=array(    // Because we may change data that are denormalized, we must update dernormalized data after.
348
-		    'UPDATE llx_product p SET p.stock= (SELECT SUM(ps.reel) FROM llx_product_stock ps WHERE ps.fk_product = p.rowid);'
349
-		);
350
-	}
351
-
352
-
353
-	/**
354
-	 *		Function called when module is enabled.
355
-	 *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
356
-	 *		It also creates data directories
357
-	 *
358
-	 *      @param      string	$options    Options when enabling module ('', 'noboxes')
359
-	 *      @return     int             	1 if OK, 0 if KO
360
-	 */
361
-	function init($options='')
362
-	{
363
-		global $conf,$langs;
364
-
365
-		// Permissions
366
-		$this->remove($options);
367
-
368
-		//ODT template
369
-		$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/stock/template_stock.odt';
370
-		$dirodt=DOL_DATA_ROOT.'/doctemplates/stock';
371
-		$dest=$dirodt.'/template_stock.odt';
372
-
373
-		if (file_exists($src) && ! file_exists($dest))
374
-		{
375
-			require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
376
-			dol_mkdir($dirodt);
377
-			$result=dol_copy($src,$dest,0,0);
378
-			if ($result < 0)
379
-			{
380
-				$langs->load("errors");
381
-				$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
382
-				return 0;
383
-			}
384
-		}
385
-
386
-		$sql = array();
387
-
388
-		$sql = array(
389
-			 "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[1][2])."' AND type = 'stock' AND entity = ".$conf->entity,
390
-			 "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[1][2])."','stock',".$conf->entity.")",
391
-			 "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[2][2])."' AND type = 'mouvement' AND entity = ".$conf->entity,
392
-			 "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[2][2])."','mouvement',".$conf->entity.")",
393
-		);
394
-
395
-		return $this->_init($sql,$options);
396
-	}
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, $langs;
46
+
47
+        $this->db = $db;
48
+        $this->numero = 52;
49
+
50
+        $this->family = "products";
51
+        $this->module_position = '40';
52
+        // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
53
+        $this->name = preg_replace('/^mod/i','',get_class($this));
54
+        $this->description = "Gestion des stocks";
55
+
56
+        // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
57
+        $this->version = 'dolibarr';
58
+
59
+        $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
60
+        $this->picto='stock';
61
+
62
+        // Data directories to create when module is enabled
63
+        $this->dirs = array("/stock/temp");
64
+
65
+        $this->config_page_url = array("stock.php");
66
+
67
+        // Dependencies
68
+        $this->hidden = false;			// A condition to hide module
69
+        $this->depends = array("modProduct");		// List of module class names as string that must be enabled if this module is enabled
70
+        $this->requiredby = array("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
+        $this->langfiles = array("stocks");
74
+
75
+        // Constants
76
+        $this->const = array();
77
+        $r=0;
78
+
79
+        $this->const[$r] = array('STOCK_ALLOW_NEGATIVE_TRANSFER','chaine','1','',1);
80
+
81
+        $r++;
82
+        $this->const[$r][0] = "STOCK_ADDON_PDF";
83
+        $this->const[$r][1] = "chaine";
84
+        $this->const[$r][2] = "Standard";
85
+        $this->const[$r][3] = 'Name of PDF model of stock';
86
+        $this->const[$r][4] = 0;
87
+
88
+        $r++;
89
+        $this->const[$r][0] = "MOUVEMENT_ADDON_PDF";
90
+        $this->const[$r][1] = "chaine";
91
+        $this->const[$r][2] = "StdMouvement";
92
+        $this->const[$r][3] = 'Name of PDF model of stock mouvement';
93
+        $this->const[$r][4] = 0;
94
+
95
+        $r++;
96
+        $this->const[$r][0] = "STOCK_ADDON_PDF_ODT_PATH";
97
+        $this->const[$r][1] = "chaine";
98
+        $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/stocks";
99
+        $this->const[$r][3] = "";
100
+        $this->const[$r][4] = 0;
101
+
102
+        $r++;
103
+        $this->const[$r][0] = "MOUVEMENT_ADDON_PDF_ODT_PATH";
104
+        $this->const[$r][1] = "chaine";
105
+        $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/stocks/mouvements";
106
+        $this->const[$r][3] = "";
107
+        $this->const[$r][4] = 0;
108
+
109
+        // Boxes
110
+        $this->boxes = array();
111
+
112
+        // Permissions
113
+        $this->rights = array();
114
+        $this->rights_class = 'stock';
115
+
116
+        $this->rights[0][0] = 1001;
117
+        $this->rights[0][1] = 'Lire les stocks';
118
+        $this->rights[0][2] = 'r';
119
+        $this->rights[0][3] = 0;
120
+        $this->rights[0][4] = 'lire';
121
+        $this->rights[0][5] = '';
122
+
123
+        $this->rights[1][0] = 1002;
124
+        $this->rights[1][1] = 'Creer/Modifier les stocks';
125
+        $this->rights[1][2] = 'w';
126
+        $this->rights[1][3] = 0;
127
+        $this->rights[1][4] = 'creer';
128
+        $this->rights[1][5] = '';
129
+
130
+        $this->rights[2][0] = 1003;
131
+        $this->rights[2][1] = 'Supprimer les stocks';
132
+        $this->rights[2][2] = 'd';
133
+        $this->rights[2][3] = 0;
134
+        $this->rights[2][4] = 'supprimer';
135
+        $this->rights[2][5] = '';
136
+
137
+        $this->rights[3][0] = 1004;
138
+        $this->rights[3][1] = 'Lire mouvements de stocks';
139
+        $this->rights[3][2] = 'r';
140
+        $this->rights[3][3] = 0;
141
+        $this->rights[3][4] = 'mouvement';
142
+        $this->rights[3][5] = 'lire';
143
+
144
+        $this->rights[4][0] = 1005;
145
+        $this->rights[4][1] = 'Creer/modifier mouvements de stocks';
146
+        $this->rights[4][2] = 'w';
147
+        $this->rights[4][3] = 0;
148
+        $this->rights[4][4] = 'mouvement';
149
+        $this->rights[4][5] = 'creer';
150
+
151
+        if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
152
+
153
+        $this->rights[5][0] = 1011;
154
+        $this->rights[5][1] = 'inventoryReadPermission';	// Permission label
155
+        $this->rights[5][3] = 0; 					// Permission by default for new user (0/1)
156
+        $this->rights[5][4] = 'inventory_advance';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
157
+        $this->rights[5][5] = 'read';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
158
+
159
+        $this->rights[6][0] = 1012;
160
+        $this->rights[6][1] = 'inventoryCreatePermission';	// Permission label
161
+        $this->rights[6][3] = 0; 					// Permission by default for new user (0/1)
162
+        $this->rights[6][4] = 'inventory_advance';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
163
+        $this->rights[6][5] = 'write';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
164
+
165
+        $this->rights[8][0] = 1014;
166
+        $this->rights[8][1] = 'inventoryValidatePermission';	// Permission label
167
+        $this->rights[8][3] = 0; 					// Permission by default for new user (0/1)
168
+        $this->rights[8][4] = 'inventory_advance';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
169
+        $this->rights[8][5] = 'validate';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
170
+
171
+        $this->rights[9][0] = 1015;
172
+        $this->rights[9][1] = 'inventoryChangePMPPermission';	// Permission label
173
+        $this->rights[9][3] = 0; 					// Permission by default for new user (0/1)
174
+        $this->rights[9][4] = 'inventory_advance';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
175
+        $this->rights[9][5] = 'changePMP';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
176
+        }
177
+
178
+        // Main menu entries
179
+        $this->menu = array();			// List of menus to add
180
+        $r=0;
181
+
182
+        // Menus
183
+        //-------
184
+        $this->menu = 1;        // This module add menu entries. They are coded into menu manager.
185
+
186
+
187
+        // Exports
188
+        //--------
189
+        $r=0;
190
+
191
+        $r++;
192
+        $this->export_code[$r]=$this->rights_class;
193
+        $this->export_label[$r]="WarehousesAndProducts";	// Translation key (used only if key ExportDataset_xxx_z not found)
194
+        $this->export_permission[$r]=array(array("stock","lire"));
195
+        $this->export_fields_array[$r]=array(
196
+            'e.rowid'=>'IdWarehouse','e.ref'=>'LocationSummary','e.description'=>'DescWareHouse','e.lieu'=>'LieuWareHouse','e.address'=>'Address',
197
+            'e.zip'=>'Zip','e.town'=>'Town','p.rowid'=>"ProductId",'p.ref'=>"Ref",'p.fk_product_type'=>"Type",'p.label'=>"Label",'p.description'=>"Description",
198
+            'p.note'=>"Note",'p.price'=>"Price",'p.tva_tx'=>'VAT','p.tosell'=>"OnSell",'p.tobuy'=>'OnBuy','p.duration'=>"Duration",'p.datec'=>'DateCreation',
199
+            'p.tms'=>'DateModification','p.pmp'=>'PMPValue','p.cost_price'=>'CostPrice'
200
+        );
201
+        $this->export_TypeFields_array[$r]=array(
202
+            'e.rowid'=>'List:entrepot:ref','e.ref'=>'Text','e.lieu'=>'Text','e.address'=>'Text','e.zip'=>'Text','e.town'=>'Text','p.rowid'=>"List:product:label",
203
+            'p.ref'=>"Text",'p.fk_product_type'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.note'=>"Text",'p.price'=>"Numeric",'p.tva_tx'=>'Numeric',
204
+            'p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",'p.duration'=>"Duree",'p.datec'=>'Date','p.tms'=>'Date','p.pmp'=>'Numeric','p.cost_price'=>'Numeric',
205
+            'ps.reel'=>'Numeric'
206
+        );
207
+        $this->export_entities_array[$r]=array(
208
+            'e.rowid'=>'warehouse','e.ref'=>'warehouse','e.description'=>'warehouse','e.lieu'=>'warehouse','e.address'=>'warehouse','e.zip'=>'warehouse',
209
+            'e.town'=>'warehouse','p.rowid'=>"product",'p.ref'=>"product",'p.fk_product_type'=>"product",'p.label'=>"product",'p.description'=>"product",
210
+            'p.note'=>"product",'p.price'=>"product",'p.tva_tx'=>'product','p.tosell'=>"product",'p.tobuy'=>"product",'p.duration'=>"product",
211
+            'p.datec'=>'product','p.tms'=>'product','p.pmp'=>'product','p.cost_price'=>'product','ps.reel'=>'stock'
212
+        );
213
+        $this->export_aggregate_array[$r]=array('ps.reel'=>'SUM');    // TODO Not used yet
214
+        $this->export_dependencies_array[$r]=array('stock'=>array('p.rowid','e.rowid')); // We must keep this until the aggregate_array is used. To add unique key if we ask a field of a child to avoid the DISTINCT to discard them.
215
+        $keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra';
216
+        include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
217
+        $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('ps.reel'=>'Stock'));
218
+
219
+        $this->export_sql_start[$r]='SELECT DISTINCT ';
220
+        $this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON extra.fk_object = p.rowid, '.MAIN_DB_PREFIX.'product_stock as ps, '.MAIN_DB_PREFIX.'entrepot as e';
221
+        $this->export_sql_end[$r] .=' WHERE p.rowid = ps.fk_product AND ps.fk_entrepot = e.rowid';
222
+        $this->export_sql_end[$r] .=' AND e.entity IN ('.getEntity('stock').')';
223
+        if ($conf->productbatch->enabled)
224
+        {
225
+            // Export of stock including lot number
226
+            $langs->load("productbatch");
227
+
228
+            // This request is same than previous but without field ps.stock (real stock in warehouse) and with link to subtable productbatch
229
+            $r++;
230
+
231
+            $this->export_code[$r]=$this->rights_class.'_lot';
232
+            $this->export_label[$r]="WarehousesAndProductsBatchDetail";	// Translation key (used only if key ExportDataset_xxx_z not found)
233
+            $this->export_permission[$r]=array(array("stock","lire"));
234
+            $this->export_fields_array[$r]=array(
235
+                'e.rowid'=>'IdWarehouse','e.ref'=>'LocationSummary','e.description'=>'DescWareHouse','e.lieu'=>'LieuWareHouse','e.address'=>'Address',
236
+                'e.zip'=>'Zip','e.town'=>'Town','p.rowid'=>"ProductId",'p.ref'=>"Ref",'p.fk_product_type'=>"Type",'p.label'=>"Label",'p.description'=>"Description",
237
+                'p.note'=>"Note",'p.price'=>"Price",'p.tva_tx'=>'VAT','p.tosell'=>"OnSell",'p.tobuy'=>'OnBuy','p.duration'=>"Duration",'p.datec'=>'DateCreation',
238
+                'p.tms'=>'DateModification','pb.rowid'=>'Id','pb.batch'=>'Batch','pb.qty'=>'Qty','pl.eatby'=>'EatByDate','pl.sellby'=>'SellByDate'
239
+            );
240
+            $this->export_TypeFields_array[$r]=array(
241
+                'e.rowid'=>'List:entrepot:ref','e.ref'=>'Text','e.lieu'=>'Text','e.description'=>'Text','e.address'=>'Text','e.zip'=>'Text','e.town'=>'Text',
242
+                'p.rowid'=>"List:product:label",'p.ref'=>"Text",'p.fk_product_type'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.note'=>"Text",
243
+                'p.price'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",'p.duration'=>"Duree",'p.datec'=>'Date','p.tms'=>'Date',
244
+                'pb.batch'=>'Text','pb.qty'=>'Numeric','pl.eatby'=>'Date','pl.sellby'=>'Date'
245
+            );
246
+            $this->export_entities_array[$r]=array(
247
+                'e.rowid'=>'warehouse','e.ref'=>'warehouse','e.description'=>'warehouse','e.lieu'=>'warehouse','e.address'=>'warehouse','e.zip'=>'warehouse',
248
+                'e.town'=>'warehouse','p.rowid'=>"product",'p.ref'=>"product",'p.fk_product_type'=>"product",'p.label'=>"product",'p.description'=>"product",
249
+                'p.note'=>"product",'p.price'=>"product",'p.tva_tx'=>'product','p.tosell'=>"product",'p.tobuy'=>"product",'p.duration'=>"product",
250
+                'p.datec'=>'product','p.tms'=>'product','pb.rowid'=>'stockbatch','pb.batch'=>'stockbatch','pb.qty'=>'stockbatch','pl.eatby'=>'batch',
251
+                'pl.sellby'=>'batch'
252
+            );
253
+            $this->export_aggregate_array[$r]=array('ps.reel'=>'SUM');    // TODO Not used yet
254
+            $this->export_dependencies_array[$r]=array('stockbatch'=>array('pb.rowid'),'batch'=>array('pb.rowid')); // We must keep this until the aggregate_array is used. To add unique key if we ask a field of a child to avoid the DISTINCT to discard them.
255
+            $keyforselect='product_lot'; $keyforelement='batch'; $keyforaliasextra='extra';
256
+            include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
257
+            $this->export_sql_start[$r]='SELECT DISTINCT ';
258
+            $this->export_sql_end[$r]  =' FROM ('.MAIN_DB_PREFIX.'product as p, '.MAIN_DB_PREFIX.'product_stock as ps, '.MAIN_DB_PREFIX.'product_batch as pb)';
259
+            $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_lot as pl ON pl.fk_product = p.rowid AND pl.batch = pb.batch';
260
+            $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_lot_extrafields as extra ON extra.fk_object = pl.rowid,';
261
+            $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'entrepot as e';
262
+            $this->export_sql_end[$r] .=' WHERE p.rowid = ps.fk_product AND ps.fk_entrepot = e.rowid AND ps.rowid = pb.fk_product_stock';
263
+            $this->export_sql_end[$r] .=' AND e.entity IN ('.getEntity('stock').')';
264
+        }
265
+
266
+        // Export of stock movement
267
+        $r++;
268
+        $this->export_code[$r]=$this->rights_class.'_movement';
269
+        $this->export_label[$r]="StockMovements";	// Translation key (used only if key ExportDataset_xxx_z not found)
270
+        $this->export_permission[$r]=array(array("stock","lire"));
271
+        $this->export_fields_array[$r]=array(
272
+            'e.rowid'=>'IdWarehouse','e.ref'=>'LocationSummary','e.description'=>'DescWareHouse','e.lieu'=>'LieuWareHouse','e.address'=>'Address','e.zip'=>'Zip',
273
+            'e.town'=>'Town','p.rowid'=>"ProductId",'p.ref'=>"Ref",'p.fk_product_type'=>"Type",'p.label'=>"Label",'p.description'=>"Description",'p.note'=>"Note",
274
+            'p.price'=>"Price",'p.tva_tx'=>'VAT','p.tosell'=>"OnSell",'p.tobuy'=>'OnBuy','p.duration'=>"Duration",'p.datec'=>'DateCreation',
275
+            'p.tms'=>'DateModification','sm.rowid'=>'MovementId','sm.value'=>'Qty','sm.datem'=>'DateMovement','sm.label'=>'MovementLabel',
276
+            'sm.inventorycode'=>'InventoryCode'
277
+        );
278
+        $this->export_TypeFields_array[$r]=array(
279
+            'e.rowid'=>'List:entrepot:ref','e.ref'=>'Text','e.description'=>'Text','e.lieu'=>'Text','e.address'=>'Text','e.zip'=>'Text','e.town'=>'Text',
280
+            'p.rowid'=>"List:product:label",'p.ref'=>"Text",'p.fk_product_type'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.note'=>"Text",
281
+            'p.price'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",'p.duration'=>"Duree",'p.datec'=>'Date','p.tms'=>'Date',
282
+            'sm.rowid'=>'Numeric','sm.value'=>'Numeric','sm.datem'=>'Date','sm.batch'=>'Text','sm.label'=>'Text','sm.inventorycode'=>'Text'
283
+        );
284
+        $this->export_entities_array[$r]=array(
285
+            'e.rowid'=>'warehouse','e.ref'=>'warehouse','e.description'=>'warehouse','e.lieu'=>'warehouse','e.address'=>'warehouse','e.zip'=>'warehouse',
286
+            'e.town'=>'warehouse','p.rowid'=>"product",'p.ref'=>"product",'p.fk_product_type'=>"product",'p.label'=>"product",'p.description'=>"product",
287
+            'p.note'=>"product",'p.price'=>"product",'p.tva_tx'=>'product','p.tosell'=>"product",'p.tobuy'=>"product",'p.duration'=>"product",'p.datec'=>'product',
288
+            'p.tms'=>'product','sm.rowid'=>'movement','sm.value'=>'movement','sm.datem'=>'movement','sm.label'=>'movement','sm.inventorycode'=>'movement'
289
+        );
290
+        if ($conf->productbatch->enabled)
291
+        {
292
+            $this->export_fields_array[$r]['sm.batch']='Batch';
293
+            $this->export_TypeFields_array[$r]['sm.batch']='Text';
294
+            $this->export_entities_array[$r]['sm.batch']='movement';
295
+        }
296
+        $this->export_aggregate_array[$r]=array('sm.value'=>'SUM');    // TODO Not used yet
297
+        $this->export_dependencies_array[$r]=array('movement'=>array('sm.rowid')); // We must keep this until the aggregate_array is used. To add unique key if we ask a field of a child to avoid the DISTINCT to discard them.
298
+        $this->export_sql_start[$r]='SELECT DISTINCT ';
299
+        $this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p, '.MAIN_DB_PREFIX.'stock_mouvement as sm, '.MAIN_DB_PREFIX.'entrepot as e';
300
+        $this->export_sql_end[$r] .=' WHERE p.rowid = sm.fk_product AND sm.fk_entrepot = e.rowid';
301
+        $this->export_sql_end[$r] .=' AND e.entity IN ('.getEntity('stock').')';
302
+
303
+        // Imports
304
+        //--------
305
+
306
+        $r=0;
307
+
308
+        // Import warehouses
309
+        $r++;
310
+        $this->import_code[$r]=$this->rights_class.'_'.$r;
311
+        $this->import_label[$r]="Warehouses";	// Translation key
312
+        $this->import_icon[$r]=$this->picto;
313
+        $this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
314
+        $this->import_tables_array[$r]=array('e'=>MAIN_DB_PREFIX.'entrepot');
315
+        $this->import_tables_creator_array[$r]=array('e'=>'fk_user_author');
316
+        $this->import_fields_array[$r]=array('e.ref'=>"LocationSummary*",
317
+                'e.description'=>"DescWareHouse",'e.lieu'=>"LieuWareHouse",
318
+                'e.address'=>"Address",'e.zip'=>'Zip','e.fk_pays'=>'CountryCode',
319
+                'e.statut'=>'Status'
320
+        );
321
+
322
+        $this->import_convertvalue_array[$r]=array(
323
+                'e.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ccountry.class.php','class'=>'Ccountry','method'=>'fetch','dict'=>'DictionaryCountry')
324
+        );
325
+        $this->import_regex_array[$r]=array('e.statut'=>'^[0|1]');
326
+        $this->import_examplevalues_array[$r]=array('e.ref'=>"ALM001",
327
+                'e.description'=>"Central Warehouse",'e.lieu'=>"Central",
328
+                'e.address'=>"Route 66",'e.zip'=>'28080','e.fk_pays'=>'US',
329
+                'e.statut'=>'1');
330
+
331
+        // Import stocks
332
+        $r++;
333
+        $this->import_code[$r]=$this->rights_class.'_'.$r;
334
+        $this->import_label[$r]="Stocks";	// Translation key
335
+        $this->import_icon[$r]=$this->picto;
336
+        $this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
337
+        $this->import_tables_array[$r]=array('ps'=>MAIN_DB_PREFIX.'product_stock');
338
+        $this->import_fields_array[$r]=array('ps.fk_product'=>"Product*",'ps.fk_entrepot'=>"Warehouse*",'ps.reel'=>"Stock*");
339
+
340
+        $this->import_convertvalue_array[$r]=array(
341
+            'ps.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'product'),
342
+            'ps.fk_entrepot'=>array('rule'=>'fetchidfromref','classfile'=>'/product/stock/class/entrepot.class.php','class'=>'Entrepot','method'=>'fetch','element'=>'ref')
343
+            );
344
+        $this->import_examplevalues_array[$r]=array(
345
+            'ps.fk_product'=>"PREF123456",'ps.fk_entrepot'=>"ALM001",'ps.reel'=>"10"
346
+        );
347
+        $this->import_run_sql_after_array[$r]=array(    // Because we may change data that are denormalized, we must update dernormalized data after.
348
+            'UPDATE llx_product p SET p.stock= (SELECT SUM(ps.reel) FROM llx_product_stock ps WHERE ps.fk_product = p.rowid);'
349
+        );
350
+    }
351
+
352
+
353
+    /**
354
+     *		Function called when module is enabled.
355
+     *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
356
+     *		It also creates data directories
357
+     *
358
+     *      @param      string	$options    Options when enabling module ('', 'noboxes')
359
+     *      @return     int             	1 if OK, 0 if KO
360
+     */
361
+    function init($options='')
362
+    {
363
+        global $conf,$langs;
364
+
365
+        // Permissions
366
+        $this->remove($options);
367
+
368
+        //ODT template
369
+        $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/stock/template_stock.odt';
370
+        $dirodt=DOL_DATA_ROOT.'/doctemplates/stock';
371
+        $dest=$dirodt.'/template_stock.odt';
372
+
373
+        if (file_exists($src) && ! file_exists($dest))
374
+        {
375
+            require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
376
+            dol_mkdir($dirodt);
377
+            $result=dol_copy($src,$dest,0,0);
378
+            if ($result < 0)
379
+            {
380
+                $langs->load("errors");
381
+                $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
382
+                return 0;
383
+            }
384
+        }
385
+
386
+        $sql = array();
387
+
388
+        $sql = array(
389
+                "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[1][2])."' AND type = 'stock' AND entity = ".$conf->entity,
390
+                "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[1][2])."','stock',".$conf->entity.")",
391
+                "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[2][2])."' AND type = 'mouvement' AND entity = ".$conf->entity,
392
+                "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[2][2])."','mouvement',".$conf->entity.")",
393
+        );
394
+
395
+        return $this->_init($sql,$options);
396
+    }
397 397
 }
Please login to merge, or discard this patch.
Spacing   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
  *	\brief      Fichier de description et activation du module Stock
27 27
  */
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
 /**
@@ -50,14 +50,14 @@  discard block
 block discarded – undo
50 50
 		$this->family = "products";
51 51
 		$this->module_position = '40';
52 52
 		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
53
-		$this->name = preg_replace('/^mod/i','',get_class($this));
53
+		$this->name = preg_replace('/^mod/i', '', get_class($this));
54 54
 		$this->description = "Gestion des stocks";
55 55
 
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
-		$this->picto='stock';
60
+		$this->picto = 'stock';
61 61
 
62 62
 		// Data directories to create when module is enabled
63 63
 		$this->dirs = array("/stock/temp");
@@ -65,18 +65,18 @@  discard block
 block discarded – undo
65 65
 		$this->config_page_url = array("stock.php");
66 66
 
67 67
 		// Dependencies
68
-		$this->hidden = false;			// A condition to hide module
69
-		$this->depends = array("modProduct");		// List of module class names as string that must be enabled if this module is enabled
70
-		$this->requiredby = array("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("modProduct"); // List of module class names as string that must be enabled if this module is enabled
70
+		$this->requiredby = array("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
 		$this->langfiles = array("stocks");
74 74
 
75 75
 		// Constants
76 76
 		$this->const = array();
77
-		$r=0;
77
+		$r = 0;
78 78
 
79
-		$this->const[$r] = array('STOCK_ALLOW_NEGATIVE_TRANSFER','chaine','1','',1);
79
+		$this->const[$r] = array('STOCK_ALLOW_NEGATIVE_TRANSFER', 'chaine', '1', '', 1);
80 80
 
81 81
 		$r++;
82 82
 		$this->const[$r][0] = "STOCK_ADDON_PDF";
@@ -151,75 +151,75 @@  discard block
 block discarded – undo
151 151
 		if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
152 152
 
153 153
 		$this->rights[5][0] = 1011;
154
-		$this->rights[5][1] = 'inventoryReadPermission';	// Permission label
155
-		$this->rights[5][3] = 0; 					// Permission by default for new user (0/1)
156
-		$this->rights[5][4] = 'inventory_advance';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
157
-		$this->rights[5][5] = 'read';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
154
+		$this->rights[5][1] = 'inventoryReadPermission'; // Permission label
155
+		$this->rights[5][3] = 0; // Permission by default for new user (0/1)
156
+		$this->rights[5][4] = 'inventory_advance'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
157
+		$this->rights[5][5] = 'read'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
158 158
 
159 159
 		$this->rights[6][0] = 1012;
160
-		$this->rights[6][1] = 'inventoryCreatePermission';	// Permission label
161
-		$this->rights[6][3] = 0; 					// Permission by default for new user (0/1)
162
-		$this->rights[6][4] = 'inventory_advance';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
163
-		$this->rights[6][5] = 'write';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
160
+		$this->rights[6][1] = 'inventoryCreatePermission'; // Permission label
161
+		$this->rights[6][3] = 0; // Permission by default for new user (0/1)
162
+		$this->rights[6][4] = 'inventory_advance'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
163
+		$this->rights[6][5] = 'write'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
164 164
 
165 165
 		$this->rights[8][0] = 1014;
166
-		$this->rights[8][1] = 'inventoryValidatePermission';	// Permission label
167
-		$this->rights[8][3] = 0; 					// Permission by default for new user (0/1)
168
-		$this->rights[8][4] = 'inventory_advance';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
169
-		$this->rights[8][5] = 'validate';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
166
+		$this->rights[8][1] = 'inventoryValidatePermission'; // Permission label
167
+		$this->rights[8][3] = 0; // Permission by default for new user (0/1)
168
+		$this->rights[8][4] = 'inventory_advance'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
169
+		$this->rights[8][5] = 'validate'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
170 170
 
171 171
 		$this->rights[9][0] = 1015;
172
-		$this->rights[9][1] = 'inventoryChangePMPPermission';	// Permission label
173
-		$this->rights[9][3] = 0; 					// Permission by default for new user (0/1)
174
-		$this->rights[9][4] = 'inventory_advance';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
175
-		$this->rights[9][5] = 'changePMP';			// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
172
+		$this->rights[9][1] = 'inventoryChangePMPPermission'; // Permission label
173
+		$this->rights[9][3] = 0; // Permission by default for new user (0/1)
174
+		$this->rights[9][4] = 'inventory_advance'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
175
+		$this->rights[9][5] = 'changePMP'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
176 176
 		}
177 177
 
178 178
 		// Main menu entries
179
-		$this->menu = array();			// List of menus to add
180
-		$r=0;
179
+		$this->menu = array(); // List of menus to add
180
+		$r = 0;
181 181
 
182 182
 		// Menus
183 183
 		//-------
184
-		$this->menu = 1;        // This module add menu entries. They are coded into menu manager.
184
+		$this->menu = 1; // This module add menu entries. They are coded into menu manager.
185 185
 
186 186
 
187 187
 		// Exports
188 188
 		//--------
189
-		$r=0;
189
+		$r = 0;
190 190
 
191 191
 		$r++;
192
-		$this->export_code[$r]=$this->rights_class;
193
-		$this->export_label[$r]="WarehousesAndProducts";	// Translation key (used only if key ExportDataset_xxx_z not found)
194
-		$this->export_permission[$r]=array(array("stock","lire"));
195
-		$this->export_fields_array[$r]=array(
196
-			'e.rowid'=>'IdWarehouse','e.ref'=>'LocationSummary','e.description'=>'DescWareHouse','e.lieu'=>'LieuWareHouse','e.address'=>'Address',
197
-			'e.zip'=>'Zip','e.town'=>'Town','p.rowid'=>"ProductId",'p.ref'=>"Ref",'p.fk_product_type'=>"Type",'p.label'=>"Label",'p.description'=>"Description",
198
-			'p.note'=>"Note",'p.price'=>"Price",'p.tva_tx'=>'VAT','p.tosell'=>"OnSell",'p.tobuy'=>'OnBuy','p.duration'=>"Duration",'p.datec'=>'DateCreation',
199
-			'p.tms'=>'DateModification','p.pmp'=>'PMPValue','p.cost_price'=>'CostPrice'
192
+		$this->export_code[$r] = $this->rights_class;
193
+		$this->export_label[$r] = "WarehousesAndProducts"; // Translation key (used only if key ExportDataset_xxx_z not found)
194
+		$this->export_permission[$r] = array(array("stock", "lire"));
195
+		$this->export_fields_array[$r] = array(
196
+			'e.rowid'=>'IdWarehouse', 'e.ref'=>'LocationSummary', 'e.description'=>'DescWareHouse', 'e.lieu'=>'LieuWareHouse', 'e.address'=>'Address',
197
+			'e.zip'=>'Zip', 'e.town'=>'Town', 'p.rowid'=>"ProductId", 'p.ref'=>"Ref", 'p.fk_product_type'=>"Type", 'p.label'=>"Label", 'p.description'=>"Description",
198
+			'p.note'=>"Note", 'p.price'=>"Price", 'p.tva_tx'=>'VAT', 'p.tosell'=>"OnSell", 'p.tobuy'=>'OnBuy', 'p.duration'=>"Duration", 'p.datec'=>'DateCreation',
199
+			'p.tms'=>'DateModification', 'p.pmp'=>'PMPValue', 'p.cost_price'=>'CostPrice'
200 200
 		);
201
-		$this->export_TypeFields_array[$r]=array(
202
-			'e.rowid'=>'List:entrepot:ref','e.ref'=>'Text','e.lieu'=>'Text','e.address'=>'Text','e.zip'=>'Text','e.town'=>'Text','p.rowid'=>"List:product:label",
203
-			'p.ref'=>"Text",'p.fk_product_type'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.note'=>"Text",'p.price'=>"Numeric",'p.tva_tx'=>'Numeric',
204
-			'p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",'p.duration'=>"Duree",'p.datec'=>'Date','p.tms'=>'Date','p.pmp'=>'Numeric','p.cost_price'=>'Numeric',
201
+		$this->export_TypeFields_array[$r] = array(
202
+			'e.rowid'=>'List:entrepot:ref', 'e.ref'=>'Text', 'e.lieu'=>'Text', 'e.address'=>'Text', 'e.zip'=>'Text', 'e.town'=>'Text', 'p.rowid'=>"List:product:label",
203
+			'p.ref'=>"Text", 'p.fk_product_type'=>"Text", 'p.label'=>"Text", 'p.description'=>"Text", 'p.note'=>"Text", 'p.price'=>"Numeric", 'p.tva_tx'=>'Numeric',
204
+			'p.tosell'=>"Boolean", 'p.tobuy'=>"Boolean", 'p.duration'=>"Duree", 'p.datec'=>'Date', 'p.tms'=>'Date', 'p.pmp'=>'Numeric', 'p.cost_price'=>'Numeric',
205 205
 			'ps.reel'=>'Numeric'
206 206
 		);
207
-		$this->export_entities_array[$r]=array(
208
-			'e.rowid'=>'warehouse','e.ref'=>'warehouse','e.description'=>'warehouse','e.lieu'=>'warehouse','e.address'=>'warehouse','e.zip'=>'warehouse',
209
-			'e.town'=>'warehouse','p.rowid'=>"product",'p.ref'=>"product",'p.fk_product_type'=>"product",'p.label'=>"product",'p.description'=>"product",
210
-			'p.note'=>"product",'p.price'=>"product",'p.tva_tx'=>'product','p.tosell'=>"product",'p.tobuy'=>"product",'p.duration'=>"product",
211
-			'p.datec'=>'product','p.tms'=>'product','p.pmp'=>'product','p.cost_price'=>'product','ps.reel'=>'stock'
207
+		$this->export_entities_array[$r] = array(
208
+			'e.rowid'=>'warehouse', 'e.ref'=>'warehouse', 'e.description'=>'warehouse', 'e.lieu'=>'warehouse', 'e.address'=>'warehouse', 'e.zip'=>'warehouse',
209
+			'e.town'=>'warehouse', 'p.rowid'=>"product", 'p.ref'=>"product", 'p.fk_product_type'=>"product", 'p.label'=>"product", 'p.description'=>"product",
210
+			'p.note'=>"product", 'p.price'=>"product", 'p.tva_tx'=>'product', 'p.tosell'=>"product", 'p.tobuy'=>"product", 'p.duration'=>"product",
211
+			'p.datec'=>'product', 'p.tms'=>'product', 'p.pmp'=>'product', 'p.cost_price'=>'product', 'ps.reel'=>'stock'
212 212
 		);
213
-		$this->export_aggregate_array[$r]=array('ps.reel'=>'SUM');    // TODO Not used yet
214
-		$this->export_dependencies_array[$r]=array('stock'=>array('p.rowid','e.rowid')); // We must keep this until the aggregate_array is used. To add unique key if we ask a field of a child to avoid the DISTINCT to discard them.
215
-		$keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra';
213
+		$this->export_aggregate_array[$r] = array('ps.reel'=>'SUM'); // TODO Not used yet
214
+		$this->export_dependencies_array[$r] = array('stock'=>array('p.rowid', 'e.rowid')); // We must keep this until the aggregate_array is used. To add unique key if we ask a field of a child to avoid the DISTINCT to discard them.
215
+		$keyforselect = 'product'; $keyforelement = 'product'; $keyforaliasextra = 'extra';
216 216
 		include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
217
-		$this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('ps.reel'=>'Stock'));
217
+		$this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('ps.reel'=>'Stock'));
218 218
 
219
-		$this->export_sql_start[$r]='SELECT DISTINCT ';
220
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON extra.fk_object = p.rowid, '.MAIN_DB_PREFIX.'product_stock as ps, '.MAIN_DB_PREFIX.'entrepot as e';
221
-		$this->export_sql_end[$r] .=' WHERE p.rowid = ps.fk_product AND ps.fk_entrepot = e.rowid';
222
-		$this->export_sql_end[$r] .=' AND e.entity IN ('.getEntity('stock').')';
219
+		$this->export_sql_start[$r] = 'SELECT DISTINCT ';
220
+		$this->export_sql_end[$r]  = ' FROM '.MAIN_DB_PREFIX.'product as p LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON extra.fk_object = p.rowid, '.MAIN_DB_PREFIX.'product_stock as ps, '.MAIN_DB_PREFIX.'entrepot as e';
221
+		$this->export_sql_end[$r] .= ' WHERE p.rowid = ps.fk_product AND ps.fk_entrepot = e.rowid';
222
+		$this->export_sql_end[$r] .= ' AND e.entity IN ('.getEntity('stock').')';
223 223
 		if ($conf->productbatch->enabled)
224 224
 		{
225 225
 			// Export of stock including lot number
@@ -228,123 +228,123 @@  discard block
 block discarded – undo
228 228
 			// This request is same than previous but without field ps.stock (real stock in warehouse) and with link to subtable productbatch
229 229
 			$r++;
230 230
 
231
-			$this->export_code[$r]=$this->rights_class.'_lot';
232
-			$this->export_label[$r]="WarehousesAndProductsBatchDetail";	// Translation key (used only if key ExportDataset_xxx_z not found)
233
-			$this->export_permission[$r]=array(array("stock","lire"));
234
-			$this->export_fields_array[$r]=array(
235
-				'e.rowid'=>'IdWarehouse','e.ref'=>'LocationSummary','e.description'=>'DescWareHouse','e.lieu'=>'LieuWareHouse','e.address'=>'Address',
236
-				'e.zip'=>'Zip','e.town'=>'Town','p.rowid'=>"ProductId",'p.ref'=>"Ref",'p.fk_product_type'=>"Type",'p.label'=>"Label",'p.description'=>"Description",
237
-				'p.note'=>"Note",'p.price'=>"Price",'p.tva_tx'=>'VAT','p.tosell'=>"OnSell",'p.tobuy'=>'OnBuy','p.duration'=>"Duration",'p.datec'=>'DateCreation',
238
-				'p.tms'=>'DateModification','pb.rowid'=>'Id','pb.batch'=>'Batch','pb.qty'=>'Qty','pl.eatby'=>'EatByDate','pl.sellby'=>'SellByDate'
231
+			$this->export_code[$r] = $this->rights_class.'_lot';
232
+			$this->export_label[$r] = "WarehousesAndProductsBatchDetail"; // Translation key (used only if key ExportDataset_xxx_z not found)
233
+			$this->export_permission[$r] = array(array("stock", "lire"));
234
+			$this->export_fields_array[$r] = array(
235
+				'e.rowid'=>'IdWarehouse', 'e.ref'=>'LocationSummary', 'e.description'=>'DescWareHouse', 'e.lieu'=>'LieuWareHouse', 'e.address'=>'Address',
236
+				'e.zip'=>'Zip', 'e.town'=>'Town', 'p.rowid'=>"ProductId", 'p.ref'=>"Ref", 'p.fk_product_type'=>"Type", 'p.label'=>"Label", 'p.description'=>"Description",
237
+				'p.note'=>"Note", 'p.price'=>"Price", 'p.tva_tx'=>'VAT', 'p.tosell'=>"OnSell", 'p.tobuy'=>'OnBuy', 'p.duration'=>"Duration", 'p.datec'=>'DateCreation',
238
+				'p.tms'=>'DateModification', 'pb.rowid'=>'Id', 'pb.batch'=>'Batch', 'pb.qty'=>'Qty', 'pl.eatby'=>'EatByDate', 'pl.sellby'=>'SellByDate'
239 239
 			);
240
-			$this->export_TypeFields_array[$r]=array(
241
-				'e.rowid'=>'List:entrepot:ref','e.ref'=>'Text','e.lieu'=>'Text','e.description'=>'Text','e.address'=>'Text','e.zip'=>'Text','e.town'=>'Text',
242
-				'p.rowid'=>"List:product:label",'p.ref'=>"Text",'p.fk_product_type'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.note'=>"Text",
243
-				'p.price'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",'p.duration'=>"Duree",'p.datec'=>'Date','p.tms'=>'Date',
244
-				'pb.batch'=>'Text','pb.qty'=>'Numeric','pl.eatby'=>'Date','pl.sellby'=>'Date'
240
+			$this->export_TypeFields_array[$r] = array(
241
+				'e.rowid'=>'List:entrepot:ref', 'e.ref'=>'Text', 'e.lieu'=>'Text', 'e.description'=>'Text', 'e.address'=>'Text', 'e.zip'=>'Text', 'e.town'=>'Text',
242
+				'p.rowid'=>"List:product:label", 'p.ref'=>"Text", 'p.fk_product_type'=>"Text", 'p.label'=>"Text", 'p.description'=>"Text", 'p.note'=>"Text",
243
+				'p.price'=>"Numeric", 'p.tva_tx'=>'Numeric', 'p.tosell'=>"Boolean", 'p.tobuy'=>"Boolean", 'p.duration'=>"Duree", 'p.datec'=>'Date', 'p.tms'=>'Date',
244
+				'pb.batch'=>'Text', 'pb.qty'=>'Numeric', 'pl.eatby'=>'Date', 'pl.sellby'=>'Date'
245 245
 			);
246
-			$this->export_entities_array[$r]=array(
247
-				'e.rowid'=>'warehouse','e.ref'=>'warehouse','e.description'=>'warehouse','e.lieu'=>'warehouse','e.address'=>'warehouse','e.zip'=>'warehouse',
248
-				'e.town'=>'warehouse','p.rowid'=>"product",'p.ref'=>"product",'p.fk_product_type'=>"product",'p.label'=>"product",'p.description'=>"product",
249
-				'p.note'=>"product",'p.price'=>"product",'p.tva_tx'=>'product','p.tosell'=>"product",'p.tobuy'=>"product",'p.duration'=>"product",
250
-				'p.datec'=>'product','p.tms'=>'product','pb.rowid'=>'stockbatch','pb.batch'=>'stockbatch','pb.qty'=>'stockbatch','pl.eatby'=>'batch',
246
+			$this->export_entities_array[$r] = array(
247
+				'e.rowid'=>'warehouse', 'e.ref'=>'warehouse', 'e.description'=>'warehouse', 'e.lieu'=>'warehouse', 'e.address'=>'warehouse', 'e.zip'=>'warehouse',
248
+				'e.town'=>'warehouse', 'p.rowid'=>"product", 'p.ref'=>"product", 'p.fk_product_type'=>"product", 'p.label'=>"product", 'p.description'=>"product",
249
+				'p.note'=>"product", 'p.price'=>"product", 'p.tva_tx'=>'product', 'p.tosell'=>"product", 'p.tobuy'=>"product", 'p.duration'=>"product",
250
+				'p.datec'=>'product', 'p.tms'=>'product', 'pb.rowid'=>'stockbatch', 'pb.batch'=>'stockbatch', 'pb.qty'=>'stockbatch', 'pl.eatby'=>'batch',
251 251
 				'pl.sellby'=>'batch'
252 252
 			);
253
-			$this->export_aggregate_array[$r]=array('ps.reel'=>'SUM');    // TODO Not used yet
254
-			$this->export_dependencies_array[$r]=array('stockbatch'=>array('pb.rowid'),'batch'=>array('pb.rowid')); // We must keep this until the aggregate_array is used. To add unique key if we ask a field of a child to avoid the DISTINCT to discard them.
255
-			$keyforselect='product_lot'; $keyforelement='batch'; $keyforaliasextra='extra';
253
+			$this->export_aggregate_array[$r] = array('ps.reel'=>'SUM'); // TODO Not used yet
254
+			$this->export_dependencies_array[$r] = array('stockbatch'=>array('pb.rowid'), 'batch'=>array('pb.rowid')); // We must keep this until the aggregate_array is used. To add unique key if we ask a field of a child to avoid the DISTINCT to discard them.
255
+			$keyforselect = 'product_lot'; $keyforelement = 'batch'; $keyforaliasextra = 'extra';
256 256
 			include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
257
-			$this->export_sql_start[$r]='SELECT DISTINCT ';
258
-			$this->export_sql_end[$r]  =' FROM ('.MAIN_DB_PREFIX.'product as p, '.MAIN_DB_PREFIX.'product_stock as ps, '.MAIN_DB_PREFIX.'product_batch as pb)';
259
-			$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_lot as pl ON pl.fk_product = p.rowid AND pl.batch = pb.batch';
260
-			$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_lot_extrafields as extra ON extra.fk_object = pl.rowid,';
261
-			$this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'entrepot as e';
262
-			$this->export_sql_end[$r] .=' WHERE p.rowid = ps.fk_product AND ps.fk_entrepot = e.rowid AND ps.rowid = pb.fk_product_stock';
263
-			$this->export_sql_end[$r] .=' AND e.entity IN ('.getEntity('stock').')';
257
+			$this->export_sql_start[$r] = 'SELECT DISTINCT ';
258
+			$this->export_sql_end[$r]  = ' FROM ('.MAIN_DB_PREFIX.'product as p, '.MAIN_DB_PREFIX.'product_stock as ps, '.MAIN_DB_PREFIX.'product_batch as pb)';
259
+			$this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_lot as pl ON pl.fk_product = p.rowid AND pl.batch = pb.batch';
260
+			$this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_lot_extrafields as extra ON extra.fk_object = pl.rowid,';
261
+			$this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'entrepot as e';
262
+			$this->export_sql_end[$r] .= ' WHERE p.rowid = ps.fk_product AND ps.fk_entrepot = e.rowid AND ps.rowid = pb.fk_product_stock';
263
+			$this->export_sql_end[$r] .= ' AND e.entity IN ('.getEntity('stock').')';
264 264
 		}
265 265
 
266 266
 		// Export of stock movement
267 267
 		$r++;
268
-		$this->export_code[$r]=$this->rights_class.'_movement';
269
-		$this->export_label[$r]="StockMovements";	// Translation key (used only if key ExportDataset_xxx_z not found)
270
-		$this->export_permission[$r]=array(array("stock","lire"));
271
-		$this->export_fields_array[$r]=array(
272
-			'e.rowid'=>'IdWarehouse','e.ref'=>'LocationSummary','e.description'=>'DescWareHouse','e.lieu'=>'LieuWareHouse','e.address'=>'Address','e.zip'=>'Zip',
273
-			'e.town'=>'Town','p.rowid'=>"ProductId",'p.ref'=>"Ref",'p.fk_product_type'=>"Type",'p.label'=>"Label",'p.description'=>"Description",'p.note'=>"Note",
274
-			'p.price'=>"Price",'p.tva_tx'=>'VAT','p.tosell'=>"OnSell",'p.tobuy'=>'OnBuy','p.duration'=>"Duration",'p.datec'=>'DateCreation',
275
-			'p.tms'=>'DateModification','sm.rowid'=>'MovementId','sm.value'=>'Qty','sm.datem'=>'DateMovement','sm.label'=>'MovementLabel',
268
+		$this->export_code[$r] = $this->rights_class.'_movement';
269
+		$this->export_label[$r] = "StockMovements"; // Translation key (used only if key ExportDataset_xxx_z not found)
270
+		$this->export_permission[$r] = array(array("stock", "lire"));
271
+		$this->export_fields_array[$r] = array(
272
+			'e.rowid'=>'IdWarehouse', 'e.ref'=>'LocationSummary', 'e.description'=>'DescWareHouse', 'e.lieu'=>'LieuWareHouse', 'e.address'=>'Address', 'e.zip'=>'Zip',
273
+			'e.town'=>'Town', 'p.rowid'=>"ProductId", 'p.ref'=>"Ref", 'p.fk_product_type'=>"Type", 'p.label'=>"Label", 'p.description'=>"Description", 'p.note'=>"Note",
274
+			'p.price'=>"Price", 'p.tva_tx'=>'VAT', 'p.tosell'=>"OnSell", 'p.tobuy'=>'OnBuy', 'p.duration'=>"Duration", 'p.datec'=>'DateCreation',
275
+			'p.tms'=>'DateModification', 'sm.rowid'=>'MovementId', 'sm.value'=>'Qty', 'sm.datem'=>'DateMovement', 'sm.label'=>'MovementLabel',
276 276
 			'sm.inventorycode'=>'InventoryCode'
277 277
 		);
278
-		$this->export_TypeFields_array[$r]=array(
279
-			'e.rowid'=>'List:entrepot:ref','e.ref'=>'Text','e.description'=>'Text','e.lieu'=>'Text','e.address'=>'Text','e.zip'=>'Text','e.town'=>'Text',
280
-			'p.rowid'=>"List:product:label",'p.ref'=>"Text",'p.fk_product_type'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.note'=>"Text",
281
-			'p.price'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",'p.duration'=>"Duree",'p.datec'=>'Date','p.tms'=>'Date',
282
-			'sm.rowid'=>'Numeric','sm.value'=>'Numeric','sm.datem'=>'Date','sm.batch'=>'Text','sm.label'=>'Text','sm.inventorycode'=>'Text'
278
+		$this->export_TypeFields_array[$r] = array(
279
+			'e.rowid'=>'List:entrepot:ref', 'e.ref'=>'Text', 'e.description'=>'Text', 'e.lieu'=>'Text', 'e.address'=>'Text', 'e.zip'=>'Text', 'e.town'=>'Text',
280
+			'p.rowid'=>"List:product:label", 'p.ref'=>"Text", 'p.fk_product_type'=>"Text", 'p.label'=>"Text", 'p.description'=>"Text", 'p.note'=>"Text",
281
+			'p.price'=>"Numeric", 'p.tva_tx'=>'Numeric', 'p.tosell'=>"Boolean", 'p.tobuy'=>"Boolean", 'p.duration'=>"Duree", 'p.datec'=>'Date', 'p.tms'=>'Date',
282
+			'sm.rowid'=>'Numeric', 'sm.value'=>'Numeric', 'sm.datem'=>'Date', 'sm.batch'=>'Text', 'sm.label'=>'Text', 'sm.inventorycode'=>'Text'
283 283
 		);
284
-		$this->export_entities_array[$r]=array(
285
-			'e.rowid'=>'warehouse','e.ref'=>'warehouse','e.description'=>'warehouse','e.lieu'=>'warehouse','e.address'=>'warehouse','e.zip'=>'warehouse',
286
-			'e.town'=>'warehouse','p.rowid'=>"product",'p.ref'=>"product",'p.fk_product_type'=>"product",'p.label'=>"product",'p.description'=>"product",
287
-			'p.note'=>"product",'p.price'=>"product",'p.tva_tx'=>'product','p.tosell'=>"product",'p.tobuy'=>"product",'p.duration'=>"product",'p.datec'=>'product',
288
-			'p.tms'=>'product','sm.rowid'=>'movement','sm.value'=>'movement','sm.datem'=>'movement','sm.label'=>'movement','sm.inventorycode'=>'movement'
284
+		$this->export_entities_array[$r] = array(
285
+			'e.rowid'=>'warehouse', 'e.ref'=>'warehouse', 'e.description'=>'warehouse', 'e.lieu'=>'warehouse', 'e.address'=>'warehouse', 'e.zip'=>'warehouse',
286
+			'e.town'=>'warehouse', 'p.rowid'=>"product", 'p.ref'=>"product", 'p.fk_product_type'=>"product", 'p.label'=>"product", 'p.description'=>"product",
287
+			'p.note'=>"product", 'p.price'=>"product", 'p.tva_tx'=>'product', 'p.tosell'=>"product", 'p.tobuy'=>"product", 'p.duration'=>"product", 'p.datec'=>'product',
288
+			'p.tms'=>'product', 'sm.rowid'=>'movement', 'sm.value'=>'movement', 'sm.datem'=>'movement', 'sm.label'=>'movement', 'sm.inventorycode'=>'movement'
289 289
 		);
290 290
 		if ($conf->productbatch->enabled)
291 291
 		{
292
-			$this->export_fields_array[$r]['sm.batch']='Batch';
293
-			$this->export_TypeFields_array[$r]['sm.batch']='Text';
294
-			$this->export_entities_array[$r]['sm.batch']='movement';
292
+			$this->export_fields_array[$r]['sm.batch'] = 'Batch';
293
+			$this->export_TypeFields_array[$r]['sm.batch'] = 'Text';
294
+			$this->export_entities_array[$r]['sm.batch'] = 'movement';
295 295
 		}
296
-		$this->export_aggregate_array[$r]=array('sm.value'=>'SUM');    // TODO Not used yet
297
-		$this->export_dependencies_array[$r]=array('movement'=>array('sm.rowid')); // We must keep this until the aggregate_array is used. To add unique key if we ask a field of a child to avoid the DISTINCT to discard them.
298
-		$this->export_sql_start[$r]='SELECT DISTINCT ';
299
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p, '.MAIN_DB_PREFIX.'stock_mouvement as sm, '.MAIN_DB_PREFIX.'entrepot as e';
300
-		$this->export_sql_end[$r] .=' WHERE p.rowid = sm.fk_product AND sm.fk_entrepot = e.rowid';
301
-		$this->export_sql_end[$r] .=' AND e.entity IN ('.getEntity('stock').')';
296
+		$this->export_aggregate_array[$r] = array('sm.value'=>'SUM'); // TODO Not used yet
297
+		$this->export_dependencies_array[$r] = array('movement'=>array('sm.rowid')); // We must keep this until the aggregate_array is used. To add unique key if we ask a field of a child to avoid the DISTINCT to discard them.
298
+		$this->export_sql_start[$r] = 'SELECT DISTINCT ';
299
+		$this->export_sql_end[$r]  = ' FROM '.MAIN_DB_PREFIX.'product as p, '.MAIN_DB_PREFIX.'stock_mouvement as sm, '.MAIN_DB_PREFIX.'entrepot as e';
300
+		$this->export_sql_end[$r] .= ' WHERE p.rowid = sm.fk_product AND sm.fk_entrepot = e.rowid';
301
+		$this->export_sql_end[$r] .= ' AND e.entity IN ('.getEntity('stock').')';
302 302
 
303 303
 		// Imports
304 304
 		//--------
305 305
 
306
-		$r=0;
306
+		$r = 0;
307 307
 
308 308
 		// Import warehouses
309 309
 		$r++;
310
-		$this->import_code[$r]=$this->rights_class.'_'.$r;
311
-		$this->import_label[$r]="Warehouses";	// Translation key
312
-		$this->import_icon[$r]=$this->picto;
313
-		$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
314
-		$this->import_tables_array[$r]=array('e'=>MAIN_DB_PREFIX.'entrepot');
315
-		$this->import_tables_creator_array[$r]=array('e'=>'fk_user_author');
316
-		$this->import_fields_array[$r]=array('e.ref'=>"LocationSummary*",
317
-				'e.description'=>"DescWareHouse",'e.lieu'=>"LieuWareHouse",
318
-				'e.address'=>"Address",'e.zip'=>'Zip','e.fk_pays'=>'CountryCode',
310
+		$this->import_code[$r] = $this->rights_class.'_'.$r;
311
+		$this->import_label[$r] = "Warehouses"; // Translation key
312
+		$this->import_icon[$r] = $this->picto;
313
+		$this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
314
+		$this->import_tables_array[$r] = array('e'=>MAIN_DB_PREFIX.'entrepot');
315
+		$this->import_tables_creator_array[$r] = array('e'=>'fk_user_author');
316
+		$this->import_fields_array[$r] = array('e.ref'=>"LocationSummary*",
317
+				'e.description'=>"DescWareHouse", 'e.lieu'=>"LieuWareHouse",
318
+				'e.address'=>"Address", 'e.zip'=>'Zip', 'e.fk_pays'=>'CountryCode',
319 319
 				'e.statut'=>'Status'
320 320
 		);
321 321
 
322
-		$this->import_convertvalue_array[$r]=array(
323
-				'e.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ccountry.class.php','class'=>'Ccountry','method'=>'fetch','dict'=>'DictionaryCountry')
322
+		$this->import_convertvalue_array[$r] = array(
323
+				'e.fk_pays'=>array('rule'=>'fetchidfromcodeid', 'classfile'=>'/core/class/ccountry.class.php', 'class'=>'Ccountry', 'method'=>'fetch', 'dict'=>'DictionaryCountry')
324 324
 		);
325
-		$this->import_regex_array[$r]=array('e.statut'=>'^[0|1]');
326
-		$this->import_examplevalues_array[$r]=array('e.ref'=>"ALM001",
327
-				'e.description'=>"Central Warehouse",'e.lieu'=>"Central",
328
-				'e.address'=>"Route 66",'e.zip'=>'28080','e.fk_pays'=>'US',
325
+		$this->import_regex_array[$r] = array('e.statut'=>'^[0|1]');
326
+		$this->import_examplevalues_array[$r] = array('e.ref'=>"ALM001",
327
+				'e.description'=>"Central Warehouse", 'e.lieu'=>"Central",
328
+				'e.address'=>"Route 66", 'e.zip'=>'28080', 'e.fk_pays'=>'US',
329 329
 				'e.statut'=>'1');
330 330
 
331 331
 		// Import stocks
332 332
 		$r++;
333
-		$this->import_code[$r]=$this->rights_class.'_'.$r;
334
-		$this->import_label[$r]="Stocks";	// Translation key
335
-		$this->import_icon[$r]=$this->picto;
336
-		$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
337
-		$this->import_tables_array[$r]=array('ps'=>MAIN_DB_PREFIX.'product_stock');
338
-		$this->import_fields_array[$r]=array('ps.fk_product'=>"Product*",'ps.fk_entrepot'=>"Warehouse*",'ps.reel'=>"Stock*");
339
-
340
-		$this->import_convertvalue_array[$r]=array(
341
-			'ps.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'product'),
342
-			'ps.fk_entrepot'=>array('rule'=>'fetchidfromref','classfile'=>'/product/stock/class/entrepot.class.php','class'=>'Entrepot','method'=>'fetch','element'=>'ref')
333
+		$this->import_code[$r] = $this->rights_class.'_'.$r;
334
+		$this->import_label[$r] = "Stocks"; // Translation key
335
+		$this->import_icon[$r] = $this->picto;
336
+		$this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
337
+		$this->import_tables_array[$r] = array('ps'=>MAIN_DB_PREFIX.'product_stock');
338
+		$this->import_fields_array[$r] = array('ps.fk_product'=>"Product*", 'ps.fk_entrepot'=>"Warehouse*", 'ps.reel'=>"Stock*");
339
+
340
+		$this->import_convertvalue_array[$r] = array(
341
+			'ps.fk_product'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/class/product.class.php', 'class'=>'Product', 'method'=>'fetch', 'element'=>'product'),
342
+			'ps.fk_entrepot'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/stock/class/entrepot.class.php', 'class'=>'Entrepot', 'method'=>'fetch', 'element'=>'ref')
343 343
 		  );
344
-		$this->import_examplevalues_array[$r]=array(
345
-		    'ps.fk_product'=>"PREF123456",'ps.fk_entrepot'=>"ALM001",'ps.reel'=>"10"
344
+		$this->import_examplevalues_array[$r] = array(
345
+		    'ps.fk_product'=>"PREF123456", 'ps.fk_entrepot'=>"ALM001", 'ps.reel'=>"10"
346 346
 		);
347
-		$this->import_run_sql_after_array[$r]=array(    // Because we may change data that are denormalized, we must update dernormalized data after.
347
+		$this->import_run_sql_after_array[$r] = array(    // Because we may change data that are denormalized, we must update dernormalized data after.
348 348
 		    'UPDATE llx_product p SET p.stock= (SELECT SUM(ps.reel) FROM llx_product_stock ps WHERE ps.fk_product = p.rowid);'
349 349
 		);
350 350
 	}
@@ -358,27 +358,27 @@  discard block
 block discarded – undo
358 358
 	 *      @param      string	$options    Options when enabling module ('', 'noboxes')
359 359
 	 *      @return     int             	1 if OK, 0 if KO
360 360
 	 */
361
-	function init($options='')
361
+	function init($options = '')
362 362
 	{
363
-		global $conf,$langs;
363
+		global $conf, $langs;
364 364
 
365 365
 		// Permissions
366 366
 		$this->remove($options);
367 367
 
368 368
 		//ODT template
369
-		$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/stock/template_stock.odt';
370
-		$dirodt=DOL_DATA_ROOT.'/doctemplates/stock';
371
-		$dest=$dirodt.'/template_stock.odt';
369
+		$src = DOL_DOCUMENT_ROOT.'/install/doctemplates/stock/template_stock.odt';
370
+		$dirodt = DOL_DATA_ROOT.'/doctemplates/stock';
371
+		$dest = $dirodt.'/template_stock.odt';
372 372
 
373
-		if (file_exists($src) && ! file_exists($dest))
373
+		if (file_exists($src) && !file_exists($dest))
374 374
 		{
375 375
 			require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
376 376
 			dol_mkdir($dirodt);
377
-			$result=dol_copy($src,$dest,0,0);
377
+			$result = dol_copy($src, $dest, 0, 0);
378 378
 			if ($result < 0)
379 379
 			{
380 380
 				$langs->load("errors");
381
-				$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
381
+				$this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
382 382
 				return 0;
383 383
 			}
384 384
 		}
@@ -392,6 +392,6 @@  discard block
 block discarded – undo
392 392
 			 "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[2][2])."','mouvement',".$conf->entity.")",
393 393
 		);
394 394
 
395
-		return $this->_init($sql,$options);
395
+		return $this->_init($sql, $options);
396 396
 	}
397 397
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/product_batch/modules_product_batch.class.php 2 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -31,37 +31,37 @@
 block discarded – undo
31 31
  *  \brief      File with parent class for generating contracts to PDF and File of class to manage contract numbering
32 32
  */
33 33
 
34
- require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
34
+    require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
35 35
 
36 36
 /**
37 37
  *	Parent class to manage intervention document templates
38 38
  */
39 39
 abstract class ModelePDFProductBatch extends CommonDocGenerator
40 40
 {
41
-	/**
42
-	 * @var string Error code (or message)
43
-	 */
44
-	public $error='';
41
+    /**
42
+     * @var string Error code (or message)
43
+     */
44
+    public $error='';
45 45
 
46 46
 
47 47
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
48 48
     /**
49
-	 *  Return list of active generation modules
50
-	 *
49
+     *  Return list of active generation modules
50
+     *
51 51
      *  @param  DoliDB	$db     			Database handler
52 52
      *  @param  integer	$maxfilenamelength  Max length of value to show
53 53
      *  @return	array						List of templates
54 54
      */
55 55
     static function liste_modeles($db, $maxfilenamelength=0)
56
-	{
56
+    {
57 57
         // phpcs:enable
58
-		global $conf;
58
+        global $conf;
59 59
 
60
-		$type='product_batch';
61
-		$list = array();
60
+        $type='product_batch';
61
+        $list = array();
62 62
 
63
-		include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
64
-		$list = getListOfModels($db, $type, $maxfilenamelength);
65
-		return $list;
66
-	}
63
+        include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
64
+        $list = getListOfModels($db, $type, $maxfilenamelength);
65
+        return $list;
66
+    }
67 67
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	/**
42 42
 	 * @var string Error code (or message)
43 43
 	 */
44
-	public $error='';
44
+	public $error = '';
45 45
 
46 46
 
47 47
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
      *  @param  integer	$maxfilenamelength  Max length of value to show
53 53
      *  @return	array						List of templates
54 54
      */
55
-    static function liste_modeles($db, $maxfilenamelength=0)
55
+    static function liste_modeles($db, $maxfilenamelength = 0)
56 56
 	{
57 57
         // phpcs:enable
58 58
 		global $conf;
59 59
 
60
-		$type='product_batch';
60
+		$type = 'product_batch';
61 61
 		$list = array();
62 62
 
63 63
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
Please login to merge, or discard this patch.
htdocs/core/modules/product/doc/doc_generic_product_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_product_odt extends ModelePDFProduct
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 = 'PRODUCT_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 PRODUCT_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 = 'PRODUCT_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 PRODUCT_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="PRODUCT_ADDON_PDF_ODT_PATH">';
123
-		if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0)
124
-		{
125
-			$texte.= '<input type="hidden" name="param2" value="PRODUCT_ADDON_PDF_ODT_DEFAULT">';
126
-			$texte.= '<input type="hidden" name="param3" value="PRODUCT_ADDON_PDF_ODT_TOBILL">';
127
-			$texte.= '<input type="hidden" name="param4" value="PRODUCT_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->PRODUCT_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->PRODUCT_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_PRODUCT_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="PRODUCT_ADDON_PDF_ODT_PATH">';
123
+        if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0)
124
+        {
125
+            $texte.= '<input type="hidden" name="param2" value="PRODUCT_ADDON_PDF_ODT_DEFAULT">';
126
+            $texte.= '<input type="hidden" name="param3" value="PRODUCT_ADDON_PDF_ODT_TOBILL">';
127
+            $texte.= '<input type="hidden" name="param4" value="PRODUCT_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->PRODUCT_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->PRODUCT_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_PRODUCT_CHOOSE_ODT_DOCUMENT > 0)
170 170
 			{
171 171
 				// Model for creation
172 172
 				$liste=ModelePDFProduct::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		Product		$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		Product		$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 $product,$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 Product($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
-			$productFournisseur = new ProductFournisseur($this->db);
262
-			$supplierprices = $productFournisseur->list_product_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 product, 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='product_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 object 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 $product,$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 Product($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
+            $productFournisseur = new ProductFournisseur($this->db);
262
+            $supplierprices = $productFournisseur->list_product_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 product, 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='product_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 object 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   +130 added lines, -130 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 = 'PRODUCT_ADDON_PDF_ODT_PATH';	// Name of constant that is used to save list of directories to scan
74
+		$this->scandir = 'PRODUCT_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 PRODUCT_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 PRODUCT_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="PRODUCT_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="PRODUCT_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="PRODUCT_ADDON_PDF_ODT_DEFAULT">';
126
-			$texte.= '<input type="hidden" name="param3" value="PRODUCT_ADDON_PDF_ODT_TOBILL">';
127
-			$texte.= '<input type="hidden" name="param4" value="PRODUCT_ADDON_PDF_ODT_CLOSED">';
125
+			$texte .= '<input type="hidden" name="param2" value="PRODUCT_ADDON_PDF_ODT_DEFAULT">';
126
+			$texte .= '<input type="hidden" name="param3" value="PRODUCT_ADDON_PDF_ODT_TOBILL">';
127
+			$texte .= '<input type="hidden" name="param4" value="PRODUCT_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->PRODUCT_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->PRODUCT_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->PRODUCT_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->PRODUCT_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_PRODUCT_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 $product,$langs,$conf,$mysoc,$hookmanager,$user;
223
+		global $product, $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 Product($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 product, 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='product_FREE_TEXT';
351
-				if (! empty($conf->global->$paramfreetext))
349
+				$newfreetext = '';
350
+				$paramfreetext = 'product_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,7 +360,7 @@  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
 						)
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 				}
369 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 object 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,15 +430,15 @@  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
 								{
@@ -460,34 +460,34 @@  discard block
 block discarded – undo
460 460
 				}
461 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 object 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/product/doc/pdf_standard.modules.php 3 patches
Indentation   +466 added lines, -466 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,147 +83,147 @@  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_codeproduitservice = 0;      // Affiche code produit-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
-	}
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_codeproduitservice = 0;      // Affiche code produit-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 149
 
150 150
 
151 151
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
152
-	/**
153
-	 *	Function to build a document on disk using the generic odt module.
154
-	 *
155
-	 *	@param		Product		$object				Object source to build document
156
-	 *	@param		Translate	$outputlangs		Lang output object
157
-	 * 	@param		string		$srctemplatepath	Full path of source filename for generator using a template file
158
-	 *  @param		int			$hidedetails		Do not show line details
159
-	 *  @param		int			$hidedesc			Do not show desc
160
-	 *  @param		int			$hideref			Do not show ref
161
-	 *	@return		int         					1 if OK, <=0 if KO
162
-	 */
163
-	function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
164
-	{
152
+    /**
153
+     *	Function to build a document on disk using the generic odt module.
154
+     *
155
+     *	@param		Product		$object				Object source to build document
156
+     *	@param		Translate	$outputlangs		Lang output object
157
+     * 	@param		string		$srctemplatepath	Full path of source filename for generator using a template file
158
+     *  @param		int			$hidedetails		Do not show line details
159
+     *  @param		int			$hidedesc			Do not show desc
160
+     *  @param		int			$hideref			Do not show ref
161
+     *	@return		int         					1 if OK, <=0 if KO
162
+     */
163
+    function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
164
+    {
165 165
         // phpcs:enable
166
-		global $user,$langs,$conf,$mysoc,$db,$hookmanager;
167
-
168
-		if (! is_object($outputlangs)) $outputlangs=$langs;
169
-		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
170
-		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
171
-
172
-		// Load traductions files requiredby by page
173
-		$outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "deliveries"));
174
-
175
-		$nblignes = count($object->lines);
176
-
177
-		if ($conf->produit->dir_output)
178
-		{
179
-		    // Definition of $dir and $file
180
-			if ($object->specimen)
181
-			{
182
-				$dir = $conf->produit->dir_output;
183
-				$file = $dir . "/SPECIMEN.pdf";
184
-			}
185
-			else
186
-			{
187
-				$objectref = dol_sanitizeFileName($object->ref);
188
-				$dir = $conf->produit->dir_output . "/" . $objectref;
189
-				$file = $dir . "/" . $objectref . ".pdf";
190
-			}
191
-
192
-			$productFournisseur = new ProductFournisseur($this->db);
193
-			$supplierprices = $productFournisseur->list_product_fournisseur_price($object->id);
194
-			$object->supplierprices = $supplierprices;
195
-
196
-			if (! file_exists($dir))
197
-			{
198
-				if (dol_mkdir($dir) < 0)
199
-				{
200
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
201
-					return -1;
202
-				}
203
-			}
166
+        global $user,$langs,$conf,$mysoc,$db,$hookmanager;
167
+
168
+        if (! is_object($outputlangs)) $outputlangs=$langs;
169
+        // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
170
+        if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
171
+
172
+        // Load traductions files requiredby by page
173
+        $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "deliveries"));
174
+
175
+        $nblignes = count($object->lines);
176
+
177
+        if ($conf->produit->dir_output)
178
+        {
179
+            // Definition of $dir and $file
180
+            if ($object->specimen)
181
+            {
182
+                $dir = $conf->produit->dir_output;
183
+                $file = $dir . "/SPECIMEN.pdf";
184
+            }
185
+            else
186
+            {
187
+                $objectref = dol_sanitizeFileName($object->ref);
188
+                $dir = $conf->produit->dir_output . "/" . $objectref;
189
+                $file = $dir . "/" . $objectref . ".pdf";
190
+            }
191
+
192
+            $productFournisseur = new ProductFournisseur($this->db);
193
+            $supplierprices = $productFournisseur->list_product_fournisseur_price($object->id);
194
+            $object->supplierprices = $supplierprices;
195
+
196
+            if (! file_exists($dir))
197
+            {
198
+                if (dol_mkdir($dir) < 0)
199
+                {
200
+                    $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
201
+                    return -1;
202
+                }
203
+            }
204 204
 
205
-			if (file_exists($dir))
206
-			{
207
-							// Add pdfgeneration hook
208
-				if (! is_object($hookmanager))
209
-				{
210
-					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
211
-					$hookmanager=new HookManager($this->db);
212
-				}
213
-				$hookmanager->initHooks(array('pdfgeneration'));
214
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
215
-				global $action;
216
-				$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
205
+            if (file_exists($dir))
206
+            {
207
+                            // Add pdfgeneration hook
208
+                if (! is_object($hookmanager))
209
+                {
210
+                    include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
211
+                    $hookmanager=new HookManager($this->db);
212
+                }
213
+                $hookmanager->initHooks(array('pdfgeneration'));
214
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
215
+                global $action;
216
+                $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
217 217
 
218
-				// Create pdf instance
219
-				$pdf=pdf_getInstance($this->format);
220
-				$default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
221
-				$pdf->SetAutoPageBreak(1,0);
218
+                // Create pdf instance
219
+                $pdf=pdf_getInstance($this->format);
220
+                $default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
221
+                $pdf->SetAutoPageBreak(1,0);
222 222
 
223
-				$heightforinfotot = 40;	// Height reserved to output the info and total part
224
-		        $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
225
-	            $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
226
-	            if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
223
+                $heightforinfotot = 40;	// Height reserved to output the info and total part
224
+                $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
225
+                $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
226
+                if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
227 227
 
228 228
                 if (class_exists('TCPDF'))
229 229
                 {
@@ -238,113 +238,113 @@  discard block
 block discarded – undo
238 238
                     $tplidx = $pdf->importPage(1);
239 239
                 }
240 240
 
241
-				$pdf->Open();
242
-				$pagenb=0;
243
-				$pdf->SetDrawColor(128,128,128);
241
+                $pdf->Open();
242
+                $pagenb=0;
243
+                $pdf->SetDrawColor(128,128,128);
244 244
 
245
-				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
246
-				$pdf->SetSubject($outputlangs->transnoentities("Order"));
247
-				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
248
-				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
249
-				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
250
-				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
245
+                $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
246
+                $pdf->SetSubject($outputlangs->transnoentities("Order"));
247
+                $pdf->SetCreator("Dolibarr ".DOL_VERSION);
248
+                $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
249
+                $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
250
+                if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
251 251
 
252
-				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
252
+                $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
253 253
 
254 254
 
255
-				// New page
256
-				$pdf->AddPage();
257
-				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
258
-				$pagenb++;
259
-				$this->_pagehead($pdf, $object, 1, $outputlangs);
260
-				$pdf->SetFont('','', $default_font_size - 1);
261
-				$pdf->MultiCell(0, 3, '');		// Set interline to 3
262
-				$pdf->SetTextColor(0,0,0);
255
+                // New page
256
+                $pdf->AddPage();
257
+                if (! empty($tplidx)) $pdf->useTemplate($tplidx);
258
+                $pagenb++;
259
+                $this->_pagehead($pdf, $object, 1, $outputlangs);
260
+                $pdf->SetFont('','', $default_font_size - 1);
261
+                $pdf->MultiCell(0, 3, '');		// Set interline to 3
262
+                $pdf->SetTextColor(0,0,0);
263 263
 
264 264
 
265
-				$tab_top = 42;
266
-				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
267
-				$tab_height = 130;
268
-				$tab_height_newpage = 150;
265
+                $tab_top = 42;
266
+                $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
267
+                $tab_height = 130;
268
+                $tab_height_newpage = 150;
269 269
 
270
-				//
271
-				$pdf->SetFont('','B', $default_font_size);
272
-				$pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top, dol_htmlentitiesbr($object->label), 0, 1);
273
-				$nexY = $pdf->GetY();
270
+                //
271
+                $pdf->SetFont('','B', $default_font_size);
272
+                $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top, dol_htmlentitiesbr($object->label), 0, 1);
273
+                $nexY = $pdf->GetY();
274 274
 
275
-				$pdf->SetFont('','', $default_font_size);
276
-				$pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, dol_htmlentitiesbr($object->description), 0, 1);
277
-				$nexY = $pdf->GetY();
275
+                $pdf->SetFont('','', $default_font_size);
276
+                $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, dol_htmlentitiesbr($object->description), 0, 1);
277
+                $nexY = $pdf->GetY();
278 278
 
279
-				$nexY+=5;
279
+                $nexY+=5;
280 280
 
281
-				if ($object->weight)
282
-				{
283
-				    $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Weight").': '.dol_htmlentitiesbr($object->weight), 0, 1);
284
-				    $nexY = $pdf->GetY();
285
-				}
286
-				if ($object->weight)
287
-				{
288
-				    $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").': '.($object->length != ''?$object->length:'?').' x '.($object->width != ''?$object->width:'?').' x '.($object->height != ''?$object->height:'?'), 0, 1);
289
-				    $nexY = $pdf->GetY();
290
-				}
291
-				if ($object->surface)
292
-				{
293
-				    $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Area").': '.dol_htmlentitiesbr($object->surface), 0, 1);
294
-				    $nexY = $pdf->GetY();
295
-				}
296
-				if ($object->volume)
297
-				{
298
-    				$pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Volume").': '.dol_htmlentitiesbr($object->volume), 0, 1);
299
-	   			    $nexY = $pdf->GetY();
300
-				}
281
+                if ($object->weight)
282
+                {
283
+                    $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Weight").': '.dol_htmlentitiesbr($object->weight), 0, 1);
284
+                    $nexY = $pdf->GetY();
285
+                }
286
+                if ($object->weight)
287
+                {
288
+                    $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").': '.($object->length != ''?$object->length:'?').' x '.($object->width != ''?$object->width:'?').' x '.($object->height != ''?$object->height:'?'), 0, 1);
289
+                    $nexY = $pdf->GetY();
290
+                }
291
+                if ($object->surface)
292
+                {
293
+                    $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Area").': '.dol_htmlentitiesbr($object->surface), 0, 1);
294
+                    $nexY = $pdf->GetY();
295
+                }
296
+                if ($object->volume)
297
+                {
298
+                    $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Volume").': '.dol_htmlentitiesbr($object->volume), 0, 1);
299
+                        $nexY = $pdf->GetY();
300
+                }
301 301
 
302 302
 
303
-				// Affiche notes
304
-				// TODO There is no public note on product yet
305
-				$notetoshow=empty($object->note_public)?'':$object->note_public;
306
-				if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
307
-				{
308
-					// Get first sale rep
309
-					if (is_object($object->thirdparty))
310
-					{
311
-						$salereparray=$object->thirdparty->getSalesRepresentatives($user);
312
-						$salerepobj=new User($this->db);
313
-						$salerepobj->fetch($salereparray[0]['id']);
314
-						if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
315
-					}
316
-				}
317
-				if ($notetoshow)
318
-				{
319
-					$substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
320
-					complete_substitutions_array($substitutionarray, $outputlangs, $object);
321
-					$notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
303
+                // Affiche notes
304
+                // TODO There is no public note on product yet
305
+                $notetoshow=empty($object->note_public)?'':$object->note_public;
306
+                if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
307
+                {
308
+                    // Get first sale rep
309
+                    if (is_object($object->thirdparty))
310
+                    {
311
+                        $salereparray=$object->thirdparty->getSalesRepresentatives($user);
312
+                        $salerepobj=new User($this->db);
313
+                        $salerepobj->fetch($salereparray[0]['id']);
314
+                        if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
315
+                    }
316
+                }
317
+                if ($notetoshow)
318
+                {
319
+                    $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
320
+                    complete_substitutions_array($substitutionarray, $outputlangs, $object);
321
+                    $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
322 322
 
323
-					$tab_top = 88;
323
+                    $tab_top = 88;
324 324
 
325
-					$pdf->SetFont('','', $default_font_size - 1);
326
-					$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
327
-					$nexY = $pdf->GetY();
328
-					$height_note=$nexY-$tab_top;
325
+                    $pdf->SetFont('','', $default_font_size - 1);
326
+                    $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
327
+                    $nexY = $pdf->GetY();
328
+                    $height_note=$nexY-$tab_top;
329 329
 
330
-					// Rect prend une longueur en 3eme param
331
-					$pdf->SetDrawColor(192,192,192);
332
-					$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
330
+                    // Rect prend une longueur en 3eme param
331
+                    $pdf->SetDrawColor(192,192,192);
332
+                    $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
333 333
 
334
-					$tab_height = $tab_height - $height_note;
335
-					$tab_top = $nexY+6;
336
-				}
337
-				else
338
-				{
339
-					$height_note=0;
340
-				}
334
+                    $tab_height = $tab_height - $height_note;
335
+                    $tab_top = $nexY+6;
336
+                }
337
+                else
338
+                {
339
+                    $height_note=0;
340
+                }
341 341
 
342
-				$iniY = $tab_top + 7;
343
-				$curY = $tab_top + 7;
344
-				$nexY = $tab_top + 7;
342
+                $iniY = $tab_top + 7;
343
+                $curY = $tab_top + 7;
344
+                $nexY = $tab_top + 7;
345 345
 
346
-				// Loop on each lines
347
-				/*
346
+                // Loop on each lines
347
+                /*
348 348
 				for ($i = 0 ; $i < $nblignes ; $i++)
349 349
 				{
350 350
 					$curY = $nexY;
@@ -552,235 +552,235 @@  discard block
 block discarded – undo
552 552
 				}
553 553
                 */
554 554
 
555
-				// Affiche zone infos
556
-				//$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
557
-
558
-				// Pied de page
559
-				$this->_pagefoot($pdf,$object,$outputlangs);
560
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
561
-
562
-				$pdf->Close();
563
-
564
-				$pdf->Output($file,'F');
565
-
566
-				// Add pdfgeneration hook
567
-				$hookmanager->initHooks(array('pdfgeneration'));
568
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
569
-				global $action;
570
-				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
571
-
572
-				if (! empty($conf->global->MAIN_UMASK))
573
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
574
-
575
-				$this->result = array('fullpath'=>$file);
576
-
577
-				return 1;   // Pas d'erreur
578
-			}
579
-			else
580
-			{
581
-				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
582
-				return 0;
583
-			}
584
-		}
585
-		else
586
-		{
587
-			$this->error=$langs->trans("ErrorConstantNotDefined","PRODUCT_OUTPUTDIR");
588
-			return 0;
589
-		}
590
-	}
591
-
592
-
593
-	/**
594
-	 *   Show table for lines
595
-	 *
596
-	 *   @param		TCPDF		$pdf     		Object PDF
597
-	 *   @param		string		$tab_top		Top position of table
598
-	 *   @param		string		$tab_height		Height of table (rectangle)
599
-	 *   @param		int			$nexY			Y (not used)
600
-	 *   @param		Translate	$outputlangs	Langs object
601
-	 *   @param		int			$hidetop		1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
602
-	 *   @param		int			$hidebottom		Hide bottom bar of array
603
-	 *   @param		string		$currency		Currency code
604
-	 *   @return	void
605
-	 */
606
-	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
607
-	{
608
-	    global $conf;
609
-
610
-	    // Force to disable hidetop and hidebottom
611
-	    $hidebottom=0;
612
-	    if ($hidetop) $hidetop=-1;
613
-
614
-	    $currency = !empty($currency) ? $currency : $conf->currency;
615
-	    $default_font_size = pdf_getPDFFontSize($outputlangs);
616
-
617
-	    // Amount in (at tab_top - 1)
618
-	    $pdf->SetTextColor(0,0,0);
619
-	    $pdf->SetFont('','', $default_font_size - 2);
620
-
621
-	    if (empty($hidetop))
622
-	    {
623
-	        $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
624
-	        $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
625
-	        $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
626
-
627
-	        //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
628
-	        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));
629
-	    }
555
+                // Affiche zone infos
556
+                //$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
630 557
 
631
-	    $pdf->SetDrawColor(128,128,128);
632
-	    $pdf->SetFont('','', $default_font_size - 1);
558
+                // Pied de page
559
+                $this->_pagefoot($pdf,$object,$outputlangs);
560
+                if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
633 561
 
634
-	    // Output Rect
635
-	    $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
562
+                $pdf->Close();
636 563
 
637
-	    if (empty($hidetop))
638
-	    {
639
-	        $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
564
+                $pdf->Output($file,'F');
640 565
 
641
-	        $pdf->SetXY($this->posxdesc-1, $tab_top+1);
642
-	        $pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
643
-	    }
644
-
645
-	    if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
646
-	    {
647
-	        $pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
648
-	        if (empty($hidetop))
649
-	        {
650
-	            $pdf->SetXY($this->posxtva-3, $tab_top+1);
651
-	            $pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
652
-	        }
653
-	    }
654
-
655
-	    $pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
656
-	    if (empty($hidetop))
657
-	    {
658
-	        $pdf->SetXY($this->posxup-1, $tab_top+1);
659
-	        $pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
660
-	    }
566
+                // Add pdfgeneration hook
567
+                $hookmanager->initHooks(array('pdfgeneration'));
568
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
569
+                global $action;
570
+                $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
661 571
 
662
-	    $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
663
-	    if (empty($hidetop))
664
-	    {
665
-	        $pdf->SetXY($this->posxqty-1, $tab_top+1);
666
-	        if($conf->global->PRODUCT_USE_UNITS)
667
-	        {
668
-	            $pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
669
-	        }
670
-	        else
671
-	        {
672
-	            $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
673
-	        }
674
-	    }
675
-
676
-	    if($conf->global->PRODUCT_USE_UNITS) {
677
-	        $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
678
-	        if (empty($hidetop)) {
679
-	            $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
680
-	            $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '',
681
-	                'C');
682
-	        }
683
-	    }
572
+                if (! empty($conf->global->MAIN_UMASK))
573
+                    @chmod($file, octdec($conf->global->MAIN_UMASK));
684 574
 
685
-	    $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
686
-	    if (empty($hidetop))
687
-	    {
688
-	        if ($this->atleastonediscount)
689
-	        {
690
-	            $pdf->SetXY($this->posxdiscount-1, $tab_top+1);
691
-	            $pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
692
-	        }
693
-	    }
575
+                $this->result = array('fullpath'=>$file);
694 576
 
695
-	    if ($this->atleastonediscount)
696
-	    {
697
-	        $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
698
-	    }
699
-	    if (empty($hidetop))
700
-	    {
701
-	        $pdf->SetXY($this->postotalht-1, $tab_top+1);
702
-	        $pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHT"),'','C');
703
-	    }
704
-	}
705
-
706
-	/**
707
-	 *  Show top header of page.
708
-	 *
709
-	 *  @param	TCPDF		$pdf     		Object PDF
710
-	 *  @param  Object		$object     	Object to show
711
-	 *  @param  int	    	$showaddress    0=no, 1=yes
712
-	 *  @param  Translate	$outputlangs	Object lang for output
713
-	 *  @param	string		$titlekey		Translation key to show as title of document
714
-	 *  @return	void
715
-	 */
716
-	function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="")
717
-	{
718
-	    global $conf,$langs,$hookmanager;
719
-
720
-	    // Load traductions files requiredby by page
721
-		$outputlangs->loadLangs(array("main", "propal", "companies", "bills", "orders"));
722
-
723
-	    $default_font_size = pdf_getPDFFontSize($outputlangs);
724
-
725
-	    if ($object->type == 1) $titlekey='ServiceSheet';
726
-	    else $titlekey='ProductSheet';
727
-
728
-	    pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
729
-
730
-	    // Show Draft Watermark
731
-	    if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
732
-	    {
733
-	        pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
734
-	    }
577
+                return 1;   // Pas d'erreur
578
+            }
579
+            else
580
+            {
581
+                $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
582
+                return 0;
583
+            }
584
+        }
585
+        else
586
+        {
587
+            $this->error=$langs->trans("ErrorConstantNotDefined","PRODUCT_OUTPUTDIR");
588
+            return 0;
589
+        }
590
+    }
735 591
 
736
-	    $pdf->SetTextColor(0,0,60);
737
-	    $pdf->SetFont('','B', $default_font_size + 3);
738 592
 
739
-	    $posy=$this->marge_haute;
740
-	    $posx=$this->page_largeur-$this->marge_droite-100;
741
-
742
-	    $pdf->SetXY($this->marge_gauche,$posy);
743
-
744
-	    // Logo
745
-	    $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
746
-	    if ($this->emetteur->logo)
747
-	    {
748
-	        if (is_readable($logo))
749
-	        {
750
-	            $height=pdf_getHeightForLogo($logo);
751
-	            $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
752
-	        }
753
-	        else
754
-	        {
755
-	            $pdf->SetTextColor(200,0,0);
756
-	            $pdf->SetFont('','B', $default_font_size -2);
757
-	            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
758
-	            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
759
-	        }
760
-	    }
761
-	    else
762
-	    {
763
-	        $text=$this->emetteur->name;
764
-	        $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
765
-	    }
766
-
767
-	    $pdf->SetFont('','B', $default_font_size + 3);
768
-	    $pdf->SetXY($posx,$posy);
769
-	    $pdf->SetTextColor(0,0,60);
770
-	    $title=$outputlangs->transnoentities($titlekey);
771
-	    $pdf->MultiCell(100, 3, $title, '', 'R');
772
-
773
-	    $pdf->SetFont('','B',$default_font_size);
774
-
775
-	    $posy+=5;
776
-	    $pdf->SetXY($posx,$posy);
777
-	    $pdf->SetTextColor(0,0,60);
778
-	    $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
779
-
780
-	    $posy+=1;
781
-	    $pdf->SetFont('','', $default_font_size - 1);
593
+    /**
594
+     *   Show table for lines
595
+     *
596
+     *   @param		TCPDF		$pdf     		Object PDF
597
+     *   @param		string		$tab_top		Top position of table
598
+     *   @param		string		$tab_height		Height of table (rectangle)
599
+     *   @param		int			$nexY			Y (not used)
600
+     *   @param		Translate	$outputlangs	Langs object
601
+     *   @param		int			$hidetop		1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
602
+     *   @param		int			$hidebottom		Hide bottom bar of array
603
+     *   @param		string		$currency		Currency code
604
+     *   @return	void
605
+     */
606
+    function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
607
+    {
608
+        global $conf;
609
+
610
+        // Force to disable hidetop and hidebottom
611
+        $hidebottom=0;
612
+        if ($hidetop) $hidetop=-1;
613
+
614
+        $currency = !empty($currency) ? $currency : $conf->currency;
615
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
616
+
617
+        // Amount in (at tab_top - 1)
618
+        $pdf->SetTextColor(0,0,0);
619
+        $pdf->SetFont('','', $default_font_size - 2);
620
+
621
+        if (empty($hidetop))
622
+        {
623
+            $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
624
+            $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
625
+            $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
626
+
627
+            //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
628
+            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));
629
+        }
630
+
631
+        $pdf->SetDrawColor(128,128,128);
632
+        $pdf->SetFont('','', $default_font_size - 1);
633
+
634
+        // Output Rect
635
+        $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
636
+
637
+        if (empty($hidetop))
638
+        {
639
+            $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
640
+
641
+            $pdf->SetXY($this->posxdesc-1, $tab_top+1);
642
+            $pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
643
+        }
644
+
645
+        if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
646
+        {
647
+            $pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
648
+            if (empty($hidetop))
649
+            {
650
+                $pdf->SetXY($this->posxtva-3, $tab_top+1);
651
+                $pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
652
+            }
653
+        }
654
+
655
+        $pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
656
+        if (empty($hidetop))
657
+        {
658
+            $pdf->SetXY($this->posxup-1, $tab_top+1);
659
+            $pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
660
+        }
661
+
662
+        $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
663
+        if (empty($hidetop))
664
+        {
665
+            $pdf->SetXY($this->posxqty-1, $tab_top+1);
666
+            if($conf->global->PRODUCT_USE_UNITS)
667
+            {
668
+                $pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
669
+            }
670
+            else
671
+            {
672
+                $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
673
+            }
674
+        }
675
+
676
+        if($conf->global->PRODUCT_USE_UNITS) {
677
+            $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
678
+            if (empty($hidetop)) {
679
+                $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
680
+                $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '',
681
+                    'C');
682
+            }
683
+        }
684
+
685
+        $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
686
+        if (empty($hidetop))
687
+        {
688
+            if ($this->atleastonediscount)
689
+            {
690
+                $pdf->SetXY($this->posxdiscount-1, $tab_top+1);
691
+                $pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
692
+            }
693
+        }
694
+
695
+        if ($this->atleastonediscount)
696
+        {
697
+            $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
698
+        }
699
+        if (empty($hidetop))
700
+        {
701
+            $pdf->SetXY($this->postotalht-1, $tab_top+1);
702
+            $pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHT"),'','C');
703
+        }
704
+    }
782 705
 
783
-	    /*if ($object->ref_client)
706
+    /**
707
+     *  Show top header of page.
708
+     *
709
+     *  @param	TCPDF		$pdf     		Object PDF
710
+     *  @param  Object		$object     	Object to show
711
+     *  @param  int	    	$showaddress    0=no, 1=yes
712
+     *  @param  Translate	$outputlangs	Object lang for output
713
+     *  @param	string		$titlekey		Translation key to show as title of document
714
+     *  @return	void
715
+     */
716
+    function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="")
717
+    {
718
+        global $conf,$langs,$hookmanager;
719
+
720
+        // Load traductions files requiredby by page
721
+        $outputlangs->loadLangs(array("main", "propal", "companies", "bills", "orders"));
722
+
723
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
724
+
725
+        if ($object->type == 1) $titlekey='ServiceSheet';
726
+        else $titlekey='ProductSheet';
727
+
728
+        pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
729
+
730
+        // Show Draft Watermark
731
+        if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
732
+        {
733
+            pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
734
+        }
735
+
736
+        $pdf->SetTextColor(0,0,60);
737
+        $pdf->SetFont('','B', $default_font_size + 3);
738
+
739
+        $posy=$this->marge_haute;
740
+        $posx=$this->page_largeur-$this->marge_droite-100;
741
+
742
+        $pdf->SetXY($this->marge_gauche,$posy);
743
+
744
+        // Logo
745
+        $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
746
+        if ($this->emetteur->logo)
747
+        {
748
+            if (is_readable($logo))
749
+            {
750
+                $height=pdf_getHeightForLogo($logo);
751
+                $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
752
+            }
753
+            else
754
+            {
755
+                $pdf->SetTextColor(200,0,0);
756
+                $pdf->SetFont('','B', $default_font_size -2);
757
+                $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
758
+                $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
759
+            }
760
+        }
761
+        else
762
+        {
763
+            $text=$this->emetteur->name;
764
+            $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
765
+        }
766
+
767
+        $pdf->SetFont('','B', $default_font_size + 3);
768
+        $pdf->SetXY($posx,$posy);
769
+        $pdf->SetTextColor(0,0,60);
770
+        $title=$outputlangs->transnoentities($titlekey);
771
+        $pdf->MultiCell(100, 3, $title, '', 'R');
772
+
773
+        $pdf->SetFont('','B',$default_font_size);
774
+
775
+        $posy+=5;
776
+        $pdf->SetXY($posx,$posy);
777
+        $pdf->SetTextColor(0,0,60);
778
+        $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
779
+
780
+        $posy+=1;
781
+        $pdf->SetFont('','', $default_font_size - 1);
782
+
783
+        /*if ($object->ref_client)
784 784
 	    {
785 785
 	        $posy+=5;
786 786
 	        $pdf->SetXY($posx,$posy);
@@ -788,14 +788,14 @@  discard block
 block discarded – undo
788 788
 	        $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
789 789
 	    }*/
790 790
 
791
-	    /*$posy+=4;
791
+        /*$posy+=4;
792 792
 	    $pdf->SetXY($posx,$posy);
793 793
 	    $pdf->SetTextColor(0,0,60);
794 794
 	    $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderDate")." : " . dol_print_date($object->date,"%d %b %Y",false,$outputlangs,true), '', 'R');
795 795
 	    */
796 796
 
797
-	    // Get contact
798
-	    /*
797
+        // Get contact
798
+        /*
799 799
 	    if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
800 800
 	    {
801 801
 	        $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
@@ -810,14 +810,14 @@  discard block
 block discarded – undo
810 810
 	        }
811 811
 	    }*/
812 812
 
813
-	    $posy+=2;
813
+        $posy+=2;
814 814
 
815
-	    // Show list of linked objects
816
-	    $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
815
+        // Show list of linked objects
816
+        $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
817 817
 
818
-	    if ($showaddress)
819
-	    {
820
-	        /*
818
+        if ($showaddress)
819
+        {
820
+            /*
821 821
 	        // Sender properties
822 822
 	        $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
823 823
 
@@ -848,24 +848,24 @@  discard block
 block discarded – undo
848 848
 	        $pdf->SetFont('','', $default_font_size - 1);
849 849
 	        $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
850 850
 	        */
851
-	    }
852
-
853
-	    $pdf->SetTextColor(0,0,0);
854
-	}
855
-
856
-	/**
857
-	 *   	Show footer of page. Need this->emetteur object
858
-	 *
859
-	 *   	@param	TCPDF		$pdf     			PDF
860
-	 * 		@param	Object		$object				Object to show
861
-	 *      @param	Translate	$outputlangs		Object lang for output
862
-	 *      @param	int			$hidefreetext		1=Hide free text
863
-	 *      @return	int								Return height of bottom margin including footer text
864
-	 */
865
-	function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
866
-	{
867
-	    global $conf;
868
-	    $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
869
-	    return pdf_pagefoot($pdf,$outputlangs,'PRODUCT_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
870
-	}
851
+        }
852
+
853
+        $pdf->SetTextColor(0,0,0);
854
+    }
855
+
856
+    /**
857
+     *   	Show footer of page. Need this->emetteur object
858
+     *
859
+     *   	@param	TCPDF		$pdf     			PDF
860
+     * 		@param	Object		$object				Object to show
861
+     *      @param	Translate	$outputlangs		Object lang for output
862
+     *      @param	int			$hidefreetext		1=Hide free text
863
+     *      @return	int								Return height of bottom margin including footer text
864
+     */
865
+    function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
866
+    {
867
+        global $conf;
868
+        $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
869
+        return pdf_pagefoot($pdf,$outputlangs,'PRODUCT_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
870
+    }
871 871
 }
Please login to merge, or discard this patch.
Spacing   +135 added lines, -135 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,23 +128,23 @@  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_codeproduitservice = 0;      // Affiche code produit-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_codeproduitservice = 0; // Affiche code produit-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
 
150 150
 
@@ -160,14 +160,14 @@  discard block
 block discarded – undo
160 160
 	 *  @param		int			$hideref			Do not show ref
161 161
 	 *	@return		int         					1 if OK, <=0 if KO
162 162
 	 */
163
-	function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
163
+	function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
164 164
 	{
165 165
         // phpcs:enable
166
-		global $user,$langs,$conf,$mysoc,$db,$hookmanager;
166
+		global $user, $langs, $conf, $mysoc, $db, $hookmanager;
167 167
 
168
-		if (! is_object($outputlangs)) $outputlangs=$langs;
168
+		if (!is_object($outputlangs)) $outputlangs = $langs;
169 169
 		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
170
-		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
170
+		if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1';
171 171
 
172 172
 		// Load traductions files requiredby by page
173 173
 		$outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "deliveries"));
@@ -180,24 +180,24 @@  discard block
 block discarded – undo
180 180
 			if ($object->specimen)
181 181
 			{
182 182
 				$dir = $conf->produit->dir_output;
183
-				$file = $dir . "/SPECIMEN.pdf";
183
+				$file = $dir."/SPECIMEN.pdf";
184 184
 			}
185 185
 			else
186 186
 			{
187 187
 				$objectref = dol_sanitizeFileName($object->ref);
188
-				$dir = $conf->produit->dir_output . "/" . $objectref;
189
-				$file = $dir . "/" . $objectref . ".pdf";
188
+				$dir = $conf->produit->dir_output."/".$objectref;
189
+				$file = $dir."/".$objectref.".pdf";
190 190
 			}
191 191
 
192 192
 			$productFournisseur = new ProductFournisseur($this->db);
193 193
 			$supplierprices = $productFournisseur->list_product_fournisseur_price($object->id);
194 194
 			$object->supplierprices = $supplierprices;
195 195
 
196
-			if (! file_exists($dir))
196
+			if (!file_exists($dir))
197 197
 			{
198 198
 				if (dol_mkdir($dir) < 0)
199 199
 				{
200
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
200
+					$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
201 201
 					return -1;
202 202
 				}
203 203
 			}
@@ -205,25 +205,25 @@  discard block
 block discarded – undo
205 205
 			if (file_exists($dir))
206 206
 			{
207 207
 							// Add pdfgeneration hook
208
-				if (! is_object($hookmanager))
208
+				if (!is_object($hookmanager))
209 209
 				{
210 210
 					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
211
-					$hookmanager=new HookManager($this->db);
211
+					$hookmanager = new HookManager($this->db);
212 212
 				}
213 213
 				$hookmanager->initHooks(array('pdfgeneration'));
214
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
214
+				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
215 215
 				global $action;
216
-				$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
216
+				$reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
217 217
 
218 218
 				// Create pdf instance
219
-				$pdf=pdf_getInstance($this->format);
220
-				$default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
221
-				$pdf->SetAutoPageBreak(1,0);
219
+				$pdf = pdf_getInstance($this->format);
220
+				$default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
221
+				$pdf->SetAutoPageBreak(1, 0);
222 222
 
223
-				$heightforinfotot = 40;	// Height reserved to output the info and total part
224
-		        $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
225
-	            $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
226
-	            if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
223
+				$heightforinfotot = 40; // Height reserved to output the info and total part
224
+		        $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
225
+	            $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
226
+	            if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS > 0) $heightforfooter += 6;
227 227
 
228 228
                 if (class_exists('TCPDF'))
229 229
                 {
@@ -232,51 +232,51 @@  discard block
 block discarded – undo
232 232
                 }
233 233
                 $pdf->SetFont(pdf_getPDFFont($outputlangs));
234 234
                 // Set path to the background PDF File
235
-                if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
235
+                if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
236 236
                 {
237 237
                     $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
238 238
                     $tplidx = $pdf->importPage(1);
239 239
                 }
240 240
 
241 241
 				$pdf->Open();
242
-				$pagenb=0;
243
-				$pdf->SetDrawColor(128,128,128);
242
+				$pagenb = 0;
243
+				$pdf->SetDrawColor(128, 128, 128);
244 244
 
245 245
 				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
246 246
 				$pdf->SetSubject($outputlangs->transnoentities("Order"));
247 247
 				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
248 248
 				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
249 249
 				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
250
-				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
250
+				if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
251 251
 
252
-				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
252
+				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
253 253
 
254 254
 
255 255
 				// New page
256 256
 				$pdf->AddPage();
257
-				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
257
+				if (!empty($tplidx)) $pdf->useTemplate($tplidx);
258 258
 				$pagenb++;
259 259
 				$this->_pagehead($pdf, $object, 1, $outputlangs);
260
-				$pdf->SetFont('','', $default_font_size - 1);
261
-				$pdf->MultiCell(0, 3, '');		// Set interline to 3
262
-				$pdf->SetTextColor(0,0,0);
260
+				$pdf->SetFont('', '', $default_font_size - 1);
261
+				$pdf->MultiCell(0, 3, ''); // Set interline to 3
262
+				$pdf->SetTextColor(0, 0, 0);
263 263
 
264 264
 
265 265
 				$tab_top = 42;
266
-				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
266
+				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10);
267 267
 				$tab_height = 130;
268 268
 				$tab_height_newpage = 150;
269 269
 
270 270
 				//
271
-				$pdf->SetFont('','B', $default_font_size);
271
+				$pdf->SetFont('', 'B', $default_font_size);
272 272
 				$pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top, dol_htmlentitiesbr($object->label), 0, 1);
273 273
 				$nexY = $pdf->GetY();
274 274
 
275
-				$pdf->SetFont('','', $default_font_size);
275
+				$pdf->SetFont('', '', $default_font_size);
276 276
 				$pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, dol_htmlentitiesbr($object->description), 0, 1);
277 277
 				$nexY = $pdf->GetY();
278 278
 
279
-				$nexY+=5;
279
+				$nexY += 5;
280 280
 
281 281
 				if ($object->weight)
282 282
 				{
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 				}
286 286
 				if ($object->weight)
287 287
 				{
288
-				    $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").': '.($object->length != ''?$object->length:'?').' x '.($object->width != ''?$object->width:'?').' x '.($object->height != ''?$object->height:'?'), 0, 1);
288
+				    $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").': '.($object->length != '' ? $object->length : '?').' x '.($object->width != '' ? $object->width : '?').' x '.($object->height != '' ? $object->height : '?'), 0, 1);
289 289
 				    $nexY = $pdf->GetY();
290 290
 				}
291 291
 				if ($object->surface)
@@ -302,41 +302,41 @@  discard block
 block discarded – undo
302 302
 
303 303
 				// Affiche notes
304 304
 				// TODO There is no public note on product yet
305
-				$notetoshow=empty($object->note_public)?'':$object->note_public;
306
-				if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
305
+				$notetoshow = empty($object->note_public) ? '' : $object->note_public;
306
+				if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
307 307
 				{
308 308
 					// Get first sale rep
309 309
 					if (is_object($object->thirdparty))
310 310
 					{
311
-						$salereparray=$object->thirdparty->getSalesRepresentatives($user);
312
-						$salerepobj=new User($this->db);
311
+						$salereparray = $object->thirdparty->getSalesRepresentatives($user);
312
+						$salerepobj = new User($this->db);
313 313
 						$salerepobj->fetch($salereparray[0]['id']);
314
-						if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
314
+						if (!empty($salerepobj->signature)) $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
315 315
 					}
316 316
 				}
317 317
 				if ($notetoshow)
318 318
 				{
319
-					$substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
319
+					$substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
320 320
 					complete_substitutions_array($substitutionarray, $outputlangs, $object);
321 321
 					$notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
322 322
 
323 323
 					$tab_top = 88;
324 324
 
325
-					$pdf->SetFont('','', $default_font_size - 1);
326
-					$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
325
+					$pdf->SetFont('', '', $default_font_size - 1);
326
+					$pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
327 327
 					$nexY = $pdf->GetY();
328
-					$height_note=$nexY-$tab_top;
328
+					$height_note = $nexY - $tab_top;
329 329
 
330 330
 					// Rect prend une longueur en 3eme param
331
-					$pdf->SetDrawColor(192,192,192);
332
-					$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
331
+					$pdf->SetDrawColor(192, 192, 192);
332
+					$pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
333 333
 
334 334
 					$tab_height = $tab_height - $height_note;
335
-					$tab_top = $nexY+6;
335
+					$tab_top = $nexY + 6;
336 336
 				}
337 337
 				else
338 338
 				{
339
-					$height_note=0;
339
+					$height_note = 0;
340 340
 				}
341 341
 
342 342
 				$iniY = $tab_top + 7;
@@ -556,35 +556,35 @@  discard block
 block discarded – undo
556 556
 				//$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
557 557
 
558 558
 				// Pied de page
559
-				$this->_pagefoot($pdf,$object,$outputlangs);
560
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
559
+				$this->_pagefoot($pdf, $object, $outputlangs);
560
+				if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
561 561
 
562 562
 				$pdf->Close();
563 563
 
564
-				$pdf->Output($file,'F');
564
+				$pdf->Output($file, 'F');
565 565
 
566 566
 				// Add pdfgeneration hook
567 567
 				$hookmanager->initHooks(array('pdfgeneration'));
568
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
568
+				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
569 569
 				global $action;
570
-				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
570
+				$reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
571 571
 
572
-				if (! empty($conf->global->MAIN_UMASK))
572
+				if (!empty($conf->global->MAIN_UMASK))
573 573
 					@chmod($file, octdec($conf->global->MAIN_UMASK));
574 574
 
575 575
 				$this->result = array('fullpath'=>$file);
576 576
 
577
-				return 1;   // Pas d'erreur
577
+				return 1; // Pas d'erreur
578 578
 			}
579 579
 			else
580 580
 			{
581
-				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
581
+				$this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
582 582
 				return 0;
583 583
 			}
584 584
 		}
585 585
 		else
586 586
 		{
587
-			$this->error=$langs->trans("ErrorConstantNotDefined","PRODUCT_OUTPUTDIR");
587
+			$this->error = $langs->trans("ErrorConstantNotDefined", "PRODUCT_OUTPUTDIR");
588 588
 			return 0;
589 589
 		}
590 590
 	}
@@ -603,77 +603,77 @@  discard block
 block discarded – undo
603 603
 	 *   @param		string		$currency		Currency code
604 604
 	 *   @return	void
605 605
 	 */
606
-	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
606
+	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
607 607
 	{
608 608
 	    global $conf;
609 609
 
610 610
 	    // Force to disable hidetop and hidebottom
611
-	    $hidebottom=0;
612
-	    if ($hidetop) $hidetop=-1;
611
+	    $hidebottom = 0;
612
+	    if ($hidetop) $hidetop = -1;
613 613
 
614 614
 	    $currency = !empty($currency) ? $currency : $conf->currency;
615 615
 	    $default_font_size = pdf_getPDFFontSize($outputlangs);
616 616
 
617 617
 	    // Amount in (at tab_top - 1)
618
-	    $pdf->SetTextColor(0,0,0);
619
-	    $pdf->SetFont('','', $default_font_size - 2);
618
+	    $pdf->SetTextColor(0, 0, 0);
619
+	    $pdf->SetFont('', '', $default_font_size - 2);
620 620
 
621 621
 	    if (empty($hidetop))
622 622
 	    {
623
-	        $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
624
-	        $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
623
+	        $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
624
+	        $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
625 625
 	        $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
626 626
 
627 627
 	        //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
628
-	        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));
628
+	        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));
629 629
 	    }
630 630
 
631
-	    $pdf->SetDrawColor(128,128,128);
632
-	    $pdf->SetFont('','', $default_font_size - 1);
631
+	    $pdf->SetDrawColor(128, 128, 128);
632
+	    $pdf->SetFont('', '', $default_font_size - 1);
633 633
 
634 634
 	    // Output Rect
635
-	    $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
635
+	    $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
636 636
 
637 637
 	    if (empty($hidetop))
638 638
 	    {
639
-	        $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
639
+	        $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
640 640
 
641
-	        $pdf->SetXY($this->posxdesc-1, $tab_top+1);
642
-	        $pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
641
+	        $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
642
+	        $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
643 643
 	    }
644 644
 
645 645
 	    if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
646 646
 	    {
647
-	        $pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
647
+	        $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
648 648
 	        if (empty($hidetop))
649 649
 	        {
650
-	            $pdf->SetXY($this->posxtva-3, $tab_top+1);
651
-	            $pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
650
+	            $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
651
+	            $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
652 652
 	        }
653 653
 	    }
654 654
 
655
-	    $pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
655
+	    $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
656 656
 	    if (empty($hidetop))
657 657
 	    {
658
-	        $pdf->SetXY($this->posxup-1, $tab_top+1);
659
-	        $pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
658
+	        $pdf->SetXY($this->posxup - 1, $tab_top + 1);
659
+	        $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
660 660
 	    }
661 661
 
662
-	    $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
662
+	    $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
663 663
 	    if (empty($hidetop))
664 664
 	    {
665
-	        $pdf->SetXY($this->posxqty-1, $tab_top+1);
666
-	        if($conf->global->PRODUCT_USE_UNITS)
665
+	        $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
666
+	        if ($conf->global->PRODUCT_USE_UNITS)
667 667
 	        {
668
-	            $pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
668
+	            $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
669 669
 	        }
670 670
 	        else
671 671
 	        {
672
-	            $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
672
+	            $pdf->MultiCell($this->posxdiscount - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
673 673
 	        }
674 674
 	    }
675 675
 
676
-	    if($conf->global->PRODUCT_USE_UNITS) {
676
+	    if ($conf->global->PRODUCT_USE_UNITS) {
677 677
 	        $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
678 678
 	        if (empty($hidetop)) {
679 679
 	            $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
@@ -682,13 +682,13 @@  discard block
 block discarded – undo
682 682
 	        }
683 683
 	    }
684 684
 
685
-	    $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
685
+	    $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
686 686
 	    if (empty($hidetop))
687 687
 	    {
688 688
 	        if ($this->atleastonediscount)
689 689
 	        {
690
-	            $pdf->SetXY($this->posxdiscount-1, $tab_top+1);
691
-	            $pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
690
+	            $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
691
+	            $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
692 692
 	        }
693 693
 	    }
694 694
 
@@ -698,8 +698,8 @@  discard block
 block discarded – undo
698 698
 	    }
699 699
 	    if (empty($hidetop))
700 700
 	    {
701
-	        $pdf->SetXY($this->postotalht-1, $tab_top+1);
702
-	        $pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHT"),'','C');
701
+	        $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
702
+	        $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
703 703
 	    }
704 704
 	}
705 705
 
@@ -713,72 +713,72 @@  discard block
 block discarded – undo
713 713
 	 *  @param	string		$titlekey		Translation key to show as title of document
714 714
 	 *  @return	void
715 715
 	 */
716
-	function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="")
716
+	function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey = "")
717 717
 	{
718
-	    global $conf,$langs,$hookmanager;
718
+	    global $conf, $langs, $hookmanager;
719 719
 
720 720
 	    // Load traductions files requiredby by page
721 721
 		$outputlangs->loadLangs(array("main", "propal", "companies", "bills", "orders"));
722 722
 
723 723
 	    $default_font_size = pdf_getPDFFontSize($outputlangs);
724 724
 
725
-	    if ($object->type == 1) $titlekey='ServiceSheet';
726
-	    else $titlekey='ProductSheet';
725
+	    if ($object->type == 1) $titlekey = 'ServiceSheet';
726
+	    else $titlekey = 'ProductSheet';
727 727
 
728
-	    pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
728
+	    pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
729 729
 
730 730
 	    // Show Draft Watermark
731
-	    if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
731
+	    if ($object->statut == 0 && (!empty($conf->global->COMMANDE_DRAFT_WATERMARK)))
732 732
 	    {
733
-	        pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
733
+	        pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->COMMANDE_DRAFT_WATERMARK);
734 734
 	    }
735 735
 
736
-	    $pdf->SetTextColor(0,0,60);
737
-	    $pdf->SetFont('','B', $default_font_size + 3);
736
+	    $pdf->SetTextColor(0, 0, 60);
737
+	    $pdf->SetFont('', 'B', $default_font_size + 3);
738 738
 
739
-	    $posy=$this->marge_haute;
740
-	    $posx=$this->page_largeur-$this->marge_droite-100;
739
+	    $posy = $this->marge_haute;
740
+	    $posx = $this->page_largeur - $this->marge_droite - 100;
741 741
 
742
-	    $pdf->SetXY($this->marge_gauche,$posy);
742
+	    $pdf->SetXY($this->marge_gauche, $posy);
743 743
 
744 744
 	    // Logo
745
-	    $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
745
+	    $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
746 746
 	    if ($this->emetteur->logo)
747 747
 	    {
748 748
 	        if (is_readable($logo))
749 749
 	        {
750
-	            $height=pdf_getHeightForLogo($logo);
751
-	            $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
750
+	            $height = pdf_getHeightForLogo($logo);
751
+	            $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
752 752
 	        }
753 753
 	        else
754 754
 	        {
755
-	            $pdf->SetTextColor(200,0,0);
756
-	            $pdf->SetFont('','B', $default_font_size -2);
757
-	            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
755
+	            $pdf->SetTextColor(200, 0, 0);
756
+	            $pdf->SetFont('', 'B', $default_font_size - 2);
757
+	            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
758 758
 	            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
759 759
 	        }
760 760
 	    }
761 761
 	    else
762 762
 	    {
763
-	        $text=$this->emetteur->name;
763
+	        $text = $this->emetteur->name;
764 764
 	        $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
765 765
 	    }
766 766
 
767
-	    $pdf->SetFont('','B', $default_font_size + 3);
768
-	    $pdf->SetXY($posx,$posy);
769
-	    $pdf->SetTextColor(0,0,60);
770
-	    $title=$outputlangs->transnoentities($titlekey);
767
+	    $pdf->SetFont('', 'B', $default_font_size + 3);
768
+	    $pdf->SetXY($posx, $posy);
769
+	    $pdf->SetTextColor(0, 0, 60);
770
+	    $title = $outputlangs->transnoentities($titlekey);
771 771
 	    $pdf->MultiCell(100, 3, $title, '', 'R');
772 772
 
773
-	    $pdf->SetFont('','B',$default_font_size);
773
+	    $pdf->SetFont('', 'B', $default_font_size);
774 774
 
775
-	    $posy+=5;
776
-	    $pdf->SetXY($posx,$posy);
777
-	    $pdf->SetTextColor(0,0,60);
778
-	    $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
775
+	    $posy += 5;
776
+	    $pdf->SetXY($posx, $posy);
777
+	    $pdf->SetTextColor(0, 0, 60);
778
+	    $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
779 779
 
780
-	    $posy+=1;
781
-	    $pdf->SetFont('','', $default_font_size - 1);
780
+	    $posy += 1;
781
+	    $pdf->SetFont('', '', $default_font_size - 1);
782 782
 
783 783
 	    /*if ($object->ref_client)
784 784
 	    {
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
 	        }
811 811
 	    }*/
812 812
 
813
-	    $posy+=2;
813
+	    $posy += 2;
814 814
 
815 815
 	    // Show list of linked objects
816 816
 	    $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
@@ -850,7 +850,7 @@  discard block
 block discarded – undo
850 850
 	        */
851 851
 	    }
852 852
 
853
-	    $pdf->SetTextColor(0,0,0);
853
+	    $pdf->SetTextColor(0, 0, 0);
854 854
 	}
855 855
 
856 856
 	/**
@@ -862,10 +862,10 @@  discard block
 block discarded – undo
862 862
 	 *      @param	int			$hidefreetext		1=Hide free text
863 863
 	 *      @return	int								Return height of bottom margin including footer text
864 864
 	 */
865
-	function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
865
+	function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
866 866
 	{
867 867
 	    global $conf;
868
-	    $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
869
-	    return pdf_pagefoot($pdf,$outputlangs,'PRODUCT_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
868
+	    $showdetails = $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
869
+	    return pdf_pagefoot($pdf, $outputlangs, 'PRODUCT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
870 870
 	}
871 871
 }
Please login to merge, or discard this patch.
Braces   +46 added lines, -28 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
 
150 153
 
@@ -165,9 +168,13 @@  discard block
 block discarded – undo
165 168
         // phpcs:enable
166 169
 		global $user,$langs,$conf,$mysoc,$db,$hookmanager;
167 170
 
168
-		if (! is_object($outputlangs)) $outputlangs=$langs;
171
+		if (! is_object($outputlangs)) {
172
+		    $outputlangs=$langs;
173
+		}
169 174
 		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
170
-		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
175
+		if (! empty($conf->global->MAIN_USE_FPDF)) {
176
+		    $outputlangs->charset_output='ISO-8859-1';
177
+		}
171 178
 
172 179
 		// Load traductions files requiredby by page
173 180
 		$outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "deliveries"));
@@ -181,8 +188,7 @@  discard block
 block discarded – undo
181 188
 			{
182 189
 				$dir = $conf->produit->dir_output;
183 190
 				$file = $dir . "/SPECIMEN.pdf";
184
-			}
185
-			else
191
+			} else
186 192
 			{
187 193
 				$objectref = dol_sanitizeFileName($object->ref);
188 194
 				$dir = $conf->produit->dir_output . "/" . $objectref;
@@ -223,7 +229,9 @@  discard block
 block discarded – undo
223 229
 				$heightforinfotot = 40;	// Height reserved to output the info and total part
224 230
 		        $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
225 231
 	            $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
226
-	            if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
232
+	            if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) {
233
+	                $heightforfooter+= 6;
234
+	            }
227 235
 
228 236
                 if (class_exists('TCPDF'))
229 237
                 {
@@ -247,14 +255,18 @@  discard block
 block discarded – undo
247 255
 				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
248 256
 				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
249 257
 				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
250
-				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
258
+				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
259
+				    $pdf->SetCompression(false);
260
+				}
251 261
 
252 262
 				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
253 263
 
254 264
 
255 265
 				// New page
256 266
 				$pdf->AddPage();
257
-				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
267
+				if (! empty($tplidx)) {
268
+				    $pdf->useTemplate($tplidx);
269
+				}
258 270
 				$pagenb++;
259 271
 				$this->_pagehead($pdf, $object, 1, $outputlangs);
260 272
 				$pdf->SetFont('','', $default_font_size - 1);
@@ -311,7 +323,9 @@  discard block
 block discarded – undo
311 323
 						$salereparray=$object->thirdparty->getSalesRepresentatives($user);
312 324
 						$salerepobj=new User($this->db);
313 325
 						$salerepobj->fetch($salereparray[0]['id']);
314
-						if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
326
+						if (! empty($salerepobj->signature)) {
327
+						    $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
328
+						}
315 329
 					}
316 330
 				}
317 331
 				if ($notetoshow)
@@ -333,8 +347,7 @@  discard block
 block discarded – undo
333 347
 
334 348
 					$tab_height = $tab_height - $height_note;
335 349
 					$tab_top = $nexY+6;
336
-				}
337
-				else
350
+				} else
338 351
 				{
339 352
 					$height_note=0;
340 353
 				}
@@ -557,7 +570,9 @@  discard block
 block discarded – undo
557 570
 
558 571
 				// Pied de page
559 572
 				$this->_pagefoot($pdf,$object,$outputlangs);
560
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
573
+				if (method_exists($pdf,'AliasNbPages')) {
574
+				    $pdf->AliasNbPages();
575
+				}
561 576
 
562 577
 				$pdf->Close();
563 578
 
@@ -569,20 +584,19 @@  discard block
 block discarded – undo
569 584
 				global $action;
570 585
 				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
571 586
 
572
-				if (! empty($conf->global->MAIN_UMASK))
573
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
587
+				if (! empty($conf->global->MAIN_UMASK)) {
588
+									@chmod($file, octdec($conf->global->MAIN_UMASK));
589
+				}
574 590
 
575 591
 				$this->result = array('fullpath'=>$file);
576 592
 
577 593
 				return 1;   // Pas d'erreur
578
-			}
579
-			else
594
+			} else
580 595
 			{
581 596
 				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
582 597
 				return 0;
583 598
 			}
584
-		}
585
-		else
599
+		} else
586 600
 		{
587 601
 			$this->error=$langs->trans("ErrorConstantNotDefined","PRODUCT_OUTPUTDIR");
588 602
 			return 0;
@@ -609,7 +623,9 @@  discard block
 block discarded – undo
609 623
 
610 624
 	    // Force to disable hidetop and hidebottom
611 625
 	    $hidebottom=0;
612
-	    if ($hidetop) $hidetop=-1;
626
+	    if ($hidetop) {
627
+	        $hidetop=-1;
628
+	    }
613 629
 
614 630
 	    $currency = !empty($currency) ? $currency : $conf->currency;
615 631
 	    $default_font_size = pdf_getPDFFontSize($outputlangs);
@@ -625,7 +641,9 @@  discard block
 block discarded – undo
625 641
 	        $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
626 642
 
627 643
 	        //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
628
-	        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));
644
+	        if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
645
+	            $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));
646
+	        }
629 647
 	    }
630 648
 
631 649
 	    $pdf->SetDrawColor(128,128,128);
@@ -666,8 +684,7 @@  discard block
 block discarded – undo
666 684
 	        if($conf->global->PRODUCT_USE_UNITS)
667 685
 	        {
668 686
 	            $pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
669
-	        }
670
-	        else
687
+	        } else
671 688
 	        {
672 689
 	            $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
673 690
 	        }
@@ -722,8 +739,11 @@  discard block
 block discarded – undo
722 739
 
723 740
 	    $default_font_size = pdf_getPDFFontSize($outputlangs);
724 741
 
725
-	    if ($object->type == 1) $titlekey='ServiceSheet';
726
-	    else $titlekey='ProductSheet';
742
+	    if ($object->type == 1) {
743
+	        $titlekey='ServiceSheet';
744
+	    } else {
745
+	        $titlekey='ProductSheet';
746
+	    }
727 747
 
728 748
 	    pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
729 749
 
@@ -749,16 +769,14 @@  discard block
 block discarded – undo
749 769
 	        {
750 770
 	            $height=pdf_getHeightForLogo($logo);
751 771
 	            $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
752
-	        }
753
-	        else
772
+	        } else
754 773
 	        {
755 774
 	            $pdf->SetTextColor(200,0,0);
756 775
 	            $pdf->SetFont('','B', $default_font_size -2);
757 776
 	            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
758 777
 	            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
759 778
 	        }
760
-	    }
761
-	    else
779
+	    } else
762 780
 	    {
763 781
 	        $text=$this->emetteur->name;
764 782
 	        $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/product/mod_codeproduct_elephant.php 3 patches
Indentation   +278 added lines, -278 removed lines patch added patch discarded remove patch
@@ -34,299 +34,299 @@
 block discarded – undo
34 34
  */
35 35
 class mod_codeproduct_elephant extends ModeleProductCode
36 36
 {
37
-	/**
38
-	 * @var string Nom du modele
39
-	 * @deprecated
40
-	 * @see name
41
-	 */
42
-	public $nom='Elephant';
37
+    /**
38
+     * @var string Nom du modele
39
+     * @deprecated
40
+     * @see name
41
+     */
42
+    public $nom='Elephant';
43 43
 
44
-	/**
45
-	 * @var string model name
46
-	 */
47
-	public $name='Elephant';
44
+    /**
45
+     * @var string model name
46
+     */
47
+    public $name='Elephant';
48 48
 
49
-	public $code_modifiable;				// Code modifiable
49
+    public $code_modifiable;				// Code modifiable
50 50
 
51
-	public $code_modifiable_invalide;		// Code modifiable si il est invalide
51
+    public $code_modifiable_invalide;		// Code modifiable si il est invalide
52 52
 
53
-	public $code_modifiable_null;			// Code modifiables si il est null
53
+    public $code_modifiable_null;			// Code modifiables si il est null
54 54
 
55
-	public $code_null;						// Code facultatif
55
+    public $code_null;						// Code facultatif
56 56
 
57
-	/**
57
+    /**
58 58
      * Dolibarr version of the loaded document
59 59
      * @public string
60 60
      */
61
-	public $version = 'dolibarr';    		// 'development', 'experimental', 'dolibarr'
62
-
63
-	public $code_auto;                     // Numerotation automatique
64
-
65
-	public $searchcode; // String de recherche
66
-
67
-	public $numbitcounter; // Nombre de chiffres du compteur
68
-
69
-	public $prefixIsRequired; // Le champ prefix du tiers doit etre renseigne quand on utilise {pre}
70
-
71
-
72
-	/**
73
-	 *	Constructor
74
-	 */
75
-	function __construct()
76
-	{
77
-		$this->code_null = 0;
78
-		$this->code_modifiable = 1;
79
-		$this->code_modifiable_invalide = 1;
80
-		$this->code_modifiable_null = 1;
81
-		$this->code_auto = 1;
82
-		$this->prefixIsRequired = 0;
83
-	}
84
-
85
-
86
-	/**		Return description of module
87
-	 *
88
-	 * 		@param	Translate	$langs		Object langs
89
-	 * 		@return string      			Description of module
90
-	 */
91
-	function info($langs)
92
-	{
93
-		global $conf, $mc;
94
-		global $form;
95
-
96
-		$langs->load("products");
97
-
98
-		$disabled = ((! empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity) ? ' disabled' : '');
99
-
100
-		$texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
101
-		$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
102
-		$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
103
-		$texte.= '<input type="hidden" name="action" value="setModuleOptions">';
104
-		$texte.= '<input type="hidden" name="param1" value="PRODUCT_ELEPHANT_MASK_PRODUCT">';
105
-		$texte.= '<input type="hidden" name="param2" value="PRODUCT_ELEPHANT_MASK_SERVICE">';
106
-		$texte.= '<table class="nobordernopadding" width="100%">';
107
-
108
-		$tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Product"),$langs->transnoentities("Product"));
109
-		$tooltip.=$langs->trans("GenericMaskCodes3");
110
-		$tooltip.=$langs->trans("GenericMaskCodes4c");
111
-		$tooltip.=$langs->trans("GenericMaskCodes5");
112
-
113
-		// Parametrage du prefix customers
114
-		$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("ProductCodeModel").'):</td>';
115
-		$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value1" value="'.(! empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT)?$conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT:'').'"'.$disabled.'>',$tooltip,1,1).'</td>';
116
-
117
-		$texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"'.$disabled.'></td>';
118
-
119
-		$texte.= '</tr>';
120
-
121
-		// Parametrage du prefix suppliers
122
-		$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("ServiceCodeModel").'):</td>';
123
-		$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value2" value="'.(! empty($conf->global->PRODUCT_ELEPHANT_MASK_SERVICE)?$conf->global->PRODUCT_ELEPHANT_MASK_SERVICE:'').'"'.$disabled.'>',$tooltip,1,1).'</td>';
124
-		$texte.= '</tr>';
125
-
126
-		$texte.= '</table>';
127
-		$texte.= '</form>';
128
-
129
-		return $texte;
130
-	}
131
-
132
-
133
-	/**
134
-	 * Return an example of result returned by getNextValue
135
-	 *
136
-	 * @param	Translate	$langs		Object langs
137
-	 * @param	product		$objproduct		Object product
138
-	 * @param	int			$type		Type of third party (1:customer, 2:supplier, -1:autodetect)
139
-	 * @return	string					Return string example
140
-	 */
141
-	function getExample($langs,$objproduct=0,$type=-1)
142
-	{
143
-		if ($type == 0 || $type == -1)
144
-		{
145
-			$exampleproduct = $this->getNextValue($objproduct,0);
146
-			if (! $exampleproduct)
147
-			{
148
-				$exampleproduct = $langs->trans('NotConfigured');
149
-			}
150
-			if($exampleproduct=="ErrorBadMask")
151
-			{
152
-				$langs->load("errors");
153
-				$exampleproduct=$langs->trans($exampleproduct);
154
-			}
155
-		}
156
-		if ($type == 1 || $type == -1)
157
-		{
158
-			$exampleservice = $this->getNextValue($objproduct,1);
159
-			if (! $exampleservice)
160
-			{
161
-				$exampleservice = $langs->trans('NotConfigured');
162
-			}
163
-			if($exampleservice=="ErrorBadMask")
164
-			{
165
-				$langs->load("errors");
166
-				$exampleservice=$langs->trans($exampleservice);
167
-			}
168
-		}
169
-
170
-		if ($type == 0) return $exampleproduct;
171
-		if ($type == 1) return $exampleservice;
172
-		return $exampleproduct.'<br>'.$exampleservice;
173
-	}
174
-
175
-	/**
176
-	 * Return next value
177
-	 *
178
-	 * @param	Product		$objproduct     Object product
179
-	 * @param  	int		    $type       Produit ou service (0:product, 1:service)
180
-	 * @return 	string      			Value if OK, '' if module not configured, <0 if KO
181
-	 */
182
-	function getNextValue($objproduct=0,$type=-1)
183
-	{
184
-		global $db,$conf;
185
-
186
-		require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
187
-
188
-		// Get Mask value
189
-		$mask = '';
190
-		if ($type == 0 && ! empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT))
191
-			$mask = $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
192
-		else if ($type == 1 && ! empty($conf->global->PRODUCT_ELEPHANT_MASK_SERVICE))
193
-			$mask = $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
194
-
195
-		if (empty($mask))
196
-		{
197
-			$this->error='NotConfigured';
198
-			return '';
199
-		}
200
-
201
-		$field='';$where='';
202
-		if ($type == 0)
203
-		{
204
-			$field = 'ref';
205
-			//$where = ' AND client in (1,2)';
206
-		}
207
-		else if ($type == 1)
208
-		{
209
-			$field = 'ref';
210
-			//$where = ' AND fournisseur = 1';
211
-		}
212
-		else return -1;
213
-
214
-		$now=dol_now();
215
-
216
-		$numFinal=get_next_value($db,$mask,'product',$field,$where,'',$now);
217
-
218
-		return  $numFinal;
219
-	}
61
+    public $version = 'dolibarr';    		// 'development', 'experimental', 'dolibarr'
62
+
63
+    public $code_auto;                     // Numerotation automatique
64
+
65
+    public $searchcode; // String de recherche
66
+
67
+    public $numbitcounter; // Nombre de chiffres du compteur
68
+
69
+    public $prefixIsRequired; // Le champ prefix du tiers doit etre renseigne quand on utilise {pre}
70
+
71
+
72
+    /**
73
+     *	Constructor
74
+     */
75
+    function __construct()
76
+    {
77
+        $this->code_null = 0;
78
+        $this->code_modifiable = 1;
79
+        $this->code_modifiable_invalide = 1;
80
+        $this->code_modifiable_null = 1;
81
+        $this->code_auto = 1;
82
+        $this->prefixIsRequired = 0;
83
+    }
84
+
85
+
86
+    /**		Return description of module
87
+     *
88
+     * 		@param	Translate	$langs		Object langs
89
+     * 		@return string      			Description of module
90
+     */
91
+    function info($langs)
92
+    {
93
+        global $conf, $mc;
94
+        global $form;
95
+
96
+        $langs->load("products");
97
+
98
+        $disabled = ((! empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity) ? ' disabled' : '');
99
+
100
+        $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
101
+        $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
102
+        $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
103
+        $texte.= '<input type="hidden" name="action" value="setModuleOptions">';
104
+        $texte.= '<input type="hidden" name="param1" value="PRODUCT_ELEPHANT_MASK_PRODUCT">';
105
+        $texte.= '<input type="hidden" name="param2" value="PRODUCT_ELEPHANT_MASK_SERVICE">';
106
+        $texte.= '<table class="nobordernopadding" width="100%">';
107
+
108
+        $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Product"),$langs->transnoentities("Product"));
109
+        $tooltip.=$langs->trans("GenericMaskCodes3");
110
+        $tooltip.=$langs->trans("GenericMaskCodes4c");
111
+        $tooltip.=$langs->trans("GenericMaskCodes5");
112
+
113
+        // Parametrage du prefix customers
114
+        $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("ProductCodeModel").'):</td>';
115
+        $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value1" value="'.(! empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT)?$conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT:'').'"'.$disabled.'>',$tooltip,1,1).'</td>';
116
+
117
+        $texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"'.$disabled.'></td>';
118
+
119
+        $texte.= '</tr>';
120
+
121
+        // Parametrage du prefix suppliers
122
+        $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("ServiceCodeModel").'):</td>';
123
+        $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value2" value="'.(! empty($conf->global->PRODUCT_ELEPHANT_MASK_SERVICE)?$conf->global->PRODUCT_ELEPHANT_MASK_SERVICE:'').'"'.$disabled.'>',$tooltip,1,1).'</td>';
124
+        $texte.= '</tr>';
125
+
126
+        $texte.= '</table>';
127
+        $texte.= '</form>';
128
+
129
+        return $texte;
130
+    }
131
+
132
+
133
+    /**
134
+     * Return an example of result returned by getNextValue
135
+     *
136
+     * @param	Translate	$langs		Object langs
137
+     * @param	product		$objproduct		Object product
138
+     * @param	int			$type		Type of third party (1:customer, 2:supplier, -1:autodetect)
139
+     * @return	string					Return string example
140
+     */
141
+    function getExample($langs,$objproduct=0,$type=-1)
142
+    {
143
+        if ($type == 0 || $type == -1)
144
+        {
145
+            $exampleproduct = $this->getNextValue($objproduct,0);
146
+            if (! $exampleproduct)
147
+            {
148
+                $exampleproduct = $langs->trans('NotConfigured');
149
+            }
150
+            if($exampleproduct=="ErrorBadMask")
151
+            {
152
+                $langs->load("errors");
153
+                $exampleproduct=$langs->trans($exampleproduct);
154
+            }
155
+        }
156
+        if ($type == 1 || $type == -1)
157
+        {
158
+            $exampleservice = $this->getNextValue($objproduct,1);
159
+            if (! $exampleservice)
160
+            {
161
+                $exampleservice = $langs->trans('NotConfigured');
162
+            }
163
+            if($exampleservice=="ErrorBadMask")
164
+            {
165
+                $langs->load("errors");
166
+                $exampleservice=$langs->trans($exampleservice);
167
+            }
168
+        }
169
+
170
+        if ($type == 0) return $exampleproduct;
171
+        if ($type == 1) return $exampleservice;
172
+        return $exampleproduct.'<br>'.$exampleservice;
173
+    }
174
+
175
+    /**
176
+     * Return next value
177
+     *
178
+     * @param	Product		$objproduct     Object product
179
+     * @param  	int		    $type       Produit ou service (0:product, 1:service)
180
+     * @return 	string      			Value if OK, '' if module not configured, <0 if KO
181
+     */
182
+    function getNextValue($objproduct=0,$type=-1)
183
+    {
184
+        global $db,$conf;
185
+
186
+        require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
187
+
188
+        // Get Mask value
189
+        $mask = '';
190
+        if ($type == 0 && ! empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT))
191
+            $mask = $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
192
+        else if ($type == 1 && ! empty($conf->global->PRODUCT_ELEPHANT_MASK_SERVICE))
193
+            $mask = $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
194
+
195
+        if (empty($mask))
196
+        {
197
+            $this->error='NotConfigured';
198
+            return '';
199
+        }
200
+
201
+        $field='';$where='';
202
+        if ($type == 0)
203
+        {
204
+            $field = 'ref';
205
+            //$where = ' AND client in (1,2)';
206
+        }
207
+        else if ($type == 1)
208
+        {
209
+            $field = 'ref';
210
+            //$where = ' AND fournisseur = 1';
211
+        }
212
+        else return -1;
213
+
214
+        $now=dol_now();
215
+
216
+        $numFinal=get_next_value($db,$mask,'product',$field,$where,'',$now);
217
+
218
+        return  $numFinal;
219
+    }
220 220
 
221 221
 
222 222
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
223
-	/**
224
-	 *   Check if mask/numbering use prefix
225
-	 *
226
-	 *   @return	int			0 or 1
227
-	 */
228
-	function verif_prefixIsUsed()
229
-	{
223
+    /**
224
+     *   Check if mask/numbering use prefix
225
+     *
226
+     *   @return	int			0 or 1
227
+     */
228
+    function verif_prefixIsUsed()
229
+    {
230 230
         // phpcs:enable
231
-		global $conf;
232
-
233
-		$mask = $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
234
-		if (preg_match('/\{pre\}/i',$mask)) return 1;
235
-
236
-		$mask = $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
237
-		if (preg_match('/\{pre\}/i',$mask)) return 1;
238
-
239
-		return 0;
240
-	}
241
-
242
-
243
-	/**
244
-	 * 	Check validity of code according to its rules
245
-	 *
246
-	 *	@param	DoliDB		$db		Database handler
247
-	 *	@param	string		$code	Code to check/correct
248
-	 *	@param	Product		$product	Object product
249
-	 *  @param  int		  	$type   0 = customer/prospect , 1 = supplier
250
-	 *  @return int					0 if OK
251
-	 * 								-1 ErrorBadCustomerCodeSyntax
252
-	 * 								-2 ErrorCustomerCodeRequired
253
-	 * 								-3 ErrorCustomerCodeAlreadyUsed
254
-	 * 								-4 ErrorPrefixRequired
255
-	 * 								-5 Other (see this->error)
256
-	 */
257
-	function verif($db, &$code, $product, $type)
258
-	{
259
-		global $conf;
260
-
261
-		require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
262
-
263
-		$result=0;
264
-		$code = strtoupper(trim($code));
265
-
266
-		if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))
267
-		{
268
-			$result=0;
269
-		}
270
-		else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) )
271
-		{
272
-			$result=-2;
273
-		}
274
-		else
275
-		{
276
-			// Get Mask value
277
-			$mask = '';
278
-			if ($type==0) $mask = empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT)?'':$conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
279
-			if ($type==1) $mask = empty($conf->global->PRODUCT_ELEPHANT_MASK_SERVICE)?'':$conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
280
-			if (! $mask)
281
-			{
282
-				$this->error='NotConfigured';
283
-				return -5;
284
-			}
285
-
286
-			$result=check_value($mask,$code);
287
-			if (is_string($result))
288
-			{
289
-				$this->error = $result;
290
-				return -5;
291
-			}
292
-		}
293
-
294
-		dol_syslog("mod_codeclient_elephant::verif type=".$type." result=".$result);
295
-		return $result;
296
-	}
231
+        global $conf;
232
+
233
+        $mask = $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
234
+        if (preg_match('/\{pre\}/i',$mask)) return 1;
235
+
236
+        $mask = $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
237
+        if (preg_match('/\{pre\}/i',$mask)) return 1;
238
+
239
+        return 0;
240
+    }
241
+
242
+
243
+    /**
244
+     * 	Check validity of code according to its rules
245
+     *
246
+     *	@param	DoliDB		$db		Database handler
247
+     *	@param	string		$code	Code to check/correct
248
+     *	@param	Product		$product	Object product
249
+     *  @param  int		  	$type   0 = customer/prospect , 1 = supplier
250
+     *  @return int					0 if OK
251
+     * 								-1 ErrorBadCustomerCodeSyntax
252
+     * 								-2 ErrorCustomerCodeRequired
253
+     * 								-3 ErrorCustomerCodeAlreadyUsed
254
+     * 								-4 ErrorPrefixRequired
255
+     * 								-5 Other (see this->error)
256
+     */
257
+    function verif($db, &$code, $product, $type)
258
+    {
259
+        global $conf;
260
+
261
+        require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
262
+
263
+        $result=0;
264
+        $code = strtoupper(trim($code));
265
+
266
+        if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))
267
+        {
268
+            $result=0;
269
+        }
270
+        else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) )
271
+        {
272
+            $result=-2;
273
+        }
274
+        else
275
+        {
276
+            // Get Mask value
277
+            $mask = '';
278
+            if ($type==0) $mask = empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT)?'':$conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
279
+            if ($type==1) $mask = empty($conf->global->PRODUCT_ELEPHANT_MASK_SERVICE)?'':$conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
280
+            if (! $mask)
281
+            {
282
+                $this->error='NotConfigured';
283
+                return -5;
284
+            }
285
+
286
+            $result=check_value($mask,$code);
287
+            if (is_string($result))
288
+            {
289
+                $this->error = $result;
290
+                return -5;
291
+            }
292
+        }
293
+
294
+        dol_syslog("mod_codeclient_elephant::verif type=".$type." result=".$result);
295
+        return $result;
296
+    }
297 297
 
298 298
 
299 299
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
300
-	/**
301
-	 *		Renvoi si un code est pris ou non (par autre tiers)
302
-	 *
303
-	 *		@param	DoliDB		$db			Handler acces base
304
-	 *		@param	string		$code		Code a verifier
305
-	 *		@param	Product		$product		Objet product
306
-	 *		@return	int						0 if available, <0 if KO
307
-	 */
308
-	function verif_dispo($db, $code, $product)
309
-	{
300
+    /**
301
+     *		Renvoi si un code est pris ou non (par autre tiers)
302
+     *
303
+     *		@param	DoliDB		$db			Handler acces base
304
+     *		@param	string		$code		Code a verifier
305
+     *		@param	Product		$product		Objet product
306
+     *		@return	int						0 if available, <0 if KO
307
+     */
308
+    function verif_dispo($db, $code, $product)
309
+    {
310 310
         // phpcs:enable
311
-		$sql = "SELECT ref FROM ".MAIN_DB_PREFIX."product";
312
-		$sql.= " WHERE ref = '".$code."'";
313
-		if ($product->id > 0) $sql.= " AND rowid <> ".$product->id;
314
-
315
-		$resql=$db->query($sql);
316
-		if ($resql)
317
-		{
318
-			if ($db->num_rows($resql) == 0)
319
-			{
320
-				return 0;
321
-			}
322
-			else
323
-			{
324
-				return -1;
325
-			}
326
-		}
327
-		else
328
-		{
329
-			return -2;
330
-		}
331
-	}
311
+        $sql = "SELECT ref FROM ".MAIN_DB_PREFIX."product";
312
+        $sql.= " WHERE ref = '".$code."'";
313
+        if ($product->id > 0) $sql.= " AND rowid <> ".$product->id;
314
+
315
+        $resql=$db->query($sql);
316
+        if ($resql)
317
+        {
318
+            if ($db->num_rows($resql) == 0)
319
+            {
320
+                return 0;
321
+            }
322
+            else
323
+            {
324
+                return -1;
325
+            }
326
+        }
327
+        else
328
+        {
329
+            return -2;
330
+        }
331
+    }
332 332
 }
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -39,28 +39,28 @@  discard block
 block discarded – undo
39 39
 	 * @deprecated
40 40
 	 * @see name
41 41
 	 */
42
-	public $nom='Elephant';
42
+	public $nom = 'Elephant';
43 43
 
44 44
 	/**
45 45
 	 * @var string model name
46 46
 	 */
47
-	public $name='Elephant';
47
+	public $name = 'Elephant';
48 48
 
49
-	public $code_modifiable;				// Code modifiable
49
+	public $code_modifiable; // Code modifiable
50 50
 
51
-	public $code_modifiable_invalide;		// Code modifiable si il est invalide
51
+	public $code_modifiable_invalide; // Code modifiable si il est invalide
52 52
 
53
-	public $code_modifiable_null;			// Code modifiables si il est null
53
+	public $code_modifiable_null; // Code modifiables si il est null
54 54
 
55
-	public $code_null;						// Code facultatif
55
+	public $code_null; // Code facultatif
56 56
 
57 57
 	/**
58 58
      * Dolibarr version of the loaded document
59 59
      * @public string
60 60
      */
61
-	public $version = 'dolibarr';    		// 'development', 'experimental', 'dolibarr'
61
+	public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
62 62
 
63
-	public $code_auto;                     // Numerotation automatique
63
+	public $code_auto; // Numerotation automatique
64 64
 
65 65
 	public $searchcode; // String de recherche
66 66
 
@@ -95,36 +95,36 @@  discard block
 block discarded – undo
95 95
 
96 96
 		$langs->load("products");
97 97
 
98
-		$disabled = ((! empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity) ? ' disabled' : '');
98
+		$disabled = ((!empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity) ? ' disabled' : '');
99 99
 
100 100
 		$texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
101
-		$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
102
-		$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
103
-		$texte.= '<input type="hidden" name="action" value="setModuleOptions">';
104
-		$texte.= '<input type="hidden" name="param1" value="PRODUCT_ELEPHANT_MASK_PRODUCT">';
105
-		$texte.= '<input type="hidden" name="param2" value="PRODUCT_ELEPHANT_MASK_SERVICE">';
106
-		$texte.= '<table class="nobordernopadding" width="100%">';
107
-
108
-		$tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Product"),$langs->transnoentities("Product"));
109
-		$tooltip.=$langs->trans("GenericMaskCodes3");
110
-		$tooltip.=$langs->trans("GenericMaskCodes4c");
111
-		$tooltip.=$langs->trans("GenericMaskCodes5");
101
+		$texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
102
+		$texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
103
+		$texte .= '<input type="hidden" name="action" value="setModuleOptions">';
104
+		$texte .= '<input type="hidden" name="param1" value="PRODUCT_ELEPHANT_MASK_PRODUCT">';
105
+		$texte .= '<input type="hidden" name="param2" value="PRODUCT_ELEPHANT_MASK_SERVICE">';
106
+		$texte .= '<table class="nobordernopadding" width="100%">';
107
+
108
+		$tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Product"), $langs->transnoentities("Product"));
109
+		$tooltip .= $langs->trans("GenericMaskCodes3");
110
+		$tooltip .= $langs->trans("GenericMaskCodes4c");
111
+		$tooltip .= $langs->trans("GenericMaskCodes5");
112 112
 
113 113
 		// Parametrage du prefix customers
114
-		$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("ProductCodeModel").'):</td>';
115
-		$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value1" value="'.(! empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT)?$conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT:'').'"'.$disabled.'>',$tooltip,1,1).'</td>';
114
+		$texte .= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("ProductCodeModel").'):</td>';
115
+		$texte .= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value1" value="'.(!empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT) ? $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT : '').'"'.$disabled.'>', $tooltip, 1, 1).'</td>';
116 116
 
117
-		$texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"'.$disabled.'></td>';
117
+		$texte .= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"'.$disabled.'></td>';
118 118
 
119
-		$texte.= '</tr>';
119
+		$texte .= '</tr>';
120 120
 
121 121
 		// Parametrage du prefix suppliers
122
-		$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("ServiceCodeModel").'):</td>';
123
-		$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value2" value="'.(! empty($conf->global->PRODUCT_ELEPHANT_MASK_SERVICE)?$conf->global->PRODUCT_ELEPHANT_MASK_SERVICE:'').'"'.$disabled.'>',$tooltip,1,1).'</td>';
124
-		$texte.= '</tr>';
122
+		$texte .= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("ServiceCodeModel").'):</td>';
123
+		$texte .= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value2" value="'.(!empty($conf->global->PRODUCT_ELEPHANT_MASK_SERVICE) ? $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE : '').'"'.$disabled.'>', $tooltip, 1, 1).'</td>';
124
+		$texte .= '</tr>';
125 125
 
126
-		$texte.= '</table>';
127
-		$texte.= '</form>';
126
+		$texte .= '</table>';
127
+		$texte .= '</form>';
128 128
 
129 129
 		return $texte;
130 130
 	}
@@ -138,32 +138,32 @@  discard block
 block discarded – undo
138 138
 	 * @param	int			$type		Type of third party (1:customer, 2:supplier, -1:autodetect)
139 139
 	 * @return	string					Return string example
140 140
 	 */
141
-	function getExample($langs,$objproduct=0,$type=-1)
141
+	function getExample($langs, $objproduct = 0, $type = -1)
142 142
 	{
143 143
 		if ($type == 0 || $type == -1)
144 144
 		{
145
-			$exampleproduct = $this->getNextValue($objproduct,0);
146
-			if (! $exampleproduct)
145
+			$exampleproduct = $this->getNextValue($objproduct, 0);
146
+			if (!$exampleproduct)
147 147
 			{
148 148
 				$exampleproduct = $langs->trans('NotConfigured');
149 149
 			}
150
-			if($exampleproduct=="ErrorBadMask")
150
+			if ($exampleproduct == "ErrorBadMask")
151 151
 			{
152 152
 				$langs->load("errors");
153
-				$exampleproduct=$langs->trans($exampleproduct);
153
+				$exampleproduct = $langs->trans($exampleproduct);
154 154
 			}
155 155
 		}
156 156
 		if ($type == 1 || $type == -1)
157 157
 		{
158
-			$exampleservice = $this->getNextValue($objproduct,1);
159
-			if (! $exampleservice)
158
+			$exampleservice = $this->getNextValue($objproduct, 1);
159
+			if (!$exampleservice)
160 160
 			{
161 161
 				$exampleservice = $langs->trans('NotConfigured');
162 162
 			}
163
-			if($exampleservice=="ErrorBadMask")
163
+			if ($exampleservice == "ErrorBadMask")
164 164
 			{
165 165
 				$langs->load("errors");
166
-				$exampleservice=$langs->trans($exampleservice);
166
+				$exampleservice = $langs->trans($exampleservice);
167 167
 			}
168 168
 		}
169 169
 
@@ -179,26 +179,26 @@  discard block
 block discarded – undo
179 179
 	 * @param  	int		    $type       Produit ou service (0:product, 1:service)
180 180
 	 * @return 	string      			Value if OK, '' if module not configured, <0 if KO
181 181
 	 */
182
-	function getNextValue($objproduct=0,$type=-1)
182
+	function getNextValue($objproduct = 0, $type = -1)
183 183
 	{
184
-		global $db,$conf;
184
+		global $db, $conf;
185 185
 
186
-		require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
186
+		require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
187 187
 
188 188
 		// Get Mask value
189 189
 		$mask = '';
190
-		if ($type == 0 && ! empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT))
190
+		if ($type == 0 && !empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT))
191 191
 			$mask = $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
192
-		else if ($type == 1 && ! empty($conf->global->PRODUCT_ELEPHANT_MASK_SERVICE))
192
+		else if ($type == 1 && !empty($conf->global->PRODUCT_ELEPHANT_MASK_SERVICE))
193 193
 			$mask = $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
194 194
 
195 195
 		if (empty($mask))
196 196
 		{
197
-			$this->error='NotConfigured';
197
+			$this->error = 'NotConfigured';
198 198
 			return '';
199 199
 		}
200 200
 
201
-		$field='';$where='';
201
+		$field = ''; $where = '';
202 202
 		if ($type == 0)
203 203
 		{
204 204
 			$field = 'ref';
@@ -211,9 +211,9 @@  discard block
 block discarded – undo
211 211
 		}
212 212
 		else return -1;
213 213
 
214
-		$now=dol_now();
214
+		$now = dol_now();
215 215
 
216
-		$numFinal=get_next_value($db,$mask,'product',$field,$where,'',$now);
216
+		$numFinal = get_next_value($db, $mask, 'product', $field, $where, '', $now);
217 217
 
218 218
 		return  $numFinal;
219 219
 	}
@@ -231,10 +231,10 @@  discard block
 block discarded – undo
231 231
 		global $conf;
232 232
 
233 233
 		$mask = $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
234
-		if (preg_match('/\{pre\}/i',$mask)) return 1;
234
+		if (preg_match('/\{pre\}/i', $mask)) return 1;
235 235
 
236 236
 		$mask = $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
237
-		if (preg_match('/\{pre\}/i',$mask)) return 1;
237
+		if (preg_match('/\{pre\}/i', $mask)) return 1;
238 238
 
239 239
 		return 0;
240 240
 	}
@@ -258,32 +258,32 @@  discard block
 block discarded – undo
258 258
 	{
259 259
 		global $conf;
260 260
 
261
-		require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
261
+		require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
262 262
 
263
-		$result=0;
263
+		$result = 0;
264 264
 		$code = strtoupper(trim($code));
265 265
 
266 266
 		if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))
267 267
 		{
268
-			$result=0;
268
+			$result = 0;
269 269
 		}
270
-		else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) )
270
+		else if (empty($code) && (!$this->code_null || !empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)))
271 271
 		{
272
-			$result=-2;
272
+			$result = -2;
273 273
 		}
274 274
 		else
275 275
 		{
276 276
 			// Get Mask value
277 277
 			$mask = '';
278
-			if ($type==0) $mask = empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT)?'':$conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
279
-			if ($type==1) $mask = empty($conf->global->PRODUCT_ELEPHANT_MASK_SERVICE)?'':$conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
280
-			if (! $mask)
278
+			if ($type == 0) $mask = empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT) ? '' : $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
279
+			if ($type == 1) $mask = empty($conf->global->PRODUCT_ELEPHANT_MASK_SERVICE) ? '' : $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
280
+			if (!$mask)
281 281
 			{
282
-				$this->error='NotConfigured';
282
+				$this->error = 'NotConfigured';
283 283
 				return -5;
284 284
 			}
285 285
 
286
-			$result=check_value($mask,$code);
286
+			$result = check_value($mask, $code);
287 287
 			if (is_string($result))
288 288
 			{
289 289
 				$this->error = $result;
@@ -309,10 +309,10 @@  discard block
 block discarded – undo
309 309
 	{
310 310
         // phpcs:enable
311 311
 		$sql = "SELECT ref FROM ".MAIN_DB_PREFIX."product";
312
-		$sql.= " WHERE ref = '".$code."'";
313
-		if ($product->id > 0) $sql.= " AND rowid <> ".$product->id;
312
+		$sql .= " WHERE ref = '".$code."'";
313
+		if ($product->id > 0) $sql .= " AND rowid <> ".$product->id;
314 314
 
315
-		$resql=$db->query($sql);
315
+		$resql = $db->query($sql);
316 316
 		if ($resql)
317 317
 		{
318 318
 			if ($db->num_rows($resql) == 0)
Please login to merge, or discard this patch.
Braces   +33 added lines, -22 removed lines patch added patch discarded remove patch
@@ -167,8 +167,12 @@  discard block
 block discarded – undo
167 167
 			}
168 168
 		}
169 169
 
170
-		if ($type == 0) return $exampleproduct;
171
-		if ($type == 1) return $exampleservice;
170
+		if ($type == 0) {
171
+		    return $exampleproduct;
172
+		}
173
+		if ($type == 1) {
174
+		    return $exampleservice;
175
+		}
172 176
 		return $exampleproduct.'<br>'.$exampleservice;
173 177
 	}
174 178
 
@@ -187,10 +191,11 @@  discard block
 block discarded – undo
187 191
 
188 192
 		// Get Mask value
189 193
 		$mask = '';
190
-		if ($type == 0 && ! empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT))
191
-			$mask = $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
192
-		else if ($type == 1 && ! empty($conf->global->PRODUCT_ELEPHANT_MASK_SERVICE))
193
-			$mask = $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
194
+		if ($type == 0 && ! empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT)) {
195
+					$mask = $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
196
+		} else if ($type == 1 && ! empty($conf->global->PRODUCT_ELEPHANT_MASK_SERVICE)) {
197
+					$mask = $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
198
+		}
194 199
 
195 200
 		if (empty($mask))
196 201
 		{
@@ -203,13 +208,13 @@  discard block
 block discarded – undo
203 208
 		{
204 209
 			$field = 'ref';
205 210
 			//$where = ' AND client in (1,2)';
206
-		}
207
-		else if ($type == 1)
211
+		} else if ($type == 1)
208 212
 		{
209 213
 			$field = 'ref';
210 214
 			//$where = ' AND fournisseur = 1';
215
+		} else {
216
+		    return -1;
211 217
 		}
212
-		else return -1;
213 218
 
214 219
 		$now=dol_now();
215 220
 
@@ -231,10 +236,14 @@  discard block
 block discarded – undo
231 236
 		global $conf;
232 237
 
233 238
 		$mask = $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
234
-		if (preg_match('/\{pre\}/i',$mask)) return 1;
239
+		if (preg_match('/\{pre\}/i',$mask)) {
240
+		    return 1;
241
+		}
235 242
 
236 243
 		$mask = $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
237
-		if (preg_match('/\{pre\}/i',$mask)) return 1;
244
+		if (preg_match('/\{pre\}/i',$mask)) {
245
+		    return 1;
246
+		}
238 247
 
239 248
 		return 0;
240 249
 	}
@@ -266,17 +275,19 @@  discard block
 block discarded – undo
266 275
 		if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))
267 276
 		{
268 277
 			$result=0;
269
-		}
270
-		else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) )
278
+		} else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) )
271 279
 		{
272 280
 			$result=-2;
273
-		}
274
-		else
281
+		} else
275 282
 		{
276 283
 			// Get Mask value
277 284
 			$mask = '';
278
-			if ($type==0) $mask = empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT)?'':$conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
279
-			if ($type==1) $mask = empty($conf->global->PRODUCT_ELEPHANT_MASK_SERVICE)?'':$conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
285
+			if ($type==0) {
286
+			    $mask = empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT)?'':$conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
287
+			}
288
+			if ($type==1) {
289
+			    $mask = empty($conf->global->PRODUCT_ELEPHANT_MASK_SERVICE)?'':$conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
290
+			}
280 291
 			if (! $mask)
281 292
 			{
282 293
 				$this->error='NotConfigured';
@@ -310,7 +321,9 @@  discard block
 block discarded – undo
310 321
         // phpcs:enable
311 322
 		$sql = "SELECT ref FROM ".MAIN_DB_PREFIX."product";
312 323
 		$sql.= " WHERE ref = '".$code."'";
313
-		if ($product->id > 0) $sql.= " AND rowid <> ".$product->id;
324
+		if ($product->id > 0) {
325
+		    $sql.= " AND rowid <> ".$product->id;
326
+		}
314 327
 
315 328
 		$resql=$db->query($sql);
316 329
 		if ($resql)
@@ -318,13 +331,11 @@  discard block
 block discarded – undo
318 331
 			if ($db->num_rows($resql) == 0)
319 332
 			{
320 333
 				return 0;
321
-			}
322
-			else
334
+			} else
323 335
 			{
324 336
 				return -1;
325 337
 			}
326
-		}
327
-		else
338
+		} else
328 339
 		{
329 340
 			return -2;
330 341
 		}
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/product/mod_codeproduct_leopard.php 3 patches
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -32,112 +32,112 @@
 block discarded – undo
32 32
  */
33 33
 class mod_codeproduct_leopard extends ModeleProductCode
34 34
 {
35
-	/*
35
+    /*
36 36
 	 * Attention ce module est utilise par defaut si aucun module n'a
37 37
 	 * ete definit dans la configuration
38 38
 	 *
39 39
 	 * Le fonctionnement de celui-ci doit donc rester le plus ouvert possible
40 40
 	 */
41 41
 
42
-	/**
43
-	 * @var string Nom du modele
44
-	 * @deprecated
45
-	 * @see name
46
-	 */
47
-	public $nom='Leopard';
42
+    /**
43
+     * @var string Nom du modele
44
+     * @deprecated
45
+     * @see name
46
+     */
47
+    public $nom='Leopard';
48 48
 
49
-	/**
50
-	 * @var string model name
51
-	 */
52
-	public $name='Leopard';
49
+    /**
50
+     * @var string model name
51
+     */
52
+    public $name='Leopard';
53 53
 
54
-	public $code_modifiable;				// Code modifiable
54
+    public $code_modifiable;				// Code modifiable
55 55
 
56
-	public $code_modifiable_invalide;		// Code modifiable si il est invalide
56
+    public $code_modifiable_invalide;		// Code modifiable si il est invalide
57 57
 
58
-	public $code_modifiable_null;			// Code modifiables si il est null
58
+    public $code_modifiable_null;			// Code modifiables si il est null
59 59
 
60
-	public $code_null;						// Code facultatif
60
+    public $code_null;						// Code facultatif
61 61
 
62
-	/**
62
+    /**
63 63
      * Dolibarr version of the loaded document
64 64
      * @public string
65 65
      */
66
-	public $version = 'dolibarr';    		// 'development', 'experimental', 'dolibarr'
67
-
68
-	public $code_auto; 	                // Numerotation automatique
69
-
66
+    public $version = 'dolibarr';    		// 'development', 'experimental', 'dolibarr'
70 67
 
71
-	/**
72
-	 *	Constructor
73
-	 */
74
-	function __construct()
75
-	{
76
-		$this->code_null = 1;
77
-		$this->code_modifiable = 1;
78
-		$this->code_modifiable_invalide = 1;
79
-		$this->code_modifiable_null = 1;
80
-		$this->code_auto = 0;
81
-	}
82
-
83
-
84
-	/**		Return description of module
85
-	 *
86
-	 * 		@param	Translate	$langs	Object langs
87
-	 * 		@return string      		Description of module
88
-	 */
89
-	function info($langs)
90
-	{
91
-		$langs->load("companies");
92
-		return $langs->trans("LeopardNumRefModelDesc");
93
-	}
68
+    public $code_auto; 	                // Numerotation automatique
94 69
 
95 70
 
96
-	/**
97
-	 * Return an example of result returned by getNextValue
98
-	 *
99
-	 * @param	product		$objproduct		Object product
100
-	 * @param	int			$type		Type of third party (1:customer, 2:supplier, -1:autodetect)
101
-	 * @return	string					Return next value
102
-	 */
103
-	function getNextValue($objproduct=0,$type=-1)
104
-	{
105
-		global $langs;
106
-		return '';
107
-	}
108
-
109
-
110
-	/**
111
-	 * 	Check validity of code according to its rules
112
-	 *
113
-	 *	@param	DoliDB		$db		Database handler
114
-	 *	@param	string		$code	Code to check/correct
115
-	 *	@param	Product		$product	Object product
116
-	 *  @param  int		  	$type   0 = product , 1 = service
117
-	 *  @return int					0 if OK
118
-	 * 								-1 ErrorBadProductCodeSyntax
119
-	 * 								-2 ErrorProductCodeRequired
120
-	 * 								-3 ErrorProductCodeAlreadyUsed
121
-	 * 								-4 ErrorPrefixRequired
122
-	 */
123
-	function verif($db, &$code, $product, $type)
124
-	{
125
-		global $conf;
126
-
127
-		$result=0;
128
-		$code = strtoupper(trim($code));
129
-
130
-		if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))
131
-		{
132
-			$result=0;
133
-		}
134
-		else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) )
135
-		{
136
-			$result=-2;
137
-		}
138
-
139
-		dol_syslog("mod_codeproduct_leopard::verif type=".$type." result=".$result);
140
-		return $result;
141
-	}
71
+    /**
72
+     *	Constructor
73
+     */
74
+    function __construct()
75
+    {
76
+        $this->code_null = 1;
77
+        $this->code_modifiable = 1;
78
+        $this->code_modifiable_invalide = 1;
79
+        $this->code_modifiable_null = 1;
80
+        $this->code_auto = 0;
81
+    }
82
+
83
+
84
+    /**		Return description of module
85
+     *
86
+     * 		@param	Translate	$langs	Object langs
87
+     * 		@return string      		Description of module
88
+     */
89
+    function info($langs)
90
+    {
91
+        $langs->load("companies");
92
+        return $langs->trans("LeopardNumRefModelDesc");
93
+    }
94
+
95
+
96
+    /**
97
+     * Return an example of result returned by getNextValue
98
+     *
99
+     * @param	product		$objproduct		Object product
100
+     * @param	int			$type		Type of third party (1:customer, 2:supplier, -1:autodetect)
101
+     * @return	string					Return next value
102
+     */
103
+    function getNextValue($objproduct=0,$type=-1)
104
+    {
105
+        global $langs;
106
+        return '';
107
+    }
108
+
109
+
110
+    /**
111
+     * 	Check validity of code according to its rules
112
+     *
113
+     *	@param	DoliDB		$db		Database handler
114
+     *	@param	string		$code	Code to check/correct
115
+     *	@param	Product		$product	Object product
116
+     *  @param  int		  	$type   0 = product , 1 = service
117
+     *  @return int					0 if OK
118
+     * 								-1 ErrorBadProductCodeSyntax
119
+     * 								-2 ErrorProductCodeRequired
120
+     * 								-3 ErrorProductCodeAlreadyUsed
121
+     * 								-4 ErrorPrefixRequired
122
+     */
123
+    function verif($db, &$code, $product, $type)
124
+    {
125
+        global $conf;
126
+
127
+        $result=0;
128
+        $code = strtoupper(trim($code));
129
+
130
+        if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))
131
+        {
132
+            $result=0;
133
+        }
134
+        else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) )
135
+        {
136
+            $result=-2;
137
+        }
138
+
139
+        dol_syslog("mod_codeproduct_leopard::verif type=".$type." result=".$result);
140
+        return $result;
141
+    }
142 142
 }
143 143
 
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -44,28 +44,28 @@  discard block
 block discarded – undo
44 44
 	 * @deprecated
45 45
 	 * @see name
46 46
 	 */
47
-	public $nom='Leopard';
47
+	public $nom = 'Leopard';
48 48
 
49 49
 	/**
50 50
 	 * @var string model name
51 51
 	 */
52
-	public $name='Leopard';
52
+	public $name = 'Leopard';
53 53
 
54
-	public $code_modifiable;				// Code modifiable
54
+	public $code_modifiable; // Code modifiable
55 55
 
56
-	public $code_modifiable_invalide;		// Code modifiable si il est invalide
56
+	public $code_modifiable_invalide; // Code modifiable si il est invalide
57 57
 
58
-	public $code_modifiable_null;			// Code modifiables si il est null
58
+	public $code_modifiable_null; // Code modifiables si il est null
59 59
 
60
-	public $code_null;						// Code facultatif
60
+	public $code_null; // Code facultatif
61 61
 
62 62
 	/**
63 63
      * Dolibarr version of the loaded document
64 64
      * @public string
65 65
      */
66
-	public $version = 'dolibarr';    		// 'development', 'experimental', 'dolibarr'
66
+	public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
67 67
 
68
-	public $code_auto; 	                // Numerotation automatique
68
+	public $code_auto; // Numerotation automatique
69 69
 
70 70
 
71 71
 	/**
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	 * @param	int			$type		Type of third party (1:customer, 2:supplier, -1:autodetect)
101 101
 	 * @return	string					Return next value
102 102
 	 */
103
-	function getNextValue($objproduct=0,$type=-1)
103
+	function getNextValue($objproduct = 0, $type = -1)
104 104
 	{
105 105
 		global $langs;
106 106
 		return '';
@@ -124,16 +124,16 @@  discard block
 block discarded – undo
124 124
 	{
125 125
 		global $conf;
126 126
 
127
-		$result=0;
127
+		$result = 0;
128 128
 		$code = strtoupper(trim($code));
129 129
 
130 130
 		if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))
131 131
 		{
132
-			$result=0;
132
+			$result = 0;
133 133
 		}
134
-		else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) )
134
+		else if (empty($code) && (!$this->code_null || !empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)))
135 135
 		{
136
-			$result=-2;
136
+			$result = -2;
137 137
 		}
138 138
 
139 139
 		dol_syslog("mod_codeproduct_leopard::verif type=".$type." result=".$result);
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -129,8 +129,7 @@
 block discarded – undo
129 129
 		if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))
130 130
 		{
131 131
 			$result=0;
132
-		}
133
-		else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) )
132
+		} else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) )
134 133
 		{
135 134
 			$result=-2;
136 135
 		}
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/product/modules_product.class.php 3 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -26,17 +26,17 @@  discard block
 block discarded – undo
26 26
  *  \brief      File with parent class for generating products to PDF and File of class to manage product numbering
27 27
  */
28 28
 
29
- require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
29
+    require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
30 30
 
31 31
 /**
32 32
  *	Parent class to manage intervention document templates
33 33
  */
34 34
 abstract class ModelePDFProduct extends CommonDocGenerator
35 35
 {
36
-	/**
37
-	 * @var string Error code (or message)
38
-	 */
39
-	public $error='';
36
+    /**
37
+     * @var string Error code (or message)
38
+     */
39
+    public $error='';
40 40
 
41 41
 
42 42
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -47,26 +47,26 @@  discard block
 block discarded – undo
47 47
      *  @param  integer	$maxfilenamelength  Max length of value to show
48 48
      *  @return	array						List of templates
49 49
      */
50
-	static function liste_modeles($db,$maxfilenamelength=0)
51
-	{
50
+    static function liste_modeles($db,$maxfilenamelength=0)
51
+    {
52 52
         // phpcs:enable
53
-		global $conf;
53
+        global $conf;
54 54
 
55
-		$type='product';
56
-		$liste=array();
55
+        $type='product';
56
+        $liste=array();
57 57
 
58
-		include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
59
-		$liste=getListOfModels($db,$type,$maxfilenamelength);
60
-		return $liste;
61
-	}
58
+        include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
59
+        $liste=getListOfModels($db,$type,$maxfilenamelength);
60
+        return $liste;
61
+    }
62 62
 }
63 63
 
64 64
 abstract class ModeleProductCode
65 65
 {
66 66
     /**
67
-	 * @var string Error code (or message)
68
-	 */
69
-	public $error='';
67
+     * @var string Error code (or message)
68
+     */
69
+    public $error='';
70 70
 
71 71
     /**     Renvoi la description par defaut du modele de numerotation
72 72
      *
@@ -243,10 +243,10 @@  discard block
 block discarded – undo
243 243
 
244 244
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
245 245
     /**
246
-	 *   Check if mask/numbering use prefix
247
-	 *
248
-	 *   @return	int		0=no, 1=yes
249
-	 */
246
+     *   Check if mask/numbering use prefix
247
+     *
248
+     *   @return	int		0=no, 1=yes
249
+     */
250 250
     function verif_prefixIsUsed()
251 251
     {
252 252
         // phpcs:enable
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	/**
37 37
 	 * @var string Error code (or message)
38 38
 	 */
39
-	public $error='';
39
+	public $error = '';
40 40
 
41 41
 
42 42
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -47,16 +47,16 @@  discard block
 block discarded – undo
47 47
      *  @param  integer	$maxfilenamelength  Max length of value to show
48 48
      *  @return	array						List of templates
49 49
      */
50
-	static function liste_modeles($db,$maxfilenamelength=0)
50
+	static function liste_modeles($db, $maxfilenamelength = 0)
51 51
 	{
52 52
         // phpcs:enable
53 53
 		global $conf;
54 54
 
55
-		$type='product';
56
-		$liste=array();
55
+		$type = 'product';
56
+		$liste = array();
57 57
 
58 58
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
59
-		$liste=getListOfModels($db,$type,$maxfilenamelength);
59
+		$liste = getListOfModels($db, $type, $maxfilenamelength);
60 60
 		return $liste;
61 61
 	}
62 62
 }
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
     /**
67 67
 	 * @var string Error code (or message)
68 68
 	 */
69
-	public $error='';
69
+	public $error = '';
70 70
 
71 71
     /**     Renvoi la description par defaut du modele de numerotation
72 72
      *
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      */
87 87
     function getNom($langs)
88 88
     {
89
-        return empty($this->name)?$this->nom:$this->name;
89
+        return empty($this->name) ? $this->nom : $this->name;
90 90
     }
91 91
 
92 92
 
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
      *	@param	int			$type		Type
119 119
      *  @return string      			Value
120 120
      */
121
-    function getNextValue($objproduct=0,$type=-1)
121
+    function getNextValue($objproduct = 0, $type = -1)
122 122
     {
123 123
         global $langs;
124 124
         return $langs->trans("Function_getNextValue_InModuleNotWorking");
@@ -149,11 +149,11 @@  discard block
 block discarded – undo
149 149
      *  @param  integer	$maxfilenamelength  Max length of value to show
150 150
      *  @return	array						List of numbers
151 151
      */
152
-    static function liste_modeles($db,$maxfilenamelength=0)
152
+    static function liste_modeles($db, $maxfilenamelength = 0)
153 153
     {
154 154
         // phpcs:enable
155
-        $liste=array();
156
-        $sql ="";
155
+        $liste = array();
156
+        $sql = "";
157 157
 
158 158
         $resql = $db->query($sql);
159 159
         if ($resql)
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
             while ($i < $num)
164 164
             {
165 165
                 $row = $db->fetch_row($resql);
166
-                $liste[$row[0]]=$row[1];
166
+                $liste[$row[0]] = $row[1];
167 167
                 $i++;
168 168
             }
169 169
         }
@@ -182,61 +182,61 @@  discard block
 block discarded – undo
182 182
      *		@param	int			$type		-1=Nothing, 0=Customer, 1=Supplier
183 183
      *		@return	string					HTML translated description
184 184
      */
185
-    function getToolTip($langs,$product,$type)
185
+    function getToolTip($langs, $product, $type)
186 186
     {
187 187
         global $conf;
188 188
 
189 189
         $langs->load("admin");
190 190
 
191
-        $s='';
192
-        if ($type == -1) $s.=$langs->trans("Name").': <b>'.$this->getNom($langs).'</b><br>';
193
-        if ($type == -1) $s.=$langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
194
-        if ($type == 0)  $s.=$langs->trans("ProductCodeDesc").'<br>';
195
-        if ($type == 1)  $s.=$langs->trans("ServiceCodeDesc").'<br>';
196
-        if ($type != -1) $s.=$langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>';
197
-        $s.='<br>';
198
-        $s.='<u>'.$langs->trans("ThisIsModuleRules").':</u><br>';
191
+        $s = '';
192
+        if ($type == -1) $s .= $langs->trans("Name").': <b>'.$this->getNom($langs).'</b><br>';
193
+        if ($type == -1) $s .= $langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
194
+        if ($type == 0)  $s .= $langs->trans("ProductCodeDesc").'<br>';
195
+        if ($type == 1)  $s .= $langs->trans("ServiceCodeDesc").'<br>';
196
+        if ($type != -1) $s .= $langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>';
197
+        $s .= '<br>';
198
+        $s .= '<u>'.$langs->trans("ThisIsModuleRules").':</u><br>';
199 199
         if ($type == 0)
200 200
         {
201
-            $s.=$langs->trans("RequiredIfProduct").': ';
202
-            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>';
203
-            $s.=yn(!$this->code_null,1,2);
204
-            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')';
205
-            $s.='<br>';
201
+            $s .= $langs->trans("RequiredIfProduct").': ';
202
+            if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '<strike>';
203
+            $s .= yn(!$this->code_null, 1, 2);
204
+            if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
205
+            $s .= '<br>';
206 206
         }
207 207
         elseif ($type == 1)
208 208
         {
209
-            $s.=$langs->trans("RequiredIfService").': ';
210
-            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>';
211
-            $s.=yn(!$this->code_null,1,2);
212
-            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')';
213
-            $s.='<br>';
209
+            $s .= $langs->trans("RequiredIfService").': ';
210
+            if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '<strike>';
211
+            $s .= yn(!$this->code_null, 1, 2);
212
+            if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
213
+            $s .= '<br>';
214 214
         }
215 215
         elseif ($type == -1)
216 216
         {
217
-            $s.=$langs->trans("Required").': ';
218
-            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>';
219
-            $s.=yn(!$this->code_null,1,2);
220
-            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')';
221
-            $s.='<br>';
217
+            $s .= $langs->trans("Required").': ';
218
+            if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '<strike>';
219
+            $s .= yn(!$this->code_null, 1, 2);
220
+            if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
221
+            $s .= '<br>';
222 222
         }
223
-        $s.=$langs->trans("CanBeModifiedIfOk").': ';
224
-        $s.=yn($this->code_modifiable,1,2);
225
-        $s.='<br>';
226
-        $s.=$langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide,1,2).'<br>';
227
-        $s.=$langs->trans("AutomaticCode").': '.yn($this->code_auto,1,2).'<br>';
228
-        $s.='<br>';
223
+        $s .= $langs->trans("CanBeModifiedIfOk").': ';
224
+        $s .= yn($this->code_modifiable, 1, 2);
225
+        $s .= '<br>';
226
+        $s .= $langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide, 1, 2).'<br>';
227
+        $s .= $langs->trans("AutomaticCode").': '.yn($this->code_auto, 1, 2).'<br>';
228
+        $s .= '<br>';
229 229
         if ($type == 0 || $type == -1)
230 230
         {
231
-            $nextval=$this->getNextValue($product,0);
232
-            if (empty($nextval)) $nextval=$langs->trans("Undefined");
233
-            $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Product").')':'').': <b>'.$nextval.'</b><br>';
231
+            $nextval = $this->getNextValue($product, 0);
232
+            if (empty($nextval)) $nextval = $langs->trans("Undefined");
233
+            $s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Product").')' : '').': <b>'.$nextval.'</b><br>';
234 234
         }
235 235
         if ($type == 1 || $type == -1)
236 236
         {
237
-            $nextval=$this->getNextValue($product,1);
238
-            if (empty($nextval)) $nextval=$langs->trans("Undefined");
239
-            $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Service").')':'').': <b>'.$nextval.'</b>';
237
+            $nextval = $this->getNextValue($product, 1);
238
+            if (empty($nextval)) $nextval = $langs->trans("Undefined");
239
+            $s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Service").')' : '').': <b>'.$nextval.'</b>';
240 240
         }
241 241
         return $s;
242 242
     }
Please login to merge, or discard this patch.
Braces   +54 added lines, -23 removed lines patch added patch discarded remove patch
@@ -134,10 +134,18 @@  discard block
 block discarded – undo
134 134
         global $langs;
135 135
         $langs->load("admin");
136 136
 
137
-        if ($this->version == 'development') return $langs->trans("VersionDevelopment");
138
-        if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
139
-        if ($this->version == 'dolibarr') return DOL_VERSION;
140
-        if ($this->version) return $this->version;
137
+        if ($this->version == 'development') {
138
+            return $langs->trans("VersionDevelopment");
139
+        }
140
+        if ($this->version == 'experimental') {
141
+            return $langs->trans("VersionExperimental");
142
+        }
143
+        if ($this->version == 'dolibarr') {
144
+            return DOL_VERSION;
145
+        }
146
+        if ($this->version) {
147
+            return $this->version;
148
+        }
141 149
         return $langs->trans("NotAvailable");
142 150
     }
143 151
 
@@ -166,8 +174,7 @@  discard block
 block discarded – undo
166 174
                 $liste[$row[0]]=$row[1];
167 175
                 $i++;
168 176
             }
169
-        }
170
-        else
177
+        } else
171 178
         {
172 179
             return -1;
173 180
         }
@@ -189,35 +196,55 @@  discard block
 block discarded – undo
189 196
         $langs->load("admin");
190 197
 
191 198
         $s='';
192
-        if ($type == -1) $s.=$langs->trans("Name").': <b>'.$this->getNom($langs).'</b><br>';
193
-        if ($type == -1) $s.=$langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
194
-        if ($type == 0)  $s.=$langs->trans("ProductCodeDesc").'<br>';
195
-        if ($type == 1)  $s.=$langs->trans("ServiceCodeDesc").'<br>';
196
-        if ($type != -1) $s.=$langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>';
199
+        if ($type == -1) {
200
+            $s.=$langs->trans("Name").': <b>'.$this->getNom($langs).'</b><br>';
201
+        }
202
+        if ($type == -1) {
203
+            $s.=$langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
204
+        }
205
+        if ($type == 0) {
206
+            $s.=$langs->trans("ProductCodeDesc").'<br>';
207
+        }
208
+        if ($type == 1) {
209
+            $s.=$langs->trans("ServiceCodeDesc").'<br>';
210
+        }
211
+        if ($type != -1) {
212
+            $s.=$langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>';
213
+        }
197 214
         $s.='<br>';
198 215
         $s.='<u>'.$langs->trans("ThisIsModuleRules").':</u><br>';
199 216
         if ($type == 0)
200 217
         {
201 218
             $s.=$langs->trans("RequiredIfProduct").': ';
202
-            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>';
219
+            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) {
220
+                $s.='<strike>';
221
+            }
203 222
             $s.=yn(!$this->code_null,1,2);
204
-            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')';
223
+            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) {
224
+                $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')';
225
+            }
205 226
             $s.='<br>';
206
-        }
207
-        elseif ($type == 1)
227
+        } elseif ($type == 1)
208 228
         {
209 229
             $s.=$langs->trans("RequiredIfService").': ';
210
-            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>';
230
+            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) {
231
+                $s.='<strike>';
232
+            }
211 233
             $s.=yn(!$this->code_null,1,2);
212
-            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')';
234
+            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) {
235
+                $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')';
236
+            }
213 237
             $s.='<br>';
214
-        }
215
-        elseif ($type == -1)
238
+        } elseif ($type == -1)
216 239
         {
217 240
             $s.=$langs->trans("Required").': ';
218
-            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>';
241
+            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) {
242
+                $s.='<strike>';
243
+            }
219 244
             $s.=yn(!$this->code_null,1,2);
220
-            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')';
245
+            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) {
246
+                $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')';
247
+            }
221 248
             $s.='<br>';
222 249
         }
223 250
         $s.=$langs->trans("CanBeModifiedIfOk").': ';
@@ -229,13 +256,17 @@  discard block
 block discarded – undo
229 256
         if ($type == 0 || $type == -1)
230 257
         {
231 258
             $nextval=$this->getNextValue($product,0);
232
-            if (empty($nextval)) $nextval=$langs->trans("Undefined");
259
+            if (empty($nextval)) {
260
+                $nextval=$langs->trans("Undefined");
261
+            }
233 262
             $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Product").')':'').': <b>'.$nextval.'</b><br>';
234 263
         }
235 264
         if ($type == 1 || $type == -1)
236 265
         {
237 266
             $nextval=$this->getNextValue($product,1);
238
-            if (empty($nextval)) $nextval=$langs->trans("Undefined");
267
+            if (empty($nextval)) {
268
+                $nextval=$langs->trans("Undefined");
269
+            }
239 270
             $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Service").')':'').': <b>'.$nextval.'</b>';
240 271
         }
241 272
         return $s;
Please login to merge, or discard this patch.