Passed
Push — master ( fa5a21...043752 )
by Alxarafe
27:01
created
dolibarr/htdocs/expedition/class/expeditionbatch.class.php 1 patch
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
 	/**
32 32
 	 * @var string ID to identify managed object
33 33
 	 */
34
-	public $element='expeditionlignebatch';
34
+	public $element = 'expeditionlignebatch';
35 35
 
36
-	private static $_table_element='expeditiondet_batch';		//!< Name of table without prefix where object is stored
36
+	private static $_table_element = 'expeditiondet_batch'; //!< Name of table without prefix where object is stored
37 37
 
38 38
 	var $sellby;
39 39
 	var $eatby;
@@ -63,18 +63,18 @@  discard block
 block discarded – undo
63 63
 	function fetchFromStock($id_stockdluo)
64 64
 	{
65 65
 		$sql = "SELECT";
66
-		$sql.= " pb.batch,";
67
-		$sql.= " pl.sellby,";
68
-		$sql.= " pl.eatby,";
69
-		$sql.= " ps.fk_entrepot";
66
+		$sql .= " pb.batch,";
67
+		$sql .= " pl.sellby,";
68
+		$sql .= " pl.eatby,";
69
+		$sql .= " ps.fk_entrepot";
70 70
 
71
-		$sql.= " FROM ".MAIN_DB_PREFIX."product_batch as pb";
72
-		$sql.= " JOIN ".MAIN_DB_PREFIX."product_stock as ps on pb.fk_product_stock=ps.rowid";
73
-		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."product_lot as pl on pl.batch = pb.batch AND pl.fk_product = ps.fk_product";
74
-		$sql.= " WHERE pb.rowid = ".(int) $id_stockdluo;
71
+		$sql .= " FROM ".MAIN_DB_PREFIX."product_batch as pb";
72
+		$sql .= " JOIN ".MAIN_DB_PREFIX."product_stock as ps on pb.fk_product_stock=ps.rowid";
73
+		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."product_lot as pl on pl.batch = pb.batch AND pl.fk_product = ps.fk_product";
74
+		$sql .= " WHERE pb.rowid = ".(int) $id_stockdluo;
75 75
 
76 76
 		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
77
-		$resql=$this->db->query($sql);
77
+		$resql = $this->db->query($sql);
78 78
 		if ($resql)
79 79
 		{
80 80
 			if ($this->db->num_rows($resql))
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
 				$this->sellby = $this->db->jdate($obj->sellby);
85 85
 				$this->eatby = $this->db->jdate($obj->eatby);
86 86
 				$this->batch = $obj->batch;
87
-				$this->entrepot_id= $obj->fk_entrepot;
88
-				$this->fk_origin_stock=(int) $id_stockdluo;
87
+				$this->entrepot_id = $obj->fk_entrepot;
88
+				$this->fk_origin_stock = (int) $id_stockdluo;
89 89
 			}
90 90
 			$this->db->free($resql);
91 91
 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 		}
94 94
 		else
95 95
 		{
96
-			$this->error="Error ".$this->db->lasterror();
96
+			$this->error = "Error ".$this->db->lasterror();
97 97
 			return -1;
98 98
 		}
99 99
 	}
@@ -111,40 +111,40 @@  discard block
 block discarded – undo
111 111
 		$id_line_expdet = (int) $id_line_expdet;
112 112
 
113 113
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX.self::$_table_element." (";
114
-		$sql.= "fk_expeditiondet";
115
-		$sql.= ", sellby";
116
-		$sql.= ", eatby";
117
-		$sql.= ", batch";
118
-		$sql.= ", qty";
119
-		$sql.= ", fk_origin_stock";
120
-		$sql.= ") VALUES (";
121
-		$sql.= $id_line_expdet.",";
122
-		$sql.= " ".(! isset($this->sellby) || dol_strlen($this->sellby)==0?'NULL':("'".$this->db->idate($this->sellby))."'").",";
123
-		$sql.= " ".(! isset($this->eatby) || dol_strlen($this->eatby)==0?'NULL':("'".$this->db->idate($this->eatby))."'").",";
124
-		$sql.= " ".(! isset($this->batch)?'NULL':("'".$this->db->escape($this->batch)."'")).",";
125
-		$sql.= " ".(! isset($this->qty)?((! isset($this->dluo_qty))?'NULL':$this->dluo_qty):$this->qty).","; // dluo_qty deprecated, use qty
126
-		$sql.= " ".(! isset($this->fk_origin_stock)?'NULL':$this->fk_origin_stock);
127
-		$sql.= ")";
114
+		$sql .= "fk_expeditiondet";
115
+		$sql .= ", sellby";
116
+		$sql .= ", eatby";
117
+		$sql .= ", batch";
118
+		$sql .= ", qty";
119
+		$sql .= ", fk_origin_stock";
120
+		$sql .= ") VALUES (";
121
+		$sql .= $id_line_expdet.",";
122
+		$sql .= " ".(!isset($this->sellby) || dol_strlen($this->sellby) == 0 ? 'NULL' : ("'".$this->db->idate($this->sellby))."'").",";
123
+		$sql .= " ".(!isset($this->eatby) || dol_strlen($this->eatby) == 0 ? 'NULL' : ("'".$this->db->idate($this->eatby))."'").",";
124
+		$sql .= " ".(!isset($this->batch) ? 'NULL' : ("'".$this->db->escape($this->batch)."'")).",";
125
+		$sql .= " ".(!isset($this->qty) ? ((!isset($this->dluo_qty)) ? 'NULL' : $this->dluo_qty) : $this->qty).","; // dluo_qty deprecated, use qty
126
+		$sql .= " ".(!isset($this->fk_origin_stock) ? 'NULL' : $this->fk_origin_stock);
127
+		$sql .= ")";
128 128
 
129 129
 		dol_syslog(__METHOD__, LOG_DEBUG);
130
-		$resql=$this->db->query($sql);
131
-		if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
130
+		$resql = $this->db->query($sql);
131
+		if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
132 132
 
133
-		if (! $error)
133
+		if (!$error)
134 134
 		{
135 135
             $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.self::$_table_element);
136
-			$this->fk_expeditiondet=$id_line_expdet;
136
+			$this->fk_expeditiondet = $id_line_expdet;
137 137
 			return $this->id;
138 138
 		}
139 139
 		else
140 140
 		{
141
-			foreach($this->errors as $errmsg)
141
+			foreach ($this->errors as $errmsg)
142 142
 			{
143 143
 	            dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
144
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
144
+	            $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
145 145
 			}
146 146
 			$this->db->rollback();
147
-			return -1*$error;
147
+			return -1 * $error;
148 148
 		}
149 149
 	}
150 150
 
@@ -155,12 +155,12 @@  discard block
 block discarded – undo
155 155
 	 * @param	int		$id_expedition	rowid of shipment
156 156
 	 * @return 	int						-1 if KO, 1 if OK
157 157
 	 */
158
-	static function deletefromexp($db,$id_expedition)
158
+	static function deletefromexp($db, $id_expedition)
159 159
 	{
160 160
 		$id_expedition = (int) $id_expedition;
161 161
 
162
-		$sql="DELETE FROM ".MAIN_DB_PREFIX.self::$_table_element;
163
-		$sql.=" WHERE fk_expeditiondet in (SELECT rowid FROM ".MAIN_DB_PREFIX."expeditiondet WHERE fk_expedition=".$id_expedition.")";
162
+		$sql = "DELETE FROM ".MAIN_DB_PREFIX.self::$_table_element;
163
+		$sql .= " WHERE fk_expeditiondet in (SELECT rowid FROM ".MAIN_DB_PREFIX."expeditiondet WHERE fk_expedition=".$id_expedition.")";
164 164
 
165 165
 		dol_syslog(__METHOD__, LOG_DEBUG);
166 166
 		if ($db->query($sql))
@@ -181,38 +181,38 @@  discard block
 block discarded – undo
181 181
 	 * @param	int			$fk_product			If provided, load also detailed information of lot
182 182
 	 * @return	int|array						-1 if KO, array of ExpeditionLineBatch if OK
183 183
 	 */
184
-	static function fetchAll($db, $id_line_expdet, $fk_product=0)
184
+	static function fetchAll($db, $id_line_expdet, $fk_product = 0)
185 185
 	{
186
-		$sql="SELECT";
187
-		$sql.= " eb.rowid,";
188
-		$sql.= " eb.fk_expeditiondet,";
189
-		$sql.= " eb.sellby as oldsellby,";				// deprecated
190
-		$sql.= " eb.eatby as oldeatby,";				// deprecated
191
-		$sql.= " eb.batch,";
192
-		$sql.= " eb.qty,";
193
-		$sql.= " eb.fk_origin_stock";
186
+		$sql = "SELECT";
187
+		$sql .= " eb.rowid,";
188
+		$sql .= " eb.fk_expeditiondet,";
189
+		$sql .= " eb.sellby as oldsellby,"; // deprecated
190
+		$sql .= " eb.eatby as oldeatby,"; // deprecated
191
+		$sql .= " eb.batch,";
192
+		$sql .= " eb.qty,";
193
+		$sql .= " eb.fk_origin_stock";
194 194
 		if ($fk_product > 0)
195 195
 		{
196
-			$sql.= ", pl.sellby";
197
-			$sql.= ", pl.eatby";
196
+			$sql .= ", pl.sellby";
197
+			$sql .= ", pl.eatby";
198 198
 		}
199
-		$sql.= " FROM ".MAIN_DB_PREFIX.self::$_table_element." as eb";
199
+		$sql .= " FROM ".MAIN_DB_PREFIX.self::$_table_element." as eb";
200 200
 		if ($fk_product > 0)
201 201
 		{
202
-			$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON pl.batch = eb.batch AND pl.fk_product = ".$fk_product;
202
+			$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON pl.batch = eb.batch AND pl.fk_product = ".$fk_product;
203 203
 		}
204
-		$sql.= " WHERE fk_expeditiondet=".(int) $id_line_expdet;
204
+		$sql .= " WHERE fk_expeditiondet=".(int) $id_line_expdet;
205 205
 
206
-		dol_syslog(__METHOD__ ."", LOG_DEBUG);
207
-		$resql=$db->query($sql);
206
+		dol_syslog(__METHOD__."", LOG_DEBUG);
207
+		$resql = $db->query($sql);
208 208
 		if ($resql)
209 209
 		{
210
-			$num=$db->num_rows($resql);
211
-			$i=0;
210
+			$num = $db->num_rows($resql);
211
+			$i = 0;
212 212
 			$ret = array();
213
-			while ($i<$num)
213
+			while ($i < $num)
214 214
 			{
215
-				$tmp=new self($db);
215
+				$tmp = new self($db);
216 216
 
217 217
 				$obj = $db->fetch_object($resql);
218 218
 
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 				$tmp->dluo_qty = $obj->qty; // dluo_qty deprecated, use qty
226 226
 				$tmp->qty = $obj->qty;
227 227
 
228
-				$ret[]=$tmp;
228
+				$ret[] = $tmp;
229 229
 				$i++;
230 230
 			}
231 231
 			$db->free($resql);
Please login to merge, or discard this patch.
dolibarr/htdocs/expedition/class/expedition.class.php 1 patch
Spacing   +562 added lines, -562 removed lines patch added patch discarded remove patch
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
 
36 36
 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
37 37
 require_once DOL_DOCUMENT_ROOT."/core/class/commonobjectline.class.php";
38
-if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
39
-if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
40
-if (! empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';
38
+if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
39
+if (!empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
40
+if (!empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';
41 41
 
42 42
 
43 43
 /**
@@ -48,22 +48,22 @@  discard block
 block discarded – undo
48 48
 	/**
49 49
 	 * @var string ID to identify managed object
50 50
 	 */
51
-	public $element="shipping";
51
+	public $element = "shipping";
52 52
 
53 53
 	/**
54 54
 	 * @var int Field with ID of parent key if this field has a parent
55 55
 	 */
56
-	public $fk_element="fk_expedition";
56
+	public $fk_element = "fk_expedition";
57 57
 
58 58
 	/**
59 59
 	 * @var string Name of table without prefix where object is stored
60 60
 	 */
61
-	public $table_element="expedition";
61
+	public $table_element = "expedition";
62 62
 
63 63
 	/**
64 64
 	 * @var int    Name of subtable line
65 65
 	 */
66
-	public $table_element_line="expeditiondet";
66
+	public $table_element_line = "expeditiondet";
67 67
 
68 68
 	/**
69 69
 	 * 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	 * @var int warehouse id
95 95
 	 */
96 96
 	public $entrepot_id;
97
-	public $lines=array();
97
+	public $lines = array();
98 98
 
99 99
 	/**
100 100
 	 * @var string Tracking number
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 	// A denormalized value
124 124
 	public $trueSize;
125 125
 
126
-	public $date_delivery;		// Date delivery planed
126
+	public $date_delivery; // Date delivery planed
127 127
 
128 128
 	/**
129 129
 	 * @deprecated
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 	public $date_valid;
148 148
 
149 149
 	public $meths;
150
-	public $listmeths;			// List of carriers
150
+	public $listmeths; // List of carriers
151 151
 
152 152
     /**
153 153
 	 * Draft status
@@ -227,26 +227,26 @@  discard block
 block discarded – undo
227 227
 				$dir = dol_buildpath($reldir."core/modules/expedition/");
228 228
 
229 229
 				// Load file with numbering class (if found)
230
-				$mybool|=@include_once $dir.$file;
230
+				$mybool |= @include_once $dir.$file;
231 231
 			}
232 232
 
233
-			if (! $mybool)
233
+			if (!$mybool)
234 234
 			{
235
-				dol_print_error('',"Failed to include file ".$file);
235
+				dol_print_error('', "Failed to include file ".$file);
236 236
 				return '';
237 237
 			}
238 238
 
239 239
 			$obj = new $classname();
240 240
 			$numref = "";
241
-			$numref = $obj->getNextValue($soc,$this);
241
+			$numref = $obj->getNextValue($soc, $this);
242 242
 
243
-			if ( $numref != "")
243
+			if ($numref != "")
244 244
 			{
245 245
 				return $numref;
246 246
 			}
247 247
 			else
248 248
 			{
249
-				dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
249
+				dol_print_error($this->db, get_class($this)."::getNextNumRef ".$obj->error);
250 250
 				return "";
251 251
 			}
252 252
 		}
@@ -264,13 +264,13 @@  discard block
 block discarded – undo
264 264
 	 * 	@param		int		$notrigger	1=Does not execute triggers, 0= execute triggers
265 265
 	 *  @return int 				<0 si erreur, id expedition creee si ok
266 266
 	 */
267
-	function create($user, $notrigger=0)
267
+	function create($user, $notrigger = 0)
268 268
 	{
269 269
 		global $conf, $hookmanager;
270 270
 
271
-		$now=dol_now();
271
+		$now = dol_now();
272 272
 
273
-		require_once DOL_DOCUMENT_ROOT .'/product/stock/class/mouvementstock.class.php';
273
+		require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
274 274
 		$error = 0;
275 275
 
276 276
 		// Clean parameters
@@ -284,90 +284,90 @@  discard block
 block discarded – undo
284 284
 		$this->db->begin();
285 285
 
286 286
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."expedition (";
287
-		$sql.= "ref";
288
-		$sql.= ", entity";
289
-		$sql.= ", ref_customer";
290
-		$sql.= ", ref_int";
291
-		$sql.= ", date_creation";
292
-		$sql.= ", fk_user_author";
293
-		$sql.= ", date_expedition";
294
-		$sql.= ", date_delivery";
295
-		$sql.= ", fk_soc";
296
-		$sql.= ", fk_projet";
297
-		$sql.= ", fk_address";
298
-		$sql.= ", fk_shipping_method";
299
-		$sql.= ", tracking_number";
300
-		$sql.= ", weight";
301
-		$sql.= ", size";
302
-		$sql.= ", width";
303
-		$sql.= ", height";
304
-		$sql.= ", weight_units";
305
-		$sql.= ", size_units";
306
-		$sql.= ", note_private";
307
-		$sql.= ", note_public";
308
-		$sql.= ", model_pdf";
309
-		$sql.= ", fk_incoterms, location_incoterms";
310
-		$sql.= ") VALUES (";
311
-		$sql.= "'(PROV)'";
312
-		$sql.= ", ".$conf->entity;
313
-		$sql.= ", ".($this->ref_customer?"'".$this->db->escape($this->ref_customer)."'":"null");
314
-		$sql.= ", ".($this->ref_int?"'".$this->db->escape($this->ref_int)."'":"null");
315
-		$sql.= ", '".$this->db->idate($now)."'";
316
-		$sql.= ", ".$user->id;
317
-		$sql.= ", ".($this->date_expedition>0?"'".$this->db->idate($this->date_expedition)."'":"null");
318
-		$sql.= ", ".($this->date_delivery>0?"'".$this->db->idate($this->date_delivery)."'":"null");
319
-		$sql.= ", ".$this->socid;
320
-		$sql.= ", ".$this->fk_project;
321
-		$sql.= ", ".($this->fk_delivery_address>0?$this->fk_delivery_address:"null");
322
-		$sql.= ", ".($this->shipping_method_id>0?$this->shipping_method_id:"null");
323
-		$sql.= ", '".$this->db->escape($this->tracking_number)."'";
324
-		$sql.= ", ".$this->weight;
325
-		$sql.= ", ".$this->sizeS;	// TODO Should use this->trueDepth
326
-		$sql.= ", ".$this->sizeW;	// TODO Should use this->trueWidth
327
-		$sql.= ", ".$this->sizeH;	// TODO Should use this->trueHeight
328
-		$sql.= ", ".$this->weight_units;
329
-		$sql.= ", ".$this->size_units;
330
-		$sql.= ", ".(!empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null");
331
-		$sql.= ", ".(!empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null");
332
-		$sql.= ", ".(!empty($this->model_pdf)?"'".$this->db->escape($this->model_pdf)."'":"null");
333
-		$sql.= ", ".(int) $this->fk_incoterms;
334
-		$sql.= ", '".$this->db->escape($this->location_incoterms)."'";
335
-		$sql.= ")";
287
+		$sql .= "ref";
288
+		$sql .= ", entity";
289
+		$sql .= ", ref_customer";
290
+		$sql .= ", ref_int";
291
+		$sql .= ", date_creation";
292
+		$sql .= ", fk_user_author";
293
+		$sql .= ", date_expedition";
294
+		$sql .= ", date_delivery";
295
+		$sql .= ", fk_soc";
296
+		$sql .= ", fk_projet";
297
+		$sql .= ", fk_address";
298
+		$sql .= ", fk_shipping_method";
299
+		$sql .= ", tracking_number";
300
+		$sql .= ", weight";
301
+		$sql .= ", size";
302
+		$sql .= ", width";
303
+		$sql .= ", height";
304
+		$sql .= ", weight_units";
305
+		$sql .= ", size_units";
306
+		$sql .= ", note_private";
307
+		$sql .= ", note_public";
308
+		$sql .= ", model_pdf";
309
+		$sql .= ", fk_incoterms, location_incoterms";
310
+		$sql .= ") VALUES (";
311
+		$sql .= "'(PROV)'";
312
+		$sql .= ", ".$conf->entity;
313
+		$sql .= ", ".($this->ref_customer ? "'".$this->db->escape($this->ref_customer)."'" : "null");
314
+		$sql .= ", ".($this->ref_int ? "'".$this->db->escape($this->ref_int)."'" : "null");
315
+		$sql .= ", '".$this->db->idate($now)."'";
316
+		$sql .= ", ".$user->id;
317
+		$sql .= ", ".($this->date_expedition > 0 ? "'".$this->db->idate($this->date_expedition)."'" : "null");
318
+		$sql .= ", ".($this->date_delivery > 0 ? "'".$this->db->idate($this->date_delivery)."'" : "null");
319
+		$sql .= ", ".$this->socid;
320
+		$sql .= ", ".$this->fk_project;
321
+		$sql .= ", ".($this->fk_delivery_address > 0 ? $this->fk_delivery_address : "null");
322
+		$sql .= ", ".($this->shipping_method_id > 0 ? $this->shipping_method_id : "null");
323
+		$sql .= ", '".$this->db->escape($this->tracking_number)."'";
324
+		$sql .= ", ".$this->weight;
325
+		$sql .= ", ".$this->sizeS; // TODO Should use this->trueDepth
326
+		$sql .= ", ".$this->sizeW; // TODO Should use this->trueWidth
327
+		$sql .= ", ".$this->sizeH; // TODO Should use this->trueHeight
328
+		$sql .= ", ".$this->weight_units;
329
+		$sql .= ", ".$this->size_units;
330
+		$sql .= ", ".(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null");
331
+		$sql .= ", ".(!empty($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null");
332
+		$sql .= ", ".(!empty($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null");
333
+		$sql .= ", ".(int) $this->fk_incoterms;
334
+		$sql .= ", '".$this->db->escape($this->location_incoterms)."'";
335
+		$sql .= ")";
336 336
 
337 337
 		dol_syslog(get_class($this)."::create", LOG_DEBUG);
338
-		$resql=$this->db->query($sql);
338
+		$resql = $this->db->query($sql);
339 339
 		if ($resql)
340 340
 		{
341 341
 			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."expedition");
342 342
 
343 343
 			$sql = "UPDATE ".MAIN_DB_PREFIX."expedition";
344
-			$sql.= " SET ref = '(PROV".$this->id.")'";
345
-			$sql.= " WHERE rowid = ".$this->id;
344
+			$sql .= " SET ref = '(PROV".$this->id.")'";
345
+			$sql .= " WHERE rowid = ".$this->id;
346 346
 
347 347
 			dol_syslog(get_class($this)."::create", LOG_DEBUG);
348 348
 			if ($this->db->query($sql))
349 349
 			{
350 350
 				// Insertion des lignes
351
-				$num=count($this->lines);
351
+				$num = count($this->lines);
352 352
 				for ($i = 0; $i < $num; $i++)
353 353
 				{
354
-					if (! isset($this->lines[$i]->detail_batch))
354
+					if (!isset($this->lines[$i]->detail_batch))
355 355
 					{	// no batch management
356
-						if (! $this->create_line($this->lines[$i]->entrepot_id, $this->lines[$i]->origin_line_id, $this->lines[$i]->qty, $this->lines[$i]->array_options) > 0)
356
+						if (!$this->create_line($this->lines[$i]->entrepot_id, $this->lines[$i]->origin_line_id, $this->lines[$i]->qty, $this->lines[$i]->array_options) > 0)
357 357
 						{
358 358
 							$error++;
359 359
 						}
360 360
 					}
361 361
 					else
362 362
 					{	// with batch management
363
-						if (! $this->create_line_batch($this->lines[$i],$this->lines[$i]->array_options) > 0)
363
+						if (!$this->create_line_batch($this->lines[$i], $this->lines[$i]->array_options) > 0)
364 364
 						{
365 365
 							$error++;
366 366
 						}
367 367
 					}
368 368
 				}
369 369
 
370
-				if (! $error && $this->id && $this->origin_id)
370
+				if (!$error && $this->id && $this->origin_id)
371 371
 				{
372 372
 					$ret = $this->add_object_linked();
373 373
 					if (!$ret)
@@ -377,42 +377,42 @@  discard block
 block discarded – undo
377 377
 				}
378 378
 
379 379
 				// Actions on extra fields
380
-				if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))
380
+				if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))
381 381
 				{
382
-					$result=$this->insertExtraFields();
382
+					$result = $this->insertExtraFields();
383 383
 					if ($result < 0)
384 384
 					{
385 385
 						$error++;
386 386
 					}
387 387
 				}
388 388
 
389
-				if (! $error && ! $notrigger)
389
+				if (!$error && !$notrigger)
390 390
 				{
391 391
 					// Call trigger
392
-					$result=$this->call_trigger('SHIPPING_CREATE',$user);
392
+					$result = $this->call_trigger('SHIPPING_CREATE', $user);
393 393
 					if ($result < 0) { $error++; }
394 394
 					// End call triggers
395 395
 
396
-					if (! $error)
396
+					if (!$error)
397 397
 					{
398 398
 						$this->db->commit();
399 399
 						return $this->id;
400 400
 					}
401 401
 					else
402 402
 					{
403
-						foreach($this->errors as $errmsg)
403
+						foreach ($this->errors as $errmsg)
404 404
 						{
405 405
 							dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
406
-							$this->error.=($this->error?', '.$errmsg:$errmsg);
406
+							$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
407 407
 						}
408 408
 						$this->db->rollback();
409
-						return -1*$error;
409
+						return -1 * $error;
410 410
 					}
411 411
 				}
412 412
 				else
413 413
 				{
414 414
 					$error++;
415
-					$this->error=$this->db->lasterror()." - sql=$sql";
415
+					$this->error = $this->db->lasterror()." - sql=$sql";
416 416
 					$this->db->rollback();
417 417
 					return -3;
418 418
 				}
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
 			else
421 421
 			{
422 422
 				$error++;
423
-				$this->error=$this->db->lasterror()." - sql=$sql";
423
+				$this->error = $this->db->lasterror()." - sql=$sql";
424 424
 				$this->db->rollback();
425 425
 				return -2;
426 426
 			}
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 		else
429 429
 		{
430 430
 			$error++;
431
-			$this->error=$this->db->error()." - sql=$sql";
431
+			$this->error = $this->db->error()." - sql=$sql";
432 432
 			$this->db->rollback();
433 433
 			return -1;
434 434
 		}
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
 	 * @param	array	$array_options		extrafields array
445 445
 	 * @return	int							<0 if KO, line_id if OK
446 446
 	 */
447
-	function create_line($entrepot_id, $origin_line_id, $qty,$array_options=0)
447
+	function create_line($entrepot_id, $origin_line_id, $qty, $array_options = 0)
448 448
 	{
449 449
         //phpcs:enable
450 450
 		$expeditionline = new ExpeditionLigne($this->db);
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
 
457 457
 		if (($lineId = $expeditionline->insert()) < 0)
458 458
 		{
459
-			$this->errors[]=$expeditionline->error;
459
+			$this->errors[] = $expeditionline->error;
460 460
 		}
461 461
 		return $lineId;
462 462
 	}
@@ -470,13 +470,13 @@  discard block
 block discarded – undo
470 470
 	 * @param	array		$array_options		extrafields array
471 471
 	 * @return	int							<0 if KO, >0 if OK
472 472
 	 */
473
-	function create_line_batch($line_ext,$array_options=0)
473
+	function create_line_batch($line_ext, $array_options = 0)
474 474
 	{
475 475
         // phpcs:enable
476 476
 		$error = 0;
477 477
 		$stockLocationQty = array(); // associated array with batch qty in stock location
478 478
 
479
-		$tab=$line_ext->detail_batch;
479
+		$tab = $line_ext->detail_batch;
480 480
 		// create stockLocation Qty array
481 481
 		foreach ($tab as $detbatch)
482 482
 		{
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 		// create shipment lines
489 489
 		foreach ($stockLocationQty as $stockLocation => $qty)
490 490
 		{
491
-			if (($line_id = $this->create_line($stockLocation,$line_ext->origin_line_id,$qty,$array_options)) < 0)
491
+			if (($line_id = $this->create_line($stockLocation, $line_ext->origin_line_id, $qty, $array_options)) < 0)
492 492
 			{
493 493
 				$error++;
494 494
 			}
@@ -497,8 +497,8 @@  discard block
 block discarded – undo
497 497
 				// create shipment batch lines for stockLocation
498 498
 				foreach ($tab as $detbatch)
499 499
 				{
500
-					if ($detbatch->entrepot_id == $stockLocation){
501
-						if (! ($detbatch->create($line_id) >0))		// Create an expeditionlinebatch
500
+					if ($detbatch->entrepot_id == $stockLocation) {
501
+						if (!($detbatch->create($line_id) > 0))		// Create an expeditionlinebatch
502 502
 						{
503 503
 							$error++;
504 504
 						}
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
 			}
508 508
 		}
509 509
 
510
-		if (! $error) return 1;
510
+		if (!$error) return 1;
511 511
 		else return -1;
512 512
 	}
513 513
 
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
 	 * 	@param	string	$ref_int	Internal reference of other object
521 521
 	 *	@return int			        >0 if OK, 0 if not found, <0 if KO
522 522
 	 */
523
-	function fetch($id, $ref='', $ref_ext='', $ref_int='')
523
+	function fetch($id, $ref = '', $ref_ext = '', $ref_int = '')
524 524
 	{
525 525
 		global $conf;
526 526
 
@@ -528,23 +528,23 @@  discard block
 block discarded – undo
528 528
 		if (empty($id) && empty($ref) && empty($ref_ext) && empty($ref_int)) return -1;
529 529
 
530 530
 		$sql = "SELECT e.rowid, e.ref, e.fk_soc as socid, e.date_creation, e.ref_customer, e.ref_ext, e.ref_int, e.fk_user_author, e.fk_statut, e.fk_projet, e.billed";
531
-		$sql.= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
532
-		$sql.= ", e.date_expedition as date_expedition, e.model_pdf, e.fk_address, e.date_delivery";
533
-		$sql.= ", e.fk_shipping_method, e.tracking_number";
534
-		$sql.= ", e.note_private, e.note_public";
535
-		$sql.= ', e.fk_incoterms, e.location_incoterms';
536
-		$sql.= ', i.libelle as libelle_incoterms';
537
-		$sql.= ', s.libelle as shipping_method';
538
-		$sql.= ", el.fk_source as origin_id, el.sourcetype as origin";
539
-		$sql.= " FROM ".MAIN_DB_PREFIX."expedition as e";
540
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element)."'";
541
-		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON e.fk_incoterms = i.rowid';
542
-		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_shipment_mode as s ON e.fk_shipping_method = s.rowid';
543
-		$sql.= " WHERE e.entity IN (".getEntity('expedition').")";
544
-		if ($id)   	  $sql.= " AND e.rowid=".$id;
545
-		if ($ref)     $sql.= " AND e.ref='".$this->db->escape($ref)."'";
546
-		if ($ref_ext) $sql.= " AND e.ref_ext='".$this->db->escape($ref_ext)."'";
547
-		if ($ref_int) $sql.= " AND e.ref_int='".$this->db->escape($ref_int)."'";
531
+		$sql .= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
532
+		$sql .= ", e.date_expedition as date_expedition, e.model_pdf, e.fk_address, e.date_delivery";
533
+		$sql .= ", e.fk_shipping_method, e.tracking_number";
534
+		$sql .= ", e.note_private, e.note_public";
535
+		$sql .= ', e.fk_incoterms, e.location_incoterms';
536
+		$sql .= ', i.libelle as libelle_incoterms';
537
+		$sql .= ', s.libelle as shipping_method';
538
+		$sql .= ", el.fk_source as origin_id, el.sourcetype as origin";
539
+		$sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
540
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element)."'";
541
+		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON e.fk_incoterms = i.rowid';
542
+		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_shipment_mode as s ON e.fk_shipping_method = s.rowid';
543
+		$sql .= " WHERE e.entity IN (".getEntity('expedition').")";
544
+		if ($id)   	  $sql .= " AND e.rowid=".$id;
545
+		if ($ref)     $sql .= " AND e.ref='".$this->db->escape($ref)."'";
546
+		if ($ref_ext) $sql .= " AND e.ref_ext='".$this->db->escape($ref_ext)."'";
547
+		if ($ref_int) $sql .= " AND e.ref_int='".$this->db->escape($ref_int)."'";
548 548
 
549 549
 		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
550 550
 		$result = $this->db->query($sql);
@@ -557,25 +557,25 @@  discard block
 block discarded – undo
557 557
 				$this->id                   = $obj->rowid;
558 558
 				$this->ref                  = $obj->ref;
559 559
 				$this->socid                = $obj->socid;
560
-				$this->ref_customer	    = $obj->ref_customer;
560
+				$this->ref_customer = $obj->ref_customer;
561 561
 				$this->ref_ext		    = $obj->ref_ext;
562 562
 				$this->ref_int		    = $obj->ref_int;
563 563
 				$this->statut               = $obj->fk_statut;
564 564
 				$this->user_author_id       = $obj->fk_user_author;
565 565
 				$this->date_creation        = $this->db->jdate($obj->date_creation);
566
-				$this->date                 = $this->db->jdate($obj->date_expedition);	// TODO deprecated
567
-				$this->date_expedition      = $this->db->jdate($obj->date_expedition);	// TODO deprecated
568
-				$this->date_shipping        = $this->db->jdate($obj->date_expedition);	// Date real
569
-				$this->date_delivery        = $this->db->jdate($obj->date_delivery);	// Date planed
566
+				$this->date                 = $this->db->jdate($obj->date_expedition); // TODO deprecated
567
+				$this->date_expedition      = $this->db->jdate($obj->date_expedition); // TODO deprecated
568
+				$this->date_shipping        = $this->db->jdate($obj->date_expedition); // Date real
569
+				$this->date_delivery        = $this->db->jdate($obj->date_delivery); // Date planed
570 570
 				$this->fk_delivery_address  = $obj->fk_address;
571 571
 				$this->modelpdf             = $obj->model_pdf;
572 572
 				$this->shipping_method_id   = $obj->fk_shipping_method;
573
-				$this->shipping_method	    = $obj->shipping_method;
573
+				$this->shipping_method = $obj->shipping_method;
574 574
 				$this->tracking_number      = $obj->tracking_number;
575
-				$this->origin               = ($obj->origin?$obj->origin:'commande'); // For compatibility
575
+				$this->origin               = ($obj->origin ? $obj->origin : 'commande'); // For compatibility
576 576
 				$this->origin_id            = $obj->origin_id;
577 577
 				$this->billed               = $obj->billed;
578
-				$this->fk_project	    = $obj->fk_projet;
578
+				$this->fk_project = $obj->fk_projet;
579 579
 
580 580
 				$this->trueWeight           = $obj->weight;
581 581
 				$this->weight_units         = $obj->weight_units;
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
 				/*
610 610
 				 * Thirparty
611 611
 				 */
612
-				$result=$this->fetch_thirdparty();
612
+				$result = $this->fetch_thirdparty();
613 613
 
614 614
 				// Retreive extrafields
615 615
 				$this->fetch_optionals();
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
 				/*
618 618
 				 * Lines
619 619
 				 */
620
-				$result=$this->fetch_lines();
620
+				$result = $this->fetch_lines();
621 621
 				if ($result < 0)
622 622
 				{
623 623
 					return -3;
@@ -628,13 +628,13 @@  discard block
 block discarded – undo
628 628
 			else
629 629
 			{
630 630
 				dol_syslog(get_class($this).'::Fetch no expedition found', LOG_ERR);
631
-				$this->error='Delivery with id '.$id.' not found';
631
+				$this->error = 'Delivery with id '.$id.' not found';
632 632
 				return 0;
633 633
 			}
634 634
 		}
635 635
 		else
636 636
 		{
637
-			$this->error=$this->db->error();
637
+			$this->error = $this->db->error();
638 638
 			return -1;
639 639
 		}
640 640
 	}
@@ -646,7 +646,7 @@  discard block
 block discarded – undo
646 646
 	 *  @param		int			$notrigger	1=Does not execute triggers, 0= execute triggers
647 647
 	 *  @return     int						<0 if OK, >0 if KO
648 648
 	 */
649
-	function valid($user, $notrigger=0)
649
+	function valid($user, $notrigger = 0)
650 650
 	{
651 651
 		global $conf, $langs;
652 652
 
@@ -661,10 +661,10 @@  discard block
 block discarded – undo
661 661
 			return 0;
662 662
 		}
663 663
 
664
-		if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->creer))
665
-	   	|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->shipping_advance->validate))))
664
+		if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->creer))
665
+	   	|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->shipping_advance->validate))))
666 666
 		{
667
-			$this->error='Permission denied';
667
+			$this->error = 'Permission denied';
668 668
 			dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
669 669
 			return -1;
670 670
 		}
