Passed
Push — master ( 3cffbe...0f9140 )
by Alxarafe
23:50
created
dolibarr/htdocs/expedition/class/expeditionbatch.class.php 3 patches
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -28,21 +28,21 @@  discard block
 block discarded – undo
28 28
  */
29 29
 class ExpeditionLineBatch extends CommonObject
30 30
 {
31
-	/**
32
-	 * @var string ID to identify managed object
33
-	 */
34
-	public $element='expeditionlignebatch';
35
-
36
-	private static $_table_element='expeditiondet_batch';		//!< Name of table without prefix where object is stored
37
-
38
-	var $sellby;
39
-	var $eatby;
40
-	var $batch;
41
-	var $qty;
42
-	var $dluo_qty; // deprecated, use qty
43
-	var $entrepot_id;
44
-	var $fk_origin_stock;
45
-	var $fk_expeditiondet;
31
+    /**
32
+     * @var string ID to identify managed object
33
+     */
34
+    public $element='expeditionlignebatch';
35
+
36
+    private static $_table_element='expeditiondet_batch';		//!< Name of table without prefix where object is stored
37
+
38
+    var $sellby;
39
+    var $eatby;
40
+    var $batch;
41
+    var $qty;
42
+    var $dluo_qty; // deprecated, use qty
43
+    var $entrepot_id;
44
+    var $fk_origin_stock;
45
+    var $fk_expeditiondet;
46 46
 
47 47
     /**
48 48
      *  Constructor
@@ -54,187 +54,187 @@  discard block
 block discarded – undo
54 54
         $this->db = $db;
55 55
     }
56 56
 
57
-	/**
58
-	 * Fill object based on a product-warehouse-batch's record
59
-	 *
60
-	 * @param	int		$id_stockdluo	Rowid in product_batch table
61
-	 * @return	int      		   	 -1 if KO, 1 if OK
62
-	 */
63
-	function fetchFromStock($id_stockdluo)
64
-	{
65
-		$sql = "SELECT";
66
-		$sql.= " pb.batch,";
67
-		$sql.= " pl.sellby,";
68
-		$sql.= " pl.eatby,";
69
-		$sql.= " ps.fk_entrepot";
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;
75
-
76
-		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
77
-		$resql=$this->db->query($sql);
78
-		if ($resql)
79
-		{
80
-			if ($this->db->num_rows($resql))
81
-			{
82
-				$obj = $this->db->fetch_object($resql);
83
-
84
-				$this->sellby = $this->db->jdate($obj->sellby);
85
-				$this->eatby = $this->db->jdate($obj->eatby);
86
-				$this->batch = $obj->batch;
87
-				$this->entrepot_id= $obj->fk_entrepot;
88
-				$this->fk_origin_stock=(int) $id_stockdluo;
89
-			}
90
-			$this->db->free($resql);
91
-
92
-			return 1;
93
-		}
94
-		else
95
-		{
96
-			$this->error="Error ".$this->db->lasterror();
97
-			return -1;
98
-		}
99
-	}
100
-
101
-	/**
102
-	 * Create an expeditiondet_batch DB record link to an expedtiondet record
103
-	 *
104
-	 * @param	int		$id_line_expdet		rowid of expedtiondet record
105
-	 * @return	int							<0 if KO, Id of record (>0) if OK
106
-	 */
107
-	function create($id_line_expdet)
108
-	{
109
-		$error = 0;
110
-
111
-		$id_line_expdet = (int) $id_line_expdet;
112
-
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.= ")";
128
-
129
-		dol_syslog(__METHOD__, LOG_DEBUG);
130
-		$resql=$this->db->query($sql);
131
-		if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
132
-
133
-		if (! $error)
134
-		{
57
+    /**
58
+     * Fill object based on a product-warehouse-batch's record
59
+     *
60
+     * @param	int		$id_stockdluo	Rowid in product_batch table
61
+     * @return	int      		   	 -1 if KO, 1 if OK
62
+     */
63
+    function fetchFromStock($id_stockdluo)
64
+    {
65
+        $sql = "SELECT";
66
+        $sql.= " pb.batch,";
67
+        $sql.= " pl.sellby,";
68
+        $sql.= " pl.eatby,";
69
+        $sql.= " ps.fk_entrepot";
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;
75
+
76
+        dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
77
+        $resql=$this->db->query($sql);
78
+        if ($resql)
79
+        {
80
+            if ($this->db->num_rows($resql))
81
+            {
82
+                $obj = $this->db->fetch_object($resql);
83
+
84
+                $this->sellby = $this->db->jdate($obj->sellby);
85
+                $this->eatby = $this->db->jdate($obj->eatby);
86
+                $this->batch = $obj->batch;
87
+                $this->entrepot_id= $obj->fk_entrepot;
88
+                $this->fk_origin_stock=(int) $id_stockdluo;
89
+            }
90
+            $this->db->free($resql);
91
+
92
+            return 1;
93
+        }
94
+        else
95
+        {
96
+            $this->error="Error ".$this->db->lasterror();
97
+            return -1;
98
+        }
99
+    }
100
+
101
+    /**
102
+     * Create an expeditiondet_batch DB record link to an expedtiondet record
103
+     *
104
+     * @param	int		$id_line_expdet		rowid of expedtiondet record
105
+     * @return	int							<0 if KO, Id of record (>0) if OK
106
+     */
107
+    function create($id_line_expdet)
108
+    {
109
+        $error = 0;
110
+
111
+        $id_line_expdet = (int) $id_line_expdet;
112
+
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.= ")";
128
+
129
+        dol_syslog(__METHOD__, LOG_DEBUG);
130
+        $resql=$this->db->query($sql);
131
+        if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
132
+
133
+        if (! $error)
134
+        {
135 135
             $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.self::$_table_element);
136
-			$this->fk_expeditiondet=$id_line_expdet;
137
-			return $this->id;
138
-		}
139
-		else
140
-		{
141
-			foreach($this->errors as $errmsg)
142
-			{
143
-	            dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
144
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
145
-			}
146
-			$this->db->rollback();
147
-			return -1*$error;
148
-		}
149
-	}
150
-
151
-	/**
152
-	 * Delete batch record attach to a shipment
153
-	 *
154
-	 * @param	DoliDB	$db				Database object
155
-	 * @param	int		$id_expedition	rowid of shipment
156
-	 * @return 	int						-1 if KO, 1 if OK
157
-	 */
158
-	static function deletefromexp($db,$id_expedition)
159
-	{
160
-		$id_expedition = (int) $id_expedition;
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.")";
164
-
165
-		dol_syslog(__METHOD__, LOG_DEBUG);
166
-		if ($db->query($sql))
167
-		{
168
-			return 1;
169
-		}
170
-		else
171
-		{
172
-			return -1;
173
-		}
174
-	}
175
-
176
-	/**
177
-	 * Retrieve all batch number detailed information of a shipment line
178
-	 *
179
-	 * @param	DoliDB		$db					Database object
180
-	 * @param	int			$id_line_expdet		id of shipment line
181
-	 * @param	int			$fk_product			If provided, load also detailed information of lot
182
-	 * @return	int|array						-1 if KO, array of ExpeditionLineBatch if OK
183
-	 */
184
-	static function fetchAll($db, $id_line_expdet, $fk_product=0)
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";
194
-		if ($fk_product > 0)
195
-		{
196
-			$sql.= ", pl.sellby";
197
-			$sql.= ", pl.eatby";
198
-		}
199
-		$sql.= " FROM ".MAIN_DB_PREFIX.self::$_table_element." as eb";
200
-		if ($fk_product > 0)
201
-		{
202
-			$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON pl.batch = eb.batch AND pl.fk_product = ".$fk_product;
203
-		}
204
-		$sql.= " WHERE fk_expeditiondet=".(int) $id_line_expdet;
205
-
206
-		dol_syslog(__METHOD__ ."", LOG_DEBUG);
207
-		$resql=$db->query($sql);
208
-		if ($resql)
209
-		{
210
-			$num=$db->num_rows($resql);
211
-			$i=0;
212
-			$ret = array();
213
-			while ($i<$num)
214
-			{
215
-				$tmp=new self($db);
216
-
217
-				$obj = $db->fetch_object($resql);
218
-
219
-				$tmp->sellby = $db->jdate($obj->sellby ? $obj->sellby : $obj->oldsellby);
220
-				$tmp->eatby = $db->jdate($obj->eatby ? $obj->eatby : $obj->oldeatby);
221
-				$tmp->batch = $obj->batch;
222
-				$tmp->id = $obj->rowid;
223
-				$tmp->fk_origin_stock = $obj->fk_origin_stock;
224
-				$tmp->fk_expeditiondet = $obj->fk_expeditiondet;
225
-				$tmp->dluo_qty = $obj->qty; // dluo_qty deprecated, use qty
226
-				$tmp->qty = $obj->qty;
227
-
228
-				$ret[]=$tmp;
229
-				$i++;
230
-			}
231
-			$db->free($resql);
232
-			return $ret;
233
-		}
234
-		else
235
-		{
236
-			dol_print_error($db);
237
-			return -1;
238
-		}
239
-	}
136
+            $this->fk_expeditiondet=$id_line_expdet;
137
+            return $this->id;
138
+        }
139
+        else
140
+        {
141
+            foreach($this->errors as $errmsg)
142
+            {
143
+                dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
144
+                $this->error.=($this->error?', '.$errmsg:$errmsg);
145
+            }
146
+            $this->db->rollback();
147
+            return -1*$error;
148
+        }
149
+    }
150
+
151
+    /**
152
+     * Delete batch record attach to a shipment
153
+     *
154
+     * @param	DoliDB	$db				Database object
155
+     * @param	int		$id_expedition	rowid of shipment
156
+     * @return 	int						-1 if KO, 1 if OK
157
+     */
158
+    static function deletefromexp($db,$id_expedition)
159
+    {
160
+        $id_expedition = (int) $id_expedition;
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.")";
164
+
165
+        dol_syslog(__METHOD__, LOG_DEBUG);
166
+        if ($db->query($sql))
167
+        {
168
+            return 1;
169
+        }
170
+        else
171
+        {
172
+            return -1;
173
+        }
174
+    }
175
+
176
+    /**
177
+     * Retrieve all batch number detailed information of a shipment line
178
+     *
179
+     * @param	DoliDB		$db					Database object
180
+     * @param	int			$id_line_expdet		id of shipment line
181
+     * @param	int			$fk_product			If provided, load also detailed information of lot
182
+     * @return	int|array						-1 if KO, array of ExpeditionLineBatch if OK
183
+     */
184
+    static function fetchAll($db, $id_line_expdet, $fk_product=0)
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";
194
+        if ($fk_product > 0)
195
+        {
196
+            $sql.= ", pl.sellby";
197
+            $sql.= ", pl.eatby";
198
+        }
199
+        $sql.= " FROM ".MAIN_DB_PREFIX.self::$_table_element." as eb";
200
+        if ($fk_product > 0)
201
+        {
202
+            $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON pl.batch = eb.batch AND pl.fk_product = ".$fk_product;
203
+        }
204
+        $sql.= " WHERE fk_expeditiondet=".(int) $id_line_expdet;
205
+
206
+        dol_syslog(__METHOD__ ."", LOG_DEBUG);
207
+        $resql=$db->query($sql);
208
+        if ($resql)
209
+        {
210
+            $num=$db->num_rows($resql);
211
+            $i=0;
212
+            $ret = array();
213
+            while ($i<$num)
214
+            {
215
+                $tmp=new self($db);
216
+
217
+                $obj = $db->fetch_object($resql);
218
+
219
+                $tmp->sellby = $db->jdate($obj->sellby ? $obj->sellby : $obj->oldsellby);
220
+                $tmp->eatby = $db->jdate($obj->eatby ? $obj->eatby : $obj->oldeatby);
221
+                $tmp->batch = $obj->batch;
222
+                $tmp->id = $obj->rowid;
223
+                $tmp->fk_origin_stock = $obj->fk_origin_stock;
224
+                $tmp->fk_expeditiondet = $obj->fk_expeditiondet;
225
+                $tmp->dluo_qty = $obj->qty; // dluo_qty deprecated, use qty
226
+                $tmp->qty = $obj->qty;
227
+
228
+                $ret[]=$tmp;
229
+                $i++;
230
+            }
231
+            $db->free($resql);
232
+            return $ret;
233
+        }
234
+        else
235
+        {
236
+            dol_print_error($db);
237
+            return -1;
238
+        }
239
+    }
240 240
 }