@@ -678,10 +678,10 @@  discard block
 block discarded – undo
678 678
 		$soc->fetch($this->socid);
679 679
 
680 680
 		// Class of company linked to order
681
-		$result=$soc->set_as_client();
681
+		$result = $soc->set_as_client();
682 682
 
683 683
 		// Define new ref
684
-		if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
684
+		if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
685 685
 		{
686 686
 			$numref = $this->getNextNumRef($soc);
687 687
 		}
@@ -691,26 +691,26 @@  discard block
 block discarded – undo
691 691
 		}
692 692
 		$this->newref = $numref;
693 693
 
694
-		$now=dol_now();
694
+		$now = dol_now();
695 695
 
696 696
 		// Validate
697 697
 		$sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET";
698
-		$sql.= " ref='".$numref."'";
699
-		$sql.= ", fk_statut = 1";
700
-		$sql.= ", date_valid = '".$this->db->idate($now)."'";
701
-		$sql.= ", fk_user_valid = ".$user->id;
702
-		$sql.= " WHERE rowid = ".$this->id;
698
+		$sql .= " ref='".$numref."'";
699
+		$sql .= ", fk_statut = 1";
700
+		$sql .= ", date_valid = '".$this->db->idate($now)."'";
701
+		$sql .= ", fk_user_valid = ".$user->id;
702
+		$sql .= " WHERE rowid = ".$this->id;
703 703
 
704 704
 		dol_syslog(get_class($this)."::valid update expedition", LOG_DEBUG);
705
-		$resql=$this->db->query($sql);
706
-		if (! $resql)
705
+		$resql = $this->db->query($sql);
706
+		if (!$resql)
707 707
 		{
708
-			$this->error=$this->db->lasterror();
708
+			$this->error = $this->db->lasterror();
709 709
 			$error++;
710 710
 		}
711 711
 
712 712
 		// If stock increment is done on sending (recommanded choice)
713
-		if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT))
713
+		if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT))
714 714
 		{
715 715
 			require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
716 716
 
@@ -718,16 +718,16 @@  discard block
 block discarded – undo
718 718
 
719 719
 			// Loop on each product line to add a stock movement
720 720
 			$sql = "SELECT cd.fk_product, cd.subprice,";
721
-			$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
722
-			$sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
723
-			$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
724
-			$sql.= " ".MAIN_DB_PREFIX."expeditiondet as ed";
725
-			$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
726
-			$sql.= " WHERE ed.fk_expedition = ".$this->id;
727
-			$sql.= " AND cd.rowid = ed.fk_origin_line";
721
+			$sql .= " ed.rowid, ed.qty, ed.fk_entrepot,";
722
+			$sql .= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
723
+			$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
724
+			$sql .= " ".MAIN_DB_PREFIX."expeditiondet as ed";
725
+			$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
726
+			$sql .= " WHERE ed.fk_expedition = ".$this->id;
727
+			$sql .= " AND cd.rowid = ed.fk_origin_line";
728 728
 
729 729
 			dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
730
-			$resql=$this->db->query($sql);
730
+			$resql = $this->db->query($sql);
731 731
 			if ($resql)
732 732
 			{
733 733
 				$cpt = $this->db->num_rows($resql);
@@ -754,10 +754,10 @@  discard block
 block discarded – undo
754 754
 						// line without batch detail
755 755
 
756 756
 						// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record.
757
-						$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentValidatedInDolibarr",$numref));
757
+						$result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentValidatedInDolibarr", $numref));
758 758
 						if ($result < 0) {
759 759
 							$error++;
760
-							$this->errors[]=$mouvS->error;
760
+							$this->errors[] = $mouvS->error;
761 761
 							$this->errors = array_merge($this->errors, $mouvS->errors);
762 762
 							break;
763 763
 						}
@@ -768,10 +768,10 @@  discard block
 block discarded – undo
768 768
 
769 769
 						// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record.
770 770
 						// Note: ->fk_origin_stock = id into table llx_product_batch (may be rename into llx_product_stock_batch in another version)
771
-						$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentValidatedInDolibarr",$numref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
771
+						$result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentValidatedInDolibarr", $numref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
772 772
 						if ($result < 0) {
773 773
 							$error++;
774
-							$this->errors[]=$mouvS->error;
774
+							$this->errors[] = $mouvS->error;
775 775
 							$this->errors = array_merge($this->errors, $mouvS->errors);
776 776
 							break;
777 777
 						}
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
 			else
782 782
 			{
783 783
 				$this->db->rollback();
784
-				$this->error=$this->db->error();
784
+				$this->error = $this->db->error();
785 785
 				return -2;
786 786
 			}
787 787
 		}
@@ -789,20 +789,20 @@  discard block
 block discarded – undo
789 789
 		// Change status of order to "shipment in process"
790 790
 		$ret = $this->setStatut(Commande::STATUS_SHIPMENTONPROCESS, $this->origin_id, $this->origin);
791 791
 
792
-		if (! $ret)
792
+		if (!$ret)
793 793
 		{
794 794
 			$error++;
795 795
 		}
796 796
 
797
-		if (! $error && ! $notrigger)
797
+		if (!$error && !$notrigger)
798 798
 		{
799 799
 			// Call trigger
800
-			$result=$this->call_trigger('SHIPPING_VALIDATE',$user);
800
+			$result = $this->call_trigger('SHIPPING_VALIDATE', $user);
801 801
 			if ($result < 0) { $error++; }
802 802
 			// End call triggers
803 803
 		}
804 804
 
805
-		if (! $error)
805
+		if (!$error)
806 806
 		{
807 807
 			$this->oldref = $this->ref;
808 808
 
@@ -823,13 +823,13 @@  discard block
 block discarded – undo
823 823
 					{
824 824
 						dol_syslog("Rename ok");
825 825
 						// Rename docs starting with $oldref with $newref
826
-						$listoffiles=dol_dir_list($conf->expedition->dir_output.'/sending/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
827
-						foreach($listoffiles as $fileentry)
826
+						$listoffiles = dol_dir_list($conf->expedition->dir_output.'/sending/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
827
+						foreach ($listoffiles as $fileentry)
828 828
 						{
829
-							$dirsource=$fileentry['name'];
830
-							$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
831
-							$dirsource=$fileentry['path'].'/'.$dirsource;
832
-							$dirdest=$fileentry['path'].'/'.$dirdest;
829
+							$dirsource = $fileentry['name'];
830
+							$dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
831
+							$dirsource = $fileentry['path'].'/'.$dirsource;
832
+							$dirdest = $fileentry['path'].'/'.$dirdest;
833 833
 							@rename($dirsource, $dirdest);
834 834
 						}
835 835
 					}
@@ -838,26 +838,26 @@  discard block
 block discarded – undo
838 838
 		}
839 839
 
840 840
 		// Set new ref and current status
841
-		if (! $error)
841
+		if (!$error)
842 842
 		{
843 843
 			$this->ref = $numref;
844 844
 			$this->statut = 1;
845 845
 		}
846 846
 
847
-		if (! $error)
847
+		if (!$error)
848 848
 		{
849 849
 			$this->db->commit();
850 850
 			return 1;
851 851
 		}
852 852
 		else
853 853
 		{
854
-			foreach($this->errors as $errmsg)
854
+			foreach ($this->errors as $errmsg)
855 855
 			{
856 856
 				dol_syslog(get_class($this)."::valid ".$errmsg, LOG_ERR);
857
-				$this->error.=($this->error?', '.$errmsg:$errmsg);
857
+				$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
858 858
 			}
859 859
 			$this->db->rollback();
860
-			return -1*$error;
860
+			return -1 * $error;
861 861
 		}
862 862
 	}
863 863
 
@@ -881,14 +881,14 @@  discard block
 block discarded – undo
881 881
 				// Expedition validee
882 882
 				include_once DOL_DOCUMENT_ROOT.'/livraison/class/livraison.class.php';
883 883
 				$delivery = new Livraison($this->db);
884
-				$result=$delivery->create_from_sending($user, $this->id);
884
+				$result = $delivery->create_from_sending($user, $this->id);
885 885
 				if ($result > 0)
886 886
 				{
887 887
 					return $result;
888 888
 				}
889 889
 				else
890 890
 				{
891
-					$this->error=$delivery->error;
891
+					$this->error = $delivery->error;
892 892
 					return $result;
893 893
 				}
894 894
 			}
@@ -908,7 +908,7 @@  discard block
 block discarded – undo
908 908
 	 * @param	array	$array_options		extrafields array
909 909
 	 * @return	int							<0 if KO, >0 if OK
910 910
 	 */
911
-	function addline($entrepot_id, $id, $qty,$array_options=0)
911
+	function addline($entrepot_id, $id, $qty, $array_options = 0)
912 912
 	{
913 913
 		global $conf, $langs;
914 914
 
@@ -922,22 +922,22 @@  discard block
 block discarded – undo
922 922
 		$orderline = new OrderLine($this->db);
923 923
 		$orderline->fetch($id);
924 924
 
925
-		if (! empty($conf->stock->enabled) && ! empty($orderline->fk_product))
925
+		if (!empty($conf->stock->enabled) && !empty($orderline->fk_product))
926 926
 		{
927 927
 			$fk_product = $orderline->fk_product;
928 928
 
929
-			if (! ($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS))
929
+			if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS))
930 930
 			{
931 931
 				$langs->load("errors");
932
-				$this->error=$langs->trans("ErrorWarehouseRequiredIntoShipmentLine");
932
+				$this->error = $langs->trans("ErrorWarehouseRequiredIntoShipmentLine");
933 933
 				return -1;
934 934
 			}
935 935
 
936 936
 			if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT)
937 937
 			{
938 938
 				// Check must be done for stock of product into warehouse if $entrepot_id defined
939
-				$product=new Product($this->db);
940
-				$result=$product->fetch($fk_product);
939
+				$product = new Product($this->db);
940
+				$result = $product->fetch($fk_product);
941 941
 
942 942
 				if ($entrepot_id > 0) {
943 943
 					$product->load_stock('warehouseopen');
@@ -946,11 +946,11 @@  discard block
 block discarded – undo
946 946
 				else
947 947
 					$product_stock = $product->stock_reel;
948 948
 
949
-				$product_type=$product->type;
949
+				$product_type = $product->type;
950 950
 				if ($product_type == 0 && $product_stock < $qty)
951 951
 				{
952 952
 					$langs->load("errors");
953
-					$this->error=$langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref);
953
+					$this->error = $langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref);
954 954
 					$this->db->rollback();
955 955
 					return -3;
956 956
 				}
@@ -958,14 +958,14 @@  discard block
 block discarded – undo
958 958
 		}
959 959
 
960 960
 		// If product need a batch number, we should not have called this function but addline_batch instead.
961
-		if (! empty($conf->productbatch->enabled) && ! empty($orderline->fk_product) && ! empty($orderline->product_tobatch))
961
+		if (!empty($conf->productbatch->enabled) && !empty($orderline->fk_product) && !empty($orderline->product_tobatch))
962 962
 		{
963
-			$this->error='ADDLINE_WAS_CALLED_INSTEAD_OF_ADDLINEBATCH';
963
+			$this->error = 'ADDLINE_WAS_CALLED_INSTEAD_OF_ADDLINEBATCH';
964 964
 			return -4;
965 965
 		}
966 966
 
967 967
 		// extrafields
968
-		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
968
+		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) // For avoid conflicts if trigger used
969 969
 			$line->array_options = $array_options;
970 970
 
971 971
 		$this->lines[$num] = $line;
@@ -979,33 +979,33 @@  discard block
 block discarded – undo
979 979
 	 * @param	array		$array_options		extrafields array
980 980
 	 * @return	int						<0 if KO, >0 if OK
981 981
 	 */
982
-	function addline_batch($dbatch,$array_options=0)
982
+	function addline_batch($dbatch, $array_options = 0)
983 983
 	{
984 984
         // phpcs:enable
985
-		global $conf,$langs;
985
+		global $conf, $langs;
986 986
 
987 987
 		$num = count($this->lines);
988
-		if ($dbatch['qty']>0)
988
+		if ($dbatch['qty'] > 0)
989 989
 		{
990 990
 			$line = new ExpeditionLigne($this->db);
991
-			$tab=array();
991
+			$tab = array();
992 992
 			foreach ($dbatch['detail'] as $key=>$value)
993 993
 			{
994
-				if ($value['q']>0)
994
+				if ($value['q'] > 0)
995 995
 				{
996 996
 					// $value['q']=qty to move
997 997
 					// $value['id_batch']=id into llx_product_batch of record to move
998 998
 					//var_dump($value);
999 999
 
1000 1000
 					$linebatch = new ExpeditionLineBatch($this->db);
1001
-					$ret=$linebatch->fetchFromStock($value['id_batch']);	// load serial, sellby, eatby
1002
-					if ($ret<0)
1001
+					$ret = $linebatch->fetchFromStock($value['id_batch']); // load serial, sellby, eatby
1002
+					if ($ret < 0)
1003 1003
 					{
1004
-						$this->error=$linebatch->error;
1004
+						$this->error = $linebatch->error;
1005 1005
 						return -1;
1006 1006
 					}
1007
-					$linebatch->qty=$value['q'];
1008
-					$tab[]=$linebatch;
1007
+					$linebatch->qty = $value['q'];
1008
+					$tab[] = $linebatch;
1009 1009
 
1010 1010
 					if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT)
1011 1011
 					{
@@ -1016,7 +1016,7 @@  discard block
 block discarded – undo
1016 1016
 						if ($prod_batch->qty < $linebatch->qty)
1017 1017
 						{
1018 1018
 							$langs->load("errors");
1019
-							$this->errors[]=$langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $prod_batch->fk_product);
1019
+							$this->errors[] = $langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $prod_batch->fk_product);
1020 1020
 							dol_syslog(get_class($this)."::addline_batch error=Product ".$prod_batch->batch.": ".$this->errorsToString(), LOG_ERR);
1021 1021
 							$this->db->rollback();
1022 1022
 							return -1;
@@ -1029,10 +1029,10 @@  discard block
 block discarded – undo
1029 1029
 			$line->entrepot_id = $linebatch->entrepot_id;
1030 1030
 			$line->origin_line_id = $dbatch['ix_l'];
1031 1031
 			$line->qty = $dbatch['qty'];
1032
-			$line->detail_batch=$tab;
1032
+			$line->detail_batch = $tab;
1033 1033
 
1034 1034
 			// extrafields
1035
-			if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
1035
+			if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) // For avoid conflicts if trigger used
1036 1036
 				$line->array_options = $array_options;
1037 1037
 
1038 1038
 			//var_dump($line);
@@ -1048,32 +1048,32 @@  discard block
 block discarded – undo
1048 1048
 	 *  @param  int		$notrigger	    0=launch triggers after, 1=disable triggers
1049 1049
 	 *  @return int 			       	<0 if KO, >0 if OK
1050 1050
 	 */
1051
-	function update($user=null, $notrigger=0)
1051
+	function update($user = null, $notrigger = 0)
1052 1052
 	{
1053 1053
 		global $conf;
1054
-		$error=0;
1054
+		$error = 0;
1055 1055
 
1056 1056
 		// Clean parameters
1057 1057
 
1058
-		if (isset($this->ref)) $this->ref=trim($this->ref);
1059
-		if (isset($this->entity)) $this->entity=trim($this->entity);
1060
-		if (isset($this->ref_customer)) $this->ref_customer=trim($this->ref_customer);
1061
-		if (isset($this->socid)) $this->socid=trim($this->socid);
1062
-		if (isset($this->fk_user_author)) $this->fk_user_author=trim($this->fk_user_author);
1063
-		if (isset($this->fk_user_valid)) $this->fk_user_valid=trim($this->fk_user_valid);
1064
-		if (isset($this->fk_delivery_address)) $this->fk_delivery_address=trim($this->fk_delivery_address);
1065
-		if (isset($this->shipping_method_id)) $this->shipping_method_id=trim($this->shipping_method_id);
1066
-		if (isset($this->tracking_number)) $this->tracking_number=trim($this->tracking_number);
1067
-		if (isset($this->statut)) $this->statut=(int) $this->statut;
1068
-		if (isset($this->trueDepth)) $this->trueDepth=trim($this->trueDepth);
1069
-		if (isset($this->trueWidth)) $this->trueWidth=trim($this->trueWidth);
1070
-		if (isset($this->trueHeight)) $this->trueHeight=trim($this->trueHeight);
1071
-		if (isset($this->size_units)) $this->size_units=trim($this->size_units);
1072
-		if (isset($this->weight_units)) $this->weight_units=trim($this->weight_units);
1073
-		if (isset($this->trueWeight)) $this->weight=trim($this->trueWeight);
1074
-		if (isset($this->note_private)) $this->note=trim($this->note_private);
1075
-		if (isset($this->note_public)) $this->note=trim($this->note_public);
1076
-		if (isset($this->modelpdf)) $this->modelpdf=trim($this->modelpdf);
1058
+		if (isset($this->ref)) $this->ref = trim($this->ref);
1059
+		if (isset($this->entity)) $this->entity = trim($this->entity);
1060
+		if (isset($this->ref_customer)) $this->ref_customer = trim($this->ref_customer);
1061
+		if (isset($this->socid)) $this->socid = trim($this->socid);
1062
+		if (isset($this->fk_user_author)) $this->fk_user_author = trim($this->fk_user_author);
1063
+		if (isset($this->fk_user_valid)) $this->fk_user_valid = trim($this->fk_user_valid);
1064
+		if (isset($this->fk_delivery_address)) $this->fk_delivery_address = trim($this->fk_delivery_address);
1065
+		if (isset($this->shipping_method_id)) $this->shipping_method_id = trim($this->shipping_method_id);
1066
+		if (isset($this->tracking_number)) $this->tracking_number = trim($this->tracking_number);
1067
+		if (isset($this->statut)) $this->statut = (int) $this->statut;
1068
+		if (isset($this->trueDepth)) $this->trueDepth = trim($this->trueDepth);
1069
+		if (isset($this->trueWidth)) $this->trueWidth = trim($this->trueWidth);
1070
+		if (isset($this->trueHeight)) $this->trueHeight = trim($this->trueHeight);
1071
+		if (isset($this->size_units)) $this->size_units = trim($this->size_units);
1072
+		if (isset($this->weight_units)) $this->weight_units = trim($this->weight_units);
1073
+		if (isset($this->trueWeight)) $this->weight = trim($this->trueWeight);
1074
+		if (isset($this->note_private)) $this->note = trim($this->note_private);
1075
+		if (isset($this->note_public)) $this->note = trim($this->note_public);
1076
+		if (isset($this->modelpdf)) $this->modelpdf = trim($this->modelpdf);
1077 1077
 
1078 1078
 
1079 1079
 
@@ -1083,46 +1083,46 @@  discard block
 block discarded – undo
1083 1083
 		// Update request
1084 1084
 		$sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET";
1085 1085
 
1086
-		$sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
1087
-		$sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").",";
1088
-		$sql.= " ref_customer=".(isset($this->ref_customer)?"'".$this->db->escape($this->ref_customer)."'":"null").",";
1089
-		$sql.= " fk_soc=".(isset($this->socid)?$this->socid:"null").",";
1090
-		$sql.= " date_creation=".(dol_strlen($this->date_creation)!=0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').",";
1091
-		$sql.= " fk_user_author=".(isset($this->fk_user_author)?$this->fk_user_author:"null").",";
1092
-		$sql.= " date_valid=".(dol_strlen($this->date_valid)!=0 ? "'".$this->db->idate($this->date_valid)."'" : 'null').",";
1093
-		$sql.= " fk_user_valid=".(isset($this->fk_user_valid)?$this->fk_user_valid:"null").",";
1094
-		$sql.= " date_expedition=".(dol_strlen($this->date_expedition)!=0 ? "'".$this->db->idate($this->date_expedition)."'" : 'null').",";
1095
-		$sql.= " date_delivery=".(dol_strlen($this->date_delivery)!=0 ? "'".$this->db->idate($this->date_delivery)."'" : 'null').",";
1096
-		$sql.= " fk_address=".(isset($this->fk_delivery_address)?$this->fk_delivery_address:"null").",";
1097
-		$sql.= " fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0)?$this->shipping_method_id:"null").",";
1098
-		$sql.= " tracking_number=".(isset($this->tracking_number)?"'".$this->db->escape($this->tracking_number)."'":"null").",";
1099
-		$sql.= " fk_statut=".(isset($this->statut)?$this->statut:"null").",";
1100
-		$sql.= " fk_projet=".(isset($this->fk_project)?$this->fk_project:"null").",";
1101
-		$sql.= " height=".(($this->trueHeight != '')?$this->trueHeight:"null").",";
1102
-		$sql.= " width=".(($this->trueWidth != '')?$this->trueWidth:"null").",";
1103
-		$sql.= " size_units=".(isset($this->size_units)?$this->size_units:"null").",";
1104
-		$sql.= " size=".(($this->trueDepth != '')?$this->trueDepth:"null").",";
1105
-		$sql.= " weight_units=".(isset($this->weight_units)?$this->weight_units:"null").",";
1106
-		$sql.= " weight=".(($this->trueWeight != '')?$this->trueWeight:"null").",";
1107
-		$sql.= " note_private=".(isset($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null").",";
1108
-		$sql.= " note_public=".(isset($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null").",";
1109
-		$sql.= " model_pdf=".(isset($this->modelpdf)?"'".$this->db->escape($this->modelpdf)."'":"null").",";
1110
-		$sql.= " entity=".$conf->entity;
1111
-
1112
-		$sql.= " WHERE rowid=".$this->id;
1086
+		$sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
1087
+		$sql .= " ref=".(isset($this->ref) ? "'".$this->db->escape($this->ref)."'" : "null").",";
1088
+		$sql .= " ref_customer=".(isset($this->ref_customer) ? "'".$this->db->escape($this->ref_customer)."'" : "null").",";
1089
+		$sql .= " fk_soc=".(isset($this->socid) ? $this->socid : "null").",";
1090
+		$sql .= " date_creation=".(dol_strlen($this->date_creation) != 0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').",";
1091
+		$sql .= " fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author : "null").",";
1092
+		$sql .= " date_valid=".(dol_strlen($this->date_valid) != 0 ? "'".$this->db->idate($this->date_valid)."'" : 'null').",";
1093
+		$sql .= " fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid : "null").",";
1094
+		$sql .= " date_expedition=".(dol_strlen($this->date_expedition) != 0 ? "'".$this->db->idate($this->date_expedition)."'" : 'null').",";
1095
+		$sql .= " date_delivery=".(dol_strlen($this->date_delivery) != 0 ? "'".$this->db->idate($this->date_delivery)."'" : 'null').",";
1096
+		$sql .= " fk_address=".(isset($this->fk_delivery_address) ? $this->fk_delivery_address : "null").",";
1097
+		$sql .= " fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id : "null").",";
1098
+		$sql .= " tracking_number=".(isset($this->tracking_number) ? "'".$this->db->escape($this->tracking_number)."'" : "null").",";
1099
+		$sql .= " fk_statut=".(isset($this->statut) ? $this->statut : "null").",";
1100
+		$sql .= " fk_projet=".(isset($this->fk_project) ? $this->fk_project : "null").",";
1101
+		$sql .= " height=".(($this->trueHeight != '') ? $this->trueHeight : "null").",";
1102
+		$sql .= " width=".(($this->trueWidth != '') ? $this->trueWidth : "null").",";
1103
+		$sql .= " size_units=".(isset($this->size_units) ? $this->size_units : "null").",";
1104
+		$sql .= " size=".(($this->trueDepth != '') ? $this->trueDepth : "null").",";
1105
+		$sql .= " weight_units=".(isset($this->weight_units) ? $this->weight_units : "null").",";
1106
+		$sql .= " weight=".(($this->trueWeight != '') ? $this->trueWeight : "null").",";
1107
+		$sql .= " note_private=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").",";
1108
+		$sql .= " note_public=".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null").",";
1109
+		$sql .= " model_pdf=".(isset($this->modelpdf) ? "'".$this->db->escape($this->modelpdf)."'" : "null").",";
1110
+		$sql .= " entity=".$conf->entity;
1111
+
1112
+		$sql .= " WHERE rowid=".$this->id;
1113 1113
 
1114 1114
 		$this->db->begin();
1115 1115
 
1116 1116
 		dol_syslog(get_class($this)."::update", LOG_DEBUG);
1117 1117
 		$resql = $this->db->query($sql);
1118
-		if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
1118
+		if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
1119 1119
 
1120
-		if (! $error)
1120
+		if (!$error)
1121 1121
 		{
1122
-			if (! $notrigger)
1122
+			if (!$notrigger)
1123 1123
 			{
1124 1124
 				// Call trigger
1125
-				$result=$this->call_trigger('SHIPPING_MODIFY',$user);
1125
+				$result = $this->call_trigger('SHIPPING_MODIFY', $user);
1126 1126
 				if ($result < 0) { $error++; }
1127 1127
 				// End call triggers
1128 1128
 			}
@@ -1131,13 +1131,13 @@  discard block
 block discarded – undo
1131 1131
 		// Commit or rollback
1132 1132
 		if ($error)
1133 1133
 		{
1134
-			foreach($this->errors as $errmsg)
1134
+			foreach ($this->errors as $errmsg)
1135 1135
 			{
1136 1136
 				dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
1137
-				$this->error.=($this->error?', '.$errmsg:$errmsg);
1137
+				$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1138 1138
 			}
1139 1139
 			$this->db->rollback();
1140
-			return -1*$error;
1140
+			return -1 * $error;
1141 1141
 		}
1142 1142
 		else
1143 1143
 		{
@@ -1159,32 +1159,32 @@  discard block
 block discarded – undo
1159 1159
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1160 1160
 		require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';
1161 1161
 
1162
-		$error=0;
1163
-		$this->error='';
1162
+		$error = 0;
1163
+		$this->error = '';
1164 1164
 
1165 1165
 		$this->db->begin();
1166 1166
 
1167 1167
 		// Add a protection to refuse deleting if shipment has at least one delivery
1168
-		$this->fetchObjectLinked($this->id, 'shipping', 0, 'delivery');	// Get deliveries linked to this shipment
1168
+		$this->fetchObjectLinked($this->id, 'shipping', 0, 'delivery'); // Get deliveries linked to this shipment
1169 1169
 		if (count($this->linkedObjectsIds) > 0)
1170 1170
 		{
1171
-			$this->error='ErrorThereIsSomeDeliveries';
1171
+			$this->error = 'ErrorThereIsSomeDeliveries';
1172 1172
 			$error++;
1173 1173
 		}
1174 1174
 
1175
-		if (! $error)
1175
+		if (!$error)
1176 1176
 		{
1177
-			if (! $notrigger)
1177
+			if (!$notrigger)
1178 1178
 			{
1179 1179
 				// Call trigger
1180
-				$result=$this->call_trigger('SHIPPING_DELETE',$user);
1180
+				$result = $this->call_trigger('SHIPPING_DELETE', $user);
1181 1181
 				if ($result < 0) { $error++; }
1182 1182
 				// End call triggers
1183 1183
 			}
1184 1184
 		}
1185 1185
 
1186 1186
 		// Stock control
1187
-		if (! $error && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > 0)
1187
+		if (!$error && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > 0)
1188 1188
 		{
1189 1189
 			require_once DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php";
1190 1190
 
@@ -1192,13 +1192,13 @@  discard block
 block discarded – undo
1192 1192
 
1193 1193
 			// Loop on each product line to add a stock movement
1194 1194
 			$sql = "SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
1195
-			$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
1196
-			$sql.= " ".MAIN_DB_PREFIX."expeditiondet as ed";
1197
-			$sql.= " WHERE ed.fk_expedition = ".$this->id;
1198
-			$sql.= " AND cd.rowid = ed.fk_origin_line";
1195
+			$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
1196
+			$sql .= " ".MAIN_DB_PREFIX."expeditiondet as ed";
1197
+			$sql .= " WHERE ed.fk_expedition = ".$this->id;
1198
+			$sql .= " AND cd.rowid = ed.fk_origin_line";
1199 1199
 
1200 1200
 			dol_syslog(get_class($this)."::delete select details", LOG_DEBUG);
1201
-			$resql=$this->db->query($sql);
1201
+			$resql = $this->db->query($sql);
1202 1202
 			if ($resql)
1203 1203
 			{
1204 1204
 				$cpt = $this->db->num_rows($resql);
@@ -1214,20 +1214,20 @@  discard block
 block discarded – undo
1214 1214
 					$lotArray = null;
1215 1215
 					if ($conf->productbatch->enabled)
1216 1216
 					{
1217
-						$lotArray = ExpeditionLineBatch::fetchAll($this->db,$obj->expeditiondet_id);
1218
-						if (! is_array($lotArray))
1217
+						$lotArray = ExpeditionLineBatch::fetchAll($this->db, $obj->expeditiondet_id);
1218
+						if (!is_array($lotArray))
1219 1219
 						{
1220
-							$error++;$this->errors[]="Error ".$this->db->lasterror();
1220
+							$error++; $this->errors[] = "Error ".$this->db->lasterror();
1221 1221
 						}
1222 1222
 					}
1223 1223
 					if (empty($lotArray)) {
1224 1224
 						// no lot/serial
1225 1225
 						// We increment stock of product (and sub-products)
1226 1226
 						// We use warehouse selected for each line
1227
-						$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans("ShipmentDeletedInDolibarr", $this->ref));  // Price is set to 0, because we don't want to see WAP changed
1227
+						$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans("ShipmentDeletedInDolibarr", $this->ref)); // Price is set to 0, because we don't want to see WAP changed
1228 1228
 						if ($result < 0)
1229 1229
 						{
1230
-							$error++;$this->errors=$this->errors + $mouvS->errors;
1230
+							$error++; $this->errors = $this->errors + $mouvS->errors;
1231 1231
 							break;
1232 1232
 						}
1233 1233
 					}
@@ -1235,12 +1235,12 @@  discard block
 block discarded – undo
1235 1235
 					{
1236 1236
 						// We increment stock of batches
1237 1237
 						// We use warehouse selected for each line
1238
-						foreach($lotArray as $lot)
1238
+						foreach ($lotArray as $lot)
1239 1239
 						{
1240
-							$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans("ShipmentDeletedInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch);  // Price is set to 0, because we don't want to see WAP changed
1240
+							$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans("ShipmentDeletedInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch); // Price is set to 0, because we don't want to see WAP changed
1241 1241
 							if ($result < 0)
1242 1242
 							{
1243
-								$error++;$this->errors=$this->errors + $mouvS->errors;
1243
+								$error++; $this->errors = $this->errors + $mouvS->errors;
1244 1244
 								break;
1245 1245
 							}
1246 1246
 						}
@@ -1250,41 +1250,41 @@  discard block
 block discarded – undo
1250 1250
 			}
1251 1251
 			else
1252 1252
 			{
1253
-				$error++;$this->errors[]="Error ".$this->db->lasterror();
1253
+				$error++; $this->errors[] = "Error ".$this->db->lasterror();
1254 1254
 			}
1255 1255
 		}
1256 1256
 
1257 1257
 		// delete batch expedition line
1258
-		if (! $error && $conf->productbatch->enabled)
1258
+		if (!$error && $conf->productbatch->enabled)
1259 1259
 		{
1260
-			if (ExpeditionLineBatch::deletefromexp($this->db,$this->id) < 0)
1260
+			if (ExpeditionLineBatch::deletefromexp($this->db, $this->id) < 0)
1261 1261
 			{
1262
-				$error++;$this->errors[]="Error ".$this->db->lasterror();
1262
+				$error++; $this->errors[] = "Error ".$this->db->lasterror();
1263 1263
 			}
1264 1264
 		}
1265 1265
 
1266
-		if (! $error)
1266
+		if (!$error)
1267 1267
 		{
1268 1268
 			$sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet";
1269
-			$sql.= " WHERE fk_expedition = ".$this->id;
1269
+			$sql .= " WHERE fk_expedition = ".$this->id;
1270 1270
 
1271
-			if ( $this->db->query($sql) )
1271
+			if ($this->db->query($sql))
1272 1272
 			{
1273 1273
 				// Delete linked object
1274 1274
 				$res = $this->deleteObjectLinked();
1275 1275
 				if ($res < 0) $error++;
1276 1276
 
1277
-				if (! $error)
1277
+				if (!$error)
1278 1278
 				{
1279 1279
 					$sql = "DELETE FROM ".MAIN_DB_PREFIX."expedition";
1280
-					$sql.= " WHERE rowid = ".$this->id;
1280
+					$sql .= " WHERE rowid = ".$this->id;
1281 1281
 
1282 1282
 					if ($this->db->query($sql))
1283 1283
 					{
1284
-						if (! empty($this->origin) && $this->origin_id > 0)
1284
+						if (!empty($this->origin) && $this->origin_id > 0)
1285 1285
 						{
1286 1286
 							$this->fetch_origin();
1287
-							$origin=$this->origin;
1287
+							$origin = $this->origin;
1288 1288
 							if ($this->$origin->statut == Commande::STATUS_SHIPMENTONPROCESS)     // If order source of shipment is "shipment in progress"
1289 1289
 							{
1290 1290
 								// Check if there is no more shipment. If not, we can move back status of order to "validated" instead of "shipment in progress"
@@ -1297,19 +1297,19 @@  discard block
 block discarded – undo
1297 1297
 							}
1298 1298
 						}
1299 1299
 
1300
-						if (! $error)
1300
+						if (!$error)
1301 1301
 						{
1302 1302
 							$this->db->commit();
1303 1303
 
1304 1304
 							// We delete PDFs
1305 1305
 							$ref = dol_sanitizeFileName($this->ref);
1306
-							if (! empty($conf->expedition->dir_output))
1306
+							if (!empty($conf->expedition->dir_output))
1307 1307
 							{
1308
-								$dir = $conf->expedition->dir_output . '/sending/' . $ref ;
1309
-								$file = $dir . '/' . $ref . '.pdf';
1308
+								$dir = $conf->expedition->dir_output.'/sending/'.$ref;
1309
+								$file = $dir.'/'.$ref.'.pdf';
1310 1310
 								if (file_exists($file))
1311 1311
 								{
1312
-									if (! dol_delete_file($file))
1312
+									if (!dol_delete_file($file))
1313 1313
 									{
1314 1314
 										return 0;
1315 1315
 									}
@@ -1318,7 +1318,7 @@  discard block
 block discarded – undo
1318 1318
 								{
1319 1319
 									if (!dol_delete_dir_recursive($dir))
1320 1320
 									{
1321
-										$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
1321
+										$this->error = $langs->trans("ErrorCanNotDeleteDir", $dir);
1322 1322
 										return 0;
1323 1323
 									}
1324 1324
 								}
@@ -1334,21 +1334,21 @@  discard block
 block discarded – undo
1334 1334
 					}
1335 1335
 					else
1336 1336
 					{
1337
-						$this->error=$this->db->lasterror()." - sql=$sql";
1337
+						$this->error = $this->db->lasterror()." - sql=$sql";
1338 1338
 						$this->db->rollback();
1339 1339
 						return -3;
1340 1340
 					}
1341 1341
 				}
1342 1342
 				else
1343 1343
 				{
1344
-					$this->error=$this->db->lasterror()." - sql=$sql";
1344
+					$this->error = $this->db->lasterror()." - sql=$sql";
1345 1345
 					$this->db->rollback();
1346 1346
 					return -2;
1347 1347
 				}
1348 1348
 			}
1349 1349
 			else
1350 1350
 			{
1351
-				$this->error=$this->db->lasterror()." - sql=$sql";
1351
+				$this->error = $this->db->lasterror()." - sql=$sql";
1352 1352
 				$this->db->rollback();
1353 1353
 				return -1;
1354 1354
 			}
@@ -1373,17 +1373,17 @@  discard block
 block discarded – undo
1373 1373
 		// TODO: recuperer les champs du document associe a part
1374 1374
 
1375 1375
 		$sql = "SELECT cd.rowid, cd.fk_product, cd.label as custom_label, cd.description, cd.qty as qty_asked, cd.product_type";
1376
-		$sql.= ", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva";
1377
-		$sql.= ", cd.vat_src_code, cd.tva_tx, cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.info_bits, cd.price, cd.subprice, cd.remise_percent,cd.buy_price_ht as pa_ht";
1378
-		$sql.= ", cd.fk_multicurrency, cd.multicurrency_code, cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc";
1379
-		$sql.= ", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_origin_line, ed.fk_entrepot";
1380
-		$sql.= ", p.ref as product_ref, p.label as product_label, p.fk_product_type";
1381
-		$sql.= ", p.weight, p.weight_units, p.length, p.length_units, p.surface, p.surface_units, p.volume, p.volume_units, p.tobatch as product_tobatch";
1382
-		$sql.= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd";
1383
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = cd.fk_product";
1384
-		$sql.= " WHERE ed.fk_expedition = ".$this->id;
1385
-		$sql.= " AND ed.fk_origin_line = cd.rowid";
1386
-		$sql.= " ORDER BY cd.rang, ed.fk_origin_line";
1376
+		$sql .= ", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva";
1377
+		$sql .= ", cd.vat_src_code, cd.tva_tx, cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.info_bits, cd.price, cd.subprice, cd.remise_percent,cd.buy_price_ht as pa_ht";
1378
+		$sql .= ", cd.fk_multicurrency, cd.multicurrency_code, cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc";
1379
+		$sql .= ", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_origin_line, ed.fk_entrepot";
1380
+		$sql .= ", p.ref as product_ref, p.label as product_label, p.fk_product_type";
1381
+		$sql .= ", p.weight, p.weight_units, p.length, p.length_units, p.surface, p.surface_units, p.volume, p.volume_units, p.tobatch as product_tobatch";
1382
+		$sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd";
1383
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = cd.fk_product";
1384
+		$sql .= " WHERE ed.fk_expedition = ".$this->id;
1385
+		$sql .= " AND ed.fk_origin_line = cd.rowid";
1386
+		$sql .= " ORDER BY cd.rang, ed.fk_origin_line";
1387 1387
 
1388 1388
 		dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
1389 1389
 		$resql = $this->db->query($sql);
@@ -1407,8 +1407,8 @@  discard block
 block discarded – undo
1407 1407
 				$obj = $this->db->fetch_object($resql);
1408 1408
 
1409 1409
 				if ($originline == $obj->fk_origin_line) {
1410
-					$line->entrepot_id       = 0; // entrepod_id in details_entrepot
1411
-					$line->qty_shipped    	+= $obj->qty_shipped;
1410
+					$line->entrepot_id = 0; // entrepod_id in details_entrepot
1411
+					$line->qty_shipped += $obj->qty_shipped;
1412 1412
 				} else {
1413 1413
 					$line = new ExpeditionLigne($this->db);
1414 1414
 					$line->entrepot_id    	= $obj->fk_entrepot;
@@ -1422,24 +1422,24 @@  discard block
 block discarded – undo
1422 1422
 				$line->details_entrepot[]     = $detail_entrepot;
1423 1423
 
1424 1424
 				$line->line_id          = $obj->line_id;
1425
-				$line->rowid            = $obj->line_id;    // TODO deprecated
1425
+				$line->rowid            = $obj->line_id; // TODO deprecated
1426 1426
 				$line->id               = $obj->line_id;
1427 1427
 
1428
-				$line->fk_origin     	= 'orderline';
1428
+				$line->fk_origin = 'orderline';
1429 1429
 				$line->fk_origin_line 	= $obj->fk_origin_line;
1430
-				$line->origin_line_id 	= $obj->fk_origin_line;	    // TODO deprecated
1430
+				$line->origin_line_id 	= $obj->fk_origin_line; // TODO deprecated
1431 1431
 
1432
-				$line->fk_expedition    = $this->id;                // id of parent
1432
+				$line->fk_expedition    = $this->id; // id of parent
1433 1433
 
1434 1434
 				$line->product_type     = $obj->product_type;
1435 1435
 				$line->fk_product     	= $obj->fk_product;
1436 1436
 				$line->fk_product_type	= $obj->fk_product_type;
1437
-				$line->ref				= $obj->product_ref;		// TODO deprecated
1438
-				$line->product_ref		= $obj->product_ref;
1439
-				$line->product_label	= $obj->product_label;
1440
-				$line->libelle        	= $obj->product_label;		// TODO deprecated
1441
-				$line->product_tobatch  = $obj->product_tobatch;
1442
-				$line->label			= $obj->custom_label;
1437
+				$line->ref = $obj->product_ref; // TODO deprecated
1438
+				$line->product_ref = $obj->product_ref;
1439
+				$line->product_label = $obj->product_label;
1440
+				$line->libelle        	= $obj->product_label; // TODO deprecated
1441
+				$line->product_tobatch = $obj->product_tobatch;
1442
+				$line->label = $obj->custom_label;
1443 1443
 				$line->description    	= $obj->description;
1444 1444
 				$line->qty_asked      	= $obj->qty_asked;
1445 1445
 				$line->weight         	= $obj->weight;
@@ -1447,44 +1447,44 @@  discard block
 block discarded – undo
1447 1447
 				$line->length         	= $obj->length;
1448 1448
 				$line->length_units   	= $obj->length_units;
1449 1449
 				$line->surface        	= $obj->surface;
1450
-				$line->surface_units   	= $obj->surface_units;
1450
+				$line->surface_units = $obj->surface_units;
1451 1451
 				$line->volume         	= $obj->volume;
1452 1452
 				$line->volume_units   	= $obj->volume_units;
1453 1453
 
1454
-				$line->pa_ht 			= $obj->pa_ht;
1454
+				$line->pa_ht = $obj->pa_ht;
1455 1455
 
1456 1456
 				// Local taxes
1457
-				$localtax_array=array(0=>$obj->localtax1_type, 1=>$obj->localtax1_tx, 2=>$obj->localtax2_type, 3=>$obj->localtax2_tx);
1457
+				$localtax_array = array(0=>$obj->localtax1_type, 1=>$obj->localtax1_tx, 2=>$obj->localtax2_type, 3=>$obj->localtax2_tx);
1458 1458
 				$localtax1_tx = get_localtax($obj->tva_tx, 1, $this->thirdparty);
1459 1459
 				$localtax2_tx = get_localtax($obj->tva_tx, 2, $this->thirdparty);
1460 1460
 
1461 1461
 				// For invoicing
1462
-				$tabprice = calcul_price_total($obj->qty_shipped, $obj->subprice, $obj->remise_percent, $obj->tva_tx, $localtax1_tx, $localtax2_tx, 0, 'HT', $obj->info_bits, $obj->fk_product_type, $mysoc, $localtax_array);	// We force type to 0
1463
-				$line->desc	         	= $obj->description;		// We need ->desc because some code into CommonObject use desc (property defined for other elements)
1464
-				$line->qty 				= $line->qty_shipped;
1465
-				$line->total_ht			= $tabprice[0];
1462
+				$tabprice = calcul_price_total($obj->qty_shipped, $obj->subprice, $obj->remise_percent, $obj->tva_tx, $localtax1_tx, $localtax2_tx, 0, 'HT', $obj->info_bits, $obj->fk_product_type, $mysoc, $localtax_array); // We force type to 0
1463
+				$line->desc = $obj->description; // We need ->desc because some code into CommonObject use desc (property defined for other elements)
1464
+				$line->qty = $line->qty_shipped;
1465
+				$line->total_ht = $tabprice[0];
1466 1466
 				$line->total_localtax1 	= $tabprice[9];
1467 1467
 				$line->total_localtax2 	= $tabprice[10];
1468 1468
 				$line->total_ttc	 	= $tabprice[2];
1469 1469
 				$line->total_tva	 	= $tabprice[1];
1470
-				$line->vat_src_code	 	= $obj->vat_src_code;
1471
-				$line->tva_tx 		 	= $obj->tva_tx;
1470
+				$line->vat_src_code = $obj->vat_src_code;
1471
+				$line->tva_tx = $obj->tva_tx;
1472 1472
 				$line->localtax1_tx 	= $obj->localtax1_tx;
1473 1473
 				$line->localtax2_tx 	= $obj->localtax2_tx;
1474
-				$line->info_bits        = $obj->info_bits;
1475
-				$line->price			= $obj->price;
1476
-				$line->subprice			= $obj->subprice;
1477
-				$line->remise_percent	= $obj->remise_percent;
1474
+				$line->info_bits = $obj->info_bits;
1475
+				$line->price = $obj->price;
1476
+				$line->subprice = $obj->subprice;
1477
+				$line->remise_percent = $obj->remise_percent;
1478 1478
 
1479
-				$this->total_ht+= $tabprice[0];
1480
-				$this->total_tva+= $tabprice[1];
1481
-				$this->total_ttc+= $tabprice[2];
1482
-				$this->total_localtax1+= $tabprice[9];
1483
-				$this->total_localtax2+= $tabprice[10];
1479
+				$this->total_ht += $tabprice[0];
1480
+				$this->total_tva += $tabprice[1];
1481
+				$this->total_ttc += $tabprice[2];
1482
+				$this->total_localtax1 += $tabprice[9];
1483
+				$this->total_localtax2 += $tabprice[10];
1484 1484
 
1485 1485
 				// Multicurrency
1486
-				$this->fk_multicurrency 		= $obj->fk_multicurrency;
1487
-				$this->multicurrency_code 		= $obj->multicurrency_code;
1486
+				$this->fk_multicurrency = $obj->fk_multicurrency;
1487
+				$this->multicurrency_code = $obj->multicurrency_code;
1488 1488
 				$this->multicurrency_subprice 	= $obj->multicurrency_subprice;
1489 1489
 				$this->multicurrency_total_ht 	= $obj->multicurrency_total_ht;
1490 1490
 				$this->multicurrency_total_tva 	= $obj->multicurrency_total_tva;
@@ -1496,7 +1496,7 @@  discard block
 block discarded – undo
1496 1496
 				}
1497 1497
 
1498 1498
 				// Detail of batch
1499
-				if (! empty($conf->productbatch->enabled) && $obj->line_id > 0 && $obj->product_tobatch > 0)
1499
+				if (!empty($conf->productbatch->enabled) && $obj->line_id > 0 && $obj->product_tobatch > 0)
1500 1500
 				{
1501 1501
 					require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';
1502 1502
 
@@ -1521,7 +1521,7 @@  discard block
 block discarded – undo
1521 1521
 				}
1522 1522
 				else
1523 1523
 				{
1524
-					$line->total_ht			+= $tabprice[0];
1524
+					$line->total_ht += $tabprice[0];
1525 1525
 					$line->total_localtax1 	+= $tabprice[9];
1526 1526
 					$line->total_localtax2 	+= $tabprice[10];
1527 1527
 					$line->total_ttc	 	+= $tabprice[2];
@@ -1536,7 +1536,7 @@  discard block
 block discarded – undo
1536 1536
 		}
1537 1537
 		else
1538 1538
 		{
1539
-			$this->error=$this->db->error();
1539
+			$this->error = $this->db->error();
1540 1540
 			return -3;
1541 1541
 		}
1542 1542
 	}
@@ -1556,7 +1556,7 @@  discard block
 block discarded – undo
1556 1556
 		{
1557 1557
 			$this->db->begin();
1558 1558
 
1559
-			$line=new ExpeditionLigne($this->db);
1559
+			$line = new ExpeditionLigne($this->db);
1560 1560
 
1561 1561
 			// For triggers
1562 1562
 			$line->fetch($lineid);
@@ -1576,7 +1576,7 @@  discard block
 block discarded – undo
1576 1576
 		}
1577 1577
 		else
1578 1578
 		{
1579
-			$this->error='ErrorDeleteLineNotAllowedByObjectStatus';
1579
+			$this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
1580 1580
 			return -2;
1581 1581
 		}
1582 1582
 	}
@@ -1593,13 +1593,13 @@  discard block
 block discarded – undo
1593 1593
 	 *  @param      int     	$save_lastsearch_value		-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
1594 1594
 	 *	@return     string          						String with URL
1595 1595
 	 */
1596
-	function getNomUrl($withpicto=0, $option='', $max=0, $short=0, $notooltip=0, $save_lastsearch_value=-1)
1596
+	function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $notooltip = 0, $save_lastsearch_value = -1)
1597 1597
 	{
1598 1598
 		global $langs;
1599 1599
 
1600
-		$result='';
1601
-		$label = '<u>' . $langs->trans("ShowSending") . '</u>';
1602
-		$label .= '<br><b>' . $langs->trans('Ref') . ':</b> '.$this->ref;
1600
+		$result = '';
1601
+		$label = '<u>'.$langs->trans("ShowSending").'</u>';
1602
+		$label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1603 1603
 		$label .= '<br><b>'.$langs->trans('RefCustomer').':</b> '.($this->ref_customer ? $this->ref_customer : $this->ref_client);
1604 1604
 
1605 1605
 		$url = DOL_URL_ROOT.'/expedition/card.php?id='.$this->id;
@@ -1609,29 +1609,29 @@  discard block
 block discarded – undo
1609 1609
 		if ($option !== 'nolink')
1610 1610
 		{
1611 1611
 			// Add param to save lastsearch_values or not
1612
-			$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
1613
-			if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
1614
-			if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
1612
+			$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1613
+			if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
1614
+			if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
1615 1615
 		}
1616 1616
 
1617
-		$linkclose='';
1617
+		$linkclose = '';
1618 1618
 		if (empty($notooltip))
1619 1619
 		{
1620
-			if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1620
+			if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1621 1621
 			{
1622
-				$label=$langs->trans("ShowSending");
1623
-				$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
1622
+				$label = $langs->trans("ShowSending");
1623
+				$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1624 1624
 			}
1625
-			$linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
1626
-			$linkclose.=' class="classfortooltip"';
1625
+			$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
1626
+			$linkclose .= ' class="classfortooltip"';
1627 1627
 		}
1628 1628
 
1629 1629
 		$linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1630
-		$linkend='</a>';
1630
+		$linkend = '</a>';
1631 1631
 
1632 1632
 		$result .= $linkstart;
1633
-		if ($withpicto) $result.=img_object(($notooltip?'':$label), $this->picto, ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
1634
-		if ($withpicto != 2) $result.= $this->ref;
1633
+		if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1634
+		if ($withpicto != 2) $result .= $this->ref;
1635 1635
 		$result .= $linkend;
1636 1636
 
1637 1637
 		return $result;
@@ -1643,9 +1643,9 @@  discard block
 block discarded – undo
1643 1643
 	 *	@param      int		$mode      	0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto
1644 1644
 	 *	@return     string      		Libelle
1645 1645
 	 */
1646
-	function getLibStatut($mode=0)
1646
+	function getLibStatut($mode = 0)
1647 1647
 	{
1648
-		return $this->LibStatut($this->statut,$mode);
1648
+		return $this->LibStatut($this->statut, $mode);
1649 1649
 	}
1650 1650
 
1651 1651
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -1656,40 +1656,40 @@  discard block
 block discarded – undo
1656 1656
 	 * @param      int		$mode       0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto
1657 1657
 	 * @return     string				Label of status
1658 1658
 	 */
1659
-	function LibStatut($statut,$mode)
1659
+	function LibStatut($statut, $mode)
1660 1660
 	{
1661 1661
         // phpcs:enable
1662 1662
 		global $langs;
1663 1663
 
1664
-		if ($mode==0)
1664
+		if ($mode == 0)
1665 1665
 		{
1666
-			if ($statut==0) return $langs->trans($this->statuts[$statut]);
1667
-			elseif ($statut==1) return $langs->trans($this->statuts[$statut]);
1668
-			elseif ($statut==2) return $langs->trans($this->statuts[$statut]);
1666
+			if ($statut == 0) return $langs->trans($this->statuts[$statut]);
1667
+			elseif ($statut == 1) return $langs->trans($this->statuts[$statut]);
1668
+			elseif ($statut == 2) return $langs->trans($this->statuts[$statut]);
1669 1669
 		}
1670
-		elseif ($mode==1)
1670
+		elseif ($mode == 1)
1671 1671
 		{
1672
-			if ($statut==0) return $langs->trans($this->statutshorts[$statut]);
1673
-			elseif ($statut==1) return $langs->trans($this->statutshorts[$statut]);
1674
-			elseif ($statut==2) return $langs->trans($this->statutshorts[$statut]);
1672
+			if ($statut == 0) return $langs->trans($this->statutshorts[$statut]);
1673
+			elseif ($statut == 1) return $langs->trans($this->statutshorts[$statut]);
1674
+			elseif ($statut == 2) return $langs->trans($this->statutshorts[$statut]);
1675 1675
 		}
1676 1676
 		elseif ($mode == 3)
1677 1677
 		{
1678
-			if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0');
1679
-			elseif ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut4');
1680
-			elseif ($statut==2) return img_picto($langs->trans($this->statuts[$statut]),'statut6');
1678
+			if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]), 'statut0');
1679
+			elseif ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]), 'statut4');
1680
+			elseif ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]), 'statut6');
1681 1681
 		}
1682 1682
 		elseif ($mode == 4)
1683 1683
 		{
1684
-			if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
1685
-			elseif ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
1686
-			elseif ($statut==2) return img_picto($langs->trans($this->statuts[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]);
1684
+			if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]), 'statut0').' '.$langs->trans($this->statuts[$statut]);
1685
+			elseif ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]), 'statut4').' '.$langs->trans($this->statuts[$statut]);
1686
+			elseif ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]), 'statut6').' '.$langs->trans($this->statuts[$statut]);
1687 1687
 		}