Please login to merge, or discard this 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.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -90,8 +90,7 @@  discard block
 block discarded – undo
90 90
 			$this->db->free($resql);
91 91
 
92 92
 			return 1;
93
-		}
94
-		else
93
+		} else
95 94
 		{
96 95
 			$this->error="Error ".$this->db->lasterror();
97 96
 			return -1;
@@ -135,8 +134,7 @@  discard block
 block discarded – undo
135 134
             $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.self::$_table_element);
136 135
 			$this->fk_expeditiondet=$id_line_expdet;
137 136
 			return $this->id;
138
-		}
139
-		else
137
+		} else
140 138
 		{
141 139
 			foreach($this->errors as $errmsg)
142 140
 			{
@@ -166,8 +164,7 @@  discard block
 block discarded – undo
166 164
 		if ($db->query($sql))
167 165
 		{
168 166
 			return 1;
169
-		}
170
-		else
167
+		} else
171 168
 		{
172 169
 			return -1;
173 170
 		}
@@ -230,8 +227,7 @@  discard block
 block discarded – undo
230 227
 			}
231 228
 			$db->free($resql);
232 229
 			return $ret;
233
-		}
234
-		else
230
+		} else
235 231
 		{
236 232
 			dol_print_error($db);
237 233
 			return -1;
Please login to merge, or discard this patch.
dolibarr/htdocs/expedition/class/expedition.class.php 3 patches
Indentation   +2658 added lines, -2658 removed lines patch added patch discarded remove patch
@@ -45,2305 +45,2305 @@  discard block
 block discarded – undo
45 45
  */
46 46
 class Expedition extends CommonObject
47 47
 {
48
-	/**
49
-	 * @var string ID to identify managed object
50
-	 */
51
-	public $element="shipping";
52
-
53
-	/**
54
-	 * @var int Field with ID of parent key if this field has a parent
55
-	 */
56
-	public $fk_element="fk_expedition";
57
-
58
-	/**
59
-	 * @var string Name of table without prefix where object is stored
60
-	 */
61
-	public $table_element="expedition";
62
-
63
-	/**
64
-	 * @var int    Name of subtable line
65
-	 */
66
-	public $table_element_line="expeditiondet";
67
-
68
-	/**
69
-	 * 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
70
-	 * @var int
71
-	 */
72
-	public $ismultientitymanaged = 1;
73
-
74
-	/**
75
-	 * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
76
-	 */
77
-	public $picto = 'sending';
78
-
79
-	public $socid;
80
-
81
-	/**
82
-	 * @var string Customer ref
83
-	 */
84
-	public $ref_customer;
85
-
86
-	/**
87
-	 * @var string internal ref
88
-	 */
89
-	public $ref_int;
90
-
91
-	public $brouillon;
92
-
93
-	/**
94
-	 * @var int warehouse id
95
-	 */
96
-	public $entrepot_id;
97
-	public $lines=array();
98
-
99
-	/**
100
-	 * @var string Tracking number
101
-	 */
102
-	public $tracking_number;
103
-
104
-	/**
105
-	 * @var string Tracking url
106
-	 */
107
-	public $tracking_url;
108
-	public $billed;
109
-
110
-	/**
111
-	 * @var string name of pdf model
112
-	 */
113
-	public $model_pdf;
114
-
115
-	public $trueWeight;
116
-	public $weight_units;
117
-	public $trueWidth;
118
-	public $width_units;
119
-	public $trueHeight;
120
-	public $height_units;
121
-	public $trueDepth;
122
-	public $depth_units;
123
-	// A denormalized value
124
-	public $trueSize;
125
-
126
-	public $date_delivery;		// Date delivery planed
127
-
128
-	/**
129
-	 * @deprecated
130
-	 * @see date_shipping
131
-	 */
132
-	public $date;
133
-
134
-	/**
135
-	 * @deprecated
136
-	 * @see date_shipping
137
-	 */
138
-	public $date_expedition;
139
-
140
-	/**
141
-	 * Effective delivery date
142
-	 * @var int
143
-	 */
144
-	public $date_shipping;
145
-
146
-	public $date_creation;
147
-	public $date_valid;
148
-
149
-	public $meths;
150
-	public $listmeths;			// List of carriers
151
-
152
-    /**
153
-	 * Draft status
154
-	 */
155
-	const STATUS_DRAFT = 0;
156
-
157
-	/**
158
-	 * Validated status
159
-	 */
160
-	const STATUS_VALIDATED = 1;
161
-
162
-	/**
163
-	 * Closed status
164
-	 */
165
-	const STATUS_CLOSED = 2;
166
-
167
-
168
-
169
-	/**
170
-	 *	Constructor
171
-	 *
172
-	 *  @param		DoliDB		$db      Database handler
173
-	 */
174
-	function __construct($db)
175
-	{
176
-		global $conf;
177
-
178
-		$this->db = $db;
179
-		$this->lines = array();
180
-		$this->products = array();
181
-
182
-		// List of long language codes for status
183
-		$this->statuts = array();
184
-		$this->statuts[-1] = 'StatusSendingCanceled';
185
-		$this->statuts[0]  = 'StatusSendingDraft';
186
-		$this->statuts[1]  = 'StatusSendingValidated';
187
-		$this->statuts[2]  = 'StatusSendingProcessed';
188
-
189
-		// List of short language codes for status
190
-		$this->statutshorts = array();
191
-		$this->statutshorts[-1] = 'StatusSendingCanceledShort';
192
-		$this->statutshorts[0]  = 'StatusSendingDraftShort';
193
-		$this->statutshorts[1]  = 'StatusSendingValidatedShort';
194
-		$this->statutshorts[2]  = 'StatusSendingProcessedShort';
195
-
196
-		/* Status "billed" or not is managed by another field than status
197
-		if (! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))
198
-		{
199
-			$this->statuts[2]  = 'StatusSendingBilled';
200
-			$this->statutshorts[2]  = 'StatusSendingBilledShort';
201
-		}*/
202
-	}
203
-
204
-	/**
205
-	 *	Return next contract ref
206
-	 *
207
-	 *	@param	Societe		$soc	Thirdparty object
208
-	 *	@return string				Free reference for contract
209
-	 */
210
-	function getNextNumRef($soc)
211
-	{
212
-		global $langs, $conf;
213
-		$langs->load("sendings");
214
-
215
-		if (!empty($conf->global->EXPEDITION_ADDON_NUMBER))
216
-		{
217
-			$mybool = false;
218
-
219
-			$file = $conf->global->EXPEDITION_ADDON_NUMBER.".php";
220
-			$classname = $conf->global->EXPEDITION_ADDON_NUMBER;
221
-
222
-			// Include file with class
223
-			$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
224
-
225
-			foreach ($dirmodels as $reldir) {
226
-
227
-				$dir = dol_buildpath($reldir."core/modules/expedition/");
228
-
229
-				// Load file with numbering class (if found)
230
-				$mybool|[email protected]_once $dir.$file;
231
-			}
232
-
233
-			if (! $mybool)
234
-			{
235
-				dol_print_error('',"Failed to include file ".$file);
236
-				return '';
237
-			}
238
-
239
-			$obj = new $classname();
240
-			$numref = "";
241
-			$numref = $obj->getNextValue($soc,$this);
242
-
243
-			if ( $numref != "")
244
-			{
245
-				return $numref;
246
-			}
247
-			else
248
-			{
249
-				dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
250
-				return "";
251
-			}
252
-		}
253
-		else
254
-		{
255
-			print $langs->trans("Error")." ".$langs->trans("Error_EXPEDITION_ADDON_NUMBER_NotDefined");
256
-			return "";
257
-		}
258
-	}
259
-
260
-	/**
261
-	 *  Create expedition en base
262
-	 *
263
-	 *  @param	User	$user       Objet du user qui cree
264
-	 * 	@param		int		$notrigger	1=Does not execute triggers, 0= execute triggers
265
-	 *  @return int 				<0 si erreur, id expedition creee si ok
266
-	 */
267
-	function create($user, $notrigger=0)
268
-	{
269
-		global $conf, $hookmanager;
270
-
271
-		$now=dol_now();
272
-
273
-		require_once DOL_DOCUMENT_ROOT .'/product/stock/class/mouvementstock.class.php';
274
-		$error = 0;
275
-
276
-		// Clean parameters
277
-		$this->brouillon = 1;
278
-		$this->tracking_number = dol_sanitizeFileName($this->tracking_number);
279
-		if (empty($this->fk_project)) $this->fk_project = 0;
280
-
281
-		$this->user = $user;
282
-
283
-
284
-		$this->db->begin();
285
-
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";