1688 1688
 		elseif ($mode == 5)
1689 1689
 		{
1690
-			if ($statut==0) return $langs->trans($this->statutshorts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut0');
1691
-			elseif ($statut==1) return $langs->trans($this->statutshorts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut4');
1692
-			elseif ($statut==2) return $langs->trans($this->statutshorts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut6');
1690
+			if ($statut == 0) return $langs->trans($this->statutshorts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]), 'statut0');
1691
+			elseif ($statut == 1) return $langs->trans($this->statutshorts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]), 'statut4');
1692
+			elseif ($statut == 2) return $langs->trans($this->statutshorts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]), 'statut6');
1693 1693
 		}
1694 1694
 	}
1695 1695
 
@@ -1704,7 +1704,7 @@  discard block
 block discarded – undo
1704 1704
 	{
1705 1705
 		global $langs;
1706 1706
 
1707
-		$now=dol_now();
1707
+		$now = dol_now();
1708 1708
 
1709 1709
 		dol_syslog(get_class($this)."::initAsSpecimen");
1710 1710
 
@@ -1712,8 +1712,8 @@  discard block
 block discarded – undo
1712 1712
 		$num_prods = 0;
1713 1713
 		$prodids = array();
1714 1714
 		$sql = "SELECT rowid";
1715
-		$sql.= " FROM ".MAIN_DB_PREFIX."product";
1716
-		$sql.= " WHERE entity IN (".getEntity('product').")";
1715
+		$sql .= " FROM ".MAIN_DB_PREFIX."product";
1716
+		$sql .= " WHERE entity IN (".getEntity('product').")";
1717 1717
 		$resql = $this->db->query($sql);
1718 1718
 		if ($resql)
1719 1719
 		{
@@ -1727,20 +1727,20 @@  discard block
 block discarded – undo
1727 1727
 			}
1728 1728
 		}
1729 1729
 
1730
-		$order=new Commande($this->db);
1730
+		$order = new Commande($this->db);
1731 1731
 		$order->initAsSpecimen();
1732 1732
 
1733 1733
 		// Initialise parametres
1734
-		$this->id=0;
1734
+		$this->id = 0;
1735 1735
 		$this->ref = 'SPECIMEN';
1736
-		$this->specimen=1;
1736
+		$this->specimen = 1;
1737 1737
 		$this->statut               = 1;
1738 1738
 		$this->livraison_id         = 0;
1739 1739
 		$this->date                 = $now;
1740 1740
 		$this->date_creation        = $now;
1741 1741
 		$this->date_valid           = $now;
1742 1742
 		$this->date_delivery        = $now;
1743
-		$this->date_expedition      = $now + 24*3600;
1743
+		$this->date_expedition      = $now + 24 * 3600;
1744 1744
 
1745 1745
 		$this->entrepot_id          = 0;
1746 1746
 		$this->fk_delivery_address  = 0;
@@ -1752,22 +1752,22 @@  discard block
 block discarded – undo
1752 1752
 		$this->origin_id            = 1;
1753 1753
 		$this->origin               = 'commande';
1754 1754
 
1755
-		$this->note_private			= 'Private note';
1756
-		$this->note_public			= 'Public note';
1755
+		$this->note_private = 'Private note';
1756
+		$this->note_public = 'Public note';
1757 1757
 
1758 1758
 		$nbp = 5;
1759 1759
 		$xnbp = 0;
1760 1760
 		while ($xnbp < $nbp)
1761 1761
 		{
1762
-			$line=new ExpeditionLigne($this->db);
1763
-			$line->desc=$langs->trans("Description")." ".$xnbp;
1764
-			$line->libelle=$langs->trans("Description")." ".$xnbp;
1765
-			$line->qty=10;
1766
-			$line->qty_asked=5;
1767
-			$line->qty_shipped=4;
1768
-			$line->fk_product=$this->commande->lines[$xnbp]->fk_product;
1769
-
1770
-			$this->lines[]=$line;
1762
+			$line = new ExpeditionLigne($this->db);
1763
+			$line->desc = $langs->trans("Description")." ".$xnbp;
1764
+			$line->libelle = $langs->trans("Description")." ".$xnbp;
1765
+			$line->qty = 10;
1766
+			$line->qty_asked = 5;
1767
+			$line->qty_shipped = 4;
1768
+			$line->fk_product = $this->commande->lines[$xnbp]->fk_product;
1769
+
1770
+			$this->lines[] = $line;
1771 1771
 			$xnbp++;
1772 1772
 		}
1773 1773
 	}
@@ -1786,11 +1786,11 @@  discard block
 block discarded – undo
1786 1786
 		if ($user->rights->expedition->creer)
1787 1787
 		{
1788 1788
 			$sql = "UPDATE ".MAIN_DB_PREFIX."expedition";
1789
-			$sql.= " SET date_delivery = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null');
1790
-			$sql.= " WHERE rowid = ".$this->id;
1789
+			$sql .= " SET date_delivery = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null');
1790
+			$sql .= " WHERE rowid = ".$this->id;
1791 1791
 
1792 1792
 			dol_syslog(get_class($this)."::set_date_livraison", LOG_DEBUG);
1793
-			$resql=$this->db->query($sql);
1793
+			$resql = $this->db->query($sql);
1794 1794
 			if ($resql)
1795 1795
 			{
1796 1796
 				$this->date_delivery = $date_livraison;
@@ -1798,7 +1798,7 @@  discard block
 block discarded – undo
1798 1798
 			}
1799 1799
 			else
1800 1800
 			{
1801
-				$this->error=$this->db->error();
1801
+				$this->error = $this->db->error();
1802 1802
 				return -1;
1803 1803
 			}
1804 1804
 		}
@@ -1821,17 +1821,17 @@  discard block
 block discarded – undo
1821 1821
 		$this->meths = array();
1822 1822
 
1823 1823
 		$sql = "SELECT em.rowid, em.code, em.libelle";
1824
-		$sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1825
-		$sql.= " WHERE em.active = 1";
1826
-		$sql.= " ORDER BY em.libelle ASC";
1824
+		$sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1825
+		$sql .= " WHERE em.active = 1";
1826
+		$sql .= " ORDER BY em.libelle ASC";
1827 1827
 
1828 1828
 		$resql = $this->db->query($sql);
1829 1829
 		if ($resql)
1830 1830
 		{
1831 1831
 			while ($obj = $this->db->fetch_object($resql))
1832 1832
 			{
1833
-				$label=$langs->trans('SendingMethod'.$obj->code);
1834
-				$this->meths[$obj->rowid] = ($label != 'SendingMethod'.$obj->code?$label:$obj->libelle);
1833
+				$label = $langs->trans('SendingMethod'.$obj->code);
1834
+				$this->meths[$obj->rowid] = ($label != 'SendingMethod'.$obj->code ? $label : $obj->libelle);
1835 1835
 			}
1836 1836
 		}
1837 1837
 	}
@@ -1843,17 +1843,17 @@  discard block
 block discarded – undo
1843 1843
 	 *  @param  id      $id     only this carrier, all if none
1844 1844
 	 *  @return void
1845 1845
 	 */
1846
-	function list_delivery_methods($id='')
1846
+	function list_delivery_methods($id = '')
1847 1847
 	{
1848 1848
         // phpcs:enable
1849 1849
 		global $langs;
1850 1850
 
1851 1851
 		$this->listmeths = array();
1852
-		$i=0;
1852
+		$i = 0;
1853 1853
 
1854 1854
 		$sql = "SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1855
-		$sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1856
-		if ($id!='') $sql.= " WHERE em.rowid=".$id;
1855
+		$sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1856
+		if ($id != '') $sql .= " WHERE em.rowid=".$id;
1857 1857
 
1858 1858
 		$resql = $this->db->query($sql);
1859 1859
 		if ($resql)
@@ -1862,8 +1862,8 @@  discard block
 block discarded – undo
1862 1862
 			{
1863 1863
 				$this->listmeths[$i]['rowid'] = $obj->rowid;
1864 1864
 				$this->listmeths[$i]['code'] = $obj->code;
1865
-				$label=$langs->trans('SendingMethod'.$obj->code);
1866
-				$this->listmeths[$i]['libelle'] = ($label != 'SendingMethod'.$obj->code?$label:$obj->libelle);
1865
+				$label = $langs->trans('SendingMethod'.$obj->code);
1866
+				$this->listmeths[$i]['libelle'] = ($label != 'SendingMethod'.$obj->code ? $label : $obj->libelle);
1867 1867
 				$this->listmeths[$i]['description'] = $obj->description;
1868 1868
 				$this->listmeths[$i]['tracking'] = $obj->tracking;
1869 1869
 				$this->listmeths[$i]['active'] = $obj->active;
@@ -1880,26 +1880,26 @@  discard block
 block discarded – undo
1880 1880
 	 *
1881 1881
 	 *  @return void
1882 1882
 	 */
1883
-	function update_delivery_method($id='')
1883
+	function update_delivery_method($id = '')
1884 1884
 	{
1885 1885
         // phpcs:enable
1886
-		if ($id=='')
1886
+		if ($id == '')
1887 1887
 		{
1888 1888
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX."c_shipment_mode (code, libelle, description, tracking)";
1889
-			$sql.=" VALUES ('".$this->db->escape($this->update['code'])."','".$this->db->escape($this->update['libelle'])."','".$this->db->escape($this->update['description'])."','".$this->db->escape($this->update['tracking'])."')";
1889
+			$sql .= " VALUES ('".$this->db->escape($this->update['code'])."','".$this->db->escape($this->update['libelle'])."','".$this->db->escape($this->update['description'])."','".$this->db->escape($this->update['tracking'])."')";
1890 1890
 			$resql = $this->db->query($sql);
1891 1891
 		}
1892 1892
 		else
1893 1893
 		{
1894 1894
 			$sql = "UPDATE ".MAIN_DB_PREFIX."c_shipment_mode SET";
1895
-			$sql.= " code='".$this->db->escape($this->update['code'])."'";
1896
-			$sql.= ",libelle='".$this->db->escape($this->update['libelle'])."'";
1897
-			$sql.= ",description='".$this->db->escape($this->update['description'])."'";
1898
-			$sql.= ",tracking='".$this->db->escape($this->update['tracking'])."'";
1899
-			$sql.= " WHERE rowid=".$id;
1895
+			$sql .= " code='".$this->db->escape($this->update['code'])."'";
1896
+			$sql .= ",libelle='".$this->db->escape($this->update['libelle'])."'";
1897
+			$sql .= ",description='".$this->db->escape($this->update['description'])."'";
1898
+			$sql .= ",tracking='".$this->db->escape($this->update['tracking'])."'";
1899
+			$sql .= " WHERE rowid=".$id;
1900 1900
 			$resql = $this->db->query($sql);
1901 1901
 		}
1902
-		if ($resql < 0) dol_print_error($this->db,'');
1902
+		if ($resql < 0) dol_print_error($this->db, '');
1903 1903
 	}
1904 1904
 
1905 1905
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -1914,7 +1914,7 @@  discard block
 block discarded – undo
1914 1914
 	{
1915 1915
         // phpcs:enable
1916 1916
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=1';
1917
-		$sql.= ' WHERE rowid='.$id;
1917
+		$sql .= ' WHERE rowid='.$id;
1918 1918
 
1919 1919
 		$resql = $this->db->query($sql);
1920 1920
 	}
@@ -1931,7 +1931,7 @@  discard block
 block discarded – undo
1931 1931
 	{
1932 1932
         // phpcs:enable
1933 1933
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=0';
1934
-		$sql.= ' WHERE rowid='.$id;
1934
+		$sql .= ' WHERE rowid='.$id;
1935 1935
 
1936 1936
 		$resql = $this->db->query($sql);
1937 1937
 	}
@@ -1943,13 +1943,13 @@  discard block
 block discarded – undo
1943 1943
 	 * @param	string	$value		Value
1944 1944
 	 * @return	void
1945 1945
 	 */
1946
-	function getUrlTrackingStatus($value='')
1946
+	function getUrlTrackingStatus($value = '')
1947 1947
 	{
1948
-		if (! empty($this->shipping_method_id))
1948
+		if (!empty($this->shipping_method_id))
1949 1949
 		{
1950 1950
 			$sql = "SELECT em.code, em.tracking";
1951
-			$sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1952
-			$sql.= " WHERE em.rowid = ".$this->shipping_method_id;
1951
+			$sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1952
+			$sql .= " WHERE em.rowid = ".$this->shipping_method_id;
1953 1953
 
1954 1954
 			$resql = $this->db->query($sql);
1955 1955
 			if ($resql)
@@ -1964,7 +1964,7 @@  discard block
 block discarded – undo
1964 1964
 		if (!empty($tracking) && !empty($value))
1965 1965
 		{
1966 1966
 			$url = str_replace('{TRACKID}', $value, $tracking);
1967
-			$this->tracking_url = sprintf('<a target="_blank" href="%s">'.($value?$value:'url').'</a>',$url,$url);
1967
+			$this->tracking_url = sprintf('<a target="_blank" href="%s">'.($value ? $value : 'url').'</a>', $url, $url);
1968 1968
 		}
1969 1969
 		else
1970 1970
 		{
@@ -1979,16 +1979,16 @@  discard block
 block discarded – undo
1979 1979
 	 */
1980 1980
 	function setClosed()
1981 1981
 	{
1982
-		global $conf,$langs,$user;
1982
+		global $conf, $langs, $user;
1983 1983
 
1984
-		$error=0;
1984
+		$error = 0;
1985 1985
 
1986 1986
 		$this->db->begin();
1987 1987
 
1988 1988
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut='.self::STATUS_CLOSED;
1989 1989
 		$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0';
1990 1990
 
1991
-		$resql=$this->db->query($sql);
1991
+		$resql = $this->db->query($sql);
1992 1992
 		if ($resql)
1993 1993
 		{
1994 1994
 			// Set order billed if 100% of order is shipped (qty in shipment lines match qty in order lines)
@@ -1997,17 +1997,17 @@  discard block
 block discarded – undo
1997 1997
 				$order = new Commande($this->db);
1998 1998
 				$order->fetch($this->origin_id);
1999 1999
 
2000
-				$order->loadExpeditions(self::STATUS_CLOSED);		// Fill $order->expeditions = array(orderlineid => qty)
2000
+				$order->loadExpeditions(self::STATUS_CLOSED); // Fill $order->expeditions = array(orderlineid => qty)
2001 2001
 
2002 2002
 				$shipments_match_order = 1;
2003
-				foreach($order->lines as $line)
2003
+				foreach ($order->lines as $line)
2004 2004
 				{
2005 2005
 					$lineid = $line->id;
2006 2006
 					$qty = $line->qty;
2007
-					if (($line->product_type == 0 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->expeditions[$lineid] != $qty)
2007
+					if (($line->product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->expeditions[$lineid] != $qty)
2008 2008
 					{
2009 2009
 						$shipments_match_order = 0;
2010
-						$text='Qty for order line id '.$lineid.' is '.$qty.'. However in the shipments with status Expedition::STATUS_CLOSED='.self::STATUS_CLOSED.' we have qty = '.$order->expeditions[$lineid].', so we can t close order';
2010
+						$text = 'Qty for order line id '.$lineid.' is '.$qty.'. However in the shipments with status Expedition::STATUS_CLOSED='.self::STATUS_CLOSED.' we have qty = '.$order->expeditions[$lineid].', so we can t close order';
2011 2011
 						dol_syslog($text);
2012 2012
 						break;
2013 2013
 					}
@@ -2019,11 +2019,11 @@  discard block
 block discarded – undo
2019 2019
 				}
2020 2020
 			}
2021 2021
 
2022
-			$this->statut=self::STATUS_CLOSED;
2022
+			$this->statut = self::STATUS_CLOSED;
2023 2023
 
2024 2024
 
2025 2025
 			// If stock increment is done on closing
2026
-			if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE))
2026
+			if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE))
2027 2027
 			{
2028 2028
 				require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
2029 2029
 
@@ -2032,16 +2032,16 @@  discard block
 block discarded – undo
2032 2032
 				// Loop on each product line to add a stock movement
2033 2033
 				// TODO possibilite d'expedier a partir d'une propale ou autre origine ?
2034 2034
 				$sql = "SELECT cd.fk_product, cd.subprice,";
2035
-				$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
2036
-				$sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
2037
-				$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
2038
-				$sql.= " ".MAIN_DB_PREFIX."expeditiondet as ed";
2039
-				$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
2040
-				$sql.= " WHERE ed.fk_expedition = ".$this->id;
2041
-				$sql.= " AND cd.rowid = ed.fk_origin_line";
2035
+				$sql .= " ed.rowid, ed.qty, ed.fk_entrepot,";
2036
+				$sql .= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
2037
+				$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
2038
+				$sql .= " ".MAIN_DB_PREFIX."expeditiondet as ed";
2039
+				$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
2040
+				$sql .= " WHERE ed.fk_expedition = ".$this->id;
2041
+				$sql .= " AND cd.rowid = ed.fk_origin_line";
2042 2042
 
2043 2043
 				dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
2044
-				$resql=$this->db->query($sql);
2044
+				$resql = $this->db->query($sql);
2045 2045
 				if ($resql)
2046 2046
 				{
2047 2047
 					$cpt = $this->db->num_rows($resql);
@@ -2067,7 +2067,7 @@  discard block
 block discarded – undo
2067 2067
 							// line without batch detail
2068 2068
 
2069 2069
 							// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
2070
-							$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentClassifyClosedInDolibarr",$numref));
2070
+							$result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentClassifyClosedInDolibarr", $numref));
2071 2071
 							if ($result < 0) {
2072 2072
 								$this->error = $mouvS->error;
2073 2073
 								$this->errors = $mouvS->errors;
@@ -2079,7 +2079,7 @@  discard block
 block discarded – undo
2079 2079
 							// line with batch detail
2080 2080
 
2081 2081
 							// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
2082
-							$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentClassifyClosedInDolibarr",$numref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
2082
+							$result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentClassifyClosedInDolibarr", $numref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
2083 2083
 							if ($result < 0) {
2084 2084
 								$this->error = $mouvS->error;
2085 2085
 								$this->errors = $mouvS->errors;
@@ -2090,15 +2090,15 @@  discard block
 block discarded – undo
2090 2090
 				}
2091 2091
 				else
2092 2092
 				{
2093
-					$this->error=$this->db->lasterror();
2093
+					$this->error = $this->db->lasterror();
2094 2094
 					$error++;
2095 2095
 				}
2096 2096
 			}
2097 2097
 
2098 2098
 			// Call trigger
2099
-			if (! $error)
2099
+			if (!$error)
2100 2100
 			{
2101
-				$result=$this->call_trigger('SHIPPING_CLOSED',$user);
2101
+				$result = $this->call_trigger('SHIPPING_CLOSED', $user);
2102 2102
 				if ($result < 0) {
2103 2103
 					$error++;
2104 2104
 				}
@@ -2110,7 +2110,7 @@  discard block
 block discarded – undo
2110 2110
 			$error++;
2111 2111
 		}
2112 2112
 
2113
-		if (! $error)
2113
+		if (!$error)
2114 2114
 		{
2115 2115
 			$this->db->commit();
2116 2116
 			return 1;
@@ -2132,27 +2132,27 @@  discard block
 block discarded – undo
2132 2132
 	{
2133 2133
         // phpcs:enable
2134 2134
 		global $user;
2135
-		$error=0;
2135
+		$error = 0;
2136 2136
 
2137 2137
 		$this->db->begin();
2138 2138
 
2139
-		$sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=2, billed=1';    // TODO Update only billed
2139
+		$sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=2, billed=1'; // TODO Update only billed
2140 2140
 		$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0';
2141 2141
 
2142
-		$resql=$this->db->query($sql);
2142
+		$resql = $this->db->query($sql);
2143 2143
 		if ($resql)
2144 2144
 		{
2145
-			$this->statut=2;
2146
-			$this->billed=1;
2145
+			$this->statut = 2;
2146
+			$this->billed = 1;
2147 2147
 
2148 2148
 			// Call trigger
2149
-			$result=$this->call_trigger('SHIPPING_BILLED',$user);
2149
+			$result = $this->call_trigger('SHIPPING_BILLED', $user);
2150 2150
 			if ($result < 0) {
2151 2151
 				$error++;
2152 2152
 			}
2153 2153
 		} else {
2154 2154
 			$error++;
2155
-			$this->errors[]=$this->db->lasterror;
2155
+			$this->errors[] = $this->db->lasterror;
2156 2156
 		}
2157 2157
 
2158 2158
 		if (empty($error)) {
@@ -2173,9 +2173,9 @@  discard block
 block discarded – undo
2173 2173
 	 */
2174 2174
 	function reOpen()
2175 2175
 	{
2176
-		global $conf,$langs,$user;
2176
+		global $conf, $langs, $user;
2177 2177
 
2178
-		$error=0;
2178
+		$error = 0;
2179 2179
 
2180 2180
 		// Protection. This avoid to move stock later when we should not
2181 2181
 		if ($this->statut == self::STATUS_VALIDATED)
@@ -2188,14 +2188,14 @@  discard block
 block discarded – undo
2188 2188
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=1';
2189 2189
 		$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0';
2190 2190
 
2191
-		$resql=$this->db->query($sql);
2191
+		$resql = $this->db->query($sql);
2192 2192
 		if ($resql)
2193 2193
 		{
2194
-			$this->statut=1;
2195
-			$this->billed=0;
2194
+			$this->statut = 1;
2195
+			$this->billed = 0;
2196 2196
 
2197 2197
 			// If stock increment is done on closing
2198
-			if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE))
2198
+			if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE))
2199 2199
 			{
2200 2200
 				require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
2201 2201
 
@@ -2204,16 +2204,16 @@  discard block
 block discarded – undo
2204 2204
 				// Loop on each product line to add a stock movement
2205 2205
 				// TODO possibilite d'expedier a partir d'une propale ou autre origine
2206 2206
 				$sql = "SELECT cd.fk_product, cd.subprice,";
2207
-				$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
2208
-				$sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
2209
-				$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
2210
-				$sql.= " ".MAIN_DB_PREFIX."expeditiondet as ed";
2211
-				$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
2212
-				$sql.= " WHERE ed.fk_expedition = ".$this->id;
2213
-				$sql.= " AND cd.rowid = ed.fk_origin_line";
2207
+				$sql .= " ed.rowid, ed.qty, ed.fk_entrepot,";
2208
+				$sql .= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
2209
+				$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
2210
+				$sql .= " ".MAIN_DB_PREFIX."expeditiondet as ed";
2211
+				$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
2212
+				$sql .= " WHERE ed.fk_expedition = ".$this->id;
2213
+				$sql .= " AND cd.rowid = ed.fk_origin_line";
2214 2214
 
2215 2215
 				dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
2216
-				$resql=$this->db->query($sql);
2216
+				$resql = $this->db->query($sql);
2217 2217
 				if ($resql)
2218 2218
 				{
2219 2219
 					$cpt = $this->db->num_rows($resql);
@@ -2240,7 +2240,7 @@  discard block
 block discarded – undo
2240 2240
 							// line without batch detail
2241 2241
 
2242 2242
 							// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
2243
-							$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ShipmentUnClassifyCloseddInDolibarr",$numref));
2243
+							$result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ShipmentUnClassifyCloseddInDolibarr", $numref));
2244 2244
 							if ($result < 0) {
2245 2245
 								$this->error = $mouvS->error;
2246 2246
 								$this->errors = $mouvS->errors;
@@ -2252,7 +2252,7 @@  discard block
 block discarded – undo
2252 2252
 							// line with batch detail
2253 2253
 
2254 2254
 							// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
2255
-							$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ShipmentUnClassifyCloseddInDolibarr",$numref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
2255
+							$result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ShipmentUnClassifyCloseddInDolibarr", $numref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
2256 2256
 							if ($result < 0) {
2257 2257
 								$this->error = $mouvS->error;
2258 2258
 								$this->errors = $mouvS->errors;
@@ -2263,25 +2263,25 @@  discard block
 block discarded – undo
2263 2263
 				}
2264 2264
 				else
2265 2265
 				{
2266
-					$this->error=$this->db->lasterror();
2266
+					$this->error = $this->db->lasterror();
2267 2267
 					$error++;
2268 2268
 				}
2269 2269
 			}
2270 2270
 
2271
-			if (! $error)
2271
+			if (!$error)
2272 2272
 			{
2273 2273
 				// Call trigger
2274
-				$result=$this->call_trigger('SHIPPING_REOPEN',$user);
2274
+				$result = $this->call_trigger('SHIPPING_REOPEN', $user);
2275 2275
 				if ($result < 0) {
2276 2276
 					$error++;
2277 2277
 				}
2278 2278
    			}
2279 2279
 		} else {
2280 2280
 			$error++;
2281
-			$this->errors[]=$this->db->lasterror();
2281
+			$this->errors[] = $this->db->lasterror();
2282 2282
 		}
2283 2283
 
2284
-		if (! $error)
2284
+		if (!$error)
2285 2285
 		{
2286 2286
 			$this->db->commit();
2287 2287
 			return 1;
@@ -2304,19 +2304,19 @@  discard block
 block discarded – undo
2304 2304
      *  @param      null|array  $moreparams     Array to provide more information
2305 2305
 	 *  @return     int         				0 if KO, 1 if OK
2306 2306
 	 */
2307
-	public function generateDocument($modele, $outputlangs,$hidedetails=0, $hidedesc=0, $hideref=0,$moreparams=null)
2307
+	public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
2308 2308
 	{
2309
-		global $conf,$langs;
2309
+		global $conf, $langs;
2310 2310
 
2311 2311
 		$langs->load("sendings");
2312 2312
 
2313
-		if (! dol_strlen($modele)) {
2313
+		if (!dol_strlen($modele)) {
2314 2314
 
2315 2315
 			$modele = 'rouget';
2316 2316
 
2317 2317
 			if ($this->modelpdf) {
2318 2318
 				$modele = $this->modelpdf;
2319
-			} elseif (! empty($conf->global->EXPEDITION_ADDON_PDF)) {
2319
+			} elseif (!empty($conf->global->EXPEDITION_ADDON_PDF)) {
2320 2320
 				$modele = $conf->global->EXPEDITION_ADDON_PDF;
2321 2321
 			}
2322 2322
 		}
@@ -2325,7 +2325,7 @@  discard block
 block discarded – undo
2325 2325
 
2326 2326
 		$this->fetch_origin();
2327 2327
 
2328
-		return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref,$moreparams);
2328
+		return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2329 2329
 	}
2330 2330
 
2331 2331
 	/**
@@ -2355,12 +2355,12 @@  discard block
 block discarded – undo
2355 2355
 	/**
2356 2356
 	 * @var string ID to identify managed object
2357 2357
 	 */
2358
-	public $element='expeditiondet';
2358
+	public $element = 'expeditiondet';
2359 2359
 
2360 2360
 	/**
2361 2361
 	 * @var string Name of table without prefix where object is stored
2362 2362
 	 */
2363
-	public $table_element='expeditiondet';
2363
+	public $table_element = 'expeditiondet';
2364 2364
 
2365 2365
 	/**
2366 2366
 	 * @deprecated
@@ -2505,7 +2505,7 @@  discard block
 block discarded – undo
2505 2505
      */
2506 2506
 	function __construct($db)
2507 2507
 	{
2508
-		$this->db=$db;
2508
+		$this->db = $db;
2509 2509
 	}
2510 2510
 
2511 2511
 	/**
@@ -2517,18 +2517,18 @@  discard block
 block discarded – undo
2517 2517
 	function fetch($rowid)
2518 2518
 	{
2519 2519
 		$sql = 'SELECT ed.rowid, ed.fk_expedition, ed.fk_entrepot, ed.fk_origin_line, ed.qty, ed.rang';
2520
-		$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as ed';
2521
-		$sql.= ' WHERE ed.rowid = '.$rowid;
2520
+		$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as ed';
2521
+		$sql .= ' WHERE ed.rowid = '.$rowid;
2522 2522
 		$result = $this->db->query($sql);
2523 2523
 		if ($result)
2524 2524
 		{
2525 2525
 			$objp = $this->db->fetch_object($result);
2526
-			$this->id				= $objp->rowid;
2527
-			$this->fk_expedition	= $objp->fk_expedition;
2528
-			$this->entrepot_id		= $objp->fk_entrepot;
2529
-			$this->fk_origin_line	= $objp->fk_origin_line;
2530
-			$this->qty				= $objp->qty;
2531
-			$this->rang				= $objp->rang;
2526
+			$this->id = $objp->rowid;
2527
+			$this->fk_expedition = $objp->fk_expedition;
2528
+			$this->entrepot_id = $objp->fk_entrepot;
2529
+			$this->fk_origin_line = $objp->fk_origin_line;
2530
+			$this->qty = $objp->qty;
2531
+			$this->rang = $objp->rang;
2532 2532
 
2533 2533
 			$this->db->free($result);
2534 2534
 
@@ -2549,34 +2549,34 @@  discard block
 block discarded – undo
2549 2549
 	 *	@param      int		$notrigger		1 = disable triggers
2550 2550
 	 *	@return     int						<0 if KO, line id >0 if OK
2551 2551
 	 */
2552
-	function insert($user=null, $notrigger=0)
2552
+	function insert($user = null, $notrigger = 0)
2553 2553
 	{
2554 2554
 		global $langs, $conf;
2555 2555
 
2556
-		$error=0;
2556
+		$error = 0;
2557 2557
 
2558 2558
 		// Check parameters
2559
-		if (empty($this->fk_expedition) || empty($this->fk_origin_line) || ! is_numeric($this->qty))
2559
+		if (empty($this->fk_expedition) || empty($this->fk_origin_line) || !is_numeric($this->qty))
2560 2560
 		{
2561 2561
 			$this->error = 'ErrorMandatoryParametersNotProvided';
2562 2562
 			return -1;
2563 2563
 		}
2564 2564
 		// Clean parameters
2565
-		if (empty($this->entrepot_id)) $this->entrepot_id='null';
2565
+		if (empty($this->entrepot_id)) $this->entrepot_id = 'null';
2566 2566
 
2567 2567
 		$this->db->begin();
2568 2568
 
2569 2569
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."expeditiondet (";
2570
-		$sql.= "fk_expedition";
2571
-		$sql.= ", fk_entrepot";
2572
-		$sql.= ", fk_origin_line";
2573
-		$sql.= ", qty";
2574
-		$sql.= ") VALUES (";
2575
-		$sql.= $this->fk_expedition;
2576
-		$sql.= ", ".$this->entrepot_id;
2577
-		$sql.= ", ".$this->fk_origin_line;
2578
-		$sql.= ", ".$this->qty;
2579
-		$sql.= ")";
2570
+		$sql .= "fk_expedition";
2571
+		$sql .= ", fk_entrepot";
2572
+		$sql .= ", fk_origin_line";
2573
+		$sql .= ", qty";
2574
+		$sql .= ") VALUES (";
2575
+		$sql .= $this->fk_expedition;
2576
+		$sql .= ", ".$this->entrepot_id;
2577
+		$sql .= ", ".$this->fk_origin_line;
2578
+		$sql .= ", ".$this->qty;
2579
+		$sql .= ")";
2580 2580
 
2581 2581
 		dol_syslog(get_class($this)."::insert", LOG_DEBUG);
2582 2582
 		$resql = $this->db->query($sql);
@@ -2584,19 +2584,19 @@  discard block
 block discarded – undo
2584 2584
 		{
2585 2585
 			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."expeditiondet");
2586 2586
 
2587
-			if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))
2587
+			if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))
2588 2588
 			{
2589
-				$result=$this->insertExtraFields();
2589
+				$result = $this->insertExtraFields();
2590 2590
 				if ($result < 0)
2591 2591
 				{
2592 2592
 					$error++;
2593 2593
 				}
2594 2594
 			}
2595 2595
 
2596
-			if (! $error && ! $notrigger)
2596
+			if (!$error && !$notrigger)
2597 2597
 			{
2598 2598
 				// Call trigger
2599
-				$result=$this->call_trigger('LINESHIPPING_INSERT',$user);
2599
+				$result = $this->call_trigger('LINESHIPPING_INSERT', $user);
2600 2600
 				if ($result < 0)
2601 2601
 				{
2602 2602
 					$error++;
@@ -2604,19 +2604,19 @@  discard block
 block discarded – undo
2604 2604
 				// End call triggers
2605 2605
 			}
2606 2606
 
2607
-			if (! $error) {
2607
+			if (!$error) {
2608 2608
 				$this->db->commit();
2609 2609
 				return $this->id;
2610 2610
 			}
2611 2611
 
2612
-			foreach($this->errors as $errmsg)
2612
+			foreach ($this->errors as $errmsg)
2613 2613
 			{
2614 2614
 				dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
2615
-				$this->error.=($this->error?', '.$errmsg:$errmsg);
2615
+				$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
2616 2616
 			}
2617 2617
 
2618 2618
 			$this->db->rollback();
2619
-			return -1*$error;
2619
+			return -1 * $error;
2620 2620
 		}
2621 2621
 		else
2622 2622
 		{
@@ -2635,7 +2635,7 @@  discard block
 block discarded – undo
2635 2635
 	{
2636 2636
 		global $conf;
2637 2637
 
2638
-		$error=0;
2638
+		$error = 0;
2639 2639
 
2640 2640
 		$this->db->begin();
2641 2641
 
@@ -2643,37 +2643,37 @@  discard block
 block discarded – undo
2643 2643
 		if ($conf->productbatch->enabled)
2644 2644
 		{
2645 2645
 			$sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet_batch";
2646
-			$sql.= " WHERE fk_expeditiondet = ".$this->id;
2646
+			$sql .= " WHERE fk_expeditiondet = ".$this->id;
2647 2647
 
2648 2648
 			if (!$this->db->query($sql))
2649 2649
 			{
2650
-				$this->errors[]=$this->db->lasterror()." - sql=$sql";
2650
+				$this->errors[] = $this->db->lasterror()." - sql=$sql";
2651 2651
 				$error++;
2652 2652
 			}
2653 2653
 		}
2654 2654
 
2655 2655
 		$sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet";
2656
-		$sql.= " WHERE rowid = ".$this->id;
2656
+		$sql .= " WHERE rowid = ".$this->id;
2657 2657
 
2658
-		if (! $error && $this->db->query($sql))
2658
+		if (!$error && $this->db->query($sql))
2659 2659
 		{
2660 2660
 			// Remove extrafields
2661 2661
 			if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
2662 2662
 			{
2663
-				$result=$this->deleteExtraFields();
2663
+				$result = $this->deleteExtraFields();
2664 2664
 				if ($result < 0)
2665 2665
 				{
2666
-					$this->errors[]=$this->error;
2666
+					$this->errors[] = $this->error;
2667 2667
 					$error++;
2668 2668
 				}
2669 2669
 			}
2670
-			if (! $error && ! $notrigger)
2670
+			if (!$error && !$notrigger)
2671 2671
 			{
2672 2672
 				// Call trigger
2673
-				$result=$this->call_trigger('LINESHIPPING_DELETE',$user);
2673
+				$result = $this->call_trigger('LINESHIPPING_DELETE', $user);
2674 2674
 				if ($result < 0)
2675 2675
 				{
2676
-					$this->errors[]=$this->error;
2676
+					$this->errors[] = $this->error;
2677 2677
 					$error++;
2678 2678
 				}
2679 2679
 				// End call triggers
@@ -2681,23 +2681,23 @@  discard block
 block discarded – undo
2681 2681
 		}
2682 2682
 		else
2683 2683
 		{
2684
-			$this->errors[]=$this->db->lasterror()." - sql=$sql";
2684
+			$this->errors[] = $this->db->lasterror()." - sql=$sql";
2685 2685
 			$error++;
2686 2686
 		}
2687 2687
 
2688
-		if (! $error) {
2688
+		if (!$error) {
2689 2689
 			$this->db->commit();
2690 2690
 			return 1;
2691 2691
 		}
2692 2692
 		else
2693 2693
 		{
2694
-			foreach($this->errors as $errmsg)
2694
+			foreach ($this->errors as $errmsg)
2695 2695
 			{
2696 2696
 				dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
2697
-				$this->error.=($this->error?', '.$errmsg:$errmsg);
2697
+				$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
2698 2698
 			}
2699 2699
 			$this->db->rollback();
2700
-			return -1*$error;
2700
+			return -1 * $error;
2701 2701
 		}
2702 2702
 	}
2703 2703
 
@@ -2712,15 +2712,15 @@  discard block
 block discarded – undo
2712 2712
 	{
2713 2713
 		global $conf;
2714 2714
 
2715
-		$error=0;
2715
+		$error = 0;
2716 2716
 
2717 2717
 		dol_syslog(get_class($this)."::update id=$this->id, entrepot_id=$this->entrepot_id, product_id=$this->fk_product, qty=$this->qty");
2718 2718
 
2719 2719
 		$this->db->begin();
2720 2720
 
2721 2721
 		// Clean parameters
2722
-		if (empty($this->qty)) $this->qty=0;
2723
-		$qty=price2num($this->qty);
2722
+		if (empty($this->qty)) $this->qty = 0;
2723
+		$qty = price2num($this->qty);
2724 2724
 		$remainingQty = 0;
2725 2725
 		$batch = null;
2726 2726
 		$batch_id = null;
@@ -2730,7 +2730,7 @@  discard block
 block discarded – undo
2730 2730
 			if (count($this->detail_batch) > 1)
2731 2731
 			{
2732 2732
 				dol_syslog(get_class($this).'::update only possible for one batch', LOG_ERR);
2733
-				$this->errors[]='ErrorBadParameters';
2733
+				$this->errors[] = 'ErrorBadParameters';
2734 2734
 				$error++;
2735 2735
 			}
2736 2736
 			else
@@ -2741,13 +2741,13 @@  discard block
 block discarded – undo
2741 2741
 				if ($this->entrepot_id != $this->detail_batch[0]->entrepot_id)
2742 2742
 				{
2743 2743
 					dol_syslog(get_class($this).'::update only possible for batch of same warehouse', LOG_ERR);
2744
-					$this->errors[]='ErrorBadParameters';
2744
+					$this->errors[] = 'ErrorBadParameters';
2745 2745
 					$error++;
2746 2746
 				}
2747 2747
 				$qty = price2num($this->detail_batch[0]->qty);
2748 2748
 			}
2749 2749
 		}
2750
-		else if (! empty($this->detail_batch))
2750
+		else if (!empty($this->detail_batch))
2751 2751
 		{
2752 2752
 			$batch = $this->detail_batch->batch;
2753 2753
 			$batch_id = $this->detail_batch->fk_origin_stock;
@@ -2755,38 +2755,38 @@  discard block
 block discarded – undo
2755 2755
 			if ($this->entrepot_id != $this->detail_batch->entrepot_id)
2756 2756
 			{
2757 2757
 				dol_syslog(get_class($this).'::update only possible for batch of same warehouse', LOG_ERR);
2758
-				$this->errors[]='ErrorBadParameters';
2758
+				$this->errors[] = 'ErrorBadParameters';
2759 2759
 				$error++;
2760 2760
 			}
2761 2761
 			$qty = price2num($this->detail_batch->qty);
2762 2762
 		}
2763 2763
 
2764 2764
 		// check parameters
2765
-		if (! isset($this->id) || ! isset($this->entrepot_id))
2765
+		if (!isset($this->id) || !isset($this->entrepot_id))
2766 2766
 		{
2767 2767
 			dol_syslog(get_class($this).'::update missing line id and/or warehouse id', LOG_ERR);
2768
-			$this->errors[]='ErrorMandatoryParametersNotProvided';
2768
+			$this->errors[] = 'ErrorMandatoryParametersNotProvided';
2769 2769
 			$error++;
2770 2770
 			return -1;
2771 2771
 		}
2772 2772
 
2773 2773
 		// update lot
2774 2774
 
2775
-		if (! empty($batch) && $conf->productbatch->enabled)
2775
+		if (!empty($batch) && $conf->productbatch->enabled)
2776 2776
 		{
2777 2777
 			dol_syslog(get_class($this)."::update expedition batch id=$expedition_batch_id, batch_id=$batch_id, batch=$batch");
2778 2778
 
2779 2779
 			if (empty($batch_id) || empty($this->fk_product)) {
2780 2780
 				dol_syslog(get_class($this).'::update missing fk_origin_stock (batch_id) and/or fk_product', LOG_ERR);
2781
-				$this->errors[]='ErrorMandatoryParametersNotProvided';
2781
+				$this->errors[] = 'ErrorMandatoryParametersNotProvided';
2782 2782
 				$error++;
2783 2783
 			}
2784 2784
 
2785 2785
 			// fetch remaining lot qty
2786 2786
 			require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';
2787
-			if (! $error && ($lotArray = ExpeditionLineBatch::fetchAll($this->db, $this->id)) < 0)
2787
+			if (!$error && ($lotArray = ExpeditionLineBatch::fetchAll($this->db, $this->id)) < 0)
2788 2788
 			{
2789
-				$this->errors[]=$this->db->lasterror()." - ExpeditionLineBatch::fetchAll";
2789
+				$this->errors[] = $this->db->lasterror()." - ExpeditionLineBatch::fetchAll";
2790 2790
 				$error++;
2791 2791
 			}
2792 2792
 			else
@@ -2806,25 +2806,25 @@  discard block
 block discarded – undo
2806 2806
 				// fetch from product_lot
2807 2807
 				require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
2808 2808
 				$lot = new Productlot($this->db);
2809
-				if ($lot->fetch(0,$this->fk_product,$batch) < 0)
2809
+				if ($lot->fetch(0, $this->fk_product, $batch) < 0)
2810 2810
 				{
2811 2811
 					$this->errors[] = $lot->errors;
2812 2812
 					$error++;
2813 2813
 				}
2814
-				if (! $error && ! empty($expedition_batch_id))
2814
+				if (!$error && !empty($expedition_batch_id))
2815 2815
 				{
2816 2816
 					// delete lot expedition line
2817 2817
 					$sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet_batch";
2818
-					$sql.= " WHERE fk_expeditiondet = ".$this->id;
2819
-					$sql.= " AND rowid = ".$expedition_batch_id;
2818
+					$sql .= " WHERE fk_expeditiondet = ".$this->id;
2819
+					$sql .= " AND rowid = ".$expedition_batch_id;
2820 2820
 
2821 2821
 					if (!$this->db->query($sql))
2822 2822
 					{
2823
-						$this->errors[]=$this->db->lasterror()." - sql=$sql";
2823
+						$this->errors[] = $this->db->lasterror()." - sql=$sql";
2824 2824
 						$error++;
2825 2825
 					}
2826 2826
 				}
2827
-				if (! $error && $this->detail_batch->qty > 0)
2827
+				if (!$error && $this->detail_batch->qty > 0)
2828 2828
 				{
2829 2829
 					// create lot expedition line
2830 2830
 					if (isset($lot->id))
@@ -2838,48 +2838,48 @@  discard block
 block discarded – undo
2838 2838
 						$shipmentLot->fk_origin_stock = $batch_id;
2839 2839
 						if ($shipmentLot->create($this->id) < 0)
2840 2840
 						{
2841
-							$this->errors[]=$shipmentLot->errors;
2841
+							$this->errors[] = $shipmentLot->errors;
2842 2842
 							$error++;
2843 2843
 						}
2844 2844
 					}
2845 2845
 				}
2846 2846
 			}
2847 2847
 		}
2848
-		if (! $error)
2848
+		if (!$error)
2849 2849
 		{
2850 2850
 			// update line
2851 2851
 			$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
2852
-			$sql.= " fk_entrepot = ".($this->entrepot_id > 0 ? $this->entrepot_id : 'null');
2853
-			$sql.= " , qty = ".$qty;
2854
-			$sql.= " WHERE rowid = ".$this->id;
2852
+			$sql .= " fk_entrepot = ".($this->entrepot_id > 0 ? $this->entrepot_id : 'null');
2853
+			$sql .= " , qty = ".$qty;
2854
+			$sql .= " WHERE rowid = ".$this->id;
2855 2855
 
2856 2856
 			if (!$this->db->query($sql))
2857 2857
 			{
2858
-				$this->errors[]=$this->db->lasterror()." - sql=$sql";
2858
+				$this->errors[] = $this->db->lasterror()." - sql=$sql";
2859 2859
 				$error++;
2860 2860
 			}
2861 2861
 		}
2862 2862
 
2863
-		if (! $error)
2863
+		if (!$error)
2864 2864
 		{
2865 2865
 			if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
2866 2866
 			{
2867
-				$result=$this->insertExtraFields();
2867
+				$result = $this->insertExtraFields();
2868 2868
 				if ($result < 0)
2869 2869
 				{
2870
-					$this->errors[]=$this->error;
2870
+					$this->errors[] = $this->error;
2871 2871
 					$error++;
2872 2872
 				}
2873 2873
 			}
2874 2874
 		}
2875 2875
 
2876
-		if (! $error && ! $notrigger)
2876
+		if (!$error && !$notrigger)
2877 2877
 		{
2878 2878
 			// Call trigger
2879
-			$result=$this->call_trigger('LINESHIPPING_UPDATE',$user);
2879
+			$result = $this->call_trigger('LINESHIPPING_UPDATE', $user);
2880 2880
 			if ($result < 0)
2881 2881
 			{
2882
-				$this->errors[]=$this->error;
2882
+				$this->errors[] = $this->error;
2883 2883
 				$error++;
2884 2884
 			}
2885 2885
 			// End call triggers
@@ -2890,13 +2890,13 @@  discard block
 block discarded – undo
2890 2890
 		}
2891 2891
 		else
2892 2892
 		{
2893
-			foreach($this->errors as $errmsg)
2893
+			foreach ($this->errors as $errmsg)
2894 2894
 			{
2895 2895
 				dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
2896
-				$this->error.=($this->error?', '.$errmsg:$errmsg);
2896
+				$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
2897 2897
 			}
2898 2898
 			$this->db->rollback();
2899
-			return -1*$error;
2899
+			return -1 * $error;
2900 2900
 		}
2901 2901
 	}
2902 2902
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/expedition/class/expeditionstats.class.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
24 24
  *  \brief      File of class fo tmanage shipment statistics
25 25
  */
26 26
 
27
-include_once DOL_DOCUMENT_ROOT . '/core/class/stats.class.php';
28
-include_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php';
29
-include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
27
+include_once DOL_DOCUMENT_ROOT.'/core/class/stats.class.php';
28
+include_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
29
+include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
30 30
 
31 31
 
32 32
 /**
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	 * @param 	string	$mode	   	Option (not used)
56 56
 	 * @param   int		$userid    	Id user for filter (creation user)
57 57
      */
58
-    function __construct($db, $socid, $mode, $userid=0)
58
+    function __construct($db, $socid, $mode, $userid = 0)
59 59
     {
60 60
 		global $user, $conf;
61 61
 
@@ -65,20 +65,20 @@  discard block
 block discarded – undo
65 65
         $this->userid = $userid;
66 66
 		$this->cachefilesuffix = $mode;
67 67
 
68
-        $object=new Expedition($this->db);
68
+        $object = new Expedition($this->db);
69 69
 		$this->from = MAIN_DB_PREFIX.$object->table_element." as c";
70 70
 		//$this->from.= ", ".MAIN_DB_PREFIX."societe as s";
71
-		$this->field='weight';	// Warning, unit of weight is NOT USED AND MUST BE
72
-		$this->where.= " c.fk_statut > 0";    // Not draft and not cancelled
71
+		$this->field = 'weight'; // Warning, unit of weight is NOT USED AND MUST BE
72
+		$this->where .= " c.fk_statut > 0"; // Not draft and not cancelled
73 73
 
74 74
 		//$this->where.= " AND c.fk_soc = s.rowid AND c.entity = ".$conf->entity;
75
-		$this->where.= " AND c.entity = ".$conf->entity;
76
-		if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
75
+		$this->where .= " AND c.entity = ".$conf->entity;
76
+		if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id;
77 77
 		if ($this->socid)
78 78
 		{
79
-			$this->where.=" AND c.fk_soc = ".$this->socid;
79
+			$this->where .= " AND c.fk_soc = ".$this->socid;
80 80
 		}
81
-        if ($this->userid > 0) $this->where.=' AND c.fk_user_author = '.$this->userid;
81
+        if ($this->userid > 0) $this->where .= ' AND c.fk_user_author = '.$this->userid;
82 82
     }
83 83
 
84 84
     /**
@@ -88,19 +88,19 @@  discard block
 block discarded – undo
88 88
      *	@param	int		$format		0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month
89 89
 	 * @return	array				Array with number by month
90 90
      */
91
-    function getNbByMonth($year, $format=0)
91
+    function getNbByMonth($year, $format = 0)
92 92
     {
93 93
         global $user;
94 94
 
95 95
         $sql = "SELECT date_format(c.date_valid,'%m') as dm, COUNT(*) as nb";
96
-		$sql.= " FROM ".$this->from;
96
+		$sql .= " FROM ".$this->from;
97 97
 		if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
98
-		$sql.= " WHERE c.date_valid BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
99
-		$sql.= " AND ".$this->where;
100
-		$sql.= " GROUP BY dm";
101
-        $sql.= $this->db->order('dm','DESC');
98
+		$sql .= " WHERE c.date_valid BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
99
+		$sql .= " AND ".$this->where;
100
+		$sql .= " GROUP BY dm";
101
+        $sql .= $this->db->order('dm', 'DESC');
102 102
 
103
-		$res=$this->_getNbByMonth($year, $sql, $format);
103
+		$res = $this->_getNbByMonth($year, $sql, $format);
104 104
 		return $res;
105 105
     }
106 106
 
@@ -115,11 +115,11 @@  discard block
 block discarded – undo
115 115
 		global $user;
116 116
 
117 117
 		$sql = "SELECT date_format(c.date_valid,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")";
118
-		$sql.= " FROM ".$this->from;
118
+		$sql .= " FROM ".$this->from;
119 119
 		if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
120
-		$sql.= " WHERE ".$this->where;
121
-		$sql.= " GROUP BY dm";
122
-        $sql.= $this->db->order('dm','DESC');
120
+		$sql .= " WHERE ".$this->where;
121
+		$sql .= " GROUP BY dm";
122
+        $sql .= $this->db->order('dm', 'DESC');
123 123
 
124 124
 		return $this->_getNbByYear($sql);
125 125
 	}
@@ -134,11 +134,11 @@  discard block
 block discarded – undo
134 134
 		global $user;
135 135
 
136 136
 		$sql = "SELECT date_format(c.date_valid,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->field.") as total, AVG(".$this->field.") as avg";
137
-		$sql.= " FROM ".$this->from;
137
+		$sql .= " FROM ".$this->from;
138 138
 		if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
139
-		$sql.= " WHERE ".$this->where;
140
-		$sql.= " GROUP BY year";
141
-        $sql.= $this->db->order('year','DESC');
139
+		$sql .= " WHERE ".$this->where;
140
+		$sql .= " GROUP BY year";
141
+        $sql .= $this->db->order('year', 'DESC');
142 142
 
143 143
 		return $this->_getAllByYear($sql);
144 144
 	}
Please login to merge, or discard this patch.
dolibarr/htdocs/expedition/class/api_shipments.class.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -65,16 +65,16 @@  discard block
 block discarded – undo
65 65
      */
66 66
     function get($id)
67 67
     {
68
-		if(! DolibarrApiAccess::$user->rights->expedition->lire) {
68
+		if (!DolibarrApiAccess::$user->rights->expedition->lire) {
69 69
 			throw new RestException(401);
70 70
 		}
71 71
 
72 72
         $result = $this->shipment->fetch($id);
73
-        if( ! $result ) {
73
+        if (!$result) {
74 74
             throw new RestException(404, 'Shipment not found');
75 75
         }
76 76
 
77
-		if( ! DolibarrApi::_checkAccessToResource('expedition',$this->shipment->id)) {
77
+		if (!DolibarrApi::_checkAccessToResource('expedition', $this->shipment->id)) {
78 78
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
79 79
 		}
80 80
 
@@ -110,18 +110,18 @@  discard block
 block discarded – undo
110 110
 
111 111
         // If the internal user must only see his customers, force searching by him
112 112
         $search_sale = 0;
113
-        if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
113
+        if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
114 114
 
115 115
         $sql = "SELECT t.rowid";
116 116
         if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
117
-        $sql.= " FROM ".MAIN_DB_PREFIX."expedition as t";
117
+        $sql .= " FROM ".MAIN_DB_PREFIX."expedition as t";
118 118
 
119
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
119
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
120 120
 
121
-        $sql.= ' WHERE t.entity IN ('.getEntity('expedition').')';
122
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc";
123
-        if ($socids) $sql.= " AND t.fk_soc IN (".$socids.")";
124
-        if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
121
+        $sql .= ' WHERE t.entity IN ('.getEntity('expedition').')';
122
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.fk_soc = sc.fk_soc";
123
+        if ($socids) $sql .= " AND t.fk_soc IN (".$socids.")";
124
+        if ($search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
125 125
         // Insert sale filter
126 126
         if ($search_sale > 0)
127 127
         {
@@ -130,23 +130,23 @@  discard block
 block discarded – undo
130 130
         // Add sql filters
131 131
         if ($sqlfilters)
132 132
         {
133
-            if (! DolibarrApi::_checkFilters($sqlfilters))
133
+            if (!DolibarrApi::_checkFilters($sqlfilters))
134 134
             {
135 135
                 throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
136 136
             }
137
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
138
-            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
137
+	        $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
138
+            $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
139 139
         }
140 140
 
141
-        $sql.= $db->order($sortfield, $sortorder);
142
-        if ($limit)	{
141
+        $sql .= $db->order($sortfield, $sortorder);
142
+        if ($limit) {
143 143
             if ($page < 0)
144 144
             {
145 145
                 $page = 0;
146 146
             }
147 147
             $offset = $limit * $page;
148 148
 
149
-            $sql.= $db->plimit($limit + 1, $offset);
149
+            $sql .= $db->plimit($limit + 1, $offset);
150 150
         }
151 151
 
152 152
         dol_syslog("API Rest request");
@@ -156,12 +156,12 @@  discard block
 block discarded – undo
156 156
         {
157 157
             $num = $db->num_rows($result);
158 158
             $min = min($num, ($limit <= 0 ? $num : $limit));
159
-            $i=0;
159
+            $i = 0;
160 160
             while ($i < $min)
161 161
             {
162 162
                 $obj = $db->fetch_object($result);
163 163
                 $shipment_static = new Expedition($db);
164
-                if($shipment_static->fetch($obj->rowid)) {
164
+                if ($shipment_static->fetch($obj->rowid)) {
165 165
                     $obj_ret[] = $this->_cleanObjectDatas($shipment_static);
166 166
                 }
167 167
                 $i++;
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
         else {
171 171
             throw new RestException(503, 'Error when retrieve commande list : '.$db->lasterror());
172 172
         }
173
-        if( ! count($obj_ret)) {
173
+        if (!count($obj_ret)) {
174 174
             throw new RestException(404, 'No shipment found');
175 175
         }
176 176
 		return $obj_ret;
@@ -184,13 +184,13 @@  discard block
 block discarded – undo
184 184
      */
185 185
     function post($request_data = null)
186 186
     {
187
-      if(! DolibarrApiAccess::$user->rights->expedition->creer) {
187
+      if (!DolibarrApiAccess::$user->rights->expedition->creer) {
188 188
 			  throw new RestException(401, "Insuffisant rights");
189 189
 		  }
190 190
         // Check mandatory fields
191 191
         $result = $this->_validate($request_data);
192 192
 
193
-        foreach($request_data as $field => $value) {
193
+        foreach ($request_data as $field => $value) {
194 194
             $this->shipment->$field = $value;
195 195
         }
196 196
         if (isset($request_data["lines"])) {
@@ -378,16 +378,16 @@  discard block
 block discarded – undo
378 378
      */
379 379
     function deleteLine($id, $lineid)
380 380
     {
381
-    	if(! DolibarrApiAccess::$user->rights->expedition->creer) {
381
+    	if (!DolibarrApiAccess::$user->rights->expedition->creer) {
382 382
     		throw new RestException(401);
383 383
     	}
384 384
 
385 385
     	$result = $this->shipment->fetch($id);
386
-    	if( ! $result ) {
386
+    	if (!$result) {
387 387
     		throw new RestException(404, 'Shipment not found');
388 388
     	}
389 389
 
390
-    	if( ! DolibarrApi::_checkAccessToResource('expedition',$this->shipment->id)) {
390
+    	if (!DolibarrApi::_checkAccessToResource('expedition', $this->shipment->id)) {
391 391
     		throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
392 392
     	}
393 393
 
@@ -414,19 +414,19 @@  discard block
 block discarded – undo
414 414
      */
415 415
     function put($id, $request_data = null)
416 416
     {
417
-      if (! DolibarrApiAccess::$user->rights->expedition->creer) {
417
+      if (!DolibarrApiAccess::$user->rights->expedition->creer) {
418 418
 		  	throw new RestException(401);
419 419
 		  }
420 420
 
421 421
         $result = $this->shipment->fetch($id);
422
-        if (! $result) {
422
+        if (!$result) {
423 423
             throw new RestException(404, 'Shipment not found');
424 424
         }
425 425
 
426
-		if (! DolibarrApi::_checkAccessToResource('expedition',$this->shipment->id)) {
426
+		if (!DolibarrApi::_checkAccessToResource('expedition', $this->shipment->id)) {
427 427
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
428 428
 		}
429
-        foreach($request_data as $field => $value) {
429
+        foreach ($request_data as $field => $value) {
430 430
             if ($field == 'id') continue;
431 431
             $this->shipment->$field = $value;
432 432
         }
@@ -450,19 +450,19 @@  discard block
 block discarded – undo
450 450
      */
451 451
     function delete($id)
452 452
     {
453
-        if(! DolibarrApiAccess::$user->rights->shipment->supprimer) {
453
+        if (!DolibarrApiAccess::$user->rights->shipment->supprimer) {
454 454
 			throw new RestException(401);
455 455
 		}
456 456
         $result = $this->shipment->fetch($id);
457
-        if( ! $result ) {
457
+        if (!$result) {
458 458
             throw new RestException(404, 'Shipment not found');
459 459
         }
460 460
 
461
-		if( ! DolibarrApi::_checkAccessToResource('expedition',$this->shipment->id)) {
461
+		if (!DolibarrApi::_checkAccessToResource('expedition', $this->shipment->id)) {
462 462
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
463 463
 		}
464 464
 
465
-        if( ! $this->shipment->delete(DolibarrApiAccess::$user)) {
465
+        if (!$this->shipment->delete(DolibarrApiAccess::$user)) {
466 466
             throw new RestException(500, 'Error when deleting shipment : '.$this->shipment->error);
467 467
         }
468 468
 
@@ -493,17 +493,17 @@  discard block
 block discarded – undo
493 493
      *   "notrigger": 0
494 494
      * }
495 495
      */
496
-    function validate($id, $notrigger=0)
496
+    function validate($id, $notrigger = 0)
497 497
     {
498
-        if(! DolibarrApiAccess::$user->rights->expedition->creer) {
498
+        if (!DolibarrApiAccess::$user->rights->expedition->creer) {
499 499
 			throw new RestException(401);
500 500
 		}
501 501
         $result = $this->shipment->fetch($id);
502
-        if( ! $result ) {
502
+        if (!$result) {
503 503
             throw new RestException(404, 'Shipment not found');
504 504
         }
505 505
 
506
-		if( ! DolibarrApi::_checkAccessToResource('expedition',$this->shipment->id)) {
506
+		if (!DolibarrApi::_checkAccessToResource('expedition', $this->shipment->id)) {
507 507
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
508 508
 		}
509 509
 
@@ -515,11 +515,11 @@  discard block
 block discarded – undo
515 515
 		    throw new RestException(500, 'Error when validating Shipment: '.$this->shipment->error);
516 516
 		}
517 517
 	$result = $this->shipment->fetch($id);
518
-        if( ! $result ) {
518
+        if (!$result) {
519 519
             throw new RestException(404, 'Shipment not found');
520 520
         }
521 521
 
522
-	if( ! DolibarrApi::_checkAccessToResource('expedition',$this->shipment->id)) {
522
+	if (!DolibarrApi::_checkAccessToResource('expedition', $this->shipment->id)) {
523 523
             throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
524 524
        }
525 525
 
@@ -620,7 +620,7 @@  discard block
 block discarded – undo
620 620
 
621 621
         $object = parent::_cleanObjectDatas($object);
622 622
 
623
-        unset($object->thirdparty);	// id already returned
623
+        unset($object->thirdparty); // id already returned
624 624
 
625 625
         unset($object->note);
626 626
         unset($object->address);
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
         unset($object->barcode_type_label);
630 630
         unset($object->barcode_type_coder);
631 631
 
632
-        if (! empty($object->lines) && is_array($object->lines))
632
+        if (!empty($object->lines) && is_array($object->lines))
633 633
         {
634 634
         	foreach ($object->lines as $line)
635 635
         	{
Please login to merge, or discard this patch.
dolibarr/htdocs/expedition/tpl/linkedobjectblock.tpl.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 // Protection to avoid direct call of template
20
-if (empty($conf) || ! is_object($conf))
20
+if (empty($conf) || !is_object($conf))
21 21
 {
22 22
 	print "Error, template page can't be called as URL";
23 23
 	exit;
@@ -37,19 +37,19 @@  discard block
 block discarded – undo
37 37
 // Load translation files required by the page
38 38
 $langs->load("sendings");
39 39
 
40
-$total=0; $ilink=0;
41
-foreach($linkedObjectBlock as $key => $objectlink)
40
+$total = 0; $ilink = 0;
41
+foreach ($linkedObjectBlock as $key => $objectlink)
42 42
 {
43 43
     $ilink++;
44 44
 
45
-    $trclass='oddeven';
46
-    if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) $trclass.=' liste_sub_total';
45
+    $trclass = 'oddeven';
46
+    if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) $trclass .= ' liste_sub_total';
47 47
 ?>
48 48
     <tr class="<?php echo $trclass; ?>">
49 49
         <td><?php echo $langs->trans("Shipment"); ?></td>
50 50
         <td><?php echo $objectlink->getNomUrl(1); ?></td>
51 51
         <td></td>
52
-    	<td align="center"><?php echo dol_print_date($objectlink->date_delivery,'day'); ?></td>
52
+    	<td align="center"><?php echo dol_print_date($objectlink->date_delivery, 'day'); ?></td>
53 53
     	<td align="right"><?php
54 54
     		if ($user->rights->expedition->lire) {
55 55
     			$total = $total + $objectlink->total_ht;
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
     	<td align="right">
60 60
     		<?php
61 61
     		// For now, shipments must stay linked to order, so link is not deletable
62
-    		if($object->element != 'commande') {
62
+    		if ($object->element != 'commande') {
63 63
     			?>
64 64
     			<a href="<?php echo $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=dellink&dellinkid='.$key; ?>"><?php echo img_picto($langs->transnoentitiesnoconv("RemoveLink"), 'unlink'); ?></a></td>
65 65
     			<?php
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 if (count($linkedObjectBlock) > 1)
72 72
 {
73 73
     ?>
74
-    <tr class="liste_total <?php echo (empty($noMoreLinkedObjectBlockAfter)?'liste_sub_total':''); ?>">
74
+    <tr class="liste_total <?php echo (empty($noMoreLinkedObjectBlockAfter) ? 'liste_sub_total' : ''); ?>">
75 75
         <td><?php echo $langs->trans("Total"); ?></td>
76 76
         <td></td>
77 77
     	<td align="center"></td>
Please login to merge, or discard this patch.
dolibarr/htdocs/societe/class/companypaymentmode.class.php 1 patch
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  */
24 24
 
25 25
 // Put here all includes required by your class file
26
-require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
26
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
27 27
 //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
28 28
 //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
29 29
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	/**
80 80
 	 * @var array  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
81 81
 	 */
82
-	public $fields=array(
82
+	public $fields = array(
83 83
 		'rowid' =>array('type'=>'integer', 'label'=>'Rowid', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>10),
84 84
 		'fk_soc' =>array('type'=>'integer', 'label'=>'Fk soc', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>15),
85 85
 		'label' =>array('type'=>'varchar(30)', 'label'=>'Label', 'enabled'=>1, 'visible'=>-2, 'position'=>30),
@@ -212,8 +212,8 @@  discard block
 block discarded – undo
212 212
 
213 213
 		$this->db = $db;
214 214
 
215
-		if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible']=0;
216
-		if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled']=0;
215
+		if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible'] = 0;
216
+		if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled'] = 0;
217 217
 	}
218 218
 
219 219
 	/**
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 	 */
226 226
 	public function create(User $user, $notrigger = false)
227 227
 	{
228
-		$idpayment =  $this->createCommon($user, $notrigger);
228
+		$idpayment = $this->createCommon($user, $notrigger);
229 229
 
230 230
 		return $idpayment;
231 231
 	}
@@ -291,11 +291,11 @@  discard block
 block discarded – undo
291 291
 	public function fetch($id, $ref = null, $socid = 0, $type = '')
292 292
 	{
293 293
 		$morewhere = '';
294
-		if ($socid) $morewhere.= " AND fk_soc  = ".$this->db->escape($socid)." AND default_rib = 1";
295
-		if ($type)  $morewhere.= " AND type = '".$this->db->escape($type)."'";
294
+		if ($socid) $morewhere .= " AND fk_soc  = ".$this->db->escape($socid)." AND default_rib = 1";
295
+		if ($type)  $morewhere .= " AND type = '".$this->db->escape($type)."'";
296 296
 
297 297
 		$result = $this->fetchCommon($id, $ref, $morewhere);
298
-		if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
298
+		if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
299 299
 		return $result;
300 300
 	}
301 301
 
@@ -347,51 +347,51 @@  discard block
 block discarded – undo
347 347
      *  @param  int     $save_lastsearch_value    	-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
348 348
 	 *	@return	string								String with URL
349 349
 	 */
350
-	function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
350
+	function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
351 351
 	{
352 352
 		global $db, $conf, $langs;
353 353
         global $dolibarr_main_authentication, $dolibarr_main_demo;
354 354
         global $menumanager;
355 355
 
356
-        if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
356
+        if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
357 357
 
358 358
         $result = '';
359 359
         $companylink = '';
360 360
 
361
-        $label = '<u>' . $langs->trans("CompanyPaymentMode") . '</u>';
362
-        $label.= '<br>';
363
-        $label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
361
+        $label = '<u>'.$langs->trans("CompanyPaymentMode").'</u>';
362
+        $label .= '<br>';
363
+        $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
364 364
 
365
-        $url = dol_buildpath('/monmodule/companypaymentmode_card.php',1).'?id='.$this->id;
365
+        $url = dol_buildpath('/monmodule/companypaymentmode_card.php', 1).'?id='.$this->id;
366 366
 
367 367
         if ($option != 'nolink')
368 368
         {
369 369
 	        // Add param to save lastsearch_values or not
370
-	        $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
371
-	        if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
372
-	        if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
370
+	        $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
371
+	        if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
372
+	        if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
373 373
         }
374 374
 
375
-        $linkclose='';
375
+        $linkclose = '';
376 376
         if (empty($notooltip))
377 377
         {
378
-            if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
378
+            if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
379 379
             {
380
-                $label=$langs->trans("ShowCompanyPaymentMode");
381
-                $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
380
+                $label = $langs->trans("ShowCompanyPaymentMode");
381
+                $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
382 382
             }
383
-            $linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
384
-            $linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
383
+            $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
384
+            $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
385 385
         }
386
-        else $linkclose = ($morecss?' class="'.$morecss.'"':'');
386
+        else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
387 387
 
388 388
 		$linkstart = '<a href="'.$url.'"';
389
-		$linkstart.=$linkclose.'>';
390
-		$linkend='</a>';
389
+		$linkstart .= $linkclose.'>';
390
+		$linkend = '</a>';
391 391
 
392 392
 		$result .= $linkstart;
393
-		if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
394
-		if ($withpicto != 2) $result.= $this->ref;
393
+		if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
394
+		if ($withpicto != 2) $result .= $this->ref;
395 395
 		$result .= $linkend;
396 396
 		//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
397 397
 
@@ -405,10 +405,10 @@  discard block
 block discarded – undo
405 405
 	 * @param	string	$alltypes	1=The default is for all payment types instead of per type
406 406
 	 * @return  int             	0 if KO, 1 if OK
407 407
 	 */
408
-	function setAsDefault($id=0, $alltypes=0)
408
+	function setAsDefault($id = 0, $alltypes = 0)
409 409
 	{
410 410
 		$sql1 = "SELECT rowid as id, fk_soc, type FROM ".MAIN_DB_PREFIX."societe_rib";
411
-		$sql1.= " WHERE rowid = ".($id?$id:$this->id);
411
+		$sql1 .= " WHERE rowid = ".($id ? $id : $this->id);
412 412
 
413 413
 		dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
414 414
 		$result1 = $this->db->query($sql1);
@@ -428,14 +428,14 @@  discard block
 block discarded – undo
428 428
 				$this->db->begin();
429 429
 
430 430
 				$sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0";
431
-				$sql2.= " WHERE default_rib <> 0 AND fk_soc = ".$obj->fk_soc;
432
-				if ($type) $sql2.= " AND type = '".$this->db->escape($type)."'";
431
+				$sql2 .= " WHERE default_rib <> 0 AND fk_soc = ".$obj->fk_soc;
432
+				if ($type) $sql2 .= " AND type = '".$this->db->escape($type)."'";
433 433
 				dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
434 434
 				$result2 = $this->db->query($sql2);
435 435
 
436 436
 				$sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1";
437
-				$sql3.= " WHERE rowid = ".$obj->id;
438
-				if ($type) $sql3.= " AND type = '".$this->db->escape($type)."'";
437
+				$sql3 .= " WHERE rowid = ".$obj->id;
438
+				if ($type) $sql3 .= " AND type = '".$this->db->escape($type)."'";
439 439
 				dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
440 440
 				$result3 = $this->db->query($sql3);
441 441
 
@@ -465,9 +465,9 @@  discard block
 block discarded – undo
465 465
 	 *  @param	int		$mode          0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
466 466
 	 *  @return	string 			       Label of status
467 467
 	 */
468
-	function getLibStatut($mode=0)
468
+	function getLibStatut($mode = 0)
469 469
 	{
470
-		return $this->LibStatut($this->status,$mode);
470
+		return $this->LibStatut($this->status, $mode);
471 471
 	}
472 472
 
473 473
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
 	 *  @param  int		$mode          	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
479 479
 	 *  @return string 			       	Label of status
480 480
 	 */
481
-	static function LibStatut($status,$mode=0)
481
+	static function LibStatut($status, $mode = 0)
482 482
 	{
483 483
         // phpcs:enable
484 484
 		global $langs;
@@ -490,28 +490,28 @@  discard block
 block discarded – undo
490 490
 		}
491 491
 		elseif ($mode == 2)
492 492
 		{
493
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
494
-			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
493
+			if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled');
494
+			if ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled');
495 495
 		}
496 496
 		elseif ($mode == 3)
497 497
 		{
498
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4');
499
-			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5');
498
+			if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4');
499
+			if ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5');
500 500
 		}
501 501
 		elseif ($mode == 4)
502 502
 		{
503
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
504
-			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
503
+			if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled');
504
+			if ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled');
505 505
 		}
506 506
 		elseif ($mode == 5)
507 507
 		{
508
-			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
509
-			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
508
+			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'), 'statut4');
509
+			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'), 'statut5');
510 510
 		}
511 511
 		elseif ($mode == 6)
512 512
 		{
513
-			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
514
-			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
513
+			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'), 'statut4');
514
+			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'), 'statut5');
515 515
 		}
516 516
 	}
517 517
 
@@ -524,10 +524,10 @@  discard block
 block discarded – undo
524 524
 	function info($id)
525 525
 	{
526 526
 		$sql = 'SELECT rowid, date_creation as datec, tms as datem,';
527
-		$sql.= ' fk_user_creat, fk_user_modif';
528
-		$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
529
-		$sql.= ' WHERE t.rowid = '.$id;
530
-		$result=$this->db->query($sql);
527
+		$sql .= ' fk_user_creat, fk_user_modif';
528
+		$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
529
+		$sql .= ' WHERE t.rowid = '.$id;
530
+		$result = $this->db->query($sql);
531 531
 		if ($result)
532 532
 		{
533 533
 			if ($this->db->num_rows($result))
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
 				{
539 539
 					$cuser = new User($this->db);
540 540
 					$cuser->fetch($obj->fk_user_author);
541
-					$this->user_creation   = $cuser;
541
+					$this->user_creation = $cuser;
542 542
 				}
543 543
 
544 544
 				if ($obj->fk_user_valid)
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
 				{
553 553
 					$cluser = new User($this->db);
554 554
 					$cluser->fetch($obj->fk_user_cloture);
555
-					$this->user_cloture   = $cluser;
555
+					$this->user_cloture = $cluser;
556 556
 				}
557 557
 
558 558
 				$this->date_creation     = $this->db->jdate($obj->datec);
Please login to merge, or discard this patch.
dolibarr/htdocs/societe/class/address.class.php 1 patch
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
 	 *  @param  User	$user       Object user making creation
86 86
 	 *  @return int         		0 if OK, < 0 if KO
87 87
 	 */
88
-	function create($socid, $user='')
88
+	function create($socid, $user = '')
89 89
 	{
90
-		global $langs,$conf;
90
+		global $langs, $conf;
91 91
 
92 92
 		// Nettoyage parametres
93 93
 		$this->name  = trim($this->name);
@@ -101,12 +101,12 @@  discard block
 block discarded – undo
101 101
 
102 102
 		if ($result >= 0)
103 103
 		{
104
-			$now=dol_now();
104
+			$now = dol_now();
105 105
 
106 106
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_address (label, fk_soc, name, datec, fk_user_creat) ";
107 107
 			$sql .= " VALUES ('".$this->db->escape($this->label)."', '".$socid."', '".$this->db->escape($this->name)."', '".$this->db->idate($now)."', '".$user->id."')";
108 108
 
109
-			$result=$this->db->query($sql);
109
+			$result = $this->db->query($sql);
110 110
 			if ($result)
111 111
 			{
112 112
 				$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_address");
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 				if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
133 133
 				{
134 134
 
135
-					$this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->name);
135
+					$this->error = $langs->trans("ErrorCompanyNameAlreadyExists", $this->name);
136 136
 				}
137 137
 
138 138
 				$this->db->rollback();
@@ -175,27 +175,27 @@  discard block
 block discarded – undo
175 175
 	 *  @param  User	$user           Utilisateur qui demande la mise a jour
176 176
 	 *  @return int             		<0 if KO, >=0 if OK
177 177
 	 */
178
-	function update($id, $socid, $user='')
178
+	function update($id, $socid, $user = '')
179 179
 	{
180 180
 		global $langs;
181 181
 
182 182
 		// Clean parameters
183
-		$this->fk_soc		= $socid;
183
+		$this->fk_soc = $socid;
184 184
 		$this->label		= trim($this->label);
185 185
 		$this->name			= trim($this->name);
186
-		$this->address		= trim($this->address);
187
-		$this->zip			= trim($this->zip);
186
+		$this->address = trim($this->address);
187
+		$this->zip = trim($this->zip);
188 188
 		$this->town			= trim($this->town);
189
-		$this->country_id	= trim($this->country_id);
189
+		$this->country_id = trim($this->country_id);
190 190
 		$this->phone		= trim($this->phone);
191
-		$this->phone		= preg_replace("/\s/","",$this->phone);
192
-		$this->phone		= preg_replace("/\./","",$this->phone);
191
+		$this->phone		= preg_replace("/\s/", "", $this->phone);
192
+		$this->phone		= preg_replace("/\./", "", $this->phone);
193 193
 		$this->fax			= trim($this->fax);
194
-		$this->fax			= preg_replace("/\s/","",$this->fax);
195
-		$this->fax			= preg_replace("/\./","",$this->fax);
196
-		$this->note			= trim($this->note);
194
+		$this->fax			= preg_replace("/\s/", "", $this->fax);
195
+		$this->fax			= preg_replace("/\./", "", $this->fax);
196
+		$this->note = trim($this->note);
197 197
 
198
-		$result = $this->verify();		// Verifie que name et label obligatoire
198
+		$result = $this->verify(); // Verifie que name et label obligatoire
199 199
 
200 200
 		if ($result >= 0)
201 201
 		{
@@ -204,20 +204,20 @@  discard block
 block discarded – undo
204 204
 			$this->db->begin();
205 205
 
206 206
 			$sql = "UPDATE ".MAIN_DB_PREFIX."societe_address";
207
-			$sql.= " SET label = '" . $this->db->escape($this->label) ."'"; // Champ obligatoire
208
-			$sql.= ", name = '" . $this->db->escape($this->name) ."'"; // Champ obligatoire
209
-			$sql.= ", address = ".($this->address?"'".$this->db->escape($this->address)."'":"null");
210
-			$sql.= ", zip = ".($this->zip?"'".$this->db->escape($this->zip)."'":"null");
211
-			$sql.= ", town = ".($this->town?"'".$this->db->escape($this->town)."'":"null");
212
-			$sql.= ", fk_pays = '" . ($this->country_id?$this->db->escape($this->country_id):'0') ."'";
213
-			$sql.= ", note = ".($this->note?"'".$this->db->escape($this->note)."'":"null");
214
-			$sql.= ", phone = ".($this->phone?"'".$this->db->escape($this->phone)."'":"null");
215
-			$sql.= ", fax = ".($this->fax?"'".$this->db->escape($this->fax)."'":"null");
207
+			$sql .= " SET label = '".$this->db->escape($this->label)."'"; // Champ obligatoire
208
+			$sql .= ", name = '".$this->db->escape($this->name)."'"; // Champ obligatoire
209
+			$sql .= ", address = ".($this->address ? "'".$this->db->escape($this->address)."'" : "null");
210
+			$sql .= ", zip = ".($this->zip ? "'".$this->db->escape($this->zip)."'" : "null");
211
+			$sql .= ", town = ".($this->town ? "'".$this->db->escape($this->town)."'" : "null");
212
+			$sql .= ", fk_pays = '".($this->country_id ? $this->db->escape($this->country_id) : '0')."'";
213
+			$sql .= ", note = ".($this->note ? "'".$this->db->escape($this->note)."'" : "null");
214
+			$sql .= ", phone = ".($this->phone ? "'".$this->db->escape($this->phone)."'" : "null");
215
+			$sql .= ", fax = ".($this->fax ? "'".$this->db->escape($this->fax)."'" : "null");
216 216
 			if ($user) $sql .= ",fk_user_modif = '".$user->id."'";
217
-			$sql .= " WHERE fk_soc = '" . $socid ."' AND rowid = '" . $this->db->escape($id) ."'";
217
+			$sql .= " WHERE fk_soc = '".$socid."' AND rowid = '".$this->db->escape($id)."'";
218 218
 
219 219
 			dol_syslog(get_class($this)."::Update", LOG_DEBUG);
220
-			$resql=$this->db->query($sql);
220
+			$resql = $this->db->query($sql);
221 221
 			if ($resql)
222 222
 			{
223 223
 				dol_syslog(get_class($this)."::Update success");
@@ -229,13 +229,13 @@  discard block
 block discarded – undo
229 229
 				if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
230 230
 				{
231 231
 
232
-					$this->error=$langs->trans("ErrorDuplicateField",$this->name);
233
-					$result=-1;
232
+					$this->error = $langs->trans("ErrorDuplicateField", $this->name);
233
+					$result = -1;
234 234
 				}
235 235
 				else
236 236
 				{
237
-					$this->error=$this->db->lasterror();
238
-					$result=-2;
237
+					$this->error = $this->db->lasterror();
238
+					$result = -2;
239 239
 				}
240 240
 				$this->db->rollback();
241 241
 				return $result;
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	 *  @param  User	$user        Objet de l'utilisateur
252 252
 	 *  @return int 			     >0 si ok, <0 si ko
253 253
 	 */
254
-	function fetch_lines($socid, $user=null)
254
+	function fetch_lines($socid, $user = null)
255 255
 	{
256 256
         // phpcs:enable
257 257
 		global $langs, $conf;
@@ -260,18 +260,18 @@  discard block
 block discarded – undo
260 260
 		$sql .= ' FROM '.MAIN_DB_PREFIX.'societe';
261 261
 		$sql .= ' WHERE rowid = '.$socid;
262 262
 
263
-		$resqlsoc=$this->db->query($sql);
263
+		$resqlsoc = $this->db->query($sql);
264 264
 		if ($resqlsoc)
265 265
 		{
266 266
 			if ($this->db->num_rows($resqlsoc))
267 267
 			{
268 268
 				$obj = $this->db->fetch_object($resqlsoc);
269 269
 
270
-				$this->socname 		= $obj->name;
271
-				$this->socid		= $obj->rowid;
272
-				$this->id			= $obj->rowid;
273
-				$this->client		= $obj->client;
274
-				$this->fournisseur	= $obj->fournisseur;
270
+				$this->socname = $obj->name;
271
+				$this->socid = $obj->rowid;
272
+				$this->id = $obj->rowid;
273
+				$this->client = $obj->client;
274
+				$this->fournisseur = $obj->fournisseur;
275 275
 			}
276 276
 
277 277
 			$this->db->free($resqlsoc);
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 				$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON a.fk_pays = c.rowid';
289 289
 				$sql .= ' WHERE a.fk_soc = '.$this->socid;
290 290
 
291
-				$resql=$this->db->query($sql);
291
+				$resql = $this->db->query($sql);
292 292
 				if ($resql)
293 293
 				{
294 294
 					$num = $this->db->num_rows($resql);
@@ -299,22 +299,22 @@  discard block
 block discarded – undo
299 299
 
300 300
 						$line = new AddressLine($this->db);
301 301
 
302
-						$line->id				= $objp->id;
303
-						$line->date_creation	 = $this->db->jdate($objp->date_creation);
302
+						$line->id = $objp->id;
303
+						$line->date_creation = $this->db->jdate($objp->date_creation);
304 304
 						$line->date_modification = $this->db->jdate($objp->date_modification);
305 305
 						$line->label			= $objp->label;
306 306
 						$line->name				= $objp->name;
307
-						$line->address			= $objp->address;
308
-						$line->zip				= $objp->zip;
307
+						$line->address = $objp->address;
308
+						$line->zip = $objp->zip;
309 309
 						$line->town				= $objp->town;
310
-						$line->country_id		= $objp->country_id;
311
-						$line->country_code		= $objp->country_id?$objp->country_code:'';
312
-						$line->country			= $objp->country_id?($langs->trans('Country'.$objp->country_code)!='Country'.$objp->country_code?$langs->trans('Country'.$objp->country_code):$objp->country):'';
310
+						$line->country_id = $objp->country_id;
311
+						$line->country_code = $objp->country_id ? $objp->country_code : '';
312
+						$line->country = $objp->country_id ? ($langs->trans('Country'.$objp->country_code) != 'Country'.$objp->country_code ? $langs->trans('Country'.$objp->country_code) : $objp->country) : '';
313 313
 						$line->phone			= $objp->phone;
314
-						$line->fax				= $objp->fax;
314
+						$line->fax = $objp->fax;
315 315
 						$line->note				= $objp->note;
316 316
 
317
-						$this->lines[$i]		= $line;
317
+						$this->lines[$i] = $line;
318 318
 						$i++;
319 319
 					}
320 320
 					$this->db->free($resql);
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
 		}
335 335
 		else
336 336
 		{
337
-			$this->error=$this->db->error();
337
+			$this->error = $this->db->error();
338 338
 		}
339 339
 	}
340 340
 
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
 	 *  @param  User	$user       Objet de l'utilisateur
347 347
 	 *  @return int 				>0 si ok, <0 si ko
348 348
 	 */
349
-	function fetch_address($id, $user=null)
349
+	function fetch_address($id, $user = null)
350 350
 	{
351 351
         // phpcs:enable
352 352
 		global $langs;
@@ -358,31 +358,31 @@  discard block
 block discarded – undo
358 358
 		$sql .= ' FROM '.MAIN_DB_PREFIX.'societe_address as a';
359 359
 		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON a.fk_pays = c.rowid';
360 360
 		$sql .= ' WHERE a.rowid = '.$id;
361
-		$resql=$this->db->query($sql);
361
+		$resql = $this->db->query($sql);
362 362
 		if ($resql)
363 363
 		{
364 364
 			if ($this->db->num_rows($resql))
365 365
 			{
366 366
 				$obj = $this->db->fetch_object($resql);
367 367
 
368
-				$this->id				= $obj->rowid;
369
-				$this->socid			= $obj->fk_soc;
368
+				$this->id = $obj->rowid;
369
+				$this->socid = $obj->fk_soc;
370 370
 
371
-				$this->date_modification		= $this->db->jdate($obj->date_modification);
372
-				$this->date_creation 	= $this->db->jdate($obj->date_creation);
371
+				$this->date_modification = $this->db->jdate($obj->date_modification);
372
+				$this->date_creation = $this->db->jdate($obj->date_creation);
373 373
 
374
-				$this->label 			= $obj->label;
374
+				$this->label = $obj->label;
375 375
 				$this->name 			= $obj->name;
376
-				$this->address 			= $obj->address;
376
+				$this->address = $obj->address;
377 377
 				$this->zip 				= $obj->zip;
378 378
 				$this->town 			= $obj->town;
379 379
 
380
-				$this->country_id 		= $obj->country_id;
381
-				$this->country_code 	= $obj->country_id?$obj->country_code:'';
382
-				$this->country			= $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->trans('Country'.$obj->country_code):$obj->country):'';
380
+				$this->country_id = $obj->country_id;
381
+				$this->country_code = $obj->country_id ? $obj->country_code : '';
382
+				$this->country = $obj->country_id ? ($langs->trans('Country'.$obj->country_code) != 'Country'.$obj->country_code ? $langs->trans('Country'.$obj->country_code) : $obj->country) : '';
383 383
 
384 384
 				$this->phone			= $obj->phone;
385
-				$this->fax				= $obj->fax;
385
+				$this->fax = $obj->fax;
386 386
 				$this->note				= $obj->note;
387 387
 
388 388
 				$result = 1;
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
 			else
391 391
 			{
392 392
 				dol_syslog('Erreur Societe::Fetch aucune adresse avec id='.$this->id.' - '.$sql);
393
-				$this->error='Erreur Societe::Fetch aucune adresse avec id='.$this->id.' - '.$sql;
393
+				$this->error = 'Erreur Societe::Fetch aucune adresse avec id='.$this->id.' - '.$sql;
394 394
 				$result = -2;
395 395
 			}
396 396
 
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 		{
401 401
 			dol_syslog('Erreur Societe::Fetch echec', LOG_DEBUG);
402 402
 			dol_syslog('Erreur Societe::Fetch '.$this->db->error());
403
-			$this->error=$this->db->error();
403
+			$this->error = $this->db->error();
404 404
 			$result = -3;
405 405
 		}
406 406
 
@@ -415,13 +415,13 @@  discard block
 block discarded – undo
415 415
 	 *  @param	int		$socid	id third party
416 416
 	 *  @return	<0 KO >0 OK
417 417
 	 */
418
-	function delete($id,$socid)
418
+	function delete($id, $socid)
419 419
 	{
420 420
 		dol_syslog("Address::Delete");
421 421
 
422 422
 		$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_address";
423
-		$sql.= " WHERE rowid = ".$id;
424
-		$sql.= " AND fk_soc = ".$socid;
423
+		$sql .= " WHERE rowid = ".$id;
424
+		$sql .= " AND fk_soc = ".$socid;
425 425
 
426 426
 		$result = $this->db->query($sql);
427 427
 
@@ -440,18 +440,18 @@  discard block
 block discarded – undo
440 440
 	 *	@param		string		$option			Where the link point to
441 441
 	 *	@return		string						String with URL
442 442
 	 */
443
-	function getNomUrl($withpicto=0,$option='')
443
+	function getNomUrl($withpicto = 0, $option = '')
444 444
 	{
445 445
 		global $langs;
446 446
 
447
-		$result='';
447
+		$result = '';
448 448
         $label = $langs->trans("ShowAddress").': '.$this->label;
449 449
 
450 450
         $link = '<a href="'.DOL_URL_ROOT.'/comm/address.php?id='.$this->id.'&socid='.$this->socid.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
451
-		$linkend='</a>';
451
+		$linkend = '</a>';
452 452
 
453
-        if ($withpicto) $result.=($link.img_object($langs->trans("ShowAddress").': '.$this->label, 'address', 'class="classfortooltip"').$linkend.' ');
454
-		$result.=$link.$this->label.$linkend;
453
+        if ($withpicto) $result .= ($link.img_object($langs->trans("ShowAddress").': '.$this->label, 'address', 'class="classfortooltip"').$linkend.' ');
454
+		$result .= $link.$this->label.$linkend;
455 455
 		return $result;
456 456
 	}
457 457
 
@@ -465,11 +465,11 @@  discard block
 block discarded – undo
465 465
 	function info($id)
466 466
 	{
467 467
 		$sql = "SELECT s.rowid, s.nom as name, datec as date_creation, tms as date_modification,";
468
-		$sql.= " fk_user_creat, fk_user_modif";
469
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
470
-		$sql.= " WHERE s.rowid = ".$id;
468
+		$sql .= " fk_user_creat, fk_user_modif";
469
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
470
+		$sql .= " WHERE s.rowid = ".$id;
471 471
 
472
-		$result=$this->db->query($sql);
472
+		$result = $this->db->query($sql);
473 473
 		if ($result)
474 474
 		{
475 475
 			if ($this->db->num_rows($result))
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
 				if ($obj->fk_user_creat) {
482 482
 					$cuser = new User($this->db);
483 483
 					$cuser->fetch($obj->fk_user_creat);
484
-					$this->user_creation     = $cuser;
484
+					$this->user_creation = $cuser;
485 485
 				}
486 486
 
487 487
 				if ($obj->fk_user_modif) {
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
 					$muser->fetch($obj->fk_user_modif);
490 490
 					$this->user_modification = $muser;
491 491
 				}
492
-				$this->ref			     = $obj->name;
492
+				$this->ref = $obj->name;
493 493
 				$this->date_creation     = $this->db->jdate($obj->date_creation);
494 494
 				$this->date_modification = $this->db->jdate($obj->date_modification);
495 495
 			}
Please login to merge, or discard this patch.
dolibarr/htdocs/societe/class/companybankaccount.class.php 1 patch
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  *		\brief      File of class to manage bank accounts description of third parties
26 26
  */
27 27
 
28
-require_once DOL_DOCUMENT_ROOT .'/compta/bank/class/account.class.php';
28
+require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
29 29
 
30 30
 
31 31
 /**
@@ -67,37 +67,37 @@  discard block
 block discarded – undo
67 67
 	 * @param   int    $notrigger   1=Disable triggers
68 68
 	 * @return	int					<0 if KO, >= 0 if OK
69 69
 	 */
70
-	function create(User $user = null, $notrigger=0)
70
+	function create(User $user = null, $notrigger = 0)
71 71
 	{
72 72
 		$now	= dol_now();
73
-		$error	= 0;
73
+		$error = 0;
74 74
 		// Correct default_rib to be sure to have always one default
75 75
 		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_rib where fk_soc = ".$this->socid." AND default_rib = 1 AND type = 'ban'";
76 76
    		$result = $this->db->query($sql);
77 77
 		if ($result)
78 78
 		{
79
-			$numrows=$this->db->num_rows($result);
79
+			$numrows = $this->db->num_rows($result);
80 80
 			if ($this->default_rib && $numrows > 0) $this->default_rib = 0;
81 81
 			if (empty($this->default_rib) && $numrows == 0) $this->default_rib = 1;
82 82
 		}
83 83
 
84 84
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_rib (fk_soc, type, datec)";
85
-		$sql.= " VALUES (".$this->socid.", 'ban', '".$this->db->idate($now)."')";
86
-		$resql=$this->db->query($sql);
85
+		$sql .= " VALUES (".$this->socid.", 'ban', '".$this->db->idate($now)."')";
86
+		$resql = $this->db->query($sql);
87 87
 		if ($resql)
88 88
 		{
89 89
 			if ($this->db->affected_rows($resql))
90 90
 			{
91 91
 				$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_rib");
92 92
 
93
-				if (! $notrigger)
93
+				if (!$notrigger)
94 94
 				{
95 95
 				   	// Call trigger
96
-					$result=$this->call_trigger('COMPANY_RIB_CREATE',$user);
96
+					$result = $this->call_trigger('COMPANY_RIB_CREATE', $user);
97 97
 					if ($result < 0) $error++;
98 98
 					// End call triggers
99 99
 
100
-					if (! $error)
100
+					if (!$error)
101 101
 					{
102 102
 						return 1;
103 103
 					}
@@ -131,47 +131,47 @@  discard block
 block discarded – undo
131 131
 		global $conf;
132 132
 		$error = 0;
133 133
 
134
-		if (! $this->id) return -1;
134
+		if (!$this->id) return -1;
135 135
 
136 136
 		if (dol_strlen($this->domiciliation) > 255) $this->domiciliation = dol_trunc($this->domiciliation, 254, 'right', 'UTF-8', 1);
137 137
 		if (dol_strlen($this->owner_address) > 255) $this->owner_address = dol_trunc($this->owner_address, 254, 'right', 'UTF-8', 1);
138 138
 
139 139
 		$sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET";
140
-		$sql.= " bank = '" .$this->db->escape($this->bank)."'";
141
-		$sql.= ",code_banque='".$this->db->escape($this->code_banque)."'";
142
-		$sql.= ",code_guichet='".$this->db->escape($this->code_guichet)."'";
143
-		$sql.= ",number='".$this->db->escape($this->number)."'";
144
-		$sql.= ",cle_rib='".$this->db->escape($this->cle_rib)."'";
145
-		$sql.= ",bic='".$this->db->escape($this->bic)."'";
146
-		$sql.= ",iban_prefix = '".$this->db->escape($this->iban)."'";
147
-		$sql.= ",domiciliation='".$this->db->escape($this->domiciliation)."'";
148
-		$sql.= ",proprio = '".$this->db->escape($this->proprio)."'";
149
-		$sql.= ",owner_address = '".$this->db->escape($this->owner_address)."'";
150
-		$sql.= ",default_rib = ".$this->default_rib;
140
+		$sql .= " bank = '".$this->db->escape($this->bank)."'";
141
+		$sql .= ",code_banque='".$this->db->escape($this->code_banque)."'";
142
+		$sql .= ",code_guichet='".$this->db->escape($this->code_guichet)."'";
143
+		$sql .= ",number='".$this->db->escape($this->number)."'";
144
+		$sql .= ",cle_rib='".$this->db->escape($this->cle_rib)."'";
145
+		$sql .= ",bic='".$this->db->escape($this->bic)."'";
146
+		$sql .= ",iban_prefix = '".$this->db->escape($this->iban)."'";
147
+		$sql .= ",domiciliation='".$this->db->escape($this->domiciliation)."'";
148
+		$sql .= ",proprio = '".$this->db->escape($this->proprio)."'";
149
+		$sql .= ",owner_address = '".$this->db->escape($this->owner_address)."'";
150
+		$sql .= ",default_rib = ".$this->default_rib;
151 151
 		if ($conf->prelevement->enabled)
152 152
 		{
153
-			$sql.= ",frstrecur = '".$this->db->escape($this->frstrecur)."'";
154
-			$sql.= ",rum = '".$this->db->escape($this->rum)."'";
155
-			$sql.= ",date_rum = ".($this->date_rum ? "'".$this->db->idate($this->date_rum)."'" : "null");
153
+			$sql .= ",frstrecur = '".$this->db->escape($this->frstrecur)."'";
154
+			$sql .= ",rum = '".$this->db->escape($this->rum)."'";
155
+			$sql .= ",date_rum = ".($this->date_rum ? "'".$this->db->idate($this->date_rum)."'" : "null");
156 156
 		}
157 157
 		if (trim($this->label) != '')
158
-			$sql.= ",label = '".$this->db->escape($this->label)."'";
158
+			$sql .= ",label = '".$this->db->escape($this->label)."'";
159 159
 		else
160
-			$sql.= ",label = NULL";
161
-		$sql.= " WHERE rowid = ".$this->id;
160
+			$sql .= ",label = NULL";
161
+		$sql .= " WHERE rowid = ".$this->id;
162 162
 
163 163
 		$result = $this->db->query($sql);
164 164
 		if ($result)
165 165
 		{
166 166
 
167 167
 
168
-		if (! $notrigger)
168
+		if (!$notrigger)
169 169
 		{
170 170
 			// Call trigger
171
-			$result=$this->call_trigger('COMPANY_RIB_MODIFY',$user);
171
+			$result = $this->call_trigger('COMPANY_RIB_MODIFY', $user);
172 172
 			if ($result < 0) $error++;
173 173
 			// End call triggers
174
-			if(! $error )
174
+			if (!$error)
175 175
 			{
176 176
 				return 1;
177 177
 			}
@@ -201,19 +201,19 @@  discard block
 block discarded – undo
201 201
 	 *  @param	int		$type		If id of company filled, we say if we want record of this type only
202 202
 	 * 	@return	int					<0 if KO, >0 if OK
203 203
 	 */
204
-	function fetch($id, $socid=0, $default=1, $type='ban')
204
+	function fetch($id, $socid = 0, $default = 1, $type = 'ban')
205 205
 	{
206 206
 		if (empty($id) && empty($socid)) return -1;
207 207
 
208 208
 		$sql = "SELECT rowid, type, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,";
209
-		$sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur";
210
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe_rib";
211
-		if ($id)    $sql.= " WHERE rowid = ".$id;
209
+		$sql .= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur";
210
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe_rib";
211
+		if ($id)    $sql .= " WHERE rowid = ".$id;
212 212
 		if ($socid)
213 213
 		{
214
-			$sql.= " WHERE fk_soc  = ".$socid;
215
-			if ($default > -1) $sql.=" AND default_rib = ".$this->db->escape($default);
216
-			if ($type) $sql.= " AND type ='".$this->db->escape($type)."'";
214
+			$sql .= " WHERE fk_soc  = ".$socid;
215
+			if ($default > -1) $sql .= " AND default_rib = ".$this->db->escape($default);
216
+			if ($type) $sql .= " AND type ='".$this->db->escape($type)."'";
217 217
 		}
218 218
 
219 219
 		$resql = $this->db->query($sql);
@@ -223,10 +223,10 @@  discard block
 block discarded – undo
223 223
 			{
224 224
 				$obj = $this->db->fetch_object($resql);
225 225
 
226
-				$this->ref             = $obj->fk_soc.'-'.$obj->label;      // Generate an artificial ref
226
+				$this->ref = $obj->fk_soc.'-'.$obj->label; // Generate an artificial ref
227 227
 
228
-				$this->id			   = $obj->rowid;
229
-				$this->type			   = $obj->type;
228
+				$this->id = $obj->rowid;
229
+				$this->type = $obj->type;
230 230
 				$this->socid           = $obj->fk_soc;
231 231
 				$this->bank            = $obj->bank;
232 232
 				$this->code_banque     = $obj->code_banque;
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 				$this->number          = $obj->number;
235 235
 				$this->cle_rib         = $obj->cle_rib;
236 236
 				$this->bic             = $obj->bic;
237
-				$this->iban		       = $obj->iban;
237
+				$this->iban = $obj->iban;
238 238
 				$this->domiciliation   = $obj->domiciliation;
239 239
 				$this->proprio         = $obj->proprio;
240 240
 				$this->owner_address   = $obj->owner_address;
@@ -263,37 +263,37 @@  discard block
 block discarded – undo
263 263
 	 *	@param  	int		$notrigger	1=Disable triggers
264 264
 	 *  @return		int		            <0 if KO, >0 if OK
265 265
 	 */
266
-	function delete(User $user = null, $notrigger=0)
266
+	function delete(User $user = null, $notrigger = 0)
267 267
 	{
268 268
 		global $conf;
269 269
 
270 270
 		$error = 0;
271 271
 
272
-		dol_syslog(get_class($this) . "::delete ".$this->id, LOG_DEBUG);
272
+		dol_syslog(get_class($this)."::delete ".$this->id, LOG_DEBUG);
273 273
 
274 274
 		$this->db->begin();
275 275
 
276
-		if (! $error && ! $notrigger)
276
+		if (!$error && !$notrigger)
277 277
 		{
278 278
 			// Call trigger
279
-			$result=$this->call_trigger('COMPANY_RIB_DELETE',$user);
279
+			$result = $this->call_trigger('COMPANY_RIB_DELETE', $user);
280 280
 			if ($result < 0) $error++;
281 281
 			// End call triggers
282 282
 		}
283 283
 
284
-		if (! $error)
284
+		if (!$error)
285 285
 		{
286
-			$sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe_rib";
287
-			$sql .= " WHERE rowid  = " . $this->id;
286
+			$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_rib";
287
+			$sql .= " WHERE rowid  = ".$this->id;
288 288
 
289
-			if (! $this->db->query($sql))
289
+			if (!$this->db->query($sql))
290 290
 			{
291 291
 				$error++;
292
-				$this->errors[]=$this->db->lasterror();
292
+				$this->errors[] = $this->db->lasterror();
293 293
 			}
294 294
 		}
295 295
 
296
-		if (! $error)
296
+		if (!$error)
297 297
 		{
298 298
 			$this->db->commit();
299 299
 			return 1;
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 		else
302 302
 		{
303 303
 			$this->db->rollback();
304
-			return -1*$error;
304
+			return -1 * $error;
305 305
 		}
306 306
 	}
307 307
 
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 	{
316 316
 		$rib = '';
317 317
 
318
-		if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib || $this->iban || $this->bic ) {
318
+		if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib || $this->iban || $this->bic) {
319 319
 
320 320
 			if ($this->label && $displayriblabel) {
321 321
 				$rib = $this->label." : ";
@@ -333,10 +333,10 @@  discard block
 block discarded – undo
333 333
 	 * @param   int     $rib    RIB id
334 334
 	 * @return  int             0 if KO, 1 if OK
335 335
 	 */
336
-	function setAsDefault($rib=0)
336
+	function setAsDefault($rib = 0)
337 337
 	{
338 338
 		$sql1 = "SELECT rowid as id, fk_soc  FROM ".MAIN_DB_PREFIX."societe_rib";
339
-		$sql1.= " WHERE rowid = ".($rib?$rib:$this->id);
339
+		$sql1 .= " WHERE rowid = ".($rib ? $rib : $this->id);
340 340
 
341 341
 		dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
342 342
 		$result1 = $this->db->query($sql1);
@@ -353,12 +353,12 @@  discard block
 block discarded – undo
353 353
 				$this->db->begin();
354 354
 
355 355
 				$sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0";
356
-				$sql2.= " WHERE type = 'ban' AND fk_soc = ".$obj->fk_soc;
356
+				$sql2 .= " WHERE type = 'ban' AND fk_soc = ".$obj->fk_soc;
357 357
 				dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
358 358
 				$result2 = $this->db->query($sql2);
359 359
 
360 360
 				$sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1";
361
-				$sql3.= " WHERE rowid = ".$obj->id;
361
+				$sql3 .= " WHERE rowid = ".$obj->id;
362 362
 				dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
363 363
 				$result3 = $this->db->query($sql3);
364 364
 
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
 		$this->country_id      = 1;
410 410
 
411 411
 		$this->rum             = 'UMR-CU1212-0007-5-1475405262';
412
-		$this->date_rum        =dol_now() - 10000;
412
+		$this->date_rum        = dol_now() - 10000;
413 413
 		$this->frstrecur       = 'FRST';
414 414
 
415 415
 		$this->socid = 0;
Please login to merge, or discard this patch.
dolibarr/htdocs/societe/class/api_contacts.class.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 
82 82
 		if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe'))
83 83
 		{
84
-			throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
84
+			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
85 85
 		}
86 86
 
87 87
 		return $this->_cleanObjectDatas($this->contact);
@@ -122,37 +122,37 @@  discard block
 block discarded – undo
122 122
 			$search_sale = DolibarrApiAccess::$user->id;
123 123
 
124 124
 		$sql = "SELECT t.rowid";
125
-		$sql.= " FROM " . MAIN_DB_PREFIX . "socpeople as t";
126
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX . "socpeople_extrafields as te ON te.fk_object = t.rowid";
125
+		$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as t";
126
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as te ON te.fk_object = t.rowid";
127 127
 		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
128 128
 			// We need this table joined to the select in order to filter by sale
129
-			$sql.= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
129
+			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
130 130
 		}
131
-		$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON t.fk_soc = s.rowid";
132
-		$sql.= ' WHERE t.entity IN (' . getEntity('socpeople') . ')';
133
-		if ($socids) $sql.= " AND t.fk_soc IN (" . $socids . ")";
131
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON t.fk_soc = s.rowid";
132
+		$sql .= ' WHERE t.entity IN ('.getEntity('socpeople').')';
133
+		if ($socids) $sql .= " AND t.fk_soc IN (".$socids.")";
134 134
 
135 135
 		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0)
136
-			$sql.= " AND t.fk_soc = sc.fk_soc";
136
+			$sql .= " AND t.fk_soc = sc.fk_soc";
137 137
 		if ($search_sale > 0)
138
-			$sql.= " AND s.rowid = sc.fk_soc";  // Join for the needed table to filter by sale
138
+			$sql .= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
139 139
 		// Insert sale filter
140 140
 		if ($search_sale > 0)
141 141
 		{
142
-			$sql .= " AND sc.fk_user = " . $search_sale;
142
+			$sql .= " AND sc.fk_user = ".$search_sale;
143 143
 		}
144 144
 	    // Add sql filters
145 145
         if ($sqlfilters)
146 146
         {
147
-            if (! DolibarrApi::_checkFilters($sqlfilters))
147
+            if (!DolibarrApi::_checkFilters($sqlfilters))
148 148
             {
149 149
                 throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
150 150
             }
151
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
152
-            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
151
+	        $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
152
+            $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
153 153
         }
154 154
 
155
-		$sql.= $db->order($sortfield, $sortorder);
155
+		$sql .= $db->order($sortfield, $sortorder);
156 156
 
157 157
 		if ($limit)
158 158
 		{
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 			}
163 163
 			$offset = $limit * $page;
164 164
 
165
-			$sql.= $db->plimit($limit + 1, $offset);
165
+			$sql .= $db->plimit($limit + 1, $offset);
166 166
 		}
167 167
 		$result = $db->query($sql);
168 168
 		if ($result)
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 			}
182 182
 		}
183 183
 		else {
184
-			throw new RestException(503, 'Error when retrieve contacts : ' . $sql);
184
+			throw new RestException(503, 'Error when retrieve contacts : '.$sql);
185 185
 		}
186 186
 		if (!count($obj_ret))
187 187
 		{
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 
238 238
 		if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe'))
239 239
 		{
240
-			throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
240
+			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
241 241
 		}
242 242
 
243 243
 		foreach ($request_data as $field => $value)
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 
273 273
 		if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe'))
274 274
 		{
275
-			throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
275
+			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
276 276
 		}
277 277
 
278 278
 		return $this->contact->delete($id);
@@ -312,19 +312,19 @@  discard block
 block discarded – undo
312 312
 	    }
313 313
 
314 314
 	    if (!DolibarrApi::_checkAccessToResource('contact', $contact->id, 'socpeople&societe')) {
315
-	        throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
315
+	        throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
316 316
 	    }
317 317
 
318 318
 	    // Check mandatory fields
319 319
 	    $login = $request_data["login"];
320 320
 	    $password = $request_data["password"];
321 321
 	    $useraccount = new User($this->db);
322
-	    $result = $useraccount->create_from_contact($contact,$login,$password);
322
+	    $result = $useraccount->create_from_contact($contact, $login, $password);
323 323
 	    if ($result <= 0) {
324 324
 	        throw new RestException(500, "User not created");
325 325
 	    }
326 326
 	    // password parameter not used in create_from_contact
327
-	    $useraccount->setPassword($useraccount,$password);
327
+	    $useraccount->setPassword($useraccount, $password);
328 328
 
329 329
 	    return $result;
330 330
 	}
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
      */
345 345
 	function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
346 346
 	{
347
-		if (! DolibarrApiAccess::$user->rights->categorie->lire) {
347
+		if (!DolibarrApiAccess::$user->rights->categorie->lire) {
348 348
 			throw new RestException(401);
349 349
 		}
350 350
 
Please login to merge, or discard this patch.