Passed
Push — master ( 222e44...208bd5 )
by Alxarafe
31:22
created
dolibarr/htdocs/comm/prospect/index.php 3 patches
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 
33 33
 if ($user->societe_id > 0)
34 34
 {
35
-	$socid = $user->societe_id;
35
+    $socid = $user->societe_id;
36 36
 }
37 37
 
38 38
 
@@ -54,16 +54,16 @@  discard block
 block discarded – undo
54 54
 
55 55
 if (! empty($conf->propal->enabled))
56 56
 {
57
-	$var=false;
58
-	print '<form method="post" action="'.DOL_URL_ROOT.'/comm/propal/card.php">';
59
-	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
60
-	print '<table class="noborder nohover" width="100%">';
61
-	print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("SearchAProposal").'</td></tr>';
62
-	print '<tr class="oddeven"><td>';
63
-	print $langs->trans("Ref").':</td><td><input type="text" class="flat" name="sf_ref" size="18"></td><td rowspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
64
-	print '<tr class="oddeven"><td class="nowrap">'.$langs->trans("Other").':</td><td><input type="text" class="flat" name="sall" size="18"></td>';
65
-	print '</tr>';
66
-	print "</table></form><br>\n";
57
+    $var=false;
58
+    print '<form method="post" action="'.DOL_URL_ROOT.'/comm/propal/card.php">';
59
+    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
60
+    print '<table class="noborder nohover" width="100%">';
61
+    print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("SearchAProposal").'</td></tr>';
62
+    print '<tr class="oddeven"><td>';
63
+    print $langs->trans("Ref").':</td><td><input type="text" class="flat" name="sf_ref" size="18"></td><td rowspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
64
+    print '<tr class="oddeven"><td class="nowrap">'.$langs->trans("Other").':</td><td><input type="text" class="flat" name="sall" size="18"></td>';
65
+    print '</tr>';
66
+    print "</table></form><br>\n";
67 67
 }
68 68
 
69 69
 /*
@@ -85,26 +85,26 @@  discard block
 block discarded – undo
85 85
 $resql=$db->query($sql);
86 86
 if ($resql)
87 87
 {
88
-	$num = $db->num_rows($resql);
89
-	$i = 0;
90
-	if ($num > 0 )
91
-	{
92
-		print '<table class="noborder" width="100%">';
93
-		print '<tr class="liste_titre">';
94
-		print '<td colspan="2">'.$langs->trans("ProspectsByStatus").'</td></tr>';
95
-		while ($i < $num)
96
-		{
97
-			$obj = $db->fetch_object($resql);
98
-
99
-			print '<tr class="oddeven"><td>';
100
-			print '<a href="prospects.php?page=0&amp;stcomm='.$obj->id.'">';
101
-			print img_action($langs->trans("Show"),$obj->id).' ';
102
-			print $langs->trans("StatusProspect".$obj->id);
103
-			print '</a></td><td align="right">'.$obj->cc.'</td></tr>';
104
-			$i++;
105
-		}
106
-		print "</table><br>";
107
-	}
88
+    $num = $db->num_rows($resql);
89
+    $i = 0;
90
+    if ($num > 0 )
91
+    {
92
+        print '<table class="noborder" width="100%">';
93
+        print '<tr class="liste_titre">';
94
+        print '<td colspan="2">'.$langs->trans("ProspectsByStatus").'</td></tr>';
95
+        while ($i < $num)
96
+        {
97
+            $obj = $db->fetch_object($resql);
98
+
99
+            print '<tr class="oddeven"><td>';
100
+            print '<a href="prospects.php?page=0&amp;stcomm='.$obj->id.'">';
101
+            print img_action($langs->trans("Show"),$obj->id).' ';
102
+            print $langs->trans("StatusProspect".$obj->id);
103
+            print '</a></td><td align="right">'.$obj->cc.'</td></tr>';
104
+            $i++;
105
+        }
106
+        print "</table><br>";
107
+    }
108 108
 }
109 109
 
110 110
 
@@ -113,47 +113,47 @@  discard block
 block discarded – undo
113 113
  */
114 114
 if (! empty($conf->propal->enabled) && $user->rights->propale->lire)
115 115
 {
116
-	$sql = "SELECT p.rowid, p.ref, p.price, s.nom as sname";
117
-	$sql.= " FROM ".MAIN_DB_PREFIX."propal as p";
118
-	$sql.= ", ".MAIN_DB_PREFIX."societe as s";
119
-	if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
120
-	$sql.= " WHERE p.fk_statut = 0";
121
-	$sql.= " AND p.fk_soc = s.rowid";
122
-	$sql.= " AND p.entity IN (".getEntity('propal').")";
123
-	if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
124
-
125
-	$resql=$db->query($sql);
126
-	if ($resql)
127
-	{
128
-		$total=0;
129
-		$num = $db->num_rows($resql);
130
-		$i = 0;
131
-		if ($num > 0)
132
-		{
133
-			print '<table class="noborder"" width="100%">';
134
-			print '<tr class="liste_titre">';
135
-			print '<td colspan="2">'.$langs->trans("ProposalsDraft").'</td></tr>';
136
-
137
-			while ($i < $num)
138
-			{
139
-				$obj = $db->fetch_object($resql);
140
-
141
-				print '<tr class="oddeven"><td>';
142
-				print '<a href="'.DOL_URL_ROOT.'/comm/propal/card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowPropal"),"propal").' '.$obj->ref.'</a>';
143
-				print '</td><td align="right">';
144
-				print price($obj->price);
145
-				print "</td></tr>";
146
-				$i++;
147
-				$total += $obj->price;
148
-			}
149
-			if ($total>0) {
150
-
151
-				print '<tr class="liste_total"><td>'.$langs->trans("Total")."</td><td align=\"right\">".price($total)."</td></tr>";
152
-			}
153
-			print "</table><br>";
154
-		}
155
-		$db->free($resql);
156
-	}
116
+    $sql = "SELECT p.rowid, p.ref, p.price, s.nom as sname";
117
+    $sql.= " FROM ".MAIN_DB_PREFIX."propal as p";
118
+    $sql.= ", ".MAIN_DB_PREFIX."societe as s";
119
+    if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
120
+    $sql.= " WHERE p.fk_statut = 0";
121
+    $sql.= " AND p.fk_soc = s.rowid";
122
+    $sql.= " AND p.entity IN (".getEntity('propal').")";
123
+    if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
124
+
125
+    $resql=$db->query($sql);
126
+    if ($resql)
127
+    {
128
+        $total=0;
129
+        $num = $db->num_rows($resql);
130
+        $i = 0;
131
+        if ($num > 0)
132
+        {
133
+            print '<table class="noborder"" width="100%">';
134
+            print '<tr class="liste_titre">';
135
+            print '<td colspan="2">'.$langs->trans("ProposalsDraft").'</td></tr>';
136
+
137
+            while ($i < $num)
138
+            {
139
+                $obj = $db->fetch_object($resql);
140
+
141
+                print '<tr class="oddeven"><td>';
142
+                print '<a href="'.DOL_URL_ROOT.'/comm/propal/card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowPropal"),"propal").' '.$obj->ref.'</a>';
143
+                print '</td><td align="right">';
144
+                print price($obj->price);
145
+                print "</td></tr>";
146
+                $i++;
147
+                $total += $obj->price;
148
+            }
149
+            if ($total>0) {
150
+
151
+                print '<tr class="liste_total"><td>'.$langs->trans("Total")."</td><td align=\"right\">".price($total)."</td></tr>";
152
+            }
153
+            print "</table><br>";
154
+        }
155
+        $db->free($resql);
156
+    }
157 157
 }
158 158
 
159 159
 
@@ -171,64 +171,64 @@  discard block
 block discarded – undo
171 171
  */
172 172
 if (! empty($conf->propal->enabled) && $user->rights->propale->lire)
173 173
 {
174
-	$sql = "SELECT s.nom as name, s.rowid as socid, s.client, s.canvas,";
175
-	$sql.= " p.rowid as propalid, p.total as total_ttc, p.ref, p.datep as dp, c.label as statut, c.id as statutid";
176
-	$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
177
-	$sql.= ", ".MAIN_DB_PREFIX."propal as p";
178
-	$sql.= ", ".MAIN_DB_PREFIX."c_propalst as c";
179
-	if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
180
-	$sql.= " WHERE p.fk_soc = s.rowid";
181
-	$sql.= " AND p.fk_statut = c.id";
182
-	$sql.= " AND p.fk_statut = 1";
183
-	$sql.= " AND p.entity IN (".getEntity('propal').")";
184
-	if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
185
-	if ($socid) $sql.= " AND s.rowid = ".$socid;
186
-	$sql.= " ORDER BY p.rowid DESC";
187
-	$sql.= $db->plimit(5, 0);
188
-
189
-	$resql=$db->query($sql);
190
-	if ($resql)
191
-	{
192
-		$total = 0;
193
-		$num = $db->num_rows($resql);
194
-		$i = 0;
195
-		if ($num > 0)
196
-		{
197
-			print '<table class="noborder" width="100%">';
198
-			print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("ProposalsOpened").'</td></tr>';
199
-
200
-			while ($i < $num)
201
-			{
202
-				$obj = $db->fetch_object($resql);
203
-
204
-				print '<tr class="oddeven"><td>';
205
-				print '<a href="../propal.php?id='.$obj->propalid.'">';
206
-				print img_object($langs->trans("ShowPropal"),"propal").' '.$obj->ref.'</a></td>';
207
-
208
-				print "<td>";
174
+    $sql = "SELECT s.nom as name, s.rowid as socid, s.client, s.canvas,";
175
+    $sql.= " p.rowid as propalid, p.total as total_ttc, p.ref, p.datep as dp, c.label as statut, c.id as statutid";
176
+    $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
177
+    $sql.= ", ".MAIN_DB_PREFIX."propal as p";
178
+    $sql.= ", ".MAIN_DB_PREFIX."c_propalst as c";
179
+    if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
180
+    $sql.= " WHERE p.fk_soc = s.rowid";
181
+    $sql.= " AND p.fk_statut = c.id";
182
+    $sql.= " AND p.fk_statut = 1";
183
+    $sql.= " AND p.entity IN (".getEntity('propal').")";
184
+    if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
185
+    if ($socid) $sql.= " AND s.rowid = ".$socid;
186
+    $sql.= " ORDER BY p.rowid DESC";
187
+    $sql.= $db->plimit(5, 0);
188
+
189
+    $resql=$db->query($sql);
190
+    if ($resql)
191
+    {
192
+        $total = 0;
193
+        $num = $db->num_rows($resql);
194
+        $i = 0;
195
+        if ($num > 0)
196
+        {
197
+            print '<table class="noborder" width="100%">';
198
+            print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("ProposalsOpened").'</td></tr>';
199
+
200
+            while ($i < $num)
201
+            {
202
+                $obj = $db->fetch_object($resql);
203
+
204
+                print '<tr class="oddeven"><td>';
205
+                print '<a href="../propal.php?id='.$obj->propalid.'">';
206
+                print img_object($langs->trans("ShowPropal"),"propal").' '.$obj->ref.'</a></td>';
207
+
208
+                print "<td>";
209 209
                 $companystatic->id=$obj->socid;
210 210
                 $companystatic->name=$obj->name;
211 211
                 $companystatic->client=$obj->client;
212 212
                 $companystatic->canvas=$obj->canvas;
213 213
                 print $companystatic->getNomUrl(1,'',44);
214
-				print "</td>\n";
215
-				print "<td align=\"right\">";
216
-				print dol_print_date($db->jdate($obj->dp),'day')."</td>\n";
217
-				print "<td align=\"right\">".price($obj->total_ttc)."</td></tr>\n";
218
-				$i++;
219
-				$total += $obj->price;
220
-			}
221
-			if ($total>0)
222
-			{
223
-				print '<tr class="liste_total"><td colspan="3" align="right">'.$langs->trans("Total")."</td><td align=\"right\">".price($total)."</td></tr>";
224
-			}
225
-			print "</table><br>";
226
-		}
227
-	}
228
-	else
229
-	{
230
-		dol_print_error($db);
231
-	}
214
+                print "</td>\n";
215
+                print "<td align=\"right\">";
216
+                print dol_print_date($db->jdate($obj->dp),'day')."</td>\n";
217
+                print "<td align=\"right\">".price($obj->total_ttc)."</td></tr>\n";
218
+                $i++;
219
+                $total += $obj->price;
220
+            }
221
+            if ($total>0)
222
+            {
223
+                print '<tr class="liste_total"><td colspan="3" align="right">'.$langs->trans("Total")."</td><td align=\"right\">".price($total)."</td></tr>";
224
+            }
225
+            print "</table><br>";
226
+        }
227
+    }
228
+    else
229
+    {
230
+        dol_print_error($db);
231
+    }
232 232
 }
233 233
 
234 234
 /*
@@ -247,28 +247,28 @@  discard block
 block discarded – undo
247 247
 $resql=$db->query($sql);
248 248
 if ($resql)
249 249
 {
250
-	$num = $db->num_rows($resql);
251
-	$i = 0;
252
-	if ($num > 0 )
253
-	{
254
-		print '<table class="noborder" width="100%">';
255
-		print '<tr class="liste_titre"><td>'.$langs->trans("ProspectToContact").'</td></tr>';
256
-
257
-		while ($i < $num)
258
-		{
259
-			$obj = $db->fetch_object($resql);
260
-
261
-			print '<tr class="oddeven"><td width="12%">';
250
+    $num = $db->num_rows($resql);
251
+    $i = 0;
252
+    if ($num > 0 )
253
+    {
254
+        print '<table class="noborder" width="100%">';
255
+        print '<tr class="liste_titre"><td>'.$langs->trans("ProspectToContact").'</td></tr>';
256
+
257
+        while ($i < $num)
258
+        {
259
+            $obj = $db->fetch_object($resql);
260
+
261
+            print '<tr class="oddeven"><td width="12%">';
262 262
             $companystatic->id=$obj->socid;
263 263
             $companystatic->name=$obj->name;
264 264
             $companystatic->client=$obj->client;
265 265
             $companystatic->canvas=$obj->canvas;
266 266
             print $companystatic->getNomUrl(1,'prospect',44);
267
-			print '</td></tr>';
268
-			$i++;
269
-		}
270
-		print "</table><br>";
271
-	}
267
+            print '</td></tr>';
268
+            $i++;
269
+        }
270
+        print "</table><br>";
271
+    }
272 272
 }
273 273
 
274 274
 
Please login to merge, or discard this patch.
Braces   +31 added lines, -12 removed lines patch added patch discarded remove patch
@@ -74,11 +74,15 @@  discard block
 block discarded – undo
74 74
 $sql = "SELECT count(*) as cc, st.libelle, st.id";
75 75
 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
76 76
 $sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st ";
77
-if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
77
+if (! $user->rights->societe->client->voir && ! $socid) {
78
+    $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
79
+}
78 80
 $sql.= " WHERE s.fk_stcomm = st.id";
79 81
 $sql.= " AND s.client IN (2, 3)";
80 82
 $sql.= " AND s.entity IN (".getEntity($companystatic->element).")";
81
-if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
83
+if (! $user->rights->societe->client->voir && ! $socid) {
84
+    $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
85
+}
82 86
 $sql.= " GROUP BY st.id";
83 87
 $sql.= " ORDER BY st.id";
84 88
 
@@ -116,11 +120,15 @@  discard block
 block discarded – undo
116 120
 	$sql = "SELECT p.rowid, p.ref, p.price, s.nom as sname";
117 121
 	$sql.= " FROM ".MAIN_DB_PREFIX."propal as p";
118 122
 	$sql.= ", ".MAIN_DB_PREFIX."societe as s";
119
-	if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
123
+	if (! $user->rights->societe->client->voir && ! $socid) {
124
+	    $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
125
+	}
120 126
 	$sql.= " WHERE p.fk_statut = 0";
121 127
 	$sql.= " AND p.fk_soc = s.rowid";
122 128
 	$sql.= " AND p.entity IN (".getEntity('propal').")";
123
-	if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
129
+	if (! $user->rights->societe->client->voir && ! $socid) {
130
+	    $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
131
+	}
124 132
 
125 133
 	$resql=$db->query($sql);
126 134
 	if ($resql)
@@ -164,7 +172,9 @@  discard block
 block discarded – undo
164 172
 /*
165 173
  * Actions commerciales a faire
166 174
  */
167
-if (! empty($conf->agenda->enabled)) show_array_actions_to_do(10);
175
+if (! empty($conf->agenda->enabled)) {
176
+    show_array_actions_to_do(10);
177
+}
168 178
 
169 179
 /*
170 180
  * Dernieres propales ouvertes
@@ -176,13 +186,19 @@  discard block
 block discarded – undo
176 186
 	$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
177 187
 	$sql.= ", ".MAIN_DB_PREFIX."propal as p";
178 188
 	$sql.= ", ".MAIN_DB_PREFIX."c_propalst as c";
179
-	if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
189
+	if (! $user->rights->societe->client->voir && ! $socid) {
190
+	    $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
191
+	}
180 192
 	$sql.= " WHERE p.fk_soc = s.rowid";
181 193
 	$sql.= " AND p.fk_statut = c.id";
182 194
 	$sql.= " AND p.fk_statut = 1";
183 195
 	$sql.= " AND p.entity IN (".getEntity('propal').")";
184
-	if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
185
-	if ($socid) $sql.= " AND s.rowid = ".$socid;
196
+	if (! $user->rights->societe->client->voir && ! $socid) {
197
+	    $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
198
+	}
199
+	if ($socid) {
200
+	    $sql.= " AND s.rowid = ".$socid;
201
+	}
186 202
 	$sql.= " ORDER BY p.rowid DESC";
187 203
 	$sql.= $db->plimit(5, 0);
188 204
 
@@ -224,8 +240,7 @@  discard block
 block discarded – undo
224 240
 			}
225 241
 			print "</table><br>";
226 242
 		}
227
-	}
228
-	else
243
+	} else
229 244
 	{
230 245
 		dol_print_error($db);
231 246
 	}
@@ -237,10 +252,14 @@  discard block
 block discarded – undo
237 252
  */
238 253
 $sql = "SELECT s.nom as name, s.rowid as socid, s.client, s.canvas";
239 254
 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
240
-if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
255
+if (! $user->rights->societe->client->voir && ! $socid) {
256
+    $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
257
+}
241 258
 $sql.= " WHERE s.fk_stcomm = 1";
242 259
 $sql.= " AND s.entity IN (".getEntity($companystatic->element).")";
243
-if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
260
+if (! $user->rights->societe->client->voir && ! $socid) {
261
+    $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
262
+}
244 263
 $sql.= " ORDER BY s.tms ASC";
245 264
 $sql.= $db->plimit(15, 0);
246 265
 
Please login to merge, or discard this patch.
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 
27 27
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
28 28
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
29
-require DOL_BASE_PATH . '/main.inc.php';
29
+require DOL_BASE_PATH.'/main.inc.php';
30 30
 require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
31 31
 
32 32
 // Load translation files required by the page
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
  *	View
45 45
  */
46 46
 
47
-$companystatic=new Societe($db);
47
+$companystatic = new Societe($db);
48 48
 
49 49
 llxHeader();
50 50
 
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
 print '<div class="fichecenter"><div class="fichethirdleft">';
56 56
 
57 57
 
58
-if (! empty($conf->propal->enabled))
58
+if (!empty($conf->propal->enabled))
59 59
 {
60
-	$var=false;
60
+	$var = false;
61 61
 	print '<form method="post" action="'.DOL_URL_ROOT.'/comm/propal/card.php">';
62 62
 	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
63 63
 	print '<table class="noborder nohover" width="100%">';
@@ -75,22 +75,22 @@  discard block
 block discarded – undo
75 75
  */
76 76
 
77 77
 $sql = "SELECT count(*) as cc, st.libelle, st.id";
78
-$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
79
-$sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st ";
80
-if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
81
-$sql.= " WHERE s.fk_stcomm = st.id";
82
-$sql.= " AND s.client IN (2, 3)";
83
-$sql.= " AND s.entity IN (".getEntity($companystatic->element).")";
84
-if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
85
-$sql.= " GROUP BY st.id";
86
-$sql.= " ORDER BY st.id";
87
-
88
-$resql=$db->query($sql);
78
+$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
79
+$sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st ";
80
+if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
81
+$sql .= " WHERE s.fk_stcomm = st.id";
82
+$sql .= " AND s.client IN (2, 3)";
83
+$sql .= " AND s.entity IN (".getEntity($companystatic->element).")";
84
+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
85
+$sql .= " GROUP BY st.id";
86
+$sql .= " ORDER BY st.id";
87
+
88
+$resql = $db->query($sql);
89 89
 if ($resql)
90 90
 {
91 91
 	$num = $db->num_rows($resql);
92 92
 	$i = 0;
93
-	if ($num > 0 )
93
+	if ($num > 0)
94 94
 	{
95 95
 		print '<table class="noborder" width="100%">';
96 96
 		print '<tr class="liste_titre">';
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 
102 102
 			print '<tr class="oddeven"><td>';
103 103
 			print '<a href="prospects.php?page=0&amp;stcomm='.$obj->id.'">';
104
-			print img_action($langs->trans("Show"),$obj->id).' ';
104
+			print img_action($langs->trans("Show"), $obj->id).' ';
105 105
 			print $langs->trans("StatusProspect".$obj->id);
106 106
 			print '</a></td><td align="right">'.$obj->cc.'</td></tr>';
107 107
 			$i++;
@@ -114,21 +114,21 @@  discard block
 block discarded – undo
114 114
 /*
115 115
  * Liste des propal brouillons
116 116
  */
117
-if (! empty($conf->propal->enabled) && $user->rights->propale->lire)
117
+if (!empty($conf->propal->enabled) && $user->rights->propale->lire)
118 118
 {
119 119
 	$sql = "SELECT p.rowid, p.ref, p.price, s.nom as sname";
120
-	$sql.= " FROM ".MAIN_DB_PREFIX."propal as p";
121
-	$sql.= ", ".MAIN_DB_PREFIX."societe as s";
122
-	if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
123
-	$sql.= " WHERE p.fk_statut = 0";
124
-	$sql.= " AND p.fk_soc = s.rowid";
125
-	$sql.= " AND p.entity IN (".getEntity('propal').")";
126
-	if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
127
-
128
-	$resql=$db->query($sql);
120
+	$sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
121
+	$sql .= ", ".MAIN_DB_PREFIX."societe as s";
122
+	if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
123
+	$sql .= " WHERE p.fk_statut = 0";
124
+	$sql .= " AND p.fk_soc = s.rowid";
125
+	$sql .= " AND p.entity IN (".getEntity('propal').")";
126
+	if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
127
+
128
+	$resql = $db->query($sql);
129 129
 	if ($resql)
130 130
 	{
131
-		$total=0;
131
+		$total = 0;
132 132
 		$num = $db->num_rows($resql);
133 133
 		$i = 0;
134 134
 		if ($num > 0)
@@ -142,14 +142,14 @@  discard block
 block discarded – undo
142 142
 				$obj = $db->fetch_object($resql);
143 143
 
144 144
 				print '<tr class="oddeven"><td>';
145
-				print '<a href="'.DOL_URL_ROOT.'/comm/propal/card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowPropal"),"propal").' '.$obj->ref.'</a>';
145
+				print '<a href="'.DOL_URL_ROOT.'/comm/propal/card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowPropal"), "propal").' '.$obj->ref.'</a>';
146 146
 				print '</td><td align="right">';
147 147
 				print price($obj->price);
148 148
 				print "</td></tr>";
149 149
 				$i++;
150 150
 				$total += $obj->price;
151 151
 			}
152
-			if ($total>0) {
152
+			if ($total > 0) {
153 153
 
154 154
 				print '<tr class="liste_total"><td>'.$langs->trans("Total")."</td><td align=\"right\">".price($total)."</td></tr>";
155 155
 			}
@@ -167,29 +167,29 @@  discard block
 block discarded – undo
167 167
 /*
168 168
  * Actions commerciales a faire
169 169
  */
170
-if (! empty($conf->agenda->enabled)) show_array_actions_to_do(10);
170
+if (!empty($conf->agenda->enabled)) show_array_actions_to_do(10);
171 171
 
172 172
 /*
173 173
  * Dernieres propales ouvertes
174 174
  */
175
-if (! empty($conf->propal->enabled) && $user->rights->propale->lire)
175
+if (!empty($conf->propal->enabled) && $user->rights->propale->lire)
176 176
 {
177 177
 	$sql = "SELECT s.nom as name, s.rowid as socid, s.client, s.canvas,";
178
-	$sql.= " p.rowid as propalid, p.total as total_ttc, p.ref, p.datep as dp, c.label as statut, c.id as statutid";
179
-	$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
180
-	$sql.= ", ".MAIN_DB_PREFIX."propal as p";
181
-	$sql.= ", ".MAIN_DB_PREFIX."c_propalst as c";
182
-	if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
183
-	$sql.= " WHERE p.fk_soc = s.rowid";
184
-	$sql.= " AND p.fk_statut = c.id";
185
-	$sql.= " AND p.fk_statut = 1";
186
-	$sql.= " AND p.entity IN (".getEntity('propal').")";
187
-	if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
188
-	if ($socid) $sql.= " AND s.rowid = ".$socid;
189
-	$sql.= " ORDER BY p.rowid DESC";
190
-	$sql.= $db->plimit(5, 0);
191
-
192
-	$resql=$db->query($sql);
178
+	$sql .= " p.rowid as propalid, p.total as total_ttc, p.ref, p.datep as dp, c.label as statut, c.id as statutid";
179
+	$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
180
+	$sql .= ", ".MAIN_DB_PREFIX."propal as p";
181
+	$sql .= ", ".MAIN_DB_PREFIX."c_propalst as c";
182
+	if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
183
+	$sql .= " WHERE p.fk_soc = s.rowid";
184
+	$sql .= " AND p.fk_statut = c.id";
185
+	$sql .= " AND p.fk_statut = 1";
186
+	$sql .= " AND p.entity IN (".getEntity('propal').")";
187
+	if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
188
+	if ($socid) $sql .= " AND s.rowid = ".$socid;
189
+	$sql .= " ORDER BY p.rowid DESC";
190
+	$sql .= $db->plimit(5, 0);
191
+
192
+	$resql = $db->query($sql);
193 193
 	if ($resql)
194 194
 	{
195 195
 		$total = 0;
@@ -206,22 +206,22 @@  discard block
 block discarded – undo
206 206
 
207 207
 				print '<tr class="oddeven"><td>';
208 208
 				print '<a href="../propal.php?id='.$obj->propalid.'">';
209
-				print img_object($langs->trans("ShowPropal"),"propal").' '.$obj->ref.'</a></td>';
209
+				print img_object($langs->trans("ShowPropal"), "propal").' '.$obj->ref.'</a></td>';
210 210
 
211 211
 				print "<td>";
212
-                $companystatic->id=$obj->socid;
213
-                $companystatic->name=$obj->name;
214
-                $companystatic->client=$obj->client;
215
-                $companystatic->canvas=$obj->canvas;
216
-                print $companystatic->getNomUrl(1,'',44);
212
+                $companystatic->id = $obj->socid;
213
+                $companystatic->name = $obj->name;
214
+                $companystatic->client = $obj->client;
215
+                $companystatic->canvas = $obj->canvas;
216
+                print $companystatic->getNomUrl(1, '', 44);
217 217
 				print "</td>\n";
218 218
 				print "<td align=\"right\">";
219
-				print dol_print_date($db->jdate($obj->dp),'day')."</td>\n";
219
+				print dol_print_date($db->jdate($obj->dp), 'day')."</td>\n";
220 220
 				print "<td align=\"right\">".price($obj->total_ttc)."</td></tr>\n";
221 221
 				$i++;
222 222
 				$total += $obj->price;
223 223
 			}
224
-			if ($total>0)
224
+			if ($total > 0)
225 225
 			{
226 226
 				print '<tr class="liste_total"><td colspan="3" align="right">'.$langs->trans("Total")."</td><td align=\"right\">".price($total)."</td></tr>";
227 227
 			}
@@ -239,20 +239,20 @@  discard block
 block discarded – undo
239 239
  *
240 240
  */
241 241
 $sql = "SELECT s.nom as name, s.rowid as socid, s.client, s.canvas";
242
-$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
243
-if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
244
-$sql.= " WHERE s.fk_stcomm = 1";
245
-$sql.= " AND s.entity IN (".getEntity($companystatic->element).")";
246
-if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
247
-$sql.= " ORDER BY s.tms ASC";
248
-$sql.= $db->plimit(15, 0);
249
-
250
-$resql=$db->query($sql);
242
+$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
243
+if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
244
+$sql .= " WHERE s.fk_stcomm = 1";
245
+$sql .= " AND s.entity IN (".getEntity($companystatic->element).")";
246
+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
247
+$sql .= " ORDER BY s.tms ASC";
248
+$sql .= $db->plimit(15, 0);
249
+
250
+$resql = $db->query($sql);
251 251
 if ($resql)
252 252
 {
253 253
 	$num = $db->num_rows($resql);
254 254
 	$i = 0;
255
-	if ($num > 0 )
255
+	if ($num > 0)
256 256
 	{
257 257
 		print '<table class="noborder" width="100%">';
258 258
 		print '<tr class="liste_titre"><td>'.$langs->trans("ProspectToContact").'</td></tr>';
@@ -262,11 +262,11 @@  discard block
 block discarded – undo
262 262
 			$obj = $db->fetch_object($resql);
263 263
 
264 264
 			print '<tr class="oddeven"><td width="12%">';
265
-            $companystatic->id=$obj->socid;
266
-            $companystatic->name=$obj->name;
267
-            $companystatic->client=$obj->client;
268
-            $companystatic->canvas=$obj->canvas;
269
-            print $companystatic->getNomUrl(1,'prospect',44);
265
+            $companystatic->id = $obj->socid;
266
+            $companystatic->name = $obj->name;
267
+            $companystatic->client = $obj->client;
268
+            $companystatic->canvas = $obj->canvas;
269
+            print $companystatic->getNomUrl(1, 'prospect', 44);
270 270
 			print '</td></tr>';
271 271
 			$i++;
272 272
 		}
Please login to merge, or discard this patch.
dolibarr/htdocs/reception/class/reception.class.php 3 patches
Indentation   +1643 added lines, -1643 removed lines patch added patch discarded remove patch
@@ -43,717 +43,717 @@  discard block
 block discarded – undo
43 43
  */
44 44
 class Reception extends CommonObject
45 45
 {
46
-	public $element="reception";
47
-	public $fk_element="fk_reception";
48
-	public $table_element="reception";
49
-	public $table_element_line="commande_fournisseur_dispatch";
50
-	protected $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
46
+    public $element="reception";
47
+    public $fk_element="fk_reception";
48
+    public $table_element="reception";
49
+    public $table_element_line="commande_fournisseur_dispatch";
50
+    protected $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
51 51
     public $picto = 'reception';
52 52
 
53
-	var $socid;
54
-	var $ref_supplier;
55
-	var $ref_int;
56
-	var $brouillon;
57
-	var $entrepot_id;
58
-	var $lines=array();
59
-	var $tracking_number;
60
-	var $tracking_url;
61
-	var $billed;
62
-	var $model_pdf;
63
-
64
-	var $trueWeight;
65
-	var $weight_units;
66
-	var $trueWidth;
67
-	var $width_units;
68
-	var $trueHeight;
69
-	var $height_units;
70
-	var $trueDepth;
71
-	var $depth_units;
72
-	// A denormalized value
73
-	var $trueSize;
74
-
75
-	var $date_delivery;		// Date delivery planed
76
-
77
-
78
-	/**
79
-	 * Effective delivery date
80
-	 * @var int
81
-	 */
82
-	public $date_reception;
83
-	var $date_creation;
84
-	var $date_valid;
85
-
86
-	var $meths;
87
-	var $listmeths;			// List of carriers
88
-
89
-
90
-	const STATUS_DRAFT = 0;
91
-	const STATUS_VALIDATED = 1;
92
-	const STATUS_CLOSED = 2;
93
-
94
-
95
-
96
-	/**
97
-	 *	Constructor
98
-	 *
99
-	 *  @param		DoliDB		$db      Database handler
100
-	 */
101
-	function __construct($db)
102
-	{
103
-		$this->db = $db;
104
-		$this->lines = array();
105
-		$this->products = array();
106
-
107
-		// List of long language codes for status
108
-		$this->statuts = array();
109
-		$this->statuts[-1] = 'StatusReceptionCanceled';
110
-		$this->statuts[0]  = 'StatusReceptionDraft';
111
-		$this->statuts[1]  = 'StatusReceptionValidated';
112
-		$this->statuts[2]  = 'StatusReceptionProcessed';
113
-	}
114
-
115
-	/**
116
-	 *	Return next contract ref
117
-	 *
118
-	 *	@param	Societe		$soc	Thirdparty object
119
-	 *	@return string				Free reference for contract
120
-	 */
121
-	function getNextNumRef($soc)
122
-	{
123
-		global $langs, $conf;
124
-		$langs->load("receptions");
125
-
126
-	    if (!empty($conf->global->RECEPTION_ADDON_NUMBER))
53
+    var $socid;
54
+    var $ref_supplier;
55
+    var $ref_int;
56
+    var $brouillon;
57
+    var $entrepot_id;
58
+    var $lines=array();
59
+    var $tracking_number;
60
+    var $tracking_url;
61
+    var $billed;
62
+    var $model_pdf;
63
+
64
+    var $trueWeight;
65
+    var $weight_units;
66
+    var $trueWidth;
67
+    var $width_units;
68
+    var $trueHeight;
69
+    var $height_units;
70
+    var $trueDepth;
71
+    var $depth_units;
72
+    // A denormalized value
73
+    var $trueSize;
74
+
75
+    var $date_delivery;		// Date delivery planed
76
+
77
+
78
+    /**
79
+     * Effective delivery date
80
+     * @var int
81
+     */
82
+    public $date_reception;
83
+    var $date_creation;
84
+    var $date_valid;
85
+
86
+    var $meths;
87
+    var $listmeths;			// List of carriers
88
+
89
+
90
+    const STATUS_DRAFT = 0;
91
+    const STATUS_VALIDATED = 1;
92
+    const STATUS_CLOSED = 2;
93
+
94
+
95
+
96
+    /**
97
+     *	Constructor
98
+     *
99
+     *  @param		DoliDB		$db      Database handler
100
+     */
101
+    function __construct($db)
102
+    {
103
+        $this->db = $db;
104
+        $this->lines = array();
105
+        $this->products = array();
106
+
107
+        // List of long language codes for status
108
+        $this->statuts = array();
109
+        $this->statuts[-1] = 'StatusReceptionCanceled';
110
+        $this->statuts[0]  = 'StatusReceptionDraft';
111
+        $this->statuts[1]  = 'StatusReceptionValidated';
112
+        $this->statuts[2]  = 'StatusReceptionProcessed';
113
+    }
114
+
115
+    /**
116
+     *	Return next contract ref
117
+     *
118
+     *	@param	Societe		$soc	Thirdparty object
119
+     *	@return string				Free reference for contract
120
+     */
121
+    function getNextNumRef($soc)
122
+    {
123
+        global $langs, $conf;
124
+        $langs->load("receptions");
125
+
126
+        if (!empty($conf->global->RECEPTION_ADDON_NUMBER))
127 127
         {
128
-			$mybool = false;
128
+            $mybool = false;
129 129
 
130
-			$file = $conf->global->RECEPTION_ADDON_NUMBER.".php";
131
-			$classname = $conf->global->RECEPTION_ADDON_NUMBER;
130
+            $file = $conf->global->RECEPTION_ADDON_NUMBER.".php";
131
+            $classname = $conf->global->RECEPTION_ADDON_NUMBER;
132 132
 
133
-	        // Include file with class
134
-	        $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
133
+            // Include file with class
134
+            $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
135 135
 
136
-	        foreach ($dirmodels as $reldir) {
136
+            foreach ($dirmodels as $reldir) {
137 137
 
138
-		        $dir = dol_buildpath($reldir."core/modules/reception/");
138
+                $dir = dol_buildpath($reldir."core/modules/reception/");
139 139
 
140
-		        // Load file with numbering class (if found)
141
-		        $mybool|=@include_once $dir.$file;
142
-	        }
140
+                // Load file with numbering class (if found)
141
+                $mybool|=@include_once $dir.$file;
142
+            }
143 143
 
144
-	        if (! $mybool)
145
-	        {
146
-		        dol_print_error('',"Failed to include file ".$file);
147
-		        return '';
148
-	        }
144
+            if (! $mybool)
145
+            {
146
+                dol_print_error('',"Failed to include file ".$file);
147
+                return '';
148
+            }
149 149
 
150
-			$obj = new $classname();
150
+            $obj = new $classname();
151 151
 
152
-			$numref = "";
153
-			$numref = $obj->getNextValue($soc,$this);
152
+            $numref = "";
153
+            $numref = $obj->getNextValue($soc,$this);
154 154
 
155
-			if ( $numref != "")
156
-			{
157
-				return $numref;
158
-			}
159
-			else
160
-			{
161
-				dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
162
-				return "";
163
-			}
155
+            if ( $numref != "")
156
+            {
157
+                return $numref;
158
+            }
159
+            else
160
+            {
161
+                dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
162
+                return "";
163
+            }
164
+        }
165
+        else
166
+        {
167
+            print $langs->trans("Error")." ".$langs->trans("Error_RECEPTION_ADDON_NUMBER_NotDefined");
168
+            return "";
164 169
         }
165
-	    else
166
-	    {
167
-		    print $langs->trans("Error")." ".$langs->trans("Error_RECEPTION_ADDON_NUMBER_NotDefined");
168
-		    return "";
169
-	    }
170
-	}
171
-
172
-	/**
173
-	 *  Create reception en base
174
-	 *
175
-	 *  @param	User	$user       Objet du user qui cree
176
-	 *  @param	int		$notrigger	1=Does not execute triggers, 0= execute triggers
177
-	 *  @return int 				<0 si erreur, id reception creee si ok
178
-	 */
179
-	function create($user, $notrigger=0)
180
-	{
181
-		global $conf, $hookmanager;
182
-
183
-		$now=dol_now();
184
-
185
-		require_once DOL_DOCUMENT_ROOT .'/product/stock/class/mouvementstock.class.php';
186
-		$error = 0;
187
-
188
-		// Clean parameters
189
-		$this->brouillon = 1;
190
-		$this->tracking_number = dol_sanitizeFileName($this->tracking_number);
191
-		if (empty($this->fk_project)) $this->fk_project = 0;
192
-
193
-		$this->user = $user;
194
-
195
-
196
-		$this->db->begin();
197
-
198
-		$sql = "INSERT INTO ".MAIN_DB_PREFIX."reception (";
199
-		$sql.= "ref";
200
-		$sql.= ", entity";
201
-		$sql.= ", ref_supplier";
202
-		$sql.= ", ref_int";
203
-		$sql.= ", date_creation";
204
-		$sql.= ", fk_user_author";
205
-		$sql.= ", date_reception";
206
-		$sql.= ", date_delivery";
207
-		$sql.= ", fk_soc";
208
-		$sql.= ", fk_projet";
209
-		$sql.= ", fk_shipping_method";
210
-		$sql.= ", tracking_number";
211
-		$sql.= ", weight";
212
-		$sql.= ", size";
213
-		$sql.= ", width";
214
-		$sql.= ", height";
215
-		$sql.= ", weight_units";
216
-		$sql.= ", size_units";
217
-		$sql.= ", note_private";
218
-		$sql.= ", note_public";
219
-		$sql.= ", model_pdf";
220
-		$sql.= ", fk_incoterms, location_incoterms";
221
-		$sql.= ") VALUES (";
222
-		$sql.= "'(PROV)'";
223
-		$sql.= ", ".$conf->entity;
224
-		$sql.= ", ".($this->ref_supplier?"'".$this->db->escape($this->ref_supplier)."'":"null");
225
-		$sql.= ", ".($this->ref_int?"'".$this->db->escape($this->ref_int)."'":"null");
226
-		$sql.= ", '".$this->db->idate($now)."'";
227
-		$sql.= ", ".$user->id;
228
-		$sql.= ", ".($this->date_reception>0?"'".$this->db->idate($this->date_reception)."'":"null");
229
-		$sql.= ", ".($this->date_delivery>0?"'".$this->db->idate($this->date_delivery)."'":"null");
230
-		$sql.= ", ".$this->socid;
231
-		$sql.= ", ".$this->fk_project;
232
-		$sql.= ", ".($this->shipping_method_id>0?$this->shipping_method_id:"null");
233
-		$sql.= ", '".$this->db->escape($this->tracking_number)."'";
234
-		$sql.= ", ".$this->weight;
235
-		$sql.= ", ".$this->sizeS;	// TODO Should use this->trueDepth
236
-		$sql.= ", ".$this->sizeW;	// TODO Should use this->trueWidth
237
-		$sql.= ", ".$this->sizeH;	// TODO Should use this->trueHeight
238
-		$sql.= ", ".$this->weight_units;
239
-		$sql.= ", ".$this->size_units;
240
-		$sql.= ", ".(!empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null");
241
-		$sql.= ", ".(!empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null");
242
-		$sql.= ", ".(!empty($this->model_pdf)?"'".$this->db->escape($this->model_pdf)."'":"null");
170
+    }
171
+
172
+    /**
173
+     *  Create reception en base
174
+     *
175
+     *  @param	User	$user       Objet du user qui cree
176
+     *  @param	int		$notrigger	1=Does not execute triggers, 0= execute triggers
177
+     *  @return int 				<0 si erreur, id reception creee si ok
178
+     */
179
+    function create($user, $notrigger=0)
180
+    {
181
+        global $conf, $hookmanager;
182
+
183
+        $now=dol_now();
184
+
185
+        require_once DOL_DOCUMENT_ROOT .'/product/stock/class/mouvementstock.class.php';
186
+        $error = 0;
187
+
188
+        // Clean parameters
189
+        $this->brouillon = 1;
190
+        $this->tracking_number = dol_sanitizeFileName($this->tracking_number);
191
+        if (empty($this->fk_project)) $this->fk_project = 0;
192
+
193
+        $this->user = $user;
194
+
195
+
196
+        $this->db->begin();
197
+
198
+        $sql = "INSERT INTO ".MAIN_DB_PREFIX."reception (";
199
+        $sql.= "ref";
200
+        $sql.= ", entity";
201
+        $sql.= ", ref_supplier";
202
+        $sql.= ", ref_int";
203
+        $sql.= ", date_creation";
204
+        $sql.= ", fk_user_author";
205
+        $sql.= ", date_reception";
206
+        $sql.= ", date_delivery";
207
+        $sql.= ", fk_soc";
208
+        $sql.= ", fk_projet";
209
+        $sql.= ", fk_shipping_method";
210
+        $sql.= ", tracking_number";
211
+        $sql.= ", weight";
212
+        $sql.= ", size";
213
+        $sql.= ", width";
214
+        $sql.= ", height";
215
+        $sql.= ", weight_units";
216
+        $sql.= ", size_units";
217
+        $sql.= ", note_private";
218
+        $sql.= ", note_public";
219
+        $sql.= ", model_pdf";
220
+        $sql.= ", fk_incoterms, location_incoterms";
221
+        $sql.= ") VALUES (";
222
+        $sql.= "'(PROV)'";
223
+        $sql.= ", ".$conf->entity;
224
+        $sql.= ", ".($this->ref_supplier?"'".$this->db->escape($this->ref_supplier)."'":"null");
225
+        $sql.= ", ".($this->ref_int?"'".$this->db->escape($this->ref_int)."'":"null");
226
+        $sql.= ", '".$this->db->idate($now)."'";
227
+        $sql.= ", ".$user->id;
228
+        $sql.= ", ".($this->date_reception>0?"'".$this->db->idate($this->date_reception)."'":"null");
229
+        $sql.= ", ".($this->date_delivery>0?"'".$this->db->idate($this->date_delivery)."'":"null");
230
+        $sql.= ", ".$this->socid;
231
+        $sql.= ", ".$this->fk_project;
232
+        $sql.= ", ".($this->shipping_method_id>0?$this->shipping_method_id:"null");
233
+        $sql.= ", '".$this->db->escape($this->tracking_number)."'";
234
+        $sql.= ", ".$this->weight;
235
+        $sql.= ", ".$this->sizeS;	// TODO Should use this->trueDepth
236
+        $sql.= ", ".$this->sizeW;	// TODO Should use this->trueWidth
237
+        $sql.= ", ".$this->sizeH;	// TODO Should use this->trueHeight
238
+        $sql.= ", ".$this->weight_units;
239
+        $sql.= ", ".$this->size_units;
240
+        $sql.= ", ".(!empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null");
241
+        $sql.= ", ".(!empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null");
242
+        $sql.= ", ".(!empty($this->model_pdf)?"'".$this->db->escape($this->model_pdf)."'":"null");
243 243
         $sql.= ", ".(int) $this->fk_incoterms;
244 244
         $sql.= ", '".$this->db->escape($this->location_incoterms)."'";
245
-		$sql.= ")";
246
-
247
-		dol_syslog(get_class($this)."::create", LOG_DEBUG);
248
-
249
-		$resql=$this->db->query($sql);
250
-
251
-		if ($resql)
252
-		{
253
-			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."reception");
254
-
255
-			$sql = "UPDATE ".MAIN_DB_PREFIX."reception";
256
-			$sql.= " SET ref = '(PROV".$this->id.")'";
257
-			$sql.= " WHERE rowid = ".$this->id;
258
-
259
-			dol_syslog(get_class($this)."::create", LOG_DEBUG);
260
-			if ($this->db->query($sql))
261
-			{
262
-				// Insertion des lignes
263
-				$num=count($this->lines);
264
-				for ($i = 0; $i < $num; $i++)
265
-				{
266
-					$this->lines[$i]->fk_reception = $this->id;
267
-
268
-					if (! $this->lines[$i]->create($user) > 0)
269
-					{
270
-						$error++;
271
-					}
272
-				}
273
-
274
-				if (! $error && $this->id && $this->origin_id)
275
-				{
276
-					$ret = $this->add_object_linked();
277
-					if (!$ret)
278
-					{
279
-						$error++;
280
-					}
281
-				}
282
-
283
-				// Actions on extra fields (by external module or standard code)
284
-				// TODO le hook fait double emploi avec le trigger !!
285
-				$action='add';
286
-				$hookmanager->initHooks(array('receptiondao'));
287
-				$parameters=array('socid'=>$this->id);
288
-				$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
289
-				if (empty($reshook))
290
-				{
291
-					if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
292
-					{
293
-						$result=$this->insertExtraFields();
294
-						if ($result < 0)
295
-						{
296
-							$error++;
297
-						}
298
-					}
299
-				}
300
-				else if ($reshook < 0) $error++;
301
-
302
-				if (! $error && ! $notrigger)
303
-				{
245
+        $sql.= ")";
246
+
247
+        dol_syslog(get_class($this)."::create", LOG_DEBUG);
248
+
249
+        $resql=$this->db->query($sql);
250
+
251
+        if ($resql)
252
+        {
253
+            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."reception");
254
+
255
+            $sql = "UPDATE ".MAIN_DB_PREFIX."reception";
256
+            $sql.= " SET ref = '(PROV".$this->id.")'";
257
+            $sql.= " WHERE rowid = ".$this->id;
258
+
259
+            dol_syslog(get_class($this)."::create", LOG_DEBUG);
260
+            if ($this->db->query($sql))
261
+            {
262
+                // Insertion des lignes
263
+                $num=count($this->lines);
264
+                for ($i = 0; $i < $num; $i++)
265
+                {
266
+                    $this->lines[$i]->fk_reception = $this->id;
267
+
268
+                    if (! $this->lines[$i]->create($user) > 0)
269
+                    {
270
+                        $error++;
271
+                    }
272
+                }
273
+
274
+                if (! $error && $this->id && $this->origin_id)
275
+                {
276
+                    $ret = $this->add_object_linked();
277
+                    if (!$ret)
278
+                    {
279
+                        $error++;
280
+                    }
281
+                }
282
+
283
+                // Actions on extra fields (by external module or standard code)
284
+                // TODO le hook fait double emploi avec le trigger !!
285
+                $action='add';
286
+                $hookmanager->initHooks(array('receptiondao'));
287
+                $parameters=array('socid'=>$this->id);
288
+                $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
289
+                if (empty($reshook))
290
+                {
291
+                    if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
292
+                    {
293
+                        $result=$this->insertExtraFields();
294
+                        if ($result < 0)
295
+                        {
296
+                            $error++;
297
+                        }
298
+                    }
299
+                }
300
+                else if ($reshook < 0) $error++;
301
+
302
+                if (! $error && ! $notrigger)
303
+                {
304 304
                     // Call trigger
305 305
                     $result=$this->call_trigger('RECEPTION_CREATE',$user);
306 306
                     if ($result < 0) { $error++; }
307 307
                     // End call triggers
308 308
 
309
-					if (! $error)
310
-					{
311
-						$this->db->commit();
312
-						return $this->id;
313
-					}
314
-					else
315
-					{
316
-						foreach($this->errors as $errmsg)
317
-						{
318
-							dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
319
-							$this->error.=($this->error?', '.$errmsg:$errmsg);
320
-						}
321
-						$this->db->rollback();
322
-						return -1*$error;
323
-					}
324
-				}
325
-				else
326
-				{
327
-					$error++;
328
-					$this->error=$this->db->lasterror()." - sql=$sql";
329
-					$this->db->rollback();
330
-					return -3;
331
-				}
332
-			}
333
-			else
334
-			{
335
-				$error++;
336
-				$this->error=$this->db->lasterror()." - sql=$sql";
337
-				$this->db->rollback();
338
-				return -2;
339
-			}
340
-		}
341
-		else
342
-		{
343
-			$error++;
344
-			$this->error=$this->db->error()." - sql=$sql";
345
-			$this->db->rollback();
346
-			return -1;
347
-		}
348
-	}
349
-
350
-
351
-
352
-	/**
353
-	 *	Get object and lines from database
354
-	 *
355
-	 *	@param	int		$id       	Id of object to load
356
-	 * 	@param	string	$ref		Ref of object
357
-	 * 	@param	string	$ref_ext	External reference of object
309
+                    if (! $error)
310
+                    {
311
+                        $this->db->commit();
312
+                        return $this->id;
313
+                    }
314
+                    else
315
+                    {
316
+                        foreach($this->errors as $errmsg)
317
+                        {
318
+                            dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
319
+                            $this->error.=($this->error?', '.$errmsg:$errmsg);
320
+                        }
321
+                        $this->db->rollback();
322
+                        return -1*$error;
323
+                    }
324
+                }
325
+                else
326
+                {
327
+                    $error++;
328
+                    $this->error=$this->db->lasterror()." - sql=$sql";
329
+                    $this->db->rollback();
330
+                    return -3;
331
+                }
332
+            }
333
+            else
334
+            {
335
+                $error++;
336
+                $this->error=$this->db->lasterror()." - sql=$sql";
337
+                $this->db->rollback();
338
+                return -2;
339
+            }
340
+        }
341
+        else
342
+        {
343
+            $error++;
344
+            $this->error=$this->db->error()." - sql=$sql";
345
+            $this->db->rollback();
346
+            return -1;
347
+        }
348
+    }
349
+
350
+
351
+
352
+    /**
353
+     *	Get object and lines from database
354
+     *
355
+     *	@param	int		$id       	Id of object to load
356
+     * 	@param	string	$ref		Ref of object
357
+     * 	@param	string	$ref_ext	External reference of object
358 358
      * 	@param	string	$ref_int	Internal reference of other object
359
-	 *	@return int			        >0 if OK, 0 if not found, <0 if KO
360
-	 */
361
-	function fetch($id, $ref='', $ref_ext='', $ref_int='')
362
-	{
363
-		global $conf;
364
-
365
-		// Check parameters
366
-		if (empty($id) && empty($ref) && empty($ref_ext) && empty($ref_int)) return -1;
367
-
368
-		$sql = "SELECT e.rowid, e.ref, e.fk_soc as socid, e.date_creation, e.ref_supplier, e.ref_ext, e.ref_int, e.fk_user_author, e.fk_statut";
369
-		$sql.= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
370
-		$sql.= ", e.date_reception as date_reception, e.model_pdf,  e.date_delivery";
371
-		$sql.= ", e.fk_shipping_method, e.tracking_number";
372
-		$sql.= ", el.fk_source as origin_id, el.sourcetype as origin";
373
-		$sql.= ", e.note_private, e.note_public";
359
+     *	@return int			        >0 if OK, 0 if not found, <0 if KO
360
+     */
361
+    function fetch($id, $ref='', $ref_ext='', $ref_int='')
362
+    {
363
+        global $conf;
364
+
365
+        // Check parameters
366
+        if (empty($id) && empty($ref) && empty($ref_ext) && empty($ref_int)) return -1;
367
+
368
+        $sql = "SELECT e.rowid, e.ref, e.fk_soc as socid, e.date_creation, e.ref_supplier, e.ref_ext, e.ref_int, e.fk_user_author, e.fk_statut";
369
+        $sql.= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
370
+        $sql.= ", e.date_reception as date_reception, e.model_pdf,  e.date_delivery";
371
+        $sql.= ", e.fk_shipping_method, e.tracking_number";
372
+        $sql.= ", el.fk_source as origin_id, el.sourcetype as origin";
373
+        $sql.= ", e.note_private, e.note_public";
374 374
         $sql.= ', e.fk_incoterms, e.location_incoterms';
375 375
         $sql.= ', i.libelle as libelle_incoterms';
376
-		$sql.= " FROM ".MAIN_DB_PREFIX."reception as e";
377
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element)."'";
378
-		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON e.fk_incoterms = i.rowid';
379
-		$sql.= " WHERE e.entity IN (".getEntity('reception').")";
380
-		if ($id)   	  $sql.= " AND e.rowid=".$id;
376
+        $sql.= " FROM ".MAIN_DB_PREFIX."reception as e";
377
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element)."'";
378
+        $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON e.fk_incoterms = i.rowid';
379
+        $sql.= " WHERE e.entity IN (".getEntity('reception').")";
380
+        if ($id)   	  $sql.= " AND e.rowid=".$id;
381 381
         if ($ref)     $sql.= " AND e.ref='".$this->db->escape($ref)."'";
382 382
         if ($ref_ext) $sql.= " AND e.ref_ext='".$this->db->escape($ref_ext)."'";
383 383
         if ($ref_int) $sql.= " AND e.ref_int='".$this->db->escape($ref_int)."'";
384 384
 
385
-		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
386
-		$result = $this->db->query($sql);
387
-		if ($result)
388
-		{
389
-			if ($this->db->num_rows($result))
390
-			{
391
-				$obj = $this->db->fetch_object($result);
392
-
393
-				$this->id                   = $obj->rowid;
394
-				$this->ref                  = $obj->ref;
395
-				$this->socid                = $obj->socid;
396
-				$this->ref_supplier			= $obj->ref_supplier;
397
-				$this->ref_ext				= $obj->ref_ext;
398
-				$this->ref_int				= $obj->ref_int;
399
-				$this->statut               = $obj->fk_statut;
400
-				$this->user_author_id       = $obj->fk_user_author;
401
-				$this->date_creation        = $this->db->jdate($obj->date_creation);
402
-				$this->date                 = $this->db->jdate($obj->date_reception);	// TODO deprecated
403
-				$this->date_reception      = $this->db->jdate($obj->date_reception);	// TODO deprecated
404
-				$this->date_reception        = $this->db->jdate($obj->date_reception);	// Date real
405
-				$this->date_delivery        = $this->db->jdate($obj->date_delivery);	// Date planed
406
-				$this->fk_delivery_address  = $obj->fk_address;
407
-				$this->modelpdf             = $obj->model_pdf;
408
-				$this->shipping_method_id	= $obj->fk_shipping_method;
409
-				$this->tracking_number      = $obj->tracking_number;
410
-				$this->origin               = ($obj->origin?$obj->origin:'commande'); // For compatibility
411
-				$this->origin_id            = $obj->origin_id;
412
-				$this->billed				= ($obj->fk_statut==2?1:0);
413
-
414
-				$this->trueWeight           = $obj->weight;
415
-				$this->weight_units         = $obj->weight_units;
416
-
417
-				$this->trueWidth            = $obj->width;
418
-				$this->width_units          = $obj->size_units;
419
-				$this->trueHeight           = $obj->height;
420
-				$this->height_units         = $obj->size_units;
421
-				$this->trueDepth            = $obj->size;
422
-				$this->depth_units          = $obj->size_units;
423
-
424
-				$this->note_public          = $obj->note_public;
425
-				$this->note_private         = $obj->note_private;
426
-
427
-				// A denormalized value
428
-				$this->trueSize           	= $obj->size."x".$obj->width."x".$obj->height;
429
-				$this->size_units           = $obj->size_units;
430
-
431
-				//Incoterms
432
-				$this->fk_incoterms = $obj->fk_incoterms;
433
-				$this->location_incoterms = $obj->location_incoterms;
434
-				$this->libelle_incoterms = $obj->libelle_incoterms;
435
-
436
-				$this->db->free($result);
437
-
438
-				if ($this->statut == 0) $this->brouillon = 1;
439
-
440
-				$file = $conf->reception->dir_output . "/" .get_exdir($this->id, 2, 0, 0, $this, 'reception') . "/" . $this->id.".pdf";
441
-				$this->pdf_filename = $file;
442
-
443
-				// Tracking url
444
-				$this->getUrlTrackingStatus($obj->tracking_number);
445
-
446
-				/*
385
+        dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
386
+        $result = $this->db->query($sql);
387
+        if ($result)
388
+        {
389
+            if ($this->db->num_rows($result))
390
+            {
391
+                $obj = $this->db->fetch_object($result);
392
+
393
+                $this->id                   = $obj->rowid;
394
+                $this->ref                  = $obj->ref;
395
+                $this->socid                = $obj->socid;
396
+                $this->ref_supplier			= $obj->ref_supplier;
397
+                $this->ref_ext				= $obj->ref_ext;
398
+                $this->ref_int				= $obj->ref_int;
399
+                $this->statut               = $obj->fk_statut;
400
+                $this->user_author_id       = $obj->fk_user_author;
401
+                $this->date_creation        = $this->db->jdate($obj->date_creation);
402
+                $this->date                 = $this->db->jdate($obj->date_reception);	// TODO deprecated
403
+                $this->date_reception      = $this->db->jdate($obj->date_reception);	// TODO deprecated
404
+                $this->date_reception        = $this->db->jdate($obj->date_reception);	// Date real
405
+                $this->date_delivery        = $this->db->jdate($obj->date_delivery);	// Date planed
406
+                $this->fk_delivery_address  = $obj->fk_address;
407
+                $this->modelpdf             = $obj->model_pdf;
408
+                $this->shipping_method_id	= $obj->fk_shipping_method;
409
+                $this->tracking_number      = $obj->tracking_number;
410
+                $this->origin               = ($obj->origin?$obj->origin:'commande'); // For compatibility
411
+                $this->origin_id            = $obj->origin_id;
412
+                $this->billed				= ($obj->fk_statut==2?1:0);
413
+
414
+                $this->trueWeight           = $obj->weight;
415
+                $this->weight_units         = $obj->weight_units;
416
+
417
+                $this->trueWidth            = $obj->width;
418
+                $this->width_units          = $obj->size_units;
419
+                $this->trueHeight           = $obj->height;
420
+                $this->height_units         = $obj->size_units;
421
+                $this->trueDepth            = $obj->size;
422
+                $this->depth_units          = $obj->size_units;
423
+
424
+                $this->note_public          = $obj->note_public;
425
+                $this->note_private         = $obj->note_private;
426
+
427
+                // A denormalized value
428
+                $this->trueSize           	= $obj->size."x".$obj->width."x".$obj->height;
429
+                $this->size_units           = $obj->size_units;
430
+
431
+                //Incoterms
432
+                $this->fk_incoterms = $obj->fk_incoterms;
433
+                $this->location_incoterms = $obj->location_incoterms;
434
+                $this->libelle_incoterms = $obj->libelle_incoterms;
435
+
436
+                $this->db->free($result);
437
+
438
+                if ($this->statut == 0) $this->brouillon = 1;
439
+
440
+                $file = $conf->reception->dir_output . "/" .get_exdir($this->id, 2, 0, 0, $this, 'reception') . "/" . $this->id.".pdf";
441
+                $this->pdf_filename = $file;
442
+
443
+                // Tracking url
444
+                $this->getUrlTrackingStatus($obj->tracking_number);
445
+
446
+                /*
447 447
 				 * Thirparty
448 448
 				 */
449
-				$result=$this->fetch_thirdparty();
449
+                $result=$this->fetch_thirdparty();
450 450
 
451 451
 
452
-				// Retrieve all extrafields for reception
453
-				// fetch optionals attributes and labels
454
-				require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
455
-				$extrafields=new ExtraFields($this->db);
456
-				$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
457
-				$this->fetch_optionals($this->id,$extralabels);
452
+                // Retrieve all extrafields for reception
453
+                // fetch optionals attributes and labels
454
+                require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
455
+                $extrafields=new ExtraFields($this->db);
456
+                $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
457
+                $this->fetch_optionals($this->id,$extralabels);
458 458
 
459
-				/*
459
+                /*
460 460
 				 * Lines
461 461
 				 */
462
-				$result=$this->fetch_lines();
463
-				if ($result < 0)
464
-				{
465
-					return -3;
466
-				}
467
-
468
-				return 1;
469
-			}
470
-			else
471
-			{
472
-				dol_syslog(get_class($this).'::Fetch no reception found', LOG_ERR);
473
-				$this->error='Delivery with id '.$id.' not found';
474
-				return 0;
475
-			}
476
-		}
477
-		else
478
-		{
479
-			$this->error=$this->db->error();
480
-			return -1;
481
-		}
482
-	}
483
-
484
-	/**
485
-	 *  Validate object and update stock if option enabled
486
-	 *
487
-	 *  @param      User		$user       Object user that validate
462
+                $result=$this->fetch_lines();
463
+                if ($result < 0)
464
+                {
465
+                    return -3;
466
+                }
467
+
468
+                return 1;
469
+            }
470
+            else
471
+            {
472
+                dol_syslog(get_class($this).'::Fetch no reception found', LOG_ERR);
473
+                $this->error='Delivery with id '.$id.' not found';
474
+                return 0;
475
+            }
476
+        }
477
+        else
478
+        {
479
+            $this->error=$this->db->error();
480
+            return -1;
481
+        }
482
+    }
483
+
484
+    /**
485
+     *  Validate object and update stock if option enabled
486
+     *
487
+     *  @param      User		$user       Object user that validate
488 488
      *  @param		int			$notrigger	1=Does not execute triggers, 0= execute triggers
489
-	 *  @return     int						<0 if OK, >0 if KO
490
-	 */
491
-	function valid($user, $notrigger=0)
492
-	{
493
-		global $conf, $langs;
489
+     *  @return     int						<0 if OK, >0 if KO
490
+     */
491
+    function valid($user, $notrigger=0)
492
+    {
493
+        global $conf, $langs;
494 494
 
495 495
         require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
496 496
 
497
-		dol_syslog(get_class($this)."::valid");
497
+        dol_syslog(get_class($this)."::valid");
498 498
 
499
-		// Protection
500
-		if ($this->statut)
501
-		{
502
-			dol_syslog(get_class($this)."::valid no draft status", LOG_WARNING);
503
-			return 0;
504
-		}
499
+        // Protection
500
+        if ($this->statut)
501
+        {
502
+            dol_syslog(get_class($this)."::valid no draft status", LOG_WARNING);
503
+            return 0;
504
+        }
505 505
 
506 506
         if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->creer))
507
-       	|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->reception_advance->validate))))
508
-		{
509
-			$this->error='Permission denied';
510
-			dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
511
-			return -1;
512
-		}
507
+           || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->reception_advance->validate))))
508
+        {
509
+            $this->error='Permission denied';
510
+            dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
511
+            return -1;
512
+        }
513 513
 
514
-		$this->db->begin();
514
+        $this->db->begin();
515 515
 
516
-		$error = 0;
516
+        $error = 0;
517 517
 
518
-		// Define new ref
519
-		$soc = new Societe($this->db);
520
-		$soc->fetch($this->socid);
518
+        // Define new ref
519
+        $soc = new Societe($this->db);
520
+        $soc->fetch($this->socid);
521 521
 
522 522
 
523
-		// Define new ref
524
-		if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
525
-		{
526
-			$numref = $this->getNextNumRef($soc);
527
-		}
528
-		else {
529
-			$numref = $this->ref;
530
-		}
523
+        // Define new ref
524
+        if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
525
+        {
526
+            $numref = $this->getNextNumRef($soc);
527
+        }
528
+        else {
529
+            $numref = $this->ref;
530
+        }
531 531
 
532 532
         $this->newref = $numref;
533 533
 
534
-		$now=dol_now();
535
-
536
-		// Validate
537
-		$sql = "UPDATE ".MAIN_DB_PREFIX."reception SET";
538
-		$sql.= " ref='".$this->db->escape($numref)."'";
539
-		$sql.= ", fk_statut = 1";
540
-		$sql.= ", date_valid = '".$this->db->idate($now)."'";
541
-		$sql.= ", fk_user_valid = ".$user->id;
542
-		$sql.= " WHERE rowid = ".$this->id;
543
-		dol_syslog(get_class($this)."::valid update reception", LOG_DEBUG);
544
-		$resql=$this->db->query($sql);
545
-		if (! $resql)
546
-		{
547
-			$this->error=$this->db->lasterror();
548
-			$error++;
549
-		}
550
-
551
-		// If stock increment is done on reception (recommanded choice)
552
-		if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION))
553
-		{
554
-			require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
555
-
556
-			$langs->load("agenda");
557
-
558
-			// Loop on each product line to add a stock movement
559
-			// TODO in future, reception lines may not be linked to order line
560
-			$sql = "SELECT cd.fk_product, cd.subprice,";
561
-			$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
562
-			$sql.= " ed.eatby, ed.sellby, ed.batch";
563
-			$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
564
-			$sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
565
-			$sql.= " WHERE ed.fk_reception = ".$this->id;
566
-			$sql.= " AND cd.rowid = ed.fk_commandefourndet";
567
-
568
-			dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
569
-			$resql=$this->db->query($sql);
570
-			if ($resql)
571
-			{
572
-				$cpt = $this->db->num_rows($resql);
573
-				for ($i = 0; $i < $cpt; $i++)
574
-				{
575
-					$obj = $this->db->fetch_object($resql);
576
-
577
-					$qty = $obj->qty;
578
-
579
-					if ($qty <= 0) continue;
580
-					dol_syslog(get_class($this)."::valid movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid);
581
-
582
-					//var_dump($this->lines[$i]);
583
-					$mouvS = new MouvementStock($this->db);
584
-					$mouvS->origin = &$this;
585
-
586
-					if (empty($obj->batch))
587
-					{
588
-						// line without batch detail
589
-
590
-						// 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.
591
-						$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionValidatedInDolibarr",$numref));
592
-						if ($result < 0) {
593
-							$error++;
594
-							$this->errors[]=$mouvS->error;
595
-							$this->errors = array_merge($this->errors, $mouvS->errors);
596
-							break;
597
-						}
598
-					}
599
-					else
600
-					{
601
-						// line with batch detail
602
-
603
-						// 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.
604
-					    // Note: ->fk_origin_stock = id into table llx_product_batch (may be rename into llx_product_stock_batch in another version)
605
-						$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionValidatedInDolibarr",$numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch);
606
-						if ($result < 0) {
607
-							$error++;
608
-							$this->errors[]=$mouvS->error;
609
-							$this->errors = array_merge($this->errors, $mouvS->errors);
610
-							break;
611
-						}
612
-					}
613
-				}
614
-			}
615
-			else
616
-			{
617
-				$this->db->rollback();
618
-				$this->error=$this->db->error();
619
-				return -2;
620
-			}
621
-		}
622
-
623
-		// Change status of order to "reception in process"
624
-		$ret = $this->setStatut(4, $this->origin_id, 'commande_fournisseur');
534
+        $now=dol_now();
535
+
536
+        // Validate
537
+        $sql = "UPDATE ".MAIN_DB_PREFIX."reception SET";
538
+        $sql.= " ref='".$this->db->escape($numref)."'";
539
+        $sql.= ", fk_statut = 1";
540
+        $sql.= ", date_valid = '".$this->db->idate($now)."'";
541
+        $sql.= ", fk_user_valid = ".$user->id;
542
+        $sql.= " WHERE rowid = ".$this->id;
543
+        dol_syslog(get_class($this)."::valid update reception", LOG_DEBUG);
544
+        $resql=$this->db->query($sql);
545
+        if (! $resql)
546
+        {
547
+            $this->error=$this->db->lasterror();
548
+            $error++;
549
+        }
550
+
551
+        // If stock increment is done on reception (recommanded choice)
552
+        if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION))
553
+        {
554
+            require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
555
+
556
+            $langs->load("agenda");
557
+
558
+            // Loop on each product line to add a stock movement
559
+            // TODO in future, reception lines may not be linked to order line
560
+            $sql = "SELECT cd.fk_product, cd.subprice,";
561
+            $sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
562
+            $sql.= " ed.eatby, ed.sellby, ed.batch";
563
+            $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
564
+            $sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
565
+            $sql.= " WHERE ed.fk_reception = ".$this->id;
566
+            $sql.= " AND cd.rowid = ed.fk_commandefourndet";
567
+
568
+            dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
569
+            $resql=$this->db->query($sql);
570
+            if ($resql)
571
+            {
572
+                $cpt = $this->db->num_rows($resql);
573
+                for ($i = 0; $i < $cpt; $i++)
574
+                {
575
+                    $obj = $this->db->fetch_object($resql);
576
+
577
+                    $qty = $obj->qty;
578
+
579
+                    if ($qty <= 0) continue;
580
+                    dol_syslog(get_class($this)."::valid movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid);
581
+
582
+                    //var_dump($this->lines[$i]);
583
+                    $mouvS = new MouvementStock($this->db);
584
+                    $mouvS->origin = &$this;
585
+
586
+                    if (empty($obj->batch))
587
+                    {
588
+                        // line without batch detail
589
+
590
+                        // 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.
591
+                        $result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionValidatedInDolibarr",$numref));
592
+                        if ($result < 0) {
593
+                            $error++;
594
+                            $this->errors[]=$mouvS->error;
595
+                            $this->errors = array_merge($this->errors, $mouvS->errors);
596
+                            break;
597
+                        }
598
+                    }
599
+                    else
600
+                    {
601
+                        // line with batch detail
602
+
603
+                        // 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.
604
+                        // Note: ->fk_origin_stock = id into table llx_product_batch (may be rename into llx_product_stock_batch in another version)
605
+                        $result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionValidatedInDolibarr",$numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch);
606
+                        if ($result < 0) {
607
+                            $error++;
608
+                            $this->errors[]=$mouvS->error;
609
+                            $this->errors = array_merge($this->errors, $mouvS->errors);
610
+                            break;
611
+                        }
612
+                    }
613
+                }
614
+            }
615
+            else
616
+            {
617
+                $this->db->rollback();
618
+                $this->error=$this->db->error();
619
+                return -2;
620
+            }
621
+        }
622
+
623
+        // Change status of order to "reception in process"
624
+        $ret = $this->setStatut(4, $this->origin_id, 'commande_fournisseur');
625 625
 
626 626
         if (! $ret)
627
-		{
628
-		    $error++;
629
-		}
627
+        {
628
+            $error++;
629
+        }
630 630
 
631
-		if (! $error && ! $notrigger)
632
-		{
631
+        if (! $error && ! $notrigger)
632
+        {
633 633
             // Call trigger
634 634
             $result=$this->call_trigger('RECEPTION_VALIDATE',$user);
635 635
             if ($result < 0) { $error++; }
636 636
             // End call triggers
637
-		}
637
+        }
638 638
 
639
-		if (! $error)
640
-		{
639
+        if (! $error)
640
+        {
641 641
             $this->oldref = $this->ref;
642 642
 
643
-			// Rename directory if dir was a temporary ref
644
-			if (preg_match('/^[\(]?PROV/i', $this->ref))
645
-			{
646
-				// On renomme repertoire ($this->ref = ancienne ref, $numfa = nouvelle ref)
647
-				// in order not to lose the attached files
648
-				$oldref = dol_sanitizeFileName($this->ref);
649
-				$newref = dol_sanitizeFileName($numref);
650
-				$dirsource = $conf->reception->dir_output.'/'.$oldref;
651
-				$dirdest = $conf->reception->dir_output.'/'.$newref;
652
-				if (file_exists($dirsource))
653
-				{
654
-					dol_syslog(get_class($this)."::valid rename dir ".$dirsource." into ".$dirdest);
655
-
656
-					if (@rename($dirsource, $dirdest))
657
-					{
658
-					    dol_syslog("Rename ok");
643
+            // Rename directory if dir was a temporary ref
644
+            if (preg_match('/^[\(]?PROV/i', $this->ref))
645
+            {
646
+                // On renomme repertoire ($this->ref = ancienne ref, $numfa = nouvelle ref)
647
+                // in order not to lose the attached files
648
+                $oldref = dol_sanitizeFileName($this->ref);
649
+                $newref = dol_sanitizeFileName($numref);
650
+                $dirsource = $conf->reception->dir_output.'/'.$oldref;
651
+                $dirdest = $conf->reception->dir_output.'/'.$newref;
652
+                if (file_exists($dirsource))
653
+                {
654
+                    dol_syslog(get_class($this)."::valid rename dir ".$dirsource." into ".$dirdest);
655
+
656
+                    if (@rename($dirsource, $dirdest))
657
+                    {
658
+                        dol_syslog("Rename ok");
659 659
                         // Rename docs starting with $oldref with $newref
660 660
                         $listoffiles=dol_dir_list($conf->reception->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
661 661
                         foreach($listoffiles as $fileentry)
662 662
                         {
663
-                        	$dirsource=$fileentry['name'];
664
-                        	$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
665
-                        	$dirsource=$fileentry['path'].'/'.$dirsource;
666
-                        	$dirdest=$fileentry['path'].'/'.$dirdest;
667
-                        	@rename($dirsource, $dirdest);
663
+                            $dirsource=$fileentry['name'];
664
+                            $dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
665
+                            $dirsource=$fileentry['path'].'/'.$dirsource;
666
+                            $dirdest=$fileentry['path'].'/'.$dirdest;
667
+                            @rename($dirsource, $dirdest);
668 668
                         }
669
-					}
670
-				}
671
-			}
672
-		}
673
-
674
-		// Set new ref and current status
675
-		if (! $error)
676
-		{
677
-			$this->ref = $numref;
678
-			$this->statut = 1;
679
-		}
680
-
681
-		if (! $error)
682
-		{
683
-			$this->db->commit();
684
-			return 1;
685
-		}
686
-		else
687
-		{
688
-			foreach($this->errors as $errmsg)
689
-			{
690
-	            dol_syslog(get_class($this)."::valid ".$errmsg, LOG_ERR);
691
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
692
-			}
693
-			$this->db->rollback();
694
-			return -1*$error;
695
-		}
696
-	}
697
-
698
-
699
-
700
-	/**
701
-	 * Add an reception line.
702
-	 * If STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS is set, you can add a reception line, with no stock source defined
703
-	 * If STOCK_MUST_BE_ENOUGH_FOR_RECEPTION is not set, you can add a reception line, even if not enough into stock
704
-	 *
705
-	 * @param 	int			$entrepot_id		Id of warehouse
706
-	 * @param 	int			$id					Id of source line (supplier order line)
707
-	 * @param 	int			$qty				Quantity
708
-	 * @param	array		$array_options		extrafields array
709
-	 * @param	string		$comment				Comment for stock movement
710
-	 * @param	date		$eatby					eat-by date
711
-	 * @param	date		$sellby					sell-by date
712
-	 * @param	string		$batch					Lot number
713
-	 * @return	int							<0 if KO, >0 if OK
714
-	 */
715
-	function addline($entrepot_id, $id, $qty, $array_options=0, $comment='', $eatby='', $sellby='', $batch='')
716
-	{
717
-		global $conf, $langs, $user;
718
-
719
-		$num = count($this->lines);
720
-		$line = new CommandeFournisseurDispatch($this->db);
721
-
722
-		$line->fk_entrepot = $entrepot_id;
723
-		$line->fk_commandefourndet = $id;
724
-		$line->qty = $qty;
725
-
726
-		$supplierorderline = new CommandeFournisseurLigne($this->db);
727
-		$supplierorderline->fetch($id);
728
-
729
-		if (! empty($conf->stock->enabled) && ! empty($supplierorderline->fk_product))
730
-		{
731
-			$fk_product = $supplierorderline->fk_product;
732
-
733
-			if (! ($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS))
734
-			{
735
-			    $langs->load("errors");
736
-				$this->error=$langs->trans("ErrorWarehouseRequiredIntoReceptionLine");
737
-				return -1;
738
-			}
739
-		}
740
-
741
-		// extrafields
742
-		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
743
-			$line->array_options = $array_options;
744
-
745
-		$line->fk_product = $fk_product;
746
-		$line->fk_commande = $supplierorderline->fk_commande ;
747
-		$line->fk_user = $user->id ;
748
-		$line->comment = $comment;
749
-		$line->batch = $batch;
750
-		$line->eatby = $eatby;
751
-		$line->sellby = $sellby;
752
-		$line->status=1;
753
-		$line->fk_reception=$this->id;
754
-
755
-		$this->lines[$num] = $line;
756
-	}
669
+                    }
670
+                }
671
+            }
672
+        }
673
+
674
+        // Set new ref and current status
675
+        if (! $error)
676
+        {
677
+            $this->ref = $numref;
678
+            $this->statut = 1;
679
+        }
680
+
681
+        if (! $error)
682
+        {
683
+            $this->db->commit();
684
+            return 1;
685
+        }
686
+        else
687
+        {
688
+            foreach($this->errors as $errmsg)
689
+            {
690
+                dol_syslog(get_class($this)."::valid ".$errmsg, LOG_ERR);
691
+                $this->error.=($this->error?', '.$errmsg:$errmsg);
692
+            }
693
+            $this->db->rollback();
694
+            return -1*$error;
695
+        }
696
+    }
697
+
698
+
699
+
700
+    /**
701
+     * Add an reception line.
702
+     * If STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS is set, you can add a reception line, with no stock source defined
703
+     * If STOCK_MUST_BE_ENOUGH_FOR_RECEPTION is not set, you can add a reception line, even if not enough into stock
704
+     *
705
+     * @param 	int			$entrepot_id		Id of warehouse
706
+     * @param 	int			$id					Id of source line (supplier order line)
707
+     * @param 	int			$qty				Quantity
708
+     * @param	array		$array_options		extrafields array
709
+     * @param	string		$comment				Comment for stock movement
710
+     * @param	date		$eatby					eat-by date
711
+     * @param	date		$sellby					sell-by date
712
+     * @param	string		$batch					Lot number
713
+     * @return	int							<0 if KO, >0 if OK
714
+     */
715
+    function addline($entrepot_id, $id, $qty, $array_options=0, $comment='', $eatby='', $sellby='', $batch='')
716
+    {
717
+        global $conf, $langs, $user;
718
+
719
+        $num = count($this->lines);
720
+        $line = new CommandeFournisseurDispatch($this->db);
721
+
722
+        $line->fk_entrepot = $entrepot_id;
723
+        $line->fk_commandefourndet = $id;
724
+        $line->qty = $qty;
725
+
726
+        $supplierorderline = new CommandeFournisseurLigne($this->db);
727
+        $supplierorderline->fetch($id);
728
+
729
+        if (! empty($conf->stock->enabled) && ! empty($supplierorderline->fk_product))
730
+        {
731
+            $fk_product = $supplierorderline->fk_product;
732
+
733
+            if (! ($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS))
734
+            {
735
+                $langs->load("errors");
736
+                $this->error=$langs->trans("ErrorWarehouseRequiredIntoReceptionLine");
737
+                return -1;
738
+            }
739
+        }
740
+
741
+        // extrafields
742
+        if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
743
+            $line->array_options = $array_options;
744
+
745
+        $line->fk_product = $fk_product;
746
+        $line->fk_commande = $supplierorderline->fk_commande ;
747
+        $line->fk_user = $user->id ;
748
+        $line->comment = $comment;
749
+        $line->batch = $batch;
750
+        $line->eatby = $eatby;
751
+        $line->sellby = $sellby;
752
+        $line->status=1;
753
+        $line->fk_reception=$this->id;
754
+
755
+        $this->lines[$num] = $line;
756
+    }
757 757
 
758 758
 
759 759
     /**
@@ -765,314 +765,314 @@  discard block
 block discarded – undo
765 765
      */
766 766
     function update($user=null, $notrigger=0)
767 767
     {
768
-    	global $conf;
769
-		$error=0;
770
-
771
-		// Clean parameters
772
-
773
-		if (isset($this->ref)) $this->ref=trim($this->ref);
774
-		if (isset($this->entity)) $this->entity=trim($this->entity);
775
-		if (isset($this->ref_supplier)) $this->ref_supplier=trim($this->ref_supplier);
776
-		if (isset($this->socid)) $this->socid=trim($this->socid);
777
-		if (isset($this->fk_user_author)) $this->fk_user_author=trim($this->fk_user_author);
778
-		if (isset($this->fk_user_valid)) $this->fk_user_valid=trim($this->fk_user_valid);
779
-		if (isset($this->fk_delivery_address)) $this->fk_delivery_address=trim($this->fk_delivery_address);
780
-		if (isset($this->shipping_method_id)) $this->shipping_method_id=trim($this->shipping_method_id);
781
-		if (isset($this->tracking_number)) $this->tracking_number=trim($this->tracking_number);
782
-		if (isset($this->statut)) $this->statut=(int) $this->statut;
783
-		if (isset($this->trueDepth)) $this->trueDepth=trim($this->trueDepth);
784
-		if (isset($this->trueWidth)) $this->trueWidth=trim($this->trueWidth);
785
-		if (isset($this->trueHeight)) $this->trueHeight=trim($this->trueHeight);
786
-		if (isset($this->size_units)) $this->size_units=trim($this->size_units);
787
-		if (isset($this->weight_units)) $this->weight_units=trim($this->weight_units);
788
-		if (isset($this->trueWeight)) $this->weight=trim($this->trueWeight);
789
-		if (isset($this->note_private)) $this->note=trim($this->note_private);
790
-		if (isset($this->note_public)) $this->note=trim($this->note_public);
791
-		if (isset($this->modelpdf)) $this->modelpdf=trim($this->modelpdf);
792
-
793
-
794
-		// Check parameters
795
-		// Put here code to add control on parameters values
768
+        global $conf;
769
+        $error=0;
770
+
771
+        // Clean parameters
772
+
773
+        if (isset($this->ref)) $this->ref=trim($this->ref);
774
+        if (isset($this->entity)) $this->entity=trim($this->entity);
775
+        if (isset($this->ref_supplier)) $this->ref_supplier=trim($this->ref_supplier);
776
+        if (isset($this->socid)) $this->socid=trim($this->socid);
777
+        if (isset($this->fk_user_author)) $this->fk_user_author=trim($this->fk_user_author);
778
+        if (isset($this->fk_user_valid)) $this->fk_user_valid=trim($this->fk_user_valid);
779
+        if (isset($this->fk_delivery_address)) $this->fk_delivery_address=trim($this->fk_delivery_address);
780
+        if (isset($this->shipping_method_id)) $this->shipping_method_id=trim($this->shipping_method_id);
781
+        if (isset($this->tracking_number)) $this->tracking_number=trim($this->tracking_number);
782
+        if (isset($this->statut)) $this->statut=(int) $this->statut;
783
+        if (isset($this->trueDepth)) $this->trueDepth=trim($this->trueDepth);
784
+        if (isset($this->trueWidth)) $this->trueWidth=trim($this->trueWidth);
785
+        if (isset($this->trueHeight)) $this->trueHeight=trim($this->trueHeight);
786
+        if (isset($this->size_units)) $this->size_units=trim($this->size_units);
787
+        if (isset($this->weight_units)) $this->weight_units=trim($this->weight_units);
788
+        if (isset($this->trueWeight)) $this->weight=trim($this->trueWeight);
789
+        if (isset($this->note_private)) $this->note=trim($this->note_private);
790
+        if (isset($this->note_public)) $this->note=trim($this->note_public);
791
+        if (isset($this->modelpdf)) $this->modelpdf=trim($this->modelpdf);
792
+
793
+
794
+        // Check parameters
795
+        // Put here code to add control on parameters values
796 796
 
797 797
         // Update request
798 798
         $sql = "UPDATE ".MAIN_DB_PREFIX."reception SET";
799 799
 
800
-		$sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
801
-		$sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").",";
802
-		$sql.= " ref_supplier=".(isset($this->ref_supplier)?"'".$this->db->escape($this->ref_supplier)."'":"null").",";
803
-		$sql.= " fk_soc=".(isset($this->socid)?$this->socid:"null").",";
804
-		$sql.= " date_creation=".(dol_strlen($this->date_creation)!=0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').",";
805
-		$sql.= " fk_user_author=".(isset($this->fk_user_author)?$this->fk_user_author:"null").",";
806
-		$sql.= " date_valid=".(dol_strlen($this->date_valid)!=0 ? "'".$this->db->idate($this->date_valid)."'" : 'null').",";
807
-		$sql.= " fk_user_valid=".(isset($this->fk_user_valid)?$this->fk_user_valid:"null").",";
808
-		$sql.= " date_reception=".(dol_strlen($this->date_reception)!=0 ? "'".$this->db->idate($this->date_reception)."'" : 'null').",";
809
-		$sql.= " date_delivery=".(dol_strlen($this->date_delivery)!=0 ? "'".$this->db->idate($this->date_delivery)."'" : 'null').",";
810
-		$sql.= " fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0)?$this->shipping_method_id:"null").",";
811
-		$sql.= " tracking_number=".(isset($this->tracking_number)?"'".$this->db->escape($this->tracking_number)."'":"null").",";
812
-		$sql.= " fk_statut=".(isset($this->statut)?$this->statut:"null").",";
813
-		$sql.= " height=".(($this->trueHeight != '')?$this->trueHeight:"null").",";
814
-		$sql.= " width=".(($this->trueWidth != '')?$this->trueWidth:"null").",";
815
-		$sql.= " size_units=".(isset($this->size_units)?$this->size_units:"null").",";
816
-		$sql.= " size=".(($this->trueDepth != '')?$this->trueDepth:"null").",";
817
-		$sql.= " weight_units=".(isset($this->weight_units)?$this->weight_units:"null").",";
818
-		$sql.= " weight=".(($this->trueWeight != '')?$this->trueWeight:"null").",";
819
-		$sql.= " note_private=".(isset($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null").",";
820
-		$sql.= " note_public=".(isset($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null").",";
821
-		$sql.= " model_pdf=".(isset($this->modelpdf)?"'".$this->db->escape($this->modelpdf)."'":"null").",";
822
-		$sql.= " entity=".$conf->entity;
800
+        $sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
801
+        $sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").",";
802
+        $sql.= " ref_supplier=".(isset($this->ref_supplier)?"'".$this->db->escape($this->ref_supplier)."'":"null").",";
803
+        $sql.= " fk_soc=".(isset($this->socid)?$this->socid:"null").",";
804
+        $sql.= " date_creation=".(dol_strlen($this->date_creation)!=0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').",";
805
+        $sql.= " fk_user_author=".(isset($this->fk_user_author)?$this->fk_user_author:"null").",";
806
+        $sql.= " date_valid=".(dol_strlen($this->date_valid)!=0 ? "'".$this->db->idate($this->date_valid)."'" : 'null').",";
807
+        $sql.= " fk_user_valid=".(isset($this->fk_user_valid)?$this->fk_user_valid:"null").",";
808
+        $sql.= " date_reception=".(dol_strlen($this->date_reception)!=0 ? "'".$this->db->idate($this->date_reception)."'" : 'null').",";
809
+        $sql.= " date_delivery=".(dol_strlen($this->date_delivery)!=0 ? "'".$this->db->idate($this->date_delivery)."'" : 'null').",";
810
+        $sql.= " fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0)?$this->shipping_method_id:"null").",";
811
+        $sql.= " tracking_number=".(isset($this->tracking_number)?"'".$this->db->escape($this->tracking_number)."'":"null").",";
812
+        $sql.= " fk_statut=".(isset($this->statut)?$this->statut:"null").",";
813
+        $sql.= " height=".(($this->trueHeight != '')?$this->trueHeight:"null").",";
814
+        $sql.= " width=".(($this->trueWidth != '')?$this->trueWidth:"null").",";
815
+        $sql.= " size_units=".(isset($this->size_units)?$this->size_units:"null").",";
816
+        $sql.= " size=".(($this->trueDepth != '')?$this->trueDepth:"null").",";
817
+        $sql.= " weight_units=".(isset($this->weight_units)?$this->weight_units:"null").",";
818
+        $sql.= " weight=".(($this->trueWeight != '')?$this->trueWeight:"null").",";
819
+        $sql.= " note_private=".(isset($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null").",";
820
+        $sql.= " note_public=".(isset($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null").",";
821
+        $sql.= " model_pdf=".(isset($this->modelpdf)?"'".$this->db->escape($this->modelpdf)."'":"null").",";
822
+        $sql.= " entity=".$conf->entity;
823 823
 
824 824
         $sql.= " WHERE rowid=".$this->id;
825 825
 
826
-		$this->db->begin();
826
+        $this->db->begin();
827 827
 
828
-		dol_syslog(get_class($this)."::update", LOG_DEBUG);
828
+        dol_syslog(get_class($this)."::update", LOG_DEBUG);
829 829
         $resql = $this->db->query($sql);
830
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
830
+        if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
831 831
 
832
-		if (! $error)
833
-		{
834
-			if (! $notrigger)
835
-			{
832
+        if (! $error)
833
+        {
834
+            if (! $notrigger)
835
+            {
836 836
                 // Call trigger
837 837
                 $result=$this->call_trigger('RECEPTION_MODIFY',$user);
838 838
                 if ($result < 0) { $error++; }
839 839
                 // End call triggers
840
-	    	}
841
-		}
840
+            }
841
+        }
842 842
 
843 843
         // Commit or rollback
844
-		if ($error)
845
-		{
846
-			foreach($this->errors as $errmsg)
847
-			{
848
-	            dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
849
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
850
-			}
851
-			$this->db->rollback();
852
-			return -1*$error;
853
-		}
854
-		else
855
-		{
856
-			$this->db->commit();
857
-			return 1;
858
-		}
859
-	}
860
-
861
-	/**
862
-	 * 	Delete reception.
863
-	 *
864
-	 *	@param	User	$user	Object user
865
-	 * 	@return	int				>0 if OK, 0 if deletion done but failed to delete files, <0 if KO
866
-	 */
867
-	function delete(User $user)
868
-	{
869
-		global $conf, $langs, $user;
870
-		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
871
-
872
-		$error=0;
873
-		$this->error='';
874
-
875
-
876
-		$this->db->begin();
877
-
878
-		// Stock control
879
-		if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_RECEPTION && $this->statut > 0)
880
-		{
881
-			require_once DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php";
882
-
883
-			$langs->load("agenda");
884
-
885
-			// Loop on each product line to add a stock movement
886
-			$sql = "SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.eatby, ed.sellby, ed.batch, ed.rowid as commande_fournisseur_dispatch_id";
887
-			$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
888
-			$sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
889
-			$sql.= " WHERE ed.fk_reception = ".$this->id;
890
-			$sql.= " AND cd.rowid = ed.fk_commandefourndet";
891
-
892
-			dol_syslog(get_class($this)."::delete select details", LOG_DEBUG);
893
-			$resql=$this->db->query($sql);
894
-			if ($resql)
895
-			{
896
-				$cpt = $this->db->num_rows($resql);
897
-				for ($i = 0; $i < $cpt; $i++)
898
-				{
899
-					dol_syslog(get_class($this)."::delete movement index ".$i);
900
-					$obj = $this->db->fetch_object($resql);
901
-
902
-					$mouvS = new MouvementStock($this->db);
903
-					// we do not log origin because it will be deleted
904
-					$mouvS->origin = null;
905
-
906
-					$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans("ReceptionDeletedInDolibarr", $this->ref),'', $obj->eatby, $obj->sellby, $obj->batch);  // Price is set to 0, because we don't want to see WAP changed
907
-				}
908
-			}
909
-			else
910
-			{
911
-				$error++;$this->errors[]="Error ".$this->db->lasterror();
912
-			}
913
-		}
914
-
915
-		if (! $error)
916
-		{
917
-			$sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch";
918
-			$sql.= " WHERE fk_reception = ".$this->id;
919
-
920
-			if ( $this->db->query($sql) )
921
-			{
922
-				// Delete linked object
923
-				$res = $this->deleteObjectLinked();
924
-				if ($res < 0) $error++;
925
-
926
-				if (! $error)
927
-				{
928
-					$sql = "DELETE FROM ".MAIN_DB_PREFIX."reception";
929
-					$sql.= " WHERE rowid = ".$this->id;
930
-
931
-					if ($this->db->query($sql))
932
-					{
933
-						// Call trigger
934
-						$result=$this->call_trigger('RECEPTION_DELETE',$user);
935
-						if ($result < 0) { $error++; }
936
-						// End call triggers
937
-
938
-						if (! empty($this->origin) && $this->origin_id > 0)
939
-						{
940
-						    $this->fetch_origin();
941
-						    $origin=$this->origin;
942
-						    if ($this->$origin->statut == 4)     // If order source of reception is "partially received"
943
-						    {
844
+        if ($error)
845
+        {
846
+            foreach($this->errors as $errmsg)
847
+            {
848
+                dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
849
+                $this->error.=($this->error?', '.$errmsg:$errmsg);
850
+            }
851
+            $this->db->rollback();
852
+            return -1*$error;
853
+        }
854
+        else
855
+        {
856
+            $this->db->commit();
857
+            return 1;
858
+        }
859
+    }
860
+
861
+    /**
862
+     * 	Delete reception.
863
+     *
864
+     *	@param	User	$user	Object user
865
+     * 	@return	int				>0 if OK, 0 if deletion done but failed to delete files, <0 if KO
866
+     */
867
+    function delete(User $user)
868
+    {
869
+        global $conf, $langs, $user;
870
+        require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
871
+
872
+        $error=0;
873
+        $this->error='';
874
+
875
+
876
+        $this->db->begin();
877
+
878
+        // Stock control
879
+        if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_RECEPTION && $this->statut > 0)
880
+        {
881
+            require_once DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php";
882
+
883
+            $langs->load("agenda");
884
+
885
+            // Loop on each product line to add a stock movement
886
+            $sql = "SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.eatby, ed.sellby, ed.batch, ed.rowid as commande_fournisseur_dispatch_id";
887
+            $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
888
+            $sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
889
+            $sql.= " WHERE ed.fk_reception = ".$this->id;
890
+            $sql.= " AND cd.rowid = ed.fk_commandefourndet";
891
+
892
+            dol_syslog(get_class($this)."::delete select details", LOG_DEBUG);
893
+            $resql=$this->db->query($sql);
894
+            if ($resql)
895
+            {
896
+                $cpt = $this->db->num_rows($resql);
897
+                for ($i = 0; $i < $cpt; $i++)
898
+                {
899
+                    dol_syslog(get_class($this)."::delete movement index ".$i);
900
+                    $obj = $this->db->fetch_object($resql);
901
+
902
+                    $mouvS = new MouvementStock($this->db);
903
+                    // we do not log origin because it will be deleted
904
+                    $mouvS->origin = null;
905
+
906
+                    $result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans("ReceptionDeletedInDolibarr", $this->ref),'', $obj->eatby, $obj->sellby, $obj->batch);  // Price is set to 0, because we don't want to see WAP changed
907
+                }
908
+            }
909
+            else
910
+            {
911
+                $error++;$this->errors[]="Error ".$this->db->lasterror();
912
+            }
913
+        }
914
+
915
+        if (! $error)
916
+        {
917
+            $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch";
918
+            $sql.= " WHERE fk_reception = ".$this->id;
919
+
920
+            if ( $this->db->query($sql) )
921
+            {
922
+                // Delete linked object
923
+                $res = $this->deleteObjectLinked();
924
+                if ($res < 0) $error++;
925
+
926
+                if (! $error)
927
+                {
928
+                    $sql = "DELETE FROM ".MAIN_DB_PREFIX."reception";
929
+                    $sql.= " WHERE rowid = ".$this->id;
930
+
931
+                    if ($this->db->query($sql))
932
+                    {
933
+                        // Call trigger
934
+                        $result=$this->call_trigger('RECEPTION_DELETE',$user);
935
+                        if ($result < 0) { $error++; }
936
+                        // End call triggers
937
+
938
+                        if (! empty($this->origin) && $this->origin_id > 0)
939
+                        {
940
+                            $this->fetch_origin();
941
+                            $origin=$this->origin;
942
+                            if ($this->$origin->statut == 4)     // If order source of reception is "partially received"
943
+                            {
944 944
                                 // Check if there is no more reception. If not, we can move back status of order to "validated" instead of "reception in progress"
945
-						        $this->$origin->loadReceptions();
946
-						        //var_dump($this->$origin->receptions);exit;
947
-						        if (count($this->$origin->receptions) <= 0)
948
-						        {
945
+                                $this->$origin->loadReceptions();
946
+                                //var_dump($this->$origin->receptions);exit;
947
+                                if (count($this->$origin->receptions) <= 0)
948
+                                {
949 949
                                     $this->$origin->setStatut(3); // ordered
950
-						        }
951
-						    }
952
-						}
953
-
954
-						if (! $error)
955
-						{
956
-							$this->db->commit();
957
-
958
-							// We delete PDFs
959
-							$ref = dol_sanitizeFileName($this->ref);
960
-							if (! empty($conf->reception->dir_output))
961
-							{
962
-								$dir = $conf->reception->dir_output . '/' . $ref ;
963
-								$file = $dir . '/' . $ref . '.pdf';
964
-								if (file_exists($file))
965
-								{
966
-									if (! dol_delete_file($file))
967
-									{
968
-										return 0;
969
-									}
970
-								}
971
-								if (file_exists($dir))
972
-								{
973
-									if (!dol_delete_dir_recursive($dir))
974
-									{
975
-										$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
976
-										return 0;
977
-									}
978
-								}
979
-							}
980
-
981
-							return 1;
982
-						}
983
-						else
984
-						{
985
-							$this->db->rollback();
986
-							return -1;
987
-						}
988
-					}
989
-					else
990
-					{
991
-						$this->error=$this->db->lasterror()." - sql=$sql";
992
-						$this->db->rollback();
993
-						return -3;
994
-					}
995
-				}
996
-				else
997
-				{
998
-					$this->error=$this->db->lasterror()." - sql=$sql";
999
-					$this->db->rollback();
1000
-					return -2;
1001
-				}
1002
-			}
1003
-			else
1004
-			{
1005
-				$this->error=$this->db->lasterror()." - sql=$sql";
1006
-				$this->db->rollback();
1007
-				return -1;
1008
-			}
1009
-		}
1010
-		else
1011
-		{
1012
-			$this->db->rollback();
1013
-			return -1;
1014
-		}
1015
-	}
950
+                                }
951
+                            }
952
+                        }
953
+
954
+                        if (! $error)
955
+                        {
956
+                            $this->db->commit();
957
+
958
+                            // We delete PDFs
959
+                            $ref = dol_sanitizeFileName($this->ref);
960
+                            if (! empty($conf->reception->dir_output))
961
+                            {
962
+                                $dir = $conf->reception->dir_output . '/' . $ref ;
963
+                                $file = $dir . '/' . $ref . '.pdf';
964
+                                if (file_exists($file))
965
+                                {
966
+                                    if (! dol_delete_file($file))
967
+                                    {
968
+                                        return 0;
969
+                                    }
970
+                                }
971
+                                if (file_exists($dir))
972
+                                {
973
+                                    if (!dol_delete_dir_recursive($dir))
974
+                                    {
975
+                                        $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
976
+                                        return 0;
977
+                                    }
978
+                                }
979
+                            }
980
+
981
+                            return 1;
982
+                        }
983
+                        else
984
+                        {
985
+                            $this->db->rollback();
986
+                            return -1;
987
+                        }
988
+                    }
989
+                    else
990
+                    {
991
+                        $this->error=$this->db->lasterror()." - sql=$sql";
992
+                        $this->db->rollback();
993
+                        return -3;
994
+                    }
995
+                }
996
+                else
997
+                {
998
+                    $this->error=$this->db->lasterror()." - sql=$sql";
999
+                    $this->db->rollback();
1000
+                    return -2;
1001
+                }
1002
+            }
1003
+            else
1004
+            {
1005
+                $this->error=$this->db->lasterror()." - sql=$sql";
1006
+                $this->db->rollback();
1007
+                return -1;
1008
+            }
1009
+        }
1010
+        else
1011
+        {
1012
+            $this->db->rollback();
1013
+            return -1;
1014
+        }
1015
+    }
1016 1016
 
1017 1017
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1018
-	/**
1019
-	 *	Load lines
1020
-	 *
1021
-	 *	@return	int		>0 if OK, Otherwise if KO
1022
-	 */
1023
-	function fetch_lines()
1024
-	{
1025
-		// phpcs:enable
1026
-		global $db;
1027
-		dol_include_once('/fourn/class/fournisseur.commande.dispatch.class.php');
1028
-		$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'commande_fournisseur_dispatch WHERE fk_reception='.$this->id;
1029
-		$resql = $db->query($sql);
1030
-
1031
-		if(!empty($resql)){
1032
-			$this->lines = array();
1033
-			while ($obj = $resql->fetch_object()){
1034
-				$line = new CommandeFournisseurDispatch($db);
1035
-				$line->fetch($obj->rowid);
1036
-				$line->fetch_product();
1037
-				$sql_commfourndet = 'SELECT qty, ref,  label, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent FROM llx_commande_fournisseurdet WHERE rowid='.$line->fk_commandefourndet;
1038
-				$resql_commfourndet = $db->query($sql_commfourndet);
1039
-				if(!empty($resql_commfourndet)){
1040
-					$obj = $db->fetch_object($resql_commfourndet);
1041
-					$line->qty_asked = $obj->qty;
1042
-					$line->description = $line->comment;
1043
-					$line->desc =  $line->comment;
1044
-					$line->tva_tx = $obj->tva_tx;
1045
-					$line->vat_src_code = $obj->vat_src_code;
1046
-					$line->subprice = $obj->subprice;
1047
-					$line->multicurrency_subprice = $obj->multicurrency_subprice;
1048
-					$line->remise_percent = $obj->remise_percent;
1049
-					$line->label = !empty($obj->label)?$obj->label:$line->product->label;
1050
-					$line->ref_supplier = $obj->ref;
1051
-				}else {
1052
-					$line->qty_asked = 0;
1053
-					$line->description = '';
1054
-					$line->label = $obj->label;
1055
-				}
1056
-
1057
-				$pu_ht=($line->subprice*$line->qty)*(100-$line->remise_percent)/100;
1058
-				$tva = $pu_ht*$line->tva_tx/100;
1059
-				$this->total_ht += $pu_ht;
1060
-				$this->total_tva += $pu_ht*$line->tva_tx/100;
1061
-
1062
-				$this->total_ttc += $pu_ht+$tva;
1063
-
1064
-
1065
-				$this->lines[]=$line;
1066
-			}
1067
-
1068
-			return 1;
1069
-		}
1070
-		else {
1071
-			return -1;
1072
-		}
1073
-	}
1074
-
1075
-	/**
1018
+    /**
1019
+     *	Load lines
1020
+     *
1021
+     *	@return	int		>0 if OK, Otherwise if KO
1022
+     */
1023
+    function fetch_lines()
1024
+    {
1025
+        // phpcs:enable
1026
+        global $db;
1027
+        dol_include_once('/fourn/class/fournisseur.commande.dispatch.class.php');
1028
+        $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'commande_fournisseur_dispatch WHERE fk_reception='.$this->id;
1029
+        $resql = $db->query($sql);
1030
+
1031
+        if(!empty($resql)){
1032
+            $this->lines = array();
1033
+            while ($obj = $resql->fetch_object()){
1034
+                $line = new CommandeFournisseurDispatch($db);
1035
+                $line->fetch($obj->rowid);
1036
+                $line->fetch_product();
1037
+                $sql_commfourndet = 'SELECT qty, ref,  label, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent FROM llx_commande_fournisseurdet WHERE rowid='.$line->fk_commandefourndet;
1038
+                $resql_commfourndet = $db->query($sql_commfourndet);
1039
+                if(!empty($resql_commfourndet)){
1040
+                    $obj = $db->fetch_object($resql_commfourndet);
1041
+                    $line->qty_asked = $obj->qty;
1042
+                    $line->description = $line->comment;
1043
+                    $line->desc =  $line->comment;
1044
+                    $line->tva_tx = $obj->tva_tx;
1045
+                    $line->vat_src_code = $obj->vat_src_code;
1046
+                    $line->subprice = $obj->subprice;
1047
+                    $line->multicurrency_subprice = $obj->multicurrency_subprice;
1048
+                    $line->remise_percent = $obj->remise_percent;
1049
+                    $line->label = !empty($obj->label)?$obj->label:$line->product->label;
1050
+                    $line->ref_supplier = $obj->ref;
1051
+                }else {
1052
+                    $line->qty_asked = 0;
1053
+                    $line->description = '';
1054
+                    $line->label = $obj->label;
1055
+                }
1056
+
1057
+                $pu_ht=($line->subprice*$line->qty)*(100-$line->remise_percent)/100;
1058
+                $tva = $pu_ht*$line->tva_tx/100;
1059
+                $this->total_ht += $pu_ht;
1060
+                $this->total_tva += $pu_ht*$line->tva_tx/100;
1061
+
1062
+                $this->total_ttc += $pu_ht+$tva;
1063
+
1064
+
1065
+                $this->lines[]=$line;
1066
+            }
1067
+
1068
+            return 1;
1069
+        }
1070
+        else {
1071
+            return -1;
1072
+        }
1073
+    }
1074
+
1075
+    /**
1076 1076
      *	Return clicable link of object (with eventually picto)
1077 1077
      *
1078 1078
      *	@param      int			$withpicto      Add picto into link
@@ -1082,152 +1082,152 @@  discard block
 block discarded – undo
1082 1082
      *  @param      int         $notooltip      1=No tooltip
1083 1083
      *	@return     string          			String with URL
1084 1084
      */
1085
-	function getNomUrl($withpicto=0,$option=0,$max=0,$short=0,$notooltip=0)
1086
-	{
1087
-		global $langs;
1088
-		$result='';
1085
+    function getNomUrl($withpicto=0,$option=0,$max=0,$short=0,$notooltip=0)
1086
+    {
1087
+        global $langs;
1088
+        $result='';
1089 1089
         $label = '<u>' . $langs->trans("ShowReception") . '</u>';
1090 1090
         $label .= '<br><b>' . $langs->trans('Ref') . ':</b> '.$this->ref;
1091 1091
         $label .= '<br><b>'.$langs->trans('RefSupplier').':</b> '.($this->ref_supplier ? $this->ref_supplier : $this->ref_client);
1092 1092
 
1093
-		$url = DOL_URL_ROOT.'/reception/card.php?id='.$this->id;
1093
+        $url = DOL_URL_ROOT.'/reception/card.php?id='.$this->id;
1094 1094
 
1095
-		if ($short) return $url;
1095
+        if ($short) return $url;
1096 1096
 
1097
-		$linkclose='';
1098
-		if (empty($notooltip))
1099
-		{
1100
-		    if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1101
-		    {
1102
-		        $label=$langs->trans("ShowReception");
1103
-		        $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
1104
-		    }
1105
-		    $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
1106
-		    $linkclose.=' class="classfortooltip"';
1107
-		}
1097
+        $linkclose='';
1098
+        if (empty($notooltip))
1099
+        {
1100
+            if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1101
+            {
1102
+                $label=$langs->trans("ShowReception");
1103
+                $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
1104
+            }
1105
+            $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
1106
+            $linkclose.=' class="classfortooltip"';
1107
+        }
1108 1108
 
1109 1109
         $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1110
-		$linkend='</a>';
1110
+        $linkend='</a>';
1111 1111
 
1112
-		$picto='sending';
1112
+        $picto='sending';
1113 1113
 
1114
-		if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
1115
-		if ($withpicto && $withpicto != 2) $result.=' ';
1116
-		$result.=$linkstart.$this->ref.$linkend;
1117
-		return $result;
1118
-	}
1114
+        if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
1115
+        if ($withpicto && $withpicto != 2) $result.=' ';
1116
+        $result.=$linkstart.$this->ref.$linkend;
1117
+        return $result;
1118
+    }
1119 1119
 
1120
-	/**
1120
+    /**
1121 1121
      *	Return status label
1122 1122
      *
1123 1123
      *	@param      int		$mode      	0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto
1124 1124
      *	@return     string      		Libelle
1125 1125
      */
1126
-	function getLibStatut($mode=0)
1127
-	{
1128
-		return $this->LibStatut($this->statut,$mode);
1129
-	}
1130
-
1131
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1132
-	/**
1133
-	 * Return label of a status
1134
-	 *
1135
-	 * @param      int		$statut		Id statut
1136
-	 * @param      int		$mode       0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto
1137
-	 * @return     string				Label of status
1138
-	 */
1139
-	function LibStatut($statut,$mode)
1140
-	{
1141
-		// phpcs:enable
1142
-		global $langs;
1143
-
1144
-		if ($mode==0)
1145
-		{
1146
-			if ($statut==0) return $langs->trans($this->statuts[$statut]);
1147
-			if ($statut==1)  return $langs->trans($this->statuts[$statut]);
1148
-			if ($statut==2)  return $langs->trans($this->statuts[$statut]);
1149
-		}
1150
-		if ($mode==1)
1151
-		{
1152
-			if ($statut==0) return $langs->trans('StatusReceptionDraftShort');
1153
-			if ($statut==1) return $langs->trans('StatusReceptionValidatedShort');
1154
-			if ($statut==2) return $langs->trans('StatusReceptionProcessedShort');
1155
-		}
1156
-		if ($mode == 3)
1157
-		{
1158
-			if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0');
1159
-			if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut4');
1160
-			if ($statut==2) return img_picto($langs->trans('StatusReceptionProcessed'),'statut6');
1161
-		}
1162
-		if ($mode == 4)
1163
-		{
1164
-			if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
1165
-			if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
1166
-			if ($statut==2) return img_picto($langs->trans('StatusReceptionProcessed'),'statut6').' '.$langs->trans('StatusReceptionProcessed');
1167
-		}
1168
-		if ($mode == 5)
1169
-		{
1170
-			if ($statut==0) return $langs->trans('StatusReceptionDraftShort').' '.img_picto($langs->trans($this->statuts[$statut]),'statut0');
1171
-			if ($statut==1) return $langs->trans('StatusReceptionValidatedShort').' '.img_picto($langs->trans($this->statuts[$statut]),'statut4');
1172
-			if ($statut==2) return $langs->trans('StatusReceptionProcessedShort').' '.img_picto($langs->trans('StatusReceptionProcessedShort'),'statut6');
1173
-		}
1174
-	}
1175
-
1176
-	/**
1126
+    function getLibStatut($mode=0)
1127
+    {
1128
+        return $this->LibStatut($this->statut,$mode);
1129
+    }
1130
+
1131
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1132
+    /**
1133
+     * Return label of a status
1134
+     *
1135
+     * @param      int		$statut		Id statut
1136
+     * @param      int		$mode       0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto
1137
+     * @return     string				Label of status
1138
+     */
1139
+    function LibStatut($statut,$mode)
1140
+    {
1141
+        // phpcs:enable
1142
+        global $langs;
1143
+
1144
+        if ($mode==0)
1145
+        {
1146
+            if ($statut==0) return $langs->trans($this->statuts[$statut]);
1147
+            if ($statut==1)  return $langs->trans($this->statuts[$statut]);
1148
+            if ($statut==2)  return $langs->trans($this->statuts[$statut]);
1149
+        }
1150
+        if ($mode==1)
1151
+        {
1152
+            if ($statut==0) return $langs->trans('StatusReceptionDraftShort');
1153
+            if ($statut==1) return $langs->trans('StatusReceptionValidatedShort');
1154
+            if ($statut==2) return $langs->trans('StatusReceptionProcessedShort');
1155
+        }
1156
+        if ($mode == 3)
1157
+        {
1158
+            if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0');
1159
+            if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut4');
1160
+            if ($statut==2) return img_picto($langs->trans('StatusReceptionProcessed'),'statut6');
1161
+        }
1162
+        if ($mode == 4)
1163
+        {
1164
+            if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
1165
+            if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
1166
+            if ($statut==2) return img_picto($langs->trans('StatusReceptionProcessed'),'statut6').' '.$langs->trans('StatusReceptionProcessed');
1167
+        }
1168
+        if ($mode == 5)
1169
+        {
1170
+            if ($statut==0) return $langs->trans('StatusReceptionDraftShort').' '.img_picto($langs->trans($this->statuts[$statut]),'statut0');
1171
+            if ($statut==1) return $langs->trans('StatusReceptionValidatedShort').' '.img_picto($langs->trans($this->statuts[$statut]),'statut4');
1172
+            if ($statut==2) return $langs->trans('StatusReceptionProcessedShort').' '.img_picto($langs->trans('StatusReceptionProcessedShort'),'statut6');
1173
+        }
1174
+    }
1175
+
1176
+    /**
1177 1177
      *  Initialise an instance with random values.
1178 1178
      *  Used to build previews or test instances.
1179 1179
      *	id must be 0 if object instance is a specimen.
1180 1180
      *
1181 1181
      *  @return	void
1182
-	 */
1183
-	function initAsSpecimen()
1184
-	{
1185
-		global $langs;
1186
-		dol_include_once('/fourn/class/fournisseur.commande.dispatch.class.php');
1187
-		$now=dol_now();
1182
+     */
1183
+    function initAsSpecimen()
1184
+    {
1185
+        global $langs;
1186
+        dol_include_once('/fourn/class/fournisseur.commande.dispatch.class.php');
1187
+        $now=dol_now();
1188 1188
 
1189
-		dol_syslog(get_class($this)."::initAsSpecimen");
1189
+        dol_syslog(get_class($this)."::initAsSpecimen");
1190 1190
 
1191 1191
         // Load array of products prodids
1192
-		$num_prods = 0;
1193
-		$prodids = array();
1194
-		$sql = "SELECT rowid";
1195
-		$sql.= " FROM ".MAIN_DB_PREFIX."product";
1196
-		$sql.= " WHERE entity IN (".getEntity('product').")";
1197
-		$resql = $this->db->query($sql);
1198
-		if ($resql)
1199
-		{
1200
-			$num_prods = $this->db->num_rows($resql);
1201
-			$i = 0;
1202
-			while ($i < $num_prods)
1203
-			{
1204
-				$i++;
1205
-				$row = $this->db->fetch_row($resql);
1206
-				$prodids[$i] = $row[0];
1207
-			}
1208
-		}
1209
-
1210
-		$order=new Commande($this->db);
1211
-		$order->initAsSpecimen();
1212
-
1213
-		// Initialise parametres
1214
-		$this->id=0;
1215
-		$this->ref = 'SPECIMEN';
1216
-		$this->specimen=1;
1217
-		$this->statut               = 1;
1218
-		$this->livraison_id         = 0;
1219
-		$this->date                 = $now;
1220
-		$this->date_creation        = $now;
1221
-		$this->date_valid           = $now;
1222
-		$this->date_delivery        = $now;
1223
-		$this->date_reception      = $now + 24*3600;
1224
-
1225
-		$this->entrepot_id          = 0;
1226
-		$this->fk_delivery_address  = 0;
1227
-		$this->socid                = 1;
1228
-
1229
-		$this->commande_id          = 0;
1230
-		$this->commande             = $order;
1192
+        $num_prods = 0;
1193
+        $prodids = array();
1194
+        $sql = "SELECT rowid";
1195
+        $sql.= " FROM ".MAIN_DB_PREFIX."product";
1196
+        $sql.= " WHERE entity IN (".getEntity('product').")";
1197
+        $resql = $this->db->query($sql);
1198
+        if ($resql)
1199
+        {
1200
+            $num_prods = $this->db->num_rows($resql);
1201
+            $i = 0;
1202
+            while ($i < $num_prods)
1203
+            {
1204
+                $i++;
1205
+                $row = $this->db->fetch_row($resql);
1206
+                $prodids[$i] = $row[0];
1207
+            }
1208
+        }
1209
+
1210
+        $order=new Commande($this->db);
1211
+        $order->initAsSpecimen();
1212
+
1213
+        // Initialise parametres
1214
+        $this->id=0;
1215
+        $this->ref = 'SPECIMEN';
1216
+        $this->specimen=1;
1217
+        $this->statut               = 1;
1218
+        $this->livraison_id         = 0;
1219
+        $this->date                 = $now;
1220
+        $this->date_creation        = $now;
1221
+        $this->date_valid           = $now;
1222
+        $this->date_delivery        = $now;
1223
+        $this->date_reception      = $now + 24*3600;
1224
+
1225
+        $this->entrepot_id          = 0;
1226
+        $this->fk_delivery_address  = 0;
1227
+        $this->socid                = 1;
1228
+
1229
+        $this->commande_id          = 0;
1230
+        $this->commande             = $order;
1231 1231
 
1232 1232
         $this->origin_id            = 1;
1233 1233
         $this->origin               = 'commande';
@@ -1235,85 +1235,85 @@  discard block
 block discarded – undo
1235 1235
         $this->note_private			= 'Private note';
1236 1236
         $this->note_public			= 'Public note';
1237 1237
 
1238
-		$nbp = 5;
1239
-		$xnbp = 0;
1240
-		while ($xnbp < $nbp)
1241
-		{
1242
-			$line=new CommandeFournisseurDispatch($this->db);
1243
-			$line->desc=$langs->trans("Description")." ".$xnbp;
1244
-			$line->libelle=$langs->trans("Description")." ".$xnbp;
1245
-			$line->qty=10;
1238
+        $nbp = 5;
1239
+        $xnbp = 0;
1240
+        while ($xnbp < $nbp)
1241
+        {
1242
+            $line=new CommandeFournisseurDispatch($this->db);
1243
+            $line->desc=$langs->trans("Description")." ".$xnbp;
1244
+            $line->libelle=$langs->trans("Description")." ".$xnbp;
1245
+            $line->qty=10;
1246 1246
 
1247
-			$line->fk_product=$this->commande->lines[$xnbp]->fk_product;
1247
+            $line->fk_product=$this->commande->lines[$xnbp]->fk_product;
1248 1248
 
1249
-			$this->lines[]=$line;
1250
-			$xnbp++;
1251
-		}
1252
-	}
1249
+            $this->lines[]=$line;
1250
+            $xnbp++;
1251
+        }
1252
+    }
1253 1253
 
1254 1254
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1255
-	/**
1256
-	 *	Set the planned delivery date
1257
-	 *
1258
-	 *	@param      User			$user        		Objet utilisateur qui modifie
1259
-	 *	@param      timestamp		$date_livraison     Date de livraison
1260
-	 *	@return     int         						<0 if KO, >0 if OK
1261
-	 */
1262
-	function set_date_livraison($user, $date_livraison)
1263
-	{
1264
-		// phpcs:enable
1265
-		if ($user->rights->reception->creer)
1266
-		{
1267
-			$sql = "UPDATE ".MAIN_DB_PREFIX."reception";
1268
-			$sql.= " SET date_delivery = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null');
1269
-			$sql.= " WHERE rowid = ".$this->id;
1270
-
1271
-			dol_syslog(get_class($this)."::set_date_livraison", LOG_DEBUG);
1272
-			$resql=$this->db->query($sql);
1273
-			if ($resql)
1274
-			{
1275
-				$this->date_delivery = $date_livraison;
1276
-				return 1;
1277
-			}
1278
-			else
1279
-			{
1280
-				$this->error=$this->db->error();
1281
-				return -1;
1282
-			}
1283
-		}
1284
-		else
1285
-		{
1286
-			return -2;
1287
-		}
1288
-	}
1255
+    /**
1256
+     *	Set the planned delivery date
1257
+     *
1258
+     *	@param      User			$user        		Objet utilisateur qui modifie
1259
+     *	@param      timestamp		$date_livraison     Date de livraison
1260
+     *	@return     int         						<0 if KO, >0 if OK
1261
+     */
1262
+    function set_date_livraison($user, $date_livraison)
1263
+    {
1264
+        // phpcs:enable
1265
+        if ($user->rights->reception->creer)
1266
+        {
1267
+            $sql = "UPDATE ".MAIN_DB_PREFIX."reception";
1268
+            $sql.= " SET date_delivery = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null');
1269
+            $sql.= " WHERE rowid = ".$this->id;
1270
+
1271
+            dol_syslog(get_class($this)."::set_date_livraison", LOG_DEBUG);
1272
+            $resql=$this->db->query($sql);
1273
+            if ($resql)
1274
+            {
1275
+                $this->date_delivery = $date_livraison;
1276
+                return 1;
1277
+            }
1278
+            else
1279
+            {
1280
+                $this->error=$this->db->error();
1281
+                return -1;
1282
+            }
1283
+        }
1284
+        else
1285
+        {
1286
+            return -2;
1287
+        }
1288
+    }
1289 1289
 
1290 1290
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1291
-	/**
1292
-	 *	Fetch deliveries method and return an array. Load array this->meths(rowid=>label).
1293
-	 *
1294
-	 * 	@return	void
1295
-	 */
1296
-	function fetch_delivery_methods()
1297
-	{
1298
-		// phpcs:enable
1299
-		global $langs;
1300
-		$this->meths = array();
1301
-
1302
-		$sql = "SELECT em.rowid, em.code, em.libelle";
1303
-		$sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1304
-		$sql.= " WHERE em.active = 1";
1305
-		$sql.= " ORDER BY em.libelle ASC";
1306
-
1307
-		$resql = $this->db->query($sql);
1308
-		if ($resql)
1309
-		{
1310
-			while ($obj = $this->db->fetch_object($resql))
1311
-			{
1312
-				$label=$langs->trans('ReceptionMethod'.$obj->code);
1313
-				$this->meths[$obj->rowid] = ($label != 'ReceptionMethod'.$obj->code?$label:$obj->libelle);
1314
-			}
1315
-		}
1316
-	}
1291
+    /**
1292
+     *	Fetch deliveries method and return an array. Load array this->meths(rowid=>label).
1293
+     *
1294
+     * 	@return	void
1295
+     */
1296
+    function fetch_delivery_methods()
1297
+    {
1298
+        // phpcs:enable
1299
+        global $langs;
1300
+        $this->meths = array();
1301
+
1302
+        $sql = "SELECT em.rowid, em.code, em.libelle";
1303
+        $sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1304
+        $sql.= " WHERE em.active = 1";
1305
+        $sql.= " ORDER BY em.libelle ASC";
1306
+
1307
+        $resql = $this->db->query($sql);
1308
+        if ($resql)
1309
+        {
1310
+            while ($obj = $this->db->fetch_object($resql))
1311
+            {
1312
+                $label=$langs->trans('ReceptionMethod'.$obj->code);
1313
+                $this->meths[$obj->rowid] = ($label != 'ReceptionMethod'.$obj->code?$label:$obj->libelle);
1314
+            }
1315
+        }
1316
+    }
1317 1317
 
1318 1318
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1319 1319
     /**
@@ -1324,7 +1324,7 @@  discard block
 block discarded – undo
1324 1324
      */
1325 1325
     function list_delivery_methods($id='')
1326 1326
     {
1327
-		// phpcs:enable
1327
+        // phpcs:enable
1328 1328
         global $langs;
1329 1329
 
1330 1330
         $this->listmeths = array();
@@ -1361,7 +1361,7 @@  discard block
 block discarded – undo
1361 1361
      */
1362 1362
     function update_delivery_method($id='')
1363 1363
     {
1364
-		// phpcs:enable
1364
+        // phpcs:enable
1365 1365
         if ($id=='')
1366 1366
         {
1367 1367
             $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_shipment_mode (code, libelle, description, tracking)";
@@ -1381,7 +1381,7 @@  discard block
 block discarded – undo
1381 1381
         if ($resql < 0) dol_print_error($this->db,'');
1382 1382
     }
1383 1383
 
1384
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1384
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1385 1385
     /**
1386 1386
      *  Activate delivery method.
1387 1387
      *
@@ -1391,7 +1391,7 @@  discard block
 block discarded – undo
1391 1391
      */
1392 1392
     function activ_delivery_method($id)
1393 1393
     {
1394
-		// phpcs:enable
1394
+        // phpcs:enable
1395 1395
         $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=1';
1396 1396
         $sql.= ' WHERE rowid='.$id;
1397 1397
 
@@ -1408,7 +1408,7 @@  discard block
 block discarded – undo
1408 1408
      */
1409 1409
     function disable_delivery_method($id)
1410 1410
     {
1411
-		// phpcs:enable
1411
+        // phpcs:enable
1412 1412
         $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=0';
1413 1413
         $sql.= ' WHERE rowid='.$id;
1414 1414
 
@@ -1416,366 +1416,366 @@  discard block
 block discarded – undo
1416 1416
     }
1417 1417
 
1418 1418
 
1419
-	/**
1420
-	 * Forge an set tracking url
1421
-	 *
1422
-	 * @param	string	$value		Value
1423
-	 * @return	void
1424
-	 */
1425
-	function getUrlTrackingStatus($value='')
1426
-	{
1427
-		if (! empty($this->shipping_method_id))
1428
-		{
1429
-			$sql = "SELECT em.code, em.tracking";
1430
-			$sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1431
-			$sql.= " WHERE em.rowid = ".$this->shipping_method_id;
1432
-
1433
-			$resql = $this->db->query($sql);
1434
-			if ($resql)
1435
-			{
1436
-				if ($obj = $this->db->fetch_object($resql))
1437
-				{
1438
-					$tracking = $obj->tracking;
1439
-				}
1440
-			}
1441
-		}
1442
-
1443
-		if (!empty($tracking) && !empty($value))
1444
-		{
1445
-			$url = str_replace('{TRACKID}', $value, $tracking);
1446
-			$this->tracking_url = sprintf('<a target="_blank" href="%s">'.($value?$value:'url').'</a>',$url,$url);
1447
-		}
1448
-		else
1449
-		{
1450
-			$this->tracking_url = $value;
1451
-		}
1452
-	}
1453
-
1454
-	/**
1455
-	 *	Classify the reception as closed.
1456
-	 *
1457
-	 *	@return     int     <0 if KO, >0 if OK
1458
-	 */
1459
-	function setClosed()
1460
-	{
1461
-		global $conf,$langs,$user;
1462
-
1463
-		$error=0;
1464
-
1465
-		$this->db->begin();
1466
-
1467
-		$sql = 'UPDATE '.MAIN_DB_PREFIX.'reception SET fk_statut='.self::STATUS_CLOSED;
1468
-		$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0';
1469
-
1470
-		$resql=$this->db->query($sql);
1471
-		if ($resql)
1472
-		{
1473
-			// Set order billed if 100% of order is received (qty in reception lines match qty in order lines)
1474
-			if ($this->origin == 'order_supplier' && $this->origin_id > 0)
1475
-			{
1476
-				$order = new CommandeFournisseur($this->db);
1477
-				$order->fetch($this->origin_id);
1478
-
1479
-				$order->loadReceptions(self::STATUS_CLOSED);		// Fill $order->receptions = array(orderlineid => qty)
1480
-
1481
-				$receptions_match_order = 1;
1482
-				foreach($order->lines as $line)
1483
-				{
1484
-					$lineid = $line->id;
1485
-					$qty = $line->qty;
1486
-					if (($line->product_type == 0 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->receptions[$lineid] < $qty)
1487
-					{
1488
-						$receptions_match_order = 0;
1489
-						$text='Qty for order line id '.$lineid.' is '.$qty.'. However in the receptions with status Reception::STATUS_CLOSED='.self::STATUS_CLOSED.' we have qty = '.$order->receptions[$lineid].', so we can t close order';
1490
-						dol_syslog($text);
1491
-						break;
1492
-					}
1493
-				}
1494
-				if ($receptions_match_order)
1495
-				{
1496
-					dol_syslog("Qty for the ".count($order->lines)." lines of order have same value for receptions with status Reception::STATUS_CLOSED=".self::STATUS_CLOSED.', so we close order');
1497
-					$order->Livraison($user, dol_now(), 'tot', 'Reception '.$this->ref);
1498
-				}
1499
-			}
1500
-
1501
-			$this->statut=self::STATUS_CLOSED;
1502
-
1503
-
1504
-			// If stock increment is done on closing
1505
-			if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))
1506
-			{
1507
-				require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
1508
-
1509
-				$langs->load("agenda");
1510
-
1511
-				// Loop on each product line to add a stock movement
1512
-				// TODO possibilite de receptionner a partir d'une propale ou autre origine ?
1513
-				$sql = "SELECT cd.fk_product, cd.subprice,";
1514
-				$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
1515
-				$sql.= " ed.eatby, ed.sellby, ed.batch";
1516
-				$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
1517
-				$sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
1518
-				$sql.= " WHERE ed.fk_reception = ".$this->id;
1519
-				$sql.= " AND cd.rowid = ed.fk_commandefourndet";
1520
-
1521
-				dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
1522
-				$resql=$this->db->query($sql);
1523
-
1524
-				if ($resql)
1525
-				{
1526
-					$cpt = $this->db->num_rows($resql);
1527
-					for ($i = 0; $i < $cpt; $i++)
1528
-					{
1529
-						$obj = $this->db->fetch_object($resql);
1530
-
1531
-						$qty = $obj->qty;
1532
-
1533
-						if ($qty <= 0) continue;
1534
-						dol_syslog(get_class($this)."::valid movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid);
1535
-
1536
-						$mouvS = new MouvementStock($this->db);
1537
-						$mouvS->origin = &$this;
1538
-
1539
-						if (empty($obj->batch))
1540
-						{
1541
-							// line without batch detail
1542
-
1543
-							// 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
1544
-							$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionClassifyClosedInDolibarr",$numref));
1545
-							if ($result < 0) {
1546
-							    $this->error = $mouvS->error;
1547
-							    $this->errors = $mouvS->errors;
1548
-								$error++; break;
1549
-							}
1550
-						}
1551
-						else
1552
-						{
1553
-							// line with batch detail
1554
-
1555
-							// 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
1556
-							$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionClassifyClosedInDolibarr",$numref),  $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch);
1557
-
1558
-							if ($result < 0) {
1559
-							    $this->error = $mouvS->error;
1560
-							    $this->errors = $mouvS->errors;
1561
-							    $error++; break;
1562
-							}
1563
-						}
1564
-					}
1565
-				}
1566
-				else
1567
-				{
1568
-					$this->error=$this->db->lasterror();
1569
-					$error++;
1570
-				}
1571
-			}
1572
-
1573
-			// Call trigger
1574
-			if (! $error)
1575
-			{
1576
-    			$result=$this->call_trigger('RECEPTION_CLOSED',$user);
1577
-    			if ($result < 0) {
1578
-    			    $error++;
1579
-    			}
1580
-			}
1581
-		}
1582
-		else
1583
-		{
1584
-			dol_print_error($this->db);
1419
+    /**
1420
+     * Forge an set tracking url
1421
+     *
1422
+     * @param	string	$value		Value
1423
+     * @return	void
1424
+     */
1425
+    function getUrlTrackingStatus($value='')
1426
+    {
1427
+        if (! empty($this->shipping_method_id))
1428
+        {
1429
+            $sql = "SELECT em.code, em.tracking";
1430
+            $sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1431
+            $sql.= " WHERE em.rowid = ".$this->shipping_method_id;
1432
+
1433
+            $resql = $this->db->query($sql);
1434
+            if ($resql)
1435
+            {
1436
+                if ($obj = $this->db->fetch_object($resql))
1437
+                {
1438
+                    $tracking = $obj->tracking;
1439
+                }
1440
+            }
1441
+        }
1442
+
1443
+        if (!empty($tracking) && !empty($value))
1444
+        {
1445
+            $url = str_replace('{TRACKID}', $value, $tracking);
1446
+            $this->tracking_url = sprintf('<a target="_blank" href="%s">'.($value?$value:'url').'</a>',$url,$url);
1447
+        }
1448
+        else
1449
+        {
1450
+            $this->tracking_url = $value;
1451
+        }
1452
+    }
1453
+
1454
+    /**
1455
+     *	Classify the reception as closed.
1456
+     *
1457
+     *	@return     int     <0 if KO, >0 if OK
1458
+     */
1459
+    function setClosed()
1460
+    {
1461
+        global $conf,$langs,$user;
1462
+
1463
+        $error=0;
1464
+
1465
+        $this->db->begin();
1466
+
1467
+        $sql = 'UPDATE '.MAIN_DB_PREFIX.'reception SET fk_statut='.self::STATUS_CLOSED;
1468
+        $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0';
1469
+
1470
+        $resql=$this->db->query($sql);
1471
+        if ($resql)
1472
+        {
1473
+            // Set order billed if 100% of order is received (qty in reception lines match qty in order lines)
1474
+            if ($this->origin == 'order_supplier' && $this->origin_id > 0)
1475
+            {
1476
+                $order = new CommandeFournisseur($this->db);
1477
+                $order->fetch($this->origin_id);
1478
+
1479
+                $order->loadReceptions(self::STATUS_CLOSED);		// Fill $order->receptions = array(orderlineid => qty)
1480
+
1481
+                $receptions_match_order = 1;
1482
+                foreach($order->lines as $line)
1483
+                {
1484
+                    $lineid = $line->id;
1485
+                    $qty = $line->qty;
1486
+                    if (($line->product_type == 0 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->receptions[$lineid] < $qty)
1487
+                    {
1488
+                        $receptions_match_order = 0;
1489
+                        $text='Qty for order line id '.$lineid.' is '.$qty.'. However in the receptions with status Reception::STATUS_CLOSED='.self::STATUS_CLOSED.' we have qty = '.$order->receptions[$lineid].', so we can t close order';
1490
+                        dol_syslog($text);
1491
+                        break;
1492
+                    }
1493
+                }
1494
+                if ($receptions_match_order)
1495
+                {
1496
+                    dol_syslog("Qty for the ".count($order->lines)." lines of order have same value for receptions with status Reception::STATUS_CLOSED=".self::STATUS_CLOSED.', so we close order');
1497
+                    $order->Livraison($user, dol_now(), 'tot', 'Reception '.$this->ref);
1498
+                }
1499
+            }
1500
+
1501
+            $this->statut=self::STATUS_CLOSED;
1502
+
1503
+
1504
+            // If stock increment is done on closing
1505
+            if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))
1506
+            {
1507
+                require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
1508
+
1509
+                $langs->load("agenda");
1510
+
1511
+                // Loop on each product line to add a stock movement
1512
+                // TODO possibilite de receptionner a partir d'une propale ou autre origine ?
1513
+                $sql = "SELECT cd.fk_product, cd.subprice,";
1514
+                $sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
1515
+                $sql.= " ed.eatby, ed.sellby, ed.batch";
1516
+                $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
1517
+                $sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
1518
+                $sql.= " WHERE ed.fk_reception = ".$this->id;
1519
+                $sql.= " AND cd.rowid = ed.fk_commandefourndet";
1520
+
1521
+                dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
1522
+                $resql=$this->db->query($sql);
1523
+
1524
+                if ($resql)
1525
+                {
1526
+                    $cpt = $this->db->num_rows($resql);
1527
+                    for ($i = 0; $i < $cpt; $i++)
1528
+                    {
1529
+                        $obj = $this->db->fetch_object($resql);
1530
+
1531
+                        $qty = $obj->qty;
1532
+
1533
+                        if ($qty <= 0) continue;
1534
+                        dol_syslog(get_class($this)."::valid movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid);
1535
+
1536
+                        $mouvS = new MouvementStock($this->db);
1537
+                        $mouvS->origin = &$this;
1538
+
1539
+                        if (empty($obj->batch))
1540
+                        {
1541
+                            // line without batch detail
1542
+
1543
+                            // 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
1544
+                            $result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionClassifyClosedInDolibarr",$numref));
1545
+                            if ($result < 0) {
1546
+                                $this->error = $mouvS->error;
1547
+                                $this->errors = $mouvS->errors;
1548
+                                $error++; break;
1549
+                            }
1550
+                        }
1551
+                        else
1552
+                        {
1553
+                            // line with batch detail
1554
+
1555
+                            // 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
1556
+                            $result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionClassifyClosedInDolibarr",$numref),  $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch);
1557
+
1558
+                            if ($result < 0) {
1559
+                                $this->error = $mouvS->error;
1560
+                                $this->errors = $mouvS->errors;
1561
+                                $error++; break;
1562
+                            }
1563
+                        }
1564
+                    }
1565
+                }
1566
+                else
1567
+                {
1568
+                    $this->error=$this->db->lasterror();
1569
+                    $error++;
1570
+                }
1571
+            }
1572
+
1573
+            // Call trigger
1574
+            if (! $error)
1575
+            {
1576
+                $result=$this->call_trigger('RECEPTION_CLOSED',$user);
1577
+                if ($result < 0) {
1578
+                    $error++;
1579
+                }
1580
+            }
1581
+        }
1582
+        else
1583
+        {
1584
+            dol_print_error($this->db);
1585 1585
             $error++;
1586
-		}
1587
-
1588
-		if (! $error)
1589
-		{
1590
-		    $this->db->commit();
1591
-		    return 1;
1592
-		}
1593
-		else
1594
-		{
1595
-		    $this->db->rollback();
1596
-		    return -1;
1597
-		}
1598
-	}
1586
+        }
1587
+
1588
+        if (! $error)
1589
+        {
1590
+            $this->db->commit();
1591
+            return 1;
1592
+        }
1593
+        else
1594
+        {
1595
+            $this->db->rollback();
1596
+            return -1;
1597
+        }
1598
+    }
1599 1599
 
1600 1600
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1601
-	/**
1602
-	 *	Classify the reception as invoiced (used when WORKFLOW_BILL_ON_RECEPTION is on)
1603
-	 *
1604
-	 *	@return     int     <0 if ko, >0 if ok
1605
-	 */
1606
-	function set_billed()
1607
-	{
1608
-		// phpcs:enable
1609
-	    global $user;
1610
-		$error=0;
1611
-
1612
-		$this->db->begin();
1613
-
1614
-		$this->setClosed();
1615
-
1616
-		$sql = 'UPDATE '.MAIN_DB_PREFIX.'reception SET  billed=1';
1617
-		$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0';
1618
-
1619
-		$resql=$this->db->query($sql);
1620
-		if ($resql)
1621
-		{
1622
-			$this->statut=2;
1623
-			$this->billed=1;
1624
-
1625
-			// Call trigger
1626
-			$result=$this->call_trigger('RECEPTION_BILLED',$user);
1627
-			if ($result < 0) {
1628
-				$error++;
1629
-			}
1630
-		} else {
1631
-			$error++;
1632
-			$this->errors[]=$this->db->lasterror;
1633
-		}
1634
-
1635
-		if (empty($error)) {
1636
-			$this->db->commit();
1637
-			return 1;
1638
-		}
1639
-		else
1640
-		{
1641
-			$this->db->rollback();
1642
-			return -1;
1643
-		}
1644
-	}
1645
-
1646
-	/**
1647
-	 *	Classify the reception as validated/opened
1648
-	 *
1649
-	 *	@return     int     <0 if ko, >0 if ok
1650
-	 */
1651
-	function reOpen()
1652
-	{
1653
-		global $conf,$langs,$user;
1654
-
1655
-		$error=0;
1656
-
1657
-		$this->db->begin();
1658
-
1659
-		$sql = 'UPDATE '.MAIN_DB_PREFIX.'reception SET fk_statut=1, billed=0';
1660
-		$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0';
1661
-
1662
-		$resql=$this->db->query($sql);
1663
-		if ($resql)
1664
-		{
1665
-			$this->statut=1;
1666
-			$this->billed=0;
1667
-
1668
-			// If stock increment is done on closing
1669
-			if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))
1670
-			{
1671
-				require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
1672
-				$numref = $this->ref;
1673
-				$langs->load("agenda");
1674
-
1675
-				// Loop on each product line to add a stock movement
1676
-				// TODO possibilite de receptionner a partir d'une propale ou autre origine
1677
-				$sql = "SELECT ed.fk_product, cd.subprice,";
1678
-				$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
1679
-				$sql.= " ed.eatby, ed.sellby, ed.batch";
1680
-				$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
1681
-				$sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
1682
-				$sql.= " WHERE ed.fk_reception = ".$this->id;
1683
-				$sql.= " AND cd.rowid = ed.fk_commandefourndet";
1684
-
1685
-				dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
1686
-				$resql=$this->db->query($sql);
1687
-				if ($resql)
1688
-				{
1689
-					$cpt = $this->db->num_rows($resql);
1690
-					for ($i = 0; $i < $cpt; $i++)
1691
-					{
1692
-						$obj = $this->db->fetch_object($resql);
1693
-
1694
-						$qty = $obj->qty;
1695
-
1696
-						if ($qty <= 0) continue;
1697
-
1698
-						dol_syslog(get_class($this)."::reopen reception movement index ".$i." ed.rowid=".$obj->rowid);
1699
-
1700
-						//var_dump($this->lines[$i]);
1701
-						$mouvS = new MouvementStock($this->db);
1702
-						$mouvS->origin = &$this;
1703
-
1704
-						if (empty($obj->batch))
1705
-						{
1706
-							// line without batch detail
1707
-
1708
-							// 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
1709
-							$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionUnClassifyCloseddInDolibarr",$numref));
1710
-							if ($result < 0) {
1711
-							    $this->error = $mouvS->error;
1712
-							    $this->errors = $mouvS->errors;
1713
-								$error++; break;
1714
-							}
1715
-						}
1716
-						else
1717
-						{
1718
-							// line with batch detail
1719
-
1720
-							// 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
1721
-							$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionUnClassifyCloseddInDolibarr",$numref),  $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
1722
-							if ($result < 0) {
1723
-							    $this->error = $mouvS->error;
1724
-							    $this->errors = $mouvS->errors;
1725
-							    $error++; break;
1726
-							}
1727
-						}
1728
-					}
1729
-				}
1730
-				else
1731
-				{
1732
-					$this->error=$this->db->lasterror();
1733
-					$error++;
1734
-				}
1735
-			}
1736
-
1737
-			if (! $error)
1738
-			{
1739
-    			// Call trigger
1740
-    			$result=$this->call_trigger('RECEPTION_REOPEN',$user);
1741
-    			if ($result < 0) {
1742
-    				$error++;
1743
-    			}
1744
-   			}
1745
-
1746
-			if($this->origin == 'order_supplier'){
1747
-				$commande = new CommandeFournisseur($this->db);
1748
-				$commande->fetch($this->origin_id);
1749
-				$commande->setStatus($user,4);
1750
-			}
1751
-		} else {
1752
-			$error++;
1753
-			$this->errors[]=$this->db->lasterror();
1754
-		}
1755
-
1756
-		if (! $error)
1757
-		{
1758
-			$this->db->commit();
1759
-			return 1;
1760
-		}
1761
-		else
1762
-		{
1763
-			$this->db->rollback();
1764
-			return -1;
1765
-		}
1766
-	}
1601
+    /**
1602
+     *	Classify the reception as invoiced (used when WORKFLOW_BILL_ON_RECEPTION is on)
1603
+     *
1604
+     *	@return     int     <0 if ko, >0 if ok
1605
+     */
1606
+    function set_billed()
1607
+    {
1608
+        // phpcs:enable
1609
+        global $user;
1610
+        $error=0;
1767 1611
 
1612
+        $this->db->begin();
1768 1613
 
1769
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1770
-	 /**
1771
-     *	Set draft status
1614
+        $this->setClosed();
1615
+
1616
+        $sql = 'UPDATE '.MAIN_DB_PREFIX.'reception SET  billed=1';
1617
+        $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0';
1618
+
1619
+        $resql=$this->db->query($sql);
1620
+        if ($resql)
1621
+        {
1622
+            $this->statut=2;
1623
+            $this->billed=1;
1624
+
1625
+            // Call trigger
1626
+            $result=$this->call_trigger('RECEPTION_BILLED',$user);
1627
+            if ($result < 0) {
1628
+                $error++;
1629
+            }
1630
+        } else {
1631
+            $error++;
1632
+            $this->errors[]=$this->db->lasterror;
1633
+        }
1634
+
1635
+        if (empty($error)) {
1636
+            $this->db->commit();
1637
+            return 1;
1638
+        }
1639
+        else
1640
+        {
1641
+            $this->db->rollback();
1642
+            return -1;
1643
+        }
1644
+    }
1645
+
1646
+    /**
1647
+     *	Classify the reception as validated/opened
1772 1648
      *
1773
-     *	@param	User	$user			Object user that modify
1774
-     *	@return	int						<0 if KO, >0 if OK
1649
+     *	@return     int     <0 if ko, >0 if ok
1775 1650
      */
1651
+    function reOpen()
1652
+    {
1653
+        global $conf,$langs,$user;
1654
+
1655
+        $error=0;
1656
+
1657
+        $this->db->begin();
1658
+
1659
+        $sql = 'UPDATE '.MAIN_DB_PREFIX.'reception SET fk_statut=1, billed=0';
1660
+        $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0';
1661
+
1662
+        $resql=$this->db->query($sql);
1663
+        if ($resql)
1664
+        {
1665
+            $this->statut=1;
1666
+            $this->billed=0;
1667
+
1668
+            // If stock increment is done on closing
1669
+            if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))
1670
+            {
1671
+                require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
1672
+                $numref = $this->ref;
1673
+                $langs->load("agenda");
1674
+
1675
+                // Loop on each product line to add a stock movement
1676
+                // TODO possibilite de receptionner a partir d'une propale ou autre origine
1677
+                $sql = "SELECT ed.fk_product, cd.subprice,";
1678
+                $sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
1679
+                $sql.= " ed.eatby, ed.sellby, ed.batch";
1680
+                $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
1681
+                $sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
1682
+                $sql.= " WHERE ed.fk_reception = ".$this->id;
1683
+                $sql.= " AND cd.rowid = ed.fk_commandefourndet";
1684
+
1685
+                dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
1686
+                $resql=$this->db->query($sql);
1687
+                if ($resql)
1688
+                {
1689
+                    $cpt = $this->db->num_rows($resql);
1690
+                    for ($i = 0; $i < $cpt; $i++)
1691
+                    {
1692
+                        $obj = $this->db->fetch_object($resql);
1693
+
1694
+                        $qty = $obj->qty;
1695
+
1696
+                        if ($qty <= 0) continue;
1697
+
1698
+                        dol_syslog(get_class($this)."::reopen reception movement index ".$i." ed.rowid=".$obj->rowid);
1699
+
1700
+                        //var_dump($this->lines[$i]);
1701
+                        $mouvS = new MouvementStock($this->db);
1702
+                        $mouvS->origin = &$this;
1703
+
1704
+                        if (empty($obj->batch))
1705
+                        {
1706
+                            // line without batch detail
1707
+
1708
+                            // 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
1709
+                            $result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionUnClassifyCloseddInDolibarr",$numref));
1710
+                            if ($result < 0) {
1711
+                                $this->error = $mouvS->error;
1712
+                                $this->errors = $mouvS->errors;
1713
+                                $error++; break;
1714
+                            }
1715
+                        }
1716
+                        else
1717
+                        {
1718
+                            // line with batch detail
1719
+
1720
+                            // 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
1721
+                            $result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionUnClassifyCloseddInDolibarr",$numref),  $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
1722
+                            if ($result < 0) {
1723
+                                $this->error = $mouvS->error;
1724
+                                $this->errors = $mouvS->errors;
1725
+                                $error++; break;
1726
+                            }
1727
+                        }
1728
+                    }
1729
+                }
1730
+                else
1731
+                {
1732
+                    $this->error=$this->db->lasterror();
1733
+                    $error++;
1734
+                }
1735
+            }
1736
+
1737
+            if (! $error)
1738
+            {
1739
+                // Call trigger
1740
+                $result=$this->call_trigger('RECEPTION_REOPEN',$user);
1741
+                if ($result < 0) {
1742
+                    $error++;
1743
+                }
1744
+                }
1745
+
1746
+            if($this->origin == 'order_supplier'){
1747
+                $commande = new CommandeFournisseur($this->db);
1748
+                $commande->fetch($this->origin_id);
1749
+                $commande->setStatus($user,4);
1750
+            }
1751
+        } else {
1752
+            $error++;
1753
+            $this->errors[]=$this->db->lasterror();
1754
+        }
1755
+
1756
+        if (! $error)
1757
+        {
1758
+            $this->db->commit();
1759
+            return 1;
1760
+        }
1761
+        else
1762
+        {
1763
+            $this->db->rollback();
1764
+            return -1;
1765
+        }
1766
+    }
1767
+
1768
+
1769
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1770
+        /**
1771
+         *	Set draft status
1772
+         *
1773
+         *	@param	User	$user			Object user that modify
1774
+         *	@return	int						<0 if KO, >0 if OK
1775
+         */
1776 1776
     function set_draft($user)
1777 1777
     {
1778
-		// phpcs:enable
1778
+        // phpcs:enable
1779 1779
         global $conf,$langs;
1780 1780
 
1781 1781
         $error=0;
@@ -1787,7 +1787,7 @@  discard block
 block discarded – undo
1787 1787
         }
1788 1788
 
1789 1789
         if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->creer))
1790
-       	|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->reception_advance->validate))))
1790
+           || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->reception_advance->validate))))
1791 1791
         {
1792 1792
             $this->error='Permission denied';
1793 1793
             return -1;
@@ -1803,118 +1803,118 @@  discard block
 block discarded – undo
1803 1803
         if ($this->db->query($sql))
1804 1804
         {
1805 1805
             // If stock increment is done on closing
1806
-			if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION))
1807
-			{
1808
-				require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
1809
-
1810
-				$langs->load("agenda");
1811
-
1812
-				// Loop on each product line to add a stock movement
1813
-				// TODO possibilite de receptionner a partir d'une propale ou autre origine
1814
-				$sql = "SELECT cd.fk_product, cd.subprice,";
1815
-				$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
1816
-				$sql.= " ed.eatby, ed.sellby, ed.batch";
1817
-				$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
1818
-				$sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
1819
-				$sql.= " WHERE ed.fk_reception = ".$this->id;
1820
-				$sql.= " AND cd.rowid = ed.fk_commandefourndet";
1821
-
1822
-				dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
1823
-				$resql=$this->db->query($sql);
1824
-				if ($resql)
1825
-				{
1826
-					$cpt = $this->db->num_rows($resql);
1827
-					for ($i = 0; $i < $cpt; $i++)
1828
-					{
1829
-						$obj = $this->db->fetch_object($resql);
1830
-
1831
-						$qty = $obj->qty;
1832
-
1833
-
1834
-						if ($qty <= 0) continue;
1835
-						dol_syslog(get_class($this)."::reopen reception movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid);
1836
-
1837
-						//var_dump($this->lines[$i]);
1838
-						$mouvS = new MouvementStock($this->db);
1839
-						$mouvS->origin = &$this;
1840
-
1841
-						if (empty($obj->batch))
1842
-						{
1843
-							// line without batch detail
1844
-
1845
-							// 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
1846
-							$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionBackToDraftInDolibarr",$this->ref));
1847
-							if ($result < 0) {
1848
-							    $this->error = $mouvS->error;
1849
-							    $this->errors = $mouvS->errors;
1850
-								$error++;
1851
-								break;
1852
-							}
1853
-						}
1854
-						else
1855
-						{
1856
-							// line with batch detail
1857
-
1858
-							// 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
1859
-							$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionBackToDraftInDolibarr",$this->ref),  $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch);
1860
-							if ($result < 0) {
1861
-							    $this->error = $mouvS->error;
1862
-							    $this->errors = $mouvS->errors;
1863
-							    $error++; break;
1864
-							}
1865
-						}
1866
-					}
1867
-				}
1868
-				else
1869
-				{
1870
-					$this->error=$this->db->lasterror();
1871
-					$error++;
1872
-				}
1873
-			}
1806
+            if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION))
1807
+            {
1808
+                require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
1809
+
1810
+                $langs->load("agenda");
1811
+
1812
+                // Loop on each product line to add a stock movement
1813
+                // TODO possibilite de receptionner a partir d'une propale ou autre origine
1814
+                $sql = "SELECT cd.fk_product, cd.subprice,";
1815
+                $sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
1816
+                $sql.= " ed.eatby, ed.sellby, ed.batch";
1817
+                $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
1818
+                $sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
1819
+                $sql.= " WHERE ed.fk_reception = ".$this->id;
1820
+                $sql.= " AND cd.rowid = ed.fk_commandefourndet";
1821
+
1822
+                dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
1823
+                $resql=$this->db->query($sql);
1824
+                if ($resql)
1825
+                {
1826
+                    $cpt = $this->db->num_rows($resql);
1827
+                    for ($i = 0; $i < $cpt; $i++)
1828
+                    {
1829
+                        $obj = $this->db->fetch_object($resql);
1830
+
1831
+                        $qty = $obj->qty;
1832
+
1833
+
1834
+                        if ($qty <= 0) continue;
1835
+                        dol_syslog(get_class($this)."::reopen reception movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid);
1836
+
1837
+                        //var_dump($this->lines[$i]);
1838
+                        $mouvS = new MouvementStock($this->db);
1839
+                        $mouvS->origin = &$this;
1840
+
1841
+                        if (empty($obj->batch))
1842
+                        {
1843
+                            // line without batch detail
1844
+
1845
+                            // 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
1846
+                            $result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionBackToDraftInDolibarr",$this->ref));
1847
+                            if ($result < 0) {
1848
+                                $this->error = $mouvS->error;
1849
+                                $this->errors = $mouvS->errors;
1850
+                                $error++;
1851
+                                break;
1852
+                            }
1853
+                        }
1854
+                        else
1855
+                        {
1856
+                            // line with batch detail
1857
+
1858
+                            // 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
1859
+                            $result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionBackToDraftInDolibarr",$this->ref),  $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch);
1860
+                            if ($result < 0) {
1861
+                                $this->error = $mouvS->error;
1862
+                                $this->errors = $mouvS->errors;
1863
+                                $error++; break;
1864
+                            }
1865
+                        }
1866
+                    }
1867
+                }
1868
+                else
1869
+                {
1870
+                    $this->error=$this->db->lasterror();
1871
+                    $error++;
1872
+                }
1873
+            }
1874 1874
 
1875 1875
             if (!$error) {
1876
-            	// Call trigger
1877
-            	$result=$this->call_trigger('RECEPTION_UNVALIDATE',$user);
1878
-            	if ($result < 0) $error++;
1876
+                // Call trigger
1877
+                $result=$this->call_trigger('RECEPTION_UNVALIDATE',$user);
1878
+                if ($result < 0) $error++;
1879
+            }
1880
+            if ($this->origin == 'order_supplier')
1881
+            {
1882
+                if (!empty($this->origin) && $this->origin_id > 0)
1883
+                {
1884
+                    $this->fetch_origin();
1885
+                    $origin = $this->origin;
1886
+                    if ($this->$origin->statut == 4)  // If order source of reception is "partially received"
1887
+                    {
1888
+                        // Check if there is no more reception validated.
1889
+                        $this->$origin->fetchObjectLinked();
1890
+                        $setStatut = 1;
1891
+                        if (!empty($this->$origin->linkedObjects['reception']))
1892
+                        {
1893
+                            foreach ($this->$origin->linkedObjects['reception'] as $rcption)
1894
+                            {
1895
+                                if ($rcption->statut > 0)
1896
+                                {
1897
+                                    $setStatut = 0;
1898
+                                    break;
1899
+                                }
1900
+                            }
1901
+                            //var_dump($this->$origin->receptions);exit;
1902
+                            if ($setStatut)
1903
+                            {
1904
+                                $this->$origin->setStatut(3); // ordered
1905
+                            }
1906
+                        }
1907
+                    }
1908
+                }
1879 1909
             }
1880
-			if ($this->origin == 'order_supplier')
1881
-			{
1882
-				if (!empty($this->origin) && $this->origin_id > 0)
1883
-				{
1884
-					$this->fetch_origin();
1885
-					$origin = $this->origin;
1886
-					if ($this->$origin->statut == 4)  // If order source of reception is "partially received"
1887
-					{
1888
-						// Check if there is no more reception validated.
1889
-						$this->$origin->fetchObjectLinked();
1890
-						$setStatut = 1;
1891
-						if (!empty($this->$origin->linkedObjects['reception']))
1892
-						{
1893
-							foreach ($this->$origin->linkedObjects['reception'] as $rcption)
1894
-							{
1895
-								if ($rcption->statut > 0)
1896
-								{
1897
-									$setStatut = 0;
1898
-									break;
1899
-								}
1900
-							}
1901
-							//var_dump($this->$origin->receptions);exit;
1902
-							if ($setStatut)
1903
-							{
1904
-								$this->$origin->setStatut(3); // ordered
1905
-							}
1906
-						}
1907
-					}
1908
-				}
1909
-			}
1910
-
1911
-			if (!$error) {
1912
-           		$this->statut=self::STATUS_DRAFT;
1913
-            	$this->db->commit();
1914
-            	return 1;
1910
+
1911
+            if (!$error) {
1912
+                    $this->statut=self::STATUS_DRAFT;
1913
+                $this->db->commit();
1914
+                return 1;
1915 1915
             }else {
1916
-            	$this->db->rollback();
1917
-            	return -1;
1916
+                $this->db->rollback();
1917
+                return -1;
1918 1918
             }
1919 1919
         }
1920 1920
         else
@@ -1925,52 +1925,52 @@  discard block
 block discarded – undo
1925 1925
         }
1926 1926
     }
1927 1927
 
1928
-	/**
1929
-	 *  Create a document onto disk according to template module.
1930
-	 *
1931
-	 *  @param	    string		$modele			Force the model to using ('' to not force)
1932
-	 *  @param		Translate	$outputlangs	object lang to use for translations
1933
-	 *  @param      int			$hidedetails    Hide details of lines
1934
-	 *  @param      int			$hidedesc       Hide description
1935
-	 *  @param      int			$hideref        Hide ref
1936
-	 *  @return     int         				0 if KO, 1 if OK
1937
-	 */
1938
-	public function generateDocument($modele, $outputlangs,$hidedetails=0, $hidedesc=0, $hideref=0)
1939
-	{
1940
-		global $conf,$langs;
1941
-
1942
-		$langs->load("receptions");
1943
-
1944
-		if (! dol_strlen($modele))
1945
-		{
1946
-			$modele = 'squille';
1947
-
1948
-			if ($this->modelpdf) {
1949
-				$modele = $this->modelpdf;
1950
-			} elseif (! empty($conf->global->RECEPTION_ADDON_PDF)) {
1951
-				$modele = $conf->global->RECEPTION_ADDON_PDF;
1952
-			}
1953
-		}
1954
-
1955
-		$modelpath = "core/modules/reception/doc/";
1956
-
1957
-		$this->fetch_origin();
1958
-
1959
-		return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1960
-	}
1961
-
1962
-	/**
1963
-	 * Function used to replace a thirdparty id with another one.
1964
-	 *
1965
-	 * @param DoliDB $db Database handler
1966
-	 * @param int $origin_id Old thirdparty id
1967
-	 * @param int $dest_id New thirdparty id
1968
-	 * @return bool
1969
-	 */
1970
-	public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
1971
-	{
1972
-		$tables = array('reception');
1973
-
1974
-		return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
1975
-	}
1928
+    /**
1929
+     *  Create a document onto disk according to template module.
1930
+     *
1931
+     *  @param	    string		$modele			Force the model to using ('' to not force)
1932
+     *  @param		Translate	$outputlangs	object lang to use for translations
1933
+     *  @param      int			$hidedetails    Hide details of lines
1934
+     *  @param      int			$hidedesc       Hide description
1935
+     *  @param      int			$hideref        Hide ref
1936
+     *  @return     int         				0 if KO, 1 if OK
1937
+     */
1938
+    public function generateDocument($modele, $outputlangs,$hidedetails=0, $hidedesc=0, $hideref=0)
1939
+    {
1940
+        global $conf,$langs;
1941
+
1942
+        $langs->load("receptions");
1943
+
1944
+        if (! dol_strlen($modele))
1945
+        {
1946
+            $modele = 'squille';
1947
+
1948
+            if ($this->modelpdf) {
1949
+                $modele = $this->modelpdf;
1950
+            } elseif (! empty($conf->global->RECEPTION_ADDON_PDF)) {
1951
+                $modele = $conf->global->RECEPTION_ADDON_PDF;
1952
+            }
1953
+        }
1954
+
1955
+        $modelpath = "core/modules/reception/doc/";
1956
+
1957
+        $this->fetch_origin();
1958
+
1959
+        return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1960
+    }
1961
+
1962
+    /**
1963
+     * Function used to replace a thirdparty id with another one.
1964
+     *
1965
+     * @param DoliDB $db Database handler
1966
+     * @param int $origin_id Old thirdparty id
1967
+     * @param int $dest_id New thirdparty id
1968
+     * @return bool
1969
+     */
1970
+    public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
1971
+    {
1972
+        $tables = array('reception');
1973
+
1974
+        return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
1975
+    }
1976 1976
 }
1977 1977
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +417 added lines, -417 removed lines patch added patch discarded remove patch
@@ -34,8 +34,8 @@  discard block
 block discarded – undo
34 34
 
35 35
 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
36 36
 require_once DOL_DOCUMENT_ROOT."/core/class/commonobjectline.class.php";
37
-if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
38
-if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
37
+if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
38
+if (!empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
39 39
 
40 40
 
41 41
 /**
@@ -43,11 +43,11 @@  discard block
 block discarded – undo
43 43
  */
44 44
 class Reception extends CommonObject
45 45
 {
46
-	public $element="reception";
47
-	public $fk_element="fk_reception";
48
-	public $table_element="reception";
49
-	public $table_element_line="commande_fournisseur_dispatch";
50
-	protected $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
46
+	public $element = "reception";
47
+	public $fk_element = "fk_reception";
48
+	public $table_element = "reception";
49
+	public $table_element_line = "commande_fournisseur_dispatch";
50
+	protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
51 51
     public $picto = 'reception';
52 52
 
53 53
 	var $socid;
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	var $ref_int;
56 56
 	var $brouillon;
57 57
 	var $entrepot_id;
58
-	var $lines=array();
58
+	var $lines = array();
59 59
 	var $tracking_number;
60 60
 	var $tracking_url;
61 61
 	var $billed;
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	// A denormalized value
73 73
 	var $trueSize;
74 74
 
75
-	var $date_delivery;		// Date delivery planed
75
+	var $date_delivery; // Date delivery planed
76 76
 
77 77
 
78 78
 	/**
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	var $date_valid;
85 85
 
86 86
 	var $meths;
87
-	var $listmeths;			// List of carriers
87
+	var $listmeths; // List of carriers
88 88
 
89 89
 
90 90
 	const STATUS_DRAFT = 0;
@@ -138,27 +138,27 @@  discard block
 block discarded – undo
138 138
 		        $dir = dol_buildpath($reldir."core/modules/reception/");
139 139
 
140 140
 		        // Load file with numbering class (if found)
141
-		        $mybool|=@include_once $dir.$file;
141
+		        $mybool |= @include_once $dir.$file;
142 142
 	        }
143 143
 
144
-	        if (! $mybool)
144
+	        if (!$mybool)
145 145
 	        {
146
-		        dol_print_error('',"Failed to include file ".$file);
146
+		        dol_print_error('', "Failed to include file ".$file);
147 147
 		        return '';
148 148
 	        }
149 149
 
150 150
 			$obj = new $classname();
151 151
 
152 152
 			$numref = "";
153
-			$numref = $obj->getNextValue($soc,$this);
153
+			$numref = $obj->getNextValue($soc, $this);
154 154
 
155
-			if ( $numref != "")
155
+			if ($numref != "")
156 156
 			{
157 157
 				return $numref;
158 158
 			}
159 159
 			else
160 160
 			{
161
-				dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
161
+				dol_print_error($this->db, get_class($this)."::getNextNumRef ".$obj->error);
162 162
 				return "";
163 163
 			}
164 164
         }
@@ -176,13 +176,13 @@  discard block
 block discarded – undo
176 176
 	 *  @param	int		$notrigger	1=Does not execute triggers, 0= execute triggers
177 177
 	 *  @return int 				<0 si erreur, id reception creee si ok
178 178
 	 */
179
-	function create($user, $notrigger=0)
179
+	function create($user, $notrigger = 0)
180 180
 	{
181 181
 		global $conf, $hookmanager;
182 182
 
183
-		$now=dol_now();
183
+		$now = dol_now();
184 184
 
185
-		require_once DOL_DOCUMENT_ROOT .'/product/stock/class/mouvementstock.class.php';
185
+		require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
186 186
 		$error = 0;
187 187
 
188 188
 		// Clean parameters
@@ -196,82 +196,82 @@  discard block
 block discarded – undo
196 196
 		$this->db->begin();
197 197
 
198 198
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."reception (";
199
-		$sql.= "ref";
200
-		$sql.= ", entity";
201
-		$sql.= ", ref_supplier";
202
-		$sql.= ", ref_int";
203
-		$sql.= ", date_creation";
204
-		$sql.= ", fk_user_author";
205
-		$sql.= ", date_reception";
206
-		$sql.= ", date_delivery";
207
-		$sql.= ", fk_soc";
208
-		$sql.= ", fk_projet";
209
-		$sql.= ", fk_shipping_method";
210
-		$sql.= ", tracking_number";
211
-		$sql.= ", weight";
212
-		$sql.= ", size";
213
-		$sql.= ", width";
214
-		$sql.= ", height";
215
-		$sql.= ", weight_units";
216
-		$sql.= ", size_units";
217
-		$sql.= ", note_private";
218
-		$sql.= ", note_public";
219
-		$sql.= ", model_pdf";
220
-		$sql.= ", fk_incoterms, location_incoterms";
221
-		$sql.= ") VALUES (";
222
-		$sql.= "'(PROV)'";
223
-		$sql.= ", ".$conf->entity;
224
-		$sql.= ", ".($this->ref_supplier?"'".$this->db->escape($this->ref_supplier)."'":"null");
225
-		$sql.= ", ".($this->ref_int?"'".$this->db->escape($this->ref_int)."'":"null");
226
-		$sql.= ", '".$this->db->idate($now)."'";
227
-		$sql.= ", ".$user->id;
228
-		$sql.= ", ".($this->date_reception>0?"'".$this->db->idate($this->date_reception)."'":"null");
229
-		$sql.= ", ".($this->date_delivery>0?"'".$this->db->idate($this->date_delivery)."'":"null");
230
-		$sql.= ", ".$this->socid;
231
-		$sql.= ", ".$this->fk_project;
232
-		$sql.= ", ".($this->shipping_method_id>0?$this->shipping_method_id:"null");
233
-		$sql.= ", '".$this->db->escape($this->tracking_number)."'";
234
-		$sql.= ", ".$this->weight;
235
-		$sql.= ", ".$this->sizeS;	// TODO Should use this->trueDepth
236
-		$sql.= ", ".$this->sizeW;	// TODO Should use this->trueWidth
237
-		$sql.= ", ".$this->sizeH;	// TODO Should use this->trueHeight
238
-		$sql.= ", ".$this->weight_units;
239
-		$sql.= ", ".$this->size_units;
240
-		$sql.= ", ".(!empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null");
241
-		$sql.= ", ".(!empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null");
242
-		$sql.= ", ".(!empty($this->model_pdf)?"'".$this->db->escape($this->model_pdf)."'":"null");
243
-        $sql.= ", ".(int) $this->fk_incoterms;
244
-        $sql.= ", '".$this->db->escape($this->location_incoterms)."'";
245
-		$sql.= ")";
199
+		$sql .= "ref";
200
+		$sql .= ", entity";
201
+		$sql .= ", ref_supplier";
202
+		$sql .= ", ref_int";
203
+		$sql .= ", date_creation";
204
+		$sql .= ", fk_user_author";
205
+		$sql .= ", date_reception";
206
+		$sql .= ", date_delivery";
207
+		$sql .= ", fk_soc";
208
+		$sql .= ", fk_projet";
209
+		$sql .= ", fk_shipping_method";
210
+		$sql .= ", tracking_number";
211
+		$sql .= ", weight";
212
+		$sql .= ", size";
213
+		$sql .= ", width";
214
+		$sql .= ", height";
215
+		$sql .= ", weight_units";
216
+		$sql .= ", size_units";
217
+		$sql .= ", note_private";
218
+		$sql .= ", note_public";
219
+		$sql .= ", model_pdf";
220
+		$sql .= ", fk_incoterms, location_incoterms";
221
+		$sql .= ") VALUES (";
222
+		$sql .= "'(PROV)'";
223
+		$sql .= ", ".$conf->entity;
224
+		$sql .= ", ".($this->ref_supplier ? "'".$this->db->escape($this->ref_supplier)."'" : "null");
225
+		$sql .= ", ".($this->ref_int ? "'".$this->db->escape($this->ref_int)."'" : "null");
226
+		$sql .= ", '".$this->db->idate($now)."'";
227
+		$sql .= ", ".$user->id;
228
+		$sql .= ", ".($this->date_reception > 0 ? "'".$this->db->idate($this->date_reception)."'" : "null");
229
+		$sql .= ", ".($this->date_delivery > 0 ? "'".$this->db->idate($this->date_delivery)."'" : "null");
230
+		$sql .= ", ".$this->socid;
231
+		$sql .= ", ".$this->fk_project;
232
+		$sql .= ", ".($this->shipping_method_id > 0 ? $this->shipping_method_id : "null");
233
+		$sql .= ", '".$this->db->escape($this->tracking_number)."'";
234
+		$sql .= ", ".$this->weight;
235
+		$sql .= ", ".$this->sizeS; // TODO Should use this->trueDepth
236
+		$sql .= ", ".$this->sizeW; // TODO Should use this->trueWidth
237
+		$sql .= ", ".$this->sizeH; // TODO Should use this->trueHeight
238
+		$sql .= ", ".$this->weight_units;
239
+		$sql .= ", ".$this->size_units;
240
+		$sql .= ", ".(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null");
241
+		$sql .= ", ".(!empty($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null");
242
+		$sql .= ", ".(!empty($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null");
243
+        $sql .= ", ".(int) $this->fk_incoterms;
244
+        $sql .= ", '".$this->db->escape($this->location_incoterms)."'";
245
+		$sql .= ")";
246 246
 
247 247
 		dol_syslog(get_class($this)."::create", LOG_DEBUG);
248 248
 
249
-		$resql=$this->db->query($sql);
249
+		$resql = $this->db->query($sql);
250 250
 
251 251
 		if ($resql)
252 252
 		{
253 253
 			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."reception");
254 254
 
255 255
 			$sql = "UPDATE ".MAIN_DB_PREFIX."reception";
256
-			$sql.= " SET ref = '(PROV".$this->id.")'";
257
-			$sql.= " WHERE rowid = ".$this->id;
256
+			$sql .= " SET ref = '(PROV".$this->id.")'";
257
+			$sql .= " WHERE rowid = ".$this->id;
258 258
 
259 259
 			dol_syslog(get_class($this)."::create", LOG_DEBUG);
260 260
 			if ($this->db->query($sql))
261 261
 			{
262 262
 				// Insertion des lignes
263
-				$num=count($this->lines);
263
+				$num = count($this->lines);
264 264
 				for ($i = 0; $i < $num; $i++)
265 265
 				{
266 266
 					$this->lines[$i]->fk_reception = $this->id;
267 267
 
268
-					if (! $this->lines[$i]->create($user) > 0)
268
+					if (!$this->lines[$i]->create($user) > 0)
269 269
 					{
270 270
 						$error++;
271 271
 					}
272 272
 				}
273 273
 
274
-				if (! $error && $this->id && $this->origin_id)
274
+				if (!$error && $this->id && $this->origin_id)
275 275
 				{
276 276
 					$ret = $this->add_object_linked();
277 277
 					if (!$ret)
@@ -282,15 +282,15 @@  discard block
 block discarded – undo
282 282
 
283 283
 				// Actions on extra fields (by external module or standard code)
284 284
 				// TODO le hook fait double emploi avec le trigger !!
285
-				$action='add';
285
+				$action = 'add';
286 286
 				$hookmanager->initHooks(array('receptiondao'));
287
-				$parameters=array('socid'=>$this->id);
288
-				$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
287
+				$parameters = array('socid'=>$this->id);
288
+				$reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
289 289
 				if (empty($reshook))
290 290
 				{
291 291
 					if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
292 292
 					{
293
-						$result=$this->insertExtraFields();
293
+						$result = $this->insertExtraFields();
294 294
 						if ($result < 0)
295 295
 						{
296 296
 							$error++;
@@ -299,33 +299,33 @@  discard block
 block discarded – undo
299 299
 				}
300 300
 				else if ($reshook < 0) $error++;
301 301
 
302
-				if (! $error && ! $notrigger)
302
+				if (!$error && !$notrigger)
303 303
 				{
304 304
                     // Call trigger
305
-                    $result=$this->call_trigger('RECEPTION_CREATE',$user);
305
+                    $result = $this->call_trigger('RECEPTION_CREATE', $user);
306 306
                     if ($result < 0) { $error++; }
307 307
                     // End call triggers
308 308
 
309
-					if (! $error)
309
+					if (!$error)
310 310
 					{
311 311
 						$this->db->commit();
312 312
 						return $this->id;
313 313
 					}
314 314
 					else
315 315
 					{
316
-						foreach($this->errors as $errmsg)
316
+						foreach ($this->errors as $errmsg)
317 317
 						{
318 318
 							dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
319
-							$this->error.=($this->error?', '.$errmsg:$errmsg);
319
+							$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
320 320
 						}
321 321
 						$this->db->rollback();
322
-						return -1*$error;
322
+						return -1 * $error;
323 323
 					}
324 324
 				}
325 325
 				else
326 326
 				{
327 327
 					$error++;
328
-					$this->error=$this->db->lasterror()." - sql=$sql";
328
+					$this->error = $this->db->lasterror()." - sql=$sql";
329 329
 					$this->db->rollback();
330 330
 					return -3;
331 331
 				}
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 			else
334 334
 			{
335 335
 				$error++;
336
-				$this->error=$this->db->lasterror()." - sql=$sql";
336
+				$this->error = $this->db->lasterror()." - sql=$sql";
337 337
 				$this->db->rollback();
338 338
 				return -2;
339 339
 			}
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 		else
342 342
 		{
343 343
 			$error++;
344
-			$this->error=$this->db->error()." - sql=$sql";
344
+			$this->error = $this->db->error()." - sql=$sql";
345 345
 			$this->db->rollback();
346 346
 			return -1;
347 347
 		}
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
      * 	@param	string	$ref_int	Internal reference of other object
359 359
 	 *	@return int			        >0 if OK, 0 if not found, <0 if KO
360 360
 	 */
361
-	function fetch($id, $ref='', $ref_ext='', $ref_int='')
361
+	function fetch($id, $ref = '', $ref_ext = '', $ref_int = '')
362 362
 	{
363 363
 		global $conf;
364 364
 
@@ -366,21 +366,21 @@  discard block
 block discarded – undo
366 366
 		if (empty($id) && empty($ref) && empty($ref_ext) && empty($ref_int)) return -1;
367 367
 
368 368
 		$sql = "SELECT e.rowid, e.ref, e.fk_soc as socid, e.date_creation, e.ref_supplier, e.ref_ext, e.ref_int, e.fk_user_author, e.fk_statut";
369
-		$sql.= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
370
-		$sql.= ", e.date_reception as date_reception, e.model_pdf,  e.date_delivery";
371
-		$sql.= ", e.fk_shipping_method, e.tracking_number";
372
-		$sql.= ", el.fk_source as origin_id, el.sourcetype as origin";
373
-		$sql.= ", e.note_private, e.note_public";
374
-        $sql.= ', e.fk_incoterms, e.location_incoterms';
375
-        $sql.= ', i.libelle as libelle_incoterms';
376
-		$sql.= " FROM ".MAIN_DB_PREFIX."reception as e";
377
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element)."'";
378
-		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON e.fk_incoterms = i.rowid';
379
-		$sql.= " WHERE e.entity IN (".getEntity('reception').")";
380
-		if ($id)   	  $sql.= " AND e.rowid=".$id;
381
-        if ($ref)     $sql.= " AND e.ref='".$this->db->escape($ref)."'";
382
-        if ($ref_ext) $sql.= " AND e.ref_ext='".$this->db->escape($ref_ext)."'";
383
-        if ($ref_int) $sql.= " AND e.ref_int='".$this->db->escape($ref_int)."'";
369
+		$sql .= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
370
+		$sql .= ", e.date_reception as date_reception, e.model_pdf,  e.date_delivery";
371
+		$sql .= ", e.fk_shipping_method, e.tracking_number";
372
+		$sql .= ", el.fk_source as origin_id, el.sourcetype as origin";
373
+		$sql .= ", e.note_private, e.note_public";
374
+        $sql .= ', e.fk_incoterms, e.location_incoterms';
375
+        $sql .= ', i.libelle as libelle_incoterms';
376
+		$sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
377
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element)."'";
378
+		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON e.fk_incoterms = i.rowid';
379
+		$sql .= " WHERE e.entity IN (".getEntity('reception').")";
380
+		if ($id)   	  $sql .= " AND e.rowid=".$id;
381
+        if ($ref)     $sql .= " AND e.ref='".$this->db->escape($ref)."'";
382
+        if ($ref_ext) $sql .= " AND e.ref_ext='".$this->db->escape($ref_ext)."'";
383
+        if ($ref_int) $sql .= " AND e.ref_int='".$this->db->escape($ref_int)."'";
384 384
 
385 385
 		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
386 386
 		$result = $this->db->query($sql);
@@ -393,23 +393,23 @@  discard block
 block discarded – undo
393 393
 				$this->id                   = $obj->rowid;
394 394
 				$this->ref                  = $obj->ref;
395 395
 				$this->socid                = $obj->socid;
396
-				$this->ref_supplier			= $obj->ref_supplier;
396
+				$this->ref_supplier = $obj->ref_supplier;
397 397
 				$this->ref_ext				= $obj->ref_ext;
398 398
 				$this->ref_int				= $obj->ref_int;
399 399
 				$this->statut               = $obj->fk_statut;
400 400
 				$this->user_author_id       = $obj->fk_user_author;
401 401
 				$this->date_creation        = $this->db->jdate($obj->date_creation);
402
-				$this->date                 = $this->db->jdate($obj->date_reception);	// TODO deprecated
403
-				$this->date_reception      = $this->db->jdate($obj->date_reception);	// TODO deprecated
404
-				$this->date_reception        = $this->db->jdate($obj->date_reception);	// Date real
405
-				$this->date_delivery        = $this->db->jdate($obj->date_delivery);	// Date planed
402
+				$this->date                 = $this->db->jdate($obj->date_reception); // TODO deprecated
403
+				$this->date_reception = $this->db->jdate($obj->date_reception); // TODO deprecated
404
+				$this->date_reception = $this->db->jdate($obj->date_reception); // Date real
405
+				$this->date_delivery        = $this->db->jdate($obj->date_delivery); // Date planed
406 406
 				$this->fk_delivery_address  = $obj->fk_address;
407 407
 				$this->modelpdf             = $obj->model_pdf;
408
-				$this->shipping_method_id	= $obj->fk_shipping_method;
408
+				$this->shipping_method_id = $obj->fk_shipping_method;
409 409
 				$this->tracking_number      = $obj->tracking_number;
410
-				$this->origin               = ($obj->origin?$obj->origin:'commande'); // For compatibility
410
+				$this->origin               = ($obj->origin ? $obj->origin : 'commande'); // For compatibility
411 411
 				$this->origin_id            = $obj->origin_id;
412
-				$this->billed				= ($obj->fk_statut==2?1:0);
412
+				$this->billed = ($obj->fk_statut == 2 ? 1 : 0);
413 413
 
414 414
 				$this->trueWeight           = $obj->weight;
415 415
 				$this->weight_units         = $obj->weight_units;
@@ -425,8 +425,8 @@  discard block
 block discarded – undo
425 425
 				$this->note_private         = $obj->note_private;
426 426
 
427 427
 				// A denormalized value
428
-				$this->trueSize           	= $obj->size."x".$obj->width."x".$obj->height;
429
-				$this->size_units           = $obj->size_units;
428
+				$this->trueSize = $obj->size."x".$obj->width."x".$obj->height;
429
+				$this->size_units = $obj->size_units;
430 430
 
431 431
 				//Incoterms
432 432
 				$this->fk_incoterms = $obj->fk_incoterms;
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 
438 438
 				if ($this->statut == 0) $this->brouillon = 1;
439 439
 
440
-				$file = $conf->reception->dir_output . "/" .get_exdir($this->id, 2, 0, 0, $this, 'reception') . "/" . $this->id.".pdf";
440
+				$file = $conf->reception->dir_output."/".get_exdir($this->id, 2, 0, 0, $this, 'reception')."/".$this->id.".pdf";
441 441
 				$this->pdf_filename = $file;
442 442
 
443 443
 				// Tracking url
@@ -446,20 +446,20 @@  discard block
 block discarded – undo
446 446
 				/*
447 447
 				 * Thirparty
448 448
 				 */
449
-				$result=$this->fetch_thirdparty();
449
+				$result = $this->fetch_thirdparty();
450 450
 
451 451
 
452 452
 				// Retrieve all extrafields for reception
453 453
 				// fetch optionals attributes and labels
454 454
 				require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
455
-				$extrafields=new ExtraFields($this->db);
456
-				$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
457
-				$this->fetch_optionals($this->id,$extralabels);
455
+				$extrafields = new ExtraFields($this->db);
456
+				$extralabels = $extrafields->fetch_name_optionals_label($this->table_element, true);
457
+				$this->fetch_optionals($this->id, $extralabels);
458 458
 
459 459
 				/*
460 460
 				 * Lines
461 461
 				 */
462
-				$result=$this->fetch_lines();
462
+				$result = $this->fetch_lines();
463 463
 				if ($result < 0)
464 464
 				{
465 465
 					return -3;
@@ -470,13 +470,13 @@  discard block
 block discarded – undo
470 470
 			else
471 471
 			{
472 472
 				dol_syslog(get_class($this).'::Fetch no reception found', LOG_ERR);
473
-				$this->error='Delivery with id '.$id.' not found';
473
+				$this->error = 'Delivery with id '.$id.' not found';
474 474
 				return 0;
475 475
 			}
476 476
 		}
477 477
 		else
478 478
 		{
479
-			$this->error=$this->db->error();
479
+			$this->error = $this->db->error();
480 480
 			return -1;
481 481
 		}
482 482
 	}
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
      *  @param		int			$notrigger	1=Does not execute triggers, 0= execute triggers
489 489
 	 *  @return     int						<0 if OK, >0 if KO
490 490
 	 */
491
-	function valid($user, $notrigger=0)
491
+	function valid($user, $notrigger = 0)
492 492
 	{
493 493
 		global $conf, $langs;
494 494
 
@@ -503,10 +503,10 @@  discard block
 block discarded – undo
503 503
 			return 0;
504 504
 		}
505 505
 
506
-        if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->creer))
507
-       	|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->reception_advance->validate))))
506
+        if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
507
+       	|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate))))
508 508
 		{
509
-			$this->error='Permission denied';
509
+			$this->error = 'Permission denied';
510 510
 			dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
511 511
 			return -1;
512 512
 		}
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 
522 522
 
523 523
 		// Define new ref
524
-		if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
524
+		if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
525 525
 		{
526 526
 			$numref = $this->getNextNumRef($soc);
527 527
 		}
@@ -531,25 +531,25 @@  discard block
 block discarded – undo
531 531
 
532 532
         $this->newref = $numref;
533 533
 
534
-		$now=dol_now();
534
+		$now = dol_now();
535 535
 
536 536
 		// Validate
537 537
 		$sql = "UPDATE ".MAIN_DB_PREFIX."reception SET";
538
-		$sql.= " ref='".$this->db->escape($numref)."'";
539
-		$sql.= ", fk_statut = 1";
540
-		$sql.= ", date_valid = '".$this->db->idate($now)."'";
541
-		$sql.= ", fk_user_valid = ".$user->id;
542
-		$sql.= " WHERE rowid = ".$this->id;
538
+		$sql .= " ref='".$this->db->escape($numref)."'";
539
+		$sql .= ", fk_statut = 1";
540
+		$sql .= ", date_valid = '".$this->db->idate($now)."'";
541
+		$sql .= ", fk_user_valid = ".$user->id;
542
+		$sql .= " WHERE rowid = ".$this->id;
543 543
 		dol_syslog(get_class($this)."::valid update reception", LOG_DEBUG);
544
-		$resql=$this->db->query($sql);
545
-		if (! $resql)
544
+		$resql = $this->db->query($sql);
545
+		if (!$resql)
546 546
 		{
547
-			$this->error=$this->db->lasterror();
547
+			$this->error = $this->db->lasterror();
548 548
 			$error++;
549 549
 		}
550 550
 
551 551
 		// If stock increment is done on reception (recommanded choice)
552
-		if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION))
552
+		if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION))
553 553
 		{
554 554
 			require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
555 555
 
@@ -558,15 +558,15 @@  discard block
 block discarded – undo
558 558
 			// Loop on each product line to add a stock movement
559 559
 			// TODO in future, reception lines may not be linked to order line
560 560
 			$sql = "SELECT cd.fk_product, cd.subprice,";
561
-			$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
562
-			$sql.= " ed.eatby, ed.sellby, ed.batch";
563
-			$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
564
-			$sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
565
-			$sql.= " WHERE ed.fk_reception = ".$this->id;
566
-			$sql.= " AND cd.rowid = ed.fk_commandefourndet";
561
+			$sql .= " ed.rowid, ed.qty, ed.fk_entrepot,";
562
+			$sql .= " ed.eatby, ed.sellby, ed.batch";
563
+			$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
564
+			$sql .= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
565
+			$sql .= " WHERE ed.fk_reception = ".$this->id;
566
+			$sql .= " AND cd.rowid = ed.fk_commandefourndet";
567 567
 
568 568
 			dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
569
-			$resql=$this->db->query($sql);
569
+			$resql = $this->db->query($sql);
570 570
 			if ($resql)
571 571
 			{
572 572
 				$cpt = $this->db->num_rows($resql);
@@ -588,10 +588,10 @@  discard block
 block discarded – undo
588 588
 						// line without batch detail
589 589
 
590 590
 						// 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.
591
-						$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionValidatedInDolibarr",$numref));
591
+						$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionValidatedInDolibarr", $numref));
592 592
 						if ($result < 0) {
593 593
 							$error++;
594
-							$this->errors[]=$mouvS->error;
594
+							$this->errors[] = $mouvS->error;
595 595
 							$this->errors = array_merge($this->errors, $mouvS->errors);
596 596
 							break;
597 597
 						}
@@ -602,10 +602,10 @@  discard block
 block discarded – undo
602 602
 
603 603
 						// 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.
604 604
 					    // Note: ->fk_origin_stock = id into table llx_product_batch (may be rename into llx_product_stock_batch in another version)
605
-						$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionValidatedInDolibarr",$numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch);
605
+						$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionValidatedInDolibarr", $numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch);
606 606
 						if ($result < 0) {
607 607
 							$error++;
608
-							$this->errors[]=$mouvS->error;
608
+							$this->errors[] = $mouvS->error;
609 609
 							$this->errors = array_merge($this->errors, $mouvS->errors);
610 610
 							break;
611 611
 						}
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
 			else
616 616
 			{
617 617
 				$this->db->rollback();
618
-				$this->error=$this->db->error();
618
+				$this->error = $this->db->error();
619 619
 				return -2;
620 620
 			}
621 621
 		}
@@ -623,20 +623,20 @@  discard block
 block discarded – undo
623 623
 		// Change status of order to "reception in process"
624 624
 		$ret = $this->setStatut(4, $this->origin_id, 'commande_fournisseur');
625 625
 
626
-        if (! $ret)
626
+        if (!$ret)
627 627
 		{
628 628
 		    $error++;
629 629
 		}
630 630
 
631
-		if (! $error && ! $notrigger)
631
+		if (!$error && !$notrigger)
632 632
 		{
633 633
             // Call trigger
634
-            $result=$this->call_trigger('RECEPTION_VALIDATE',$user);
634
+            $result = $this->call_trigger('RECEPTION_VALIDATE', $user);
635 635
             if ($result < 0) { $error++; }
636 636
             // End call triggers
637 637
 		}
638 638
 
639
-		if (! $error)
639
+		if (!$error)
640 640
 		{
641 641
             $this->oldref = $this->ref;
642 642
 
@@ -657,13 +657,13 @@  discard block
 block discarded – undo
657 657
 					{
658 658
 					    dol_syslog("Rename ok");
659 659
                         // Rename docs starting with $oldref with $newref
660
-                        $listoffiles=dol_dir_list($conf->reception->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
661
-                        foreach($listoffiles as $fileentry)
660
+                        $listoffiles = dol_dir_list($conf->reception->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
661
+                        foreach ($listoffiles as $fileentry)
662 662
                         {
663
-                        	$dirsource=$fileentry['name'];
664
-                        	$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
665
-                        	$dirsource=$fileentry['path'].'/'.$dirsource;
666
-                        	$dirdest=$fileentry['path'].'/'.$dirdest;
663
+                        	$dirsource = $fileentry['name'];
664
+                        	$dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
665
+                        	$dirsource = $fileentry['path'].'/'.$dirsource;
666
+                        	$dirdest = $fileentry['path'].'/'.$dirdest;
667 667
                         	@rename($dirsource, $dirdest);
668 668
                         }
669 669
 					}
@@ -672,26 +672,26 @@  discard block
 block discarded – undo
672 672
 		}
673 673
 
674 674
 		// Set new ref and current status
675
-		if (! $error)
675
+		if (!$error)
676 676
 		{
677 677
 			$this->ref = $numref;
678 678
 			$this->statut = 1;
679 679
 		}
680 680
 
681
-		if (! $error)
681
+		if (!$error)
682 682
 		{
683 683
 			$this->db->commit();
684 684
 			return 1;
685 685
 		}
686 686
 		else
687 687
 		{
688
-			foreach($this->errors as $errmsg)
688
+			foreach ($this->errors as $errmsg)
689 689
 			{
690 690
 	            dol_syslog(get_class($this)."::valid ".$errmsg, LOG_ERR);
691
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
691
+	            $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
692 692
 			}
693 693
 			$this->db->rollback();
694
-			return -1*$error;
694
+			return -1 * $error;
695 695
 		}
696 696
 	}
697 697
 
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
 	 * @param	string		$batch					Lot number
713 713
 	 * @return	int							<0 if KO, >0 if OK
714 714
 	 */
715
-	function addline($entrepot_id, $id, $qty, $array_options=0, $comment='', $eatby='', $sellby='', $batch='')
715
+	function addline($entrepot_id, $id, $qty, $array_options = 0, $comment = '', $eatby = '', $sellby = '', $batch = '')
716 716
 	{
717 717
 		global $conf, $langs, $user;
718 718
 
@@ -726,31 +726,31 @@  discard block
 block discarded – undo
726 726
 		$supplierorderline = new CommandeFournisseurLigne($this->db);
727 727
 		$supplierorderline->fetch($id);
728 728
 
729
-		if (! empty($conf->stock->enabled) && ! empty($supplierorderline->fk_product))
729
+		if (!empty($conf->stock->enabled) && !empty($supplierorderline->fk_product))
730 730
 		{
731 731
 			$fk_product = $supplierorderline->fk_product;
732 732
 
733
-			if (! ($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS))
733
+			if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS))
734 734
 			{
735 735
 			    $langs->load("errors");
736
-				$this->error=$langs->trans("ErrorWarehouseRequiredIntoReceptionLine");
736
+				$this->error = $langs->trans("ErrorWarehouseRequiredIntoReceptionLine");
737 737
 				return -1;
738 738
 			}
739 739
 		}
740 740
 
741 741
 		// extrafields
742
-		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
742
+		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) // For avoid conflicts if trigger used
743 743
 			$line->array_options = $array_options;
744 744
 
745 745
 		$line->fk_product = $fk_product;
746
-		$line->fk_commande = $supplierorderline->fk_commande ;
747
-		$line->fk_user = $user->id ;
746
+		$line->fk_commande = $supplierorderline->fk_commande;
747
+		$line->fk_user = $user->id;
748 748
 		$line->comment = $comment;
749 749
 		$line->batch = $batch;
750 750
 		$line->eatby = $eatby;
751 751
 		$line->sellby = $sellby;
752
-		$line->status=1;
753
-		$line->fk_reception=$this->id;
752
+		$line->status = 1;
753
+		$line->fk_reception = $this->id;
754 754
 
755 755
 		$this->lines[$num] = $line;
756 756
 	}
@@ -763,32 +763,32 @@  discard block
 block discarded – undo
763 763
      *  @param  int		$notrigger	    0=launch triggers after, 1=disable triggers
764 764
      *  @return int 			       	<0 if KO, >0 if OK
765 765
      */
766
-    function update($user=null, $notrigger=0)
766
+    function update($user = null, $notrigger = 0)
767 767
     {
768 768
     	global $conf;
769
-		$error=0;
769
+		$error = 0;
770 770
 
771 771
 		// Clean parameters
772 772
 
773
-		if (isset($this->ref)) $this->ref=trim($this->ref);
774
-		if (isset($this->entity)) $this->entity=trim($this->entity);
775
-		if (isset($this->ref_supplier)) $this->ref_supplier=trim($this->ref_supplier);
776
-		if (isset($this->socid)) $this->socid=trim($this->socid);
777
-		if (isset($this->fk_user_author)) $this->fk_user_author=trim($this->fk_user_author);
778
-		if (isset($this->fk_user_valid)) $this->fk_user_valid=trim($this->fk_user_valid);
779
-		if (isset($this->fk_delivery_address)) $this->fk_delivery_address=trim($this->fk_delivery_address);
780
-		if (isset($this->shipping_method_id)) $this->shipping_method_id=trim($this->shipping_method_id);
781
-		if (isset($this->tracking_number)) $this->tracking_number=trim($this->tracking_number);
782
-		if (isset($this->statut)) $this->statut=(int) $this->statut;
783
-		if (isset($this->trueDepth)) $this->trueDepth=trim($this->trueDepth);
784
-		if (isset($this->trueWidth)) $this->trueWidth=trim($this->trueWidth);
785
-		if (isset($this->trueHeight)) $this->trueHeight=trim($this->trueHeight);
786
-		if (isset($this->size_units)) $this->size_units=trim($this->size_units);
787
-		if (isset($this->weight_units)) $this->weight_units=trim($this->weight_units);
788
-		if (isset($this->trueWeight)) $this->weight=trim($this->trueWeight);
789
-		if (isset($this->note_private)) $this->note=trim($this->note_private);
790
-		if (isset($this->note_public)) $this->note=trim($this->note_public);
791
-		if (isset($this->modelpdf)) $this->modelpdf=trim($this->modelpdf);
773
+		if (isset($this->ref)) $this->ref = trim($this->ref);
774
+		if (isset($this->entity)) $this->entity = trim($this->entity);
775
+		if (isset($this->ref_supplier)) $this->ref_supplier = trim($this->ref_supplier);
776
+		if (isset($this->socid)) $this->socid = trim($this->socid);
777
+		if (isset($this->fk_user_author)) $this->fk_user_author = trim($this->fk_user_author);
778
+		if (isset($this->fk_user_valid)) $this->fk_user_valid = trim($this->fk_user_valid);
779
+		if (isset($this->fk_delivery_address)) $this->fk_delivery_address = trim($this->fk_delivery_address);
780
+		if (isset($this->shipping_method_id)) $this->shipping_method_id = trim($this->shipping_method_id);
781
+		if (isset($this->tracking_number)) $this->tracking_number = trim($this->tracking_number);
782
+		if (isset($this->statut)) $this->statut = (int) $this->statut;
783
+		if (isset($this->trueDepth)) $this->trueDepth = trim($this->trueDepth);
784
+		if (isset($this->trueWidth)) $this->trueWidth = trim($this->trueWidth);
785
+		if (isset($this->trueHeight)) $this->trueHeight = trim($this->trueHeight);
786
+		if (isset($this->size_units)) $this->size_units = trim($this->size_units);
787
+		if (isset($this->weight_units)) $this->weight_units = trim($this->weight_units);
788
+		if (isset($this->trueWeight)) $this->weight = trim($this->trueWeight);
789
+		if (isset($this->note_private)) $this->note = trim($this->note_private);
790
+		if (isset($this->note_public)) $this->note = trim($this->note_public);
791
+		if (isset($this->modelpdf)) $this->modelpdf = trim($this->modelpdf);
792 792
 
793 793
 
794 794
 		// Check parameters
@@ -797,44 +797,44 @@  discard block
 block discarded – undo
797 797
         // Update request
798 798
         $sql = "UPDATE ".MAIN_DB_PREFIX."reception SET";
799 799
 
800
-		$sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
801
-		$sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").",";
802
-		$sql.= " ref_supplier=".(isset($this->ref_supplier)?"'".$this->db->escape($this->ref_supplier)."'":"null").",";
803
-		$sql.= " fk_soc=".(isset($this->socid)?$this->socid:"null").",";
804
-		$sql.= " date_creation=".(dol_strlen($this->date_creation)!=0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').",";
805
-		$sql.= " fk_user_author=".(isset($this->fk_user_author)?$this->fk_user_author:"null").",";
806
-		$sql.= " date_valid=".(dol_strlen($this->date_valid)!=0 ? "'".$this->db->idate($this->date_valid)."'" : 'null').",";
807
-		$sql.= " fk_user_valid=".(isset($this->fk_user_valid)?$this->fk_user_valid:"null").",";
808
-		$sql.= " date_reception=".(dol_strlen($this->date_reception)!=0 ? "'".$this->db->idate($this->date_reception)."'" : 'null').",";
809
-		$sql.= " date_delivery=".(dol_strlen($this->date_delivery)!=0 ? "'".$this->db->idate($this->date_delivery)."'" : 'null').",";
810
-		$sql.= " fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0)?$this->shipping_method_id:"null").",";
811
-		$sql.= " tracking_number=".(isset($this->tracking_number)?"'".$this->db->escape($this->tracking_number)."'":"null").",";
812
-		$sql.= " fk_statut=".(isset($this->statut)?$this->statut:"null").",";
813
-		$sql.= " height=".(($this->trueHeight != '')?$this->trueHeight:"null").",";
814
-		$sql.= " width=".(($this->trueWidth != '')?$this->trueWidth:"null").",";
815
-		$sql.= " size_units=".(isset($this->size_units)?$this->size_units:"null").",";
816
-		$sql.= " size=".(($this->trueDepth != '')?$this->trueDepth:"null").",";
817
-		$sql.= " weight_units=".(isset($this->weight_units)?$this->weight_units:"null").",";
818
-		$sql.= " weight=".(($this->trueWeight != '')?$this->trueWeight:"null").",";
819
-		$sql.= " note_private=".(isset($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null").",";
820
-		$sql.= " note_public=".(isset($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null").",";
821
-		$sql.= " model_pdf=".(isset($this->modelpdf)?"'".$this->db->escape($this->modelpdf)."'":"null").",";
822
-		$sql.= " entity=".$conf->entity;
823
-
824
-        $sql.= " WHERE rowid=".$this->id;
800
+		$sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
801
+		$sql .= " ref=".(isset($this->ref) ? "'".$this->db->escape($this->ref)."'" : "null").",";
802
+		$sql .= " ref_supplier=".(isset($this->ref_supplier) ? "'".$this->db->escape($this->ref_supplier)."'" : "null").",";
803
+		$sql .= " fk_soc=".(isset($this->socid) ? $this->socid : "null").",";
804
+		$sql .= " date_creation=".(dol_strlen($this->date_creation) != 0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').",";
805
+		$sql .= " fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author : "null").",";
806
+		$sql .= " date_valid=".(dol_strlen($this->date_valid) != 0 ? "'".$this->db->idate($this->date_valid)."'" : 'null').",";
807
+		$sql .= " fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid : "null").",";
808
+		$sql .= " date_reception=".(dol_strlen($this->date_reception) != 0 ? "'".$this->db->idate($this->date_reception)."'" : 'null').",";
809
+		$sql .= " date_delivery=".(dol_strlen($this->date_delivery) != 0 ? "'".$this->db->idate($this->date_delivery)."'" : 'null').",";
810
+		$sql .= " fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id : "null").",";
811
+		$sql .= " tracking_number=".(isset($this->tracking_number) ? "'".$this->db->escape($this->tracking_number)."'" : "null").",";
812
+		$sql .= " fk_statut=".(isset($this->statut) ? $this->statut : "null").",";
813
+		$sql .= " height=".(($this->trueHeight != '') ? $this->trueHeight : "null").",";
814
+		$sql .= " width=".(($this->trueWidth != '') ? $this->trueWidth : "null").",";
815
+		$sql .= " size_units=".(isset($this->size_units) ? $this->size_units : "null").",";
816
+		$sql .= " size=".(($this->trueDepth != '') ? $this->trueDepth : "null").",";
817
+		$sql .= " weight_units=".(isset($this->weight_units) ? $this->weight_units : "null").",";
818
+		$sql .= " weight=".(($this->trueWeight != '') ? $this->trueWeight : "null").",";
819
+		$sql .= " note_private=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").",";
820
+		$sql .= " note_public=".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null").",";
821
+		$sql .= " model_pdf=".(isset($this->modelpdf) ? "'".$this->db->escape($this->modelpdf)."'" : "null").",";
822
+		$sql .= " entity=".$conf->entity;
823
+
824
+        $sql .= " WHERE rowid=".$this->id;
825 825
 
826 826
 		$this->db->begin();
827 827
 
828 828
 		dol_syslog(get_class($this)."::update", LOG_DEBUG);
829 829
         $resql = $this->db->query($sql);
830
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
830
+    	if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
831 831
 
832
-		if (! $error)
832
+		if (!$error)
833 833
 		{
834
-			if (! $notrigger)
834
+			if (!$notrigger)
835 835
 			{
836 836
                 // Call trigger
837
-                $result=$this->call_trigger('RECEPTION_MODIFY',$user);
837
+                $result = $this->call_trigger('RECEPTION_MODIFY', $user);
838 838
                 if ($result < 0) { $error++; }
839 839
                 // End call triggers
840 840
 	    	}
@@ -843,13 +843,13 @@  discard block
 block discarded – undo
843 843
         // Commit or rollback
844 844
 		if ($error)
845 845
 		{
846
-			foreach($this->errors as $errmsg)
846
+			foreach ($this->errors as $errmsg)
847 847
 			{
848 848
 	            dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
849
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
849
+	            $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
850 850
 			}
851 851
 			$this->db->rollback();
852
-			return -1*$error;
852
+			return -1 * $error;
853 853
 		}
854 854
 		else
855 855
 		{
@@ -869,8 +869,8 @@  discard block
 block discarded – undo
869 869
 		global $conf, $langs, $user;
870 870
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
871 871
 
872
-		$error=0;
873
-		$this->error='';
872
+		$error = 0;
873
+		$this->error = '';
874 874
 
875 875
 
876 876
 		$this->db->begin();
@@ -884,13 +884,13 @@  discard block
 block discarded – undo
884 884
 
885 885
 			// Loop on each product line to add a stock movement
886 886
 			$sql = "SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.eatby, ed.sellby, ed.batch, ed.rowid as commande_fournisseur_dispatch_id";
887
-			$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
888
-			$sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
889
-			$sql.= " WHERE ed.fk_reception = ".$this->id;
890
-			$sql.= " AND cd.rowid = ed.fk_commandefourndet";
887
+			$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
888
+			$sql .= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
889
+			$sql .= " WHERE ed.fk_reception = ".$this->id;
890
+			$sql .= " AND cd.rowid = ed.fk_commandefourndet";
891 891
 
892 892
 			dol_syslog(get_class($this)."::delete select details", LOG_DEBUG);
893
-			$resql=$this->db->query($sql);
893
+			$resql = $this->db->query($sql);
894 894
 			if ($resql)
895 895
 			{
896 896
 				$cpt = $this->db->num_rows($resql);
@@ -903,42 +903,42 @@  discard block
 block discarded – undo
903 903
 					// we do not log origin because it will be deleted
904 904
 					$mouvS->origin = null;
905 905
 
906
-					$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans("ReceptionDeletedInDolibarr", $this->ref),'', $obj->eatby, $obj->sellby, $obj->batch);  // Price is set to 0, because we don't want to see WAP changed
906
+					$result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans("ReceptionDeletedInDolibarr", $this->ref), '', $obj->eatby, $obj->sellby, $obj->batch); // Price is set to 0, because we don't want to see WAP changed
907 907
 				}
908 908
 			}
909 909
 			else
910 910
 			{
911
-				$error++;$this->errors[]="Error ".$this->db->lasterror();
911
+				$error++; $this->errors[] = "Error ".$this->db->lasterror();
912 912
 			}
913 913
 		}
914 914
 
915
-		if (! $error)
915
+		if (!$error)
916 916
 		{
917 917
 			$sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch";
918
-			$sql.= " WHERE fk_reception = ".$this->id;
918
+			$sql .= " WHERE fk_reception = ".$this->id;
919 919
 
920
-			if ( $this->db->query($sql) )
920
+			if ($this->db->query($sql))
921 921
 			{
922 922
 				// Delete linked object
923 923
 				$res = $this->deleteObjectLinked();
924 924
 				if ($res < 0) $error++;
925 925
 
926
-				if (! $error)
926
+				if (!$error)
927 927
 				{
928 928
 					$sql = "DELETE FROM ".MAIN_DB_PREFIX."reception";
929
-					$sql.= " WHERE rowid = ".$this->id;
929
+					$sql .= " WHERE rowid = ".$this->id;
930 930
 
931 931
 					if ($this->db->query($sql))
932 932
 					{
933 933
 						// Call trigger
934
-						$result=$this->call_trigger('RECEPTION_DELETE',$user);
934
+						$result = $this->call_trigger('RECEPTION_DELETE', $user);
935 935
 						if ($result < 0) { $error++; }
936 936
 						// End call triggers
937 937
 
938
-						if (! empty($this->origin) && $this->origin_id > 0)
938
+						if (!empty($this->origin) && $this->origin_id > 0)
939 939
 						{
940 940
 						    $this->fetch_origin();
941
-						    $origin=$this->origin;
941
+						    $origin = $this->origin;
942 942
 						    if ($this->$origin->statut == 4)     // If order source of reception is "partially received"
943 943
 						    {
944 944
                                 // Check if there is no more reception. If not, we can move back status of order to "validated" instead of "reception in progress"
@@ -951,19 +951,19 @@  discard block
 block discarded – undo
951 951
 						    }
952 952
 						}
953 953
 
954
-						if (! $error)
954
+						if (!$error)
955 955
 						{
956 956
 							$this->db->commit();
957 957
 
958 958
 							// We delete PDFs
959 959
 							$ref = dol_sanitizeFileName($this->ref);
960
-							if (! empty($conf->reception->dir_output))
960
+							if (!empty($conf->reception->dir_output))
961 961
 							{
962
-								$dir = $conf->reception->dir_output . '/' . $ref ;
963
-								$file = $dir . '/' . $ref . '.pdf';
962
+								$dir = $conf->reception->dir_output.'/'.$ref;
963
+								$file = $dir.'/'.$ref.'.pdf';
964 964
 								if (file_exists($file))
965 965
 								{
966
-									if (! dol_delete_file($file))
966
+									if (!dol_delete_file($file))
967 967
 									{
968 968
 										return 0;
969 969
 									}
@@ -972,7 +972,7 @@  discard block
 block discarded – undo
972 972
 								{
973 973
 									if (!dol_delete_dir_recursive($dir))
974 974
 									{
975
-										$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
975
+										$this->error = $langs->trans("ErrorCanNotDeleteDir", $dir);
976 976
 										return 0;
977 977
 									}
978 978
 								}
@@ -988,21 +988,21 @@  discard block
 block discarded – undo
988 988
 					}
989 989
 					else
990 990
 					{
991
-						$this->error=$this->db->lasterror()." - sql=$sql";
991
+						$this->error = $this->db->lasterror()." - sql=$sql";
992 992
 						$this->db->rollback();
993 993
 						return -3;
994 994
 					}
995 995
 				}
996 996
 				else
997 997
 				{
998
-					$this->error=$this->db->lasterror()." - sql=$sql";
998
+					$this->error = $this->db->lasterror()." - sql=$sql";
999 999
 					$this->db->rollback();
1000 1000
 					return -2;
1001 1001
 				}
1002 1002
 			}
1003 1003
 			else
1004 1004
 			{
1005
-				$this->error=$this->db->lasterror()." - sql=$sql";
1005
+				$this->error = $this->db->lasterror()." - sql=$sql";
1006 1006
 				$this->db->rollback();
1007 1007
 				return -1;
1008 1008
 			}
@@ -1028,41 +1028,41 @@  discard block
 block discarded – undo
1028 1028
 		$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'commande_fournisseur_dispatch WHERE fk_reception='.$this->id;
1029 1029
 		$resql = $db->query($sql);
1030 1030
 
1031
-		if(!empty($resql)){
1031
+		if (!empty($resql)) {
1032 1032
 			$this->lines = array();
1033
-			while ($obj = $resql->fetch_object()){
1033
+			while ($obj = $resql->fetch_object()) {
1034 1034
 				$line = new CommandeFournisseurDispatch($db);
1035 1035
 				$line->fetch($obj->rowid);
1036 1036
 				$line->fetch_product();
1037 1037
 				$sql_commfourndet = 'SELECT qty, ref,  label, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent FROM llx_commande_fournisseurdet WHERE rowid='.$line->fk_commandefourndet;
1038 1038
 				$resql_commfourndet = $db->query($sql_commfourndet);
1039
-				if(!empty($resql_commfourndet)){
1039
+				if (!empty($resql_commfourndet)) {
1040 1040
 					$obj = $db->fetch_object($resql_commfourndet);
1041 1041
 					$line->qty_asked = $obj->qty;
1042 1042
 					$line->description = $line->comment;
1043
-					$line->desc =  $line->comment;
1043
+					$line->desc = $line->comment;
1044 1044
 					$line->tva_tx = $obj->tva_tx;
1045 1045
 					$line->vat_src_code = $obj->vat_src_code;
1046 1046
 					$line->subprice = $obj->subprice;
1047 1047
 					$line->multicurrency_subprice = $obj->multicurrency_subprice;
1048 1048
 					$line->remise_percent = $obj->remise_percent;
1049
-					$line->label = !empty($obj->label)?$obj->label:$line->product->label;
1049
+					$line->label = !empty($obj->label) ? $obj->label : $line->product->label;
1050 1050
 					$line->ref_supplier = $obj->ref;
1051
-				}else {
1051
+				} else {
1052 1052
 					$line->qty_asked = 0;
1053 1053
 					$line->description = '';
1054 1054
 					$line->label = $obj->label;
1055 1055
 				}
1056 1056
 
1057
-				$pu_ht=($line->subprice*$line->qty)*(100-$line->remise_percent)/100;
1058
-				$tva = $pu_ht*$line->tva_tx/100;
1057
+				$pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1058
+				$tva = $pu_ht * $line->tva_tx / 100;
1059 1059
 				$this->total_ht += $pu_ht;
1060
-				$this->total_tva += $pu_ht*$line->tva_tx/100;
1060
+				$this->total_tva += $pu_ht * $line->tva_tx / 100;
1061 1061
 
1062
-				$this->total_ttc += $pu_ht+$tva;
1062
+				$this->total_ttc += $pu_ht + $tva;
1063 1063
 
1064 1064
 
1065
-				$this->lines[]=$line;
1065
+				$this->lines[] = $line;
1066 1066
 			}
1067 1067
 
1068 1068
 			return 1;
@@ -1082,38 +1082,38 @@  discard block
 block discarded – undo
1082 1082
      *  @param      int         $notooltip      1=No tooltip
1083 1083
      *	@return     string          			String with URL
1084 1084
      */
1085
-	function getNomUrl($withpicto=0,$option=0,$max=0,$short=0,$notooltip=0)
1085
+	function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0)
1086 1086
 	{
1087 1087
 		global $langs;
1088
-		$result='';
1089
-        $label = '<u>' . $langs->trans("ShowReception") . '</u>';
1090
-        $label .= '<br><b>' . $langs->trans('Ref') . ':</b> '.$this->ref;
1088
+		$result = '';
1089
+        $label = '<u>'.$langs->trans("ShowReception").'</u>';
1090
+        $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1091 1091
         $label .= '<br><b>'.$langs->trans('RefSupplier').':</b> '.($this->ref_supplier ? $this->ref_supplier : $this->ref_client);
1092 1092
 
1093 1093
 		$url = DOL_URL_ROOT.'/reception/card.php?id='.$this->id;
1094 1094
 
1095 1095
 		if ($short) return $url;
1096 1096
 
1097
-		$linkclose='';
1097
+		$linkclose = '';
1098 1098
 		if (empty($notooltip))
1099 1099
 		{
1100
-		    if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1100
+		    if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1101 1101
 		    {
1102
-		        $label=$langs->trans("ShowReception");
1103
-		        $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
1102
+		        $label = $langs->trans("ShowReception");
1103
+		        $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1104 1104
 		    }
1105
-		    $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
1106
-		    $linkclose.=' class="classfortooltip"';
1105
+		    $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
1106
+		    $linkclose .= ' class="classfortooltip"';
1107 1107
 		}
1108 1108
 
1109 1109
         $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1110
-		$linkend='</a>';
1110
+		$linkend = '</a>';
1111 1111
 
1112
-		$picto='sending';
1112
+		$picto = 'sending';
1113 1113
 
1114
-		if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
1115
-		if ($withpicto && $withpicto != 2) $result.=' ';
1116
-		$result.=$linkstart.$this->ref.$linkend;
1114
+		if ($withpicto) $result .= ($linkstart.img_object(($notooltip ? '' : $label), $picto, ($notooltip ? '' : 'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).$linkend);
1115
+		if ($withpicto && $withpicto != 2) $result .= ' ';
1116
+		$result .= $linkstart.$this->ref.$linkend;
1117 1117
 		return $result;
1118 1118
 	}
1119 1119
 
@@ -1123,9 +1123,9 @@  discard block
 block discarded – undo
1123 1123
      *	@param      int		$mode      	0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto
1124 1124
      *	@return     string      		Libelle
1125 1125
      */
1126
-	function getLibStatut($mode=0)
1126
+	function getLibStatut($mode = 0)
1127 1127
 	{
1128
-		return $this->LibStatut($this->statut,$mode);
1128
+		return $this->LibStatut($this->statut, $mode);
1129 1129
 	}
1130 1130
 
1131 1131
 	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -1136,40 +1136,40 @@  discard block
 block discarded – undo
1136 1136
 	 * @param      int		$mode       0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto
1137 1137
 	 * @return     string				Label of status
1138 1138
 	 */
1139
-	function LibStatut($statut,$mode)
1139
+	function LibStatut($statut, $mode)
1140 1140
 	{
1141 1141
 		// phpcs:enable
1142 1142
 		global $langs;
1143 1143
 
1144
-		if ($mode==0)
1144
+		if ($mode == 0)
1145 1145
 		{
1146
-			if ($statut==0) return $langs->trans($this->statuts[$statut]);
1147
-			if ($statut==1)  return $langs->trans($this->statuts[$statut]);
1148
-			if ($statut==2)  return $langs->trans($this->statuts[$statut]);
1146
+			if ($statut == 0) return $langs->trans($this->statuts[$statut]);
1147
+			if ($statut == 1)  return $langs->trans($this->statuts[$statut]);
1148
+			if ($statut == 2)  return $langs->trans($this->statuts[$statut]);
1149 1149
 		}
1150
-		if ($mode==1)
1150
+		if ($mode == 1)
1151 1151
 		{
1152
-			if ($statut==0) return $langs->trans('StatusReceptionDraftShort');
1153
-			if ($statut==1) return $langs->trans('StatusReceptionValidatedShort');
1154
-			if ($statut==2) return $langs->trans('StatusReceptionProcessedShort');
1152
+			if ($statut == 0) return $langs->trans('StatusReceptionDraftShort');
1153
+			if ($statut == 1) return $langs->trans('StatusReceptionValidatedShort');
1154
+			if ($statut == 2) return $langs->trans('StatusReceptionProcessedShort');
1155 1155
 		}
1156 1156
 		if ($mode == 3)
1157 1157
 		{
1158
-			if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0');
1159
-			if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut4');
1160
-			if ($statut==2) return img_picto($langs->trans('StatusReceptionProcessed'),'statut6');
1158
+			if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]), 'statut0');
1159
+			if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]), 'statut4');
1160
+			if ($statut == 2) return img_picto($langs->trans('StatusReceptionProcessed'), 'statut6');
1161 1161
 		}
1162 1162
 		if ($mode == 4)
1163 1163
 		{
1164
-			if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
1165
-			if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
1166
-			if ($statut==2) return img_picto($langs->trans('StatusReceptionProcessed'),'statut6').' '.$langs->trans('StatusReceptionProcessed');
1164
+			if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]), 'statut0').' '.$langs->trans($this->statuts[$statut]);
1165
+			if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]), 'statut4').' '.$langs->trans($this->statuts[$statut]);
1166
+			if ($statut == 2) return img_picto($langs->trans('StatusReceptionProcessed'), 'statut6').' '.$langs->trans('StatusReceptionProcessed');
1167 1167
 		}
1168 1168
 		if ($mode == 5)
1169 1169
 		{
1170
-			if ($statut==0) return $langs->trans('StatusReceptionDraftShort').' '.img_picto($langs->trans($this->statuts[$statut]),'statut0');
1171
-			if ($statut==1) return $langs->trans('StatusReceptionValidatedShort').' '.img_picto($langs->trans($this->statuts[$statut]),'statut4');
1172
-			if ($statut==2) return $langs->trans('StatusReceptionProcessedShort').' '.img_picto($langs->trans('StatusReceptionProcessedShort'),'statut6');
1170
+			if ($statut == 0) return $langs->trans('StatusReceptionDraftShort').' '.img_picto($langs->trans($this->statuts[$statut]), 'statut0');
1171
+			if ($statut == 1) return $langs->trans('StatusReceptionValidatedShort').' '.img_picto($langs->trans($this->statuts[$statut]), 'statut4');
1172
+			if ($statut == 2) return $langs->trans('StatusReceptionProcessedShort').' '.img_picto($langs->trans('StatusReceptionProcessedShort'), 'statut6');
1173 1173
 		}
1174 1174
 	}
1175 1175
 
@@ -1184,7 +1184,7 @@  discard block
 block discarded – undo
1184 1184
 	{
1185 1185
 		global $langs;
1186 1186
 		dol_include_once('/fourn/class/fournisseur.commande.dispatch.class.php');
1187
-		$now=dol_now();
1187
+		$now = dol_now();
1188 1188
 
1189 1189
 		dol_syslog(get_class($this)."::initAsSpecimen");
1190 1190
 
@@ -1192,8 +1192,8 @@  discard block
 block discarded – undo
1192 1192
 		$num_prods = 0;
1193 1193
 		$prodids = array();
1194 1194
 		$sql = "SELECT rowid";
1195
-		$sql.= " FROM ".MAIN_DB_PREFIX."product";
1196
-		$sql.= " WHERE entity IN (".getEntity('product').")";
1195
+		$sql .= " FROM ".MAIN_DB_PREFIX."product";
1196
+		$sql .= " WHERE entity IN (".getEntity('product').")";
1197 1197
 		$resql = $this->db->query($sql);
1198 1198
 		if ($resql)
1199 1199
 		{
@@ -1207,20 +1207,20 @@  discard block
 block discarded – undo
1207 1207
 			}
1208 1208
 		}
1209 1209
 
1210
-		$order=new Commande($this->db);
1210
+		$order = new Commande($this->db);
1211 1211
 		$order->initAsSpecimen();
1212 1212
 
1213 1213
 		// Initialise parametres
1214
-		$this->id=0;
1214
+		$this->id = 0;
1215 1215
 		$this->ref = 'SPECIMEN';
1216
-		$this->specimen=1;
1216
+		$this->specimen = 1;
1217 1217
 		$this->statut               = 1;
1218 1218
 		$this->livraison_id         = 0;
1219 1219
 		$this->date                 = $now;
1220 1220
 		$this->date_creation        = $now;
1221 1221
 		$this->date_valid           = $now;
1222 1222
 		$this->date_delivery        = $now;
1223
-		$this->date_reception      = $now + 24*3600;
1223
+		$this->date_reception = $now + 24 * 3600;
1224 1224
 
1225 1225
 		$this->entrepot_id          = 0;
1226 1226
 		$this->fk_delivery_address  = 0;
@@ -1232,21 +1232,21 @@  discard block
 block discarded – undo
1232 1232
         $this->origin_id            = 1;
1233 1233
         $this->origin               = 'commande';
1234 1234
 
1235
-        $this->note_private			= 'Private note';
1236
-        $this->note_public			= 'Public note';
1235
+        $this->note_private = 'Private note';
1236
+        $this->note_public = 'Public note';
1237 1237
 
1238 1238
 		$nbp = 5;
1239 1239
 		$xnbp = 0;
1240 1240
 		while ($xnbp < $nbp)
1241 1241
 		{
1242
-			$line=new CommandeFournisseurDispatch($this->db);
1243
-			$line->desc=$langs->trans("Description")." ".$xnbp;
1244
-			$line->libelle=$langs->trans("Description")." ".$xnbp;
1245
-			$line->qty=10;
1242
+			$line = new CommandeFournisseurDispatch($this->db);
1243
+			$line->desc = $langs->trans("Description")." ".$xnbp;
1244
+			$line->libelle = $langs->trans("Description")." ".$xnbp;
1245
+			$line->qty = 10;
1246 1246
 
1247
-			$line->fk_product=$this->commande->lines[$xnbp]->fk_product;
1247
+			$line->fk_product = $this->commande->lines[$xnbp]->fk_product;
1248 1248
 
1249
-			$this->lines[]=$line;
1249
+			$this->lines[] = $line;
1250 1250
 			$xnbp++;
1251 1251
 		}
1252 1252
 	}
@@ -1265,11 +1265,11 @@  discard block
 block discarded – undo
1265 1265
 		if ($user->rights->reception->creer)
1266 1266
 		{
1267 1267
 			$sql = "UPDATE ".MAIN_DB_PREFIX."reception";
1268
-			$sql.= " SET date_delivery = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null');
1269
-			$sql.= " WHERE rowid = ".$this->id;
1268
+			$sql .= " SET date_delivery = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null');
1269
+			$sql .= " WHERE rowid = ".$this->id;
1270 1270
 
1271 1271
 			dol_syslog(get_class($this)."::set_date_livraison", LOG_DEBUG);
1272
-			$resql=$this->db->query($sql);
1272
+			$resql = $this->db->query($sql);
1273 1273
 			if ($resql)
1274 1274
 			{
1275 1275
 				$this->date_delivery = $date_livraison;
@@ -1277,7 +1277,7 @@  discard block
 block discarded – undo
1277 1277
 			}
1278 1278
 			else
1279 1279
 			{
1280
-				$this->error=$this->db->error();
1280
+				$this->error = $this->db->error();
1281 1281
 				return -1;
1282 1282
 			}
1283 1283
 		}
@@ -1300,17 +1300,17 @@  discard block
 block discarded – undo
1300 1300
 		$this->meths = array();
1301 1301
 
1302 1302
 		$sql = "SELECT em.rowid, em.code, em.libelle";
1303
-		$sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1304
-		$sql.= " WHERE em.active = 1";
1305
-		$sql.= " ORDER BY em.libelle ASC";
1303
+		$sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1304
+		$sql .= " WHERE em.active = 1";
1305
+		$sql .= " ORDER BY em.libelle ASC";
1306 1306
 
1307 1307
 		$resql = $this->db->query($sql);
1308 1308
 		if ($resql)
1309 1309
 		{
1310 1310
 			while ($obj = $this->db->fetch_object($resql))
1311 1311
 			{
1312
-				$label=$langs->trans('ReceptionMethod'.$obj->code);
1313
-				$this->meths[$obj->rowid] = ($label != 'ReceptionMethod'.$obj->code?$label:$obj->libelle);
1312
+				$label = $langs->trans('ReceptionMethod'.$obj->code);
1313
+				$this->meths[$obj->rowid] = ($label != 'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1314 1314
 			}
1315 1315
 		}
1316 1316
 	}
@@ -1322,17 +1322,17 @@  discard block
 block discarded – undo
1322 1322
      *  @param  int      $id     only this carrier, all if none
1323 1323
      *  @return void
1324 1324
      */
1325
-    function list_delivery_methods($id='')
1325
+    function list_delivery_methods($id = '')
1326 1326
     {
1327 1327
 		// phpcs:enable
1328 1328
         global $langs;
1329 1329
 
1330 1330
         $this->listmeths = array();
1331
-        $i=0;
1331
+        $i = 0;
1332 1332
 
1333 1333
         $sql = "SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1334
-        $sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1335
-        if ($id!='') $sql.= " WHERE em.rowid=".$id;
1334
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1335
+        if ($id != '') $sql .= " WHERE em.rowid=".$id;
1336 1336
 
1337 1337
         $resql = $this->db->query($sql);
1338 1338
         if ($resql)
@@ -1341,8 +1341,8 @@  discard block
 block discarded – undo
1341 1341
             {
1342 1342
                 $this->listmeths[$i]['rowid'] = $obj->rowid;
1343 1343
                 $this->listmeths[$i]['code'] = $obj->code;
1344
-                $label=$langs->trans('ReceptionMethod'.$obj->code);
1345
-                $this->listmeths[$i]['libelle'] = ($label != 'ReceptionMethod'.$obj->code?$label:$obj->libelle);
1344
+                $label = $langs->trans('ReceptionMethod'.$obj->code);
1345
+                $this->listmeths[$i]['libelle'] = ($label != 'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1346 1346
                 $this->listmeths[$i]['description'] = $obj->description;
1347 1347
                 $this->listmeths[$i]['tracking'] = $obj->tracking;
1348 1348
                 $this->listmeths[$i]['active'] = $obj->active;
@@ -1359,26 +1359,26 @@  discard block
 block discarded – undo
1359 1359
      *
1360 1360
      *  @return void
1361 1361
      */
1362
-    function update_delivery_method($id='')
1362
+    function update_delivery_method($id = '')
1363 1363
     {
1364 1364
 		// phpcs:enable
1365
-        if ($id=='')
1365
+        if ($id == '')
1366 1366
         {
1367 1367
             $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_shipment_mode (code, libelle, description, tracking)";
1368
-            $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'])."')";
1368
+            $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'])."')";
1369 1369
             $resql = $this->db->query($sql);
1370 1370
         }
1371 1371
         else
1372 1372
         {
1373 1373
             $sql = "UPDATE ".MAIN_DB_PREFIX."c_shipment_mode SET";
1374
-            $sql.= " code='".$this->db->escape($this->update['code'])."'";
1375
-            $sql.= ",libelle='".$this->db->escape($this->update['libelle'])."'";
1376
-            $sql.= ",description='".$this->db->escape($this->update['description'])."'";
1377
-            $sql.= ",tracking='".$this->db->escape($this->update['tracking'])."'";
1378
-            $sql.= " WHERE rowid=".$id;
1374
+            $sql .= " code='".$this->db->escape($this->update['code'])."'";
1375
+            $sql .= ",libelle='".$this->db->escape($this->update['libelle'])."'";
1376
+            $sql .= ",description='".$this->db->escape($this->update['description'])."'";
1377
+            $sql .= ",tracking='".$this->db->escape($this->update['tracking'])."'";
1378
+            $sql .= " WHERE rowid=".$id;
1379 1379
             $resql = $this->db->query($sql);
1380 1380
         }
1381
-        if ($resql < 0) dol_print_error($this->db,'');
1381
+        if ($resql < 0) dol_print_error($this->db, '');
1382 1382
     }
1383 1383
 
1384 1384
 	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -1393,7 +1393,7 @@  discard block
 block discarded – undo
1393 1393
     {
1394 1394
 		// phpcs:enable
1395 1395
         $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=1';
1396
-        $sql.= ' WHERE rowid='.$id;
1396
+        $sql .= ' WHERE rowid='.$id;
1397 1397
 
1398 1398
         $resql = $this->db->query($sql);
1399 1399
     }
@@ -1410,7 +1410,7 @@  discard block
 block discarded – undo
1410 1410
     {
1411 1411
 		// phpcs:enable
1412 1412
         $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=0';
1413
-        $sql.= ' WHERE rowid='.$id;
1413
+        $sql .= ' WHERE rowid='.$id;
1414 1414
 
1415 1415
         $resql = $this->db->query($sql);
1416 1416
     }
@@ -1422,13 +1422,13 @@  discard block
 block discarded – undo
1422 1422
 	 * @param	string	$value		Value
1423 1423
 	 * @return	void
1424 1424
 	 */
1425
-	function getUrlTrackingStatus($value='')
1425
+	function getUrlTrackingStatus($value = '')
1426 1426
 	{
1427
-		if (! empty($this->shipping_method_id))
1427
+		if (!empty($this->shipping_method_id))
1428 1428
 		{
1429 1429
 			$sql = "SELECT em.code, em.tracking";
1430
-			$sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1431
-			$sql.= " WHERE em.rowid = ".$this->shipping_method_id;
1430
+			$sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1431
+			$sql .= " WHERE em.rowid = ".$this->shipping_method_id;
1432 1432
 
1433 1433
 			$resql = $this->db->query($sql);
1434 1434
 			if ($resql)
@@ -1443,7 +1443,7 @@  discard block
 block discarded – undo
1443 1443
 		if (!empty($tracking) && !empty($value))
1444 1444
 		{
1445 1445
 			$url = str_replace('{TRACKID}', $value, $tracking);
1446
-			$this->tracking_url = sprintf('<a target="_blank" href="%s">'.($value?$value:'url').'</a>',$url,$url);
1446
+			$this->tracking_url = sprintf('<a target="_blank" href="%s">'.($value ? $value : 'url').'</a>', $url, $url);
1447 1447
 		}
1448 1448
 		else
1449 1449
 		{
@@ -1458,16 +1458,16 @@  discard block
 block discarded – undo
1458 1458
 	 */
1459 1459
 	function setClosed()
1460 1460
 	{
1461
-		global $conf,$langs,$user;
1461
+		global $conf, $langs, $user;
1462 1462
 
1463
-		$error=0;
1463
+		$error = 0;
1464 1464
 
1465 1465
 		$this->db->begin();
1466 1466
 
1467 1467
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.'reception SET fk_statut='.self::STATUS_CLOSED;
1468 1468
 		$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0';
1469 1469
 
1470
-		$resql=$this->db->query($sql);
1470
+		$resql = $this->db->query($sql);
1471 1471
 		if ($resql)
1472 1472
 		{
1473 1473
 			// Set order billed if 100% of order is received (qty in reception lines match qty in order lines)
@@ -1476,17 +1476,17 @@  discard block
 block discarded – undo
1476 1476
 				$order = new CommandeFournisseur($this->db);
1477 1477
 				$order->fetch($this->origin_id);
1478 1478
 
1479
-				$order->loadReceptions(self::STATUS_CLOSED);		// Fill $order->receptions = array(orderlineid => qty)
1479
+				$order->loadReceptions(self::STATUS_CLOSED); // Fill $order->receptions = array(orderlineid => qty)
1480 1480
 
1481 1481
 				$receptions_match_order = 1;
1482
-				foreach($order->lines as $line)
1482
+				foreach ($order->lines as $line)
1483 1483
 				{
1484 1484
 					$lineid = $line->id;
1485 1485
 					$qty = $line->qty;
1486
-					if (($line->product_type == 0 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->receptions[$lineid] < $qty)
1486
+					if (($line->product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->receptions[$lineid] < $qty)
1487 1487
 					{
1488 1488
 						$receptions_match_order = 0;
1489
-						$text='Qty for order line id '.$lineid.' is '.$qty.'. However in the receptions with status Reception::STATUS_CLOSED='.self::STATUS_CLOSED.' we have qty = '.$order->receptions[$lineid].', so we can t close order';
1489
+						$text = 'Qty for order line id '.$lineid.' is '.$qty.'. However in the receptions with status Reception::STATUS_CLOSED='.self::STATUS_CLOSED.' we have qty = '.$order->receptions[$lineid].', so we can t close order';
1490 1490
 						dol_syslog($text);
1491 1491
 						break;
1492 1492
 					}
@@ -1498,11 +1498,11 @@  discard block
 block discarded – undo
1498 1498
 				}
1499 1499
 			}
1500 1500
 
1501
-			$this->statut=self::STATUS_CLOSED;
1501
+			$this->statut = self::STATUS_CLOSED;
1502 1502
 
1503 1503
 
1504 1504
 			// If stock increment is done on closing
1505
-			if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))
1505
+			if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))
1506 1506
 			{
1507 1507
 				require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
1508 1508
 
@@ -1511,15 +1511,15 @@  discard block
 block discarded – undo
1511 1511
 				// Loop on each product line to add a stock movement
1512 1512
 				// TODO possibilite de receptionner a partir d'une propale ou autre origine ?
1513 1513
 				$sql = "SELECT cd.fk_product, cd.subprice,";
1514
-				$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
1515
-				$sql.= " ed.eatby, ed.sellby, ed.batch";
1516
-				$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
1517
-				$sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
1518
-				$sql.= " WHERE ed.fk_reception = ".$this->id;
1519
-				$sql.= " AND cd.rowid = ed.fk_commandefourndet";
1514
+				$sql .= " ed.rowid, ed.qty, ed.fk_entrepot,";
1515
+				$sql .= " ed.eatby, ed.sellby, ed.batch";
1516
+				$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
1517
+				$sql .= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
1518
+				$sql .= " WHERE ed.fk_reception = ".$this->id;
1519
+				$sql .= " AND cd.rowid = ed.fk_commandefourndet";
1520 1520
 
1521 1521
 				dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
1522
-				$resql=$this->db->query($sql);
1522
+				$resql = $this->db->query($sql);
1523 1523
 
1524 1524
 				if ($resql)
1525 1525
 				{
@@ -1541,7 +1541,7 @@  discard block
 block discarded – undo
1541 1541
 							// line without batch detail
1542 1542
 
1543 1543
 							// 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
1544
-							$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionClassifyClosedInDolibarr",$numref));
1544
+							$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionClassifyClosedInDolibarr", $numref));
1545 1545
 							if ($result < 0) {
1546 1546
 							    $this->error = $mouvS->error;
1547 1547
 							    $this->errors = $mouvS->errors;
@@ -1553,7 +1553,7 @@  discard block
 block discarded – undo
1553 1553
 							// line with batch detail
1554 1554
 
1555 1555
 							// 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
1556
-							$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionClassifyClosedInDolibarr",$numref),  $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch);
1556
+							$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionClassifyClosedInDolibarr", $numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch);
1557 1557
 
1558 1558
 							if ($result < 0) {
1559 1559
 							    $this->error = $mouvS->error;
@@ -1565,15 +1565,15 @@  discard block
 block discarded – undo
1565 1565
 				}
1566 1566
 				else
1567 1567
 				{
1568
-					$this->error=$this->db->lasterror();
1568
+					$this->error = $this->db->lasterror();
1569 1569
 					$error++;
1570 1570
 				}
1571 1571
 			}
1572 1572
 
1573 1573
 			// Call trigger
1574
-			if (! $error)
1574
+			if (!$error)
1575 1575
 			{
1576
-    			$result=$this->call_trigger('RECEPTION_CLOSED',$user);
1576
+    			$result = $this->call_trigger('RECEPTION_CLOSED', $user);
1577 1577
     			if ($result < 0) {
1578 1578
     			    $error++;
1579 1579
     			}
@@ -1585,7 +1585,7 @@  discard block
 block discarded – undo
1585 1585
             $error++;
1586 1586
 		}
1587 1587
 
1588
-		if (! $error)
1588
+		if (!$error)
1589 1589
 		{
1590 1590
 		    $this->db->commit();
1591 1591
 		    return 1;
@@ -1607,7 +1607,7 @@  discard block
 block discarded – undo
1607 1607
 	{
1608 1608
 		// phpcs:enable
1609 1609
 	    global $user;
1610
-		$error=0;
1610
+		$error = 0;
1611 1611
 
1612 1612
 		$this->db->begin();
1613 1613
 
@@ -1616,20 +1616,20 @@  discard block
 block discarded – undo
1616 1616
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.'reception SET  billed=1';
1617 1617
 		$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0';
1618 1618
 
1619
-		$resql=$this->db->query($sql);
1619
+		$resql = $this->db->query($sql);
1620 1620
 		if ($resql)
1621 1621
 		{
1622
-			$this->statut=2;
1623
-			$this->billed=1;
1622
+			$this->statut = 2;
1623
+			$this->billed = 1;
1624 1624
 
1625 1625
 			// Call trigger
1626
-			$result=$this->call_trigger('RECEPTION_BILLED',$user);
1626
+			$result = $this->call_trigger('RECEPTION_BILLED', $user);
1627 1627
 			if ($result < 0) {
1628 1628
 				$error++;
1629 1629
 			}
1630 1630
 		} else {
1631 1631
 			$error++;
1632
-			$this->errors[]=$this->db->lasterror;
1632
+			$this->errors[] = $this->db->lasterror;
1633 1633
 		}
1634 1634
 
1635 1635
 		if (empty($error)) {
@@ -1650,23 +1650,23 @@  discard block
 block discarded – undo
1650 1650
 	 */
1651 1651
 	function reOpen()
1652 1652
 	{
1653
-		global $conf,$langs,$user;
1653
+		global $conf, $langs, $user;
1654 1654
 
1655
-		$error=0;
1655
+		$error = 0;
1656 1656
 
1657 1657
 		$this->db->begin();
1658 1658
 
1659 1659
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.'reception SET fk_statut=1, billed=0';
1660 1660
 		$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0';
1661 1661
 
1662
-		$resql=$this->db->query($sql);
1662
+		$resql = $this->db->query($sql);
1663 1663
 		if ($resql)
1664 1664
 		{
1665
-			$this->statut=1;
1666
-			$this->billed=0;
1665
+			$this->statut = 1;
1666
+			$this->billed = 0;
1667 1667
 
1668 1668
 			// If stock increment is done on closing
1669
-			if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))
1669
+			if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))
1670 1670
 			{
1671 1671
 				require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
1672 1672
 				$numref = $this->ref;
@@ -1675,15 +1675,15 @@  discard block
 block discarded – undo
1675 1675
 				// Loop on each product line to add a stock movement
1676 1676
 				// TODO possibilite de receptionner a partir d'une propale ou autre origine
1677 1677
 				$sql = "SELECT ed.fk_product, cd.subprice,";
1678
-				$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
1679
-				$sql.= " ed.eatby, ed.sellby, ed.batch";
1680
-				$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
1681
-				$sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
1682
-				$sql.= " WHERE ed.fk_reception = ".$this->id;
1683
-				$sql.= " AND cd.rowid = ed.fk_commandefourndet";
1678
+				$sql .= " ed.rowid, ed.qty, ed.fk_entrepot,";
1679
+				$sql .= " ed.eatby, ed.sellby, ed.batch";
1680
+				$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
1681
+				$sql .= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
1682
+				$sql .= " WHERE ed.fk_reception = ".$this->id;
1683
+				$sql .= " AND cd.rowid = ed.fk_commandefourndet";
1684 1684
 
1685 1685
 				dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
1686
-				$resql=$this->db->query($sql);
1686
+				$resql = $this->db->query($sql);
1687 1687
 				if ($resql)
1688 1688
 				{
1689 1689
 					$cpt = $this->db->num_rows($resql);
@@ -1706,7 +1706,7 @@  discard block
 block discarded – undo
1706 1706
 							// line without batch detail
1707 1707
 
1708 1708
 							// 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
1709
-							$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionUnClassifyCloseddInDolibarr",$numref));
1709
+							$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionUnClassifyCloseddInDolibarr", $numref));
1710 1710
 							if ($result < 0) {
1711 1711
 							    $this->error = $mouvS->error;
1712 1712
 							    $this->errors = $mouvS->errors;
@@ -1718,7 +1718,7 @@  discard block
 block discarded – undo
1718 1718
 							// line with batch detail
1719 1719
 
1720 1720
 							// 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
1721
-							$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionUnClassifyCloseddInDolibarr",$numref),  $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
1721
+							$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionUnClassifyCloseddInDolibarr", $numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
1722 1722
 							if ($result < 0) {
1723 1723
 							    $this->error = $mouvS->error;
1724 1724
 							    $this->errors = $mouvS->errors;
@@ -1729,31 +1729,31 @@  discard block
 block discarded – undo
1729 1729
 				}
1730 1730
 				else
1731 1731
 				{
1732
-					$this->error=$this->db->lasterror();
1732
+					$this->error = $this->db->lasterror();
1733 1733
 					$error++;
1734 1734
 				}
1735 1735
 			}
1736 1736
 
1737
-			if (! $error)
1737
+			if (!$error)
1738 1738
 			{
1739 1739
     			// Call trigger
1740
-    			$result=$this->call_trigger('RECEPTION_REOPEN',$user);
1740
+    			$result = $this->call_trigger('RECEPTION_REOPEN', $user);
1741 1741
     			if ($result < 0) {
1742 1742
     				$error++;
1743 1743
     			}
1744 1744
    			}
1745 1745
 
1746
-			if($this->origin == 'order_supplier'){
1746
+			if ($this->origin == 'order_supplier') {
1747 1747
 				$commande = new CommandeFournisseur($this->db);
1748 1748
 				$commande->fetch($this->origin_id);
1749
-				$commande->setStatus($user,4);
1749
+				$commande->setStatus($user, 4);
1750 1750
 			}
1751 1751
 		} else {
1752 1752
 			$error++;
1753
-			$this->errors[]=$this->db->lasterror();
1753
+			$this->errors[] = $this->db->lasterror();
1754 1754
 		}
1755 1755
 
1756
-		if (! $error)
1756
+		if (!$error)
1757 1757
 		{
1758 1758
 			$this->db->commit();
1759 1759
 			return 1;
@@ -1776,9 +1776,9 @@  discard block
 block discarded – undo
1776 1776
     function set_draft($user)
1777 1777
     {
1778 1778
 		// phpcs:enable
1779
-        global $conf,$langs;
1779
+        global $conf, $langs;
1780 1780
 
1781
-        $error=0;
1781
+        $error = 0;
1782 1782
 
1783 1783
         // Protection
1784 1784
         if ($this->statut <= self::STATUS_DRAFT)
@@ -1786,24 +1786,24 @@  discard block
 block discarded – undo
1786 1786
             return 0;
1787 1787
         }
1788 1788
 
1789
-        if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->creer))
1790
-       	|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->reception_advance->validate))))
1789
+        if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
1790
+       	|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate))))
1791 1791
         {
1792
-            $this->error='Permission denied';
1792
+            $this->error = 'Permission denied';
1793 1793
             return -1;
1794 1794
         }
1795 1795
 
1796 1796
         $this->db->begin();
1797 1797
 
1798 1798
         $sql = "UPDATE ".MAIN_DB_PREFIX."reception";
1799
-        $sql.= " SET fk_statut = ".self::STATUS_DRAFT;
1800
-        $sql.= " WHERE rowid = ".$this->id;
1799
+        $sql .= " SET fk_statut = ".self::STATUS_DRAFT;
1800
+        $sql .= " WHERE rowid = ".$this->id;
1801 1801
 
1802 1802
         dol_syslog(get_class($this)."::set_draft", LOG_DEBUG);
1803 1803
         if ($this->db->query($sql))
1804 1804
         {
1805 1805
             // If stock increment is done on closing
1806
-			if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION))
1806
+			if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION))
1807 1807
 			{
1808 1808
 				require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
1809 1809
 
@@ -1812,15 +1812,15 @@  discard block
 block discarded – undo
1812 1812
 				// Loop on each product line to add a stock movement
1813 1813
 				// TODO possibilite de receptionner a partir d'une propale ou autre origine
1814 1814
 				$sql = "SELECT cd.fk_product, cd.subprice,";
1815
-				$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
1816
-				$sql.= " ed.eatby, ed.sellby, ed.batch";
1817
-				$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
1818
-				$sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
1819
-				$sql.= " WHERE ed.fk_reception = ".$this->id;
1820
-				$sql.= " AND cd.rowid = ed.fk_commandefourndet";
1815
+				$sql .= " ed.rowid, ed.qty, ed.fk_entrepot,";
1816
+				$sql .= " ed.eatby, ed.sellby, ed.batch";
1817
+				$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
1818
+				$sql .= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
1819
+				$sql .= " WHERE ed.fk_reception = ".$this->id;
1820
+				$sql .= " AND cd.rowid = ed.fk_commandefourndet";
1821 1821
 
1822 1822
 				dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
1823
-				$resql=$this->db->query($sql);
1823
+				$resql = $this->db->query($sql);
1824 1824
 				if ($resql)
1825 1825
 				{
1826 1826
 					$cpt = $this->db->num_rows($resql);
@@ -1843,7 +1843,7 @@  discard block
 block discarded – undo
1843 1843
 							// line without batch detail
1844 1844
 
1845 1845
 							// 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
1846
-							$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionBackToDraftInDolibarr",$this->ref));
1846
+							$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionBackToDraftInDolibarr", $this->ref));
1847 1847
 							if ($result < 0) {
1848 1848
 							    $this->error = $mouvS->error;
1849 1849
 							    $this->errors = $mouvS->errors;
@@ -1856,7 +1856,7 @@  discard block
 block discarded – undo
1856 1856
 							// line with batch detail
1857 1857
 
1858 1858
 							// 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
1859
-							$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionBackToDraftInDolibarr",$this->ref),  $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch);
1859
+							$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionBackToDraftInDolibarr", $this->ref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch);
1860 1860
 							if ($result < 0) {
1861 1861
 							    $this->error = $mouvS->error;
1862 1862
 							    $this->errors = $mouvS->errors;
@@ -1867,14 +1867,14 @@  discard block
 block discarded – undo
1867 1867
 				}
1868 1868
 				else
1869 1869
 				{
1870
-					$this->error=$this->db->lasterror();
1870
+					$this->error = $this->db->lasterror();
1871 1871
 					$error++;
1872 1872
 				}
1873 1873
 			}
1874 1874
 
1875 1875
             if (!$error) {
1876 1876
             	// Call trigger
1877
-            	$result=$this->call_trigger('RECEPTION_UNVALIDATE',$user);
1877
+            	$result = $this->call_trigger('RECEPTION_UNVALIDATE', $user);
1878 1878
             	if ($result < 0) $error++;
1879 1879
             }
1880 1880
 			if ($this->origin == 'order_supplier')
@@ -1909,17 +1909,17 @@  discard block
 block discarded – undo
1909 1909
 			}
1910 1910
 
1911 1911
 			if (!$error) {
1912
-           		$this->statut=self::STATUS_DRAFT;
1912
+           		$this->statut = self::STATUS_DRAFT;
1913 1913
             	$this->db->commit();
1914 1914
             	return 1;
1915
-            }else {
1915
+            } else {
1916 1916
             	$this->db->rollback();
1917 1917
             	return -1;
1918 1918
             }
1919 1919
         }
1920 1920
         else
1921 1921
         {
1922
-            $this->error=$this->db->error();
1922
+            $this->error = $this->db->error();
1923 1923
             $this->db->rollback();
1924 1924
             return -1;
1925 1925
         }
@@ -1935,19 +1935,19 @@  discard block
 block discarded – undo
1935 1935
 	 *  @param      int			$hideref        Hide ref
1936 1936
 	 *  @return     int         				0 if KO, 1 if OK
1937 1937
 	 */
1938
-	public function generateDocument($modele, $outputlangs,$hidedetails=0, $hidedesc=0, $hideref=0)
1938
+	public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1939 1939
 	{
1940
-		global $conf,$langs;
1940
+		global $conf, $langs;
1941 1941
 
1942 1942
 		$langs->load("receptions");
1943 1943
 
1944
-		if (! dol_strlen($modele))
1944
+		if (!dol_strlen($modele))
1945 1945
 		{
1946 1946
 			$modele = 'squille';
1947 1947
 
1948 1948
 			if ($this->modelpdf) {
1949 1949
 				$modele = $this->modelpdf;
1950
-			} elseif (! empty($conf->global->RECEPTION_ADDON_PDF)) {
1950
+			} elseif (!empty($conf->global->RECEPTION_ADDON_PDF)) {
1951 1951
 				$modele = $conf->global->RECEPTION_ADDON_PDF;
1952 1952
 			}
1953 1953
 		}
Please login to merge, or discard this patch.
Braces   +215 added lines, -131 removed lines patch added patch discarded remove patch
@@ -34,8 +34,12 @@  discard block
 block discarded – undo
34 34
 
35 35
 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
36 36
 require_once DOL_DOCUMENT_ROOT."/core/class/commonobjectline.class.php";
37
-if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
38
-if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
37
+if (! empty($conf->propal->enabled)) {
38
+    require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
39
+}
40
+if (! empty($conf->commande->enabled)) {
41
+    require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
42
+}
39 43
 
40 44
 
41 45
 /**
@@ -155,14 +159,12 @@  discard block
 block discarded – undo
155 159
 			if ( $numref != "")
156 160
 			{
157 161
 				return $numref;
158
-			}
159
-			else
162
+			} else
160 163
 			{
161 164
 				dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
162 165
 				return "";
163 166
 			}
164
-        }
165
-	    else
167
+        } else
166 168
 	    {
167 169
 		    print $langs->trans("Error")." ".$langs->trans("Error_RECEPTION_ADDON_NUMBER_NotDefined");
168 170
 		    return "";
@@ -188,7 +190,9 @@  discard block
 block discarded – undo
188 190
 		// Clean parameters
189 191
 		$this->brouillon = 1;
190 192
 		$this->tracking_number = dol_sanitizeFileName($this->tracking_number);
191
-		if (empty($this->fk_project)) $this->fk_project = 0;
193
+		if (empty($this->fk_project)) {
194
+		    $this->fk_project = 0;
195
+		}
192 196
 
193 197
 		$this->user = $user;
194 198
 
@@ -288,16 +292,19 @@  discard block
 block discarded – undo
288 292
 				$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
289 293
 				if (empty($reshook))
290 294
 				{
291
-					if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
295
+					if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
296
+					    // For avoid conflicts if trigger used
292 297
 					{
293 298
 						$result=$this->insertExtraFields();
299
+					}
294 300
 						if ($result < 0)
295 301
 						{
296 302
 							$error++;
297 303
 						}
298 304
 					}
305
+				} else if ($reshook < 0) {
306
+				    $error++;
299 307
 				}
300
-				else if ($reshook < 0) $error++;
301 308
 
302 309
 				if (! $error && ! $notrigger)
303 310
 				{
@@ -310,8 +317,7 @@  discard block
 block discarded – undo
310 317
 					{
311 318
 						$this->db->commit();
312 319
 						return $this->id;
313
-					}
314
-					else
320
+					} else
315 321
 					{
316 322
 						foreach($this->errors as $errmsg)
317 323
 						{
@@ -321,24 +327,21 @@  discard block
 block discarded – undo
321 327
 						$this->db->rollback();
322 328
 						return -1*$error;
323 329
 					}
324
-				}
325
-				else
330
+				} else
326 331
 				{
327 332
 					$error++;
328 333
 					$this->error=$this->db->lasterror()." - sql=$sql";
329 334
 					$this->db->rollback();
330 335
 					return -3;
331 336
 				}
332
-			}
333
-			else
337
+			} else
334 338
 			{
335 339
 				$error++;
336 340
 				$this->error=$this->db->lasterror()." - sql=$sql";
337 341
 				$this->db->rollback();
338 342
 				return -2;
339 343
 			}
340
-		}
341
-		else
344
+		} else
342 345
 		{
343 346
 			$error++;
344 347
 			$this->error=$this->db->error()." - sql=$sql";
@@ -363,7 +366,9 @@  discard block
 block discarded – undo
363 366
 		global $conf;
364 367
 
365 368
 		// Check parameters
366
-		if (empty($id) && empty($ref) && empty($ref_ext) && empty($ref_int)) return -1;
369
+		if (empty($id) && empty($ref) && empty($ref_ext) && empty($ref_int)) {
370
+		    return -1;
371
+		}
367 372
 
368 373
 		$sql = "SELECT e.rowid, e.ref, e.fk_soc as socid, e.date_creation, e.ref_supplier, e.ref_ext, e.ref_int, e.fk_user_author, e.fk_statut";
369 374
 		$sql.= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
@@ -377,10 +382,18 @@  discard block
 block discarded – undo
377 382
 		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element)."'";
378 383
 		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON e.fk_incoterms = i.rowid';
379 384
 		$sql.= " WHERE e.entity IN (".getEntity('reception').")";
380
-		if ($id)   	  $sql.= " AND e.rowid=".$id;
381
-        if ($ref)     $sql.= " AND e.ref='".$this->db->escape($ref)."'";
382
-        if ($ref_ext) $sql.= " AND e.ref_ext='".$this->db->escape($ref_ext)."'";
383
-        if ($ref_int) $sql.= " AND e.ref_int='".$this->db->escape($ref_int)."'";
385
+		if ($id) {
386
+		    $sql.= " AND e.rowid=".$id;
387
+		}
388
+        if ($ref) {
389
+            $sql.= " AND e.ref='".$this->db->escape($ref)."'";
390
+        }
391
+        if ($ref_ext) {
392
+            $sql.= " AND e.ref_ext='".$this->db->escape($ref_ext)."'";
393
+        }
394
+        if ($ref_int) {
395
+            $sql.= " AND e.ref_int='".$this->db->escape($ref_int)."'";
396
+        }
384 397
 
385 398
 		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
386 399
 		$result = $this->db->query($sql);
@@ -435,7 +448,9 @@  discard block
 block discarded – undo
435 448
 
436 449
 				$this->db->free($result);
437 450
 
438
-				if ($this->statut == 0) $this->brouillon = 1;
451
+				if ($this->statut == 0) {
452
+				    $this->brouillon = 1;
453
+				}
439 454
 
440 455
 				$file = $conf->reception->dir_output . "/" .get_exdir($this->id, 2, 0, 0, $this, 'reception') . "/" . $this->id.".pdf";
441 456
 				$this->pdf_filename = $file;
@@ -466,15 +481,13 @@  discard block
 block discarded – undo
466 481
 				}
467 482
 
468 483
 				return 1;
469
-			}
470
-			else
484
+			} else
471 485
 			{
472 486
 				dol_syslog(get_class($this).'::Fetch no reception found', LOG_ERR);
473 487
 				$this->error='Delivery with id '.$id.' not found';
474 488
 				return 0;
475 489
 			}
476
-		}
477
-		else
490
+		} else
478 491
 		{
479 492
 			$this->error=$this->db->error();
480 493
 			return -1;
@@ -521,11 +534,12 @@  discard block
 block discarded – undo
521 534
 
522 535
 
523 536
 		// Define new ref
524
-		if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
537
+		if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) {
538
+		    // empty should not happened, but when it occurs, the test save life
525 539
 		{
526 540
 			$numref = $this->getNextNumRef($soc);
527 541
 		}
528
-		else {
542
+		} else {
529 543
 			$numref = $this->ref;
530 544
 		}
531 545
 
@@ -576,7 +590,9 @@  discard block
 block discarded – undo
576 590
 
577 591
 					$qty = $obj->qty;
578 592
 
579
-					if ($qty <= 0) continue;
593
+					if ($qty <= 0) {
594
+					    continue;
595
+					}
580 596
 					dol_syslog(get_class($this)."::valid movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid);
581 597
 
582 598
 					//var_dump($this->lines[$i]);
@@ -595,8 +611,7 @@  discard block
 block discarded – undo
595 611
 							$this->errors = array_merge($this->errors, $mouvS->errors);
596 612
 							break;
597 613
 						}
598
-					}
599
-					else
614
+					} else
600 615
 					{
601 616
 						// line with batch detail
602 617
 
@@ -611,8 +626,7 @@  discard block
 block discarded – undo
611 626
 						}
612 627
 					}
613 628
 				}
614
-			}
615
-			else
629
+			} else
616 630
 			{
617 631
 				$this->db->rollback();
618 632
 				$this->error=$this->db->error();
@@ -682,8 +696,7 @@  discard block
 block discarded – undo
682 696
 		{
683 697
 			$this->db->commit();
684 698
 			return 1;
685
-		}
686
-		else
699
+		} else
687 700
 		{
688 701
 			foreach($this->errors as $errmsg)
689 702
 			{
@@ -739,8 +752,10 @@  discard block
 block discarded – undo
739 752
 		}
740 753
 
741 754
 		// extrafields
742
-		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
755
+		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) {
756
+		    // For avoid conflicts if trigger used
743 757
 			$line->array_options = $array_options;
758
+		}
744 759
 
745 760
 		$line->fk_product = $fk_product;
746 761
 		$line->fk_commande = $supplierorderline->fk_commande ;
@@ -770,25 +785,63 @@  discard block
 block discarded – undo
770 785
 
771 786
 		// Clean parameters
772 787
 
773
-		if (isset($this->ref)) $this->ref=trim($this->ref);
774
-		if (isset($this->entity)) $this->entity=trim($this->entity);
775
-		if (isset($this->ref_supplier)) $this->ref_supplier=trim($this->ref_supplier);
776
-		if (isset($this->socid)) $this->socid=trim($this->socid);
777
-		if (isset($this->fk_user_author)) $this->fk_user_author=trim($this->fk_user_author);
778
-		if (isset($this->fk_user_valid)) $this->fk_user_valid=trim($this->fk_user_valid);
779
-		if (isset($this->fk_delivery_address)) $this->fk_delivery_address=trim($this->fk_delivery_address);
780
-		if (isset($this->shipping_method_id)) $this->shipping_method_id=trim($this->shipping_method_id);
781
-		if (isset($this->tracking_number)) $this->tracking_number=trim($this->tracking_number);
782
-		if (isset($this->statut)) $this->statut=(int) $this->statut;
783
-		if (isset($this->trueDepth)) $this->trueDepth=trim($this->trueDepth);
784
-		if (isset($this->trueWidth)) $this->trueWidth=trim($this->trueWidth);
785
-		if (isset($this->trueHeight)) $this->trueHeight=trim($this->trueHeight);
786
-		if (isset($this->size_units)) $this->size_units=trim($this->size_units);
787
-		if (isset($this->weight_units)) $this->weight_units=trim($this->weight_units);
788
-		if (isset($this->trueWeight)) $this->weight=trim($this->trueWeight);
789
-		if (isset($this->note_private)) $this->note=trim($this->note_private);
790
-		if (isset($this->note_public)) $this->note=trim($this->note_public);
791
-		if (isset($this->modelpdf)) $this->modelpdf=trim($this->modelpdf);
788
+		if (isset($this->ref)) {
789
+		    $this->ref=trim($this->ref);
790
+		}
791
+		if (isset($this->entity)) {
792
+		    $this->entity=trim($this->entity);
793
+		}
794
+		if (isset($this->ref_supplier)) {
795
+		    $this->ref_supplier=trim($this->ref_supplier);
796
+		}
797
+		if (isset($this->socid)) {
798
+		    $this->socid=trim($this->socid);
799
+		}
800
+		if (isset($this->fk_user_author)) {
801
+		    $this->fk_user_author=trim($this->fk_user_author);
802
+		}
803
+		if (isset($this->fk_user_valid)) {
804
+		    $this->fk_user_valid=trim($this->fk_user_valid);
805
+		}
806
+		if (isset($this->fk_delivery_address)) {
807
+		    $this->fk_delivery_address=trim($this->fk_delivery_address);
808
+		}
809
+		if (isset($this->shipping_method_id)) {
810
+		    $this->shipping_method_id=trim($this->shipping_method_id);
811
+		}
812
+		if (isset($this->tracking_number)) {
813
+		    $this->tracking_number=trim($this->tracking_number);
814
+		}
815
+		if (isset($this->statut)) {
816
+		    $this->statut=(int) $this->statut;
817
+		}
818
+		if (isset($this->trueDepth)) {
819
+		    $this->trueDepth=trim($this->trueDepth);
820
+		}
821
+		if (isset($this->trueWidth)) {
822
+		    $this->trueWidth=trim($this->trueWidth);
823
+		}
824
+		if (isset($this->trueHeight)) {
825
+		    $this->trueHeight=trim($this->trueHeight);
826
+		}
827
+		if (isset($this->size_units)) {
828
+		    $this->size_units=trim($this->size_units);
829
+		}
830
+		if (isset($this->weight_units)) {
831
+		    $this->weight_units=trim($this->weight_units);
832
+		}
833
+		if (isset($this->trueWeight)) {
834
+		    $this->weight=trim($this->trueWeight);
835
+		}
836
+		if (isset($this->note_private)) {
837
+		    $this->note=trim($this->note_private);
838
+		}
839
+		if (isset($this->note_public)) {
840
+		    $this->note=trim($this->note_public);
841
+		}
842
+		if (isset($this->modelpdf)) {
843
+		    $this->modelpdf=trim($this->modelpdf);
844
+		}
792 845
 
793 846
 
794 847
 		// Check parameters
@@ -850,8 +903,7 @@  discard block
 block discarded – undo
850 903
 			}
851 904
 			$this->db->rollback();
852 905
 			return -1*$error;
853
-		}
854
-		else
906
+		} else
855 907
 		{
856 908
 			$this->db->commit();
857 909
 			return 1;
@@ -905,8 +957,7 @@  discard block
 block discarded – undo
905 957
 
906 958
 					$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans("ReceptionDeletedInDolibarr", $this->ref),'', $obj->eatby, $obj->sellby, $obj->batch);  // Price is set to 0, because we don't want to see WAP changed
907 959
 				}
908
-			}
909
-			else
960
+			} else
910 961
 			{
911 962
 				$error++;$this->errors[]="Error ".$this->db->lasterror();
912 963
 			}
@@ -921,7 +972,9 @@  discard block
 block discarded – undo
921 972
 			{
922 973
 				// Delete linked object
923 974
 				$res = $this->deleteObjectLinked();
924
-				if ($res < 0) $error++;
975
+				if ($res < 0) {
976
+				    $error++;
977
+				}
925 978
 
926 979
 				if (! $error)
927 980
 				{
@@ -939,10 +992,12 @@  discard block
 block discarded – undo
939 992
 						{
940 993
 						    $this->fetch_origin();
941 994
 						    $origin=$this->origin;
942
-						    if ($this->$origin->statut == 4)     // If order source of reception is "partially received"
995
+						    if ($this->$origin->statut == 4) {
996
+						        // If order source of reception is "partially received"
943 997
 						    {
944 998
                                 // Check if there is no more reception. If not, we can move back status of order to "validated" instead of "reception in progress"
945 999
 						        $this->$origin->loadReceptions();
1000
+						    }
946 1001
 						        //var_dump($this->$origin->receptions);exit;
947 1002
 						        if (count($this->$origin->receptions) <= 0)
948 1003
 						        {
@@ -979,35 +1034,30 @@  discard block
 block discarded – undo
979 1034
 							}
980 1035
 
981 1036
 							return 1;
982
-						}
983
-						else
1037
+						} else
984 1038
 						{
985 1039
 							$this->db->rollback();
986 1040
 							return -1;
987 1041
 						}
988
-					}
989
-					else
1042
+					} else
990 1043
 					{
991 1044
 						$this->error=$this->db->lasterror()." - sql=$sql";
992 1045
 						$this->db->rollback();
993 1046
 						return -3;
994 1047
 					}
995
-				}
996
-				else
1048
+				} else
997 1049
 				{
998 1050
 					$this->error=$this->db->lasterror()." - sql=$sql";
999 1051
 					$this->db->rollback();
1000 1052
 					return -2;
1001 1053
 				}
1002
-			}
1003
-			else
1054
+			} else
1004 1055
 			{
1005 1056
 				$this->error=$this->db->lasterror()." - sql=$sql";
1006 1057
 				$this->db->rollback();
1007 1058
 				return -1;
1008 1059
 			}
1009
-		}
1010
-		else
1060
+		} else
1011 1061
 		{
1012 1062
 			$this->db->rollback();
1013 1063
 			return -1;
@@ -1048,7 +1098,7 @@  discard block
 block discarded – undo
1048 1098
 					$line->remise_percent = $obj->remise_percent;
1049 1099
 					$line->label = !empty($obj->label)?$obj->label:$line->product->label;
1050 1100
 					$line->ref_supplier = $obj->ref;
1051
-				}else {
1101
+				} else {
1052 1102
 					$line->qty_asked = 0;
1053 1103
 					$line->description = '';
1054 1104
 					$line->label = $obj->label;
@@ -1066,8 +1116,7 @@  discard block
 block discarded – undo
1066 1116
 			}
1067 1117
 
1068 1118
 			return 1;
1069
-		}
1070
-		else {
1119
+		} else {
1071 1120
 			return -1;
1072 1121
 		}
1073 1122
 	}
@@ -1092,7 +1141,9 @@  discard block
 block discarded – undo
1092 1141
 
1093 1142
 		$url = DOL_URL_ROOT.'/reception/card.php?id='.$this->id;
1094 1143
 
1095
-		if ($short) return $url;
1144
+		if ($short) {
1145
+		    return $url;
1146
+		}
1096 1147
 
1097 1148
 		$linkclose='';
1098 1149
 		if (empty($notooltip))
@@ -1111,8 +1162,12 @@  discard block
 block discarded – undo
1111 1162
 
1112 1163
 		$picto='sending';
1113 1164
 
1114
-		if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
1115
-		if ($withpicto && $withpicto != 2) $result.=' ';
1165
+		if ($withpicto) {
1166
+		    $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
1167
+		}
1168
+		if ($withpicto && $withpicto != 2) {
1169
+		    $result.=' ';
1170
+		}
1116 1171
 		$result.=$linkstart.$this->ref.$linkend;
1117 1172
 		return $result;
1118 1173
 	}
@@ -1143,33 +1198,63 @@  discard block
 block discarded – undo
1143 1198
 
1144 1199
 		if ($mode==0)
1145 1200
 		{
1146
-			if ($statut==0) return $langs->trans($this->statuts[$statut]);
1147
-			if ($statut==1)  return $langs->trans($this->statuts[$statut]);
1148
-			if ($statut==2)  return $langs->trans($this->statuts[$statut]);
1201
+			if ($statut==0) {
1202
+			    return $langs->trans($this->statuts[$statut]);
1203
+			}
1204
+			if ($statut==1) {
1205
+			    return $langs->trans($this->statuts[$statut]);
1206
+			}
1207
+			if ($statut==2) {
1208
+			    return $langs->trans($this->statuts[$statut]);
1209
+			}
1149 1210
 		}
1150 1211
 		if ($mode==1)
1151 1212
 		{
1152
-			if ($statut==0) return $langs->trans('StatusReceptionDraftShort');
1153
-			if ($statut==1) return $langs->trans('StatusReceptionValidatedShort');
1154
-			if ($statut==2) return $langs->trans('StatusReceptionProcessedShort');
1213
+			if ($statut==0) {
1214
+			    return $langs->trans('StatusReceptionDraftShort');
1215
+			}
1216
+			if ($statut==1) {
1217
+			    return $langs->trans('StatusReceptionValidatedShort');
1218
+			}
1219
+			if ($statut==2) {
1220
+			    return $langs->trans('StatusReceptionProcessedShort');
1221
+			}
1155 1222
 		}
1156 1223
 		if ($mode == 3)
1157 1224
 		{
1158
-			if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0');
1159
-			if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut4');
1160
-			if ($statut==2) return img_picto($langs->trans('StatusReceptionProcessed'),'statut6');
1225
+			if ($statut==0) {
1226
+			    return img_picto($langs->trans($this->statuts[$statut]),'statut0');
1227
+			}
1228
+			if ($statut==1) {
1229
+			    return img_picto($langs->trans($this->statuts[$statut]),'statut4');
1230
+			}
1231
+			if ($statut==2) {
1232
+			    return img_picto($langs->trans('StatusReceptionProcessed'),'statut6');
1233
+			}
1161 1234
 		}
1162 1235
 		if ($mode == 4)
1163 1236
 		{
1164
-			if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
1165
-			if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
1166
-			if ($statut==2) return img_picto($langs->trans('StatusReceptionProcessed'),'statut6').' '.$langs->trans('StatusReceptionProcessed');
1237
+			if ($statut==0) {
1238
+			    return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
1239
+			}
1240
+			if ($statut==1) {
1241
+			    return img_picto($langs->trans($this->statuts[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
1242
+			}
1243
+			if ($statut==2) {
1244
+			    return img_picto($langs->trans('StatusReceptionProcessed'),'statut6').' '.$langs->trans('StatusReceptionProcessed');
1245
+			}
1167 1246
 		}
1168 1247
 		if ($mode == 5)
1169 1248
 		{
1170
-			if ($statut==0) return $langs->trans('StatusReceptionDraftShort').' '.img_picto($langs->trans($this->statuts[$statut]),'statut0');
1171
-			if ($statut==1) return $langs->trans('StatusReceptionValidatedShort').' '.img_picto($langs->trans($this->statuts[$statut]),'statut4');
1172
-			if ($statut==2) return $langs->trans('StatusReceptionProcessedShort').' '.img_picto($langs->trans('StatusReceptionProcessedShort'),'statut6');
1249
+			if ($statut==0) {
1250
+			    return $langs->trans('StatusReceptionDraftShort').' '.img_picto($langs->trans($this->statuts[$statut]),'statut0');
1251
+			}
1252
+			if ($statut==1) {
1253
+			    return $langs->trans('StatusReceptionValidatedShort').' '.img_picto($langs->trans($this->statuts[$statut]),'statut4');
1254
+			}
1255
+			if ($statut==2) {
1256
+			    return $langs->trans('StatusReceptionProcessedShort').' '.img_picto($langs->trans('StatusReceptionProcessedShort'),'statut6');
1257
+			}
1173 1258
 		}
1174 1259
 	}
1175 1260
 
@@ -1274,14 +1359,12 @@  discard block
 block discarded – undo
1274 1359
 			{
1275 1360
 				$this->date_delivery = $date_livraison;
1276 1361
 				return 1;
1277
-			}
1278
-			else
1362
+			} else
1279 1363
 			{
1280 1364
 				$this->error=$this->db->error();
1281 1365
 				return -1;
1282 1366
 			}
1283
-		}
1284
-		else
1367
+		} else
1285 1368
 		{
1286 1369
 			return -2;
1287 1370
 		}
@@ -1332,7 +1415,9 @@  discard block
 block discarded – undo
1332 1415
 
1333 1416
         $sql = "SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1334 1417
         $sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1335
-        if ($id!='') $sql.= " WHERE em.rowid=".$id;
1418
+        if ($id!='') {
1419
+            $sql.= " WHERE em.rowid=".$id;
1420
+        }
1336 1421
 
1337 1422
         $resql = $this->db->query($sql);
1338 1423
         if ($resql)
@@ -1367,8 +1452,7 @@  discard block
 block discarded – undo
1367 1452
             $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_shipment_mode (code, libelle, description, tracking)";
1368 1453
             $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'])."')";
1369 1454
             $resql = $this->db->query($sql);
1370
-        }
1371
-        else
1455
+        } else
1372 1456
         {
1373 1457
             $sql = "UPDATE ".MAIN_DB_PREFIX."c_shipment_mode SET";
1374 1458
             $sql.= " code='".$this->db->escape($this->update['code'])."'";
@@ -1378,7 +1462,9 @@  discard block
 block discarded – undo
1378 1462
             $sql.= " WHERE rowid=".$id;
1379 1463
             $resql = $this->db->query($sql);
1380 1464
         }
1381
-        if ($resql < 0) dol_print_error($this->db,'');
1465
+        if ($resql < 0) {
1466
+            dol_print_error($this->db,'');
1467
+        }
1382 1468
     }
1383 1469
 
1384 1470
 	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -1444,8 +1530,7 @@  discard block
 block discarded – undo
1444 1530
 		{
1445 1531
 			$url = str_replace('{TRACKID}', $value, $tracking);
1446 1532
 			$this->tracking_url = sprintf('<a target="_blank" href="%s">'.($value?$value:'url').'</a>',$url,$url);
1447
-		}
1448
-		else
1533
+		} else
1449 1534
 		{
1450 1535
 			$this->tracking_url = $value;
1451 1536
 		}
@@ -1530,7 +1615,9 @@  discard block
 block discarded – undo
1530 1615
 
1531 1616
 						$qty = $obj->qty;
1532 1617
 
1533
-						if ($qty <= 0) continue;
1618
+						if ($qty <= 0) {
1619
+						    continue;
1620
+						}
1534 1621
 						dol_syslog(get_class($this)."::valid movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid);
1535 1622
 
1536 1623
 						$mouvS = new MouvementStock($this->db);
@@ -1547,8 +1634,7 @@  discard block
 block discarded – undo
1547 1634
 							    $this->errors = $mouvS->errors;
1548 1635
 								$error++; break;
1549 1636
 							}
1550
-						}
1551
-						else
1637
+						} else
1552 1638
 						{
1553 1639
 							// line with batch detail
1554 1640
 
@@ -1562,8 +1648,7 @@  discard block
 block discarded – undo
1562 1648
 							}
1563 1649
 						}
1564 1650
 					}
1565
-				}
1566
-				else
1651
+				} else
1567 1652
 				{
1568 1653
 					$this->error=$this->db->lasterror();
1569 1654
 					$error++;
@@ -1578,8 +1663,7 @@  discard block
 block discarded – undo
1578 1663
     			    $error++;
1579 1664
     			}
1580 1665
 			}
1581
-		}
1582
-		else
1666
+		} else
1583 1667
 		{
1584 1668
 			dol_print_error($this->db);
1585 1669
             $error++;
@@ -1589,8 +1673,7 @@  discard block
 block discarded – undo
1589 1673
 		{
1590 1674
 		    $this->db->commit();
1591 1675
 		    return 1;
1592
-		}
1593
-		else
1676
+		} else
1594 1677
 		{
1595 1678
 		    $this->db->rollback();
1596 1679
 		    return -1;
@@ -1635,8 +1718,7 @@  discard block
 block discarded – undo
1635 1718
 		if (empty($error)) {
1636 1719
 			$this->db->commit();
1637 1720
 			return 1;
1638
-		}
1639
-		else
1721
+		} else
1640 1722
 		{
1641 1723
 			$this->db->rollback();
1642 1724
 			return -1;
@@ -1693,7 +1775,9 @@  discard block
 block discarded – undo
1693 1775
 
1694 1776
 						$qty = $obj->qty;
1695 1777
 
1696
-						if ($qty <= 0) continue;
1778
+						if ($qty <= 0) {
1779
+						    continue;
1780
+						}
1697 1781
 
1698 1782
 						dol_syslog(get_class($this)."::reopen reception movement index ".$i." ed.rowid=".$obj->rowid);
1699 1783
 
@@ -1712,8 +1796,7 @@  discard block
 block discarded – undo
1712 1796
 							    $this->errors = $mouvS->errors;
1713 1797
 								$error++; break;
1714 1798
 							}
1715
-						}
1716
-						else
1799
+						} else
1717 1800
 						{
1718 1801
 							// line with batch detail
1719 1802
 
@@ -1726,8 +1809,7 @@  discard block
 block discarded – undo
1726 1809
 							}
1727 1810
 						}
1728 1811
 					}
1729
-				}
1730
-				else
1812
+				} else
1731 1813
 				{
1732 1814
 					$this->error=$this->db->lasterror();
1733 1815
 					$error++;
@@ -1757,8 +1839,7 @@  discard block
 block discarded – undo
1757 1839
 		{
1758 1840
 			$this->db->commit();
1759 1841
 			return 1;
1760
-		}
1761
-		else
1842
+		} else
1762 1843
 		{
1763 1844
 			$this->db->rollback();
1764 1845
 			return -1;
@@ -1831,7 +1912,9 @@  discard block
 block discarded – undo
1831 1912
 						$qty = $obj->qty;
1832 1913
 
1833 1914
 
1834
-						if ($qty <= 0) continue;
1915
+						if ($qty <= 0) {
1916
+						    continue;
1917
+						}
1835 1918
 						dol_syslog(get_class($this)."::reopen reception movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid);
1836 1919
 
1837 1920
 						//var_dump($this->lines[$i]);
@@ -1850,8 +1933,7 @@  discard block
 block discarded – undo
1850 1933
 								$error++;
1851 1934
 								break;
1852 1935
 							}
1853
-						}
1854
-						else
1936
+						} else
1855 1937
 						{
1856 1938
 							// line with batch detail
1857 1939
 
@@ -1864,8 +1946,7 @@  discard block
 block discarded – undo
1864 1946
 							}
1865 1947
 						}
1866 1948
 					}
1867
-				}
1868
-				else
1949
+				} else
1869 1950
 				{
1870 1951
 					$this->error=$this->db->lasterror();
1871 1952
 					$error++;
@@ -1875,7 +1956,9 @@  discard block
 block discarded – undo
1875 1956
             if (!$error) {
1876 1957
             	// Call trigger
1877 1958
             	$result=$this->call_trigger('RECEPTION_UNVALIDATE',$user);
1878
-            	if ($result < 0) $error++;
1959
+            	if ($result < 0) {
1960
+            	    $error++;
1961
+            	}
1879 1962
             }
1880 1963
 			if ($this->origin == 'order_supplier')
1881 1964
 			{
@@ -1883,10 +1966,12 @@  discard block
 block discarded – undo
1883 1966
 				{
1884 1967
 					$this->fetch_origin();
1885 1968
 					$origin = $this->origin;
1886
-					if ($this->$origin->statut == 4)  // If order source of reception is "partially received"
1969
+					if ($this->$origin->statut == 4) {
1970
+					    // If order source of reception is "partially received"
1887 1971
 					{
1888 1972
 						// Check if there is no more reception validated.
1889 1973
 						$this->$origin->fetchObjectLinked();
1974
+					}
1890 1975
 						$setStatut = 1;
1891 1976
 						if (!empty($this->$origin->linkedObjects['reception']))
1892 1977
 						{
@@ -1912,12 +1997,11 @@  discard block
 block discarded – undo
1912 1997
            		$this->statut=self::STATUS_DRAFT;
1913 1998
             	$this->db->commit();
1914 1999
             	return 1;
1915
-            }else {
2000
+            } else {
1916 2001
             	$this->db->rollback();
1917 2002
             	return -1;
1918 2003
             }
1919
-        }
1920
-        else
2004
+        } else
1921 2005
         {
1922 2006
             $this->error=$this->db->error();
1923 2007
             $this->db->rollback();
Please login to merge, or discard this patch.
dolibarr/htdocs/reception/class/receptionstats.class.php 3 patches
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -34,13 +34,13 @@  discard block
 block discarded – undo
34 34
  */
35 35
 class ReceptionStats extends Stats
36 36
 {
37
-	public $table_element;
37
+    public $table_element;
38 38
 
39
-	var $socid;
39
+    var $socid;
40 40
     var $userid;
41 41
 
42 42
     var $from;
43
-	var $field;
43
+    var $field;
44 44
     var $where;
45 45
 
46 46
 
@@ -48,95 +48,95 @@  discard block
 block discarded – undo
48 48
      * Constructor
49 49
      *
50 50
      * @param	DoliDB	$db      	Database handler
51
-	 * @param 	int		$socid	   	Id third party for filter
52
-	 * @param 	string	$mode	   	Option (not used)
53
-	 * @param   int		$userid    	Id user for filter (creation user)
51
+     * @param 	int		$socid	   	Id third party for filter
52
+     * @param 	string	$mode	   	Option (not used)
53
+     * @param   int		$userid    	Id user for filter (creation user)
54 54
      */
55 55
     function __construct($db, $socid, $mode, $userid=0)
56 56
     {
57
-		global $user, $conf;
57
+        global $user, $conf;
58 58
 
59
-		$this->db = $db;
59
+        $this->db = $db;
60 60
 
61
-		$this->socid = ($socid > 0 ? $socid : 0);
61
+        $this->socid = ($socid > 0 ? $socid : 0);
62 62
         $this->userid = $userid;
63
-		$this->cachefilesuffix = $mode;
63
+        $this->cachefilesuffix = $mode;
64 64
 
65 65
         $object=new Reception($this->db);
66
-		$this->from = MAIN_DB_PREFIX.$object->table_element." as c";
67
-		//$this->from.= ", ".MAIN_DB_PREFIX."societe as s";
68
-		$this->field='weight';	// Warning, unit of weight is NOT USED AND MUST BE
69
-		$this->where.= " c.fk_statut > 0";    // Not draft and not cancelled
70
-
71
-		//$this->where.= " AND c.fk_soc = s.rowid AND c.entity = ".$conf->entity;
72
-		$this->where.= " AND c.entity = ".$conf->entity;
73
-		if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
74
-		if ($this->socid)
75
-		{
76
-			$this->where.=" AND c.fk_soc = ".$this->socid;
77
-		}
66
+        $this->from = MAIN_DB_PREFIX.$object->table_element." as c";
67
+        //$this->from.= ", ".MAIN_DB_PREFIX."societe as s";
68
+        $this->field='weight';	// Warning, unit of weight is NOT USED AND MUST BE
69
+        $this->where.= " c.fk_statut > 0";    // Not draft and not cancelled
70
+
71
+        //$this->where.= " AND c.fk_soc = s.rowid AND c.entity = ".$conf->entity;
72
+        $this->where.= " AND c.entity = ".$conf->entity;
73
+        if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
74
+        if ($this->socid)
75
+        {
76
+            $this->where.=" AND c.fk_soc = ".$this->socid;
77
+        }
78 78
         if ($this->userid > 0) $this->where.=' AND c.fk_user_author = '.$this->userid;
79 79
     }
80 80
 
81 81
     /**
82 82
      * Return reception number by month for a year
83 83
      *
84
-	 * @param	int		$year		Year to scan
85
-	 * @return	array				Array with number by month
84
+     * @param	int		$year		Year to scan
85
+     * @return	array				Array with number by month
86 86
      */
87 87
     function getNbByMonth($year)
88 88
     {
89 89
         global $user;
90 90
 
91 91
         $sql = "SELECT date_format(c.date_valid,'%m') as dm, COUNT(*) as nb";
92
-		$sql.= " FROM ".$this->from;
93
-		if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
94
-		$sql.= " WHERE c.date_valid BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
95
-		$sql.= " AND ".$this->where;
96
-		$sql.= " GROUP BY dm";
92
+        $sql.= " FROM ".$this->from;
93
+        if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
94
+        $sql.= " WHERE c.date_valid BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
95
+        $sql.= " AND ".$this->where;
96
+        $sql.= " GROUP BY dm";
97 97
         $sql.= $this->db->order('dm','DESC');
98 98
 
99
-		$res=$this->_getNbByMonth($year, $sql);
100
-		return $res;
99
+        $res=$this->_getNbByMonth($year, $sql);
100
+        return $res;
101 101
     }
102 102
 
103
-	/**
104
-	 * Return receptions number per year
105
-	 *
106
-	 * @return	array	Array with number by year
107
-	 *
108
-	 */
109
-	function getNbByYear()
110
-	{
111
-		global $user;
112
-
113
-		$sql = "SELECT date_format(c.date_valid,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")";
114
-		$sql.= " FROM ".$this->from;
115
-		if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
116
-		$sql.= " WHERE ".$this->where;
117
-		$sql.= " GROUP BY dm";
103
+    /**
104
+     * Return receptions number per year
105
+     *
106
+     * @return	array	Array with number by year
107
+     *
108
+     */
109
+    function getNbByYear()
110
+    {
111
+        global $user;
112
+
113
+        $sql = "SELECT date_format(c.date_valid,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")";
114
+        $sql.= " FROM ".$this->from;
115
+        if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
116
+        $sql.= " WHERE ".$this->where;
117
+        $sql.= " GROUP BY dm";
118 118
         $sql.= $this->db->order('dm','DESC');
119 119
 
120
-		return $this->_getNbByYear($sql);
121
-	}
122
-
123
-	/**
124
-	 *	Return nb, total and average
125
-	 *
126
-	 *	@return	array	Array of values
127
-	 */
128
-	function getAllByYear()
129
-	{
130
-		global $user;
131
-
132
-		$sql = "SELECT date_format(c.date_valid,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->field.") as total, AVG(".$this->field.") as avg";
133
-		$sql.= " FROM ".$this->from;
134
-		if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
135
-		$sql.= " WHERE ".$this->where;
136
-		$sql.= " GROUP BY year";
137
-		$sql.= $this->db->order('year','DESC');
138
-
139
-		return $this->_getAllByYear($sql);
140
-	}
120
+        return $this->_getNbByYear($sql);
121
+    }
122
+
123
+    /**
124
+     *	Return nb, total and average
125
+     *
126
+     *	@return	array	Array of values
127
+     */
128
+    function getAllByYear()
129
+    {
130
+        global $user;
131
+
132
+        $sql = "SELECT date_format(c.date_valid,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->field.") as total, AVG(".$this->field.") as avg";
133
+        $sql.= " FROM ".$this->from;
134
+        if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
135
+        $sql.= " WHERE ".$this->where;
136
+        $sql.= " GROUP BY year";
137
+        $sql.= $this->db->order('year','DESC');
138
+
139
+        return $this->_getAllByYear($sql);
140
+    }
141 141
 }
142 142
 
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 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 reception statistics
25 25
  */
26 26
 
27
-include_once DOL_DOCUMENT_ROOT . '/core/class/stats.class.php';
28
-include_once DOL_DOCUMENT_ROOT . '/reception/class/reception.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.'/reception/class/reception.class.php';
29
+include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
30 30
 
31 31
 
32 32
 /**
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 * @param 	string	$mode	   	Option (not used)
53 53
 	 * @param   int		$userid    	Id user for filter (creation user)
54 54
      */
55
-    function __construct($db, $socid, $mode, $userid=0)
55
+    function __construct($db, $socid, $mode, $userid = 0)
56 56
     {
57 57
 		global $user, $conf;
58 58
 
@@ -62,20 +62,20 @@  discard block
 block discarded – undo
62 62
         $this->userid = $userid;
63 63
 		$this->cachefilesuffix = $mode;
64 64
 
65
-        $object=new Reception($this->db);
65
+        $object = new Reception($this->db);
66 66
 		$this->from = MAIN_DB_PREFIX.$object->table_element." as c";
67 67
 		//$this->from.= ", ".MAIN_DB_PREFIX."societe as s";
68
-		$this->field='weight';	// Warning, unit of weight is NOT USED AND MUST BE
69
-		$this->where.= " c.fk_statut > 0";    // Not draft and not cancelled
68
+		$this->field = 'weight'; // Warning, unit of weight is NOT USED AND MUST BE
69
+		$this->where .= " c.fk_statut > 0"; // Not draft and not cancelled
70 70
 
71 71
 		//$this->where.= " AND c.fk_soc = s.rowid AND c.entity = ".$conf->entity;
72
-		$this->where.= " AND c.entity = ".$conf->entity;
73
-		if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
72
+		$this->where .= " AND c.entity = ".$conf->entity;
73
+		if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id;
74 74
 		if ($this->socid)
75 75
 		{
76
-			$this->where.=" AND c.fk_soc = ".$this->socid;
76
+			$this->where .= " AND c.fk_soc = ".$this->socid;
77 77
 		}
78
-        if ($this->userid > 0) $this->where.=' AND c.fk_user_author = '.$this->userid;
78
+        if ($this->userid > 0) $this->where .= ' AND c.fk_user_author = '.$this->userid;
79 79
     }
80 80
 
81 81
     /**
@@ -89,14 +89,14 @@  discard block
 block discarded – undo
89 89
         global $user;
90 90
 
91 91
         $sql = "SELECT date_format(c.date_valid,'%m') as dm, COUNT(*) as nb";
92
-		$sql.= " FROM ".$this->from;
92
+		$sql .= " FROM ".$this->from;
93 93
 		if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
94
-		$sql.= " WHERE c.date_valid BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
95
-		$sql.= " AND ".$this->where;
96
-		$sql.= " GROUP BY dm";
97
-        $sql.= $this->db->order('dm','DESC');
94
+		$sql .= " WHERE c.date_valid BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
95
+		$sql .= " AND ".$this->where;
96
+		$sql .= " GROUP BY dm";
97
+        $sql .= $this->db->order('dm', 'DESC');
98 98
 
99
-		$res=$this->_getNbByMonth($year, $sql);
99
+		$res = $this->_getNbByMonth($year, $sql);
100 100
 		return $res;
101 101
     }
102 102
 
@@ -111,11 +111,11 @@  discard block
 block discarded – undo
111 111
 		global $user;
112 112
 
113 113
 		$sql = "SELECT date_format(c.date_valid,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")";
114
-		$sql.= " FROM ".$this->from;
114
+		$sql .= " FROM ".$this->from;
115 115
 		if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
116
-		$sql.= " WHERE ".$this->where;
117
-		$sql.= " GROUP BY dm";
118
-        $sql.= $this->db->order('dm','DESC');
116
+		$sql .= " WHERE ".$this->where;
117
+		$sql .= " GROUP BY dm";
118
+        $sql .= $this->db->order('dm', 'DESC');
119 119
 
120 120
 		return $this->_getNbByYear($sql);
121 121
 	}
@@ -130,11 +130,11 @@  discard block
 block discarded – undo
130 130
 		global $user;
131 131
 
132 132
 		$sql = "SELECT date_format(c.date_valid,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->field.") as total, AVG(".$this->field.") as avg";
133
-		$sql.= " FROM ".$this->from;
133
+		$sql .= " FROM ".$this->from;
134 134
 		if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
135
-		$sql.= " WHERE ".$this->where;
136
-		$sql.= " GROUP BY year";
137
-		$sql.= $this->db->order('year','DESC');
135
+		$sql .= " WHERE ".$this->where;
136
+		$sql .= " GROUP BY year";
137
+		$sql .= $this->db->order('year', 'DESC');
138 138
 
139 139
 		return $this->_getAllByYear($sql);
140 140
 	}
Please login to merge, or discard this patch.
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -70,12 +70,16 @@  discard block
 block discarded – undo
70 70
 
71 71
 		//$this->where.= " AND c.fk_soc = s.rowid AND c.entity = ".$conf->entity;
72 72
 		$this->where.= " AND c.entity = ".$conf->entity;
73
-		if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
73
+		if (!$user->rights->societe->client->voir && !$this->socid) {
74
+		    $this->where .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
75
+		}
74 76
 		if ($this->socid)
75 77
 		{
76 78
 			$this->where.=" AND c.fk_soc = ".$this->socid;
77 79
 		}
78
-        if ($this->userid > 0) $this->where.=' AND c.fk_user_author = '.$this->userid;
80
+        if ($this->userid > 0) {
81
+            $this->where.=' AND c.fk_user_author = '.$this->userid;
82
+        }
79 83
     }
80 84
 
81 85
     /**
@@ -90,7 +94,9 @@  discard block
 block discarded – undo
90 94
 
91 95
         $sql = "SELECT date_format(c.date_valid,'%m') as dm, COUNT(*) as nb";
92 96
 		$sql.= " FROM ".$this->from;
93
-		if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
97
+		if (!$user->rights->societe->client->voir && !$this->socid) {
98
+		    $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
99
+		}
94 100
 		$sql.= " WHERE c.date_valid BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
95 101
 		$sql.= " AND ".$this->where;
96 102
 		$sql.= " GROUP BY dm";
@@ -112,7 +118,9 @@  discard block
 block discarded – undo
112 118
 
113 119
 		$sql = "SELECT date_format(c.date_valid,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")";
114 120
 		$sql.= " FROM ".$this->from;
115
-		if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
121
+		if (!$user->rights->societe->client->voir && !$this->socid) {
122
+		    $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
123
+		}
116 124
 		$sql.= " WHERE ".$this->where;
117 125
 		$sql.= " GROUP BY dm";
118 126
         $sql.= $this->db->order('dm','DESC');
@@ -131,7 +139,9 @@  discard block
 block discarded – undo
131 139
 
132 140
 		$sql = "SELECT date_format(c.date_valid,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->field.") as total, AVG(".$this->field.") as avg";
133 141
 		$sql.= " FROM ".$this->from;
134
-		if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
142
+		if (!$user->rights->societe->client->voir && !$this->socid) {
143
+		    $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
144
+		}
135 145
 		$sql.= " WHERE ".$this->where;
136 146
 		$sql.= " GROUP BY year";
137 147
 		$sql.= $this->db->order('year','DESC');
Please login to merge, or discard this patch.
dolibarr/htdocs/reception/card.php 3 patches
Indentation   +1673 added lines, -1673 removed lines patch added patch discarded remove patch
@@ -47,8 +47,8 @@  discard block
 block discarded – undo
47 47
 if (! empty($conf->product->enabled) || ! empty($conf->service->enabled))  require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
48 48
 if (! empty($conf->propal->enabled))   require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
49 49
 if (! empty($conf->fournisseur->enabled)){
50
-	require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
51
-	require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
50
+    require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
51
+    require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
52 52
 }
53 53
 if (! empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
54 54
 if (! empty($conf->projet->enabled)) {
@@ -76,16 +76,16 @@  discard block
 block discarded – undo
76 76
 
77 77
 if ($origin == 'reception') $result=restrictedArea($user, $origin, $id);
78 78
 else {
79
-	$result=restrictedArea($user, 'reception');
80
-	if($origin == 'supplierorder'){
81
-		if (empty($user->rights->fournisseur->commande->lire) && empty($user->rights->fournisseur->commande->read)) accessforbidden();
82
-	}else if (empty($user->rights->{$origin}->lire) && empty($user->rights->{$origin}->read)) accessforbidden();
79
+    $result=restrictedArea($user, 'reception');
80
+    if($origin == 'supplierorder'){
81
+        if (empty($user->rights->fournisseur->commande->lire) && empty($user->rights->fournisseur->commande->read)) accessforbidden();
82
+    }else if (empty($user->rights->{$origin}->lire) && empty($user->rights->{$origin}->read)) accessforbidden();
83 83
 }
84 84
 
85 85
 $action		= GETPOST('action','alpha');
86 86
 //Select mail models is same action as presend
87 87
 if (GETPOST('modelselected')) {
88
-	$action = 'presend';
88
+    $action = 'presend';
89 89
 }
90 90
 $confirm	= GETPOST('confirm','alpha');
91 91
 $cancel     = GETPOST('cancel','alpha');
@@ -127,52 +127,52 @@  discard block
 block discarded – undo
127 127
 if (empty($reshook))
128 128
 {
129 129
     if ($cancel)
130
-	{
131
-		$action = '';
132
-		$object->fetch($id); // show reception also after canceling modification
133
-	}
130
+    {
131
+        $action = '';
132
+        $object->fetch($id); // show reception also after canceling modification
133
+    }
134 134
 
135
-	include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';		// Must be include, not include_once
135
+    include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';		// Must be include, not include_once
136 136
 
137
-	// Reopen
138
-	if ($action == 'reopen' && $user->rights->reception->creer)
139
-	{
140
-	    $object->fetch($id);
141
-	    $result = $object->reOpen();
142
-	}
137
+    // Reopen
138
+    if ($action == 'reopen' && $user->rights->reception->creer)
139
+    {
140
+        $object->fetch($id);
141
+        $result = $object->reOpen();
142
+    }
143 143
 
144
-	// Confirm back to draft status
145
-	if ($action == 'modif' && $user->rights->reception->creer)
146
-	{
147
-		$result = $object->set_draft($user);
148
-		if ($result >= 0)
149
-		{
150
-			// Define output language
151
-			if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
152
-			{
153
-				$outputlangs = $langs;
154
-				$newlang = '';
155
-				if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
156
-				if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $object->thirdparty->default_lang;
157
-				if (! empty($newlang)) {
158
-					$outputlangs = new Translate("", $conf);
159
-					$outputlangs->setDefaultLang($newlang);
160
-				}
161
-				$model=$object->modelpdf;
162
-				$ret = $object->fetch($id); // Reload to get new records
163
-				$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
164
-			}
165
-		}
166
-	}
167
-
168
-	// Set incoterm
169
-	if ($action == 'set_incoterms' && !empty($conf->incoterm->enabled))
170
-	{
171
-	    $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
172
-	}
144
+    // Confirm back to draft status
145
+    if ($action == 'modif' && $user->rights->reception->creer)
146
+    {
147
+        $result = $object->set_draft($user);
148
+        if ($result >= 0)
149
+        {
150
+            // Define output language
151
+            if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
152
+            {
153
+                $outputlangs = $langs;
154
+                $newlang = '';
155
+                if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
156
+                if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $object->thirdparty->default_lang;
157
+                if (! empty($newlang)) {
158
+                    $outputlangs = new Translate("", $conf);
159
+                    $outputlangs->setDefaultLang($newlang);
160
+                }
161
+                $model=$object->modelpdf;
162
+                $ret = $object->fetch($id); // Reload to get new records
163
+                $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
164
+            }
165
+        }
166
+    }
173 167
 
174
-	if ($action == 'setref_supplier')
175
-	{
168
+    // Set incoterm
169
+    if ($action == 'set_incoterms' && !empty($conf->incoterm->enabled))
170
+    {
171
+        $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
172
+    }
173
+
174
+    if ($action == 'setref_supplier')
175
+    {
176 176
         $result = $object->fetch($id);
177 177
         if ($result < 0) {
178 178
             setEventMessages($object->error, $object->errors, 'errors');
@@ -186,259 +186,259 @@  discard block
 block discarded – undo
186 186
             header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
187 187
             exit;
188 188
         }
189
-	}
189
+    }
190 190
 
191
-	if ($action == 'update_extras')
192
-	{
193
-	    // Fill array 'array_options' with data from update form
194
-	    $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
195
-	    $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
196
-	    if ($ret < 0) $error++;
191
+    if ($action == 'update_extras')
192
+    {
193
+        // Fill array 'array_options' with data from update form
194
+        $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
195
+        $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
196
+        if ($ret < 0) $error++;
197 197
 
198
-	    if (! $error)
199
-	    {
200
-	        // Actions on extra fields (by external module or standard code)
201
-	        // TODO le hook fait double emploi avec le trigger !!
202
-	        $hookmanager->initHooks(array('receptiondao'));
203
-	        $parameters = array('id' => $object->id);
204
-	        $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
205
-	        if (empty($reshook)) {
206
-	            $result = $object->insertExtraFields();
207
-       			if ($result < 0)
208
-				{
209
-					setEventMessages($object->error, $object->errors, 'errors');
210
-					$error++;
211
-				}
212
-	        } else if ($reshook < 0)
213
-	            $error++;
214
-	    }
198
+        if (! $error)
199
+        {
200
+            // Actions on extra fields (by external module or standard code)
201
+            // TODO le hook fait double emploi avec le trigger !!
202
+            $hookmanager->initHooks(array('receptiondao'));
203
+            $parameters = array('id' => $object->id);
204
+            $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
205
+            if (empty($reshook)) {
206
+                $result = $object->insertExtraFields();
207
+                    if ($result < 0)
208
+                {
209
+                    setEventMessages($object->error, $object->errors, 'errors');
210
+                    $error++;
211
+                }
212
+            } else if ($reshook < 0)
213
+                $error++;
214
+        }
215 215
 
216
-	    if ($error)
217
-	        $action = 'edit_extras';
218
-	}
216
+        if ($error)
217
+            $action = 'edit_extras';
218
+    }
219 219
 
220
-	// Create reception
221
-	if ($action == 'add' && $user->rights->reception->creer)
222
-	{
220
+    // Create reception
221
+    if ($action == 'add' && $user->rights->reception->creer)
222
+    {
223 223
 
224
-		$error = 0;
225
-		$predef = '';
224
+        $error = 0;
225
+        $predef = '';
226 226
 
227
-		$db->begin();
227
+        $db->begin();
228 228
 
229
-		$object->note = GETPOST('note', 'alpha');
230
-		$object->origin = $origin;
231
-		$object->origin_id = $origin_id;
232
-		$object->fk_project = GETPOST('projectid', 'int');
233
-		$object->weight = GETPOST('weight', 'int') == '' ? "NULL" : GETPOST('weight', 'int');
234
-		$object->sizeH = GETPOST('sizeH', 'int') == '' ? "NULL" : GETPOST('sizeH', 'int');
235
-		$object->sizeW = GETPOST('sizeW', 'int') == '' ? "NULL" : GETPOST('sizeW', 'int');
236
-		$object->sizeS = GETPOST('sizeS', 'int') == '' ? "NULL" : GETPOST('sizeS', 'int');
237
-		$object->size_units = GETPOST('size_units', 'int');
238
-		$object->weight_units = GETPOST('weight_units', 'int');
229
+        $object->note = GETPOST('note', 'alpha');
230
+        $object->origin = $origin;
231
+        $object->origin_id = $origin_id;
232
+        $object->fk_project = GETPOST('projectid', 'int');
233
+        $object->weight = GETPOST('weight', 'int') == '' ? "NULL" : GETPOST('weight', 'int');
234
+        $object->sizeH = GETPOST('sizeH', 'int') == '' ? "NULL" : GETPOST('sizeH', 'int');
235
+        $object->sizeW = GETPOST('sizeW', 'int') == '' ? "NULL" : GETPOST('sizeW', 'int');
236
+        $object->sizeS = GETPOST('sizeS', 'int') == '' ? "NULL" : GETPOST('sizeS', 'int');
237
+        $object->size_units = GETPOST('size_units', 'int');
238
+        $object->weight_units = GETPOST('weight_units', 'int');
239 239
 
240
-		$date_delivery = dol_mktime(GETPOST('date_deliveryhour', 'int'), GETPOST('date_deliverymin', 'int'), 0, GETPOST('date_deliverymonth', 'int'), GETPOST('date_deliveryday', 'int'), GETPOST('date_deliveryyear', 'int'));
240
+        $date_delivery = dol_mktime(GETPOST('date_deliveryhour', 'int'), GETPOST('date_deliverymin', 'int'), 0, GETPOST('date_deliverymonth', 'int'), GETPOST('date_deliveryday', 'int'), GETPOST('date_deliveryyear', 'int'));
241 241
 
242
-		// On va boucler sur chaque ligne du document d'origine pour completer objet reception
243
-		// avec info diverses + qte a livrer
242
+        // On va boucler sur chaque ligne du document d'origine pour completer objet reception
243
+        // avec info diverses + qte a livrer
244 244
 
245
-		if ($object->origin == "supplierorder")
246
-			$classname = 'CommandeFournisseur';
247
-		else
248
-			$classname = ucfirst($object->origin);
249
-		$objectsrc = new $classname($db);
250
-		$objectsrc->fetch($object->origin_id);
245
+        if ($object->origin == "supplierorder")
246
+            $classname = 'CommandeFournisseur';
247
+        else
248
+            $classname = ucfirst($object->origin);
249
+        $objectsrc = new $classname($db);
250
+        $objectsrc->fetch($object->origin_id);
251 251
 
252 252
 
253 253
 
254
-		$object->socid = $objectsrc->socid;
255
-		$object->ref_supplier = GETPOST('ref_supplier', 'alpha');
256
-		$object->model_pdf = GETPOST('model');
257
-		$object->date_delivery = $date_delivery;	 // Date delivery planed
258
-		$object->fk_delivery_address = $objectsrc->fk_delivery_address;
259
-		$object->shipping_method_id = GETPOST('shipping_method_id', 'int');
260
-		$object->tracking_number = GETPOST('tracking_number', 'alpha');
261
-		$object->ref_int = GETPOST('ref_int', 'alpha');
262
-		$object->note_private = GETPOST('note_private', 'none');
263
-		$object->note_public = GETPOST('note_public', 'none');
264
-		$object->fk_incoterms = GETPOST('incoterm_id', 'int');
265
-		$object->location_incoterms = GETPOST('location_incoterms', 'alpha');
266
-
267
-		$batch_line = array();
268
-		$stockLine = array();
269
-		$array_options = array();
270
-
271
-		$totalqty = 0;
272
-
273
-		$num = 0;
274
-		foreach ($_POST as $key => $value)
275
-		{
276
-			// without batch module enabled
277
-
278
-			if (strpos($key, 'qtyasked') !== false)
279
-			{
280
-				$num++;
281
-			}
282
-		}
283
-
284
-		for ($i = 1; $i <= $num; $i++)
285
-		{
286
-			$idl = "idl".$i;
287
-
288
-			$sub_qty = array();
289
-			$subtotalqty = 0;
290
-
291
-			$j = 0;
292
-			$batch = "batchl".$i."_0";
293
-			$stockLocation = "ent1".$i."_0";
294
-			$qty = "qtyl".$i;
295
-
296
-
297
-
298
-				//var_dump(GETPOST($qty,'int')); var_dump($_POST); var_dump($batch);exit;
299
-				//reception line for product with no batch management and no multiple stock location
300
-			if (GETPOST($qty, 'int') > 0)
301
-				$totalqty += GETPOST($qty, 'int');
302
-
303
-
304
-			// Extrafields
305
-			$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
306
-			$array_options[$i] = $extrafieldsline->getOptionalsFromPost($extralabelsline, $i);
307
-		}
308
-
309
-
310
-		if ($totalqty > 0)  // There is at least one thing to ship
311
-		{
312
-			//var_dump($_POST);exit;
313
-			for ($i = 1; $i <= $num; $i++)
314
-			{
315
-				$lineToTest = '';
316
-				foreach($objectsrc->lines as $linesrc){
317
-					if($linesrc->id == GETPOST($idl, 'int'))$lineToTest=$linesrc;
318
-				}
319
-				$qty = "qtyl".$i;
320
-				$comment = "comment".$i;
321
-				$eatby = "dlc".$i;
322
-				$sellby = "dluo".$i;
323
-				$batch = "batch".$i;
324
-
325
-
326
-
327
-				$timeFormat = '%d/%m/%Y';
328
-
329
-				if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && $conf->global->RECEPTION_GETS_ALL_ORDER_PRODUCTS))
330
-				{
331
-					$ent = "entl".$i;
332
-
333
-					$idl = "idl".$i;
334
-
335
-					$entrepot_id = is_numeric(GETPOST($ent, 'int')) ? GETPOST($ent, 'int') : GETPOST('entrepot_id', 'int');
336
-
337
-					if ($entrepot_id < 0)
338
-						$entrepot_id = '';
339
-					if (!($linesrc->fk_product > 0) && empty($conf->global->STOCK_SUPPORTS_SERVICES))
340
-						$entrepot_id = 0;
341
-					$eatby = GETPOST($eatby, 'alpha');
342
-					$sellby = GETPOST($sellby, 'alpha');
343
-					$eatbydate = str_replace('/','-',$eatby);
344
-					$sellbydate = str_replace('/','-',$sellby);
345
-
346
-
347
-					$ret = $object->addline($entrepot_id, GETPOST($idl, 'int'), GETPOST($qty, 'int'), $array_options[$i], GETPOST($comment, 'alpha'), strtotime($eatbydate),strtotime($sellbydate), GETPOST($batch, 'alpha'));
348
-					if ($ret < 0)
349
-					{
350
-						setEventMessages($object->error, $object->errors, 'errors');
351
-						$error++;
352
-					}
353
-				}
354
-			}
355
-
356
-
357
-	        // Fill array 'array_options' with data from add form
358
-	        $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
359
-	        if ($ret < 0) $error++;
360
-	        if (! $error)
361
-	        {
362
-	            $ret=$object->create($user);		// This create reception (like Odoo picking) and line of receptions. Stock movement will when validating reception.
254
+        $object->socid = $objectsrc->socid;
255
+        $object->ref_supplier = GETPOST('ref_supplier', 'alpha');
256
+        $object->model_pdf = GETPOST('model');
257
+        $object->date_delivery = $date_delivery;	 // Date delivery planed
258
+        $object->fk_delivery_address = $objectsrc->fk_delivery_address;
259
+        $object->shipping_method_id = GETPOST('shipping_method_id', 'int');
260
+        $object->tracking_number = GETPOST('tracking_number', 'alpha');
261
+        $object->ref_int = GETPOST('ref_int', 'alpha');
262
+        $object->note_private = GETPOST('note_private', 'none');
263
+        $object->note_public = GETPOST('note_public', 'none');
264
+        $object->fk_incoterms = GETPOST('incoterm_id', 'int');
265
+        $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
363 266
 
364
-	            if ($ret <= 0)
365
-	            {
366
-	                setEventMessages($object->error, $object->errors, 'errors');
367
-	                $error++;
368
-	            }
369
-	        }
370
-	    }
371
-	    else
372
-	    {
373
-	        setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("QtyToReceive").'/'.$langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
374
-	        $error++;
375
-	    }
267
+        $batch_line = array();
268
+        $stockLine = array();
269
+        $array_options = array();
376 270
 
377
-	    if (! $error)
378
-	    {
379
-	        $db->commit();
380
-	        header("Location: card.php?id=".$object->id);
381
-	        exit;
382
-	    }
383
-	    else
384
-	    {
385
-	        $db->rollback();
386
-	        $_GET["commande_id"]=GETPOST('commande_id','int');
387
-	        $action='create';
388
-	    }
389
-	}
271
+        $totalqty = 0;
272
+
273
+        $num = 0;
274
+        foreach ($_POST as $key => $value)
275
+        {
276
+            // without batch module enabled
277
+
278
+            if (strpos($key, 'qtyasked') !== false)
279
+            {
280
+                $num++;
281
+            }
282
+        }
283
+
284
+        for ($i = 1; $i <= $num; $i++)
285
+        {
286
+            $idl = "idl".$i;
287
+
288
+            $sub_qty = array();
289
+            $subtotalqty = 0;
290
+
291
+            $j = 0;
292
+            $batch = "batchl".$i."_0";
293
+            $stockLocation = "ent1".$i."_0";
294
+            $qty = "qtyl".$i;
295
+
296
+
297
+
298
+                //var_dump(GETPOST($qty,'int')); var_dump($_POST); var_dump($batch);exit;
299
+                //reception line for product with no batch management and no multiple stock location
300
+            if (GETPOST($qty, 'int') > 0)
301
+                $totalqty += GETPOST($qty, 'int');
302
+
303
+
304
+            // Extrafields
305
+            $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
306
+            $array_options[$i] = $extrafieldsline->getOptionalsFromPost($extralabelsline, $i);
307
+        }
308
+
309
+
310
+        if ($totalqty > 0)  // There is at least one thing to ship
311
+        {
312
+            //var_dump($_POST);exit;
313
+            for ($i = 1; $i <= $num; $i++)
314
+            {
315
+                $lineToTest = '';
316
+                foreach($objectsrc->lines as $linesrc){
317
+                    if($linesrc->id == GETPOST($idl, 'int'))$lineToTest=$linesrc;
318
+                }
319
+                $qty = "qtyl".$i;
320
+                $comment = "comment".$i;
321
+                $eatby = "dlc".$i;
322
+                $sellby = "dluo".$i;
323
+                $batch = "batch".$i;
324
+
325
+
326
+
327
+                $timeFormat = '%d/%m/%Y';
390 328
 
391
-	else if ($action == 'confirm_valid' && $confirm == 'yes' &&
329
+                if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && $conf->global->RECEPTION_GETS_ALL_ORDER_PRODUCTS))
330
+                {
331
+                    $ent = "entl".$i;
332
+
333
+                    $idl = "idl".$i;
334
+
335
+                    $entrepot_id = is_numeric(GETPOST($ent, 'int')) ? GETPOST($ent, 'int') : GETPOST('entrepot_id', 'int');
336
+
337
+                    if ($entrepot_id < 0)
338
+                        $entrepot_id = '';
339
+                    if (!($linesrc->fk_product > 0) && empty($conf->global->STOCK_SUPPORTS_SERVICES))
340
+                        $entrepot_id = 0;
341
+                    $eatby = GETPOST($eatby, 'alpha');
342
+                    $sellby = GETPOST($sellby, 'alpha');
343
+                    $eatbydate = str_replace('/','-',$eatby);
344
+                    $sellbydate = str_replace('/','-',$sellby);
345
+
346
+
347
+                    $ret = $object->addline($entrepot_id, GETPOST($idl, 'int'), GETPOST($qty, 'int'), $array_options[$i], GETPOST($comment, 'alpha'), strtotime($eatbydate),strtotime($sellbydate), GETPOST($batch, 'alpha'));
348
+                    if ($ret < 0)
349
+                    {
350
+                        setEventMessages($object->error, $object->errors, 'errors');
351
+                        $error++;
352
+                    }
353
+                }
354
+            }
355
+
356
+
357
+            // Fill array 'array_options' with data from add form
358
+            $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
359
+            if ($ret < 0) $error++;
360
+            if (! $error)
361
+            {
362
+                $ret=$object->create($user);		// This create reception (like Odoo picking) and line of receptions. Stock movement will when validating reception.
363
+
364
+                if ($ret <= 0)
365
+                {
366
+                    setEventMessages($object->error, $object->errors, 'errors');
367
+                    $error++;
368
+                }
369
+            }
370
+        }
371
+        else
372
+        {
373
+            setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("QtyToReceive").'/'.$langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
374
+            $error++;
375
+        }
376
+
377
+        if (! $error)
378
+        {
379
+            $db->commit();
380
+            header("Location: card.php?id=".$object->id);
381
+            exit;
382
+        }
383
+        else
384
+        {
385
+            $db->rollback();
386
+            $_GET["commande_id"]=GETPOST('commande_id','int');
387
+            $action='create';
388
+        }
389
+    }
390
+
391
+    else if ($action == 'confirm_valid' && $confirm == 'yes' &&
392 392
         ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->creer))
393
-       	|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->reception_advance->validate)))
394
-	)
395
-	{
396
-	    $object->fetch_thirdparty();
393
+           || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->reception_advance->validate)))
394
+    )
395
+    {
396
+        $object->fetch_thirdparty();
397 397
 
398
-	    $result = $object->valid($user);
398
+        $result = $object->valid($user);
399 399
 
400
-	    if ($result < 0)
401
-	    {
402
-			$langs->load("errors");
403
-	        setEventMessages($langs->trans($object->error), null, 'errors');
404
-	    }
405
-	    else
406
-	    {
407
-	    	// Define output language
408
-	    	if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
409
-	    	{
410
-	    		$outputlangs = $langs;
411
-	    		$newlang = '';
412
-	    		if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
413
-	    		if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $object->thirdparty->default_lang;
414
-	    		if (! empty($newlang)) {
415
-	    			$outputlangs = new Translate("", $conf);
416
-	    			$outputlangs->setDefaultLang($newlang);
417
-	    		}
418
-	    		$model=$object->modelpdf;
419
-	    		$ret = $object->fetch($id); // Reload to get new records
420
-
421
-	    		$result=$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
422
-	    		if ($result < 0) dol_print_error($db,$result);
423
-	    	}
424
-	    }
425
-	}
400
+        if ($result < 0)
401
+        {
402
+            $langs->load("errors");
403
+            setEventMessages($langs->trans($object->error), null, 'errors');
404
+        }
405
+        else
406
+        {
407
+            // Define output language
408
+            if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
409
+            {
410
+                $outputlangs = $langs;
411
+                $newlang = '';
412
+                if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
413
+                if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $object->thirdparty->default_lang;
414
+                if (! empty($newlang)) {
415
+                    $outputlangs = new Translate("", $conf);
416
+                    $outputlangs->setDefaultLang($newlang);
417
+                }
418
+                $model=$object->modelpdf;
419
+                $ret = $object->fetch($id); // Reload to get new records
426 420
 
427
-	else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->reception->supprimer)
428
-	{
429
-	    $result = $object->delete($user);
430
-	    if ($result > 0)
431
-	    {
432
-	        header("Location: ".DOL_URL_ROOT.'/reception/index.php');
433
-	        exit;
434
-	    }
435
-	    else
436
-		{
437
-			setEventMessages($object->error, $object->errors, 'errors');
438
-	    }
439
-	}
440
-	// TODO add alternative status
441
-	/*else if ($action == 'reopen' && (! empty($user->rights->reception->creer) || ! empty($user->rights->reception->reception_advance->validate)))
421
+                $result=$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
422
+                if ($result < 0) dol_print_error($db,$result);
423
+            }
424
+        }
425
+    }
426
+
427
+    else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->reception->supprimer)
428
+    {
429
+        $result = $object->delete($user);
430
+        if ($result > 0)
431
+        {
432
+            header("Location: ".DOL_URL_ROOT.'/reception/index.php');
433
+            exit;
434
+        }
435
+        else
436
+        {
437
+            setEventMessages($object->error, $object->errors, 'errors');
438
+        }
439
+    }
440
+    // TODO add alternative status
441
+    /*else if ($action == 'reopen' && (! empty($user->rights->reception->creer) || ! empty($user->rights->reception->reception_advance->validate)))
442 442
 	{
443 443
 	    $result = $object->setStatut(0);
444 444
 	    if ($result < 0)
@@ -447,262 +447,262 @@  discard block
 block discarded – undo
447 447
 	    }
448 448
 	}*/
449 449
 
450
-	else if ($action == 'setdate_livraison' && $user->rights->reception->creer)
451
-	{
452
-	    //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
453
-	    $datedelivery=dol_mktime(GETPOST('liv_hour','int'), GETPOST('liv_min','int'), 0, GETPOST('liv_month','int'), GETPOST('liv_day','int'), GETPOST('liv_year','int'));
450
+    else if ($action == 'setdate_livraison' && $user->rights->reception->creer)
451
+    {
452
+        //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
453
+        $datedelivery=dol_mktime(GETPOST('liv_hour','int'), GETPOST('liv_min','int'), 0, GETPOST('liv_month','int'), GETPOST('liv_day','int'), GETPOST('liv_year','int'));
454 454
 
455
-	    $object->fetch($id);
456
-	    $result=$object->set_date_livraison($user,$datedelivery);
457
-	    if ($result < 0)
458
-	    {
459
-	        setEventMessages($object->error, $object->errors, 'errors');
460
-	    }
461
-	}
462
-
463
-	// Action update
464
-	else if ($action == 'settracking_number' || $action == 'settracking_url'
465
-	|| $action == 'settrueWeight'
466
-	|| $action == 'settrueWidth'
467
-	|| $action == 'settrueHeight'
468
-	|| $action == 'settrueDepth'
469
-	|| $action == 'setshipping_method_id')
470
-	{
471
-	    $error=0;
455
+        $object->fetch($id);
456
+        $result=$object->set_date_livraison($user,$datedelivery);
457
+        if ($result < 0)
458
+        {
459
+            setEventMessages($object->error, $object->errors, 'errors');
460
+        }
461
+    }
472 462
 
473
-	    if ($action == 'settracking_number')		$object->tracking_number = trim(GETPOST('tracking_number','alpha'));
474
-	    if ($action == 'settracking_url')		$object->tracking_url = trim(GETPOST('tracking_url','int'));
475
-	    if ($action == 'settrueWeight')	{
476
-	    	$object->trueWeight = trim(GETPOST('trueWeight','int'));
477
-			$object->weight_units = GETPOST('weight_units','int');
478
-	    }
479
-	    if ($action == 'settrueWidth')			$object->trueWidth = trim(GETPOST('trueWidth','int'));
480
-	    if ($action == 'settrueHeight'){
481
-	    				$object->trueHeight = trim(GETPOST('trueHeight','int'));
482
-						$object->size_units = GETPOST('size_units','int');
483
-		}
484
-	    if ($action == 'settrueDepth')			$object->trueDepth = trim(GETPOST('trueDepth','int'));
485
-	    if ($action == 'setshipping_method_id')	$object->shipping_method_id = trim(GETPOST('shipping_method_id','int'));
486
-
487
-	    if (! $error)
488
-	    {
489
-	        if ($object->update($user) >= 0)
490
-	        {
491
-	            header("Location: card.php?id=".$object->id);
492
-	            exit;
493
-	        }
494
-	        setEventMessages($object->error, $object->errors, 'errors');
495
-	    }
463
+    // Action update
464
+    else if ($action == 'settracking_number' || $action == 'settracking_url'
465
+    || $action == 'settrueWeight'
466
+    || $action == 'settrueWidth'
467
+    || $action == 'settrueHeight'
468
+    || $action == 'settrueDepth'
469
+    || $action == 'setshipping_method_id')
470
+    {
471
+        $error=0;
496 472
 
497
-	    $action="";
498
-	}
473
+        if ($action == 'settracking_number')		$object->tracking_number = trim(GETPOST('tracking_number','alpha'));
474
+        if ($action == 'settracking_url')		$object->tracking_url = trim(GETPOST('tracking_url','int'));
475
+        if ($action == 'settrueWeight')	{
476
+            $object->trueWeight = trim(GETPOST('trueWeight','int'));
477
+            $object->weight_units = GETPOST('weight_units','int');
478
+        }
479
+        if ($action == 'settrueWidth')			$object->trueWidth = trim(GETPOST('trueWidth','int'));
480
+        if ($action == 'settrueHeight'){
481
+                        $object->trueHeight = trim(GETPOST('trueHeight','int'));
482
+                        $object->size_units = GETPOST('size_units','int');
483
+        }
484
+        if ($action == 'settrueDepth')			$object->trueDepth = trim(GETPOST('trueDepth','int'));
485
+        if ($action == 'setshipping_method_id')	$object->shipping_method_id = trim(GETPOST('shipping_method_id','int'));
499 486
 
500
-	// Build document
501
-	else if ($action == 'builddoc')	// En get ou en post
502
-	{
503
-		// Save last template used to generate document
504
-		if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
505
-
506
-	    // Define output language
507
-	    $outputlangs = $langs;
508
-	    $newlang='';
509
-	    if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
510
-	    if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$reception->thirdparty->default_lang;
511
-	    if (! empty($newlang))
512
-	    {
513
-	        $outputlangs = new Translate("",$conf);
514
-	        $outputlangs->setDefaultLang($newlang);
515
-	    }
516
-		$result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
517
-	    if ($result <= 0)
518
-	    {
519
-			setEventMessages($object->error, $object->errors, 'errors');
520
-	        $action='';
521
-	    }
522
-	}
487
+        if (! $error)
488
+        {
489
+            if ($object->update($user) >= 0)
490
+            {
491
+                header("Location: card.php?id=".$object->id);
492
+                exit;
493
+            }
494
+            setEventMessages($object->error, $object->errors, 'errors');
495
+        }
523 496
 
524
-	// Delete file in doc form
525
-	elseif ($action == 'remove_file')
526
-	{
527
-		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
497
+        $action="";
498
+    }
499
+
500
+    // Build document
501
+    else if ($action == 'builddoc')	// En get ou en post
502
+    {
503
+        // Save last template used to generate document
504
+        if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
505
+
506
+        // Define output language
507
+        $outputlangs = $langs;
508
+        $newlang='';
509
+        if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
510
+        if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$reception->thirdparty->default_lang;
511
+        if (! empty($newlang))
512
+        {
513
+            $outputlangs = new Translate("",$conf);
514
+            $outputlangs->setDefaultLang($newlang);
515
+        }
516
+        $result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
517
+        if ($result <= 0)
518
+        {
519
+            setEventMessages($object->error, $object->errors, 'errors');
520
+            $action='';
521
+        }
522
+    }
528 523
 
529
-		$upload_dir =	$conf->reception->dir_output ;
530
-		$file =	$upload_dir	. '/' .	GETPOST('file');
531
-		$ret=dol_delete_file($file,0,0,0,$object);
532
-		if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
533
-		else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
534
-	}
524
+    // Delete file in doc form
525
+    elseif ($action == 'remove_file')
526
+    {
527
+        require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
535 528
 
536
-	elseif ($action == 'classifybilled')
537
-	{
538
-	    $object->fetch($id);
539
-	    $result = $object->set_billed();
540
-	    if($result >= 0) {
541
-	    	header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
542
-	    	exit();
543
-	    }
544
-	}
529
+        $upload_dir =	$conf->reception->dir_output ;
530
+        $file =	$upload_dir	. '/' .	GETPOST('file');
531
+        $ret=dol_delete_file($file,0,0,0,$object);
532
+        if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
533
+        else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
534
+    }
545 535
 
546
-	elseif ($action == 'classifyclosed')
547
-	{
548
-	    $object->fetch($id);
549
-	    $result = $object->setClosed();
550
-	    if($result >= 0) {
551
-	    	header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
552
-	    	exit();
553
-	    }
554
-	}
536
+    elseif ($action == 'classifybilled')
537
+    {
538
+        $object->fetch($id);
539
+        $result = $object->set_billed();
540
+        if($result >= 0) {
541
+            header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
542
+            exit();
543
+        }
544
+    }
545
+
546
+    elseif ($action == 'classifyclosed')
547
+    {
548
+        $object->fetch($id);
549
+        $result = $object->setClosed();
550
+        if($result >= 0) {
551
+            header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
552
+            exit();
553
+        }
554
+    }
555 555
 
556
-	/*
556
+    /*
557 557
 	 *  delete a line
558 558
 	 */
559
-	elseif ($action == 'deleteline' && ! empty($line_id))
560
-	{
561
-		$object->fetch($id);
562
-		$lines = $object->lines;
563
-		$line = new CommandeFournisseurDispatch($db);
564
-
565
-		$num_prod = count($lines);
566
-		for ($i = 0 ; $i < $num_prod ; $i++)
567
-		{
568
-			if ($lines[$i]->id == $line_id)
569
-			{
570
-					// delete single warehouse line
571
-					$line->id = $line_id;
572
-					if (! $error && $line->delete($user) < 0)
573
-					{
574
-						$error++;
575
-					}
576
-			}
577
-			unset($_POST["lineid"]);
578
-		}
579
-
580
-		if(! $error) {
581
-			header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
582
-			exit();
583
-		}
584
-		else
585
-		{
586
-			setEventMessages($line->error, $line->errors, 'errors');
587
-		}
588
-	}
589
-
590
-	/*
559
+    elseif ($action == 'deleteline' && ! empty($line_id))
560
+    {
561
+        $object->fetch($id);
562
+        $lines = $object->lines;
563
+        $line = new CommandeFournisseurDispatch($db);
564
+
565
+        $num_prod = count($lines);
566
+        for ($i = 0 ; $i < $num_prod ; $i++)
567
+        {
568
+            if ($lines[$i]->id == $line_id)
569
+            {
570
+                    // delete single warehouse line
571
+                    $line->id = $line_id;
572
+                    if (! $error && $line->delete($user) < 0)
573
+                    {
574
+                        $error++;
575
+                    }
576
+            }
577
+            unset($_POST["lineid"]);
578
+        }
579
+
580
+        if(! $error) {
581
+            header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
582
+            exit();
583
+        }
584
+        else
585
+        {
586
+            setEventMessages($line->error, $line->errors, 'errors');
587
+        }
588
+    }
589
+
590
+    /*
591 591
 	 *  Update a line
592 592
 	 */
593
-	else if ($action == 'updateline' && $user->rights->reception->creer && GETPOST('save'))
594
-	{
595
-		// Clean parameters
596
-		$qty = 0;
597
-		$entrepot_id = 0;
598
-		$batch_id = 0;
599
-
600
-		$lines = $object->lines;
601
-		$num_prod = count($lines);
602
-		for ($i = 0; $i < $num_prod; $i++)
603
-		{
604
-			if ($lines[$i]->id == $line_id)  // we have found line to update
605
-			{
606
-				$line = new CommandeFournisseurDispatch($db);
607
-				$line->fetch($line_id);
608
-				// Extrafields Lines
609
-				$extrafieldsline = new ExtraFields($db);
610
-				$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
611
-				$line->array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline);
612
-
613
-
614
-				$line->fk_product = $lines[$i]->fk_product;
615
-
616
-
617
-				if ($lines[$i]->fk_product > 0)
618
-				{
619
-					// single warehouse reception line
620
-					$stockLocation = "entl".$line_id;
621
-					$qty = "qtyl".$line_id;
622
-					$comment = "comment".$line_id;
623
-
624
-
625
-					$line->id = $line_id;
626
-					$line->fk_entrepot = GETPOST($stockLocation, 'int');
627
-					$line->qty = GETPOST($qty, 'int');
628
-					$line->comment = GETPOST($comment, 'alpha');
629
-
630
-					if(!empty($conf->productbatch->enabled)){
631
-						$batch = "batch".$line_id;
632
-						$dlc = "dlc".$line_id;
633
-						$dluo = "dluo".$line_id;
634
-						$eatby = GETPOST($dlc, 'alpha');
635
-						$eatbydate = str_replace('/','-',$eatby);
636
-						$sellby = GETPOST($dluo, 'alpha');
637
-						$sellbydate = str_replace('/','-',$sellby);
638
-						$line->batch = GETPOST($batch, 'alpha');
639
-						$line->eatby = strtotime($eatbydate);
640
-						$line->sellby = strtotime($sellbydate);
641
-					}
642
-
643
-					if ($line->update($user) < 0)
644
-					{
645
-						setEventMessages($line->error, $line->errors, 'errors');
646
-						$error++;
647
-					}
648
-				}
649
-				else // Product no predefined
650
-				{
651
-					$qty = "qtyl".$line_id;
652
-					$line->id = $line_id;
653
-					$line->qty = GETPOST($qty, 'int');
654
-					$line->fk_entrepot = 0;
655
-					if ($line->update($user) < 0)
656
-					{
657
-						setEventMessages($line->error, $line->errors, 'errors');
658
-						$error++;
659
-					}
660
-					unset($_POST[$qty]);
661
-				}
662
-			}
663
-		}
664
-
665
-		unset($_POST["lineid"]);
666
-
667
-		if (! $error) {
668
-			if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
669
-				// Define output language
670
-				$outputlangs = $langs;
671
-				$newlang = '';
672
-				if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09'))
673
-					$newlang = GETPOST('lang_id','aZ09');
674
-				if ($conf->global->MAIN_MULTILANGS && empty($newlang))
675
-					$newlang = $object->thirdparty->default_lang;
676
-				if (! empty($newlang)) {
677
-					$outputlangs = new Translate("", $conf);
678
-					$outputlangs->setDefaultLang($newlang);
679
-				}
680
-
681
-				$ret = $object->fetch($object->id); // Reload to get new records
682
-				$object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
683
-			}
684
-		}
685
-		else
686
-		{
687
-			header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition
688
-			exit();
689
-		}
690
-	}
691
-
692
-	else if ($action == 'updateline' && $user->rights->reception->creer && GETPOST('cancel','alpha') == $langs->trans('Cancel')) {
693
-		header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition
694
-		exit();
695
-	}
696
-
697
-	include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
698
-
699
-	// Actions to send emails
700
-	if (empty($id)) $id=$facid;
701
-	$trigger_name='RECEPTION_SENTBYMAIL';
702
-	$paramname='id';
703
-	$mode='emailfromreception';
704
-	$trackid='shi'.$object->id;
705
-	include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
593
+    else if ($action == 'updateline' && $user->rights->reception->creer && GETPOST('save'))
594
+    {
595
+        // Clean parameters
596
+        $qty = 0;
597
+        $entrepot_id = 0;
598
+        $batch_id = 0;
599
+
600
+        $lines = $object->lines;
601
+        $num_prod = count($lines);
602
+        for ($i = 0; $i < $num_prod; $i++)
603
+        {
604
+            if ($lines[$i]->id == $line_id)  // we have found line to update
605
+            {
606
+                $line = new CommandeFournisseurDispatch($db);
607
+                $line->fetch($line_id);
608
+                // Extrafields Lines
609
+                $extrafieldsline = new ExtraFields($db);
610
+                $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
611
+                $line->array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline);
612
+
613
+
614
+                $line->fk_product = $lines[$i]->fk_product;
615
+
616
+
617
+                if ($lines[$i]->fk_product > 0)
618
+                {
619
+                    // single warehouse reception line
620
+                    $stockLocation = "entl".$line_id;
621
+                    $qty = "qtyl".$line_id;
622
+                    $comment = "comment".$line_id;
623
+
624
+
625
+                    $line->id = $line_id;
626
+                    $line->fk_entrepot = GETPOST($stockLocation, 'int');
627
+                    $line->qty = GETPOST($qty, 'int');
628
+                    $line->comment = GETPOST($comment, 'alpha');
629
+
630
+                    if(!empty($conf->productbatch->enabled)){
631
+                        $batch = "batch".$line_id;
632
+                        $dlc = "dlc".$line_id;
633
+                        $dluo = "dluo".$line_id;
634
+                        $eatby = GETPOST($dlc, 'alpha');
635
+                        $eatbydate = str_replace('/','-',$eatby);
636
+                        $sellby = GETPOST($dluo, 'alpha');
637
+                        $sellbydate = str_replace('/','-',$sellby);
638
+                        $line->batch = GETPOST($batch, 'alpha');
639
+                        $line->eatby = strtotime($eatbydate);
640
+                        $line->sellby = strtotime($sellbydate);
641
+                    }
642
+
643
+                    if ($line->update($user) < 0)
644
+                    {
645
+                        setEventMessages($line->error, $line->errors, 'errors');
646
+                        $error++;
647
+                    }
648
+                }
649
+                else // Product no predefined
650
+                {
651
+                    $qty = "qtyl".$line_id;
652
+                    $line->id = $line_id;
653
+                    $line->qty = GETPOST($qty, 'int');
654
+                    $line->fk_entrepot = 0;
655
+                    if ($line->update($user) < 0)
656
+                    {
657
+                        setEventMessages($line->error, $line->errors, 'errors');
658
+                        $error++;
659
+                    }
660
+                    unset($_POST[$qty]);
661
+                }
662
+            }
663
+        }
664
+
665
+        unset($_POST["lineid"]);
666
+
667
+        if (! $error) {
668
+            if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
669
+                // Define output language
670
+                $outputlangs = $langs;
671
+                $newlang = '';
672
+                if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09'))
673
+                    $newlang = GETPOST('lang_id','aZ09');
674
+                if ($conf->global->MAIN_MULTILANGS && empty($newlang))
675
+                    $newlang = $object->thirdparty->default_lang;
676
+                if (! empty($newlang)) {
677
+                    $outputlangs = new Translate("", $conf);
678
+                    $outputlangs->setDefaultLang($newlang);
679
+                }
680
+
681
+                $ret = $object->fetch($object->id); // Reload to get new records
682
+                $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
683
+            }
684
+        }
685
+        else
686
+        {
687
+            header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition
688
+            exit();
689
+        }
690
+    }
691
+
692
+    else if ($action == 'updateline' && $user->rights->reception->creer && GETPOST('cancel','alpha') == $langs->trans('Cancel')) {
693
+        header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition
694
+        exit();
695
+    }
696
+
697
+    include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
698
+
699
+    // Actions to send emails
700
+    if (empty($id)) $id=$facid;
701
+    $trigger_name='RECEPTION_SENTBYMAIL';
702
+    $paramname='id';
703
+    $mode='emailfromreception';
704
+    $trackid='shi'.$object->id;
705
+    include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
706 706
 }
707 707
 
708 708
 
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
 
742 742
     if ($origin)
743 743
     {
744
-		if($origin == 'supplierorder')$classname = 'CommandeFournisseur';
744
+        if($origin == 'supplierorder')$classname = 'CommandeFournisseur';
745 745
         else $classname = ucfirst($origin);
746 746
 
747 747
         $object = new $classname($db);
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
                 print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
835 835
                 print '<td colspan="3">';
836 836
                 $doleditor = new DolEditor('note_private', $object->note_private, '', 60, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
837
-        		print $doleditor->Create(1);
837
+                print $doleditor->Create(1);
838 838
                 print "</td></tr>";
839 839
             }
840 840
 
@@ -877,38 +877,38 @@  discard block
 block discarded – undo
877 877
             $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$recept,$action);    // Note that $action and $object may have been modified by hook
878 878
             print $hookmanager->resPrint;
879 879
 
880
-			if (empty($reshook) && ! empty($extrafields->attribute_label)) {
881
-				// copy from order
882
-				$orderExtrafields = new Extrafields($db);
883
-				$orderExtrafieldLabels = $orderExtrafields->fetch_name_optionals_label($object->table_element);
884
-				if ($object->fetch_optionals($object->id, $orderExtrafieldLabels) > 0) {
885
-					$recept->array_options = array_merge($recept->array_options, $object->array_options);
886
-				}
887
-				print $object->showOptionals($extrafields, 'edit');
888
-			}
880
+            if (empty($reshook) && ! empty($extrafields->attribute_label)) {
881
+                // copy from order
882
+                $orderExtrafields = new Extrafields($db);
883
+                $orderExtrafieldLabels = $orderExtrafields->fetch_name_optionals_label($object->table_element);
884
+                if ($object->fetch_optionals($object->id, $orderExtrafieldLabels) > 0) {
885
+                    $recept->array_options = array_merge($recept->array_options, $object->array_options);
886
+                }
887
+                print $object->showOptionals($extrafields, 'edit');
888
+            }
889 889
 
890 890
 
891 891
             // Incoterms
892
-			if (!empty($conf->incoterm->enabled))
893
-			{
894
-				print '<tr>';
895
-				print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $object->libelle_incoterms, 1).'</label></td>';
896
-		        print '<td colspan="3" class="maxwidthonsmartphone">';
897
-		        print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
898
-				print '</td></tr>';
899
-			}
892
+            if (!empty($conf->incoterm->enabled))
893
+            {
894
+                print '<tr>';
895
+                print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $object->libelle_incoterms, 1).'</label></td>';
896
+                print '<td colspan="3" class="maxwidthonsmartphone">';
897
+                print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
898
+                print '</td></tr>';
899
+            }
900 900
 
901 901
             // Document model
902
-			include_once DOL_DOCUMENT_ROOT . '/core/modules/reception/modules_reception.php';
903
-			$liste = ModelePdfReception::liste_modeles($db);
902
+            include_once DOL_DOCUMENT_ROOT . '/core/modules/reception/modules_reception.php';
903
+            $liste = ModelePdfReception::liste_modeles($db);
904 904
 
905
-			if (count($liste) > 1)
906
-			{
907
-    			print "<tr><td>".$langs->trans("DefaultModel")."</td>";
905
+            if (count($liste) > 1)
906
+            {
907
+                print "<tr><td>".$langs->trans("DefaultModel")."</td>";
908 908
                 print '<td colspan="3">';
909
-    			print $form->selectarray('model', $liste, $conf->global->RECEPTION_ADDON_PDF);
909
+                print $form->selectarray('model', $liste, $conf->global->RECEPTION_ADDON_PDF);
910 910
                 print "</td></tr>\n";
911
-			}
911
+            }
912 912
 
913 913
             print "</table>";
914 914
 
@@ -916,64 +916,64 @@  discard block
 block discarded – undo
916 916
 
917 917
 
918 918
             // Reception lines
919
-			$numAsked=0;
920
-			$dispatchLines = array();
921
-			foreach ($_POST as $key => $value)
922
-			{
923
-				// without batch module enabled
924
-				if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg))
925
-				{
926
-					$numAsked ++;
927
-
928
-					// $numline=$reg[2] + 1; // line of product
929
-					$numline = $numAsked;
930
-					$prod = "product_".$reg[1].'_'.$reg[2];
931
-					$qty = "qty_".$reg[1].'_'.$reg[2];
932
-					$ent = "entrepot_".$reg[1].'_'.$reg[2];
933
-					$pu = "pu_".$reg[1].'_'.$reg[2]; // This is unit price including discount
934
-					$fk_commandefourndet = "fk_commandefourndet_".$reg[1].'_'.$reg[2];
935
-					$dispatchLines[$numAsked]=array('prod' => GETPOST($prod, 'int'), 'qty' =>GETPOST($qty), 'ent' =>GETPOST($ent, 'int'), 'pu' =>GETPOST($pu), 'comment' =>GETPOST('comment'),'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'));
936
-				}
937
-
938
-				// with batch module enabled
939
-				if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg))
940
-				{
941
-					$numAsked++;
942
-
943
-					// eat-by date dispatch
944
-					// $numline=$reg[2] + 1; // line of product
945
-					$numline = $numAsked;
946
-					$prod = 'product_batch_'.$reg[1].'_'.$reg[2];
947
-					$qty = 'qty_'.$reg[1].'_'.$reg[2];
948
-					$ent = 'entrepot_'.$reg[1].'_'.$reg[2];
949
-					$pu = 'pu_'.$reg[1].'_'.$reg[2];
950
-					$lot = 'lot_number_'.$reg[1].'_'.$reg[2];
951
-					$dDLUO = dol_mktime(12, 0, 0, $_POST['dluo_'.$reg[1].'_'.$reg[2].'month'], $_POST['dluo_'.$reg[1].'_'.$reg[2].'day'], $_POST['dluo_'.$reg[1].'_'.$reg[2].'year']);
952
-					$dDLC = dol_mktime(12, 0, 0, $_POST['dlc_'.$reg[1].'_'.$reg[2].'month'], $_POST['dlc_'.$reg[1].'_'.$reg[2].'day'], $_POST['dlc_'.$reg[1].'_'.$reg[2].'year']);
953
-					$fk_commandefourndet = 'fk_commandefourndet_'.$reg[1].'_'.$reg[2];
954
-					$dispatchLines[$numAsked]=array('prod' => GETPOST($prod, 'int'), 'qty' =>GETPOST($qty), 'ent' =>GETPOST($ent, 'int'), 'pu' =>GETPOST($pu), 'comment' =>GETPOST('comment'),'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'),'DLC'=> $dDLC,'DLUO'=> $dDLUO,'lot'=> GETPOST($lot, 'alpha'));
955
-				}
956
-			}
919
+            $numAsked=0;
920
+            $dispatchLines = array();
921
+            foreach ($_POST as $key => $value)
922
+            {
923
+                // without batch module enabled
924
+                if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg))
925
+                {
926
+                    $numAsked ++;
927
+
928
+                    // $numline=$reg[2] + 1; // line of product
929
+                    $numline = $numAsked;
930
+                    $prod = "product_".$reg[1].'_'.$reg[2];
931
+                    $qty = "qty_".$reg[1].'_'.$reg[2];
932
+                    $ent = "entrepot_".$reg[1].'_'.$reg[2];
933
+                    $pu = "pu_".$reg[1].'_'.$reg[2]; // This is unit price including discount
934
+                    $fk_commandefourndet = "fk_commandefourndet_".$reg[1].'_'.$reg[2];
935
+                    $dispatchLines[$numAsked]=array('prod' => GETPOST($prod, 'int'), 'qty' =>GETPOST($qty), 'ent' =>GETPOST($ent, 'int'), 'pu' =>GETPOST($pu), 'comment' =>GETPOST('comment'),'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'));
936
+                }
937
+
938
+                // with batch module enabled
939
+                if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg))
940
+                {
941
+                    $numAsked++;
942
+
943
+                    // eat-by date dispatch
944
+                    // $numline=$reg[2] + 1; // line of product
945
+                    $numline = $numAsked;
946
+                    $prod = 'product_batch_'.$reg[1].'_'.$reg[2];
947
+                    $qty = 'qty_'.$reg[1].'_'.$reg[2];
948
+                    $ent = 'entrepot_'.$reg[1].'_'.$reg[2];
949
+                    $pu = 'pu_'.$reg[1].'_'.$reg[2];
950
+                    $lot = 'lot_number_'.$reg[1].'_'.$reg[2];
951
+                    $dDLUO = dol_mktime(12, 0, 0, $_POST['dluo_'.$reg[1].'_'.$reg[2].'month'], $_POST['dluo_'.$reg[1].'_'.$reg[2].'day'], $_POST['dluo_'.$reg[1].'_'.$reg[2].'year']);
952
+                    $dDLC = dol_mktime(12, 0, 0, $_POST['dlc_'.$reg[1].'_'.$reg[2].'month'], $_POST['dlc_'.$reg[1].'_'.$reg[2].'day'], $_POST['dlc_'.$reg[1].'_'.$reg[2].'year']);
953
+                    $fk_commandefourndet = 'fk_commandefourndet_'.$reg[1].'_'.$reg[2];
954
+                    $dispatchLines[$numAsked]=array('prod' => GETPOST($prod, 'int'), 'qty' =>GETPOST($qty), 'ent' =>GETPOST($ent, 'int'), 'pu' =>GETPOST($pu), 'comment' =>GETPOST('comment'),'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'),'DLC'=> $dDLC,'DLUO'=> $dDLUO,'lot'=> GETPOST($lot, 'alpha'));
955
+                }
956
+            }
957 957
 
958 958
 
959 959
             print '<script type="text/javascript" language="javascript">
960 960
             jQuery(document).ready(function() {
961 961
 	            jQuery("#autofill").click(function() {';
962
-    	    	$i=1;
963
-    	    	while($i <= $numAsked)
964
-    	    	{
965
-    	    		print 'jQuery("#qtyl'.$i.'").val(jQuery("#qtyasked'.$i.'").val() - jQuery("#qtydelivered'.$i.'").val());'."\n";
966
-    	    		$i++;
967
-    	    	}
968
-        		print '});
962
+                $i=1;
963
+                while($i <= $numAsked)
964
+                {
965
+                    print 'jQuery("#qtyl'.$i.'").val(jQuery("#qtyasked'.$i.'").val() - jQuery("#qtydelivered'.$i.'").val());'."\n";
966
+                    $i++;
967
+                }
968
+                print '});
969 969
 	            jQuery("#autoreset").click(function() {';
970
-    	    	$i=1;
971
-    	    	while($i <= $numAsked)
972
-    	    	{
973
-    	    		print 'jQuery("#qtyl'.$i.'").val(0);'."\n";
974
-    	    		$i++;
975
-    	    	}
976
-        		print '});
970
+                $i=1;
971
+                while($i <= $numAsked)
972
+                {
973
+                    print 'jQuery("#qtyl'.$i.'").val(0);'."\n";
974
+                    $i++;
975
+                }
976
+                print '});
977 977
         	});
978 978
             </script>';
979 979
 
@@ -994,22 +994,22 @@  discard block
 block discarded – undo
994 994
                 print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
995 995
                 print '<td align="center">'.$langs->trans("QtyReceived").'</td>';
996 996
                 print '<td align="center">'.$langs->trans("QtyToReceive");
997
-				if (empty($conf->productbatch->enabled))
998
-				{
999
-	                print ' <br>(<a href="#" id="autofill">'.$langs->trans("Fill").'</a>';
1000
-	                print ' / <a href="#" id="autoreset">'.$langs->trans("Reset").'</a>)';
1001
-				}
997
+                if (empty($conf->productbatch->enabled))
998
+                {
999
+                    print ' <br>(<a href="#" id="autofill">'.$langs->trans("Fill").'</a>';
1000
+                    print ' / <a href="#" id="autoreset">'.$langs->trans("Reset").'</a>)';
1001
+                }
1002 1002
                 print '</td>';
1003 1003
                 if (! empty($conf->stock->enabled))
1004 1004
                 {
1005
-					print '<td align="left">'.$langs->trans("Warehouse").' ('.$langs->trans("Stock").')</td>';
1005
+                    print '<td align="left">'.$langs->trans("Warehouse").' ('.$langs->trans("Stock").')</td>';
1006
+                }
1007
+                if (!empty($conf->productbatch->enabled))
1008
+                {
1009
+                    print '<td align="left">'.$langs->trans("batch_number").'</td>';
1010
+                    print '<td align="left">'.$langs->trans("EatByDate").'</td>';
1011
+                    print '<td align="left">'.$langs->trans("SellByDate").'</td>';
1006 1012
                 }
1007
-				if (!empty($conf->productbatch->enabled))
1008
-				{
1009
-					print '<td align="left">'.$langs->trans("batch_number").'</td>';
1010
-					print '<td align="left">'.$langs->trans("EatByDate").'</td>';
1011
-					print '<td align="left">'.$langs->trans("SellByDate").'</td>';
1012
-				}
1013 1013
                 print "</tr>\n";
1014 1014
             }
1015 1015
 
@@ -1018,12 +1018,12 @@  discard block
 block discarded – undo
1018 1018
             while ($indiceAsked <= $numAsked)
1019 1019
             {
1020 1020
                 $product = new Product($db);
1021
-				foreach($object->lines as $supplierLine){
1022
-					if($dispatchLines[$indiceAsked]['fk_commandefourndet'] == $supplierLine->id){
1023
-						$line = $supplierLine;
1024
-						break;
1025
-					}
1026
-				}
1021
+                foreach($object->lines as $supplierLine){
1022
+                    if($dispatchLines[$indiceAsked]['fk_commandefourndet'] == $supplierLine->id){
1023
+                        $line = $supplierLine;
1024
+                        break;
1025
+                    }
1026
+                }
1027 1027
 
1028 1028
 
1029 1029
                 // Show product and description
@@ -1070,16 +1070,16 @@  discard block
 block discarded – undo
1070 1070
                     print '</td>';
1071 1071
                 }
1072 1072
                 else
1073
-				{
1074
-				    print "<td>";
1073
+                {
1074
+                    print "<td>";
1075 1075
                     if ($type==1) $text = img_object($langs->trans('Service'),'service');
1076 1076
                     else $text = img_object($langs->trans('Product'),'product');
1077 1077
 
1078 1078
                     if (! empty($line->label)) {
1079
-                    	$text.= ' <strong>'.$line->label.'</strong>';
1080
-                    	print $form->textwithtooltip($text,$line->desc,3,'','',$i);
1079
+                        $text.= ' <strong>'.$line->label.'</strong>';
1080
+                        print $form->textwithtooltip($text,$line->desc,3,'','',$i);
1081 1081
                     } else {
1082
-                    	print $text.' '.nl2br($line->desc);
1082
+                        print $text.' '.nl2br($line->desc);
1083 1083
                     }
1084 1084
 
1085 1085
                     // Show range
@@ -1089,8 +1089,8 @@  discard block
 block discarded – undo
1089 1089
 
1090 1090
                 // Qty
1091 1091
                 print '<td align="center">'.$line->qty;
1092
-				print '<input type="hidden" name="fk_commandefournisseurdet'.$indiceAsked.'" value=\''.$line->id.'\' />';
1093
-				print '<textarea style="display:none;"  name="comment'.$indiceAsked.'" >'.$line->desc.'</textarea>';
1092
+                print '<input type="hidden" name="fk_commandefournisseurdet'.$indiceAsked.'" value=\''.$line->id.'\' />';
1093
+                print '<textarea style="display:none;"  name="comment'.$indiceAsked.'" >'.$line->desc.'</textarea>';
1094 1094
                 print '<input name="qtyasked'.$indiceAsked.'" id="qtyasked'.$indiceAsked.'" type="hidden" value="'.$line->qty.'">';
1095 1095
                 print '</td>';
1096 1096
                 $qtyProdCom=$line->qty;
@@ -1105,96 +1105,96 @@  discard block
 block discarded – undo
1105 1105
                 print '</td>';
1106 1106
 
1107 1107
 
1108
-				if ($line->product_type == 1 && empty($conf->global->STOCK_SUPPORTS_SERVICES))
1109
-				{
1110
-					$quantityToBeDelivered = 0;
1111
-				}
1112
-				else
1113
-				{
1114
-					$quantityToBeDelivered = $dispatchLines[$indiceAsked]['qty'];
1115
-				}
1108
+                if ($line->product_type == 1 && empty($conf->global->STOCK_SUPPORTS_SERVICES))
1109
+                {
1110
+                    $quantityToBeDelivered = 0;
1111
+                }
1112
+                else
1113
+                {
1114
+                    $quantityToBeDelivered = $dispatchLines[$indiceAsked]['qty'];
1115
+                }
1116 1116
                 $warehouse_id = $dispatchLines[$indiceAsked]['ent'];
1117 1117
 
1118 1118
 
1119
-				$warehouseObject = null;
1120
-				if ( !empty($conf->stock->enabled))     // If warehouse was already selected or if product is not a predefined, we go into this part with no multiwarehouse selection
1121
-				{
1122
-				    print '<!-- Case warehouse already known or product not a predefined product -->';
1119
+                $warehouseObject = null;
1120
+                if ( !empty($conf->stock->enabled))     // If warehouse was already selected or if product is not a predefined, we go into this part with no multiwarehouse selection
1121
+                {
1122
+                    print '<!-- Case warehouse already known or product not a predefined product -->';
1123 1123
 
1124
-					$stock = + $product->stock_warehouse[$dispatchLines[$indiceAsked]['ent']]->real; // Convert to number
1125
-					$deliverableQty=$dispatchLines[$indiceAsked]['qty'];
1124
+                    $stock = + $product->stock_warehouse[$dispatchLines[$indiceAsked]['ent']]->real; // Convert to number
1125
+                    $deliverableQty=$dispatchLines[$indiceAsked]['qty'];
1126 1126
 
1127 1127
 
1128 1128
 
1129
-						// Quantity to send
1130
-						print '<td align="center">';
1131
-						if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
1132
-						{
1129
+                        // Quantity to send
1130
+                        print '<td align="center">';
1131
+                        if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
1132
+                        {
1133 1133
                             if (GETPOST('qtyl'.$indiceAsked, 'int')) $defaultqty=GETPOST('qtyl'.$indiceAsked, 'int');
1134 1134
                             print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
1135
-							print '<input name="qtyl'.$indiceAsked.'" id="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$deliverableQty.'">';
1136
-						}
1137
-						else print $langs->trans("NA");
1138
-						print '</td>';
1139
-
1140
-						// Stock
1141
-						if (! empty($conf->stock->enabled))
1142
-						{
1143
-							print '<td align="left">';
1144
-							if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))   // Type of product need stock change ?
1145
-							{
1146
-								// Show warehouse combo list
1147
-								$ent = "entl".$indiceAsked;
1148
-								$idl = "idl".$indiceAsked;
1149
-								$tmpentrepot_id = is_numeric(GETPOST($ent,'int'))?GETPOST($ent,'int'):$warehouse_id;
1150
-								if ($line->fk_product > 0)
1151
-								{
1152
-									print '<!-- Show warehouse selection -->';
1153
-									print $formproduct->selectWarehouses($tmpentrepot_id, 'entl'.$indiceAsked, '', 0, 0, $line->fk_product, '', 1);
1154
-								}
1155
-							}
1156
-							else
1157
-							{
1158
-								print $langs->trans("Service");
1159
-							}
1160
-							print '</td>';
1161
-						}
1162
-
1163
-						if (!empty($conf->productbatch->enabled))
1164
-						{
1165
-							if (!empty($product->status_batch))
1166
-							{
1167
-								print '<td><input name="batch'.$indiceAsked.'" value="'.$dispatchLines[$indiceAsked]['lot'].'"></td>';
1168
-								print '<td>';
1169
-								print $form->select_date($dispatchLines[$indiceAsked]['DLC'],'dlc' . $indiceAsked, '', '', 1, "");
1170
-								print '</td>';
1171
-								print '<td>';
1172
-								print $form->select_date($dispatchLines[$indiceAsked]['DLUO'],'dluo' . $indiceAsked, '', '', 1, "");
1173
-								print '</td>';
1174
-							}
1175
-							else {
1176
-								print '<td colspan="3"></td>';
1177
-							}
1178
-						}
1179
-						print "</tr>\n";
1180
-				}
1181
-
1182
-				//Display lines extrafields
1183
-				if (is_array($extralabelslines) && count($extralabelslines)>0)
1184
-				{
1185
-					$colspan=5;
1186
-					if($conf->productbatch->enabled)$colspan+=3;
1187
-					$orderLineExtrafields = new Extrafields($db);
1188
-					$orderLineExtrafieldLabels = $orderLineExtrafields->fetch_name_optionals_label($object->table_element_line);
1189
-					$srcLine = new CommandeFournisseurLigne($db);
1190
-					$srcLine->fetch_optionals($line->id,$orderLineExtrafieldLabels); // fetch extrafields also available in orderline
1191
-					$line = new CommandeFournisseurDispatch($db);
1192
-					$line->fetch_optionals($object->id,$extralabelslines);
1193
-					$line->array_options = array_merge($line->array_options, $srcLine->array_options);
1194
-					print '<tr class="oddeven">';
1195
-					print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked);
1196
-					print '</tr>';
1197
-				}
1135
+                            print '<input name="qtyl'.$indiceAsked.'" id="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$deliverableQty.'">';
1136
+                        }
1137
+                        else print $langs->trans("NA");
1138
+                        print '</td>';
1139
+
1140
+                        // Stock
1141
+                        if (! empty($conf->stock->enabled))
1142
+                        {
1143
+                            print '<td align="left">';
1144
+                            if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))   // Type of product need stock change ?
1145
+                            {
1146
+                                // Show warehouse combo list
1147
+                                $ent = "entl".$indiceAsked;
1148
+                                $idl = "idl".$indiceAsked;
1149
+                                $tmpentrepot_id = is_numeric(GETPOST($ent,'int'))?GETPOST($ent,'int'):$warehouse_id;
1150
+                                if ($line->fk_product > 0)
1151
+                                {
1152
+                                    print '<!-- Show warehouse selection -->';
1153
+                                    print $formproduct->selectWarehouses($tmpentrepot_id, 'entl'.$indiceAsked, '', 0, 0, $line->fk_product, '', 1);
1154
+                                }
1155
+                            }
1156
+                            else
1157
+                            {
1158
+                                print $langs->trans("Service");
1159
+                            }
1160
+                            print '</td>';
1161
+                        }
1162
+
1163
+                        if (!empty($conf->productbatch->enabled))
1164
+                        {
1165
+                            if (!empty($product->status_batch))
1166
+                            {
1167
+                                print '<td><input name="batch'.$indiceAsked.'" value="'.$dispatchLines[$indiceAsked]['lot'].'"></td>';
1168
+                                print '<td>';
1169
+                                print $form->select_date($dispatchLines[$indiceAsked]['DLC'],'dlc' . $indiceAsked, '', '', 1, "");
1170
+                                print '</td>';
1171
+                                print '<td>';
1172
+                                print $form->select_date($dispatchLines[$indiceAsked]['DLUO'],'dluo' . $indiceAsked, '', '', 1, "");
1173
+                                print '</td>';
1174
+                            }
1175
+                            else {
1176
+                                print '<td colspan="3"></td>';
1177
+                            }
1178
+                        }
1179
+                        print "</tr>\n";
1180
+                }
1181
+
1182
+                //Display lines extrafields
1183
+                if (is_array($extralabelslines) && count($extralabelslines)>0)
1184
+                {
1185
+                    $colspan=5;
1186
+                    if($conf->productbatch->enabled)$colspan+=3;
1187
+                    $orderLineExtrafields = new Extrafields($db);
1188
+                    $orderLineExtrafieldLabels = $orderLineExtrafields->fetch_name_optionals_label($object->table_element_line);
1189
+                    $srcLine = new CommandeFournisseurLigne($db);
1190
+                    $srcLine->fetch_optionals($line->id,$orderLineExtrafieldLabels); // fetch extrafields also available in orderline
1191
+                    $line = new CommandeFournisseurDispatch($db);
1192
+                    $line->fetch_optionals($object->id,$extralabelslines);
1193
+                    $line->array_options = array_merge($line->array_options, $srcLine->array_options);
1194
+                    print '<tr class="oddeven">';
1195
+                    print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked);
1196
+                    print '</tr>';
1197
+                }
1198 1198
 
1199 1199
                 $indiceAsked++;
1200 1200
             }
@@ -1214,7 +1214,7 @@  discard block
 block discarded – undo
1214 1214
             print '<br>';
1215 1215
         }
1216 1216
         else
1217
-		{
1217
+        {
1218 1218
             dol_print_error($db);
1219 1219
         }
1220 1220
     }
@@ -1226,111 +1226,111 @@  discard block
 block discarded – undo
1226 1226
 /*                                                                             */
1227 1227
 /* *************************************************************************** */
1228 1228
 {
1229
-	$lines = $object->lines;
1229
+    $lines = $object->lines;
1230 1230
 
1231
-	$num_prod = count($lines);
1231
+    $num_prod = count($lines);
1232 1232
 
1233
-	if ($object->id > 0)
1234
-	{
1235
-		if (!empty($object->origin) && $object->origin_id > 0)
1236
-		{
1237
-			$object->origin = 'CommandeFournisseur';
1238
-			$typeobject = $object->origin;
1239
-			$origin = $object->origin;
1240
-			$origin_id = $object->origin_id;
1241
-			$object->fetch_origin();         // Load property $object->commande, $object->propal, ...
1242
-		}
1243
-
1244
-		$soc = new Societe($db);
1245
-		$soc->fetch($object->socid);
1246
-
1247
-		$res = $object->fetch_optionals($object->id, $extralabels);
1248
-
1249
-		$head=reception_prepare_head($object);
1250
-		dol_fiche_head($head, 'reception', $langs->trans("Reception"), -1, 'reception');
1251
-
1252
-		$formconfirm='';
1253
-
1254
-		// Confirm deleteion
1255
-		if ($action == 'delete')
1256
-		{
1257
-			$formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('DeleteReception'),$langs->trans("ConfirmDeleteReception",$object->ref),'confirm_delete','',0,1);
1258
-		}
1259
-
1260
-		// Confirmation validation
1261
-		if ($action == 'valid')
1262
-		{
1263
-			$objectref = substr($object->ref, 1, 4);
1264
-			if ($objectref == 'PROV')
1265
-			{
1266
-				$numref = $object->getNextNumRef($soc);
1267
-			}
1268
-			else
1269
-			{
1270
-				$numref = $object->ref;
1271
-			}
1272
-
1273
-			$text = $langs->trans("ConfirmValidateReception",$numref);
1274
-
1275
-			if (! empty($conf->notification->enabled))
1276
-			{
1277
-				require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
1278
-				$notify=new Notify($db);
1279
-				$text.='<br>';
1280
-				$text.=$notify->confirmMessage('RECEPTION_VALIDATE',$object->socid, $object);
1281
-			}
1282
-
1283
-			$formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('ValidateReception'),$text,'confirm_valid','',0,1);
1284
-		}
1285
-
1286
-		// Confirm cancelation
1287
-		if ($action == 'annuler')
1288
-		{
1289
-			$formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('CancelReception'),$langs->trans("ConfirmCancelReception",$object->ref),'confirm_cancel','',0,1);
1290
-		}
1291
-
1292
-		if (! $formconfirm) {
1293
-		    $parameters = array();
1294
-		    $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1295
-		    if (empty($reshook)) $formconfirm.=$hookmanager->resPrint;
1296
-		    elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint;
1297
-		}
1298
-
1299
-		// Print form confirm
1300
-		print $formconfirm;
1301
-
1302
-
1303
-		// Calculate totalWeight and totalVolume for all products
1304
-		// by adding weight and volume of each product line.
1305
-		$tmparray=$object->getTotalWeightVolume();
1306
-		$totalWeight=$tmparray['weight'];
1307
-		$totalVolume=$tmparray['volume'];
1308
-
1309
-
1310
-		if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
1311
-		{
1312
-		    $objectsrc=new Commande($db);
1313
-		    $objectsrc->fetch($object->$typeobject->id);
1314
-		}
1315
-		if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
1316
-		{
1317
-		    $objectsrc=new Propal($db);
1318
-		    $objectsrc->fetch($object->$typeobject->id);
1319
-		}
1320
-		if ($typeobject == 'CommandeFournisseur' && $object->$typeobject->id && ! empty($conf->fournisseur->enabled))
1321
-		{
1322
-		    $objectsrc=new CommandeFournisseur($db);
1323
-		    $objectsrc->fetch($object->$typeobject->id);
1324
-		}
1325
-		// Reception card
1326
-		$linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">'.$langs->trans("BackToList").'</a>';
1327
-		$morehtmlref='<div class="refidno">';
1328
-		// Ref customer reception
1329
-
1330
-		$morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1);
1331
-		$morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1);
1332
-
1333
-		// Thirdparty
1233
+    if ($object->id > 0)
1234
+    {
1235
+        if (!empty($object->origin) && $object->origin_id > 0)
1236
+        {
1237
+            $object->origin = 'CommandeFournisseur';
1238
+            $typeobject = $object->origin;
1239
+            $origin = $object->origin;
1240
+            $origin_id = $object->origin_id;
1241
+            $object->fetch_origin();         // Load property $object->commande, $object->propal, ...
1242
+        }
1243
+
1244
+        $soc = new Societe($db);
1245
+        $soc->fetch($object->socid);
1246
+
1247
+        $res = $object->fetch_optionals($object->id, $extralabels);
1248
+
1249
+        $head=reception_prepare_head($object);
1250
+        dol_fiche_head($head, 'reception', $langs->trans("Reception"), -1, 'reception');
1251
+
1252
+        $formconfirm='';
1253
+
1254
+        // Confirm deleteion
1255
+        if ($action == 'delete')
1256
+        {
1257
+            $formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('DeleteReception'),$langs->trans("ConfirmDeleteReception",$object->ref),'confirm_delete','',0,1);
1258
+        }
1259
+
1260
+        // Confirmation validation
1261
+        if ($action == 'valid')
1262
+        {
1263
+            $objectref = substr($object->ref, 1, 4);
1264
+            if ($objectref == 'PROV')
1265
+            {
1266
+                $numref = $object->getNextNumRef($soc);
1267
+            }
1268
+            else
1269
+            {
1270
+                $numref = $object->ref;
1271
+            }
1272
+
1273
+            $text = $langs->trans("ConfirmValidateReception",$numref);
1274
+
1275
+            if (! empty($conf->notification->enabled))
1276
+            {
1277
+                require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
1278
+                $notify=new Notify($db);
1279
+                $text.='<br>';
1280
+                $text.=$notify->confirmMessage('RECEPTION_VALIDATE',$object->socid, $object);
1281
+            }
1282
+
1283
+            $formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('ValidateReception'),$text,'confirm_valid','',0,1);
1284
+        }
1285
+
1286
+        // Confirm cancelation
1287
+        if ($action == 'annuler')
1288
+        {
1289
+            $formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('CancelReception'),$langs->trans("ConfirmCancelReception",$object->ref),'confirm_cancel','',0,1);
1290
+        }
1291
+
1292
+        if (! $formconfirm) {
1293
+            $parameters = array();
1294
+            $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1295
+            if (empty($reshook)) $formconfirm.=$hookmanager->resPrint;
1296
+            elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint;
1297
+        }
1298
+
1299
+        // Print form confirm
1300
+        print $formconfirm;
1301
+
1302
+
1303
+        // Calculate totalWeight and totalVolume for all products
1304
+        // by adding weight and volume of each product line.
1305
+        $tmparray=$object->getTotalWeightVolume();
1306
+        $totalWeight=$tmparray['weight'];
1307
+        $totalVolume=$tmparray['volume'];
1308
+
1309
+
1310
+        if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
1311
+        {
1312
+            $objectsrc=new Commande($db);
1313
+            $objectsrc->fetch($object->$typeobject->id);
1314
+        }
1315
+        if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
1316
+        {
1317
+            $objectsrc=new Propal($db);
1318
+            $objectsrc->fetch($object->$typeobject->id);
1319
+        }
1320
+        if ($typeobject == 'CommandeFournisseur' && $object->$typeobject->id && ! empty($conf->fournisseur->enabled))
1321
+        {
1322
+            $objectsrc=new CommandeFournisseur($db);
1323
+            $objectsrc->fetch($object->$typeobject->id);
1324
+        }
1325
+        // Reception card
1326
+        $linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">'.$langs->trans("BackToList").'</a>';
1327
+        $morehtmlref='<div class="refidno">';
1328
+        // Ref customer reception
1329
+
1330
+        $morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1);
1331
+        $morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1);
1332
+
1333
+        // Thirdparty
1334 1334
         $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
1335 1335
         // Project
1336 1336
         if (! empty($conf->projet->enabled))
@@ -1367,897 +1367,897 @@  discard block
 block discarded – undo
1367 1367
                 }
1368 1368
             }
1369 1369
         }
1370
-		$morehtmlref.='</div>';
1370
+        $morehtmlref.='</div>';
1371 1371
 
1372
-		$object->picto = 'sending';
1373
-    	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
1372
+        $object->picto = 'sending';
1373
+        dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
1374 1374
 
1375 1375
 
1376
-    	print '<div class="fichecenter">';
1377
-    	print '<div class="fichehalfleft">';
1378
-    	print '<div class="underbanner clearboth"></div>';
1376
+        print '<div class="fichecenter">';
1377
+        print '<div class="fichehalfleft">';
1378
+        print '<div class="underbanner clearboth"></div>';
1379 1379
 
1380 1380
         print '<table class="border" width="100%">';
1381 1381
 
1382
-		// Linked documents
1383
-		if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
1384
-		{
1385
-			print '<tr><td>';
1386
-			print $langs->trans("RefOrder").'</td>';
1387
-			print '<td colspan="3">';
1388
-			print $objectsrc->getNomUrl(1,'commande');
1389
-			print "</td>\n";
1390
-			print '</tr>';
1391
-		}
1392
-		if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
1393
-		{
1394
-			print '<tr><td>';
1395
-			print $langs->trans("RefProposal").'</td>';
1396
-			print '<td colspan="3">';
1397
-			print $objectsrc->getNomUrl(1,'reception');
1398
-			print "</td>\n";
1399
-			print '</tr>';
1400
-		}
1401
-		if ($typeobject == 'CommandeFournisseur' && $object->$typeobject->id && ! empty($conf->propal->enabled))
1402
-		{
1403
-			print '<tr><td>';
1404
-			print $langs->trans("RefSupplierOrder").'</td>';
1405
-			print '<td colspan="3">';
1406
-			print $objectsrc->getNomUrl(1,'reception');
1407
-			print "</td>\n";
1408
-			print '</tr>';
1409
-		}
1410
-
1411
-		// Date creation
1412
-		print '<tr><td class="titlefield">'.$langs->trans("DateCreation").'</td>';
1413
-		print '<td colspan="3">'.dol_print_date($object->date_creation,"dayhour")."</td>\n";
1414
-		print '</tr>';
1415
-
1416
-		// Delivery date planned
1417
-		print '<tr><td height="10">';
1418
-		print '<table class="nobordernopadding" width="100%"><tr><td>';
1419
-		print $langs->trans('DateDeliveryPlanned');
1420
-		print '</td>';
1421
-
1422
-		if ($action != 'editdate_livraison') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).'</a></td>';
1423
-		print '</tr></table>';
1424
-		print '</td><td colspan="2">';
1425
-		if ($action == 'editdate_livraison')
1426
-		{
1427
-			print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
1428
-			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1429
-			print '<input type="hidden" name="action" value="setdate_livraison">';
1430
-			print $form->select_date($object->date_delivery?$object->date_delivery:-1,'liv_',1,1,'',"setdate_livraison",1,0,1);
1431
-			print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
1432
-			print '</form>';
1433
-		}
1434
-		else
1435
-		{
1436
-			print $object->date_delivery ? dol_print_date($object->date_delivery,'dayhour') : '&nbsp;';
1437
-		}
1438
-		print '</td>';
1439
-		print '</tr>';
1440
-
1441
-		// Weight
1442
-		print '<tr><td>';
1443
-		print $form->editfieldkey("Weight",'trueWeight',$object->trueWeight,$object,$user->rights->reception->creer);
1444
-		print '</td><td colspan="3">';
1445
-
1446
-		if ($action=='edittrueWeight')
1447
-		{
1448
-			print '<form name="settrueweight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
1449
-			print '<input name="action" value="settrueWeight" type="hidden">';
1450
-			print '<input name="id" value="'.$object->id.'" type="hidden">';
1451
-			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1452
-			print '<input id="trueWeight" name="trueWeight" value="'.$object->trueWeight.'" type="text">';
1453
-			print $formproduct->select_measuring_units("weight_units","weight",$object->weight_units);
1454
-			print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
1455
-			print ' <input class="button" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
1456
-			print '</form>';
1457
-		}
1458
-		else
1459
-		{
1460
-			print $object->trueWeight;
1461
-			print ($object->trueWeight && $object->weight_units!='')?' '.measuring_units_string($object->weight_units,"weight"):'';
1462
-		}
1382
+        // Linked documents
1383
+        if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
1384
+        {
1385
+            print '<tr><td>';
1386
+            print $langs->trans("RefOrder").'</td>';
1387
+            print '<td colspan="3">';
1388
+            print $objectsrc->getNomUrl(1,'commande');
1389
+            print "</td>\n";
1390
+            print '</tr>';
1391
+        }
1392
+        if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
1393
+        {
1394
+            print '<tr><td>';
1395
+            print $langs->trans("RefProposal").'</td>';
1396
+            print '<td colspan="3">';
1397
+            print $objectsrc->getNomUrl(1,'reception');
1398
+            print "</td>\n";
1399
+            print '</tr>';
1400
+        }
1401
+        if ($typeobject == 'CommandeFournisseur' && $object->$typeobject->id && ! empty($conf->propal->enabled))
1402
+        {
1403
+            print '<tr><td>';
1404
+            print $langs->trans("RefSupplierOrder").'</td>';
1405
+            print '<td colspan="3">';
1406
+            print $objectsrc->getNomUrl(1,'reception');
1407
+            print "</td>\n";
1408
+            print '</tr>';
1409
+        }
1410
+
1411
+        // Date creation
1412
+        print '<tr><td class="titlefield">'.$langs->trans("DateCreation").'</td>';
1413
+        print '<td colspan="3">'.dol_print_date($object->date_creation,"dayhour")."</td>\n";
1414
+        print '</tr>';
1415
+
1416
+        // Delivery date planned
1417
+        print '<tr><td height="10">';
1418
+        print '<table class="nobordernopadding" width="100%"><tr><td>';
1419
+        print $langs->trans('DateDeliveryPlanned');
1420
+        print '</td>';
1421
+
1422
+        if ($action != 'editdate_livraison') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).'</a></td>';
1423
+        print '</tr></table>';
1424
+        print '</td><td colspan="2">';
1425
+        if ($action == 'editdate_livraison')
1426
+        {
1427
+            print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
1428
+            print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1429
+            print '<input type="hidden" name="action" value="setdate_livraison">';
1430
+            print $form->select_date($object->date_delivery?$object->date_delivery:-1,'liv_',1,1,'',"setdate_livraison",1,0,1);
1431
+            print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
1432
+            print '</form>';
1433
+        }
1434
+        else
1435
+        {
1436
+            print $object->date_delivery ? dol_print_date($object->date_delivery,'dayhour') : '&nbsp;';
1437
+        }
1438
+        print '</td>';
1439
+        print '</tr>';
1440
+
1441
+        // Weight
1442
+        print '<tr><td>';
1443
+        print $form->editfieldkey("Weight",'trueWeight',$object->trueWeight,$object,$user->rights->reception->creer);
1444
+        print '</td><td colspan="3">';
1445
+
1446
+        if ($action=='edittrueWeight')
1447
+        {
1448
+            print '<form name="settrueweight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
1449
+            print '<input name="action" value="settrueWeight" type="hidden">';
1450
+            print '<input name="id" value="'.$object->id.'" type="hidden">';
1451
+            print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1452
+            print '<input id="trueWeight" name="trueWeight" value="'.$object->trueWeight.'" type="text">';
1453
+            print $formproduct->select_measuring_units("weight_units","weight",$object->weight_units);
1454
+            print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
1455
+            print ' <input class="button" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
1456
+            print '</form>';
1457
+        }
1458
+        else
1459
+        {
1460
+            print $object->trueWeight;
1461
+            print ($object->trueWeight && $object->weight_units!='')?' '.measuring_units_string($object->weight_units,"weight"):'';
1462
+        }
1463 1463
 
1464 1464
         // Calculated
1465
-		if ($totalWeight > 0)
1466
-		{
1467
-			if (!empty($object->trueWeight)) print ' ('.$langs->trans("SumOfProductWeights").': ';
1468
-			//print $totalWeight.' '.measuring_units_string(0,"weight");
1469
-			print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND)?$conf->global->MAIN_WEIGHT_DEFAULT_ROUND:-1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT)?$conf->global->MAIN_WEIGHT_DEFAULT_UNIT:'no');
1470
-			//if (empty($object->trueWeight)) print ' ('.$langs->trans("Calculated").')';
1471
-			if (!empty($object->trueWeight)) print ')';
1472
-		}
1473
-		print '</td></tr>';
1474
-
1475
-		// Width
1476
-		print '<tr><td>'.$form->editfieldkey("Width",'trueWidth',$object->trueWidth,$object,$user->rights->reception->creer).'</td><td colspan="3">';
1477
-		print $form->editfieldval("Width",'trueWidth',$object->trueWidth,$object,$user->rights->reception->creer);
1478
-		print ($object->trueWidth && $object->width_units!='')?' '.measuring_units_string($object->width_units,"size"):'';
1479
-		print '</td></tr>';
1480
-
1481
-		// Height
1482
-		print '<tr><td>'.$form->editfieldkey("Height",'trueHeight',$object->trueHeight,$object,$user->rights->reception->creer).'</td><td colspan="3">';
1483
-		if($action=='edittrueHeight')
1484
-		{
1485
-			print '<form name="settrueHeight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
1486
-			print '<input name="action" value="settrueHeight" type="hidden">';
1487
-			print '<input name="id" value="'.$object->id.'" type="hidden">';
1488
-			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1489
-			print '<input id="trueHeight" name="trueHeight" value="'.$object->trueHeight.'" type="text">';
1490
-			print $formproduct->select_measuring_units("size_units","size",$object->size_units);
1491
-			print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
1492
-			print ' <input class="button" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
1493
-			print '</form>';
1494
-		}
1495
-		else
1496
-		{
1497
-			print $object->trueHeight;
1498
-			print ($object->trueHeight && $object->height_units!='')?' '.measuring_units_string($object->height_units,"size"):'';
1499
-		}
1500
-
1501
-		print '</td></tr>';
1502
-
1503
-		// Depth
1504
-		print '<tr><td>'.$form->editfieldkey("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->reception->creer).'</td><td colspan="3">';
1505
-		print $form->editfieldval("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->reception->creer);
1506
-		print ($object->trueDepth && $object->depth_units!='')?' '.measuring_units_string($object->depth_units,"size"):'';
1507
-		print '</td></tr>';
1508
-
1509
-		// Volume
1510
-		print '<tr><td>';
1511
-		print $langs->trans("Volume");
1512
-		print '</td>';
1513
-		print '<td colspan="3">';
1514
-		$calculatedVolume=0;
1515
-		$volumeUnit=0;
1516
-		if ($object->trueWidth && $object->trueHeight && $object->trueDepth)
1517
-		{
1518
-		    $calculatedVolume=($object->trueWidth * $object->trueHeight * $object->trueDepth);
1519
-		    $volumeUnit=$object->size_units * 3;
1520
-		}
1521
-		// If reception volume not defined we use sum of products
1522
-		if ($calculatedVolume > 0)
1523
-		{
1524
-			if ($volumeUnit < 50)
1525
-			{
1526
-			    //print $calculatedVolume.' '.measuring_units_string($volumeUnit,"volume");
1527
-			    print showDimensionInBestUnit($calculatedVolume, $volumeUnit, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND)?$conf->global->MAIN_VOLUME_DEFAULT_ROUND:-1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT)?$conf->global->MAIN_VOLUME_DEFAULT_UNIT:'no');
1528
-			}
1529
-			else print $calculatedVolume.' '.measuring_units_string($volumeUnit,"volume");
1530
-		}
1531
-		if ($totalVolume > 0)
1532
-		{
1533
-			if ($calculatedVolume) print ' ('.$langs->trans("SumOfProductVolumes").': ';
1534
-			//print $totalVolume.' '.measuring_units_string(0,"volume");
1535
-			print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND)?$conf->global->MAIN_VOLUME_DEFAULT_ROUND:-1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT)?$conf->global->MAIN_VOLUME_DEFAULT_UNIT:'no');
1536
-			//if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')';
1537
-			if ($calculatedVolume) print ')';
1538
-		}
1539
-		print "</td>\n";
1540
-		print '</tr>';
1541
-
1542
-		// Other attributes
1543
-		$cols = 2;
1544
-
1545
-		include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
1546
-
1547
-		print '</table>';
1548
-
1549
-		print '</div>';
1550
-		print '<div class="fichehalfright">';
1551
-		print '<div class="ficheaddleft">';
1552
-		print '<div class="underbanner clearboth"></div>';
1553
-
1554
-		print '<table class="border centpercent">';
1555
-
1556
-		// Reception method
1557
-		print '<tr><td height="10">';
1558
-		print '<table class="nobordernopadding" width="100%"><tr><td>';
1559
-		print $langs->trans('ReceptionMethod');
1560
-		print '</td>';
1561
-
1562
-		if ($action != 'editshipping_method_id') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editshipping_method_id&amp;id='.$object->id.'">'.img_edit($langs->trans('SetReceptionMethod'),1).'</a></td>';
1563
-		print '</tr></table>';
1564
-		print '</td><td colspan="2">';
1565
-		if ($action == 'editshipping_method_id')
1566
-		{
1567
-			print '<form name="setshipping_method_id" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
1568
-			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1569
-			print '<input type="hidden" name="action" value="setshipping_method_id">';
1570
-			$object->fetch_delivery_methods();
1571
-			print $form->selectarray("shipping_method_id",$object->meths,$object->shipping_method_id,1,0,0,"",1);
1572
-			if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1573
-			print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
1574
-			print '</form>';
1575
-		}
1576
-		else
1577
-		{
1578
-			if ($object->shipping_method_id > 0)
1579
-			{
1580
-				// Get code using getLabelFromKey
1581
-				$code=$langs->getLabelFromKey($db,$object->shipping_method_id,'c_shipment_mode','rowid','code');
1582
-				print $langs->trans("SendingMethod".strtoupper($code));
1583
-			}
1584
-		}
1585
-		print '</td>';
1586
-		print '</tr>';
1587
-
1588
-		// Tracking Number
1589
-
1590
-		print '<tr><td class="titlefield">'.$form->editfieldkey("TrackingNumber",'tracking_number',$object->tracking_number,$object,$user->rights->reception->creer).'</td><td colspan="3">';
1591
-		print $form->editfieldval("TrackingNumber",'tracking_number',$object->tracking_url,$object,$user->rights->reception->creer,'string',$object->tracking_number);
1592
-		print '</td></tr>';
1593
-
1594
-		// Incoterms
1595
-		if (!empty($conf->incoterm->enabled))
1596
-		{
1597
-			print '<tr><td>';
1598
-	        print '<table width="100%" class="nobordernopadding"><tr><td>';
1599
-	        print $langs->trans('IncotermLabel');
1600
-	        print '<td><td align="right">';
1601
-	        if ($user->rights->reception->creer) print '<a href="'.DOL_URL_ROOT.'/reception/card.php?id='.$object->id.'&action=editincoterm">'.img_edit().'</a>';
1602
-	        else print '&nbsp;';
1603
-	        print '</td></tr></table>';
1604
-	        print '</td>';
1605
-	        print '<td colspan="3">';
1606
-			if ($action != 'editincoterm')
1607
-			{
1608
-				print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1);
1609
-			}
1610
-			else
1611
-			{
1612
-				print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?id='.$object->id);
1613
-			}
1614
-	        print '</td></tr>';
1615
-		}
1616
-
1617
-		print "</table>";
1618
-
1619
-		print '</div>';
1620
-		print '</div>';
1621
-		print '</div>';
1622
-
1623
-		print '<div class="clearboth"></div>';
1624
-
1625
-
1626
-		// Lines of products
1627
-		if ($action == 'editline')
1628
-		{
1629
-			print '<form name="updateline" id="updateline" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;lineid=' . $line_id . '" method="POST">
1465
+        if ($totalWeight > 0)
1466
+        {
1467
+            if (!empty($object->trueWeight)) print ' ('.$langs->trans("SumOfProductWeights").': ';
1468
+            //print $totalWeight.' '.measuring_units_string(0,"weight");
1469
+            print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND)?$conf->global->MAIN_WEIGHT_DEFAULT_ROUND:-1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT)?$conf->global->MAIN_WEIGHT_DEFAULT_UNIT:'no');
1470
+            //if (empty($object->trueWeight)) print ' ('.$langs->trans("Calculated").')';
1471
+            if (!empty($object->trueWeight)) print ')';
1472
+        }
1473
+        print '</td></tr>';
1474
+
1475
+        // Width
1476
+        print '<tr><td>'.$form->editfieldkey("Width",'trueWidth',$object->trueWidth,$object,$user->rights->reception->creer).'</td><td colspan="3">';
1477
+        print $form->editfieldval("Width",'trueWidth',$object->trueWidth,$object,$user->rights->reception->creer);
1478
+        print ($object->trueWidth && $object->width_units!='')?' '.measuring_units_string($object->width_units,"size"):'';
1479
+        print '</td></tr>';
1480
+
1481
+        // Height
1482
+        print '<tr><td>'.$form->editfieldkey("Height",'trueHeight',$object->trueHeight,$object,$user->rights->reception->creer).'</td><td colspan="3">';
1483
+        if($action=='edittrueHeight')
1484
+        {
1485
+            print '<form name="settrueHeight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
1486
+            print '<input name="action" value="settrueHeight" type="hidden">';
1487
+            print '<input name="id" value="'.$object->id.'" type="hidden">';
1488
+            print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1489
+            print '<input id="trueHeight" name="trueHeight" value="'.$object->trueHeight.'" type="text">';
1490
+            print $formproduct->select_measuring_units("size_units","size",$object->size_units);
1491
+            print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
1492
+            print ' <input class="button" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
1493
+            print '</form>';
1494
+        }
1495
+        else
1496
+        {
1497
+            print $object->trueHeight;
1498
+            print ($object->trueHeight && $object->height_units!='')?' '.measuring_units_string($object->height_units,"size"):'';
1499
+        }
1500
+
1501
+        print '</td></tr>';
1502
+
1503
+        // Depth
1504
+        print '<tr><td>'.$form->editfieldkey("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->reception->creer).'</td><td colspan="3">';
1505
+        print $form->editfieldval("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->reception->creer);
1506
+        print ($object->trueDepth && $object->depth_units!='')?' '.measuring_units_string($object->depth_units,"size"):'';
1507
+        print '</td></tr>';
1508
+
1509
+        // Volume
1510
+        print '<tr><td>';
1511
+        print $langs->trans("Volume");
1512
+        print '</td>';
1513
+        print '<td colspan="3">';
1514
+        $calculatedVolume=0;
1515
+        $volumeUnit=0;
1516
+        if ($object->trueWidth && $object->trueHeight && $object->trueDepth)
1517
+        {
1518
+            $calculatedVolume=($object->trueWidth * $object->trueHeight * $object->trueDepth);
1519
+            $volumeUnit=$object->size_units * 3;
1520
+        }
1521
+        // If reception volume not defined we use sum of products
1522
+        if ($calculatedVolume > 0)
1523
+        {
1524
+            if ($volumeUnit < 50)
1525
+            {
1526
+                //print $calculatedVolume.' '.measuring_units_string($volumeUnit,"volume");
1527
+                print showDimensionInBestUnit($calculatedVolume, $volumeUnit, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND)?$conf->global->MAIN_VOLUME_DEFAULT_ROUND:-1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT)?$conf->global->MAIN_VOLUME_DEFAULT_UNIT:'no');
1528
+            }
1529
+            else print $calculatedVolume.' '.measuring_units_string($volumeUnit,"volume");
1530
+        }
1531
+        if ($totalVolume > 0)
1532
+        {
1533
+            if ($calculatedVolume) print ' ('.$langs->trans("SumOfProductVolumes").': ';
1534
+            //print $totalVolume.' '.measuring_units_string(0,"volume");
1535
+            print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND)?$conf->global->MAIN_VOLUME_DEFAULT_ROUND:-1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT)?$conf->global->MAIN_VOLUME_DEFAULT_UNIT:'no');
1536
+            //if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')';
1537
+            if ($calculatedVolume) print ')';
1538
+        }
1539
+        print "</td>\n";
1540
+        print '</tr>';
1541
+
1542
+        // Other attributes
1543
+        $cols = 2;
1544
+
1545
+        include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
1546
+
1547
+        print '</table>';
1548
+
1549
+        print '</div>';
1550
+        print '<div class="fichehalfright">';
1551
+        print '<div class="ficheaddleft">';
1552
+        print '<div class="underbanner clearboth"></div>';
1553
+
1554
+        print '<table class="border centpercent">';
1555
+
1556
+        // Reception method
1557
+        print '<tr><td height="10">';
1558
+        print '<table class="nobordernopadding" width="100%"><tr><td>';
1559
+        print $langs->trans('ReceptionMethod');
1560
+        print '</td>';
1561
+
1562
+        if ($action != 'editshipping_method_id') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editshipping_method_id&amp;id='.$object->id.'">'.img_edit($langs->trans('SetReceptionMethod'),1).'</a></td>';
1563
+        print '</tr></table>';
1564
+        print '</td><td colspan="2">';
1565
+        if ($action == 'editshipping_method_id')
1566
+        {
1567
+            print '<form name="setshipping_method_id" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
1568
+            print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1569
+            print '<input type="hidden" name="action" value="setshipping_method_id">';
1570
+            $object->fetch_delivery_methods();
1571
+            print $form->selectarray("shipping_method_id",$object->meths,$object->shipping_method_id,1,0,0,"",1);
1572
+            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1573
+            print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
1574
+            print '</form>';
1575
+        }
1576
+        else
1577
+        {
1578
+            if ($object->shipping_method_id > 0)
1579
+            {
1580
+                // Get code using getLabelFromKey
1581
+                $code=$langs->getLabelFromKey($db,$object->shipping_method_id,'c_shipment_mode','rowid','code');
1582
+                print $langs->trans("SendingMethod".strtoupper($code));
1583
+            }
1584
+        }
1585
+        print '</td>';
1586
+        print '</tr>';
1587
+
1588
+        // Tracking Number
1589
+
1590
+        print '<tr><td class="titlefield">'.$form->editfieldkey("TrackingNumber",'tracking_number',$object->tracking_number,$object,$user->rights->reception->creer).'</td><td colspan="3">';
1591
+        print $form->editfieldval("TrackingNumber",'tracking_number',$object->tracking_url,$object,$user->rights->reception->creer,'string',$object->tracking_number);
1592
+        print '</td></tr>';
1593
+
1594
+        // Incoterms
1595
+        if (!empty($conf->incoterm->enabled))
1596
+        {
1597
+            print '<tr><td>';
1598
+            print '<table width="100%" class="nobordernopadding"><tr><td>';
1599
+            print $langs->trans('IncotermLabel');
1600
+            print '<td><td align="right">';
1601
+            if ($user->rights->reception->creer) print '<a href="'.DOL_URL_ROOT.'/reception/card.php?id='.$object->id.'&action=editincoterm">'.img_edit().'</a>';
1602
+            else print '&nbsp;';
1603
+            print '</td></tr></table>';
1604
+            print '</td>';
1605
+            print '<td colspan="3">';
1606
+            if ($action != 'editincoterm')
1607
+            {
1608
+                print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1);
1609
+            }
1610
+            else
1611
+            {
1612
+                print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?id='.$object->id);
1613
+            }
1614
+            print '</td></tr>';
1615
+        }
1616
+
1617
+        print "</table>";
1618
+
1619
+        print '</div>';
1620
+        print '</div>';
1621
+        print '</div>';
1622
+
1623
+        print '<div class="clearboth"></div>';
1624
+
1625
+
1626
+        // Lines of products
1627
+        if ($action == 'editline')
1628
+        {
1629
+            print '<form name="updateline" id="updateline" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;lineid=' . $line_id . '" method="POST">
1630 1630
 			<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">
1631 1631
 			<input type="hidden" name="action" value="updateline">
1632 1632
 			<input type="hidden" name="mode" value="">
1633 1633
 			<input type="hidden" name="id" value="' . $object->id . '">';
1634
-		}
1635
-		print '<br>';
1636
-
1637
-		print '<div class="div-table-responsive-no-min">';
1638
-		print '<table class="noborder" width="100%">';
1639
-		print '<tr class="liste_titre">';
1640
-		// #
1641
-		if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
1642
-		{
1643
-			print '<td width="5" align="center">&nbsp;</td>';
1644
-		}
1645
-		// Product/Service
1646
-		print '<td>'.$langs->trans("Products").'</td>';
1647
-		// Comment
1648
-		print '<td>'.$langs->trans("Description").'</td>';
1649
-		// Qty
1650
-		print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
1651
-		if ($origin && $origin_id > 0)
1652
-		{
1653
-			print '<td align="center">'.$langs->trans("QtyInOtherReceptions").'</td>';
1654
-		}
1655
-		if ($action == 'editline')
1656
-		{
1657
-			$editColspan = 3;
1658
-			if (empty($conf->stock->enabled)) $editColspan--;
1659
-			if (empty($conf->productbatch->enabled)) $editColspan--;
1660
-			print '<td align="center" colspan="'. $editColspan . '">';
1661
-			if ($object->statut <= 1)
1662
-			{
1663
-				print $langs->trans("QtyToReceive").' - ';
1664
-			}
1665
-			else
1666
-			{
1667
-				print $langs->trans("QtyReceived").' - ';
1668
-			}
1669
-			if (! empty($conf->stock->enabled))
1670
-			{
1671
-				print $langs->trans("WarehouseSource").' - ';
1672
-			}
1673
-			if (! empty($conf->productbatch->enabled))
1674
-			{
1675
-				print $langs->trans("Batch");
1676
-			}
1677
-			print '</td>';
1678
-		}
1679
-		else
1680
-		{
1681
-			if ($object->statut <= 1)
1682
-			{
1683
-				print '<td align="center">'.$langs->trans("QtyToReceive").'</td>';
1684
-			}
1685
-			else
1686
-			{
1687
-				print '<td align="center">'.$langs->trans("QtyReceived").'</td>';
1688
-			}
1689
-			if (! empty($conf->stock->enabled))
1690
-			{
1691
-				print '<td align="left">'.$langs->trans("WarehouseSource").'</td>';
1692
-			}
1693
-
1694
-			if (! empty($conf->productbatch->enabled))
1695
-			{
1696
-				print '<td align="left">'.$langs->trans("Batch").'</td>';
1697
-			}
1698
-		}
1699
-		print '<td align="center">'.$langs->trans("CalculatedWeight").'</td>';
1700
-		print '<td align="center">'.$langs->trans("CalculatedVolume").'</td>';
1701
-		//print '<td align="center">'.$langs->trans("Size").'</td>';
1702
-		if ($object->statut == 0)
1703
-		{
1704
-			print '<td class="linecoledit"></td>';
1705
-			print '<td class="linecoldelete" width="10"></td>';
1706
-		}
1707
-		print "</tr>\n";
1708
-
1709
-		$var=false;
1710
-
1711
-		if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
1712
-		{
1713
-			$object->fetch_thirdparty();
1714
-			$outputlangs = $langs;
1715
-			$newlang='';
1716
-			if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
1717
-			if (empty($newlang)) $newlang=$object->thirdparty->default_lang;
1718
-			if (! empty($newlang))
1719
-			{
1720
-				$outputlangs = new Translate("",$conf);
1721
-				$outputlangs->setDefaultLang($newlang);
1722
-			}
1723
-		}
1724
-
1725
-		// Get list of products already sent for same source object into $alreadysent
1726
-		$alreadysent = array();
1727
-
1728
-		$origin = 'commande_fournisseur';
1729
-
1730
-		if ($origin && $origin_id > 0)
1731
-		{
1732
-    		$sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.date_start, obj.date_end";
1733
-    		$sql.= ", ed.rowid as receptionline_id, ed.qty, ed.fk_reception as reception_id,  ed.fk_entrepot";
1734
-    		$sql.= ", e.rowid as reception_id, e.ref as reception_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_reception";
1735
-    		//if ($conf->livraison_bon->enabled) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received";
1736
-    		$sql.= ', p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch';
1737
-    		$sql.= ', p.description as product_desc';
1738
-    		$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
1739
-    		$sql.= ", ".MAIN_DB_PREFIX."reception as e";
1740
-    		$sql.= ", ".MAIN_DB_PREFIX.$origin."det as obj";
1741
-    		//if ($conf->livraison_bon->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_reception = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."livraisondet as ld ON ld.fk_livraison = l.rowid  AND obj.rowid = ld.fk_origin_line";
1742
-    		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";
1743
-    		$sql.= " WHERE e.entity IN (".getEntity('reception').")";
1744
-    		$sql.= " AND obj.fk_commande = ".$origin_id;
1745
-    		$sql.= " AND obj.rowid = ed.fk_commandefourndet";
1746
-    		$sql.= " AND ed.fk_reception = e.rowid";
1747
-    		$sql.= " AND ed.fk_reception !=".$object->id;
1748
-    		//if ($filter) $sql.= $filter;
1749
-    		$sql.= " ORDER BY obj.fk_product";
1750
-
1751
-    		dol_syslog("get list of reception lines", LOG_DEBUG);
1752
-    		$resql = $db->query($sql);
1753
-    		if ($resql)
1754
-    		{
1755
-    		    $num = $db->num_rows($resql);
1756
-    		    $i = 0;
1757
-
1758
-    		    while($i < $num)
1759
-    		    {
1760
-        		    $obj = $db->fetch_object($resql);
1761
-        		    if ($obj)
1762
-        		    {
1763
-        		        // $obj->rowid is rowid in $origin."det" table
1764
-        		        $alreadysent[$obj->rowid][$obj->receptionline_id]=array('reception_ref'=>$obj->reception_ref, 'reception_id'=>$obj->reception_id, 'warehouse'=>$obj->fk_entrepot, 'qty'=>$obj->qty, 'date_valid'=>$obj->date_valid, 'date_delivery'=>$obj->date_delivery);
1765
-        		    }
1766
-        		    $i++;
1767
-    		    }
1768
-    		}
1769
-    		//var_dump($alreadysent);
1770
-		}
1771
-
1772
-		// Loop on each product to send/sent
1773
-		for ($i = 0 ; $i < $num_prod ; $i++)
1774
-		{
1775
-		    print '<!-- origin line id = '.$lines[$i]->origin_line_id.' -->'; // id of order line
1776
-			print '<tr class="oddeven">';
1777
-
1778
-			// #
1779
-			if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
1780
-			{
1781
-				print '<td align="center">'.($i+1).'</td>';
1782
-			}
1783
-
1784
-			// Predefined product or service
1785
-			if ($lines[$i]->fk_product > 0)
1786
-			{
1787
-				// Define output language
1788
-				if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
1789
-				{
1790
-					$prod = new Product($db);
1791
-					$prod->fetch($lines[$i]->fk_product);
1792
-					$label = ( ! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product->label;
1793
-				}
1794
-				else
1795
-					$label = (! empty($lines[$i]->product->label)?$lines[$i]->product->label:$lines[$i]->product->product_label);
1796
-
1797
-				print '<td>';
1798
-
1799
-
1800
-
1801
-				$text=$lines[$i]->product->getNomUrl(1);
1802
-				$text.= ' - '.$label;
1803
-				$description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($lines[$i]->product->description));
1804
-				print $form->textwithtooltip($text,$description,3,'','',$i);
1805
-				print_date_range($lines[$i]->date_start,$lines[$i]->date_end);
1806
-				if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
1807
-				{
1808
-					print (! empty($lines[$i]->product->description) && $lines[$i]->description!=$lines[$i]->product->description)?'<br>'.dol_htmlentitiesbr($lines[$i]->description):'';
1809
-				}
1810
-				print "</td>\n";
1811
-			}
1812
-			else
1813
-			{
1814
-				print "<td>";
1815
-				if ($lines[$i]->product_type == Product::TYPE_SERVICE) $text = img_object($langs->trans('Service'),'service');
1816
-				else $text = img_object($langs->trans('Product'),'product');
1817
-
1818
-				if (! empty($lines[$i]->label)) {
1819
-					$text.= ' <strong>'.$lines[$i]->label.'</strong>';
1820
-					print $form->textwithtooltip($text,$lines[$i]->description,3,'','',$i);
1821
-				} else {
1822
-					print $text.' '.nl2br($lines[$i]->description);
1823
-				}
1824
-
1825
-				print_date_range($lines[$i]->date_start,$lines[$i]->date_end);
1826
-				print "</td>\n";
1827
-			}
1828
-
1829
-			if ($action == 'editline' && $lines[$i]->id == $line_id)
1830
-			{
1831
-				print '<td ><textarea name="comment'.$line_id.'" id="comment'.$line_id.'" /> '.$lines[$i]->comment.'</textarea></td>';
1832
-			}
1833
-			else
1834
-			{
1835
-				print '<td style="white-space: pre-wrap;max-width: 200px;" >'.$lines[$i]->comment.'</td>';
1836
-			}
1837
-
1838
-
1839
-			// Qty ordered
1840
-			print '<td align="center">'.$lines[$i]->qty_asked.'</td>';
1841
-
1842
-			// Qty in other receptions (with reception and warehouse used)
1843
-    		if ($origin && $origin_id > 0)
1844
-    		{
1845
-    			print '<td align="center" class="nowrap">';
1846
-    			foreach ($alreadysent as $key => $val)
1847
-    			{
1848
-    			    if ($lines[$i]->fk_commandefourndet == $key)
1849
-    			    {
1850
-    			        $j = 0;
1851
-    			        foreach($val as $receptionline_id=> $receptionline_var)
1852
-    			        {
1853
-    			            if ($receptionline_var['reception_id'] == $lines[$i]->fk_reception) continue; // We want to show only "other receptions"
1854
-
1855
-    			            $j++;
1856
-    			            if ($j > 1) print '<br>';
1857
-    			            $reception_static->fetch($receptionline_var['reception_id']);
1858
-    			            print $reception_static->getNomUrl(1);
1859
-    			            print ' - '.$receptionline_var['qty'];
1860
-
1861
-    			            $htmltext=$langs->trans("DateValidation").' : '.(empty($receptionline_var['date_valid'])?$langs->trans("Draft"):dol_print_date($receptionline_var['date_valid'], 'dayhour'));
1862
-    			            if (! empty($conf->stock->enabled) && $receptionline_var['warehouse'] > 0)
1863
-    			            {
1864
-    			                $warehousestatic->fetch($receptionline_var['warehouse']);
1865
-    			                $htmltext .= '<br>'.$langs->trans("From").' : '.$warehousestatic->getNomUrl(1);
1866
-    			            }
1867
-    			            print ' '.$form->textwithpicto('', $htmltext, 1);
1868
-    			        }
1869
-    			    }
1870
-    			}
1871
-    		}
1872
-			print '</td>';
1873
-
1874
-			if ($action == 'editline' && $lines[$i]->id == $line_id)
1875
-			{
1876
-				// edit mode
1877
-				print '<td colspan="'.$editColspan.'" align="center"><table class="nobordernopadding">';
1878
-				if (! empty($conf->stock->enabled))
1879
-				{
1880
-					if ($lines[$i]->fk_product > 0)
1881
-					{
1882
-						print '<!-- case edit 1 -->';
1883
-						print '<tr>';
1884
-						// Qty to receive or received
1885
-						print '<td>' . '<input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty.'">' . '</td>';
1886
-						// Warehouse source
1887
-						print '<td>' . $formproduct->selectWarehouses($lines[$i]->fk_entrepot, 'entl'.$line_id, '', 1, 0, $lines[$i]->fk_product, '', 1). '</td>';
1888
-						// Batch number managment
1889
-						if ($conf->productbatch->enabled && !empty($lines[$i]->product->status_batch))
1890
-						{
1891
-							print '<td>  <input name="batch'.$line_id.'" id="batch'.$line_id.'" type="text" value="'.$lines[$i]->batch.'"> </br>';
1892
-							print $langs->trans('EatByDate').' : ';
1893
-							print $form->select_date($lines[$i]->eatby,'dlc' .$line_id, '', '', 1, ""). '</br>';
1894
-							print $langs->trans('SellByDate').' : ';
1895
-							print $form->select_date($lines[$i]->sellby,'dluo' .$line_id, '', '', 1, "");
1896
-							print '</td>';
1897
-						}
1898
-						print '</tr>';
1899
-					}
1900
-					else
1901
-					{
1902
-						print '<!-- case edit 2 -->';
1903
-						print '<tr>';
1904
-						// Qty to receive or received
1905
-						print '<td>' . '<input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty.'">' . '</td>';
1906
-						// Warehouse source
1907
-						print '<td>' . '</td>';
1908
-						// Batch number managment
1909
-						print '<td>' . '</td>';
1910
-						print '</tr>';
1911
-					}
1912
-				}
1913
-				print '</table></td>';
1914
-			}
1915
-			else
1916
-			{
1917
-				// Qty to receive or received
1918
-				print '<td align="center">'.$lines[$i]->qty.'</td>';
1919
-
1920
-				// Warehouse source
1921
-				if (! empty($conf->stock->enabled))
1922
-				{
1923
-					print '<td align="left">';
1924
-
1925
-					if ($lines[$i]->fk_entrepot > 0)
1926
-					{
1927
-						$entrepot = new Entrepot($db);
1928
-						$entrepot->fetch($lines[$i]->fk_entrepot);
1929
-						print $entrepot->getNomUrl(1);
1930
-					}
1931
-
1932
-					print '</td>';
1933
-				}
1934
-
1935
-				// Batch number managment
1936
-				if (! empty($conf->productbatch->enabled))
1937
-				{
1938
-					if (isset($lines[$i]->batch))
1939
-					{
1940
-						print '<!-- Detail of lot -->';
1941
-						print '<td>';
1942
-						$detail ='';
1943
-						if ($lines[$i]->product->status_batch)
1944
-						{
1945
-								$detail.= $langs->trans("Batch").': '.$lines[$i]->batch;
1946
-								$detail.= ' - '.$langs->trans("SellByDate").': '.dol_print_date($lines[$i]->sellby,"day");
1947
-								$detail.= ' - '.$langs->trans("EatByDate").': '.dol_print_date($lines[$i]->eatby,"day");
1948
-
1949
-								$detail.= '<br>';
1950
-
1951
-							print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"),$detail);
1952
-						}
1953
-						else
1954
-						{
1955
-							print $langs->trans("NA");
1956
-						}
1957
-						print '</td>';
1958
-					} else {
1959
-						print '<td></td>';
1960
-					}
1961
-				}
1962
-			}
1963
-
1964
-			// Weight
1965
-			print '<td align="center">';
1966
-			if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) print $lines[$i]->product->weight*$lines[$i]->qty.' '.measuring_units_string($lines[$i]->product->weight_units,"weight");
1967
-			else print '&nbsp;';
1968
-			print '</td>';
1969
-
1970
-			// Volume
1971
-			print '<td align="center">';
1972
-			if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) print $lines[$i]->product->volume*$lines[$i]->qty.' '.measuring_units_string($lines[$i]->product->volume_units,"volume");
1973
-			else print '&nbsp;';
1974
-			print '</td>';
1975
-
1976
-
1977
-			if ($action == 'editline' && $lines[$i]->id == $line_id)
1978
-			{
1979
-				print '<td align="center" colspan="2" valign="middle">';
1980
-				print '<input type="submit" class="button" id="savelinebutton" name="save" value="' . $langs->trans("Save") . '"><br>';
1981
-				print '<input type="submit" class="button" id="cancellinebutton" name="cancel" value="' . $langs->trans("Cancel") . '"><br>';
1982
-			}
1983
-			else if ($object->statut == 0)
1984
-			{
1985
-				// edit-delete buttons
1986
-				print '<td class="linecoledit" align="center">';
1987
-				print '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=editline&amp;lineid=' . $lines[$i]->id . '">' . img_edit() . '</a>';
1988
-				print '</td>';
1989
-				print '<td class="linecoldelete" width="10">';
1990
-				print '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=deleteline&amp;lineid=' . $lines[$i]->id . '">' . img_delete() . '</a>';
1991
-				print '</td>';
1992
-
1993
-				// Display lines extrafields
1994
-				if (! empty($rowExtrafieldsStart))
1995
-				{
1996
-					print $rowExtrafieldsStart;
1997
-					print $rowExtrafieldsView;
1998
-					print $rowEnd;
1999
-				}
2000
-			}
2001
-			print "</tr>";
2002
-
2003
-			// Display lines extrafields
2004
-			if (is_array($extralabelslines) && count($extralabelslines)>0) {
2005
-				$colspan= empty($conf->productbatch->enabled) ? 8 : 9;
2006
-				$line = new CommandeFournisseurDispatch($db);
2007
-				$line->fetch_optionals($lines[$i]->id,$extralabelslines);
2008
-				print '<tr class="oddeven">';
2009
-				if ($action == 'editline' && $lines[$i]->id == $line_id)
2010
-				{
2011
-					print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked);
2012
-				}
2013
-				else
2014
-				{
2015
-					print $line->showOptionals($extrafieldsline, 'view', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked);
2016
-				}
2017
-				print '</tr>';
2018
-			}
2019
-		}
2020
-
2021
-		// TODO Show also lines ordered but not delivered
2022
-
2023
-		print "</table>\n";
2024
-		print '</div>';
2025
-	}
2026
-
2027
-
2028
-	dol_fiche_end();
2029
-
2030
-
2031
-	$object->fetchObjectLinked($object->id,$object->element);
2032
-
2033
-
2034
-	/*
1634
+        }
1635
+        print '<br>';
1636
+
1637
+        print '<div class="div-table-responsive-no-min">';
1638
+        print '<table class="noborder" width="100%">';
1639
+        print '<tr class="liste_titre">';
1640
+        // #
1641
+        if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
1642
+        {
1643
+            print '<td width="5" align="center">&nbsp;</td>';
1644
+        }
1645
+        // Product/Service
1646
+        print '<td>'.$langs->trans("Products").'</td>';
1647
+        // Comment
1648
+        print '<td>'.$langs->trans("Description").'</td>';
1649
+        // Qty
1650
+        print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
1651
+        if ($origin && $origin_id > 0)
1652
+        {
1653
+            print '<td align="center">'.$langs->trans("QtyInOtherReceptions").'</td>';
1654
+        }
1655
+        if ($action == 'editline')
1656
+        {
1657
+            $editColspan = 3;
1658
+            if (empty($conf->stock->enabled)) $editColspan--;
1659
+            if (empty($conf->productbatch->enabled)) $editColspan--;
1660
+            print '<td align="center" colspan="'. $editColspan . '">';
1661
+            if ($object->statut <= 1)
1662
+            {
1663
+                print $langs->trans("QtyToReceive").' - ';
1664
+            }
1665
+            else
1666
+            {
1667
+                print $langs->trans("QtyReceived").' - ';
1668
+            }
1669
+            if (! empty($conf->stock->enabled))
1670
+            {
1671
+                print $langs->trans("WarehouseSource").' - ';
1672
+            }
1673
+            if (! empty($conf->productbatch->enabled))
1674
+            {
1675
+                print $langs->trans("Batch");
1676
+            }
1677
+            print '</td>';
1678
+        }
1679
+        else
1680
+        {
1681
+            if ($object->statut <= 1)
1682
+            {
1683
+                print '<td align="center">'.$langs->trans("QtyToReceive").'</td>';
1684
+            }
1685
+            else
1686
+            {
1687
+                print '<td align="center">'.$langs->trans("QtyReceived").'</td>';
1688
+            }
1689
+            if (! empty($conf->stock->enabled))
1690
+            {
1691
+                print '<td align="left">'.$langs->trans("WarehouseSource").'</td>';
1692
+            }
1693
+
1694
+            if (! empty($conf->productbatch->enabled))
1695
+            {
1696
+                print '<td align="left">'.$langs->trans("Batch").'</td>';
1697
+            }
1698
+        }
1699
+        print '<td align="center">'.$langs->trans("CalculatedWeight").'</td>';
1700
+        print '<td align="center">'.$langs->trans("CalculatedVolume").'</td>';
1701
+        //print '<td align="center">'.$langs->trans("Size").'</td>';
1702
+        if ($object->statut == 0)
1703
+        {
1704
+            print '<td class="linecoledit"></td>';
1705
+            print '<td class="linecoldelete" width="10"></td>';
1706
+        }
1707
+        print "</tr>\n";
1708
+
1709
+        $var=false;
1710
+
1711
+        if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
1712
+        {
1713
+            $object->fetch_thirdparty();
1714
+            $outputlangs = $langs;
1715
+            $newlang='';
1716
+            if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
1717
+            if (empty($newlang)) $newlang=$object->thirdparty->default_lang;
1718
+            if (! empty($newlang))
1719
+            {
1720
+                $outputlangs = new Translate("",$conf);
1721
+                $outputlangs->setDefaultLang($newlang);
1722
+            }
1723
+        }
1724
+
1725
+        // Get list of products already sent for same source object into $alreadysent
1726
+        $alreadysent = array();
1727
+
1728
+        $origin = 'commande_fournisseur';
1729
+
1730
+        if ($origin && $origin_id > 0)
1731
+        {
1732
+            $sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.date_start, obj.date_end";
1733
+            $sql.= ", ed.rowid as receptionline_id, ed.qty, ed.fk_reception as reception_id,  ed.fk_entrepot";
1734
+            $sql.= ", e.rowid as reception_id, e.ref as reception_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_reception";
1735
+            //if ($conf->livraison_bon->enabled) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received";
1736
+            $sql.= ', p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch';
1737
+            $sql.= ', p.description as product_desc';
1738
+            $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
1739
+            $sql.= ", ".MAIN_DB_PREFIX."reception as e";
1740
+            $sql.= ", ".MAIN_DB_PREFIX.$origin."det as obj";
1741
+            //if ($conf->livraison_bon->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_reception = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."livraisondet as ld ON ld.fk_livraison = l.rowid  AND obj.rowid = ld.fk_origin_line";
1742
+            $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";
1743
+            $sql.= " WHERE e.entity IN (".getEntity('reception').")";
1744
+            $sql.= " AND obj.fk_commande = ".$origin_id;
1745
+            $sql.= " AND obj.rowid = ed.fk_commandefourndet";
1746
+            $sql.= " AND ed.fk_reception = e.rowid";
1747
+            $sql.= " AND ed.fk_reception !=".$object->id;
1748
+            //if ($filter) $sql.= $filter;
1749
+            $sql.= " ORDER BY obj.fk_product";
1750
+
1751
+            dol_syslog("get list of reception lines", LOG_DEBUG);
1752
+            $resql = $db->query($sql);
1753
+            if ($resql)
1754
+            {
1755
+                $num = $db->num_rows($resql);
1756
+                $i = 0;
1757
+
1758
+                while($i < $num)
1759
+                {
1760
+                    $obj = $db->fetch_object($resql);
1761
+                    if ($obj)
1762
+                    {
1763
+                        // $obj->rowid is rowid in $origin."det" table
1764
+                        $alreadysent[$obj->rowid][$obj->receptionline_id]=array('reception_ref'=>$obj->reception_ref, 'reception_id'=>$obj->reception_id, 'warehouse'=>$obj->fk_entrepot, 'qty'=>$obj->qty, 'date_valid'=>$obj->date_valid, 'date_delivery'=>$obj->date_delivery);
1765
+                    }
1766
+                    $i++;
1767
+                }
1768
+            }
1769
+            //var_dump($alreadysent);
1770
+        }
1771
+
1772
+        // Loop on each product to send/sent
1773
+        for ($i = 0 ; $i < $num_prod ; $i++)
1774
+        {
1775
+            print '<!-- origin line id = '.$lines[$i]->origin_line_id.' -->'; // id of order line
1776
+            print '<tr class="oddeven">';
1777
+
1778
+            // #
1779
+            if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
1780
+            {
1781
+                print '<td align="center">'.($i+1).'</td>';
1782
+            }
1783
+
1784
+            // Predefined product or service
1785
+            if ($lines[$i]->fk_product > 0)
1786
+            {
1787
+                // Define output language
1788
+                if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
1789
+                {
1790
+                    $prod = new Product($db);
1791
+                    $prod->fetch($lines[$i]->fk_product);
1792
+                    $label = ( ! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product->label;
1793
+                }
1794
+                else
1795
+                    $label = (! empty($lines[$i]->product->label)?$lines[$i]->product->label:$lines[$i]->product->product_label);
1796
+
1797
+                print '<td>';
1798
+
1799
+
1800
+
1801
+                $text=$lines[$i]->product->getNomUrl(1);
1802
+                $text.= ' - '.$label;
1803
+                $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($lines[$i]->product->description));
1804
+                print $form->textwithtooltip($text,$description,3,'','',$i);
1805
+                print_date_range($lines[$i]->date_start,$lines[$i]->date_end);
1806
+                if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
1807
+                {
1808
+                    print (! empty($lines[$i]->product->description) && $lines[$i]->description!=$lines[$i]->product->description)?'<br>'.dol_htmlentitiesbr($lines[$i]->description):'';
1809
+                }
1810
+                print "</td>\n";
1811
+            }
1812
+            else
1813
+            {
1814
+                print "<td>";
1815
+                if ($lines[$i]->product_type == Product::TYPE_SERVICE) $text = img_object($langs->trans('Service'),'service');
1816
+                else $text = img_object($langs->trans('Product'),'product');
1817
+
1818
+                if (! empty($lines[$i]->label)) {
1819
+                    $text.= ' <strong>'.$lines[$i]->label.'</strong>';
1820
+                    print $form->textwithtooltip($text,$lines[$i]->description,3,'','',$i);
1821
+                } else {
1822
+                    print $text.' '.nl2br($lines[$i]->description);
1823
+                }
1824
+
1825
+                print_date_range($lines[$i]->date_start,$lines[$i]->date_end);
1826
+                print "</td>\n";
1827
+            }
1828
+
1829
+            if ($action == 'editline' && $lines[$i]->id == $line_id)
1830
+            {
1831
+                print '<td ><textarea name="comment'.$line_id.'" id="comment'.$line_id.'" /> '.$lines[$i]->comment.'</textarea></td>';
1832
+            }
1833
+            else
1834
+            {
1835
+                print '<td style="white-space: pre-wrap;max-width: 200px;" >'.$lines[$i]->comment.'</td>';
1836
+            }
1837
+
1838
+
1839
+            // Qty ordered
1840
+            print '<td align="center">'.$lines[$i]->qty_asked.'</td>';
1841
+
1842
+            // Qty in other receptions (with reception and warehouse used)
1843
+            if ($origin && $origin_id > 0)
1844
+            {
1845
+                print '<td align="center" class="nowrap">';
1846
+                foreach ($alreadysent as $key => $val)
1847
+                {
1848
+                    if ($lines[$i]->fk_commandefourndet == $key)
1849
+                    {
1850
+                        $j = 0;
1851
+                        foreach($val as $receptionline_id=> $receptionline_var)
1852
+                        {
1853
+                            if ($receptionline_var['reception_id'] == $lines[$i]->fk_reception) continue; // We want to show only "other receptions"
1854
+
1855
+                            $j++;
1856
+                            if ($j > 1) print '<br>';
1857
+                            $reception_static->fetch($receptionline_var['reception_id']);
1858
+                            print $reception_static->getNomUrl(1);
1859
+                            print ' - '.$receptionline_var['qty'];
1860
+
1861
+                            $htmltext=$langs->trans("DateValidation").' : '.(empty($receptionline_var['date_valid'])?$langs->trans("Draft"):dol_print_date($receptionline_var['date_valid'], 'dayhour'));
1862
+                            if (! empty($conf->stock->enabled) && $receptionline_var['warehouse'] > 0)
1863
+                            {
1864
+                                $warehousestatic->fetch($receptionline_var['warehouse']);
1865
+                                $htmltext .= '<br>'.$langs->trans("From").' : '.$warehousestatic->getNomUrl(1);
1866
+                            }
1867
+                            print ' '.$form->textwithpicto('', $htmltext, 1);
1868
+                        }
1869
+                    }
1870
+                }
1871
+            }
1872
+            print '</td>';
1873
+
1874
+            if ($action == 'editline' && $lines[$i]->id == $line_id)
1875
+            {
1876
+                // edit mode
1877
+                print '<td colspan="'.$editColspan.'" align="center"><table class="nobordernopadding">';
1878
+                if (! empty($conf->stock->enabled))
1879
+                {
1880
+                    if ($lines[$i]->fk_product > 0)
1881
+                    {
1882
+                        print '<!-- case edit 1 -->';
1883
+                        print '<tr>';
1884
+                        // Qty to receive or received
1885
+                        print '<td>' . '<input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty.'">' . '</td>';
1886
+                        // Warehouse source
1887
+                        print '<td>' . $formproduct->selectWarehouses($lines[$i]->fk_entrepot, 'entl'.$line_id, '', 1, 0, $lines[$i]->fk_product, '', 1). '</td>';
1888
+                        // Batch number managment
1889
+                        if ($conf->productbatch->enabled && !empty($lines[$i]->product->status_batch))
1890
+                        {
1891
+                            print '<td>  <input name="batch'.$line_id.'" id="batch'.$line_id.'" type="text" value="'.$lines[$i]->batch.'"> </br>';
1892
+                            print $langs->trans('EatByDate').' : ';
1893
+                            print $form->select_date($lines[$i]->eatby,'dlc' .$line_id, '', '', 1, ""). '</br>';
1894
+                            print $langs->trans('SellByDate').' : ';
1895
+                            print $form->select_date($lines[$i]->sellby,'dluo' .$line_id, '', '', 1, "");
1896
+                            print '</td>';
1897
+                        }
1898
+                        print '</tr>';
1899
+                    }
1900
+                    else
1901
+                    {
1902
+                        print '<!-- case edit 2 -->';
1903
+                        print '<tr>';
1904
+                        // Qty to receive or received
1905
+                        print '<td>' . '<input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty.'">' . '</td>';
1906
+                        // Warehouse source
1907
+                        print '<td>' . '</td>';
1908
+                        // Batch number managment
1909
+                        print '<td>' . '</td>';
1910
+                        print '</tr>';
1911
+                    }
1912
+                }
1913
+                print '</table></td>';
1914
+            }
1915
+            else
1916
+            {
1917
+                // Qty to receive or received
1918
+                print '<td align="center">'.$lines[$i]->qty.'</td>';
1919
+
1920
+                // Warehouse source
1921
+                if (! empty($conf->stock->enabled))
1922
+                {
1923
+                    print '<td align="left">';
1924
+
1925
+                    if ($lines[$i]->fk_entrepot > 0)
1926
+                    {
1927
+                        $entrepot = new Entrepot($db);
1928
+                        $entrepot->fetch($lines[$i]->fk_entrepot);
1929
+                        print $entrepot->getNomUrl(1);
1930
+                    }
1931
+
1932
+                    print '</td>';
1933
+                }
1934
+
1935
+                // Batch number managment
1936
+                if (! empty($conf->productbatch->enabled))
1937
+                {
1938
+                    if (isset($lines[$i]->batch))
1939
+                    {
1940
+                        print '<!-- Detail of lot -->';
1941
+                        print '<td>';
1942
+                        $detail ='';
1943
+                        if ($lines[$i]->product->status_batch)
1944
+                        {
1945
+                                $detail.= $langs->trans("Batch").': '.$lines[$i]->batch;
1946
+                                $detail.= ' - '.$langs->trans("SellByDate").': '.dol_print_date($lines[$i]->sellby,"day");
1947
+                                $detail.= ' - '.$langs->trans("EatByDate").': '.dol_print_date($lines[$i]->eatby,"day");
1948
+
1949
+                                $detail.= '<br>';
1950
+
1951
+                            print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"),$detail);
1952
+                        }
1953
+                        else
1954
+                        {
1955
+                            print $langs->trans("NA");
1956
+                        }
1957
+                        print '</td>';
1958
+                    } else {
1959
+                        print '<td></td>';
1960
+                    }
1961
+                }
1962
+            }
1963
+
1964
+            // Weight
1965
+            print '<td align="center">';
1966
+            if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) print $lines[$i]->product->weight*$lines[$i]->qty.' '.measuring_units_string($lines[$i]->product->weight_units,"weight");
1967
+            else print '&nbsp;';
1968
+            print '</td>';
1969
+
1970
+            // Volume
1971
+            print '<td align="center">';
1972
+            if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) print $lines[$i]->product->volume*$lines[$i]->qty.' '.measuring_units_string($lines[$i]->product->volume_units,"volume");
1973
+            else print '&nbsp;';
1974
+            print '</td>';
1975
+
1976
+
1977
+            if ($action == 'editline' && $lines[$i]->id == $line_id)
1978
+            {
1979
+                print '<td align="center" colspan="2" valign="middle">';
1980
+                print '<input type="submit" class="button" id="savelinebutton" name="save" value="' . $langs->trans("Save") . '"><br>';
1981
+                print '<input type="submit" class="button" id="cancellinebutton" name="cancel" value="' . $langs->trans("Cancel") . '"><br>';
1982
+            }
1983
+            else if ($object->statut == 0)
1984
+            {
1985
+                // edit-delete buttons
1986
+                print '<td class="linecoledit" align="center">';
1987
+                print '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=editline&amp;lineid=' . $lines[$i]->id . '">' . img_edit() . '</a>';
1988
+                print '</td>';
1989
+                print '<td class="linecoldelete" width="10">';
1990
+                print '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=deleteline&amp;lineid=' . $lines[$i]->id . '">' . img_delete() . '</a>';
1991
+                print '</td>';
1992
+
1993
+                // Display lines extrafields
1994
+                if (! empty($rowExtrafieldsStart))
1995
+                {
1996
+                    print $rowExtrafieldsStart;
1997
+                    print $rowExtrafieldsView;
1998
+                    print $rowEnd;
1999
+                }
2000
+            }
2001
+            print "</tr>";
2002
+
2003
+            // Display lines extrafields
2004
+            if (is_array($extralabelslines) && count($extralabelslines)>0) {
2005
+                $colspan= empty($conf->productbatch->enabled) ? 8 : 9;
2006
+                $line = new CommandeFournisseurDispatch($db);
2007
+                $line->fetch_optionals($lines[$i]->id,$extralabelslines);
2008
+                print '<tr class="oddeven">';
2009
+                if ($action == 'editline' && $lines[$i]->id == $line_id)
2010
+                {
2011
+                    print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked);
2012
+                }
2013
+                else
2014
+                {
2015
+                    print $line->showOptionals($extrafieldsline, 'view', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked);
2016
+                }
2017
+                print '</tr>';
2018
+            }
2019
+        }
2020
+
2021
+        // TODO Show also lines ordered but not delivered
2022
+
2023
+        print "</table>\n";
2024
+        print '</div>';
2025
+    }
2026
+
2027
+
2028
+    dol_fiche_end();
2029
+
2030
+
2031
+    $object->fetchObjectLinked($object->id,$object->element);
2032
+
2033
+
2034
+    /*
2035 2035
 	 *    Boutons actions
2036 2036
 	 */
2037 2037
 
2038
-	if (($user->societe_id == 0) && ($action!='presend'))
2039
-	{
2040
-		print '<div class="tabsAction">';
2041
-
2042
-		$parameters = array();
2043
-		$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2044
-		if (empty($reshook))
2045
-		{
2046
-
2047
-			if ($object->statut == Reception::STATUS_DRAFT && $num_prod > 0)
2048
-			{
2049
-				if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->creer))
2050
-	  		     || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->reception_advance->validate)))
2051
-				{
2052
-					print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valid">'.$langs->trans("Validate").'</a>';
2053
-				}
2054
-				else
2055
-				{
2056
-					print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Validate").'</a>';
2057
-				}
2058
-			}
2059
-			// Edit
2060
-			if ($object->statut == Reception::STATUS_VALIDATED && $user->rights->reception->creer) {
2061
-				print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id=' . $object->id . '&amp;action=modif">' . $langs->trans('Modify') . '</a></div>';
2062
-			}
2063
-
2064
-			// TODO add alternative status
2065
-			// 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order)
2066
-			if ($object->statut == Reception::STATUS_CLOSED && $user->rights->reception->creer)
2067
-			{
2068
-				if (! empty($conf->facture->enabled) && ! empty($conf->global->WORKFLOW_BILL_ON_RECEPTION))  // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
2069
-				{
2070
-					print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ClassifyUnbilled").'</a>';
2071
-				}
2072
-				else
2073
-				{
2074
-			    	print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ReOpen").'</a>';
2075
-				}
2076
-			}
2077
-
2078
-			// Send
2079
-			if ($object->statut > 0)
2080
-			{
2081
-				if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->reception->reception_advance->send)
2082
-				{
2083
-					print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendByMail').'</a>';
2084
-				}
2085
-				else print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
2086
-			}
2087
-
2088
-			// Create bill
2089
-			if (! empty($conf->fournisseur->enabled) && ($object->statut == Reception::STATUS_VALIDATED || $object->statut == Reception::STATUS_CLOSED))
2090
-			{
2091
-				if ($user->rights->fournisseur->facture->creer)
2092
-				{
2093
-					// TODO show button only   if (! empty($conf->global->WORKFLOW_BILL_ON_RECEPTION))
2094
-					// If we do that, we must also make this option official.
2095
-					print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("CreateBill").'</a>';
2096
-				}
2097
-			}
2098
-
2099
-
2100
-			// Close
2101
-			if ($object->statut == Reception::STATUS_VALIDATED)
2102
-			{
2103
-				if ($user->rights->reception->creer && $object->statut > 0 && ! $object->billed)
2104
-				{
2105
-					$label="Close"; $paramaction='classifyclosed';       // = Transferred/Received
2106
-					// Label here should be "Close" or "ClassifyBilled" if we decided to make bill on receptions instead of orders
2107
-					if (! empty($conf->fournisseur->enabled) && ! empty($conf->global->WORKFLOW_BILL_ON_RECEPTION))  // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
2108
-					{
2109
-					    $label="ClassifyBilled";
2110
-					    $paramaction='classifybilled';
2111
-					}
2112
-					print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action='.$paramaction.'">'.$langs->trans($label).'</a>';
2113
-				}
2114
-			}
2115
-
2116
-			if ($user->rights->reception->supprimer)
2117
-			{
2118
-				print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
2119
-			}
2120
-		}
2121
-
2122
-		print '</div>';
2123
-	}
2124
-
2125
-
2126
-	/*
2038
+    if (($user->societe_id == 0) && ($action!='presend'))
2039
+    {
2040
+        print '<div class="tabsAction">';
2041
+
2042
+        $parameters = array();
2043
+        $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2044
+        if (empty($reshook))
2045
+        {
2046
+
2047
+            if ($object->statut == Reception::STATUS_DRAFT && $num_prod > 0)
2048
+            {
2049
+                if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->creer))
2050
+                   || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->reception_advance->validate)))
2051
+                {
2052
+                    print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valid">'.$langs->trans("Validate").'</a>';
2053
+                }
2054
+                else
2055
+                {
2056
+                    print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Validate").'</a>';
2057
+                }
2058
+            }
2059
+            // Edit
2060
+            if ($object->statut == Reception::STATUS_VALIDATED && $user->rights->reception->creer) {
2061
+                print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id=' . $object->id . '&amp;action=modif">' . $langs->trans('Modify') . '</a></div>';
2062
+            }
2063
+
2064
+            // TODO add alternative status
2065
+            // 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order)
2066
+            if ($object->statut == Reception::STATUS_CLOSED && $user->rights->reception->creer)
2067
+            {
2068
+                if (! empty($conf->facture->enabled) && ! empty($conf->global->WORKFLOW_BILL_ON_RECEPTION))  // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
2069
+                {
2070
+                    print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ClassifyUnbilled").'</a>';
2071
+                }
2072
+                else
2073
+                {
2074
+                    print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ReOpen").'</a>';
2075
+                }
2076
+            }
2077
+
2078
+            // Send
2079
+            if ($object->statut > 0)
2080
+            {
2081
+                if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->reception->reception_advance->send)
2082
+                {
2083
+                    print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendByMail').'</a>';
2084
+                }
2085
+                else print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
2086
+            }
2087
+
2088
+            // Create bill
2089
+            if (! empty($conf->fournisseur->enabled) && ($object->statut == Reception::STATUS_VALIDATED || $object->statut == Reception::STATUS_CLOSED))
2090
+            {
2091
+                if ($user->rights->fournisseur->facture->creer)
2092
+                {
2093
+                    // TODO show button only   if (! empty($conf->global->WORKFLOW_BILL_ON_RECEPTION))
2094
+                    // If we do that, we must also make this option official.
2095
+                    print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("CreateBill").'</a>';
2096
+                }
2097
+            }
2098
+
2099
+
2100
+            // Close
2101
+            if ($object->statut == Reception::STATUS_VALIDATED)
2102
+            {
2103
+                if ($user->rights->reception->creer && $object->statut > 0 && ! $object->billed)
2104
+                {
2105
+                    $label="Close"; $paramaction='classifyclosed';       // = Transferred/Received
2106
+                    // Label here should be "Close" or "ClassifyBilled" if we decided to make bill on receptions instead of orders
2107
+                    if (! empty($conf->fournisseur->enabled) && ! empty($conf->global->WORKFLOW_BILL_ON_RECEPTION))  // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
2108
+                    {
2109
+                        $label="ClassifyBilled";
2110
+                        $paramaction='classifybilled';
2111
+                    }
2112
+                    print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action='.$paramaction.'">'.$langs->trans($label).'</a>';
2113
+                }
2114
+            }
2115
+
2116
+            if ($user->rights->reception->supprimer)
2117
+            {
2118
+                print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
2119
+            }
2120
+        }
2121
+
2122
+        print '</div>';
2123
+    }
2124
+
2125
+
2126
+    /*
2127 2127
 	 * Documents generated
2128 2128
 	 */
2129 2129
 
2130
-	if ($action != 'presend' && $action != 'editline')
2131
-	{
2130
+    if ($action != 'presend' && $action != 'editline')
2131
+    {
2132 2132
         print '<div class="fichecenter"><div class="fichehalfleft">';
2133 2133
 
2134 2134
         $objectref = dol_sanitizeFileName($object->ref);
2135
-		$filedir = $conf->reception->dir_output . "/" .$objectref;
2135
+        $filedir = $conf->reception->dir_output . "/" .$objectref;
2136 2136
 
2137
-		$urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
2137
+        $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
2138 2138
 
2139
-		$genallowed=$user->rights->reception->lire;
2140
-		$delallowed=$user->rights->reception->creer;
2139
+        $genallowed=$user->rights->reception->lire;
2140
+        $delallowed=$user->rights->reception->creer;
2141 2141
 
2142
-		print $formfile->showdocuments('reception',$objectref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang);
2142
+        print $formfile->showdocuments('reception',$objectref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang);
2143 2143
 
2144
-		// Show links to link elements
2145
-		//$linktoelem = $form->showLinkToObjectBlock($object, null, array('order'));
2146
-		$somethingshown = $form->showLinkedObjectBlock($object, '');
2144
+        // Show links to link elements
2145
+        //$linktoelem = $form->showLinkToObjectBlock($object, null, array('order'));
2146
+        $somethingshown = $form->showLinkedObjectBlock($object, '');
2147 2147
 
2148
-		print '</div><div class="fichehalfright"><div class="ficheaddleft">';
2149
-	}
2148
+        print '</div><div class="fichehalfright"><div class="ficheaddleft">';
2149
+    }
2150 2150
 
2151
-	if ($action == 'presend')
2152
-	{
2153
-		$ref = dol_sanitizeFileName($object->ref);
2154
-		include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
2155
-		$fileparams = dol_most_recent_file($conf->reception->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
2156
-		$file=$fileparams['fullname'];
2157
-		// Define output language
2158
-		$outputlangs = $langs;
2159
-		$newlang = '';
2160
-		if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
2161
-			$newlang = $_REQUEST['lang_id'];
2162
-		if ($conf->global->MAIN_MULTILANGS && empty($newlang))
2163
-			$newlang = $object->thirdparty->default_lang;
2164
-		if (!empty($newlang))
2165
-		{
2166
-			$outputlangs = new Translate('', $conf);
2167
-			$outputlangs->setDefaultLang($newlang);
2168
-			$outputlangs->load('receptions');
2169
-		}
2170
-		// Build document if it not exists
2171
-		if (! $file || ! is_readable($file))
2172
-		{
2173
-			$result = $object->generateDocument(GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2174
-			if ($result <= 0)
2175
-			{
2176
-				dol_print_error($db,$object->error,$object->errors);
2177
-				exit;
2178
-			}
2179
-			$fileparams = dol_most_recent_file($conf->reception->dir_output . '/reception/' . $ref, preg_quote($ref, '/').'[^\-]+');
2180
-			$file=$fileparams['fullname'];
2181
-		}
2182
-		print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
2183
-		print '<div class="clearboth"></div>';
2184
-		print '<br>';
2185
-		print load_fiche_titre($langs->trans('SendReceptionByEMail'));
2186
-		dol_fiche_head('');
2187
-		// Cree l'objet formulaire mail
2188
-		include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
2189
-		$formmail = new FormMail($db);
2190
-		$formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
2151
+    if ($action == 'presend')
2152
+    {
2153
+        $ref = dol_sanitizeFileName($object->ref);
2154
+        include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
2155
+        $fileparams = dol_most_recent_file($conf->reception->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
2156
+        $file=$fileparams['fullname'];
2157
+        // Define output language
2158
+        $outputlangs = $langs;
2159
+        $newlang = '';
2160
+        if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
2161
+            $newlang = $_REQUEST['lang_id'];
2162
+        if ($conf->global->MAIN_MULTILANGS && empty($newlang))
2163
+            $newlang = $object->thirdparty->default_lang;
2164
+        if (!empty($newlang))
2165
+        {
2166
+            $outputlangs = new Translate('', $conf);
2167
+            $outputlangs->setDefaultLang($newlang);
2168
+            $outputlangs->load('receptions');
2169
+        }
2170
+        // Build document if it not exists
2171
+        if (! $file || ! is_readable($file))
2172
+        {
2173
+            $result = $object->generateDocument(GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2174
+            if ($result <= 0)
2175
+            {
2176
+                dol_print_error($db,$object->error,$object->errors);
2177
+                exit;
2178
+            }
2179
+            $fileparams = dol_most_recent_file($conf->reception->dir_output . '/reception/' . $ref, preg_quote($ref, '/').'[^\-]+');
2180
+            $file=$fileparams['fullname'];
2181
+        }
2182
+        print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
2183
+        print '<div class="clearboth"></div>';
2184
+        print '<br>';
2185
+        print load_fiche_titre($langs->trans('SendReceptionByEMail'));
2186
+        dol_fiche_head('');
2187
+        // Cree l'objet formulaire mail
2188
+        include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
2189
+        $formmail = new FormMail($db);
2190
+        $formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
2191 2191
         $formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
2192 2192
         if($formmail->fromtype === 'user'){
2193 2193
             $formmail->fromid = $user->id;
2194 2194
         }
2195
-		$formmail->trackid='shi'.$object->id;
2196
-		if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2))	// If bit 2 is set
2197
-		{
2198
-			include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2199
-			$formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'shi'.$object->id);
2200
-		}
2201
-		$formmail->withfrom=1;
2202
-		$liste=array();
2203
-		foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value)	$liste[$key]=$value;
2204
-		$formmail->withto=GETPOST("sendto")?GETPOST("sendto"):$liste;
2205
-		$formmail->withtocc=$liste;
2206
-		$formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
2207
-		$formmail->withtopic=$outputlangs->trans('SendReceptionRef','__RECEPTIONREF__');
2208
-		$formmail->withfile=2;
2209
-		$formmail->withbody=1;
2210
-		$formmail->withdeliveryreceipt=1;
2211
-		$formmail->withcancel=1;
2212
-		// Tableau des substitutions
2213
-		$formmail->setSubstitFromObject($object,$langs);
2214
-		$formmail->substit['__RECEPTIONREF__']=$object->ref;
2215
-		$formmail->substit['__RECEPTIONTRACKNUM__']=$object->tracking_number;
2216
-		$formmail->substit['__RECEPTIONTRACKNUMURL__']=$object->tracking_url;
2217
-		//Find the good contact adress
2218
-		if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))	{
2219
-			$objectsrc=new Commande($db);
2220
-			$objectsrc->fetch($object->$typeobject->id);
2221
-		}
2222
-		if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))	{
2223
-			$objectsrc=new Propal($db);
2224
-			$objectsrc->fetch($object->$typeobject->id);
2225
-		}
2226
-		$custcontact='';
2227
-		$contactarr=array();
2228
-		if (is_object($objectsrc))    // For the case the reception was created without orders
2229
-		{
2230
-    		$contactarr=$objectsrc->liste_contact(-1,'external');
2231
-		}
2232
-		if (is_array($contactarr) && count($contactarr)>0) {
2233
-			foreach($contactarr as $contact) {
2234
-				if ($contact['libelle']==$langs->trans('TypeContact_commande_external_CUSTOMER')) {
2235
-					require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
2236
-					$contactstatic=new Contact($db);
2237
-					$contactstatic->fetch($contact['id']);
2238
-					$custcontact=$contactstatic->getFullName($langs,1);
2239
-				}
2240
-			}
2241
-			if (!empty($custcontact)) {
2242
-				$formmail->substit['__CONTACTCIVNAME__']=$custcontact;
2243
-			}
2244
-		}
2245
-		// Tableau des parametres complementaires
2246
-		$formmail->param['action']='send';
2247
-		$formmail->param['models']='reception_send';
2248
-		$formmail->param['models_id']=GETPOST('modelmailselected','int');
2249
-		$formmail->param['receptionid']=$object->id;
2250
-		$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
2251
-		// Init list of files
2252
-		if (GETPOST("mode")=='init')
2253
-		{
2254
-			$formmail->clear_attached_files();
2255
-			$formmail->add_attached_files($file,basename($file),dol_mimetype($file));
2256
-		}
2257
-		// Show form
2258
-		print $formmail->get_form();
2259
-		dol_fiche_end();
2260
-	}
2195
+        $formmail->trackid='shi'.$object->id;
2196
+        if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2))	// If bit 2 is set
2197
+        {
2198
+            include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2199
+            $formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'shi'.$object->id);
2200
+        }
2201
+        $formmail->withfrom=1;
2202
+        $liste=array();
2203
+        foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value)	$liste[$key]=$value;
2204
+        $formmail->withto=GETPOST("sendto")?GETPOST("sendto"):$liste;
2205
+        $formmail->withtocc=$liste;
2206
+        $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
2207
+        $formmail->withtopic=$outputlangs->trans('SendReceptionRef','__RECEPTIONREF__');
2208
+        $formmail->withfile=2;
2209
+        $formmail->withbody=1;
2210
+        $formmail->withdeliveryreceipt=1;
2211
+        $formmail->withcancel=1;
2212
+        // Tableau des substitutions
2213
+        $formmail->setSubstitFromObject($object,$langs);
2214
+        $formmail->substit['__RECEPTIONREF__']=$object->ref;
2215
+        $formmail->substit['__RECEPTIONTRACKNUM__']=$object->tracking_number;
2216
+        $formmail->substit['__RECEPTIONTRACKNUMURL__']=$object->tracking_url;
2217
+        //Find the good contact adress
2218
+        if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))	{
2219
+            $objectsrc=new Commande($db);
2220
+            $objectsrc->fetch($object->$typeobject->id);
2221
+        }
2222
+        if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))	{
2223
+            $objectsrc=new Propal($db);
2224
+            $objectsrc->fetch($object->$typeobject->id);
2225
+        }
2226
+        $custcontact='';
2227
+        $contactarr=array();
2228
+        if (is_object($objectsrc))    // For the case the reception was created without orders
2229
+        {
2230
+            $contactarr=$objectsrc->liste_contact(-1,'external');
2231
+        }
2232
+        if (is_array($contactarr) && count($contactarr)>0) {
2233
+            foreach($contactarr as $contact) {
2234
+                if ($contact['libelle']==$langs->trans('TypeContact_commande_external_CUSTOMER')) {
2235
+                    require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
2236
+                    $contactstatic=new Contact($db);
2237
+                    $contactstatic->fetch($contact['id']);
2238
+                    $custcontact=$contactstatic->getFullName($langs,1);
2239
+                }
2240
+            }
2241
+            if (!empty($custcontact)) {
2242
+                $formmail->substit['__CONTACTCIVNAME__']=$custcontact;
2243
+            }
2244
+        }
2245
+        // Tableau des parametres complementaires
2246
+        $formmail->param['action']='send';
2247
+        $formmail->param['models']='reception_send';
2248
+        $formmail->param['models_id']=GETPOST('modelmailselected','int');
2249
+        $formmail->param['receptionid']=$object->id;
2250
+        $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
2251
+        // Init list of files
2252
+        if (GETPOST("mode")=='init')
2253
+        {
2254
+            $formmail->clear_attached_files();
2255
+            $formmail->add_attached_files($file,basename($file),dol_mimetype($file));
2256
+        }
2257
+        // Show form
2258
+        print $formmail->get_form();
2259
+        dol_fiche_end();
2260
+    }
2261 2261
 }
2262 2262
 
2263 2263
 
Please login to merge, or discard this patch.
Braces   +315 added lines, -187 removed lines patch added patch discarded remove patch
@@ -44,13 +44,19 @@  discard block
 block discarded – undo
44 44
 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
45 45
 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
46 46
 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
47
-if (! empty($conf->product->enabled) || ! empty($conf->service->enabled))  require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
48
-if (! empty($conf->propal->enabled))   require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
47
+if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) {
48
+    require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
49
+}
50
+if (! empty($conf->propal->enabled)) {
51
+    require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
52
+}
49 53
 if (! empty($conf->fournisseur->enabled)){
50 54
 	require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
51 55
 	require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
52 56
 }
53
-if (! empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
57
+if (! empty($conf->productbatch->enabled)) {
58
+    require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
59
+}
54 60
 if (! empty($conf->projet->enabled)) {
55 61
     require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
56 62
     require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
@@ -58,29 +64,49 @@  discard block
 block discarded – undo
58 64
 
59 65
 $langs->loadLangs(array("receptions","companies","bills",'deliveries','orders','stocks','other','propal'));
60 66
 
61
-if (!empty($conf->incoterm->enabled)) $langs->load('incoterm');
62
-if (! empty($conf->productbatch->enabled)) $langs->load('productbatch');
67
+if (!empty($conf->incoterm->enabled)) {
68
+    $langs->load('incoterm');
69
+}
70
+if (! empty($conf->productbatch->enabled)) {
71
+    $langs->load('productbatch');
72
+}
63 73
 
64 74
 $origin		= GETPOST('origin','alpha')?GETPOST('origin','alpha'):'reception';   // Example: commande, propal
65 75
 $origin_id 	= GETPOST('id','int')?GETPOST('id','int'):'';
66 76
 $id = $origin_id;
67
-if (empty($origin_id)) $origin_id  = GETPOST('origin_id','int');    // Id of order or propal
68
-if (empty($origin_id)) $origin_id  = GETPOST('object_id','int');    // Id of order or propal
69
-if (empty($origin_id)) $origin_id  = GETPOST('originid','int');    // Id of order or propal
77
+if (empty($origin_id)) {
78
+    $origin_id  = GETPOST('origin_id','int');
79
+}
80
+// Id of order or propal
81
+if (empty($origin_id)) {
82
+    $origin_id  = GETPOST('object_id','int');
83
+}
84
+// Id of order or propal
85
+if (empty($origin_id)) {
86
+    $origin_id  = GETPOST('originid','int');
87
+}
88
+// Id of order or propal
70 89
 $ref=GETPOST('ref','alpha');
71 90
 $line_id = GETPOST('lineid','int')?GETPOST('lineid','int'):'';
72 91
 
73 92
 // Security check
74 93
 $socid='';
75
-if ($user->societe_id) $socid=$user->societe_id;
94
+if ($user->societe_id) {
95
+    $socid=$user->societe_id;
96
+}
76 97
 
77
-if ($origin == 'reception') $result=restrictedArea($user, $origin, $id);
78
-else {
98
+if ($origin == 'reception') {
99
+    $result=restrictedArea($user, $origin, $id);
100
+} else {
79 101
 	$result=restrictedArea($user, 'reception');
80 102
 	if($origin == 'supplierorder'){
81
-		if (empty($user->rights->fournisseur->commande->lire) && empty($user->rights->fournisseur->commande->read)) accessforbidden();
82
-	}else if (empty($user->rights->{$origin}->lire) && empty($user->rights->{$origin}->read)) accessforbidden();
83
-}
103
+		if (empty($user->rights->fournisseur->commande->lire) && empty($user->rights->fournisseur->commande->read)) {
104
+		    accessforbidden();
105
+		}
106
+	} else if (empty($user->rights->{$origin}->lire) && empty($user->rights->{$origin}->read)) {
107
+	    accessforbidden();
108
+	}
109
+	}
84 110
 
85 111
 $action		= GETPOST('action','alpha');
86 112
 //Select mail models is same action as presend
@@ -122,7 +148,9 @@  discard block
 block discarded – undo
122 148
 
123 149
 $parameters=array();
124 150
 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
125
-if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
151
+if ($reshook < 0) {
152
+    setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
153
+}
126 154
 
127 155
 if (empty($reshook))
128 156
 {
@@ -152,8 +180,12 @@  discard block
 block discarded – undo
152 180
 			{
153 181
 				$outputlangs = $langs;
154 182
 				$newlang = '';
155
-				if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
156
-				if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $object->thirdparty->default_lang;
183
+				if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) {
184
+				    $newlang = GETPOST('lang_id','aZ09');
185
+				}
186
+				if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
187
+				    $newlang = $object->thirdparty->default_lang;
188
+				}
157 189
 				if (! empty($newlang)) {
158 190
 					$outputlangs = new Translate("", $conf);
159 191
 					$outputlangs->setDefaultLang($newlang);
@@ -193,7 +225,9 @@  discard block
 block discarded – undo
193 225
 	    // Fill array 'array_options' with data from update form
194 226
 	    $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
195 227
 	    $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
196
-	    if ($ret < 0) $error++;
228
+	    if ($ret < 0) {
229
+	        $error++;
230
+	    }
197 231
 
198 232
 	    if (! $error)
199 233
 	    {
@@ -209,12 +243,14 @@  discard block
 block discarded – undo
209 243
 					setEventMessages($object->error, $object->errors, 'errors');
210 244
 					$error++;
211 245
 				}
212
-	        } else if ($reshook < 0)
213
-	            $error++;
246
+	        } else if ($reshook < 0) {
247
+	        	            $error++;
248
+	        }
214 249
 	    }
215 250
 
216
-	    if ($error)
217
-	        $action = 'edit_extras';
251
+	    if ($error) {
252
+	    	        $action = 'edit_extras';
253
+	    }
218 254
 	}
219 255
 
220 256
 	// Create reception
@@ -242,10 +278,11 @@  discard block
 block discarded – undo
242 278
 		// On va boucler sur chaque ligne du document d'origine pour completer objet reception
243 279
 		// avec info diverses + qte a livrer
244 280
 
245
-		if ($object->origin == "supplierorder")
246
-			$classname = 'CommandeFournisseur';
247
-		else
248
-			$classname = ucfirst($object->origin);
281
+		if ($object->origin == "supplierorder") {
282
+					$classname = 'CommandeFournisseur';
283
+		} else {
284
+					$classname = ucfirst($object->origin);
285
+		}
249 286
 		$objectsrc = new $classname($db);
250 287
 		$objectsrc->fetch($object->origin_id);
251 288
 
@@ -297,8 +334,9 @@  discard block
 block discarded – undo
297 334
 
298 335
 				//var_dump(GETPOST($qty,'int')); var_dump($_POST); var_dump($batch);exit;
299 336
 				//reception line for product with no batch management and no multiple stock location
300
-			if (GETPOST($qty, 'int') > 0)
301
-				$totalqty += GETPOST($qty, 'int');
337
+			if (GETPOST($qty, 'int') > 0) {
338
+							$totalqty += GETPOST($qty, 'int');
339
+			}
302 340
 
303 341
 
304 342
 			// Extrafields
@@ -307,14 +345,19 @@  discard block
 block discarded – undo
307 345
 		}
308 346
 
309 347
 
310
-		if ($totalqty > 0)  // There is at least one thing to ship
348
+		if ($totalqty > 0) {
349
+		    // There is at least one thing to ship
311 350
 		{
312 351
 			//var_dump($_POST);exit;
313
-			for ($i = 1; $i <= $num; $i++)
352
+			for ($i = 1;
353
+		}
354
+		$i <= $num; $i++)
314 355
 			{
315 356
 				$lineToTest = '';
316 357
 				foreach($objectsrc->lines as $linesrc){
317
-					if($linesrc->id == GETPOST($idl, 'int'))$lineToTest=$linesrc;
358
+					if($linesrc->id == GETPOST($idl, 'int')) {
359
+					    $lineToTest=$linesrc;
360
+					}
318 361
 				}
319 362
 				$qty = "qtyl".$i;
320 363
 				$comment = "comment".$i;
@@ -334,10 +377,12 @@  discard block
 block discarded – undo
334 377
 
335 378
 					$entrepot_id = is_numeric(GETPOST($ent, 'int')) ? GETPOST($ent, 'int') : GETPOST('entrepot_id', 'int');
336 379
 
337
-					if ($entrepot_id < 0)
338
-						$entrepot_id = '';
339
-					if (!($linesrc->fk_product > 0) && empty($conf->global->STOCK_SUPPORTS_SERVICES))
340
-						$entrepot_id = 0;
380
+					if ($entrepot_id < 0) {
381
+											$entrepot_id = '';
382
+					}
383
+					if (!($linesrc->fk_product > 0) && empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
384
+											$entrepot_id = 0;
385
+					}
341 386
 					$eatby = GETPOST($eatby, 'alpha');
342 387
 					$sellby = GETPOST($sellby, 'alpha');
343 388
 					$eatbydate = str_replace('/','-',$eatby);
@@ -356,7 +401,9 @@  discard block
 block discarded – undo
356 401
 
357 402
 	        // Fill array 'array_options' with data from add form
358 403
 	        $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
359
-	        if ($ret < 0) $error++;
404
+	        if ($ret < 0) {
405
+	            $error++;
406
+	        }
360 407
 	        if (! $error)
361 408
 	        {
362 409
 	            $ret=$object->create($user);		// This create reception (like Odoo picking) and line of receptions. Stock movement will when validating reception.
@@ -367,8 +414,7 @@  discard block
 block discarded – undo
367 414
 	                $error++;
368 415
 	            }
369 416
 	        }
370
-	    }
371
-	    else
417
+	    } else
372 418
 	    {
373 419
 	        setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("QtyToReceive").'/'.$langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
374 420
 	        $error++;
@@ -379,16 +425,13 @@  discard block
 block discarded – undo
379 425
 	        $db->commit();
380 426
 	        header("Location: card.php?id=".$object->id);
381 427
 	        exit;
382
-	    }
383
-	    else
428
+	    } else
384 429
 	    {
385 430
 	        $db->rollback();
386 431
 	        $_GET["commande_id"]=GETPOST('commande_id','int');
387 432
 	        $action='create';
388 433
 	    }
389
-	}
390
-
391
-	else if ($action == 'confirm_valid' && $confirm == 'yes' &&
434
+	} else if ($action == 'confirm_valid' && $confirm == 'yes' &&
392 435
         ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->creer))
393 436
        	|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->reception_advance->validate)))
394 437
 	)
@@ -401,16 +444,19 @@  discard block
 block discarded – undo
401 444
 	    {
402 445
 			$langs->load("errors");
403 446
 	        setEventMessages($langs->trans($object->error), null, 'errors');
404
-	    }
405
-	    else
447
+	    } else
406 448
 	    {
407 449
 	    	// Define output language
408 450
 	    	if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
409 451
 	    	{
410 452
 	    		$outputlangs = $langs;
411 453
 	    		$newlang = '';
412
-	    		if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
413
-	    		if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $object->thirdparty->default_lang;
454
+	    		if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) {
455
+	    		    $newlang = GETPOST('lang_id','aZ09');
456
+	    		}
457
+	    		if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
458
+	    		    $newlang = $object->thirdparty->default_lang;
459
+	    		}
414 460
 	    		if (! empty($newlang)) {
415 461
 	    			$outputlangs = new Translate("", $conf);
416 462
 	    			$outputlangs->setDefaultLang($newlang);
@@ -419,20 +465,19 @@  discard block
 block discarded – undo
419 465
 	    		$ret = $object->fetch($id); // Reload to get new records
420 466
 
421 467
 	    		$result=$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
422
-	    		if ($result < 0) dol_print_error($db,$result);
468
+	    		if ($result < 0) {
469
+	    		    dol_print_error($db,$result);
470
+	    		}
423 471
 	    	}
424 472
 	    }
425
-	}
426
-
427
-	else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->reception->supprimer)
473
+	} else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->reception->supprimer)
428 474
 	{
429 475
 	    $result = $object->delete($user);
430 476
 	    if ($result > 0)
431 477
 	    {
432 478
 	        header("Location: ".DOL_URL_ROOT.'/reception/index.php');
433 479
 	        exit;
434
-	    }
435
-	    else
480
+	    } else
436 481
 		{
437 482
 			setEventMessages($object->error, $object->errors, 'errors');
438 483
 	    }
@@ -470,19 +515,29 @@  discard block
 block discarded – undo
470 515
 	{
471 516
 	    $error=0;
472 517
 
473
-	    if ($action == 'settracking_number')		$object->tracking_number = trim(GETPOST('tracking_number','alpha'));
474
-	    if ($action == 'settracking_url')		$object->tracking_url = trim(GETPOST('tracking_url','int'));
518
+	    if ($action == 'settracking_number') {
519
+	        $object->tracking_number = trim(GETPOST('tracking_number','alpha'));
520
+	    }
521
+	    if ($action == 'settracking_url') {
522
+	        $object->tracking_url = trim(GETPOST('tracking_url','int'));
523
+	    }
475 524
 	    if ($action == 'settrueWeight')	{
476 525
 	    	$object->trueWeight = trim(GETPOST('trueWeight','int'));
477 526
 			$object->weight_units = GETPOST('weight_units','int');
478 527
 	    }
479
-	    if ($action == 'settrueWidth')			$object->trueWidth = trim(GETPOST('trueWidth','int'));
528
+	    if ($action == 'settrueWidth') {
529
+	        $object->trueWidth = trim(GETPOST('trueWidth','int'));
530
+	    }
480 531
 	    if ($action == 'settrueHeight'){
481 532
 	    				$object->trueHeight = trim(GETPOST('trueHeight','int'));
482 533
 						$object->size_units = GETPOST('size_units','int');
483 534
 		}
484
-	    if ($action == 'settrueDepth')			$object->trueDepth = trim(GETPOST('trueDepth','int'));
485
-	    if ($action == 'setshipping_method_id')	$object->shipping_method_id = trim(GETPOST('shipping_method_id','int'));
535
+	    if ($action == 'settrueDepth') {
536
+	        $object->trueDepth = trim(GETPOST('trueDepth','int'));
537
+	    }
538
+	    if ($action == 'setshipping_method_id') {
539
+	        $object->shipping_method_id = trim(GETPOST('shipping_method_id','int'));
540
+	    }
486 541
 
487 542
 	    if (! $error)
488 543
 	    {
@@ -498,16 +553,22 @@  discard block
 block discarded – undo
498 553
 	}
499 554
 
500 555
 	// Build document
501
-	else if ($action == 'builddoc')	// En get ou en post
556
+	else if ($action == 'builddoc') {
557
+	    // En get ou en post
502 558
 	{
503 559
 		// Save last template used to generate document
504 560
 		if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
561
+	}
505 562
 
506 563
 	    // Define output language
507 564
 	    $outputlangs = $langs;
508 565
 	    $newlang='';
509
-	    if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
510
-	    if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$reception->thirdparty->default_lang;
566
+	    if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) {
567
+	        $newlang=GETPOST('lang_id','aZ09');
568
+	    }
569
+	    if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
570
+	        $newlang=$reception->thirdparty->default_lang;
571
+	    }
511 572
 	    if (! empty($newlang))
512 573
 	    {
513 574
 	        $outputlangs = new Translate("",$conf);
@@ -529,11 +590,12 @@  discard block
 block discarded – undo
529 590
 		$upload_dir =	$conf->reception->dir_output ;
530 591
 		$file =	$upload_dir	. '/' .	GETPOST('file');
531 592
 		$ret=dol_delete_file($file,0,0,0,$object);
532
-		if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
533
-		else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
534
-	}
535
-
536
-	elseif ($action == 'classifybilled')
593
+		if ($ret) {
594
+		    setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
595
+		} else {
596
+		    setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
597
+		}
598
+	} elseif ($action == 'classifybilled')
537 599
 	{
538 600
 	    $object->fetch($id);
539 601
 	    $result = $object->set_billed();
@@ -541,9 +603,7 @@  discard block
 block discarded – undo
541 603
 	    	header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
542 604
 	    	exit();
543 605
 	    }
544
-	}
545
-
546
-	elseif ($action == 'classifyclosed')
606
+	} elseif ($action == 'classifyclosed')
547 607
 	{
548 608
 	    $object->fetch($id);
549 609
 	    $result = $object->setClosed();
@@ -580,8 +640,7 @@  discard block
 block discarded – undo
580 640
 		if(! $error) {
581 641
 			header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
582 642
 			exit();
583
-		}
584
-		else
643
+		} else
585 644
 		{
586 645
 			setEventMessages($line->error, $line->errors, 'errors');
587 646
 		}
@@ -601,9 +660,11 @@  discard block
 block discarded – undo
601 660
 		$num_prod = count($lines);
602 661
 		for ($i = 0; $i < $num_prod; $i++)
603 662
 		{
604
-			if ($lines[$i]->id == $line_id)  // we have found line to update
663
+			if ($lines[$i]->id == $line_id) {
664
+			    // we have found line to update
605 665
 			{
606 666
 				$line = new CommandeFournisseurDispatch($db);
667
+			}
607 668
 				$line->fetch($line_id);
608 669
 				// Extrafields Lines
609 670
 				$extrafieldsline = new ExtraFields($db);
@@ -645,8 +706,7 @@  discard block
 block discarded – undo
645 706
 						setEventMessages($line->error, $line->errors, 'errors');
646 707
 						$error++;
647 708
 					}
648
-				}
649
-				else // Product no predefined
709
+				} else // Product no predefined
650 710
 				{
651 711
 					$qty = "qtyl".$line_id;
652 712
 					$line->id = $line_id;
@@ -669,10 +729,12 @@  discard block
 block discarded – undo
669 729
 				// Define output language
670 730
 				$outputlangs = $langs;
671 731
 				$newlang = '';
672
-				if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09'))
673
-					$newlang = GETPOST('lang_id','aZ09');
674
-				if ($conf->global->MAIN_MULTILANGS && empty($newlang))
675
-					$newlang = $object->thirdparty->default_lang;
732
+				if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) {
733
+									$newlang = GETPOST('lang_id','aZ09');
734
+				}
735
+				if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
736
+									$newlang = $object->thirdparty->default_lang;
737
+				}
676 738
 				if (! empty($newlang)) {
677 739
 					$outputlangs = new Translate("", $conf);
678 740
 					$outputlangs->setDefaultLang($newlang);
@@ -681,15 +743,12 @@  discard block
 block discarded – undo
681 743
 				$ret = $object->fetch($object->id); // Reload to get new records
682 744
 				$object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
683 745
 			}
684
-		}
685
-		else
746
+		} else
686 747
 		{
687 748
 			header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition
688 749
 			exit();
689 750
 		}
690
-	}
691
-
692
-	else if ($action == 'updateline' && $user->rights->reception->creer && GETPOST('cancel','alpha') == $langs->trans('Cancel')) {
751
+	} else if ($action == 'updateline' && $user->rights->reception->creer && GETPOST('cancel','alpha') == $langs->trans('Cancel')) {
693 752
 		header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition
694 753
 		exit();
695 754
 	}
@@ -697,7 +756,9 @@  discard block
 block discarded – undo
697 756
 	include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
698 757
 
699 758
 	// Actions to send emails
700
-	if (empty($id)) $id=$facid;
759
+	if (empty($id)) {
760
+	    $id=$facid;
761
+	}
701 762
 	$trigger_name='RECEPTION_SENTBYMAIL';
702 763
 	$paramname='id';
703 764
 	$mode='emailfromreception';
@@ -741,19 +802,26 @@  discard block
 block discarded – undo
741 802
 
742 803
     if ($origin)
743 804
     {
744
-		if($origin == 'supplierorder')$classname = 'CommandeFournisseur';
745
-        else $classname = ucfirst($origin);
805
+		if($origin == 'supplierorder') {
806
+		    $classname = 'CommandeFournisseur';
807
+		} else {
808
+            $classname = ucfirst($origin);
809
+        }
746 810
 
747 811
         $object = new $classname($db);
748
-        if ($object->fetch($origin_id))	// This include the fetch_lines
812
+        if ($object->fetch($origin_id)) {
813
+            // This include the fetch_lines
749 814
         {
750 815
             $soc = new Societe($db);
816
+        }
751 817
             $soc->fetch($object->socid);
752 818
 
753 819
             $author = new User($db);
754 820
             $author->fetch($object->user_author_id);
755 821
 
756
-            if (! empty($conf->stock->enabled)) $entrepot = new Entrepot($db);
822
+            if (! empty($conf->stock->enabled)) {
823
+                $entrepot = new Entrepot($db);
824
+            }
757 825
 
758 826
             print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
759 827
             print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -784,8 +852,11 @@  discard block
 block discarded – undo
784 852
             print "</tr>\n";
785 853
             // Ref client
786 854
             print '<tr><td>';
787
-            if ($origin == 'supplier_order') print $langs->trans('RefSupplierOrder');
788
-            else print $langs->trans('RefSupplier');
855
+            if ($origin == 'supplier_order') {
856
+                print $langs->trans('RefSupplierOrder');
857
+            } else {
858
+                print $langs->trans('RefSupplier');
859
+            }
789 860
             print '</td><td colspan="3">';
790 861
             print '<input type="text" name="ref_supplier" value="'.$object->ref_supplier.'" />';
791 862
             print '</td>';
@@ -800,8 +871,12 @@  discard block
 block discarded – undo
800 871
             if (! empty($conf->projet->enabled))
801 872
             {
802 873
                 $projectid = GETPOST('projectid','int')?GETPOST('projectid','int'):0;
803
-                if(empty($projectid) && ! empty($object->fk_project)) $projectid = $object->fk_project;
804
-                if ($origin == 'project') $projectid = ($originid ? $originid : 0);
874
+                if(empty($projectid) && ! empty($object->fk_project)) {
875
+                    $projectid = $object->fk_project;
876
+                }
877
+                if ($origin == 'project') {
878
+                    $projectid = ($originid ? $originid : 0);
879
+                }
805 880
 
806 881
                 $langs->load("projects");
807 882
                 print '<tr>';
@@ -863,7 +938,9 @@  discard block
 block discarded – undo
863 938
             print '<td colspan="3">';
864 939
             $recept->fetch_delivery_methods();
865 940
             print $form->selectarray("shipping_method_id", $recept->meths, GETPOST('shipping_method_id','int'),1,0,0,"",1);
866
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
941
+            if ($user->admin) {
942
+                print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
943
+            }
867 944
             print "</td></tr>\n";
868 945
 
869 946
             // Tracking number
@@ -1030,17 +1107,23 @@  discard block
 block discarded – undo
1030 1107
                 $type=$line->product_type?$line->product_type:$line->fk_product_type;
1031 1108
                 // Try to enhance type detection using date_start and date_end for free lines where type
1032 1109
                 // was not saved.
1033
-                if (! empty($line->date_start)) $type=1;
1034
-                if (! empty($line->date_end)) $type=1;
1110
+                if (! empty($line->date_start)) {
1111
+                    $type=1;
1112
+                }
1113
+                if (! empty($line->date_end)) {
1114
+                    $type=1;
1115
+                }
1035 1116
 
1036 1117
                 print '<!-- line '.$line->rowid.' for product -->'."\n";
1037 1118
                 print '<tr class="oddeven">'."\n";
1038 1119
 
1039 1120
 
1040 1121
                 // Product label
1041
-                if ($line->fk_product > 0)  // If predefined product
1122
+                if ($line->fk_product > 0) {
1123
+                    // If predefined product
1042 1124
                 {
1043 1125
                     $product->fetch($line->fk_product);
1126
+                }
1044 1127
                     $product->load_stock('warehouseopen');	// Load all $product->stock_warehouse[idwarehouse]->detail_batch
1045 1128
                     //var_dump($product->stock_warehouse[1]);
1046 1129
 
@@ -1068,12 +1151,14 @@  discard block
 block discarded – undo
1068 1151
                     }
1069 1152
 
1070 1153
                     print '</td>';
1071
-                }
1072
-                else
1154
+                } else
1073 1155
 				{
1074 1156
 				    print "<td>";
1075
-                    if ($type==1) $text = img_object($langs->trans('Service'),'service');
1076
-                    else $text = img_object($langs->trans('Product'),'product');
1157
+                    if ($type==1) {
1158
+                        $text = img_object($langs->trans('Service'),'service');
1159
+                    } else {
1160
+                        $text = img_object($langs->trans('Product'),'product');
1161
+                    }
1077 1162
 
1078 1163
                     if (! empty($line->label)) {
1079 1164
                     	$text.= ' <strong>'.$line->label.'</strong>';
@@ -1108,8 +1193,7 @@  discard block
 block discarded – undo
1108 1193
 				if ($line->product_type == 1 && empty($conf->global->STOCK_SUPPORTS_SERVICES))
1109 1194
 				{
1110 1195
 					$quantityToBeDelivered = 0;
1111
-				}
1112
-				else
1196
+				} else
1113 1197
 				{
1114 1198
 					$quantityToBeDelivered = $dispatchLines[$indiceAsked]['qty'];
1115 1199
 				}
@@ -1117,9 +1201,11 @@  discard block
 block discarded – undo
1117 1201
 
1118 1202
 
1119 1203
 				$warehouseObject = null;
1120
-				if ( !empty($conf->stock->enabled))     // If warehouse was already selected or if product is not a predefined, we go into this part with no multiwarehouse selection
1204
+				if ( !empty($conf->stock->enabled)) {
1205
+				    // If warehouse was already selected or if product is not a predefined, we go into this part with no multiwarehouse selection
1121 1206
 				{
1122 1207
 				    print '<!-- Case warehouse already known or product not a predefined product -->';
1208
+				}
1123 1209
 
1124 1210
 					$stock = + $product->stock_warehouse[$dispatchLines[$indiceAsked]['ent']]->real; // Convert to number
1125 1211
 					$deliverableQty=$dispatchLines[$indiceAsked]['qty'];
@@ -1130,21 +1216,26 @@  discard block
 block discarded – undo
1130 1216
 						print '<td align="center">';
1131 1217
 						if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
1132 1218
 						{
1133
-                            if (GETPOST('qtyl'.$indiceAsked, 'int')) $defaultqty=GETPOST('qtyl'.$indiceAsked, 'int');
1219
+                            if (GETPOST('qtyl'.$indiceAsked, 'int')) {
1220
+                                $defaultqty=GETPOST('qtyl'.$indiceAsked, 'int');
1221
+                            }
1134 1222
                             print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
1135 1223
 							print '<input name="qtyl'.$indiceAsked.'" id="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$deliverableQty.'">';
1224
+						} else {
1225
+						    print $langs->trans("NA");
1136 1226
 						}
1137
-						else print $langs->trans("NA");
1138 1227
 						print '</td>';
1139 1228
 
1140 1229
 						// Stock
1141 1230
 						if (! empty($conf->stock->enabled))
1142 1231
 						{
1143 1232
 							print '<td align="left">';
1144
-							if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))   // Type of product need stock change ?
1233
+							if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1234
+							    // Type of product need stock change ?
1145 1235
 							{
1146 1236
 								// Show warehouse combo list
1147 1237
 								$ent = "entl".$indiceAsked;
1238
+							}
1148 1239
 								$idl = "idl".$indiceAsked;
1149 1240
 								$tmpentrepot_id = is_numeric(GETPOST($ent,'int'))?GETPOST($ent,'int'):$warehouse_id;
1150 1241
 								if ($line->fk_product > 0)
@@ -1152,8 +1243,7 @@  discard block
 block discarded – undo
1152 1243
 									print '<!-- Show warehouse selection -->';
1153 1244
 									print $formproduct->selectWarehouses($tmpentrepot_id, 'entl'.$indiceAsked, '', 0, 0, $line->fk_product, '', 1);
1154 1245
 								}
1155
-							}
1156
-							else
1246
+							} else
1157 1247
 							{
1158 1248
 								print $langs->trans("Service");
1159 1249
 							}
@@ -1171,8 +1261,7 @@  discard block
 block discarded – undo
1171 1261
 								print '<td>';
1172 1262
 								print $form->select_date($dispatchLines[$indiceAsked]['DLUO'],'dluo' . $indiceAsked, '', '', 1, "");
1173 1263
 								print '</td>';
1174
-							}
1175
-							else {
1264
+							} else {
1176 1265
 								print '<td colspan="3"></td>';
1177 1266
 							}
1178 1267
 						}
@@ -1183,7 +1272,9 @@  discard block
 block discarded – undo
1183 1272
 				if (is_array($extralabelslines) && count($extralabelslines)>0)
1184 1273
 				{
1185 1274
 					$colspan=5;
1186
-					if($conf->productbatch->enabled)$colspan+=3;
1275
+					if($conf->productbatch->enabled) {
1276
+					    $colspan+=3;
1277
+					}
1187 1278
 					$orderLineExtrafields = new Extrafields($db);
1188 1279
 					$orderLineExtrafieldLabels = $orderLineExtrafields->fetch_name_optionals_label($object->table_element_line);
1189 1280
 					$srcLine = new CommandeFournisseurLigne($db);
@@ -1212,21 +1303,20 @@  discard block
 block discarded – undo
1212 1303
             print '</form>';
1213 1304
 
1214 1305
             print '<br>';
1215
-        }
1216
-        else
1306
+        } else
1217 1307
 		{
1218 1308
             dol_print_error($db);
1219 1309
         }
1220 1310
     }
1221
-}
1222
-else if ($id || $ref)
1223
-/* *************************************************************************** */
1311
+} else if ($id || $ref) {
1312
+    /* *************************************************************************** */
1224 1313
 /*                                                                             */
1225 1314
 /* Edit and view mode                                                          */
1226 1315
 /*                                                                             */
1227 1316
 /* *************************************************************************** */
1228 1317
 {
1229 1318
 	$lines = $object->lines;
1319
+}
1230 1320
 
1231 1321
 	$num_prod = count($lines);
1232 1322
 
@@ -1264,8 +1354,7 @@  discard block
 block discarded – undo
1264 1354
 			if ($objectref == 'PROV')
1265 1355
 			{
1266 1356
 				$numref = $object->getNextNumRef($soc);
1267
-			}
1268
-			else
1357
+			} else
1269 1358
 			{
1270 1359
 				$numref = $object->ref;
1271 1360
 			}
@@ -1292,8 +1381,11 @@  discard block
 block discarded – undo
1292 1381
 		if (! $formconfirm) {
1293 1382
 		    $parameters = array();
1294 1383
 		    $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1295
-		    if (empty($reshook)) $formconfirm.=$hookmanager->resPrint;
1296
-		    elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint;
1384
+		    if (empty($reshook)) {
1385
+		        $formconfirm.=$hookmanager->resPrint;
1386
+		    } elseif ($reshook > 0) {
1387
+		        $formconfirm=$hookmanager->resPrint;
1388
+		    }
1297 1389
 		}
1298 1390
 
1299 1391
 		// Print form confirm
@@ -1419,7 +1511,9 @@  discard block
 block discarded – undo
1419 1511
 		print $langs->trans('DateDeliveryPlanned');
1420 1512
 		print '</td>';
1421 1513
 
1422
-		if ($action != 'editdate_livraison') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).'</a></td>';
1514
+		if ($action != 'editdate_livraison') {
1515
+		    print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).'</a></td>';
1516
+		}
1423 1517
 		print '</tr></table>';
1424 1518
 		print '</td><td colspan="2">';
1425 1519
 		if ($action == 'editdate_livraison')
@@ -1430,8 +1524,7 @@  discard block
 block discarded – undo
1430 1524
 			print $form->select_date($object->date_delivery?$object->date_delivery:-1,'liv_',1,1,'',"setdate_livraison",1,0,1);
1431 1525
 			print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
1432 1526
 			print '</form>';
1433
-		}
1434
-		else
1527
+		} else
1435 1528
 		{
1436 1529
 			print $object->date_delivery ? dol_print_date($object->date_delivery,'dayhour') : '&nbsp;';
1437 1530
 		}
@@ -1454,8 +1547,7 @@  discard block
 block discarded – undo
1454 1547
 			print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
1455 1548
 			print ' <input class="button" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
1456 1549
 			print '</form>';
1457
-		}
1458
-		else
1550
+		} else
1459 1551
 		{
1460 1552
 			print $object->trueWeight;
1461 1553
 			print ($object->trueWeight && $object->weight_units!='')?' '.measuring_units_string($object->weight_units,"weight"):'';
@@ -1464,11 +1556,15 @@  discard block
 block discarded – undo
1464 1556
         // Calculated
1465 1557
 		if ($totalWeight > 0)
1466 1558
 		{
1467
-			if (!empty($object->trueWeight)) print ' ('.$langs->trans("SumOfProductWeights").': ';
1559
+			if (!empty($object->trueWeight)) {
1560
+			    print ' ('.$langs->trans("SumOfProductWeights").': ';
1561
+			}
1468 1562
 			//print $totalWeight.' '.measuring_units_string(0,"weight");
1469 1563
 			print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND)?$conf->global->MAIN_WEIGHT_DEFAULT_ROUND:-1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT)?$conf->global->MAIN_WEIGHT_DEFAULT_UNIT:'no');
1470 1564
 			//if (empty($object->trueWeight)) print ' ('.$langs->trans("Calculated").')';
1471
-			if (!empty($object->trueWeight)) print ')';
1565
+			if (!empty($object->trueWeight)) {
1566
+			    print ')';
1567
+			}
1472 1568
 		}
1473 1569
 		print '</td></tr>';
1474 1570
 
@@ -1491,8 +1587,7 @@  discard block
 block discarded – undo
1491 1587
 			print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
1492 1588
 			print ' <input class="button" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
1493 1589
 			print '</form>';
1494
-		}
1495
-		else
1590
+		} else
1496 1591
 		{
1497 1592
 			print $object->trueHeight;
1498 1593
 			print ($object->trueHeight && $object->height_units!='')?' '.measuring_units_string($object->height_units,"size"):'';
@@ -1525,16 +1620,21 @@  discard block
 block discarded – undo
1525 1620
 			{
1526 1621
 			    //print $calculatedVolume.' '.measuring_units_string($volumeUnit,"volume");
1527 1622
 			    print showDimensionInBestUnit($calculatedVolume, $volumeUnit, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND)?$conf->global->MAIN_VOLUME_DEFAULT_ROUND:-1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT)?$conf->global->MAIN_VOLUME_DEFAULT_UNIT:'no');
1623
+			} else {
1624
+			    print $calculatedVolume.' '.measuring_units_string($volumeUnit,"volume");
1528 1625
 			}
1529
-			else print $calculatedVolume.' '.measuring_units_string($volumeUnit,"volume");
1530 1626
 		}
1531 1627
 		if ($totalVolume > 0)
1532 1628
 		{
1533
-			if ($calculatedVolume) print ' ('.$langs->trans("SumOfProductVolumes").': ';
1629
+			if ($calculatedVolume) {
1630
+			    print ' ('.$langs->trans("SumOfProductVolumes").': ';
1631
+			}
1534 1632
 			//print $totalVolume.' '.measuring_units_string(0,"volume");
1535 1633
 			print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND)?$conf->global->MAIN_VOLUME_DEFAULT_ROUND:-1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT)?$conf->global->MAIN_VOLUME_DEFAULT_UNIT:'no');
1536 1634
 			//if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')';
1537
-			if ($calculatedVolume) print ')';
1635
+			if ($calculatedVolume) {
1636
+			    print ')';
1637
+			}
1538 1638
 		}
1539 1639
 		print "</td>\n";
1540 1640
 		print '</tr>';
@@ -1559,7 +1659,9 @@  discard block
 block discarded – undo
1559 1659
 		print $langs->trans('ReceptionMethod');
1560 1660
 		print '</td>';
1561 1661
 
1562
-		if ($action != 'editshipping_method_id') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editshipping_method_id&amp;id='.$object->id.'">'.img_edit($langs->trans('SetReceptionMethod'),1).'</a></td>';
1662
+		if ($action != 'editshipping_method_id') {
1663
+		    print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editshipping_method_id&amp;id='.$object->id.'">'.img_edit($langs->trans('SetReceptionMethod'),1).'</a></td>';
1664
+		}
1563 1665
 		print '</tr></table>';
1564 1666
 		print '</td><td colspan="2">';
1565 1667
 		if ($action == 'editshipping_method_id')
@@ -1569,11 +1671,12 @@  discard block
 block discarded – undo
1569 1671
 			print '<input type="hidden" name="action" value="setshipping_method_id">';
1570 1672
 			$object->fetch_delivery_methods();
1571 1673
 			print $form->selectarray("shipping_method_id",$object->meths,$object->shipping_method_id,1,0,0,"",1);
1572
-			if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1674
+			if ($user->admin) {
1675
+			    print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1676
+			}
1573 1677
 			print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
1574 1678
 			print '</form>';
1575
-		}
1576
-		else
1679
+		} else
1577 1680
 		{
1578 1681
 			if ($object->shipping_method_id > 0)
1579 1682
 			{
@@ -1598,16 +1701,18 @@  discard block
 block discarded – undo
1598 1701
 	        print '<table width="100%" class="nobordernopadding"><tr><td>';
1599 1702
 	        print $langs->trans('IncotermLabel');
1600 1703
 	        print '<td><td align="right">';
1601
-	        if ($user->rights->reception->creer) print '<a href="'.DOL_URL_ROOT.'/reception/card.php?id='.$object->id.'&action=editincoterm">'.img_edit().'</a>';
1602
-	        else print '&nbsp;';
1704
+	        if ($user->rights->reception->creer) {
1705
+	            print '<a href="'.DOL_URL_ROOT.'/reception/card.php?id='.$object->id.'&action=editincoterm">'.img_edit().'</a>';
1706
+	        } else {
1707
+	            print '&nbsp;';
1708
+	        }
1603 1709
 	        print '</td></tr></table>';
1604 1710
 	        print '</td>';
1605 1711
 	        print '<td colspan="3">';
1606 1712
 			if ($action != 'editincoterm')
1607 1713
 			{
1608 1714
 				print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1);
1609
-			}
1610
-			else
1715
+			} else
1611 1716
 			{
1612 1717
 				print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?id='.$object->id);
1613 1718
 			}
@@ -1655,14 +1760,17 @@  discard block
 block discarded – undo
1655 1760
 		if ($action == 'editline')
1656 1761
 		{
1657 1762
 			$editColspan = 3;
1658
-			if (empty($conf->stock->enabled)) $editColspan--;
1659
-			if (empty($conf->productbatch->enabled)) $editColspan--;
1763
+			if (empty($conf->stock->enabled)) {
1764
+			    $editColspan--;
1765
+			}
1766
+			if (empty($conf->productbatch->enabled)) {
1767
+			    $editColspan--;
1768
+			}
1660 1769
 			print '<td align="center" colspan="'. $editColspan . '">';
1661 1770
 			if ($object->statut <= 1)
1662 1771
 			{
1663 1772
 				print $langs->trans("QtyToReceive").' - ';
1664
-			}
1665
-			else
1773
+			} else
1666 1774
 			{
1667 1775
 				print $langs->trans("QtyReceived").' - ';
1668 1776
 			}
@@ -1675,14 +1783,12 @@  discard block
 block discarded – undo
1675 1783
 				print $langs->trans("Batch");
1676 1784
 			}
1677 1785
 			print '</td>';
1678
-		}
1679
-		else
1786
+		} else
1680 1787
 		{
1681 1788
 			if ($object->statut <= 1)
1682 1789
 			{
1683 1790
 				print '<td align="center">'.$langs->trans("QtyToReceive").'</td>';
1684
-			}
1685
-			else
1791
+			} else
1686 1792
 			{
1687 1793
 				print '<td align="center">'.$langs->trans("QtyReceived").'</td>';
1688 1794
 			}
@@ -1713,8 +1819,12 @@  discard block
 block discarded – undo
1713 1819
 			$object->fetch_thirdparty();
1714 1820
 			$outputlangs = $langs;
1715 1821
 			$newlang='';
1716
-			if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
1717
-			if (empty($newlang)) $newlang=$object->thirdparty->default_lang;
1822
+			if (empty($newlang) && GETPOST('lang_id','aZ09')) {
1823
+			    $newlang=GETPOST('lang_id','aZ09');
1824
+			}
1825
+			if (empty($newlang)) {
1826
+			    $newlang=$object->thirdparty->default_lang;
1827
+			}
1718 1828
 			if (! empty($newlang))
1719 1829
 			{
1720 1830
 				$outputlangs = new Translate("",$conf);
@@ -1790,9 +1900,9 @@  discard block
 block discarded – undo
1790 1900
 					$prod = new Product($db);
1791 1901
 					$prod->fetch($lines[$i]->fk_product);
1792 1902
 					$label = ( ! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product->label;
1903
+				} else {
1904
+									$label = (! empty($lines[$i]->product->label)?$lines[$i]->product->label:$lines[$i]->product->product_label);
1793 1905
 				}
1794
-				else
1795
-					$label = (! empty($lines[$i]->product->label)?$lines[$i]->product->label:$lines[$i]->product->product_label);
1796 1906
 
1797 1907
 				print '<td>';
1798 1908
 
@@ -1808,12 +1918,14 @@  discard block
 block discarded – undo
1808 1918
 					print (! empty($lines[$i]->product->description) && $lines[$i]->description!=$lines[$i]->product->description)?'<br>'.dol_htmlentitiesbr($lines[$i]->description):'';
1809 1919
 				}
1810 1920
 				print "</td>\n";
1811
-			}
1812
-			else
1921
+			} else
1813 1922
 			{
1814 1923
 				print "<td>";
1815
-				if ($lines[$i]->product_type == Product::TYPE_SERVICE) $text = img_object($langs->trans('Service'),'service');
1816
-				else $text = img_object($langs->trans('Product'),'product');
1924
+				if ($lines[$i]->product_type == Product::TYPE_SERVICE) {
1925
+				    $text = img_object($langs->trans('Service'),'service');
1926
+				} else {
1927
+				    $text = img_object($langs->trans('Product'),'product');
1928
+				}
1817 1929
 
1818 1930
 				if (! empty($lines[$i]->label)) {
1819 1931
 					$text.= ' <strong>'.$lines[$i]->label.'</strong>';
@@ -1829,8 +1941,7 @@  discard block
 block discarded – undo
1829 1941
 			if ($action == 'editline' && $lines[$i]->id == $line_id)
1830 1942
 			{
1831 1943
 				print '<td ><textarea name="comment'.$line_id.'" id="comment'.$line_id.'" /> '.$lines[$i]->comment.'</textarea></td>';
1832
-			}
1833
-			else
1944
+			} else
1834 1945
 			{
1835 1946
 				print '<td style="white-space: pre-wrap;max-width: 200px;" >'.$lines[$i]->comment.'</td>';
1836 1947
 			}
@@ -1850,10 +1961,15 @@  discard block
 block discarded – undo
1850 1961
     			        $j = 0;
1851 1962
     			        foreach($val as $receptionline_id=> $receptionline_var)
1852 1963
     			        {
1853
-    			            if ($receptionline_var['reception_id'] == $lines[$i]->fk_reception) continue; // We want to show only "other receptions"
1964
+    			            if ($receptionline_var['reception_id'] == $lines[$i]->fk_reception) {
1965
+    			                continue;
1966
+    			            }
1967
+    			            // We want to show only "other receptions"
1854 1968
 
1855 1969
     			            $j++;
1856
-    			            if ($j > 1) print '<br>';
1970
+    			            if ($j > 1) {
1971
+    			                print '<br>';
1972
+    			            }
1857 1973
     			            $reception_static->fetch($receptionline_var['reception_id']);
1858 1974
     			            print $reception_static->getNomUrl(1);
1859 1975
     			            print ' - '.$receptionline_var['qty'];
@@ -1896,8 +2012,7 @@  discard block
 block discarded – undo
1896 2012
 							print '</td>';
1897 2013
 						}
1898 2014
 						print '</tr>';
1899
-					}
1900
-					else
2015
+					} else
1901 2016
 					{
1902 2017
 						print '<!-- case edit 2 -->';
1903 2018
 						print '<tr>';
@@ -1911,8 +2026,7 @@  discard block
 block discarded – undo
1911 2026
 					}
1912 2027
 				}
1913 2028
 				print '</table></td>';
1914
-			}
1915
-			else
2029
+			} else
1916 2030
 			{
1917 2031
 				// Qty to receive or received
1918 2032
 				print '<td align="center">'.$lines[$i]->qty.'</td>';
@@ -1949,8 +2063,7 @@  discard block
 block discarded – undo
1949 2063
 								$detail.= '<br>';
1950 2064
 
1951 2065
 							print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"),$detail);
1952
-						}
1953
-						else
2066
+						} else
1954 2067
 						{
1955 2068
 							print $langs->trans("NA");
1956 2069
 						}
@@ -1963,14 +2076,20 @@  discard block
 block discarded – undo
1963 2076
 
1964 2077
 			// Weight
1965 2078
 			print '<td align="center">';
1966
-			if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) print $lines[$i]->product->weight*$lines[$i]->qty.' '.measuring_units_string($lines[$i]->product->weight_units,"weight");
1967
-			else print '&nbsp;';
2079
+			if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) {
2080
+			    print $lines[$i]->product->weight*$lines[$i]->qty.' '.measuring_units_string($lines[$i]->product->weight_units,"weight");
2081
+			} else {
2082
+			    print '&nbsp;';
2083
+			}
1968 2084
 			print '</td>';
1969 2085
 
1970 2086
 			// Volume
1971 2087
 			print '<td align="center">';
1972
-			if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) print $lines[$i]->product->volume*$lines[$i]->qty.' '.measuring_units_string($lines[$i]->product->volume_units,"volume");
1973
-			else print '&nbsp;';
2088
+			if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) {
2089
+			    print $lines[$i]->product->volume*$lines[$i]->qty.' '.measuring_units_string($lines[$i]->product->volume_units,"volume");
2090
+			} else {
2091
+			    print '&nbsp;';
2092
+			}
1974 2093
 			print '</td>';
1975 2094
 
1976 2095
 
@@ -1979,8 +2098,7 @@  discard block
 block discarded – undo
1979 2098
 				print '<td align="center" colspan="2" valign="middle">';
1980 2099
 				print '<input type="submit" class="button" id="savelinebutton" name="save" value="' . $langs->trans("Save") . '"><br>';
1981 2100
 				print '<input type="submit" class="button" id="cancellinebutton" name="cancel" value="' . $langs->trans("Cancel") . '"><br>';
1982
-			}
1983
-			else if ($object->statut == 0)
2101
+			} else if ($object->statut == 0)
1984 2102
 			{
1985 2103
 				// edit-delete buttons
1986 2104
 				print '<td class="linecoledit" align="center">';
@@ -2009,8 +2127,7 @@  discard block
 block discarded – undo
2009 2127
 				if ($action == 'editline' && $lines[$i]->id == $line_id)
2010 2128
 				{
2011 2129
 					print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked);
2012
-				}
2013
-				else
2130
+				} else
2014 2131
 				{
2015 2132
 					print $line->showOptionals($extrafieldsline, 'view', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked);
2016 2133
 				}
@@ -2050,8 +2167,7 @@  discard block
 block discarded – undo
2050 2167
 	  		     || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->reception_advance->validate)))
2051 2168
 				{
2052 2169
 					print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valid">'.$langs->trans("Validate").'</a>';
2053
-				}
2054
-				else
2170
+				} else
2055 2171
 				{
2056 2172
 					print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Validate").'</a>';
2057 2173
 				}
@@ -2065,11 +2181,12 @@  discard block
 block discarded – undo
2065 2181
 			// 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order)
2066 2182
 			if ($object->statut == Reception::STATUS_CLOSED && $user->rights->reception->creer)
2067 2183
 			{
2068
-				if (! empty($conf->facture->enabled) && ! empty($conf->global->WORKFLOW_BILL_ON_RECEPTION))  // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
2184
+				if (! empty($conf->facture->enabled) && ! empty($conf->global->WORKFLOW_BILL_ON_RECEPTION)) {
2185
+				    // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
2069 2186
 				{
2070 2187
 					print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ClassifyUnbilled").'</a>';
2071 2188
 				}
2072
-				else
2189
+				} else
2073 2190
 				{
2074 2191
 			    	print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ReOpen").'</a>';
2075 2192
 				}
@@ -2081,8 +2198,9 @@  discard block
 block discarded – undo
2081 2198
 				if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->reception->reception_advance->send)
2082 2199
 				{
2083 2200
 					print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendByMail').'</a>';
2201
+				} else {
2202
+				    print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
2084 2203
 				}
2085
-				else print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
2086 2204
 			}
2087 2205
 
2088 2206
 			// Create bill
@@ -2104,9 +2222,11 @@  discard block
 block discarded – undo
2104 2222
 				{
2105 2223
 					$label="Close"; $paramaction='classifyclosed';       // = Transferred/Received
2106 2224
 					// Label here should be "Close" or "ClassifyBilled" if we decided to make bill on receptions instead of orders
2107
-					if (! empty($conf->fournisseur->enabled) && ! empty($conf->global->WORKFLOW_BILL_ON_RECEPTION))  // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
2225
+					if (! empty($conf->fournisseur->enabled) && ! empty($conf->global->WORKFLOW_BILL_ON_RECEPTION)) {
2226
+					    // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
2108 2227
 					{
2109 2228
 					    $label="ClassifyBilled";
2229
+					}
2110 2230
 					    $paramaction='classifybilled';
2111 2231
 					}
2112 2232
 					print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action='.$paramaction.'">'.$langs->trans($label).'</a>';
@@ -2157,10 +2277,12 @@  discard block
 block discarded – undo
2157 2277
 		// Define output language
2158 2278
 		$outputlangs = $langs;
2159 2279
 		$newlang = '';
2160
-		if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
2161
-			$newlang = $_REQUEST['lang_id'];
2162
-		if ($conf->global->MAIN_MULTILANGS && empty($newlang))
2163
-			$newlang = $object->thirdparty->default_lang;
2280
+		if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) {
2281
+					$newlang = $_REQUEST['lang_id'];
2282
+		}
2283
+		if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
2284
+					$newlang = $object->thirdparty->default_lang;
2285
+		}
2164 2286
 		if (!empty($newlang))
2165 2287
 		{
2166 2288
 			$outputlangs = new Translate('', $conf);
@@ -2193,14 +2315,18 @@  discard block
 block discarded – undo
2193 2315
             $formmail->fromid = $user->id;
2194 2316
         }
2195 2317
 		$formmail->trackid='shi'.$object->id;
2196
-		if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2))	// If bit 2 is set
2318
+		if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) {
2319
+		    // If bit 2 is set
2197 2320
 		{
2198 2321
 			include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2322
+		}
2199 2323
 			$formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'shi'.$object->id);
2200 2324
 		}
2201 2325
 		$formmail->withfrom=1;
2202 2326
 		$liste=array();
2203
-		foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value)	$liste[$key]=$value;
2327
+		foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value) {
2328
+		    $liste[$key]=$value;
2329
+		}
2204 2330
 		$formmail->withto=GETPOST("sendto")?GETPOST("sendto"):$liste;
2205 2331
 		$formmail->withtocc=$liste;
2206 2332
 		$formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
@@ -2225,10 +2351,12 @@  discard block
 block discarded – undo
2225 2351
 		}
2226 2352
 		$custcontact='';
2227 2353
 		$contactarr=array();
2228
-		if (is_object($objectsrc))    // For the case the reception was created without orders
2354
+		if (is_object($objectsrc)) {
2355
+		    // For the case the reception was created without orders
2229 2356
 		{
2230 2357
     		$contactarr=$objectsrc->liste_contact(-1,'external');
2231 2358
 		}
2359
+		}
2232 2360
 		if (is_array($contactarr) && count($contactarr)>0) {
2233 2361
 			foreach($contactarr as $contact) {
2234 2362
 				if ($contact['libelle']==$langs->trans('TypeContact_commande_external_CUSTOMER')) {
Please login to merge, or discard this patch.
Spacing   +421 added lines, -421 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 
37 37
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
38 38
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
39
-require DOL_BASE_PATH . '/main.inc.php';
39
+require DOL_BASE_PATH.'/main.inc.php';
40 40
 
41 41
 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
42 42
 require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
@@ -48,56 +48,56 @@  discard block
 block discarded – undo
48 48
 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
49 49
 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
50 50
 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
51
-if (! empty($conf->product->enabled) || ! empty($conf->service->enabled))  require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
52
-if (! empty($conf->propal->enabled))   require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
53
-if (! empty($conf->fournisseur->enabled)){
51
+if (!empty($conf->product->enabled) || !empty($conf->service->enabled))  require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
52
+if (!empty($conf->propal->enabled))   require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
53
+if (!empty($conf->fournisseur->enabled)) {
54 54
 	require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
55 55
 	require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
56 56
 }
57
-if (! empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
58
-if (! empty($conf->projet->enabled)) {
57
+if (!empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
58
+if (!empty($conf->projet->enabled)) {
59 59
     require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
60 60
     require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
61 61
 }
62 62
 
63
-$langs->loadLangs(array("receptions","companies","bills",'deliveries','orders','stocks','other','propal'));
63
+$langs->loadLangs(array("receptions", "companies", "bills", 'deliveries', 'orders', 'stocks', 'other', 'propal'));
64 64
 
65 65
 if (!empty($conf->incoterm->enabled)) $langs->load('incoterm');
66
-if (! empty($conf->productbatch->enabled)) $langs->load('productbatch');
66
+if (!empty($conf->productbatch->enabled)) $langs->load('productbatch');
67 67
 
68
-$origin		= GETPOST('origin','alpha')?GETPOST('origin','alpha'):'reception';   // Example: commande, propal
69
-$origin_id 	= GETPOST('id','int')?GETPOST('id','int'):'';
68
+$origin = GETPOST('origin', 'alpha') ?GETPOST('origin', 'alpha') : 'reception'; // Example: commande, propal
69
+$origin_id = GETPOST('id', 'int') ?GETPOST('id', 'int') : '';
70 70
 $id = $origin_id;
71
-if (empty($origin_id)) $origin_id  = GETPOST('origin_id','int');    // Id of order or propal
72
-if (empty($origin_id)) $origin_id  = GETPOST('object_id','int');    // Id of order or propal
73
-if (empty($origin_id)) $origin_id  = GETPOST('originid','int');    // Id of order or propal
74
-$ref=GETPOST('ref','alpha');
75
-$line_id = GETPOST('lineid','int')?GETPOST('lineid','int'):'';
71
+if (empty($origin_id)) $origin_id  = GETPOST('origin_id', 'int'); // Id of order or propal
72
+if (empty($origin_id)) $origin_id  = GETPOST('object_id', 'int'); // Id of order or propal
73
+if (empty($origin_id)) $origin_id  = GETPOST('originid', 'int'); // Id of order or propal
74
+$ref = GETPOST('ref', 'alpha');
75
+$line_id = GETPOST('lineid', 'int') ?GETPOST('lineid', 'int') : '';
76 76
 
77 77
 // Security check
78
-$socid='';
79
-if ($user->societe_id) $socid=$user->societe_id;
78
+$socid = '';
79
+if ($user->societe_id) $socid = $user->societe_id;
80 80
 
81
-if ($origin == 'reception') $result=restrictedArea($user, $origin, $id);
81
+if ($origin == 'reception') $result = restrictedArea($user, $origin, $id);
82 82
 else {
83
-	$result=restrictedArea($user, 'reception');
84
-	if($origin == 'supplierorder'){
83
+	$result = restrictedArea($user, 'reception');
84
+	if ($origin == 'supplierorder') {
85 85
 		if (empty($user->rights->fournisseur->commande->lire) && empty($user->rights->fournisseur->commande->read)) accessforbidden();
86
-	}else if (empty($user->rights->{$origin}->lire) && empty($user->rights->{$origin}->read)) accessforbidden();
86
+	} else if (empty($user->rights->{$origin}->lire) && empty($user->rights->{$origin}->read)) accessforbidden();
87 87
 }
88 88
 
89
-$action		= GETPOST('action','alpha');
89
+$action		= GETPOST('action', 'alpha');
90 90
 //Select mail models is same action as presend
91 91
 if (GETPOST('modelselected')) {
92 92
 	$action = 'presend';
93 93
 }
94
-$confirm	= GETPOST('confirm','alpha');
95
-$cancel     = GETPOST('cancel','alpha');
94
+$confirm	= GETPOST('confirm', 'alpha');
95
+$cancel = GETPOST('cancel', 'alpha');
96 96
 
97 97
 //PDF
98
-$hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
99
-$hidedesc 	 = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ?  1 : 0));
100
-$hideref 	 = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
98
+$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
99
+$hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
100
+$hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
101 101
 
102 102
 $object = new Reception($db);
103 103
 $extrafields = new ExtraFields($db);
@@ -107,16 +107,16 @@  discard block
 block discarded – undo
107 107
 $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
108 108
 
109 109
 // fetch optionals attributes lines and labels
110
-$extralabelslines=$extrafieldsline->fetch_name_optionals_label($object->table_element_line);
110
+$extralabelslines = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
111 111
 
112 112
 
113 113
 // Load object. Make an object->fetch
114
-include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php';  // Must be include, not include_once
114
+include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
115 115
 
116 116
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
117
-$hookmanager->initHooks(array('receptioncard','globalcard'));
117
+$hookmanager->initHooks(array('receptioncard', 'globalcard'));
118 118
 
119
-$permissiondellink=$user->rights->reception->creer;	// Used by the include of actions_dellink.inc.php
119
+$permissiondellink = $user->rights->reception->creer; // Used by the include of actions_dellink.inc.php
120 120
 //var_dump($object->lines[0]->detail_batch);
121 121
 
122 122
 
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
  * Actions
125 125
  */
126 126
 
127
-$parameters=array();
128
-$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
127
+$parameters = array();
128
+$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
129 129
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
130 130
 
131 131
 if (empty($reshook))
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 		$object->fetch($id); // show reception also after canceling modification
137 137
 	}
138 138
 
139
-	include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';		// Must be include, not include_once
139
+	include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
140 140
 
141 141
 	// Reopen
142 142
 	if ($action == 'reopen' && $user->rights->reception->creer)
@@ -156,13 +156,13 @@  discard block
 block discarded – undo
156 156
 			{
157 157
 				$outputlangs = $langs;
158 158
 				$newlang = '';
159
-				if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
159
+				if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
160 160
 				if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $object->thirdparty->default_lang;
161
-				if (! empty($newlang)) {
161
+				if (!empty($newlang)) {
162 162
 					$outputlangs = new Translate("", $conf);
163 163
 					$outputlangs->setDefaultLang($newlang);
164 164
 				}
165
-				$model=$object->modelpdf;
165
+				$model = $object->modelpdf;
166 166
 				$ret = $object->fetch($id); // Reload to get new records
167 167
 				$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
168 168
 			}
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
             setEventMessages($object->error, $object->errors, 'errors');
183 183
         }
184 184
 
185
-        $result = $object->setValueFrom('ref_supplier', GETPOST('ref_supplier','alpha'), '', null, 'text', '', $user, 'RECEPTION_MODIFY');
185
+        $result = $object->setValueFrom('ref_supplier', GETPOST('ref_supplier', 'alpha'), '', null, 'text', '', $user, 'RECEPTION_MODIFY');
186 186
         if ($result < 0) {
187 187
             setEventMessages($object->error, $object->errors, 'errors');
188 188
             $action = 'editref_supplier';
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 	    $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
200 200
 	    if ($ret < 0) $error++;
201 201
 
202
-	    if (! $error)
202
+	    if (!$error)
203 203
 	    {
204 204
 	        // Actions on extra fields (by external module or standard code)
205 205
 	        // TODO le hook fait double emploi avec le trigger !!
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 		$object->socid = $objectsrc->socid;
259 259
 		$object->ref_supplier = GETPOST('ref_supplier', 'alpha');
260 260
 		$object->model_pdf = GETPOST('model');
261
-		$object->date_delivery = $date_delivery;	 // Date delivery planed
261
+		$object->date_delivery = $date_delivery; // Date delivery planed
262 262
 		$object->fk_delivery_address = $objectsrc->fk_delivery_address;
263 263
 		$object->shipping_method_id = GETPOST('shipping_method_id', 'int');
264 264
 		$object->tracking_number = GETPOST('tracking_number', 'alpha');
@@ -317,8 +317,8 @@  discard block
 block discarded – undo
317 317
 			for ($i = 1; $i <= $num; $i++)
318 318
 			{
319 319
 				$lineToTest = '';
320
-				foreach($objectsrc->lines as $linesrc){
321
-					if($linesrc->id == GETPOST($idl, 'int'))$lineToTest=$linesrc;
320
+				foreach ($objectsrc->lines as $linesrc) {
321
+					if ($linesrc->id == GETPOST($idl, 'int'))$lineToTest = $linesrc;
322 322
 				}
323 323
 				$qty = "qtyl".$i;
324 324
 				$comment = "comment".$i;
@@ -344,11 +344,11 @@  discard block
 block discarded – undo
344 344
 						$entrepot_id = 0;
345 345
 					$eatby = GETPOST($eatby, 'alpha');
346 346
 					$sellby = GETPOST($sellby, 'alpha');
347
-					$eatbydate = str_replace('/','-',$eatby);
348
-					$sellbydate = str_replace('/','-',$sellby);
347
+					$eatbydate = str_replace('/', '-', $eatby);
348
+					$sellbydate = str_replace('/', '-', $sellby);
349 349
 
350 350
 
351
-					$ret = $object->addline($entrepot_id, GETPOST($idl, 'int'), GETPOST($qty, 'int'), $array_options[$i], GETPOST($comment, 'alpha'), strtotime($eatbydate),strtotime($sellbydate), GETPOST($batch, 'alpha'));
351
+					$ret = $object->addline($entrepot_id, GETPOST($idl, 'int'), GETPOST($qty, 'int'), $array_options[$i], GETPOST($comment, 'alpha'), strtotime($eatbydate), strtotime($sellbydate), GETPOST($batch, 'alpha'));
352 352
 					if ($ret < 0)
353 353
 					{
354 354
 						setEventMessages($object->error, $object->errors, 'errors');
@@ -361,9 +361,9 @@  discard block
 block discarded – undo
361 361
 	        // Fill array 'array_options' with data from add form
362 362
 	        $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
363 363
 	        if ($ret < 0) $error++;
364
-	        if (! $error)
364
+	        if (!$error)
365 365
 	        {
366
-	            $ret=$object->create($user);		// This create reception (like Odoo picking) and line of receptions. Stock movement will when validating reception.
366
+	            $ret = $object->create($user); // This create reception (like Odoo picking) and line of receptions. Stock movement will when validating reception.
367 367
 
368 368
 	            if ($ret <= 0)
369 369
 	            {
@@ -374,11 +374,11 @@  discard block
 block discarded – undo
374 374
 	    }
375 375
 	    else
376 376
 	    {
377
-	        setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("QtyToReceive").'/'.$langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
377
+	        setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("QtyToReceive").'/'.$langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
378 378
 	        $error++;
379 379
 	    }
380 380
 
381
-	    if (! $error)
381
+	    if (!$error)
382 382
 	    {
383 383
 	        $db->commit();
384 384
 	        header("Location: card.php?id=".$object->id);
@@ -387,14 +387,14 @@  discard block
 block discarded – undo
387 387
 	    else
388 388
 	    {
389 389
 	        $db->rollback();
390
-	        $_GET["commande_id"]=GETPOST('commande_id','int');
391
-	        $action='create';
390
+	        $_GET["commande_id"] = GETPOST('commande_id', 'int');
391
+	        $action = 'create';
392 392
 	    }
393 393
 	}
394 394
 
395 395
 	else if ($action == 'confirm_valid' && $confirm == 'yes' &&
396
-        ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->creer))
397
-       	|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->reception_advance->validate)))
396
+        ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
397
+       	|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))
398 398
 	)
399 399
 	{
400 400
 	    $object->fetch_thirdparty();
@@ -413,17 +413,17 @@  discard block
 block discarded – undo
413 413
 	    	{
414 414
 	    		$outputlangs = $langs;
415 415
 	    		$newlang = '';
416
-	    		if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
416
+	    		if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
417 417
 	    		if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $object->thirdparty->default_lang;
418
-	    		if (! empty($newlang)) {
418
+	    		if (!empty($newlang)) {
419 419
 	    			$outputlangs = new Translate("", $conf);
420 420
 	    			$outputlangs->setDefaultLang($newlang);
421 421
 	    		}
422
-	    		$model=$object->modelpdf;
422
+	    		$model = $object->modelpdf;
423 423
 	    		$ret = $object->fetch($id); // Reload to get new records
424 424
 
425
-	    		$result=$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
426
-	    		if ($result < 0) dol_print_error($db,$result);
425
+	    		$result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
426
+	    		if ($result < 0) dol_print_error($db, $result);
427 427
 	    	}
428 428
 	    }
429 429
 	}
@@ -454,10 +454,10 @@  discard block
 block discarded – undo
454 454
 	else if ($action == 'setdate_livraison' && $user->rights->reception->creer)
455 455
 	{
456 456
 	    //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
457
-	    $datedelivery=dol_mktime(GETPOST('liv_hour','int'), GETPOST('liv_min','int'), 0, GETPOST('liv_month','int'), GETPOST('liv_day','int'), GETPOST('liv_year','int'));
457
+	    $datedelivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int'));
458 458
 
459 459
 	    $object->fetch($id);
460
-	    $result=$object->set_date_livraison($user,$datedelivery);
460
+	    $result = $object->set_date_livraison($user, $datedelivery);
461 461
 	    if ($result < 0)
462 462
 	    {
463 463
 	        setEventMessages($object->error, $object->errors, 'errors');
@@ -472,23 +472,23 @@  discard block
 block discarded – undo
472 472
 	|| $action == 'settrueDepth'
473 473
 	|| $action == 'setshipping_method_id')
474 474
 	{
475
-	    $error=0;
475
+	    $error = 0;
476 476
 
477
-	    if ($action == 'settracking_number')		$object->tracking_number = trim(GETPOST('tracking_number','alpha'));
478
-	    if ($action == 'settracking_url')		$object->tracking_url = trim(GETPOST('tracking_url','int'));
479
-	    if ($action == 'settrueWeight')	{
480
-	    	$object->trueWeight = trim(GETPOST('trueWeight','int'));
481
-			$object->weight_units = GETPOST('weight_units','int');
477
+	    if ($action == 'settracking_number')		$object->tracking_number = trim(GETPOST('tracking_number', 'alpha'));
478
+	    if ($action == 'settracking_url')		$object->tracking_url = trim(GETPOST('tracking_url', 'int'));
479
+	    if ($action == 'settrueWeight') {
480
+	    	$object->trueWeight = trim(GETPOST('trueWeight', 'int'));
481
+			$object->weight_units = GETPOST('weight_units', 'int');
482 482
 	    }
483
-	    if ($action == 'settrueWidth')			$object->trueWidth = trim(GETPOST('trueWidth','int'));
484
-	    if ($action == 'settrueHeight'){
485
-	    				$object->trueHeight = trim(GETPOST('trueHeight','int'));
486
-						$object->size_units = GETPOST('size_units','int');
483
+	    if ($action == 'settrueWidth')			$object->trueWidth = trim(GETPOST('trueWidth', 'int'));
484
+	    if ($action == 'settrueHeight') {
485
+	    				$object->trueHeight = trim(GETPOST('trueHeight', 'int'));
486
+						$object->size_units = GETPOST('size_units', 'int');
487 487
 		}
488
-	    if ($action == 'settrueDepth')			$object->trueDepth = trim(GETPOST('trueDepth','int'));
489
-	    if ($action == 'setshipping_method_id')	$object->shipping_method_id = trim(GETPOST('shipping_method_id','int'));
488
+	    if ($action == 'settrueDepth')			$object->trueDepth = trim(GETPOST('trueDepth', 'int'));
489
+	    if ($action == 'setshipping_method_id')	$object->shipping_method_id = trim(GETPOST('shipping_method_id', 'int'));
490 490
 
491
-	    if (! $error)
491
+	    if (!$error)
492 492
 	    {
493 493
 	        if ($object->update($user) >= 0)
494 494
 	        {
@@ -498,30 +498,30 @@  discard block
 block discarded – undo
498 498
 	        setEventMessages($object->error, $object->errors, 'errors');
499 499
 	    }
500 500
 
501
-	    $action="";
501
+	    $action = "";
502 502
 	}
503 503
 
504 504
 	// Build document
505 505
 	else if ($action == 'builddoc')	// En get ou en post
506 506
 	{
507 507
 		// Save last template used to generate document
508
-		if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
508
+		if (GETPOST('model')) $object->setDocModel($user, GETPOST('model', 'alpha'));
509 509
 
510 510
 	    // Define output language
511 511
 	    $outputlangs = $langs;
512
-	    $newlang='';
513
-	    if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
514
-	    if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$reception->thirdparty->default_lang;
515
-	    if (! empty($newlang))
512
+	    $newlang = '';
513
+	    if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
514
+	    if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $reception->thirdparty->default_lang;
515
+	    if (!empty($newlang))
516 516
 	    {
517
-	        $outputlangs = new Translate("",$conf);
517
+	        $outputlangs = new Translate("", $conf);
518 518
 	        $outputlangs->setDefaultLang($newlang);
519 519
 	    }
520 520
 		$result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
521 521
 	    if ($result <= 0)
522 522
 	    {
523 523
 			setEventMessages($object->error, $object->errors, 'errors');
524
-	        $action='';
524
+	        $action = '';
525 525
 	    }
526 526
 	}
527 527
 
@@ -530,9 +530,9 @@  discard block
 block discarded – undo
530 530
 	{
531 531
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
532 532
 
533
-		$upload_dir =	$conf->reception->dir_output ;
534
-		$file =	$upload_dir	. '/' .	GETPOST('file');
535
-		$ret=dol_delete_file($file,0,0,0,$object);
533
+		$upload_dir = $conf->reception->dir_output;
534
+		$file = $upload_dir.'/'.GETPOST('file');
535
+		$ret = dol_delete_file($file, 0, 0, 0, $object);
536 536
 		if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
537 537
 		else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
538 538
 	}
@@ -541,8 +541,8 @@  discard block
 block discarded – undo
541 541
 	{
542 542
 	    $object->fetch($id);
543 543
 	    $result = $object->set_billed();
544
-	    if($result >= 0) {
545
-	    	header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
544
+	    if ($result >= 0) {
545
+	    	header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
546 546
 	    	exit();
547 547
 	    }
548 548
 	}
@@ -551,8 +551,8 @@  discard block
 block discarded – undo
551 551
 	{
552 552
 	    $object->fetch($id);
553 553
 	    $result = $object->setClosed();
554
-	    if($result >= 0) {
555
-	    	header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
554
+	    if ($result >= 0) {
555
+	    	header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
556 556
 	    	exit();
557 557
 	    }
558 558
 	}
@@ -560,20 +560,20 @@  discard block
 block discarded – undo
560 560
 	/*
561 561
 	 *  delete a line
562 562
 	 */
563
-	elseif ($action == 'deleteline' && ! empty($line_id))
563
+	elseif ($action == 'deleteline' && !empty($line_id))
564 564
 	{
565 565
 		$object->fetch($id);
566 566
 		$lines = $object->lines;
567 567
 		$line = new CommandeFournisseurDispatch($db);
568 568
 
569 569
 		$num_prod = count($lines);
570
-		for ($i = 0 ; $i < $num_prod ; $i++)
570
+		for ($i = 0; $i < $num_prod; $i++)
571 571
 		{
572 572
 			if ($lines[$i]->id == $line_id)
573 573
 			{
574 574
 					// delete single warehouse line
575 575
 					$line->id = $line_id;
576
-					if (! $error && $line->delete($user) < 0)
576
+					if (!$error && $line->delete($user) < 0)
577 577
 					{
578 578
 						$error++;
579 579
 					}
@@ -581,8 +581,8 @@  discard block
 block discarded – undo
581 581
 			unset($_POST["lineid"]);
582 582
 		}
583 583
 
584
-		if(! $error) {
585
-			header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
584
+		if (!$error) {
585
+			header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
586 586
 			exit();
587 587
 		}
588 588
 		else
@@ -631,14 +631,14 @@  discard block
 block discarded – undo
631 631
 					$line->qty = GETPOST($qty, 'int');
632 632
 					$line->comment = GETPOST($comment, 'alpha');
633 633
 
634
-					if(!empty($conf->productbatch->enabled)){
634
+					if (!empty($conf->productbatch->enabled)) {
635 635
 						$batch = "batch".$line_id;
636 636
 						$dlc = "dlc".$line_id;
637 637
 						$dluo = "dluo".$line_id;
638 638
 						$eatby = GETPOST($dlc, 'alpha');
639
-						$eatbydate = str_replace('/','-',$eatby);
639
+						$eatbydate = str_replace('/', '-', $eatby);
640 640
 						$sellby = GETPOST($dluo, 'alpha');
641
-						$sellbydate = str_replace('/','-',$sellby);
641
+						$sellbydate = str_replace('/', '-', $sellby);
642 642
 						$line->batch = GETPOST($batch, 'alpha');
643 643
 						$line->eatby = strtotime($eatbydate);
644 644
 						$line->sellby = strtotime($sellbydate);
@@ -668,16 +668,16 @@  discard block
 block discarded – undo
668 668
 
669 669
 		unset($_POST["lineid"]);
670 670
 
671
-		if (! $error) {
671
+		if (!$error) {
672 672
 			if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
673 673
 				// Define output language
674 674
 				$outputlangs = $langs;
675 675
 				$newlang = '';
676
-				if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09'))
677
-					$newlang = GETPOST('lang_id','aZ09');
676
+				if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09'))
677
+					$newlang = GETPOST('lang_id', 'aZ09');
678 678
 				if ($conf->global->MAIN_MULTILANGS && empty($newlang))
679 679
 					$newlang = $object->thirdparty->default_lang;
680
-				if (! empty($newlang)) {
680
+				if (!empty($newlang)) {
681 681
 					$outputlangs = new Translate("", $conf);
682 682
 					$outputlangs->setDefaultLang($newlang);
683 683
 				}
@@ -688,24 +688,24 @@  discard block
 block discarded – undo
688 688
 		}
689 689
 		else
690 690
 		{
691
-			header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition
691
+			header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // Pour reaffichage de la fiche en cours d'edition
692 692
 			exit();
693 693
 		}
694 694
 	}
695 695
 
696
-	else if ($action == 'updateline' && $user->rights->reception->creer && GETPOST('cancel','alpha') == $langs->trans('Cancel')) {
697
-		header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition
696
+	else if ($action == 'updateline' && $user->rights->reception->creer && GETPOST('cancel', 'alpha') == $langs->trans('Cancel')) {
697
+		header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // Pour reaffichage de la fiche en cours d'edition
698 698
 		exit();
699 699
 	}
700 700
 
701 701
 	include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
702 702
 
703 703
 	// Actions to send emails
704
-	if (empty($id)) $id=$facid;
705
-	$trigger_name='RECEPTION_SENTBYMAIL';
706
-	$paramname='id';
707
-	$mode='emailfromreception';
708
-	$trackid='shi'.$object->id;
704
+	if (empty($id)) $id = $facid;
705
+	$trigger_name = 'RECEPTION_SENTBYMAIL';
706
+	$paramname = 'id';
707
+	$mode = 'emailfromreception';
708
+	$trackid = 'shi'.$object->id;
709 709
 	include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
710 710
 }
711 711
 
@@ -714,12 +714,12 @@  discard block
 block discarded – undo
714 714
  * View
715 715
  */
716 716
 
717
-llxHeader('',$langs->trans('Reception'),'Reception');
717
+llxHeader('', $langs->trans('Reception'), 'Reception');
718 718
 
719 719
 $form = new Form($db);
720 720
 $formfile = new FormFile($db);
721 721
 $formproduct = new FormProduct($db);
722
-if (! empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }
722
+if (!empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }
723 723
 
724 724
 $product_static = new Product($db);
725 725
 $reception_static = new Reception($db);
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
 {
730 730
     print load_fiche_titre($langs->trans("CreateReception")).'<br>';
731 731
     print $langs->trans("ReceptionCreationIsDoneFromOrder");
732
-    $action=''; $id=''; $ref='';
732
+    $action = ''; $id = ''; $ref = '';
733 733
 }
734 734
 
735 735
 // Mode creation.
@@ -738,14 +738,14 @@  discard block
 block discarded – undo
738 738
     $recept = new Reception($db);
739 739
 
740 740
     print load_fiche_titre($langs->trans("CreateReception"));
741
-    if (! $origin)
741
+    if (!$origin)
742 742
     {
743 743
         setEventMessages($langs->trans("ErrorBadParameters"), null, 'errors');
744 744
     }
745 745
 
746 746
     if ($origin)
747 747
     {
748
-		if($origin == 'supplierorder')$classname = 'CommandeFournisseur';
748
+		if ($origin == 'supplierorder')$classname = 'CommandeFournisseur';
749 749
         else $classname = ucfirst($origin);
750 750
 
751 751
         $object = new $classname($db);
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
             $author = new User($db);
758 758
             $author->fetch($object->user_author_id);
759 759
 
760
-            if (! empty($conf->stock->enabled)) $entrepot = new Entrepot($db);
760
+            if (!empty($conf->stock->enabled)) $entrepot = new Entrepot($db);
761 761
 
762 762
             print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
763 763
             print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -765,9 +765,9 @@  discard block
 block discarded – undo
765 765
             print '<input type="hidden" name="origin" value="'.$origin.'">';
766 766
             print '<input type="hidden" name="origin_id" value="'.$object->id.'">';
767 767
             print '<input type="hidden" name="ref_int" value="'.$object->ref_int.'">';
768
-            if (GETPOST('entrepot_id','int'))
768
+            if (GETPOST('entrepot_id', 'int'))
769 769
             {
770
-                print '<input type="hidden" name="entrepot_id" value="'.GETPOST('entrepot_id','int').'">';
770
+                print '<input type="hidden" name="entrepot_id" value="'.GETPOST('entrepot_id', 'int').'">';
771 771
             }
772 772
 
773 773
             dol_fiche_head('');
@@ -776,13 +776,13 @@  discard block
 block discarded – undo
776 776
 
777 777
             // Ref
778 778
             print '<tr><td class="titlefieldcreate fieldrequired">';
779
-            if ($origin == 'supplierorder' && ! empty($conf->fournisseur->enabled))
779
+            if ($origin == 'supplierorder' && !empty($conf->fournisseur->enabled))
780 780
             {
781
-                print $langs->trans("RefOrder").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/fourn/commande/card.php?id='.$object->id.'">'.img_object($langs->trans("ShowOrder"),'order').' '.$object->ref;
781
+                print $langs->trans("RefOrder").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/fourn/commande/card.php?id='.$object->id.'">'.img_object($langs->trans("ShowOrder"), 'order').' '.$object->ref;
782 782
             }
783
-            if ($origin == 'propal' && ! empty($conf->propal->enabled))
783
+            if ($origin == 'propal' && !empty($conf->propal->enabled))
784 784
             {
785
-                print $langs->trans("RefProposal").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/comm/card.php?id='.$object->id.'">'.img_object($langs->trans("ShowProposal"),'propal').' '.$object->ref;
785
+                print $langs->trans("RefProposal").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/comm/card.php?id='.$object->id.'">'.img_object($langs->trans("ShowProposal"), 'propal').' '.$object->ref;
786 786
             }
787 787
             print '</a></td>';
788 788
             print "</tr>\n";
@@ -801,17 +801,17 @@  discard block
 block discarded – undo
801 801
             print '</tr>';
802 802
 
803 803
             // Project
804
-            if (! empty($conf->projet->enabled))
804
+            if (!empty($conf->projet->enabled))
805 805
             {
806
-                $projectid = GETPOST('projectid','int')?GETPOST('projectid','int'):0;
807
-                if(empty($projectid) && ! empty($object->fk_project)) $projectid = $object->fk_project;
806
+                $projectid = GETPOST('projectid', 'int') ?GETPOST('projectid', 'int') : 0;
807
+                if (empty($projectid) && !empty($object->fk_project)) $projectid = $object->fk_project;
808 808
                 if ($origin == 'project') $projectid = ($originid ? $originid : 0);
809 809
 
810 810
                 $langs->load("projects");
811 811
                 print '<tr>';
812
-                print '<td>' . $langs->trans("Project") . '</td><td colspan="2">';
812
+                print '<td>'.$langs->trans("Project").'</td><td colspan="2">';
813 813
                 $numprojet = $formproject->select_projects($soc->id, $projectid, 'projectid', 0);
814
-                print ' &nbsp; <a href="'.DOL_URL_ROOT.'/projet/card.php?socid=' . $soc->id . '&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create&socid='.$soc->id).'">' . $langs->trans("AddProject") . '</a>';
814
+                print ' &nbsp; <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$soc->id.'&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create&socid='.$soc->id).'">'.$langs->trans("AddProject").'</a>';
815 815
                 print '</td>';
816 816
                 print '</tr>';
817 817
             }
@@ -820,8 +820,8 @@  discard block
 block discarded – undo
820 820
             print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>';
821 821
             print '<td colspan="3">';
822 822
             //print dol_print_date($object->date_livraison,"day");	// date_livraison come from order and will be stored into date_delivery planed.
823
-            $date_delivery = ($date_delivery?$date_delivery:$object->date_livraison); // $date_delivery comes from GETPOST
824
-            print $form->select_date($date_delivery?$date_delivery:-1,'date_delivery',1,1,1);
823
+            $date_delivery = ($date_delivery ? $date_delivery : $object->date_livraison); // $date_delivery comes from GETPOST
824
+            print $form->select_date($date_delivery ? $date_delivery : -1, 'date_delivery', 1, 1, 1);
825 825
             print "</td>\n";
826 826
             print '</tr>';
827 827
 
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
             print "</td></tr>";
834 834
 
835 835
             // Note Private
836
-            if ($object->note_private && ! $user->societe_id)
836
+            if ($object->note_private && !$user->societe_id)
837 837
             {
838 838
                 print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
839 839
                 print '<td colspan="3">';
@@ -845,20 +845,20 @@  discard block
 block discarded – undo
845 845
             // Weight
846 846
             print '<tr><td>';
847 847
             print $langs->trans("Weight");
848
-            print '</td><td colspan="3"><input name="weight" size="4" value="'.GETPOST('weight','int').'"> ';
849
-            $text=$formproduct->select_measuring_units("weight_units","weight",GETPOST('weight_units','int'));
850
-            $htmltext=$langs->trans("KeepEmptyForAutoCalculation");
848
+            print '</td><td colspan="3"><input name="weight" size="4" value="'.GETPOST('weight', 'int').'"> ';
849
+            $text = $formproduct->select_measuring_units("weight_units", "weight", GETPOST('weight_units', 'int'));
850
+            $htmltext = $langs->trans("KeepEmptyForAutoCalculation");
851 851
             print $form->textwithpicto($text, $htmltext);
852 852
             print '</td></tr>';
853 853
             // Dim
854 854
             print '<tr><td>';
855 855
             print $langs->trans("Width").' x '.$langs->trans("Height").' x '.$langs->trans("Depth");
856
-            print ' </td><td colspan="3"><input name="sizeW" size="4" value="'.GETPOST('sizeW','int').'">';
857
-            print ' x <input name="sizeH" size="4" value="'.GETPOST('sizeH','int').'">';
858
-            print ' x <input name="sizeS" size="4" value="'.GETPOST('sizeS','int').'">';
856
+            print ' </td><td colspan="3"><input name="sizeW" size="4" value="'.GETPOST('sizeW', 'int').'">';
857
+            print ' x <input name="sizeH" size="4" value="'.GETPOST('sizeH', 'int').'">';
858
+            print ' x <input name="sizeS" size="4" value="'.GETPOST('sizeS', 'int').'">';
859 859
             print ' ';
860
-            $text=$formproduct->select_measuring_units("size_units","size");
861
-            $htmltext=$langs->trans("KeepEmptyForAutoCalculation");
860
+            $text = $formproduct->select_measuring_units("size_units", "size");
861
+            $htmltext = $langs->trans("KeepEmptyForAutoCalculation");
862 862
             print $form->textwithpicto($text, $htmltext);
863 863
             print '</td></tr>';
864 864
 
@@ -866,22 +866,22 @@  discard block
 block discarded – undo
866 866
             print "<tr><td>".$langs->trans("ReceptionMethod")."</td>";
867 867
             print '<td colspan="3">';
868 868
             $recept->fetch_delivery_methods();
869
-            print $form->selectarray("shipping_method_id", $recept->meths, GETPOST('shipping_method_id','int'),1,0,0,"",1);
870
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
869
+            print $form->selectarray("shipping_method_id", $recept->meths, GETPOST('shipping_method_id', 'int'), 1, 0, 0, "", 1);
870
+            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
871 871
             print "</td></tr>\n";
872 872
 
873 873
             // Tracking number
874 874
             print "<tr><td>".$langs->trans("TrackingNumber")."</td>";
875 875
             print '<td colspan="3">';
876
-            print '<input name="tracking_number" size="20" value="'.GETPOST('tracking_number','alpha').'">';
876
+            print '<input name="tracking_number" size="20" value="'.GETPOST('tracking_number', 'alpha').'">';
877 877
             print "</td></tr>\n";
878 878
 
879 879
             // Other attributes
880 880
             $parameters = array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"', 'socid'=>$socid);
881
-            $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$recept,$action);    // Note that $action and $object may have been modified by hook
881
+            $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $recept, $action); // Note that $action and $object may have been modified by hook
882 882
             print $hookmanager->resPrint;
883 883
 
884
-			if (empty($reshook) && ! empty($extrafields->attribute_label)) {
884
+			if (empty($reshook) && !empty($extrafields->attribute_label)) {
885 885
 				// copy from order
886 886
 				$orderExtrafields = new Extrafields($db);
887 887
 				$orderExtrafieldLabels = $orderExtrafields->fetch_name_optionals_label($object->table_element);
@@ -898,12 +898,12 @@  discard block
 block discarded – undo
898 898
 				print '<tr>';
899 899
 				print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $object->libelle_incoterms, 1).'</label></td>';
900 900
 		        print '<td colspan="3" class="maxwidthonsmartphone">';
901
-		        print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
901
+		        print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
902 902
 				print '</td></tr>';
903 903
 			}
904 904
 
905 905
             // Document model
906
-			include_once DOL_DOCUMENT_ROOT . '/core/modules/reception/modules_reception.php';
906
+			include_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
907 907
 			$liste = ModelePdfReception::liste_modeles($db);
908 908
 
909 909
 			if (count($liste) > 1)
@@ -920,14 +920,14 @@  discard block
 block discarded – undo
920 920
 
921 921
 
922 922
             // Reception lines
923
-			$numAsked=0;
923
+			$numAsked = 0;
924 924
 			$dispatchLines = array();
925 925
 			foreach ($_POST as $key => $value)
926 926
 			{
927 927
 				// without batch module enabled
928 928
 				if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg))
929 929
 				{
930
-					$numAsked ++;
930
+					$numAsked++;
931 931
 
932 932
 					// $numline=$reg[2] + 1; // line of product
933 933
 					$numline = $numAsked;
@@ -936,7 +936,7 @@  discard block
 block discarded – undo
936 936
 					$ent = "entrepot_".$reg[1].'_'.$reg[2];
937 937
 					$pu = "pu_".$reg[1].'_'.$reg[2]; // This is unit price including discount
938 938
 					$fk_commandefourndet = "fk_commandefourndet_".$reg[1].'_'.$reg[2];
939
-					$dispatchLines[$numAsked]=array('prod' => GETPOST($prod, 'int'), 'qty' =>GETPOST($qty), 'ent' =>GETPOST($ent, 'int'), 'pu' =>GETPOST($pu), 'comment' =>GETPOST('comment'),'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'));
939
+					$dispatchLines[$numAsked] = array('prod' => GETPOST($prod, 'int'), 'qty' =>GETPOST($qty), 'ent' =>GETPOST($ent, 'int'), 'pu' =>GETPOST($pu), 'comment' =>GETPOST('comment'), 'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'));
940 940
 				}
941 941
 
942 942
 				// with batch module enabled
@@ -955,7 +955,7 @@  discard block
 block discarded – undo
955 955
 					$dDLUO = dol_mktime(12, 0, 0, $_POST['dluo_'.$reg[1].'_'.$reg[2].'month'], $_POST['dluo_'.$reg[1].'_'.$reg[2].'day'], $_POST['dluo_'.$reg[1].'_'.$reg[2].'year']);
956 956
 					$dDLC = dol_mktime(12, 0, 0, $_POST['dlc_'.$reg[1].'_'.$reg[2].'month'], $_POST['dlc_'.$reg[1].'_'.$reg[2].'day'], $_POST['dlc_'.$reg[1].'_'.$reg[2].'year']);
957 957
 					$fk_commandefourndet = 'fk_commandefourndet_'.$reg[1].'_'.$reg[2];
958
-					$dispatchLines[$numAsked]=array('prod' => GETPOST($prod, 'int'), 'qty' =>GETPOST($qty), 'ent' =>GETPOST($ent, 'int'), 'pu' =>GETPOST($pu), 'comment' =>GETPOST('comment'),'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'),'DLC'=> $dDLC,'DLUO'=> $dDLUO,'lot'=> GETPOST($lot, 'alpha'));
958
+					$dispatchLines[$numAsked] = array('prod' => GETPOST($prod, 'int'), 'qty' =>GETPOST($qty), 'ent' =>GETPOST($ent, 'int'), 'pu' =>GETPOST($pu), 'comment' =>GETPOST('comment'), 'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'), 'DLC'=> $dDLC, 'DLUO'=> $dDLUO, 'lot'=> GETPOST($lot, 'alpha'));
959 959
 				}
960 960
 			}
961 961
 
@@ -963,16 +963,16 @@  discard block
 block discarded – undo
963 963
             print '<script type="text/javascript" language="javascript">
964 964
             jQuery(document).ready(function() {
965 965
 	            jQuery("#autofill").click(function() {';
966
-    	    	$i=1;
967
-    	    	while($i <= $numAsked)
966
+    	    	$i = 1;
967
+    	    	while ($i <= $numAsked)
968 968
     	    	{
969 969
     	    		print 'jQuery("#qtyl'.$i.'").val(jQuery("#qtyasked'.$i.'").val() - jQuery("#qtydelivered'.$i.'").val());'."\n";
970 970
     	    		$i++;
971 971
     	    	}
972 972
         		print '});
973 973
 	            jQuery("#autoreset").click(function() {';
974
-    	    	$i=1;
975
-    	    	while($i <= $numAsked)
974
+    	    	$i = 1;
975
+    	    	while ($i <= $numAsked)
976 976
     	    	{
977 977
     	    		print 'jQuery("#qtyl'.$i.'").val(0);'."\n";
978 978
     	    		$i++;
@@ -1004,7 +1004,7 @@  discard block
 block discarded – undo
1004 1004
 	                print ' / <a href="#" id="autoreset">'.$langs->trans("Reset").'</a>)';
1005 1005
 				}
1006 1006
                 print '</td>';
1007
-                if (! empty($conf->stock->enabled))
1007
+                if (!empty($conf->stock->enabled))
1008 1008
                 {
1009 1009
 					print '<td align="left">'.$langs->trans("Warehouse").' ('.$langs->trans("Stock").')</td>';
1010 1010
                 }
@@ -1017,13 +1017,13 @@  discard block
 block discarded – undo
1017 1017
                 print "</tr>\n";
1018 1018
             }
1019 1019
 
1020
-            $var=true;
1021
-            $indiceAsked =1;
1020
+            $var = true;
1021
+            $indiceAsked = 1;
1022 1022
             while ($indiceAsked <= $numAsked)
1023 1023
             {
1024 1024
                 $product = new Product($db);
1025
-				foreach($object->lines as $supplierLine){
1026
-					if($dispatchLines[$indiceAsked]['fk_commandefourndet'] == $supplierLine->id){
1025
+				foreach ($object->lines as $supplierLine) {
1026
+					if ($dispatchLines[$indiceAsked]['fk_commandefourndet'] == $supplierLine->id) {
1027 1027
 						$line = $supplierLine;
1028 1028
 						break;
1029 1029
 					}
@@ -1031,11 +1031,11 @@  discard block
 block discarded – undo
1031 1031
 
1032 1032
 
1033 1033
                 // Show product and description
1034
-                $type=$line->product_type?$line->product_type:$line->fk_product_type;
1034
+                $type = $line->product_type ? $line->product_type : $line->fk_product_type;
1035 1035
                 // Try to enhance type detection using date_start and date_end for free lines where type
1036 1036
                 // was not saved.
1037
-                if (! empty($line->date_start)) $type=1;
1038
-                if (! empty($line->date_end)) $type=1;
1037
+                if (!empty($line->date_start)) $type = 1;
1038
+                if (!empty($line->date_end)) $type = 1;
1039 1039
 
1040 1040
                 print '<!-- line '.$line->rowid.' for product -->'."\n";
1041 1041
                 print '<tr class="oddeven">'."\n";
@@ -1045,30 +1045,30 @@  discard block
 block discarded – undo
1045 1045
                 if ($line->fk_product > 0)  // If predefined product
1046 1046
                 {
1047 1047
                     $product->fetch($line->fk_product);
1048
-                    $product->load_stock('warehouseopen');	// Load all $product->stock_warehouse[idwarehouse]->detail_batch
1048
+                    $product->load_stock('warehouseopen'); // Load all $product->stock_warehouse[idwarehouse]->detail_batch
1049 1049
                     //var_dump($product->stock_warehouse[1]);
1050 1050
 
1051 1051
                     print '<td>';
1052 1052
                     print '<a name="'.$line->rowid.'"></a>'; // ancre pour retourner sur la ligne
1053 1053
 
1054 1054
                     // Show product and description
1055
-                    $product_static->type=$line->fk_product_type;
1056
-                    $product_static->id=$line->fk_product;
1057
-                    $product_static->ref=$line->ref;
1058
-                    $product_static->status_batch=$line->product_tobatch;
1055
+                    $product_static->type = $line->fk_product_type;
1056
+                    $product_static->id = $line->fk_product;
1057
+                    $product_static->ref = $line->ref;
1058
+                    $product_static->status_batch = $line->product_tobatch;
1059 1059
 
1060
-                    $text=$product_static->getNomUrl(1);
1061
-                    $text.= ' - '.(! empty($line->label)?$line->label:$line->product_label);
1062
-                    $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($line->desc));
1063
-                    print $form->textwithtooltip($text,$description,3,'','',$i);
1060
+                    $text = $product_static->getNomUrl(1);
1061
+                    $text .= ' - '.(!empty($line->label) ? $line->label : $line->product_label);
1062
+                    $description = ($conf->global->PRODUIT_DESC_IN_FORM ? '' : dol_htmlentitiesbr($line->desc));
1063
+                    print $form->textwithtooltip($text, $description, 3, '', '', $i);
1064 1064
 
1065 1065
                     // Show range
1066
-                    print_date_range($db->jdate($line->date_start),$db->jdate($line->date_end));
1066
+                    print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end));
1067 1067
 
1068 1068
                     // Add description in form
1069
-                    if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
1069
+                    if (!empty($conf->global->PRODUIT_DESC_IN_FORM))
1070 1070
                     {
1071
-                        print ($line->desc && $line->desc!=$line->product_label)?'<br>'.dol_htmlentitiesbr($line->desc):'';
1071
+                        print ($line->desc && $line->desc != $line->product_label) ? '<br>'.dol_htmlentitiesbr($line->desc) : '';
1072 1072
                     }
1073 1073
 
1074 1074
                     print '</td>';
@@ -1076,18 +1076,18 @@  discard block
 block discarded – undo
1076 1076
                 else
1077 1077
 				{
1078 1078
 				    print "<td>";
1079
-                    if ($type==1) $text = img_object($langs->trans('Service'),'service');
1080
-                    else $text = img_object($langs->trans('Product'),'product');
1079
+                    if ($type == 1) $text = img_object($langs->trans('Service'), 'service');
1080
+                    else $text = img_object($langs->trans('Product'), 'product');
1081 1081
 
1082
-                    if (! empty($line->label)) {
1083
-                    	$text.= ' <strong>'.$line->label.'</strong>';
1084
-                    	print $form->textwithtooltip($text,$line->desc,3,'','',$i);
1082
+                    if (!empty($line->label)) {
1083
+                    	$text .= ' <strong>'.$line->label.'</strong>';
1084
+                    	print $form->textwithtooltip($text, $line->desc, 3, '', '', $i);
1085 1085
                     } else {
1086 1086
                     	print $text.' '.nl2br($line->desc);
1087 1087
                     }
1088 1088
 
1089 1089
                     // Show range
1090
-                    print_date_range($db->jdate($line->date_start),$db->jdate($line->date_end));
1090
+                    print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end));
1091 1091
                     print "</td>\n";
1092 1092
                 }
1093 1093
 
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
 				print '<textarea style="display:none;"  name="comment'.$indiceAsked.'" >'.$line->desc.'</textarea>';
1098 1098
                 print '<input name="qtyasked'.$indiceAsked.'" id="qtyasked'.$indiceAsked.'" type="hidden" value="'.$line->qty.'">';
1099 1099
                 print '</td>';
1100
-                $qtyProdCom=$line->qty;
1100
+                $qtyProdCom = $line->qty;
1101 1101
 
1102 1102
                 // Qty already received
1103 1103
                 print '<td align="center">';
@@ -1121,20 +1121,20 @@  discard block
 block discarded – undo
1121 1121
 
1122 1122
 
1123 1123
 				$warehouseObject = null;
1124
-				if ( !empty($conf->stock->enabled))     // If warehouse was already selected or if product is not a predefined, we go into this part with no multiwarehouse selection
1124
+				if (!empty($conf->stock->enabled))     // If warehouse was already selected or if product is not a predefined, we go into this part with no multiwarehouse selection
1125 1125
 				{
1126 1126
 				    print '<!-- Case warehouse already known or product not a predefined product -->';
1127 1127
 
1128 1128
 					$stock = + $product->stock_warehouse[$dispatchLines[$indiceAsked]['ent']]->real; // Convert to number
1129
-					$deliverableQty=$dispatchLines[$indiceAsked]['qty'];
1129
+					$deliverableQty = $dispatchLines[$indiceAsked]['qty'];
1130 1130
 
1131 1131
 
1132 1132
 
1133 1133
 						// Quantity to send
1134 1134
 						print '<td align="center">';
1135
-						if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
1135
+						if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES))
1136 1136
 						{
1137
-                            if (GETPOST('qtyl'.$indiceAsked, 'int')) $defaultqty=GETPOST('qtyl'.$indiceAsked, 'int');
1137
+                            if (GETPOST('qtyl'.$indiceAsked, 'int')) $defaultqty = GETPOST('qtyl'.$indiceAsked, 'int');
1138 1138
                             print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
1139 1139
 							print '<input name="qtyl'.$indiceAsked.'" id="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$deliverableQty.'">';
1140 1140
 						}
@@ -1142,15 +1142,15 @@  discard block
 block discarded – undo
1142 1142
 						print '</td>';
1143 1143
 
1144 1144
 						// Stock
1145
-						if (! empty($conf->stock->enabled))
1145
+						if (!empty($conf->stock->enabled))
1146 1146
 						{
1147 1147
 							print '<td align="left">';
1148
-							if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))   // Type of product need stock change ?
1148
+							if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES))   // Type of product need stock change ?
1149 1149
 							{
1150 1150
 								// Show warehouse combo list
1151 1151
 								$ent = "entl".$indiceAsked;
1152 1152
 								$idl = "idl".$indiceAsked;
1153
-								$tmpentrepot_id = is_numeric(GETPOST($ent,'int'))?GETPOST($ent,'int'):$warehouse_id;
1153
+								$tmpentrepot_id = is_numeric(GETPOST($ent, 'int')) ?GETPOST($ent, 'int') : $warehouse_id;
1154 1154
 								if ($line->fk_product > 0)
1155 1155
 								{
1156 1156
 									print '<!-- Show warehouse selection -->';
@@ -1170,10 +1170,10 @@  discard block
 block discarded – undo
1170 1170
 							{
1171 1171
 								print '<td><input name="batch'.$indiceAsked.'" value="'.$dispatchLines[$indiceAsked]['lot'].'"></td>';
1172 1172
 								print '<td>';
1173
-								print $form->select_date($dispatchLines[$indiceAsked]['DLC'],'dlc' . $indiceAsked, '', '', 1, "");
1173
+								print $form->select_date($dispatchLines[$indiceAsked]['DLC'], 'dlc'.$indiceAsked, '', '', 1, "");
1174 1174
 								print '</td>';
1175 1175
 								print '<td>';
1176
-								print $form->select_date($dispatchLines[$indiceAsked]['DLUO'],'dluo' . $indiceAsked, '', '', 1, "");
1176
+								print $form->select_date($dispatchLines[$indiceAsked]['DLUO'], 'dluo'.$indiceAsked, '', '', 1, "");
1177 1177
 								print '</td>';
1178 1178
 							}
1179 1179
 							else {
@@ -1184,19 +1184,19 @@  discard block
 block discarded – undo
1184 1184
 				}
1185 1185
 
1186 1186
 				//Display lines extrafields
1187
-				if (is_array($extralabelslines) && count($extralabelslines)>0)
1187
+				if (is_array($extralabelslines) && count($extralabelslines) > 0)
1188 1188
 				{
1189
-					$colspan=5;
1190
-					if($conf->productbatch->enabled)$colspan+=3;
1189
+					$colspan = 5;
1190
+					if ($conf->productbatch->enabled)$colspan += 3;
1191 1191
 					$orderLineExtrafields = new Extrafields($db);
1192 1192
 					$orderLineExtrafieldLabels = $orderLineExtrafields->fetch_name_optionals_label($object->table_element_line);
1193 1193
 					$srcLine = new CommandeFournisseurLigne($db);
1194
-					$srcLine->fetch_optionals($line->id,$orderLineExtrafieldLabels); // fetch extrafields also available in orderline
1194
+					$srcLine->fetch_optionals($line->id, $orderLineExtrafieldLabels); // fetch extrafields also available in orderline
1195 1195
 					$line = new CommandeFournisseurDispatch($db);
1196
-					$line->fetch_optionals($object->id,$extralabelslines);
1196
+					$line->fetch_optionals($object->id, $extralabelslines);
1197 1197
 					$line->array_options = array_merge($line->array_options, $srcLine->array_options);
1198 1198
 					print '<tr class="oddeven">';
1199
-					print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked);
1199
+					print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>$colspan), $indiceAsked);
1200 1200
 					print '</tr>';
1201 1201
 				}
1202 1202
 
@@ -1210,7 +1210,7 @@  discard block
 block discarded – undo
1210 1210
             print '<div class="center">';
1211 1211
             print '<input type="submit" class="button" name="add" value="'.dol_escape_htmltag($langs->trans("Create")).'">';
1212 1212
             print '&nbsp; ';
1213
-            print '<input type="'.($backtopage?"submit":"button").'" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'"'.($backtopage?'':' onclick="javascript:history.go(-1)"').'>';	// Cancel for create does not post form if we don't know the backtopage
1213
+            print '<input type="'.($backtopage ? "submit" : "button").'" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'"'.($backtopage ? '' : ' onclick="javascript:history.go(-1)"').'>'; // Cancel for create does not post form if we don't know the backtopage
1214 1214
             print '</div>';
1215 1215
 
1216 1216
             print '</form>';
@@ -1242,7 +1242,7 @@  discard block
 block discarded – undo
1242 1242
 			$typeobject = $object->origin;
1243 1243
 			$origin = $object->origin;
1244 1244
 			$origin_id = $object->origin_id;
1245
-			$object->fetch_origin();         // Load property $object->commande, $object->propal, ...
1245
+			$object->fetch_origin(); // Load property $object->commande, $object->propal, ...
1246 1246
 		}
1247 1247
 
1248 1248
 		$soc = new Societe($db);
@@ -1250,15 +1250,15 @@  discard block
 block discarded – undo
1250 1250
 
1251 1251
 		$res = $object->fetch_optionals($object->id, $extralabels);
1252 1252
 
1253
-		$head=reception_prepare_head($object);
1253
+		$head = reception_prepare_head($object);
1254 1254
 		dol_fiche_head($head, 'reception', $langs->trans("Reception"), -1, 'reception');
1255 1255
 
1256
-		$formconfirm='';
1256
+		$formconfirm = '';
1257 1257
 
1258 1258
 		// Confirm deleteion
1259 1259
 		if ($action == 'delete')
1260 1260
 		{
1261
-			$formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('DeleteReception'),$langs->trans("ConfirmDeleteReception",$object->ref),'confirm_delete','',0,1);
1261
+			$formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteReception'), $langs->trans("ConfirmDeleteReception", $object->ref), 'confirm_delete', '', 0, 1);
1262 1262
 		}
1263 1263
 
1264 1264
 		// Confirmation validation
@@ -1274,30 +1274,30 @@  discard block
 block discarded – undo
1274 1274
 				$numref = $object->ref;
1275 1275
 			}
1276 1276
 
1277
-			$text = $langs->trans("ConfirmValidateReception",$numref);
1277
+			$text = $langs->trans("ConfirmValidateReception", $numref);
1278 1278
 
1279
-			if (! empty($conf->notification->enabled))
1279
+			if (!empty($conf->notification->enabled))
1280 1280
 			{
1281
-				require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
1282
-				$notify=new Notify($db);
1283
-				$text.='<br>';
1284
-				$text.=$notify->confirmMessage('RECEPTION_VALIDATE',$object->socid, $object);
1281
+				require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1282
+				$notify = new Notify($db);
1283
+				$text .= '<br>';
1284
+				$text .= $notify->confirmMessage('RECEPTION_VALIDATE', $object->socid, $object);
1285 1285
 			}
1286 1286
 
1287
-			$formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('ValidateReception'),$text,'confirm_valid','',0,1);
1287
+			$formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('ValidateReception'), $text, 'confirm_valid', '', 0, 1);
1288 1288
 		}
1289 1289
 
1290 1290
 		// Confirm cancelation
1291 1291
 		if ($action == 'annuler')
1292 1292
 		{
1293
-			$formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('CancelReception'),$langs->trans("ConfirmCancelReception",$object->ref),'confirm_cancel','',0,1);
1293
+			$formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('CancelReception'), $langs->trans("ConfirmCancelReception", $object->ref), 'confirm_cancel', '', 0, 1);
1294 1294
 		}
1295 1295
 
1296
-		if (! $formconfirm) {
1296
+		if (!$formconfirm) {
1297 1297
 		    $parameters = array();
1298 1298
 		    $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1299
-		    if (empty($reshook)) $formconfirm.=$hookmanager->resPrint;
1300
-		    elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint;
1299
+		    if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;
1300
+		    elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;
1301 1301
 		}
1302 1302
 
1303 1303
 		// Print form confirm
@@ -1306,64 +1306,64 @@  discard block
 block discarded – undo
1306 1306
 
1307 1307
 		// Calculate totalWeight and totalVolume for all products
1308 1308
 		// by adding weight and volume of each product line.
1309
-		$tmparray=$object->getTotalWeightVolume();
1310
-		$totalWeight=$tmparray['weight'];
1311
-		$totalVolume=$tmparray['volume'];
1309
+		$tmparray = $object->getTotalWeightVolume();
1310
+		$totalWeight = $tmparray['weight'];
1311
+		$totalVolume = $tmparray['volume'];
1312 1312
 
1313 1313
 
1314
-		if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
1314
+		if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled))
1315 1315
 		{
1316
-		    $objectsrc=new Commande($db);
1316
+		    $objectsrc = new Commande($db);
1317 1317
 		    $objectsrc->fetch($object->$typeobject->id);
1318 1318
 		}
1319
-		if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
1319
+		if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled))
1320 1320
 		{
1321
-		    $objectsrc=new Propal($db);
1321
+		    $objectsrc = new Propal($db);
1322 1322
 		    $objectsrc->fetch($object->$typeobject->id);
1323 1323
 		}
1324
-		if ($typeobject == 'CommandeFournisseur' && $object->$typeobject->id && ! empty($conf->fournisseur->enabled))
1324
+		if ($typeobject == 'CommandeFournisseur' && $object->$typeobject->id && !empty($conf->fournisseur->enabled))
1325 1325
 		{
1326
-		    $objectsrc=new CommandeFournisseur($db);
1326
+		    $objectsrc = new CommandeFournisseur($db);
1327 1327
 		    $objectsrc->fetch($object->$typeobject->id);
1328 1328
 		}
1329 1329
 		// Reception card
1330
-		$linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">'.$langs->trans("BackToList").'</a>';
1331
-		$morehtmlref='<div class="refidno">';
1330
+		$linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
1331
+		$morehtmlref = '<div class="refidno">';
1332 1332
 		// Ref customer reception
1333 1333
 
1334
-		$morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1);
1335
-		$morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1);
1334
+		$morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1);
1335
+		$morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1);
1336 1336
 
1337 1337
 		// Thirdparty
1338
-        $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
1338
+        $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
1339 1339
         // Project
1340
-        if (! empty($conf->projet->enabled))
1340
+        if (!empty($conf->projet->enabled))
1341 1341
         {
1342 1342
             $langs->load("projects");
1343
-            $morehtmlref .= '<br>' . $langs->trans('Project') . ' ';
1343
+            $morehtmlref .= '<br>'.$langs->trans('Project').' ';
1344 1344
             if (0) {    // Do not change on reception
1345 1345
                 if ($action != 'classify') {
1346
-                    $morehtmlref .= '<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
1346
+                    $morehtmlref .= '<a href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
1347 1347
                 }
1348 1348
                 if ($action == 'classify') {
1349 1349
                     // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
1350
-                    $morehtmlref .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
1350
+                    $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
1351 1351
                     $morehtmlref .= '<input type="hidden" name="action" value="classin">';
1352
-                    $morehtmlref .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
1352
+                    $morehtmlref .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1353 1353
                     $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
1354
-                    $morehtmlref .= '<input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
1354
+                    $morehtmlref .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
1355 1355
                     $morehtmlref .= '</form>';
1356 1356
                 } else {
1357
-                    $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
1357
+                    $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
1358 1358
                 }
1359 1359
             } else {
1360 1360
                 // We don't have project on reception, so we will use the project or source object instead
1361 1361
                 // TODO Add project on reception
1362 1362
                 $morehtmlref .= ' : ';
1363
-                if (! empty($objectsrc->fk_project)) {
1363
+                if (!empty($objectsrc->fk_project)) {
1364 1364
                     $proj = new Project($db);
1365 1365
                     $proj->fetch($objectsrc->fk_project);
1366
-                    $morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $objectsrc->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
1366
+                    $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objectsrc->fk_project.'" title="'.$langs->trans('ShowProject').'">';
1367 1367
                     $morehtmlref .= $proj->ref;
1368 1368
                     $morehtmlref .= '</a>';
1369 1369
                 } else {
@@ -1371,7 +1371,7 @@  discard block
 block discarded – undo
1371 1371
                 }
1372 1372
             }
1373 1373
         }
1374
-		$morehtmlref.='</div>';
1374
+		$morehtmlref .= '</div>';
1375 1375
 
1376 1376
 		$object->picto = 'sending';
1377 1377
     	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
@@ -1384,37 +1384,37 @@  discard block
 block discarded – undo
1384 1384
         print '<table class="border" width="100%">';
1385 1385
 
1386 1386
 		// Linked documents
1387
-		if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
1387
+		if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled))
1388 1388
 		{
1389 1389
 			print '<tr><td>';
1390 1390
 			print $langs->trans("RefOrder").'</td>';
1391 1391
 			print '<td colspan="3">';
1392
-			print $objectsrc->getNomUrl(1,'commande');
1392
+			print $objectsrc->getNomUrl(1, 'commande');
1393 1393
 			print "</td>\n";
1394 1394
 			print '</tr>';
1395 1395
 		}
1396
-		if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
1396
+		if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled))
1397 1397
 		{
1398 1398
 			print '<tr><td>';
1399 1399
 			print $langs->trans("RefProposal").'</td>';
1400 1400
 			print '<td colspan="3">';
1401
-			print $objectsrc->getNomUrl(1,'reception');
1401
+			print $objectsrc->getNomUrl(1, 'reception');
1402 1402
 			print "</td>\n";
1403 1403
 			print '</tr>';
1404 1404
 		}
1405
-		if ($typeobject == 'CommandeFournisseur' && $object->$typeobject->id && ! empty($conf->propal->enabled))
1405
+		if ($typeobject == 'CommandeFournisseur' && $object->$typeobject->id && !empty($conf->propal->enabled))
1406 1406
 		{
1407 1407
 			print '<tr><td>';
1408 1408
 			print $langs->trans("RefSupplierOrder").'</td>';
1409 1409
 			print '<td colspan="3">';
1410
-			print $objectsrc->getNomUrl(1,'reception');
1410
+			print $objectsrc->getNomUrl(1, 'reception');
1411 1411
 			print "</td>\n";
1412 1412
 			print '</tr>';
1413 1413
 		}
1414 1414
 
1415 1415
 		// Date creation
1416 1416
 		print '<tr><td class="titlefield">'.$langs->trans("DateCreation").'</td>';
1417
-		print '<td colspan="3">'.dol_print_date($object->date_creation,"dayhour")."</td>\n";
1417
+		print '<td colspan="3">'.dol_print_date($object->date_creation, "dayhour")."</td>\n";
1418 1418
 		print '</tr>';
1419 1419
 
1420 1420
 		// Delivery date planned
@@ -1423,7 +1423,7 @@  discard block
 block discarded – undo
1423 1423
 		print $langs->trans('DateDeliveryPlanned');
1424 1424
 		print '</td>';
1425 1425
 
1426
-		if ($action != 'editdate_livraison') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).'</a></td>';
1426
+		if ($action != 'editdate_livraison') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'), 1).'</a></td>';
1427 1427
 		print '</tr></table>';
1428 1428
 		print '</td><td colspan="2">';
1429 1429
 		if ($action == 'editdate_livraison')
@@ -1431,30 +1431,30 @@  discard block
 block discarded – undo
1431 1431
 			print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
1432 1432
 			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1433 1433
 			print '<input type="hidden" name="action" value="setdate_livraison">';
1434
-			print $form->select_date($object->date_delivery?$object->date_delivery:-1,'liv_',1,1,'',"setdate_livraison",1,0,1);
1434
+			print $form->select_date($object->date_delivery ? $object->date_delivery : -1, 'liv_', 1, 1, '', "setdate_livraison", 1, 0, 1);
1435 1435
 			print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
1436 1436
 			print '</form>';
1437 1437
 		}
1438 1438
 		else
1439 1439
 		{
1440
-			print $object->date_delivery ? dol_print_date($object->date_delivery,'dayhour') : '&nbsp;';
1440
+			print $object->date_delivery ? dol_print_date($object->date_delivery, 'dayhour') : '&nbsp;';
1441 1441
 		}
1442 1442
 		print '</td>';
1443 1443
 		print '</tr>';
1444 1444
 
1445 1445
 		// Weight
1446 1446
 		print '<tr><td>';
1447
-		print $form->editfieldkey("Weight",'trueWeight',$object->trueWeight,$object,$user->rights->reception->creer);
1447
+		print $form->editfieldkey("Weight", 'trueWeight', $object->trueWeight, $object, $user->rights->reception->creer);
1448 1448
 		print '</td><td colspan="3">';
1449 1449
 
1450
-		if ($action=='edittrueWeight')
1450
+		if ($action == 'edittrueWeight')
1451 1451
 		{
1452 1452
 			print '<form name="settrueweight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
1453 1453
 			print '<input name="action" value="settrueWeight" type="hidden">';
1454 1454
 			print '<input name="id" value="'.$object->id.'" type="hidden">';
1455 1455
 			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1456 1456
 			print '<input id="trueWeight" name="trueWeight" value="'.$object->trueWeight.'" type="text">';
1457
-			print $formproduct->select_measuring_units("weight_units","weight",$object->weight_units);
1457
+			print $formproduct->select_measuring_units("weight_units", "weight", $object->weight_units);
1458 1458
 			print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
1459 1459
 			print ' <input class="button" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
1460 1460
 			print '</form>';
@@ -1462,7 +1462,7 @@  discard block
 block discarded – undo
1462 1462
 		else
1463 1463
 		{
1464 1464
 			print $object->trueWeight;
1465
-			print ($object->trueWeight && $object->weight_units!='')?' '.measuring_units_string($object->weight_units,"weight"):'';
1465
+			print ($object->trueWeight && $object->weight_units != '') ? ' '.measuring_units_string($object->weight_units, "weight") : '';
1466 1466
 		}
1467 1467
 
1468 1468
         // Calculated
@@ -1470,28 +1470,28 @@  discard block
 block discarded – undo
1470 1470
 		{
1471 1471
 			if (!empty($object->trueWeight)) print ' ('.$langs->trans("SumOfProductWeights").': ';
1472 1472
 			//print $totalWeight.' '.measuring_units_string(0,"weight");
1473
-			print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND)?$conf->global->MAIN_WEIGHT_DEFAULT_ROUND:-1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT)?$conf->global->MAIN_WEIGHT_DEFAULT_UNIT:'no');
1473
+			print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND) ? $conf->global->MAIN_WEIGHT_DEFAULT_ROUND : -1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? $conf->global->MAIN_WEIGHT_DEFAULT_UNIT : 'no');
1474 1474
 			//if (empty($object->trueWeight)) print ' ('.$langs->trans("Calculated").')';
1475 1475
 			if (!empty($object->trueWeight)) print ')';
1476 1476
 		}
1477 1477
 		print '</td></tr>';
1478 1478
 
1479 1479
 		// Width
1480
-		print '<tr><td>'.$form->editfieldkey("Width",'trueWidth',$object->trueWidth,$object,$user->rights->reception->creer).'</td><td colspan="3">';
1481
-		print $form->editfieldval("Width",'trueWidth',$object->trueWidth,$object,$user->rights->reception->creer);
1482
-		print ($object->trueWidth && $object->width_units!='')?' '.measuring_units_string($object->width_units,"size"):'';
1480
+		print '<tr><td>'.$form->editfieldkey("Width", 'trueWidth', $object->trueWidth, $object, $user->rights->reception->creer).'</td><td colspan="3">';
1481
+		print $form->editfieldval("Width", 'trueWidth', $object->trueWidth, $object, $user->rights->reception->creer);
1482
+		print ($object->trueWidth && $object->width_units != '') ? ' '.measuring_units_string($object->width_units, "size") : '';
1483 1483
 		print '</td></tr>';
1484 1484
 
1485 1485
 		// Height
1486
-		print '<tr><td>'.$form->editfieldkey("Height",'trueHeight',$object->trueHeight,$object,$user->rights->reception->creer).'</td><td colspan="3">';
1487
-		if($action=='edittrueHeight')
1486
+		print '<tr><td>'.$form->editfieldkey("Height", 'trueHeight', $object->trueHeight, $object, $user->rights->reception->creer).'</td><td colspan="3">';
1487
+		if ($action == 'edittrueHeight')
1488 1488
 		{
1489 1489
 			print '<form name="settrueHeight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
1490 1490
 			print '<input name="action" value="settrueHeight" type="hidden">';
1491 1491
 			print '<input name="id" value="'.$object->id.'" type="hidden">';
1492 1492
 			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1493 1493
 			print '<input id="trueHeight" name="trueHeight" value="'.$object->trueHeight.'" type="text">';
1494
-			print $formproduct->select_measuring_units("size_units","size",$object->size_units);
1494
+			print $formproduct->select_measuring_units("size_units", "size", $object->size_units);
1495 1495
 			print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
1496 1496
 			print ' <input class="button" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
1497 1497
 			print '</form>';
@@ -1499,15 +1499,15 @@  discard block
 block discarded – undo
1499 1499
 		else
1500 1500
 		{
1501 1501
 			print $object->trueHeight;
1502
-			print ($object->trueHeight && $object->height_units!='')?' '.measuring_units_string($object->height_units,"size"):'';
1502
+			print ($object->trueHeight && $object->height_units != '') ? ' '.measuring_units_string($object->height_units, "size") : '';
1503 1503
 		}
1504 1504
 
1505 1505
 		print '</td></tr>';
1506 1506
 
1507 1507
 		// Depth
1508
-		print '<tr><td>'.$form->editfieldkey("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->reception->creer).'</td><td colspan="3">';
1509
-		print $form->editfieldval("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->reception->creer);
1510
-		print ($object->trueDepth && $object->depth_units!='')?' '.measuring_units_string($object->depth_units,"size"):'';
1508
+		print '<tr><td>'.$form->editfieldkey("Depth", 'trueDepth', $object->trueDepth, $object, $user->rights->reception->creer).'</td><td colspan="3">';
1509
+		print $form->editfieldval("Depth", 'trueDepth', $object->trueDepth, $object, $user->rights->reception->creer);
1510
+		print ($object->trueDepth && $object->depth_units != '') ? ' '.measuring_units_string($object->depth_units, "size") : '';
1511 1511
 		print '</td></tr>';
1512 1512
 
1513 1513
 		// Volume
@@ -1515,12 +1515,12 @@  discard block
 block discarded – undo
1515 1515
 		print $langs->trans("Volume");
1516 1516
 		print '</td>';
1517 1517
 		print '<td colspan="3">';
1518
-		$calculatedVolume=0;
1519
-		$volumeUnit=0;
1518
+		$calculatedVolume = 0;
1519
+		$volumeUnit = 0;
1520 1520
 		if ($object->trueWidth && $object->trueHeight && $object->trueDepth)
1521 1521
 		{
1522
-		    $calculatedVolume=($object->trueWidth * $object->trueHeight * $object->trueDepth);
1523
-		    $volumeUnit=$object->size_units * 3;
1522
+		    $calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth);
1523
+		    $volumeUnit = $object->size_units * 3;
1524 1524
 		}
1525 1525
 		// If reception volume not defined we use sum of products
1526 1526
 		if ($calculatedVolume > 0)
@@ -1528,15 +1528,15 @@  discard block
 block discarded – undo
1528 1528
 			if ($volumeUnit < 50)
1529 1529
 			{
1530 1530
 			    //print $calculatedVolume.' '.measuring_units_string($volumeUnit,"volume");
1531
-			    print showDimensionInBestUnit($calculatedVolume, $volumeUnit, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND)?$conf->global->MAIN_VOLUME_DEFAULT_ROUND:-1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT)?$conf->global->MAIN_VOLUME_DEFAULT_UNIT:'no');
1531
+			    print showDimensionInBestUnit($calculatedVolume, $volumeUnit, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND) ? $conf->global->MAIN_VOLUME_DEFAULT_ROUND : -1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT) ? $conf->global->MAIN_VOLUME_DEFAULT_UNIT : 'no');
1532 1532
 			}
1533
-			else print $calculatedVolume.' '.measuring_units_string($volumeUnit,"volume");
1533
+			else print $calculatedVolume.' '.measuring_units_string($volumeUnit, "volume");
1534 1534
 		}
1535 1535
 		if ($totalVolume > 0)
1536 1536
 		{
1537 1537
 			if ($calculatedVolume) print ' ('.$langs->trans("SumOfProductVolumes").': ';
1538 1538
 			//print $totalVolume.' '.measuring_units_string(0,"volume");
1539
-			print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND)?$conf->global->MAIN_VOLUME_DEFAULT_ROUND:-1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT)?$conf->global->MAIN_VOLUME_DEFAULT_UNIT:'no');
1539
+			print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND) ? $conf->global->MAIN_VOLUME_DEFAULT_ROUND : -1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT) ? $conf->global->MAIN_VOLUME_DEFAULT_UNIT : 'no');
1540 1540
 			//if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')';
1541 1541
 			if ($calculatedVolume) print ')';
1542 1542
 		}
@@ -1546,7 +1546,7 @@  discard block
 block discarded – undo
1546 1546
 		// Other attributes
1547 1547
 		$cols = 2;
1548 1548
 
1549
-		include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
1549
+		include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1550 1550
 
1551 1551
 		print '</table>';
1552 1552
 
@@ -1563,7 +1563,7 @@  discard block
 block discarded – undo
1563 1563
 		print $langs->trans('ReceptionMethod');
1564 1564
 		print '</td>';
1565 1565
 
1566
-		if ($action != 'editshipping_method_id') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editshipping_method_id&amp;id='.$object->id.'">'.img_edit($langs->trans('SetReceptionMethod'),1).'</a></td>';
1566
+		if ($action != 'editshipping_method_id') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editshipping_method_id&amp;id='.$object->id.'">'.img_edit($langs->trans('SetReceptionMethod'), 1).'</a></td>';
1567 1567
 		print '</tr></table>';
1568 1568
 		print '</td><td colspan="2">';
1569 1569
 		if ($action == 'editshipping_method_id')
@@ -1572,8 +1572,8 @@  discard block
 block discarded – undo
1572 1572
 			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1573 1573
 			print '<input type="hidden" name="action" value="setshipping_method_id">';
1574 1574
 			$object->fetch_delivery_methods();
1575
-			print $form->selectarray("shipping_method_id",$object->meths,$object->shipping_method_id,1,0,0,"",1);
1576
-			if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1575
+			print $form->selectarray("shipping_method_id", $object->meths, $object->shipping_method_id, 1, 0, 0, "", 1);
1576
+			if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1577 1577
 			print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
1578 1578
 			print '</form>';
1579 1579
 		}
@@ -1582,7 +1582,7 @@  discard block
 block discarded – undo
1582 1582
 			if ($object->shipping_method_id > 0)
1583 1583
 			{
1584 1584
 				// Get code using getLabelFromKey
1585
-				$code=$langs->getLabelFromKey($db,$object->shipping_method_id,'c_shipment_mode','rowid','code');
1585
+				$code = $langs->getLabelFromKey($db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
1586 1586
 				print $langs->trans("SendingMethod".strtoupper($code));
1587 1587
 			}
1588 1588
 		}
@@ -1591,8 +1591,8 @@  discard block
 block discarded – undo
1591 1591
 
1592 1592
 		// Tracking Number
1593 1593
 
1594
-		print '<tr><td class="titlefield">'.$form->editfieldkey("TrackingNumber",'tracking_number',$object->tracking_number,$object,$user->rights->reception->creer).'</td><td colspan="3">';
1595
-		print $form->editfieldval("TrackingNumber",'tracking_number',$object->tracking_url,$object,$user->rights->reception->creer,'string',$object->tracking_number);
1594
+		print '<tr><td class="titlefield">'.$form->editfieldkey("TrackingNumber", 'tracking_number', $object->tracking_number, $object, $user->rights->reception->creer).'</td><td colspan="3">';
1595
+		print $form->editfieldval("TrackingNumber", 'tracking_number', $object->tracking_url, $object, $user->rights->reception->creer, 'string', $object->tracking_number);
1596 1596
 		print '</td></tr>';
1597 1597
 
1598 1598
 		// Incoterms
@@ -1613,7 +1613,7 @@  discard block
 block discarded – undo
1613 1613
 			}
1614 1614
 			else
1615 1615
 			{
1616
-				print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?id='.$object->id);
1616
+				print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
1617 1617
 			}
1618 1618
 	        print '</td></tr>';
1619 1619
 		}
@@ -1630,11 +1630,11 @@  discard block
 block discarded – undo
1630 1630
 		// Lines of products
1631 1631
 		if ($action == 'editline')
1632 1632
 		{
1633
-			print '<form name="updateline" id="updateline" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;lineid=' . $line_id . '" method="POST">
1634
-			<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">
1633
+			print '<form name="updateline" id="updateline" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;lineid='.$line_id.'" method="POST">
1634
+			<input type="hidden" name="token" value="' . $_SESSION ['newtoken'].'">
1635 1635
 			<input type="hidden" name="action" value="updateline">
1636 1636
 			<input type="hidden" name="mode" value="">
1637
-			<input type="hidden" name="id" value="' . $object->id . '">';
1637
+			<input type="hidden" name="id" value="' . $object->id.'">';
1638 1638
 		}
1639 1639
 		print '<br>';
1640 1640
 
@@ -1642,7 +1642,7 @@  discard block
 block discarded – undo
1642 1642
 		print '<table class="noborder" width="100%">';
1643 1643
 		print '<tr class="liste_titre">';
1644 1644
 		// #
1645
-		if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
1645
+		if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER))
1646 1646
 		{
1647 1647
 			print '<td width="5" align="center">&nbsp;</td>';
1648 1648
 		}
@@ -1661,7 +1661,7 @@  discard block
 block discarded – undo
1661 1661
 			$editColspan = 3;
1662 1662
 			if (empty($conf->stock->enabled)) $editColspan--;
1663 1663
 			if (empty($conf->productbatch->enabled)) $editColspan--;
1664
-			print '<td align="center" colspan="'. $editColspan . '">';
1664
+			print '<td align="center" colspan="'.$editColspan.'">';
1665 1665
 			if ($object->statut <= 1)
1666 1666
 			{
1667 1667
 				print $langs->trans("QtyToReceive").' - ';
@@ -1670,11 +1670,11 @@  discard block
 block discarded – undo
1670 1670
 			{
1671 1671
 				print $langs->trans("QtyReceived").' - ';
1672 1672
 			}
1673
-			if (! empty($conf->stock->enabled))
1673
+			if (!empty($conf->stock->enabled))
1674 1674
 			{
1675 1675
 				print $langs->trans("WarehouseSource").' - ';
1676 1676
 			}
1677
-			if (! empty($conf->productbatch->enabled))
1677
+			if (!empty($conf->productbatch->enabled))
1678 1678
 			{
1679 1679
 				print $langs->trans("Batch");
1680 1680
 			}
@@ -1690,12 +1690,12 @@  discard block
 block discarded – undo
1690 1690
 			{
1691 1691
 				print '<td align="center">'.$langs->trans("QtyReceived").'</td>';
1692 1692
 			}
1693
-			if (! empty($conf->stock->enabled))
1693
+			if (!empty($conf->stock->enabled))
1694 1694
 			{
1695 1695
 				print '<td align="left">'.$langs->trans("WarehouseSource").'</td>';
1696 1696
 			}
1697 1697
 
1698
-			if (! empty($conf->productbatch->enabled))
1698
+			if (!empty($conf->productbatch->enabled))
1699 1699
 			{
1700 1700
 				print '<td align="left">'.$langs->trans("Batch").'</td>';
1701 1701
 			}
@@ -1710,18 +1710,18 @@  discard block
 block discarded – undo
1710 1710
 		}
1711 1711
 		print "</tr>\n";
1712 1712
 
1713
-		$var=false;
1713
+		$var = false;
1714 1714
 
1715
-		if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
1715
+		if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
1716 1716
 		{
1717 1717
 			$object->fetch_thirdparty();
1718 1718
 			$outputlangs = $langs;
1719
-			$newlang='';
1720
-			if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
1721
-			if (empty($newlang)) $newlang=$object->thirdparty->default_lang;
1722
-			if (! empty($newlang))
1719
+			$newlang = '';
1720
+			if (empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
1721
+			if (empty($newlang)) $newlang = $object->thirdparty->default_lang;
1722
+			if (!empty($newlang))
1723 1723
 			{
1724
-				$outputlangs = new Translate("",$conf);
1724
+				$outputlangs = new Translate("", $conf);
1725 1725
 				$outputlangs->setDefaultLang($newlang);
1726 1726
 			}
1727 1727
 		}
@@ -1734,23 +1734,23 @@  discard block
 block discarded – undo
1734 1734
 		if ($origin && $origin_id > 0)
1735 1735
 		{
1736 1736
     		$sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.date_start, obj.date_end";
1737
-    		$sql.= ", ed.rowid as receptionline_id, ed.qty, ed.fk_reception as reception_id,  ed.fk_entrepot";
1738
-    		$sql.= ", e.rowid as reception_id, e.ref as reception_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_reception";
1737
+    		$sql .= ", ed.rowid as receptionline_id, ed.qty, ed.fk_reception as reception_id,  ed.fk_entrepot";
1738
+    		$sql .= ", e.rowid as reception_id, e.ref as reception_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_reception";
1739 1739
     		//if ($conf->livraison_bon->enabled) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received";
1740
-    		$sql.= ', p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch';
1741
-    		$sql.= ', p.description as product_desc';
1742
-    		$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
1743
-    		$sql.= ", ".MAIN_DB_PREFIX."reception as e";
1744
-    		$sql.= ", ".MAIN_DB_PREFIX.$origin."det as obj";
1740
+    		$sql .= ', p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch';
1741
+    		$sql .= ', p.description as product_desc';
1742
+    		$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
1743
+    		$sql .= ", ".MAIN_DB_PREFIX."reception as e";
1744
+    		$sql .= ", ".MAIN_DB_PREFIX.$origin."det as obj";
1745 1745
     		//if ($conf->livraison_bon->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_reception = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."livraisondet as ld ON ld.fk_livraison = l.rowid  AND obj.rowid = ld.fk_origin_line";
1746
-    		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";
1747
-    		$sql.= " WHERE e.entity IN (".getEntity('reception').")";
1748
-    		$sql.= " AND obj.fk_commande = ".$origin_id;
1749
-    		$sql.= " AND obj.rowid = ed.fk_commandefourndet";
1750
-    		$sql.= " AND ed.fk_reception = e.rowid";
1751
-    		$sql.= " AND ed.fk_reception !=".$object->id;
1746
+    		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";
1747
+    		$sql .= " WHERE e.entity IN (".getEntity('reception').")";
1748
+    		$sql .= " AND obj.fk_commande = ".$origin_id;
1749
+    		$sql .= " AND obj.rowid = ed.fk_commandefourndet";
1750
+    		$sql .= " AND ed.fk_reception = e.rowid";
1751
+    		$sql .= " AND ed.fk_reception !=".$object->id;
1752 1752
     		//if ($filter) $sql.= $filter;
1753
-    		$sql.= " ORDER BY obj.fk_product";
1753
+    		$sql .= " ORDER BY obj.fk_product";
1754 1754
 
1755 1755
     		dol_syslog("get list of reception lines", LOG_DEBUG);
1756 1756
     		$resql = $db->query($sql);
@@ -1759,13 +1759,13 @@  discard block
 block discarded – undo
1759 1759
     		    $num = $db->num_rows($resql);
1760 1760
     		    $i = 0;
1761 1761
 
1762
-    		    while($i < $num)
1762
+    		    while ($i < $num)
1763 1763
     		    {
1764 1764
         		    $obj = $db->fetch_object($resql);
1765 1765
         		    if ($obj)
1766 1766
         		    {
1767 1767
         		        // $obj->rowid is rowid in $origin."det" table
1768
-        		        $alreadysent[$obj->rowid][$obj->receptionline_id]=array('reception_ref'=>$obj->reception_ref, 'reception_id'=>$obj->reception_id, 'warehouse'=>$obj->fk_entrepot, 'qty'=>$obj->qty, 'date_valid'=>$obj->date_valid, 'date_delivery'=>$obj->date_delivery);
1768
+        		        $alreadysent[$obj->rowid][$obj->receptionline_id] = array('reception_ref'=>$obj->reception_ref, 'reception_id'=>$obj->reception_id, 'warehouse'=>$obj->fk_entrepot, 'qty'=>$obj->qty, 'date_valid'=>$obj->date_valid, 'date_delivery'=>$obj->date_delivery);
1769 1769
         		    }
1770 1770
         		    $i++;
1771 1771
     		    }
@@ -1774,59 +1774,59 @@  discard block
 block discarded – undo
1774 1774
 		}
1775 1775
 
1776 1776
 		// Loop on each product to send/sent
1777
-		for ($i = 0 ; $i < $num_prod ; $i++)
1777
+		for ($i = 0; $i < $num_prod; $i++)
1778 1778
 		{
1779 1779
 		    print '<!-- origin line id = '.$lines[$i]->origin_line_id.' -->'; // id of order line
1780 1780
 			print '<tr class="oddeven">';
1781 1781
 
1782 1782
 			// #
1783
-			if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
1783
+			if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER))
1784 1784
 			{
1785
-				print '<td align="center">'.($i+1).'</td>';
1785
+				print '<td align="center">'.($i + 1).'</td>';
1786 1786
 			}
1787 1787
 
1788 1788
 			// Predefined product or service
1789 1789
 			if ($lines[$i]->fk_product > 0)
1790 1790
 			{
1791 1791
 				// Define output language
1792
-				if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
1792
+				if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
1793 1793
 				{
1794 1794
 					$prod = new Product($db);
1795 1795
 					$prod->fetch($lines[$i]->fk_product);
1796
-					$label = ( ! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product->label;
1796
+					$label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product->label;
1797 1797
 				}
1798 1798
 				else
1799
-					$label = (! empty($lines[$i]->product->label)?$lines[$i]->product->label:$lines[$i]->product->product_label);
1799
+					$label = (!empty($lines[$i]->product->label) ? $lines[$i]->product->label : $lines[$i]->product->product_label);
1800 1800
 
1801 1801
 				print '<td>';
1802 1802
 
1803 1803
 
1804 1804
 
1805
-				$text=$lines[$i]->product->getNomUrl(1);
1806
-				$text.= ' - '.$label;
1807
-				$description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($lines[$i]->product->description));
1808
-				print $form->textwithtooltip($text,$description,3,'','',$i);
1809
-				print_date_range($lines[$i]->date_start,$lines[$i]->date_end);
1810
-				if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
1805
+				$text = $lines[$i]->product->getNomUrl(1);
1806
+				$text .= ' - '.$label;
1807
+				$description = (!empty($conf->global->PRODUIT_DESC_IN_FORM) ? '' : dol_htmlentitiesbr($lines[$i]->product->description));
1808
+				print $form->textwithtooltip($text, $description, 3, '', '', $i);
1809
+				print_date_range($lines[$i]->date_start, $lines[$i]->date_end);
1810
+				if (!empty($conf->global->PRODUIT_DESC_IN_FORM))
1811 1811
 				{
1812
-					print (! empty($lines[$i]->product->description) && $lines[$i]->description!=$lines[$i]->product->description)?'<br>'.dol_htmlentitiesbr($lines[$i]->description):'';
1812
+					print (!empty($lines[$i]->product->description) && $lines[$i]->description != $lines[$i]->product->description) ? '<br>'.dol_htmlentitiesbr($lines[$i]->description) : '';
1813 1813
 				}
1814 1814
 				print "</td>\n";
1815 1815
 			}
1816 1816
 			else
1817 1817
 			{
1818 1818
 				print "<td>";
1819
-				if ($lines[$i]->product_type == Product::TYPE_SERVICE) $text = img_object($langs->trans('Service'),'service');
1820
-				else $text = img_object($langs->trans('Product'),'product');
1819
+				if ($lines[$i]->product_type == Product::TYPE_SERVICE) $text = img_object($langs->trans('Service'), 'service');
1820
+				else $text = img_object($langs->trans('Product'), 'product');
1821 1821
 
1822
-				if (! empty($lines[$i]->label)) {
1823
-					$text.= ' <strong>'.$lines[$i]->label.'</strong>';
1824
-					print $form->textwithtooltip($text,$lines[$i]->description,3,'','',$i);
1822
+				if (!empty($lines[$i]->label)) {
1823
+					$text .= ' <strong>'.$lines[$i]->label.'</strong>';
1824
+					print $form->textwithtooltip($text, $lines[$i]->description, 3, '', '', $i);
1825 1825
 				} else {
1826 1826
 					print $text.' '.nl2br($lines[$i]->description);
1827 1827
 				}
1828 1828
 
1829
-				print_date_range($lines[$i]->date_start,$lines[$i]->date_end);
1829
+				print_date_range($lines[$i]->date_start, $lines[$i]->date_end);
1830 1830
 				print "</td>\n";
1831 1831
 			}
1832 1832
 
@@ -1852,7 +1852,7 @@  discard block
 block discarded – undo
1852 1852
     			    if ($lines[$i]->fk_commandefourndet == $key)
1853 1853
     			    {
1854 1854
     			        $j = 0;
1855
-    			        foreach($val as $receptionline_id=> $receptionline_var)
1855
+    			        foreach ($val as $receptionline_id=> $receptionline_var)
1856 1856
     			        {
1857 1857
     			            if ($receptionline_var['reception_id'] == $lines[$i]->fk_reception) continue; // We want to show only "other receptions"
1858 1858
 
@@ -1862,8 +1862,8 @@  discard block
 block discarded – undo
1862 1862
     			            print $reception_static->getNomUrl(1);
1863 1863
     			            print ' - '.$receptionline_var['qty'];
1864 1864
 
1865
-    			            $htmltext=$langs->trans("DateValidation").' : '.(empty($receptionline_var['date_valid'])?$langs->trans("Draft"):dol_print_date($receptionline_var['date_valid'], 'dayhour'));
1866
-    			            if (! empty($conf->stock->enabled) && $receptionline_var['warehouse'] > 0)
1865
+    			            $htmltext = $langs->trans("DateValidation").' : '.(empty($receptionline_var['date_valid']) ? $langs->trans("Draft") : dol_print_date($receptionline_var['date_valid'], 'dayhour'));
1866
+    			            if (!empty($conf->stock->enabled) && $receptionline_var['warehouse'] > 0)
1867 1867
     			            {
1868 1868
     			                $warehousestatic->fetch($receptionline_var['warehouse']);
1869 1869
     			                $htmltext .= '<br>'.$langs->trans("From").' : '.$warehousestatic->getNomUrl(1);
@@ -1879,24 +1879,24 @@  discard block
 block discarded – undo
1879 1879
 			{
1880 1880
 				// edit mode
1881 1881
 				print '<td colspan="'.$editColspan.'" align="center"><table class="nobordernopadding">';
1882
-				if (! empty($conf->stock->enabled))
1882
+				if (!empty($conf->stock->enabled))
1883 1883
 				{
1884 1884
 					if ($lines[$i]->fk_product > 0)
1885 1885
 					{
1886 1886
 						print '<!-- case edit 1 -->';
1887 1887
 						print '<tr>';
1888 1888
 						// Qty to receive or received
1889
-						print '<td>' . '<input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty.'">' . '</td>';
1889
+						print '<td>'.'<input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty.'">'.'</td>';
1890 1890
 						// Warehouse source
1891
-						print '<td>' . $formproduct->selectWarehouses($lines[$i]->fk_entrepot, 'entl'.$line_id, '', 1, 0, $lines[$i]->fk_product, '', 1). '</td>';
1891
+						print '<td>'.$formproduct->selectWarehouses($lines[$i]->fk_entrepot, 'entl'.$line_id, '', 1, 0, $lines[$i]->fk_product, '', 1).'</td>';
1892 1892
 						// Batch number managment
1893 1893
 						if ($conf->productbatch->enabled && !empty($lines[$i]->product->status_batch))
1894 1894
 						{
1895 1895
 							print '<td>  <input name="batch'.$line_id.'" id="batch'.$line_id.'" type="text" value="'.$lines[$i]->batch.'"> </br>';
1896 1896
 							print $langs->trans('EatByDate').' : ';
1897
-							print $form->select_date($lines[$i]->eatby,'dlc' .$line_id, '', '', 1, ""). '</br>';
1897
+							print $form->select_date($lines[$i]->eatby, 'dlc'.$line_id, '', '', 1, "").'</br>';
1898 1898
 							print $langs->trans('SellByDate').' : ';
1899
-							print $form->select_date($lines[$i]->sellby,'dluo' .$line_id, '', '', 1, "");
1899
+							print $form->select_date($lines[$i]->sellby, 'dluo'.$line_id, '', '', 1, "");
1900 1900
 							print '</td>';
1901 1901
 						}
1902 1902
 						print '</tr>';
@@ -1906,11 +1906,11 @@  discard block
 block discarded – undo
1906 1906
 						print '<!-- case edit 2 -->';
1907 1907
 						print '<tr>';
1908 1908
 						// Qty to receive or received
1909
-						print '<td>' . '<input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty.'">' . '</td>';
1909
+						print '<td>'.'<input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty.'">'.'</td>';
1910 1910
 						// Warehouse source
1911
-						print '<td>' . '</td>';
1911
+						print '<td>'.'</td>';
1912 1912
 						// Batch number managment
1913
-						print '<td>' . '</td>';
1913
+						print '<td>'.'</td>';
1914 1914
 						print '</tr>';
1915 1915
 					}
1916 1916
 				}
@@ -1922,7 +1922,7 @@  discard block
 block discarded – undo
1922 1922
 				print '<td align="center">'.$lines[$i]->qty.'</td>';
1923 1923
 
1924 1924
 				// Warehouse source
1925
-				if (! empty($conf->stock->enabled))
1925
+				if (!empty($conf->stock->enabled))
1926 1926
 				{
1927 1927
 					print '<td align="left">';
1928 1928
 
@@ -1937,22 +1937,22 @@  discard block
 block discarded – undo
1937 1937
 				}
1938 1938
 
1939 1939
 				// Batch number managment
1940
-				if (! empty($conf->productbatch->enabled))
1940
+				if (!empty($conf->productbatch->enabled))
1941 1941
 				{
1942 1942
 					if (isset($lines[$i]->batch))
1943 1943
 					{
1944 1944
 						print '<!-- Detail of lot -->';
1945 1945
 						print '<td>';
1946
-						$detail ='';
1946
+						$detail = '';
1947 1947
 						if ($lines[$i]->product->status_batch)
1948 1948
 						{
1949
-								$detail.= $langs->trans("Batch").': '.$lines[$i]->batch;
1950
-								$detail.= ' - '.$langs->trans("SellByDate").': '.dol_print_date($lines[$i]->sellby,"day");
1951
-								$detail.= ' - '.$langs->trans("EatByDate").': '.dol_print_date($lines[$i]->eatby,"day");
1949
+								$detail .= $langs->trans("Batch").': '.$lines[$i]->batch;
1950
+								$detail .= ' - '.$langs->trans("SellByDate").': '.dol_print_date($lines[$i]->sellby, "day");
1951
+								$detail .= ' - '.$langs->trans("EatByDate").': '.dol_print_date($lines[$i]->eatby, "day");
1952 1952
 
1953
-								$detail.= '<br>';
1953
+								$detail .= '<br>';
1954 1954
 
1955
-							print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"),$detail);
1955
+							print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"), $detail);
1956 1956
 						}
1957 1957
 						else
1958 1958
 						{
@@ -1967,13 +1967,13 @@  discard block
 block discarded – undo
1967 1967
 
1968 1968
 			// Weight
1969 1969
 			print '<td align="center">';
1970
-			if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) print $lines[$i]->product->weight*$lines[$i]->qty.' '.measuring_units_string($lines[$i]->product->weight_units,"weight");
1970
+			if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) print $lines[$i]->product->weight * $lines[$i]->qty.' '.measuring_units_string($lines[$i]->product->weight_units, "weight");
1971 1971
 			else print '&nbsp;';
1972 1972
 			print '</td>';
1973 1973
 
1974 1974
 			// Volume
1975 1975
 			print '<td align="center">';
1976
-			if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) print $lines[$i]->product->volume*$lines[$i]->qty.' '.measuring_units_string($lines[$i]->product->volume_units,"volume");
1976
+			if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) print $lines[$i]->product->volume * $lines[$i]->qty.' '.measuring_units_string($lines[$i]->product->volume_units, "volume");
1977 1977
 			else print '&nbsp;';
1978 1978
 			print '</td>';
1979 1979
 
@@ -1981,21 +1981,21 @@  discard block
 block discarded – undo
1981 1981
 			if ($action == 'editline' && $lines[$i]->id == $line_id)
1982 1982
 			{
1983 1983
 				print '<td align="center" colspan="2" valign="middle">';
1984
-				print '<input type="submit" class="button" id="savelinebutton" name="save" value="' . $langs->trans("Save") . '"><br>';
1985
-				print '<input type="submit" class="button" id="cancellinebutton" name="cancel" value="' . $langs->trans("Cancel") . '"><br>';
1984
+				print '<input type="submit" class="button" id="savelinebutton" name="save" value="'.$langs->trans("Save").'"><br>';
1985
+				print '<input type="submit" class="button" id="cancellinebutton" name="cancel" value="'.$langs->trans("Cancel").'"><br>';
1986 1986
 			}
1987 1987
 			else if ($object->statut == 0)
1988 1988
 			{
1989 1989
 				// edit-delete buttons
1990 1990
 				print '<td class="linecoledit" align="center">';
1991
-				print '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=editline&amp;lineid=' . $lines[$i]->id . '">' . img_edit() . '</a>';
1991
+				print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=editline&amp;lineid='.$lines[$i]->id.'">'.img_edit().'</a>';
1992 1992
 				print '</td>';
1993 1993
 				print '<td class="linecoldelete" width="10">';
1994
-				print '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=deleteline&amp;lineid=' . $lines[$i]->id . '">' . img_delete() . '</a>';
1994
+				print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=deleteline&amp;lineid='.$lines[$i]->id.'">'.img_delete().'</a>';
1995 1995
 				print '</td>';
1996 1996
 
1997 1997
 				// Display lines extrafields
1998
-				if (! empty($rowExtrafieldsStart))
1998
+				if (!empty($rowExtrafieldsStart))
1999 1999
 				{
2000 2000
 					print $rowExtrafieldsStart;
2001 2001
 					print $rowExtrafieldsView;
@@ -2005,18 +2005,18 @@  discard block
 block discarded – undo
2005 2005
 			print "</tr>";
2006 2006
 
2007 2007
 			// Display lines extrafields
2008
-			if (is_array($extralabelslines) && count($extralabelslines)>0) {
2009
-				$colspan= empty($conf->productbatch->enabled) ? 8 : 9;
2008
+			if (is_array($extralabelslines) && count($extralabelslines) > 0) {
2009
+				$colspan = empty($conf->productbatch->enabled) ? 8 : 9;
2010 2010
 				$line = new CommandeFournisseurDispatch($db);
2011
-				$line->fetch_optionals($lines[$i]->id,$extralabelslines);
2011
+				$line->fetch_optionals($lines[$i]->id, $extralabelslines);
2012 2012
 				print '<tr class="oddeven">';
2013 2013
 				if ($action == 'editline' && $lines[$i]->id == $line_id)
2014 2014
 				{
2015
-					print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked);
2015
+					print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>$colspan), $indiceAsked);
2016 2016
 				}
2017 2017
 				else
2018 2018
 				{
2019
-					print $line->showOptionals($extrafieldsline, 'view', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked);
2019
+					print $line->showOptionals($extrafieldsline, 'view', array('style'=>$bc[$var], 'colspan'=>$colspan), $indiceAsked);
2020 2020
 				}
2021 2021
 				print '</tr>';
2022 2022
 			}
@@ -2032,14 +2032,14 @@  discard block
 block discarded – undo
2032 2032
 	dol_fiche_end();
2033 2033
 
2034 2034
 
2035
-	$object->fetchObjectLinked($object->id,$object->element);
2035
+	$object->fetchObjectLinked($object->id, $object->element);
2036 2036
 
2037 2037
 
2038 2038
 	/*
2039 2039
 	 *    Boutons actions
2040 2040
 	 */
2041 2041
 
2042
-	if (($user->societe_id == 0) && ($action!='presend'))
2042
+	if (($user->societe_id == 0) && ($action != 'presend'))
2043 2043
 	{
2044 2044
 		print '<div class="tabsAction">';
2045 2045
 
@@ -2050,8 +2050,8 @@  discard block
 block discarded – undo
2050 2050
 
2051 2051
 			if ($object->statut == Reception::STATUS_DRAFT && $num_prod > 0)
2052 2052
 			{
2053
-				if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->creer))
2054
-	  		     || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->reception->reception_advance->validate)))
2053
+				if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
2054
+	  		     || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))
2055 2055
 				{
2056 2056
 					print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valid">'.$langs->trans("Validate").'</a>';
2057 2057
 				}
@@ -2062,14 +2062,14 @@  discard block
 block discarded – undo
2062 2062
 			}
2063 2063
 			// Edit
2064 2064
 			if ($object->statut == Reception::STATUS_VALIDATED && $user->rights->reception->creer) {
2065
-				print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id=' . $object->id . '&amp;action=modif">' . $langs->trans('Modify') . '</a></div>';
2065
+				print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&amp;action=modif">'.$langs->trans('Modify').'</a></div>';
2066 2066
 			}
2067 2067
 
2068 2068
 			// TODO add alternative status
2069 2069
 			// 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order)
2070 2070
 			if ($object->statut == Reception::STATUS_CLOSED && $user->rights->reception->creer)
2071 2071
 			{
2072
-				if (! empty($conf->facture->enabled) && ! empty($conf->global->WORKFLOW_BILL_ON_RECEPTION))  // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
2072
+				if (!empty($conf->facture->enabled) && !empty($conf->global->WORKFLOW_BILL_ON_RECEPTION))  // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
2073 2073
 				{
2074 2074
 					print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ClassifyUnbilled").'</a>';
2075 2075
 				}
@@ -2090,7 +2090,7 @@  discard block
 block discarded – undo
2090 2090
 			}
2091 2091
 
2092 2092
 			// Create bill
2093
-			if (! empty($conf->fournisseur->enabled) && ($object->statut == Reception::STATUS_VALIDATED || $object->statut == Reception::STATUS_CLOSED))
2093
+			if (!empty($conf->fournisseur->enabled) && ($object->statut == Reception::STATUS_VALIDATED || $object->statut == Reception::STATUS_CLOSED))
2094 2094
 			{
2095 2095
 				if ($user->rights->fournisseur->facture->creer)
2096 2096
 				{
@@ -2104,14 +2104,14 @@  discard block
 block discarded – undo
2104 2104
 			// Close
2105 2105
 			if ($object->statut == Reception::STATUS_VALIDATED)
2106 2106
 			{
2107
-				if ($user->rights->reception->creer && $object->statut > 0 && ! $object->billed)
2107
+				if ($user->rights->reception->creer && $object->statut > 0 && !$object->billed)
2108 2108
 				{
2109
-					$label="Close"; $paramaction='classifyclosed';       // = Transferred/Received
2109
+					$label = "Close"; $paramaction = 'classifyclosed'; // = Transferred/Received
2110 2110
 					// Label here should be "Close" or "ClassifyBilled" if we decided to make bill on receptions instead of orders
2111
-					if (! empty($conf->fournisseur->enabled) && ! empty($conf->global->WORKFLOW_BILL_ON_RECEPTION))  // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
2111
+					if (!empty($conf->fournisseur->enabled) && !empty($conf->global->WORKFLOW_BILL_ON_RECEPTION))  // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
2112 2112
 					{
2113
-					    $label="ClassifyBilled";
2114
-					    $paramaction='classifybilled';
2113
+					    $label = "ClassifyBilled";
2114
+					    $paramaction = 'classifybilled';
2115 2115
 					}
2116 2116
 					print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action='.$paramaction.'">'.$langs->trans($label).'</a>';
2117 2117
 				}
@@ -2136,14 +2136,14 @@  discard block
 block discarded – undo
2136 2136
         print '<div class="fichecenter"><div class="fichehalfleft">';
2137 2137
 
2138 2138
         $objectref = dol_sanitizeFileName($object->ref);
2139
-		$filedir = $conf->reception->dir_output . "/" .$objectref;
2139
+		$filedir = $conf->reception->dir_output."/".$objectref;
2140 2140
 
2141 2141
 		$urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
2142 2142
 
2143
-		$genallowed=$user->rights->reception->lire;
2144
-		$delallowed=$user->rights->reception->creer;
2143
+		$genallowed = $user->rights->reception->lire;
2144
+		$delallowed = $user->rights->reception->creer;
2145 2145
 
2146
-		print $formfile->showdocuments('reception',$objectref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang);
2146
+		print $formfile->showdocuments('reception', $objectref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
2147 2147
 
2148 2148
 		// Show links to link elements
2149 2149
 		//$linktoelem = $form->showLinkToObjectBlock($object, null, array('order'));
@@ -2156,12 +2156,12 @@  discard block
 block discarded – undo
2156 2156
 	{
2157 2157
 		$ref = dol_sanitizeFileName($object->ref);
2158 2158
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
2159
-		$fileparams = dol_most_recent_file($conf->reception->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
2160
-		$file=$fileparams['fullname'];
2159
+		$fileparams = dol_most_recent_file($conf->reception->dir_output.'/'.$ref, preg_quote($ref, '/').'[^\-]+');
2160
+		$file = $fileparams['fullname'];
2161 2161
 		// Define output language
2162 2162
 		$outputlangs = $langs;
2163 2163
 		$newlang = '';
2164
-		if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
2164
+		if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id']))
2165 2165
 			$newlang = $_REQUEST['lang_id'];
2166 2166
 		if ($conf->global->MAIN_MULTILANGS && empty($newlang))
2167 2167
 			$newlang = $object->thirdparty->default_lang;
@@ -2172,16 +2172,16 @@  discard block
 block discarded – undo
2172 2172
 			$outputlangs->load('receptions');
2173 2173
 		}
2174 2174
 		// Build document if it not exists
2175
-		if (! $file || ! is_readable($file))
2175
+		if (!$file || !is_readable($file))
2176 2176
 		{
2177
-			$result = $object->generateDocument(GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2177
+			$result = $object->generateDocument(GETPOST('model') ?GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2178 2178
 			if ($result <= 0)
2179 2179
 			{
2180
-				dol_print_error($db,$object->error,$object->errors);
2180
+				dol_print_error($db, $object->error, $object->errors);
2181 2181
 				exit;
2182 2182
 			}
2183
-			$fileparams = dol_most_recent_file($conf->reception->dir_output . '/reception/' . $ref, preg_quote($ref, '/').'[^\-]+');
2184
-			$file=$fileparams['fullname'];
2183
+			$fileparams = dol_most_recent_file($conf->reception->dir_output.'/reception/'.$ref, preg_quote($ref, '/').'[^\-]+');
2184
+			$file = $fileparams['fullname'];
2185 2185
 		}
2186 2186
 		print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
2187 2187
 		print '<div class="clearboth"></div>';
@@ -2191,72 +2191,72 @@  discard block
 block discarded – undo
2191 2191
 		// Cree l'objet formulaire mail
2192 2192
 		include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
2193 2193
 		$formmail = new FormMail($db);
2194
-		$formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
2195
-        $formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
2196
-        if($formmail->fromtype === 'user'){
2194
+		$formmail->param['langsmodels'] = (empty($newlang) ? $langs->defaultlang : $newlang);
2195
+        $formmail->fromtype = (GETPOST('fromtype') ?GETPOST('fromtype') : (!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE) ? $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE : 'user'));
2196
+        if ($formmail->fromtype === 'user') {
2197 2197
             $formmail->fromid = $user->id;
2198 2198
         }
2199
-		$formmail->trackid='shi'.$object->id;
2200
-		if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2))	// If bit 2 is set
2199
+		$formmail->trackid = 'shi'.$object->id;
2200
+		if (!empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2))	// If bit 2 is set
2201 2201
 		{
2202 2202
 			include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2203
-			$formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'shi'.$object->id);
2203
+			$formmail->frommail = dolAddEmailTrackId($formmail->frommail, 'shi'.$object->id);
2204 2204
 		}
2205
-		$formmail->withfrom=1;
2206
-		$liste=array();
2207
-		foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value)	$liste[$key]=$value;
2208
-		$formmail->withto=GETPOST("sendto")?GETPOST("sendto"):$liste;
2209
-		$formmail->withtocc=$liste;
2210
-		$formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
2211
-		$formmail->withtopic=$outputlangs->trans('SendReceptionRef','__RECEPTIONREF__');
2212
-		$formmail->withfile=2;
2213
-		$formmail->withbody=1;
2214
-		$formmail->withdeliveryreceipt=1;
2215
-		$formmail->withcancel=1;
2205
+		$formmail->withfrom = 1;
2206
+		$liste = array();
2207
+		foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value)	$liste[$key] = $value;
2208
+		$formmail->withto = GETPOST("sendto") ?GETPOST("sendto") : $liste;
2209
+		$formmail->withtocc = $liste;
2210
+		$formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
2211
+		$formmail->withtopic = $outputlangs->trans('SendReceptionRef', '__RECEPTIONREF__');
2212
+		$formmail->withfile = 2;
2213
+		$formmail->withbody = 1;
2214
+		$formmail->withdeliveryreceipt = 1;
2215
+		$formmail->withcancel = 1;
2216 2216
 		// Tableau des substitutions
2217
-		$formmail->setSubstitFromObject($object,$langs);
2218
-		$formmail->substit['__RECEPTIONREF__']=$object->ref;
2219
-		$formmail->substit['__RECEPTIONTRACKNUM__']=$object->tracking_number;
2220
-		$formmail->substit['__RECEPTIONTRACKNUMURL__']=$object->tracking_url;
2217
+		$formmail->setSubstitFromObject($object, $langs);
2218
+		$formmail->substit['__RECEPTIONREF__'] = $object->ref;
2219
+		$formmail->substit['__RECEPTIONTRACKNUM__'] = $object->tracking_number;
2220
+		$formmail->substit['__RECEPTIONTRACKNUMURL__'] = $object->tracking_url;
2221 2221
 		//Find the good contact adress
2222
-		if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))	{
2223
-			$objectsrc=new Commande($db);
2222
+		if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled)) {
2223
+			$objectsrc = new Commande($db);
2224 2224
 			$objectsrc->fetch($object->$typeobject->id);
2225 2225
 		}
2226
-		if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))	{
2227
-			$objectsrc=new Propal($db);
2226
+		if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) {
2227
+			$objectsrc = new Propal($db);
2228 2228
 			$objectsrc->fetch($object->$typeobject->id);
2229 2229
 		}
2230
-		$custcontact='';
2231
-		$contactarr=array();
2230
+		$custcontact = '';
2231
+		$contactarr = array();
2232 2232
 		if (is_object($objectsrc))    // For the case the reception was created without orders
2233 2233
 		{
2234
-    		$contactarr=$objectsrc->liste_contact(-1,'external');
2234
+    		$contactarr = $objectsrc->liste_contact(-1, 'external');
2235 2235
 		}
2236
-		if (is_array($contactarr) && count($contactarr)>0) {
2237
-			foreach($contactarr as $contact) {
2238
-				if ($contact['libelle']==$langs->trans('TypeContact_commande_external_CUSTOMER')) {
2239
-					require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
2240
-					$contactstatic=new Contact($db);
2236
+		if (is_array($contactarr) && count($contactarr) > 0) {
2237
+			foreach ($contactarr as $contact) {
2238
+				if ($contact['libelle'] == $langs->trans('TypeContact_commande_external_CUSTOMER')) {
2239
+					require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
2240
+					$contactstatic = new Contact($db);
2241 2241
 					$contactstatic->fetch($contact['id']);
2242
-					$custcontact=$contactstatic->getFullName($langs,1);
2242
+					$custcontact = $contactstatic->getFullName($langs, 1);
2243 2243
 				}
2244 2244
 			}
2245 2245
 			if (!empty($custcontact)) {
2246
-				$formmail->substit['__CONTACTCIVNAME__']=$custcontact;
2246
+				$formmail->substit['__CONTACTCIVNAME__'] = $custcontact;
2247 2247
 			}
2248 2248
 		}
2249 2249
 		// Tableau des parametres complementaires
2250
-		$formmail->param['action']='send';
2251
-		$formmail->param['models']='reception_send';
2252
-		$formmail->param['models_id']=GETPOST('modelmailselected','int');
2253
-		$formmail->param['receptionid']=$object->id;
2254
-		$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
2250
+		$formmail->param['action'] = 'send';
2251
+		$formmail->param['models'] = 'reception_send';
2252
+		$formmail->param['models_id'] = GETPOST('modelmailselected', 'int');
2253
+		$formmail->param['receptionid'] = $object->id;
2254
+		$formmail->param['returnurl'] = $_SERVER["PHP_SELF"].'?id='.$object->id;
2255 2255
 		// Init list of files
2256
-		if (GETPOST("mode")=='init')
2256
+		if (GETPOST("mode") == 'init')
2257 2257
 		{
2258 2258
 			$formmail->clear_attached_files();
2259
-			$formmail->add_attached_files($file,basename($file),dol_mimetype($file));
2259
+			$formmail->add_attached_files($file, basename($file), dol_mimetype($file));
2260 2260
 		}
2261 2261
 		// Show form
2262 2262
 		print $formmail->get_form();
Please login to merge, or discard this patch.
dolibarr/htdocs/reception/tpl/linkedobjectblock.tpl.php 3 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -43,20 +43,20 @@
 block discarded – undo
43 43
         <td></td>
44 44
     	<td align="center"><?php echo dol_print_date($objectlink->date_delivery,'day'); ?></td>
45 45
     	<td align="right"><?php
46
-    		if ($user->rights->reception->lire) {
47
-    			$total = $total + $objectlink->total_ht;
48
-    			echo price($objectlink->total_ht);
49
-    		} ?></td>
46
+            if ($user->rights->reception->lire) {
47
+                $total = $total + $objectlink->total_ht;
48
+                echo price($objectlink->total_ht);
49
+            } ?></td>
50 50
     	<td align="right"><?php echo $objectlink->getLibStatut(3); ?></td>
51 51
     	<td align="right">
52 52
     		<?php
53
-    		// For now, receptions must stay linked to order, so link is not deletable
54
-    		if($object->element != 'order_supplier') {
55
-    			?>
53
+            // For now, receptions must stay linked to order, so link is not deletable
54
+            if($object->element != 'order_supplier') {
55
+                ?>
56 56
     			<a href="<?php echo $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=dellink&dellinkid='.$key; ?>"><?php echo img_picto($langs->transnoentitiesnoconv("RemoveLink"), 'unlink'); ?></a></td>
57 57
     			<?php
58
-    		}
59
-    		?>
58
+            }
59
+            ?>
60 60
     </tr>
61 61
 <?php
62 62
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -28,20 +28,20 @@  discard block
 block discarded – undo
28 28
 
29 29
 $langs->load("receptions");
30 30
 
31
-$total=0; $ilink=0;
32
-$var=true;
33
-foreach($linkedObjectBlock as $key => $objectlink)
31
+$total = 0; $ilink = 0;
32
+$var = true;
33
+foreach ($linkedObjectBlock as $key => $objectlink)
34 34
 {
35 35
     $ilink++;
36 36
 
37
-    $trclass=($var?'pair':'impair');
38
-    if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) $trclass.=' liste_sub_total';
37
+    $trclass = ($var ? 'pair' : 'impair');
38
+    if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) $trclass .= ' liste_sub_total';
39 39
 ?>
40 40
     <tr class="<?php echo $trclass; ?>">
41 41
         <td><?php echo $langs->trans("Reception"); ?></td>
42 42
         <td><?php echo $objectlink->getNomUrl(1); ?></td>
43 43
         <td></td>
44
-    	<td align="center"><?php echo dol_print_date($objectlink->date_delivery,'day'); ?></td>
44
+    	<td align="center"><?php echo dol_print_date($objectlink->date_delivery, 'day'); ?></td>
45 45
     	<td align="right"><?php
46 46
     		if ($user->rights->reception->lire) {
47 47
     			$total = $total + $objectlink->total_ht;
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
     	<td align="right">
52 52
     		<?php
53 53
     		// For now, receptions must stay linked to order, so link is not deletable
54
-    		if($object->element != 'order_supplier') {
54
+    		if ($object->element != 'order_supplier') {
55 55
     			?>
56 56
     			<a href="<?php echo $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=dellink&dellinkid='.$key; ?>"><?php echo img_picto($langs->transnoentitiesnoconv("RemoveLink"), 'unlink'); ?></a></td>
57 57
     			<?php
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 if (count($linkedObjectBlock) > 1)
64 64
 {
65 65
     ?>
66
-    <tr class="liste_total <?php echo (empty($noMoreLinkedObjectBlockAfter)?'liste_sub_total':''); ?>">
66
+    <tr class="liste_total <?php echo (empty($noMoreLinkedObjectBlockAfter) ? 'liste_sub_total' : ''); ?>">
67 67
         <td><?php echo $langs->trans("Total"); ?></td>
68 68
         <td></td>
69 69
     	<td align="center"></td>
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,8 +35,10 @@
 block discarded – undo
35 35
     $ilink++;
36 36
 
37 37
     $trclass=($var?'pair':'impair');
38
-    if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) $trclass.=' liste_sub_total';
39
-?>
38
+    if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) {
39
+        $trclass.=' liste_sub_total';
40
+    }
41
+    ?>
40 42
     <tr class="<?php echo $trclass; ?>">
41 43
         <td><?php echo $langs->trans("Reception"); ?></td>
42 44
         <td><?php echo $objectlink->getNomUrl(1); ?></td>
Please login to merge, or discard this patch.
dolibarr/htdocs/reception/note.php 3 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -98,19 +98,19 @@  discard block
 block discarded – undo
98 98
 if ($id > 0 || ! empty($ref))
99 99
 {
100 100
 
101
-	$head=reception_prepare_head($object);
102
-	dol_fiche_head($head, 'note', $langs->trans("Reception"), -1, 'sending');
101
+    $head=reception_prepare_head($object);
102
+    dol_fiche_head($head, 'note', $langs->trans("Reception"), -1, 'sending');
103 103
 
104 104
 
105
-	// Reception card
106
-	$linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php">'.$langs->trans("BackToList").'</a>';
105
+    // Reception card
106
+    $linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php">'.$langs->trans("BackToList").'</a>';
107 107
 
108
-	$morehtmlref='<div class="refidno">';
109
-	// Ref customer reception
110
-	$morehtmlref.=$form->editfieldkey("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1);
111
-	$morehtmlref.=$form->editfieldval("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1);
112
-	// Thirdparty
113
-	$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
108
+    $morehtmlref='<div class="refidno">';
109
+    // Ref customer reception
110
+    $morehtmlref.=$form->editfieldkey("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1);
111
+    $morehtmlref.=$form->editfieldval("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1);
112
+    // Thirdparty
113
+    $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
114 114
     // Project
115 115
     if (! empty($conf->projet->enabled)) {
116 116
         $langs->load("projects");
@@ -153,10 +153,10 @@  discard block
 block discarded – undo
153 153
 
154 154
     print '<div class="underbanner clearboth"></div>';
155 155
 
156
-	$cssclass='titlefield';
157
-	include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
156
+    $cssclass='titlefield';
157
+    include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
158 158
 
159
-	dol_fiche_end();
159
+    dol_fiche_end();
160 160
 }
161 161
 
162 162
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,9 @@
 block discarded – undo
48 48
 
49 49
 // Security check
50 50
 $socid='';
51
-if ($user->societe_id) $socid=$user->societe_id;
51
+if ($user->societe_id) {
52
+    $socid=$user->societe_id;
53
+}
52 54
 $result=restrictedArea($user, $origin, $origin_id);
53 55
 
54 56
 $object = new Reception($db);
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -27,12 +27,12 @@  discard block
 block discarded – undo
27 27
 
28 28
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
29 29
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
30
-require DOL_BASE_PATH . '/main.inc.php';
30
+require DOL_BASE_PATH.'/main.inc.php';
31 31
 
32 32
 require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
33 33
 require_once DOL_DOCUMENT_ROOT.'/core/lib/reception.lib.php';
34 34
 dol_include_once('/fourn/class/fournisseur.commande.class.php');
35
-if (! empty($conf->projet->enabled)) {
35
+if (!empty($conf->projet->enabled)) {
36 36
     require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
37 37
     require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
38 38
 }
@@ -46,17 +46,17 @@  discard block
 block discarded – undo
46 46
 $langs->load('other');
47 47
 $langs->load('propal');
48 48
 
49
-$id=(GETPOST('id','int')?GETPOST('id','int'):GETPOST('facid','int'));  // For backward compatibility
50
-$ref=GETPOST('ref','alpha');
51
-$action=GETPOST('action','alpha');
49
+$id = (GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
50
+$ref = GETPOST('ref', 'alpha');
51
+$action = GETPOST('action', 'alpha');
52 52
 
53 53
 // Security check
54
-$socid='';
55
-if ($user->societe_id) $socid=$user->societe_id;
56
-$result=restrictedArea($user, $origin, $origin_id);
54
+$socid = '';
55
+if ($user->societe_id) $socid = $user->societe_id;
56
+$result = restrictedArea($user, $origin, $origin_id);
57 57
 
58 58
 $object = new Reception($db);
59
-if ($id > 0 || ! empty($ref))
59
+if ($id > 0 || !empty($ref))
60 60
 {
61 61
     $object->fetch($id, $ref);
62 62
     $object->fetch_thirdparty();
@@ -69,79 +69,79 @@  discard block
 block discarded – undo
69 69
     }
70 70
 
71 71
     // Linked documents
72
-    if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
72
+    if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled))
73 73
     {
74
-        $objectsrc=new Commande($db);
74
+        $objectsrc = new Commande($db);
75 75
         $objectsrc->fetch($object->$typeobject->id);
76 76
     }
77
-    if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
77
+    if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled))
78 78
     {
79
-        $objectsrc=new Propal($db);
79
+        $objectsrc = new Propal($db);
80 80
         $objectsrc->fetch($object->$typeobject->id);
81 81
     }
82 82
 }
83 83
 
84
-$permissionnote=$user->rights->reception->creer;	// Used by the include of actions_setnotes.inc.php
84
+$permissionnote = $user->rights->reception->creer; // Used by the include of actions_setnotes.inc.php
85 85
 
86 86
 
87 87
 /*
88 88
  * Actions
89 89
  */
90 90
 
91
-include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php';	// Must be include, not includ_once
91
+include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
92 92
 
93 93
 
94 94
 /*
95 95
  * View
96 96
  */
97 97
 
98
-llxHeader('','Reception');
98
+llxHeader('', 'Reception');
99 99
 
100 100
 $form = new Form($db);
101 101
 
102
-if ($id > 0 || ! empty($ref))
102
+if ($id > 0 || !empty($ref))
103 103
 {
104 104
 
105
-	$head=reception_prepare_head($object);
105
+	$head = reception_prepare_head($object);
106 106
 	dol_fiche_head($head, 'note', $langs->trans("Reception"), -1, 'sending');
107 107
 
108 108
 
109 109
 	// Reception card
110 110
 	$linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php">'.$langs->trans("BackToList").'</a>';
111 111
 
112
-	$morehtmlref='<div class="refidno">';
112
+	$morehtmlref = '<div class="refidno">';
113 113
 	// Ref customer reception
114
-	$morehtmlref.=$form->editfieldkey("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1);
115
-	$morehtmlref.=$form->editfieldval("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1);
114
+	$morehtmlref .= $form->editfieldkey("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1);
115
+	$morehtmlref .= $form->editfieldval("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1);
116 116
 	// Thirdparty
117
-	$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
117
+	$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
118 118
     // Project
119
-    if (! empty($conf->projet->enabled)) {
119
+    if (!empty($conf->projet->enabled)) {
120 120
         $langs->load("projects");
121
-        $morehtmlref .= '<br>' . $langs->trans('Project') . ' ';
121
+        $morehtmlref .= '<br>'.$langs->trans('Project').' ';
122 122
         if (0) {    // Do not change on reception
123 123
             if ($action != 'classify') {
124
-                $morehtmlref .= '<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
124
+                $morehtmlref .= '<a href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
125 125
             }
126 126
             if ($action == 'classify') {
127 127
                 // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
128
-                $morehtmlref .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
128
+                $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
129 129
                 $morehtmlref .= '<input type="hidden" name="action" value="classin">';
130
-                $morehtmlref .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
130
+                $morehtmlref .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
131 131
                 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
132
-                $morehtmlref .= '<input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
132
+                $morehtmlref .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
133 133
                 $morehtmlref .= '</form>';
134 134
             } else {
135
-                $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
135
+                $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
136 136
             }
137 137
         } else {
138 138
             // We don't have project on reception, so we will use the project or source object instead
139 139
             // TODO Add project on reception
140 140
             $morehtmlref .= ' : ';
141
-            if (! empty($objectsrc->fk_project)) {
141
+            if (!empty($objectsrc->fk_project)) {
142 142
                 $proj = new Project($db);
143 143
                 $proj->fetch($objectsrc->fk_project);
144
-                $morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $objectsrc->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
144
+                $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objectsrc->fk_project.'" title="'.$langs->trans('ShowProject').'">';
145 145
                 $morehtmlref .= $proj->ref;
146 146
                 $morehtmlref .= '</a>';
147 147
             } else {
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
             }
150 150
         }
151 151
     }
152
-    $morehtmlref.='</div>';
152
+    $morehtmlref .= '</div>';
153 153
 
154 154
     $object->picto = 'sending';
155 155
     dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 
158 158
     print '<div class="underbanner clearboth"></div>';
159 159
 
160
-	$cssclass='titlefield';
160
+	$cssclass = 'titlefield';
161 161
 	include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
162 162
 
163 163
 	dol_fiche_end();
Please login to merge, or discard this patch.
dolibarr/htdocs/reception/index.php 3 patches
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
74 74
 if (!$user->rights->societe->client->voir && !$socid)
75 75
 {
76
-	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
77
-	$sql.= $clause." sc.fk_user = " .$user->id;
78
-	$clause = " AND ";
76
+    $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
77
+    $sql.= $clause." sc.fk_user = " .$user->id;
78
+    $clause = " AND ";
79 79
 }
80 80
 $sql.= $clause." e.fk_statut = 0";
81 81
 $sql.= " AND e.entity IN (".getEntity('reception').")";
@@ -84,34 +84,34 @@  discard block
 block discarded – undo
84 84
 $resql=$db->query($sql);
85 85
 if ($resql)
86 86
 {
87
-	$num = $db->num_rows($resql);
88
-	if ($num)
89
-	{
90
-		print '<table class="noborder" width="100%">';
91
-		print '<tr class="liste_titre">';
92
-		print '<th colspan="3">'.$langs->trans("ReceptionsToValidate").'</th></tr>';
93
-		$i = 0;
94
-		while ($i < $num)
95
-		{
96
-			$obj = $db->fetch_object($resql);
97
-
98
-			$reception->id=$obj->rowid;
99
-			$reception->ref=$obj->ref;
100
-			$reception->ref_supplier=$obj->ref_supplier;
101
-
102
-			print '<tr class="oddeven"><td class="nowrap">';
103
-			print $reception->getNomUrl(1);
104
-			print "</td>";
105
-			print '<td>';
106
-			print '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.$obj->name.'</a>';
107
-			print '</td>';
108
-			print '<td>';
109
-			if ($obj->commande_fournisseur_id) print '<a href="'.DOL_URL_ROOT.'/commande_fournisseur/card.php?id='.$obj->commande_fournisseur_id.'">'.$obj->commande_fournisseur_ref.'</a>';
110
-			print '</td></tr>';
111
-			$i++;
112
-		}
113
-		print "</table><br>";
114
-	}
87
+    $num = $db->num_rows($resql);
88
+    if ($num)
89
+    {
90
+        print '<table class="noborder" width="100%">';
91
+        print '<tr class="liste_titre">';
92
+        print '<th colspan="3">'.$langs->trans("ReceptionsToValidate").'</th></tr>';
93
+        $i = 0;
94
+        while ($i < $num)
95
+        {
96
+            $obj = $db->fetch_object($resql);
97
+
98
+            $reception->id=$obj->rowid;
99
+            $reception->ref=$obj->ref;
100
+            $reception->ref_supplier=$obj->ref_supplier;
101
+
102
+            print '<tr class="oddeven"><td class="nowrap">';
103
+            print $reception->getNomUrl(1);
104
+            print "</td>";
105
+            print '<td>';
106
+            print '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.$obj->name.'</a>';
107
+            print '</td>';
108
+            print '<td>';
109
+            if ($obj->commande_fournisseur_id) print '<a href="'.DOL_URL_ROOT.'/commande_fournisseur/card.php?id='.$obj->commande_fournisseur_id.'">'.$obj->commande_fournisseur_ref.'</a>';
110
+            print '</td></tr>';
111
+            $i++;
112
+        }
113
+        print "</table><br>";
114
+    }
115 115
 }
116 116
 
117 117
 
@@ -131,43 +131,43 @@  discard block
 block discarded – undo
131 131
 $resql=$db->query($sql);
132 132
 if ($resql)
133 133
 {
134
-	$num = $db->num_rows($resql);
135
-	if ($num)
136
-	{
137
-		$langs->load("orders");
138
-
139
-		$i = 0;
140
-		print '<table class="noborder" width="100%">';
141
-		print '<tr class="liste_titre">';
142
-		print '<th colspan="3">'.$langs->trans("SuppliersOrdersToProcess").'</th></tr>';
143
-		while ($i < $num)
144
-		{
145
-			$obj = $db->fetch_object($resql);
146
-
147
-			$orderstatic->id=$obj->rowid;
148
-			$orderstatic->ref=$obj->ref;
149
-			$orderstatic->ref_supplier=$obj->ref_supplier;
150
-			$orderstatic->statut=$obj->fk_statut;
151
-			$orderstatic->facturee=0;
152
-
153
-			$companystatic->name=$obj->name;
154
-			$companystatic->id=$obj->socid;
155
-
156
-			print '<tr class="oddeven">';
157
-			print '<td class="nowrap">';
158
-			print $orderstatic->getNomUrl(1);
159
-			print '</td>';
160
-			print '<td>';
161
-			print $companystatic->getNomUrl(1,'customer',32);
162
-			print '</td>';
163
-			print '<td align="right">';
164
-			print $orderstatic->getLibStatut(3);
165
-			print '</td>';
166
-			print '</tr>';
167
-			$i++;
168
-		}
169
-		print "</table><br>";
170
-	}
134
+    $num = $db->num_rows($resql);
135
+    if ($num)
136
+    {
137
+        $langs->load("orders");
138
+
139
+        $i = 0;
140
+        print '<table class="noborder" width="100%">';
141
+        print '<tr class="liste_titre">';
142
+        print '<th colspan="3">'.$langs->trans("SuppliersOrdersToProcess").'</th></tr>';
143
+        while ($i < $num)
144
+        {
145
+            $obj = $db->fetch_object($resql);
146
+
147
+            $orderstatic->id=$obj->rowid;
148
+            $orderstatic->ref=$obj->ref;
149
+            $orderstatic->ref_supplier=$obj->ref_supplier;
150
+            $orderstatic->statut=$obj->fk_statut;
151
+            $orderstatic->facturee=0;
152
+
153
+            $companystatic->name=$obj->name;
154
+            $companystatic->id=$obj->socid;
155
+
156
+            print '<tr class="oddeven">';
157
+            print '<td class="nowrap">';
158
+            print $orderstatic->getNomUrl(1);
159
+            print '</td>';
160
+            print '<td>';
161
+            print $companystatic->getNomUrl(1,'customer',32);
162
+            print '</td>';
163
+            print '<td align="right">';
164
+            print $orderstatic->getLibStatut(3);
165
+            print '</td>';
166
+            print '</tr>';
167
+            $i++;
168
+        }
169
+        print "</table><br>";
170
+    }
171 171
 }
172 172
 
173 173
 
@@ -191,42 +191,42 @@  discard block
 block discarded – undo
191 191
 $resql = $db->query($sql);
192 192
 if ( $resql )
193 193
 {
194
-	$langs->load("orders");
195
-
196
-	$num = $db->num_rows($resql);
197
-	if ($num)
198
-	{
199
-		$i = 0;
200
-		print '<table class="noborder" width="100%">';
201
-		print '<tr class="liste_titre">';
202
-		print '<th colspan="3">'.$langs->trans("SuppliersOrdersInProcess").'</th></tr>';
203
-		while ($i < $num)
204
-		{
205
-			$obj = $db->fetch_object($resql);
206
-
207
-		    $orderstatic->id=$obj->rowid;
208
-			$orderstatic->ref=$obj->ref;
209
-			$orderstatic->ref_supplier=$obj->ref_supplier;
210
-			$orderstatic->statut=$obj->status;
194
+    $langs->load("orders");
195
+
196
+    $num = $db->num_rows($resql);
197
+    if ($num)
198
+    {
199
+        $i = 0;
200
+        print '<table class="noborder" width="100%">';
201
+        print '<tr class="liste_titre">';
202
+        print '<th colspan="3">'.$langs->trans("SuppliersOrdersInProcess").'</th></tr>';
203
+        while ($i < $num)
204
+        {
205
+            $obj = $db->fetch_object($resql);
206
+
207
+            $orderstatic->id=$obj->rowid;
208
+            $orderstatic->ref=$obj->ref;
209
+            $orderstatic->ref_supplier=$obj->ref_supplier;
210
+            $orderstatic->statut=$obj->status;
211 211
             $orderstatic->facturee=$obj->billed;
212 212
 
213 213
             $companystatic->name=$obj->name;
214
-			$companystatic->id=$obj->socid;
215
-
216
-			print '<tr class="oddeven"><td>';
217
-			print $orderstatic->getNomUrl(1);
218
-			print '</td>';
219
-			print '<td>';
220
-			print $companystatic->getNomUrl(1,'customer');
221
-			print '</td>';
214
+            $companystatic->id=$obj->socid;
215
+
216
+            print '<tr class="oddeven"><td>';
217
+            print $orderstatic->getNomUrl(1);
218
+            print '</td>';
219
+            print '<td>';
220
+            print $companystatic->getNomUrl(1,'customer');
221
+            print '</td>';
222 222
             print '<td align="right">';
223 223
             print $orderstatic->getLibStatut(3);
224 224
             print '</td>';
225 225
             print '</tr>';
226
-			$i++;
227
-		}
228
-		print "</table><br>";
229
-	}
226
+            $i++;
227
+        }
228
+        print "</table><br>";
229
+    }
230 230
 }
231 231
 else dol_print_error($db);
232 232
 
@@ -253,39 +253,39 @@  discard block
 block discarded – undo
253 253
 $resql = $db->query($sql);
254 254
 if ($resql)
255 255
 {
256
-	$num = $db->num_rows($resql);
257
-	if ($num)
258
-	{
259
-		$i = 0;
260
-		print '<table class="noborder" width="100%">';
261
-		print '<tr class="liste_titre">';
262
-		print '<th colspan="3">'.$langs->trans("LastReceptions", $num).'</th></tr>';
263
-		while ($i < $num)
264
-		{
265
-			$obj = $db->fetch_object($resql);
266
-
267
-			$reception->id=$obj->rowid;
268
-			$reception->ref=$obj->ref;
269
-			$reception->ref_supplier=$obj->ref_supplier;
270
-
271
-			print '<tr class="oddeven"><td>';
272
-			print $reception->getNomUrl(1);
273
-			print '</td>';
274
-			print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a></td>';
275
-			print '<td>';
276
-			if ($obj->commande_fournisseur_id > 0)
277
-			{
278
-				$orderstatic->id=$obj->commande_fournisseur_id;
279
-				$orderstatic->ref=$obj->commande_fournisseur_ref;
280
-				print $orderstatic->getNomUrl(1);
281
-			}
282
-			else print '&nbsp;';
283
-			print '</td></tr>';
284
-			$i++;
285
-		}
286
-		print "</table><br>";
287
-	}
288
-	$db->free($resql);
256
+    $num = $db->num_rows($resql);
257
+    if ($num)
258
+    {
259
+        $i = 0;
260
+        print '<table class="noborder" width="100%">';
261
+        print '<tr class="liste_titre">';
262
+        print '<th colspan="3">'.$langs->trans("LastReceptions", $num).'</th></tr>';
263
+        while ($i < $num)
264
+        {
265
+            $obj = $db->fetch_object($resql);
266
+
267
+            $reception->id=$obj->rowid;
268
+            $reception->ref=$obj->ref;
269
+            $reception->ref_supplier=$obj->ref_supplier;
270
+
271
+            print '<tr class="oddeven"><td>';
272
+            print $reception->getNomUrl(1);
273
+            print '</td>';
274
+            print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a></td>';
275
+            print '<td>';
276
+            if ($obj->commande_fournisseur_id > 0)
277
+            {
278
+                $orderstatic->id=$obj->commande_fournisseur_id;
279
+                $orderstatic->ref=$obj->commande_fournisseur_ref;
280
+                print $orderstatic->getNomUrl(1);
281
+            }
282
+            else print '&nbsp;';
283
+            print '</td></tr>';
284
+            $i++;
285
+        }
286
+        print "</table><br>";
287
+    }
288
+    $db->free($resql);
289 289
 }
290 290
 else dol_print_error($db);
291 291
 
Please login to merge, or discard this patch.
Braces   +42 added lines, -15 removed lines patch added patch discarded remove patch
@@ -48,9 +48,11 @@  discard block
 block discarded – undo
48 48
 print '<div class="fichecenter"><div class="fichethirdleft">';
49 49
 
50 50
 
51
-if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))     // This is useless due to the global search combo
51
+if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) {
52
+    // This is useless due to the global search combo
52 53
 {
53 54
     print '<form method="post" action="list.php">';
55
+}
54 56
     print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
55 57
     print '<table class="noborder nohover" width="100%">';
56 58
     print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
@@ -79,7 +81,9 @@  discard block
 block discarded – undo
79 81
 }
80 82
 $sql.= $clause." e.fk_statut = 0";
81 83
 $sql.= " AND e.entity IN (".getEntity('reception').")";
82
-if ($socid) $sql.= " AND c.fk_soc = ".$socid;
84
+if ($socid) {
85
+    $sql.= " AND c.fk_soc = ".$socid;
86
+}
83 87
 
84 88
 $resql=$db->query($sql);
85 89
 if ($resql)
@@ -106,7 +110,9 @@  discard block
 block discarded – undo
106 110
 			print '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.$obj->name.'</a>';
107 111
 			print '</td>';
108 112
 			print '<td>';
109
-			if ($obj->commande_fournisseur_id) print '<a href="'.DOL_URL_ROOT.'/commande_fournisseur/card.php?id='.$obj->commande_fournisseur_id.'">'.$obj->commande_fournisseur_ref.'</a>';
113
+			if ($obj->commande_fournisseur_id) {
114
+			    print '<a href="'.DOL_URL_ROOT.'/commande_fournisseur/card.php?id='.$obj->commande_fournisseur_id.'">'.$obj->commande_fournisseur_ref.'</a>';
115
+			}
110 116
 			print '</td></tr>';
111 117
 			$i++;
112 118
 		}
@@ -121,12 +127,18 @@  discard block
 block discarded – undo
121 127
 $sql = "SELECT c.rowid, c.ref, c.ref_supplier as ref_supplier, c.fk_statut, s.nom as name, s.rowid as socid";
122 128
 $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c,";
123 129
 $sql.= " ".MAIN_DB_PREFIX."societe as s";
124
-if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
130
+if (!$user->rights->societe->client->voir && !$socid) {
131
+    $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
132
+}
125 133
 $sql.= " WHERE c.fk_soc = s.rowid";
126 134
 $sql.= " AND c.entity = ".$conf->entity;
127 135
 $sql.= " AND c.fk_statut = 3";//Commandé
128
-if ($socid) $sql.= " AND c.fk_soc = ".$socid;
129
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
136
+if ($socid) {
137
+    $sql.= " AND c.fk_soc = ".$socid;
138
+}
139
+if (!$user->rights->societe->client->voir && !$socid) {
140
+    $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
141
+}
130 142
 $sql.= " ORDER BY c.rowid ASC";
131 143
 $resql=$db->query($sql);
132 144
 if ($resql)
@@ -181,12 +193,18 @@  discard block
 block discarded – undo
181 193
 $sql = "SELECT c.rowid, c.ref, c.ref_supplier as ref_supplier, c.fk_statut as status, c.billed as billed, s.nom as name, s.rowid as socid";
182 194
 $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c,";
183 195
 $sql.= " ".MAIN_DB_PREFIX."societe as s";
184
-if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
196
+if (!$user->rights->societe->client->voir && !$socid) {
197
+    $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
198
+}
185 199
 $sql.= " WHERE c.fk_soc = s.rowid";
186 200
 $sql.= " AND c.entity = ".$conf->entity;
187 201
 $sql.= " AND c.fk_statut IN (4)";
188
-if ($socid) $sql.= " AND c.fk_soc = ".$socid;
189
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
202
+if ($socid) {
203
+    $sql.= " AND c.fk_soc = ".$socid;
204
+}
205
+if (!$user->rights->societe->client->voir && !$socid) {
206
+    $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
207
+}
190 208
 
191 209
 $resql = $db->query($sql);
192 210
 if ( $resql )
@@ -227,8 +245,9 @@  discard block
 block discarded – undo
227 245
 		}
228 246
 		print "</table><br>";
229 247
 	}
248
+} else {
249
+    dol_print_error($db);
230 250
 }
231
-else dol_print_error($db);
232 251
 
233 252
 
234 253
 /*
@@ -241,11 +260,17 @@  discard block
 block discarded – undo
241 260
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'reception' AND el.sourcetype IN ('order_supplier')";
242 261
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur as c ON el.fk_source = c.rowid AND el.sourcetype IN ('order_supplier') AND el.targettype = 'reception'";
243 262
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
244
-if (! $user->rights->societe->client->voir && ! $socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
263
+if (! $user->rights->societe->client->voir && ! $socid) {
264
+    $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
265
+}
245 266
 $sql.= " WHERE e.entity IN (".getEntity('reception').")";
246
-if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND sc.fk_user = " .$user->id;
267
+if (! $user->rights->societe->client->voir && ! $socid) {
268
+    $sql.= " AND sc.fk_user = " .$user->id;
269
+}
247 270
 $sql.= " AND e.fk_statut = 1";
248
-if ($socid) $sql.= " AND c.fk_soc = ".$socid;
271
+if ($socid) {
272
+    $sql.= " AND c.fk_soc = ".$socid;
273
+}
249 274
 $sql.= " ORDER BY e.date_delivery DESC";
250 275
 
251 276
 $sql.= $db->plimit(5, 0);
@@ -278,16 +303,18 @@  discard block
 block discarded – undo
278 303
 				$orderstatic->id=$obj->commande_fournisseur_id;
279 304
 				$orderstatic->ref=$obj->commande_fournisseur_ref;
280 305
 				print $orderstatic->getNomUrl(1);
306
+			} else {
307
+			    print '&nbsp;';
281 308
 			}
282
-			else print '&nbsp;';
283 309
 			print '</td></tr>';
284 310
 			$i++;
285 311
 		}
286 312
 		print "</table><br>";
287 313
 	}
288 314
 	$db->free($resql);
315
+} else {
316
+    dol_print_error($db);
289 317
 }
290
-else dol_print_error($db);
291 318
 
292 319
 
293 320
 print '</div></div></div>';
Please login to merge, or discard this patch.
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
29 29
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
30
-require DOL_BASE_PATH . '/main.inc.php';
30
+require DOL_BASE_PATH.'/main.inc.php';
31 31
 
32 32
 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
33 33
 require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
@@ -39,12 +39,12 @@  discard block
 block discarded – undo
39 39
  *	View
40 40
  */
41 41
 
42
-$orderstatic=new CommandeFournisseur($db);
43
-$companystatic=new Societe($db);
44
-$reception=new Reception($db);
42
+$orderstatic = new CommandeFournisseur($db);
43
+$companystatic = new Societe($db);
44
+$reception = new Reception($db);
45 45
 
46
-$helpurl='EN:Module_Receptions|FR:Module_Receptions|ES:M&oacute;dulo_Receptiones';
47
-llxHeader('',$langs->trans("Reception"),$helpurl);
46
+$helpurl = 'EN:Module_Receptions|FR:Module_Receptions|ES:M&oacute;dulo_Receptiones';
47
+llxHeader('', $langs->trans("Reception"), $helpurl);
48 48
 
49 49
 print load_fiche_titre($langs->trans("ReceptionsArea"));
50 50
 
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 print '<div class="fichecenter"><div class="fichethirdleft">';
53 53
 
54 54
 
55
-if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))     // This is useless due to the global search combo
55
+if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))     // This is useless due to the global search combo
56 56
 {
57 57
     print '<form method="post" action="list.php">';
58 58
     print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -69,23 +69,23 @@  discard block
 block discarded – undo
69 69
 $clause = " WHERE ";
70 70
 
71 71
 $sql = "SELECT e.rowid, e.ref, e.ref_supplier,";
72
-$sql.= " s.nom as name, s.rowid as socid,";
73
-$sql.= " c.ref as commande_fournisseur_ref, c.rowid as commande_fournisseur_id";
74
-$sql.= " FROM ".MAIN_DB_PREFIX."reception as e";
75
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'reception'";
76
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur as c ON el.fk_source = c.rowid";
77
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
72
+$sql .= " s.nom as name, s.rowid as socid,";
73
+$sql .= " c.ref as commande_fournisseur_ref, c.rowid as commande_fournisseur_id";
74
+$sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
75
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'reception'";
76
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur as c ON el.fk_source = c.rowid";
77
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
78 78
 if (!$user->rights->societe->client->voir && !$socid)
79 79
 {
80
-	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
81
-	$sql.= $clause." sc.fk_user = " .$user->id;
80
+	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
81
+	$sql .= $clause." sc.fk_user = ".$user->id;
82 82
 	$clause = " AND ";
83 83
 }
84
-$sql.= $clause." e.fk_statut = 0";
85
-$sql.= " AND e.entity IN (".getEntity('reception').")";
86
-if ($socid) $sql.= " AND c.fk_soc = ".$socid;
84
+$sql .= $clause." e.fk_statut = 0";
85
+$sql .= " AND e.entity IN (".getEntity('reception').")";
86
+if ($socid) $sql .= " AND c.fk_soc = ".$socid;
87 87
 
88
-$resql=$db->query($sql);
88
+$resql = $db->query($sql);
89 89
 if ($resql)
90 90
 {
91 91
 	$num = $db->num_rows($resql);
@@ -99,9 +99,9 @@  discard block
 block discarded – undo
99 99
 		{
100 100
 			$obj = $db->fetch_object($resql);
101 101
 
102
-			$reception->id=$obj->rowid;
103
-			$reception->ref=$obj->ref;
104
-			$reception->ref_supplier=$obj->ref_supplier;
102
+			$reception->id = $obj->rowid;
103
+			$reception->ref = $obj->ref;
104
+			$reception->ref_supplier = $obj->ref_supplier;
105 105
 
106 106
 			print '<tr class="oddeven"><td class="nowrap">';
107 107
 			print $reception->getNomUrl(1);
@@ -123,16 +123,16 @@  discard block
 block discarded – undo
123 123
  * CommandeFournisseurs a traiter
124 124
  */
125 125
 $sql = "SELECT c.rowid, c.ref, c.ref_supplier as ref_supplier, c.fk_statut, s.nom as name, s.rowid as socid";
126
-$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c,";
127
-$sql.= " ".MAIN_DB_PREFIX."societe as s";
128
-if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
129
-$sql.= " WHERE c.fk_soc = s.rowid";
130
-$sql.= " AND c.entity = ".$conf->entity;
131
-$sql.= " AND c.fk_statut = 3";//Commandé
132
-if ($socid) $sql.= " AND c.fk_soc = ".$socid;
133
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
134
-$sql.= " ORDER BY c.rowid ASC";
135
-$resql=$db->query($sql);
126
+$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c,";
127
+$sql .= " ".MAIN_DB_PREFIX."societe as s";
128
+if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
129
+$sql .= " WHERE c.fk_soc = s.rowid";
130
+$sql .= " AND c.entity = ".$conf->entity;
131
+$sql .= " AND c.fk_statut = 3"; //Commandé
132
+if ($socid) $sql .= " AND c.fk_soc = ".$socid;
133
+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
134
+$sql .= " ORDER BY c.rowid ASC";
135
+$resql = $db->query($sql);
136 136
 if ($resql)
137 137
 {
138 138
 	$num = $db->num_rows($resql);
@@ -148,21 +148,21 @@  discard block
 block discarded – undo
148 148
 		{
149 149
 			$obj = $db->fetch_object($resql);
150 150
 
151
-			$orderstatic->id=$obj->rowid;
152
-			$orderstatic->ref=$obj->ref;
153
-			$orderstatic->ref_supplier=$obj->ref_supplier;
154
-			$orderstatic->statut=$obj->fk_statut;
155
-			$orderstatic->facturee=0;
151
+			$orderstatic->id = $obj->rowid;
152
+			$orderstatic->ref = $obj->ref;
153
+			$orderstatic->ref_supplier = $obj->ref_supplier;
154
+			$orderstatic->statut = $obj->fk_statut;
155
+			$orderstatic->facturee = 0;
156 156
 
157
-			$companystatic->name=$obj->name;
158
-			$companystatic->id=$obj->socid;
157
+			$companystatic->name = $obj->name;
158
+			$companystatic->id = $obj->socid;
159 159
 
160 160
 			print '<tr class="oddeven">';
161 161
 			print '<td class="nowrap">';
162 162
 			print $orderstatic->getNomUrl(1);
163 163
 			print '</td>';
164 164
 			print '<td>';
165
-			print $companystatic->getNomUrl(1,'customer',32);
165
+			print $companystatic->getNomUrl(1, 'customer', 32);
166 166
 			print '</td>';
167 167
 			print '<td align="right">';
168 168
 			print $orderstatic->getLibStatut(3);
@@ -183,17 +183,17 @@  discard block
 block discarded – undo
183 183
  * CommandeFournisseurs en traitement
184 184
  */
185 185
 $sql = "SELECT c.rowid, c.ref, c.ref_supplier as ref_supplier, c.fk_statut as status, c.billed as billed, s.nom as name, s.rowid as socid";
186
-$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c,";
187
-$sql.= " ".MAIN_DB_PREFIX."societe as s";
188
-if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
189
-$sql.= " WHERE c.fk_soc = s.rowid";
190
-$sql.= " AND c.entity = ".$conf->entity;
191
-$sql.= " AND c.fk_statut IN (4)";
192
-if ($socid) $sql.= " AND c.fk_soc = ".$socid;
193
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
186
+$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c,";
187
+$sql .= " ".MAIN_DB_PREFIX."societe as s";
188
+if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
189
+$sql .= " WHERE c.fk_soc = s.rowid";
190
+$sql .= " AND c.entity = ".$conf->entity;
191
+$sql .= " AND c.fk_statut IN (4)";
192
+if ($socid) $sql .= " AND c.fk_soc = ".$socid;
193
+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
194 194
 
195 195
 $resql = $db->query($sql);
196
-if ( $resql )
196
+if ($resql)
197 197
 {
198 198
 	$langs->load("orders");
199 199
 
@@ -208,20 +208,20 @@  discard block
 block discarded – undo
208 208
 		{
209 209
 			$obj = $db->fetch_object($resql);
210 210
 
211
-		    $orderstatic->id=$obj->rowid;
212
-			$orderstatic->ref=$obj->ref;
213
-			$orderstatic->ref_supplier=$obj->ref_supplier;
214
-			$orderstatic->statut=$obj->status;
215
-            $orderstatic->facturee=$obj->billed;
211
+		    $orderstatic->id = $obj->rowid;
212
+			$orderstatic->ref = $obj->ref;
213
+			$orderstatic->ref_supplier = $obj->ref_supplier;
214
+			$orderstatic->statut = $obj->status;
215
+            $orderstatic->facturee = $obj->billed;
216 216
 
217
-            $companystatic->name=$obj->name;
218
-			$companystatic->id=$obj->socid;
217
+            $companystatic->name = $obj->name;
218
+			$companystatic->id = $obj->socid;
219 219
 
220 220
 			print '<tr class="oddeven"><td>';
221 221
 			print $orderstatic->getNomUrl(1);
222 222
 			print '</td>';
223 223
 			print '<td>';
224
-			print $companystatic->getNomUrl(1,'customer');
224
+			print $companystatic->getNomUrl(1, 'customer');
225 225
 			print '</td>';
226 226
             print '<td align="right">';
227 227
             print $orderstatic->getLibStatut(3);
@@ -239,20 +239,20 @@  discard block
 block discarded – undo
239 239
  * Last receptions
240 240
  */
241 241
 $sql = "SELECT e.rowid, e.ref, e.ref_supplier,";
242
-$sql.= " s.nom as name, s.rowid as socid,";
243
-$sql.= " c.ref as commande_fournisseur_ref, c.rowid as commande_fournisseur_id";
244
-$sql.= " FROM ".MAIN_DB_PREFIX."reception as e";
245
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'reception' AND el.sourcetype IN ('order_supplier')";
246
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur as c ON el.fk_source = c.rowid AND el.sourcetype IN ('order_supplier') AND el.targettype = 'reception'";
247
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
248
-if (! $user->rights->societe->client->voir && ! $socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
249
-$sql.= " WHERE e.entity IN (".getEntity('reception').")";
250
-if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND sc.fk_user = " .$user->id;
251
-$sql.= " AND e.fk_statut = 1";
252
-if ($socid) $sql.= " AND c.fk_soc = ".$socid;
253
-$sql.= " ORDER BY e.date_delivery DESC";
254
-
255
-$sql.= $db->plimit(5, 0);
242
+$sql .= " s.nom as name, s.rowid as socid,";
243
+$sql .= " c.ref as commande_fournisseur_ref, c.rowid as commande_fournisseur_id";
244
+$sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
245
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'reception' AND el.sourcetype IN ('order_supplier')";
246
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur as c ON el.fk_source = c.rowid AND el.sourcetype IN ('order_supplier') AND el.targettype = 'reception'";
247
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
248
+if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
249
+$sql .= " WHERE e.entity IN (".getEntity('reception').")";
250
+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id;
251
+$sql .= " AND e.fk_statut = 1";
252
+if ($socid) $sql .= " AND c.fk_soc = ".$socid;
253
+$sql .= " ORDER BY e.date_delivery DESC";
254
+
255
+$sql .= $db->plimit(5, 0);
256 256
 
257 257
 $resql = $db->query($sql);
258 258
 if ($resql)
@@ -268,19 +268,19 @@  discard block
 block discarded – undo
268 268
 		{
269 269
 			$obj = $db->fetch_object($resql);
270 270
 
271
-			$reception->id=$obj->rowid;
272
-			$reception->ref=$obj->ref;
273
-			$reception->ref_supplier=$obj->ref_supplier;
271
+			$reception->id = $obj->rowid;
272
+			$reception->ref = $obj->ref;
273
+			$reception->ref_supplier = $obj->ref_supplier;
274 274
 
275 275
 			print '<tr class="oddeven"><td>';
276 276
 			print $reception->getNomUrl(1);
277 277
 			print '</td>';
278
-			print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a></td>';
278
+			print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
279 279
 			print '<td>';
280 280
 			if ($obj->commande_fournisseur_id > 0)
281 281
 			{
282
-				$orderstatic->id=$obj->commande_fournisseur_id;
283
-				$orderstatic->ref=$obj->commande_fournisseur_ref;
282
+				$orderstatic->id = $obj->commande_fournisseur_id;
283
+				$orderstatic->ref = $obj->commande_fournisseur_ref;
284 284
 				print $orderstatic->getNomUrl(1);
285 285
 			}
286 286
 			else print '&nbsp;';
Please login to merge, or discard this patch.
dolibarr/htdocs/reception/contact.php 3 patches
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         $origin = $object->origin;
59 59
 
60 60
         $object->fetch_origin();
61
-		$typeobject = $object->origin;
61
+        $typeobject = $object->origin;
62 62
     }
63 63
 
64 64
     // Linked documents
@@ -83,26 +83,26 @@  discard block
 block discarded – undo
83 83
 {
84 84
     if ($result > 0 && $id > 0)
85 85
     {
86
-  		$result = $objectsrc->add_contact(GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'), $_POST["type"], $_POST["source"]);
86
+            $result = $objectsrc->add_contact(GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'), $_POST["type"], $_POST["source"]);
87 87
     }
88 88
 
89
-	if ($result >= 0)
90
-	{
91
-		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
92
-		exit;
93
-	}
94
-	else
95
-	{
96
-		if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
97
-		{
98
-			$langs->load("errors");
99
-			$mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
100
-		} else {
101
-			$mesg = $objectsrc->error;
102
-			$mesgs = $objectsrc->errors;
103
-		}
104
-		setEventMessages($mesg, $mesgs, 'errors');
105
-	}
89
+    if ($result >= 0)
90
+    {
91
+        header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
92
+        exit;
93
+    }
94
+    else
95
+    {
96
+        if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
97
+        {
98
+            $langs->load("errors");
99
+            $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
100
+        } else {
101
+            $mesg = $objectsrc->error;
102
+            $mesgs = $objectsrc->errors;
103
+        }
104
+        setEventMessages($mesg, $mesgs, 'errors');
105
+    }
106 106
 }
107 107
 
108 108
 // bascule du statut d'un contact
@@ -114,16 +114,16 @@  discard block
 block discarded – undo
114 114
 // Efface un contact
115 115
 else if ($action == 'deletecontact' && $user->rights->reception->creer)
116 116
 {
117
-	$result = $objectsrc->delete_contact(GETPOST("lineid"));
118
-
119
-	if ($result >= 0)
120
-	{
121
-		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
122
-		exit;
123
-	}
124
-	else {
125
-		dol_print_error($db);
126
-	}
117
+    $result = $objectsrc->delete_contact(GETPOST("lineid"));
118
+
119
+    if ($result >= 0)
120
+    {
121
+        header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
122
+        exit;
123
+    }
124
+    else {
125
+        dol_print_error($db);
126
+    }
127 127
 }
128 128
 /*
129 129
 else if ($action == 'setaddress' && $user->rights->reception->creer)
@@ -155,20 +155,20 @@  discard block
 block discarded – undo
155 155
 
156 156
 if ($id > 0 || ! empty($ref))
157 157
 {
158
-	$langs->trans("OrderCard");
158
+    $langs->trans("OrderCard");
159 159
 
160
-	$head = reception_prepare_head($object);
161
-	dol_fiche_head($head, 'contact', $langs->trans("Reception"), -1, 'sending');
160
+    $head = reception_prepare_head($object);
161
+    dol_fiche_head($head, 'contact', $langs->trans("Reception"), -1, 'sending');
162 162
 
163 163
 
164
-	// Reception card
165
-	$linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php">'.$langs->trans("BackToList").'</a>';
164
+    // Reception card
165
+    $linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php">'.$langs->trans("BackToList").'</a>';
166 166
 
167
-	$morehtmlref='<div class="refidno">';
168
-	// Ref customer reception
169
-	$morehtmlref.=$form->editfieldkey("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1);
170
-	$morehtmlref.=$form->editfieldval("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1);
171
-	// Thirdparty
167
+    $morehtmlref='<div class="refidno">';
168
+    // Ref customer reception
169
+    $morehtmlref.=$form->editfieldkey("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1);
170
+    $morehtmlref.=$form->editfieldval("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1);
171
+    // Thirdparty
172 172
     $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
173 173
     // Project
174 174
     if (! empty($conf->projet->enabled)) {
@@ -204,69 +204,69 @@  discard block
 block discarded – undo
204 204
             }
205 205
         }
206 206
     }
207
-	$morehtmlref.='</div>';
207
+    $morehtmlref.='</div>';
208 208
 
209
-	$object->picto = 'sending';
210
-	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
209
+    $object->picto = 'sending';
210
+    dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
211 211
 
212 212
 
213
-	print '<div class="fichecenter">';
213
+    print '<div class="fichecenter">';
214 214
     //print '<div class="fichehalfleft">';
215
-	print '<div class="underbanner clearboth"></div>';
215
+    print '<div class="underbanner clearboth"></div>';
216 216
 
217 217
     print '<table class="border centpercent">';
218 218
     // Linked documents
219
-	if ($origin == 'order_supplier' && $object->$typeobject->id && ! empty($conf->fournisseur->enabled))
220
-	{
221
-	    print '<tr><td class="titlefield">';
222
-	    $objectsrc=new CommandeFournisseur($db);
223
-	    $objectsrc->fetch($object->$typeobject->id);
224
-	    print $langs->trans("RefOrder").'</td>';
225
-	    print '<td colspan="3">';
226
-	    print $objectsrc->getNomUrl(1,'commande');
227
-	    print "</td>\n";
228
-	    print '</tr>';
229
-	}
230
-	if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
231
-	{
232
-	    print '<tr><td class="titlefield">';
233
-	    $objectsrc=new Propal($db);
234
-	    $objectsrc->fetch($object->$typeobject->id);
235
-	    print $langs->trans("RefProposal").'</td>';
236
-	    print '<td colspan="3">';
237
-	    print $objectsrc->getNomUrl(1,'reception');
238
-	    print "</td>\n";
239
-	    print '</tr>';
240
-	}
241
-
242
-	print "</table>";
243
-
244
-
245
-	//print '</div>';
246
-	//print '<div class="fichehalfright">';
247
-	//print '<div class="ficheaddleft">';
248
-	//print '<div class="underbanner clearboth"></div>';
249
-
250
-
251
-	//print '</div>';
252
-	//print '</div>';
253
-	print '</div>';
254
-
255
-	print '<div class="clearboth"></div>';
256
-
257
-
258
-	dol_fiche_end();
259
-
260
-	// Lignes de contacts
261
-	echo '<br>';
262
-
263
-	// Contacts lines (modules that overwrite templates must declare this into descriptor)
264
-	$dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
265
-	foreach($dirtpls as $reldir)
266
-	{
267
-		$res=@include dol_buildpath($reldir.'/contacts.tpl.php');
268
-		if ($res) break;
269
-	}
219
+    if ($origin == 'order_supplier' && $object->$typeobject->id && ! empty($conf->fournisseur->enabled))
220
+    {
221
+        print '<tr><td class="titlefield">';
222
+        $objectsrc=new CommandeFournisseur($db);
223
+        $objectsrc->fetch($object->$typeobject->id);
224
+        print $langs->trans("RefOrder").'</td>';
225
+        print '<td colspan="3">';
226
+        print $objectsrc->getNomUrl(1,'commande');
227
+        print "</td>\n";
228
+        print '</tr>';
229
+    }
230
+    if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
231
+    {
232
+        print '<tr><td class="titlefield">';
233
+        $objectsrc=new Propal($db);
234
+        $objectsrc->fetch($object->$typeobject->id);
235
+        print $langs->trans("RefProposal").'</td>';
236
+        print '<td colspan="3">';
237
+        print $objectsrc->getNomUrl(1,'reception');
238
+        print "</td>\n";
239
+        print '</tr>';
240
+    }
241
+
242
+    print "</table>";
243
+
244
+
245
+    //print '</div>';
246
+    //print '<div class="fichehalfright">';
247
+    //print '<div class="ficheaddleft">';
248
+    //print '<div class="underbanner clearboth"></div>';
249
+
250
+
251
+    //print '</div>';
252
+    //print '</div>';
253
+    print '</div>';
254
+
255
+    print '<div class="clearboth"></div>';
256
+
257
+
258
+    dol_fiche_end();
259
+
260
+    // Lignes de contacts
261
+    echo '<br>';
262
+
263
+    // Contacts lines (modules that overwrite templates must declare this into descriptor)
264
+    $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
265
+    foreach($dirtpls as $reldir)
266
+    {
267
+        $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
268
+        if ($res) break;
269
+    }
270 270
 }
271 271
 
272 272
 llxFooter();
Please login to merge, or discard this patch.
Braces   +8 added lines, -6 removed lines patch added patch discarded remove patch
@@ -44,7 +44,9 @@  discard block
 block discarded – undo
44 44
 $action=GETPOST('action','alpha');
45 45
 
46 46
 // Security check
47
-if ($user->societe_id) $socid=$user->societe_id;
47
+if ($user->societe_id) {
48
+    $socid=$user->societe_id;
49
+}
48 50
 $result = restrictedArea($user, 'reception', $id,'');
49 51
 
50 52
 $object = new Reception($db);
@@ -90,8 +92,7 @@  discard block
 block discarded – undo
90 92
 	{
91 93
 		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
92 94
 		exit;
93
-	}
94
-	else
95
+	} else
95 96
 	{
96 97
 		if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
97 98
 		{
@@ -120,8 +121,7 @@  discard block
 block discarded – undo
120 121
 	{
121 122
 		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
122 123
 		exit;
123
-	}
124
-	else {
124
+	} else {
125 125
 		dol_print_error($db);
126 126
 	}
127 127
 }
@@ -265,7 +265,9 @@  discard block
 block discarded – undo
265 265
 	foreach($dirtpls as $reldir)
266 266
 	{
267 267
 		$res=@include dol_buildpath($reldir.'/contacts.tpl.php');
268
-		if ($res) break;
268
+		if ($res) {
269
+		    break;
270
+		}
269 271
 	}
270 272
 }
271 273
 
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 
27 27
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
28 28
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
29
-require DOL_BASE_PATH . '/main.inc.php';
29
+require DOL_BASE_PATH.'/main.inc.php';
30 30
 
31 31
 require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
32 32
 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 require_once DOL_DOCUMENT_ROOT.'/core/lib/reception.lib.php';
35 35
 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
36 36
 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
37
-if (! empty($conf->projet->enabled)) {
37
+if (!empty($conf->projet->enabled)) {
38 38
     require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
39 39
     require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
40 40
 }
@@ -43,16 +43,16 @@  discard block
 block discarded – undo
43 43
 $langs->load("receptions");
44 44
 $langs->load("companies");
45 45
 
46
-$id=GETPOST('id','int');
47
-$ref=GETPOST('ref','alpha');
48
-$action=GETPOST('action','alpha');
46
+$id = GETPOST('id', 'int');
47
+$ref = GETPOST('ref', 'alpha');
48
+$action = GETPOST('action', 'alpha');
49 49
 
50 50
 // Security check
51
-if ($user->societe_id) $socid=$user->societe_id;
52
-$result = restrictedArea($user, 'reception', $id,'');
51
+if ($user->societe_id) $socid = $user->societe_id;
52
+$result = restrictedArea($user, 'reception', $id, '');
53 53
 
54 54
 $object = new Reception($db);
55
-if ($id > 0 || ! empty($ref))
55
+if ($id > 0 || !empty($ref))
56 56
 {
57 57
     $object->fetch($id, $ref);
58 58
     $object->fetch_thirdparty();
@@ -66,14 +66,14 @@  discard block
 block discarded – undo
66 66
     }
67 67
 
68 68
     // Linked documents
69
-    if ($origin == 'order_supplier' && $object->$typeobject->id && ! empty($conf->fournisseur->enabled))
69
+    if ($origin == 'order_supplier' && $object->$typeobject->id && !empty($conf->fournisseur->enabled))
70 70
     {
71
-        $objectsrc=new CommandeFournisseur($db);
71
+        $objectsrc = new CommandeFournisseur($db);
72 72
         $objectsrc->fetch($object->$typeobject->id);
73 73
     }
74
-    if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
74
+    if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled))
75 75
     {
76
-        $objectsrc=new Propal($db);
76
+        $objectsrc = new Propal($db);
77 77
         $objectsrc->fetch($object->$typeobject->id);
78 78
     }
79 79
 }
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 // bascule du statut d'un contact
113 113
 else if ($action == 'swapstatut' && $user->rights->reception->creer)
114 114
 {
115
-    $result=$objectsrc->swapContactStatus(GETPOST('ligne'));
115
+    $result = $objectsrc->swapContactStatus(GETPOST('ligne'));
116 116
 }
117 117
 
118 118
 // Efface un contact
@@ -142,13 +142,13 @@  discard block
 block discarded – undo
142 142
  * View
143 143
  */
144 144
 
145
-llxHeader('',$langs->trans('Reception'),'EN:Customers_Orders|FR:receptions_Clients|ES:Pedidos de clientes');
145
+llxHeader('', $langs->trans('Reception'), 'EN:Customers_Orders|FR:receptions_Clients|ES:Pedidos de clientes');
146 146
 
147 147
 $form = new Form($db);
148 148
 $formcompany = new FormCompany($db);
149 149
 $formother = new FormOther($db);
150
-$contactstatic=new Contact($db);
151
-$userstatic=new User($db);
150
+$contactstatic = new Contact($db);
151
+$userstatic = new User($db);
152 152
 
153 153
 
154 154
 /* *************************************************************************** */
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 /*                                                                             */
158 158
 /* *************************************************************************** */
159 159
 
160
-if ($id > 0 || ! empty($ref))
160
+if ($id > 0 || !empty($ref))
161 161
 {
162 162
 	$langs->trans("OrderCard");
163 163
 
@@ -168,39 +168,39 @@  discard block
 block discarded – undo
168 168
 	// Reception card
169 169
 	$linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php">'.$langs->trans("BackToList").'</a>';
170 170
 
171
-	$morehtmlref='<div class="refidno">';
171
+	$morehtmlref = '<div class="refidno">';
172 172
 	// Ref customer reception
173
-	$morehtmlref.=$form->editfieldkey("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1);
174
-	$morehtmlref.=$form->editfieldval("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1);
173
+	$morehtmlref .= $form->editfieldkey("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1);
174
+	$morehtmlref .= $form->editfieldval("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1);
175 175
 	// Thirdparty
176
-    $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
176
+    $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
177 177
     // Project
178
-    if (! empty($conf->projet->enabled)) {
178
+    if (!empty($conf->projet->enabled)) {
179 179
         $langs->load("projects");
180
-        $morehtmlref .= '<br>' . $langs->trans('Project') . ' ';
180
+        $morehtmlref .= '<br>'.$langs->trans('Project').' ';
181 181
         if (0) {    // Do not change on reception
182 182
             if ($action != 'classify') {
183
-                $morehtmlref .= '<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
183
+                $morehtmlref .= '<a href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
184 184
             }
185 185
             if ($action == 'classify') {
186 186
                 // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
187
-                $morehtmlref .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
187
+                $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
188 188
                 $morehtmlref .= '<input type="hidden" name="action" value="classin">';
189
-                $morehtmlref .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
189
+                $morehtmlref .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
190 190
                 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
191
-                $morehtmlref .= '<input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
191
+                $morehtmlref .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
192 192
                 $morehtmlref .= '</form>';
193 193
             } else {
194
-                $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
194
+                $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
195 195
             }
196 196
         } else {
197 197
             // We don't have project on reception, so we will use the project or source object instead
198 198
             // TODO Add project on reception
199 199
             $morehtmlref .= ' : ';
200
-            if (! empty($objectsrc->fk_project)) {
200
+            if (!empty($objectsrc->fk_project)) {
201 201
                 $proj = new Project($db);
202 202
                 $proj->fetch($objectsrc->fk_project);
203
-                $morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $objectsrc->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
203
+                $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objectsrc->fk_project.'" title="'.$langs->trans('ShowProject').'">';
204 204
                 $morehtmlref .= $proj->ref;
205 205
                 $morehtmlref .= '</a>';
206 206
             } else {
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
             }
209 209
         }
210 210
     }
211
-	$morehtmlref.='</div>';
211
+	$morehtmlref .= '</div>';
212 212
 
213 213
 	$object->picto = 'sending';
214 214
 	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
@@ -220,25 +220,25 @@  discard block
 block discarded – undo
220 220
 
221 221
     print '<table class="border centpercent">';
222 222
     // Linked documents
223
-	if ($origin == 'order_supplier' && $object->$typeobject->id && ! empty($conf->fournisseur->enabled))
223
+	if ($origin == 'order_supplier' && $object->$typeobject->id && !empty($conf->fournisseur->enabled))
224 224
 	{
225 225
 	    print '<tr><td class="titlefield">';
226
-	    $objectsrc=new CommandeFournisseur($db);
226
+	    $objectsrc = new CommandeFournisseur($db);
227 227
 	    $objectsrc->fetch($object->$typeobject->id);
228 228
 	    print $langs->trans("RefOrder").'</td>';
229 229
 	    print '<td colspan="3">';
230
-	    print $objectsrc->getNomUrl(1,'commande');
230
+	    print $objectsrc->getNomUrl(1, 'commande');
231 231
 	    print "</td>\n";
232 232
 	    print '</tr>';
233 233
 	}
234
-	if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
234
+	if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled))
235 235
 	{
236 236
 	    print '<tr><td class="titlefield">';
237
-	    $objectsrc=new Propal($db);
237
+	    $objectsrc = new Propal($db);
238 238
 	    $objectsrc->fetch($object->$typeobject->id);
239 239
 	    print $langs->trans("RefProposal").'</td>';
240 240
 	    print '<td colspan="3">';
241
-	    print $objectsrc->getNomUrl(1,'reception');
241
+	    print $objectsrc->getNomUrl(1, 'reception');
242 242
 	    print "</td>\n";
243 243
 	    print '</tr>';
244 244
 	}
@@ -265,10 +265,10 @@  discard block
 block discarded – undo
265 265
 	echo '<br>';
266 266
 
267 267
 	// Contacts lines (modules that overwrite templates must declare this into descriptor)
268
-	$dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
269
-	foreach($dirtpls as $reldir)
268
+	$dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
269
+	foreach ($dirtpls as $reldir)
270 270
 	{
271
-		$res=@include dol_buildpath($reldir.'/contacts.tpl.php');
271
+		$res = @include dol_buildpath($reldir.'/contacts.tpl.php');
272 272
 		if ($res) break;
273 273
 	}
274 274
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/reception/list.php 3 patches
Indentation   +660 added lines, -660 removed lines patch added patch discarded remove patch
@@ -138,271 +138,271 @@  discard block
 block discarded – undo
138 138
 // Purge search criteria
139 139
 if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
140 140
 {
141
-	$search_ref_supplier='';
141
+    $search_ref_supplier='';
142 142
     $search_ref_rcp='';
143 143
     $search_ref_liv='';
144 144
     $search_company='';
145 145
     $search_town='';
146
-	$search_zip="";
146
+    $search_zip="";
147 147
     $search_state="";
148
-	$search_type='';
149
-	$search_country='';
150
-	$search_type_thirdparty='';
151
-	$search_billed='';
148
+    $search_type='';
149
+    $search_country='';
150
+    $search_type_thirdparty='';
151
+    $search_billed='';
152 152
     $viewstatut='';
153 153
     $search_array_options=array();
154 154
 }
155 155
 
156 156
 if (empty($reshook))
157 157
 {
158
-	if ($massaction == 'confirm_createbills') {
159
-
160
-    	$receptions = GETPOST('toselect','array');
161
-    	$createbills_onebythird = GETPOST('createbills_onebythird', 'int');
162
-    	$validate_invoices = GETPOST('valdate_invoices', 'int');
163
-
164
-    	$TFact = array();
165
-    	$TFactThird = array();
166
-
167
-    	$nb_bills_created = 0;
168
-
169
-    	$db->begin();
170
-		$errors =array();
171
-    	foreach($receptions as $id_reception)
172
-    	{
173
-    		$rcp = new Reception($db);
174
-			 // On ne facture que les réceptions validées
175
-    		if ($rcp->fetch($id_reception) <= 0 || $rcp->statut != 1){
176
-				$errors[]=$langs->trans('StatusMustBeValidate',$rcp->ref);
177
-				$error++;
178
-				continue;
179
-			}
180
-
181
-    		$object = new FactureFournisseur($db);
182
-    		if (!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])){
183
-				$object = $TFactThird[$rcp->socid]; // If option "one bill per third" is set, we use already created reception.
184
-				if(empty($object->rowid)&&$object->id != null)$object->rowid = $object->id;
185
-				if(!empty($object->rowid))$object->fetchObjectLinked();
186
-				$rcp->fetchObjectLinked();
187
-
188
-				if (count($rcp->linkedObjectsIds['order_supplier']) > 0)
189
-				{
190
-					foreach ($rcp->linkedObjectsIds['order_supplier'] as $key => $value)
191
-					{
192
-						if(empty($object->linkedObjectsIds['order_supplier']) || !in_array($value, $object->linkedObjectsIds['order_supplier']))//Dont try to link if already linked
193
-							$object->add_object_linked('order_supplier', $value); // add supplier order linked object
194
-					}
195
-				}
196
-			}
197
-    		else {
198
-    			$object->socid = $rcp->socid;
199
-    			$object->type = FactureFournisseur::TYPE_STANDARD;
200
-    			$object->cond_reglement_id	= $rcp->thirdparty->cond_reglement_supplier_id;
201
-    			$object->mode_reglement_id	= $rcp->thirdparty->mode_reglement_supplier_id;
202
-				$object->fk_account         = !empty($rcp->thirdparty->fk_account)?$rcp->thirdparty->fk_account:0;
203
-				$object->remise_percent 	= !empty($rcp->thirdparty->remise_percent)?$rcp->thirdparty->remise_percent:0;
204
-				$object->remise_absolue 	= !empty($rcp->thirdparty->remise_absolue)?$rcp->thirdparty->remise_absolue:0;
205
-
206
-    			$object->fk_project			= $rcp->fk_project;
207
-    			$object->ref_supplier		= $rcp->ref_supplier;
208
-
209
-    			$datefacture = dol_mktime(12, 0, 0, GETPOST('remonth'),GETPOST('reday'), GETPOST('reyear'));
210
-    			if (empty($datefacture))
211
-    			{
212
-    				$datefacture = dol_mktime(date("h"), date("M"), 0, date("m"), date("d"), date("Y"));
213
-    			}
214
-
215
-    			$object->date = $datefacture;
216
-    			$object->origin    = 'reception';
217
-    			$object->origin_id = $id_reception;
218
-
219
-				$rcp->fetchObjectLinked();
220
-				if (count($rcp->linkedObjectsIds['order_supplier']) > 0)
221
-				{
222
-					foreach ($rcp->linkedObjectsIds['order_supplier'] as $key => $value)
223
-					{
224
-						$object->linked_objects['order_supplier'] = $value;
225
-					}
226
-				}
227
-
228
-    			$res = $object->create($user);
229
-				//var_dump($object->error);exit;
230
-    			if($res > 0){
231
-					$nb_bills_created++;
232
-					$object->id = $res;
233
-				}else {
234
-					$errors[]=$rcp->ref.' : '.$langs->trans($object->error);
235
-					$error++;
236
-				}
237
-    		}
238
-
239
-    		if ($object->id > 0)
240
-    		{
241
-				if(!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])){ //cause function create already add object linked for facturefournisseur
242
-					$res = $object->add_object_linked($object->origin,$id_reception);
243
-
244
-					if ($res==0)
245
-					{
246
-						$errors[]=$object->error;
247
-						$error++;
248
-					}
249
-				}
250
-
251
-    			if (! $error)
252
-    			{
253
-	    			$lines = $rcp->lines;
254
-	    			if (empty($lines) && method_exists($rcp, 'fetch_lines'))
255
-	    			{
256
-	    				$rcp->fetch_lines();
257
-	    				$lines = $rcp->lines;
258
-	    			}
259
-
260
-	    			$fk_parent_line=0;
261
-	    			$num=count($lines);
262
-
263
-	    			for ($i=0;$i<$num;$i++)
264
-	    			{
265
-	    				$desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle);
266
-	    				if ($lines[$i]->subprice < 0)
267
-	    				{
268
-	    					// Negative line, we create a discount line
269
-	    					$discount = new DiscountAbsolute($db);
270
-	    					$discount->fk_soc=$object->socid;
271
-	    					$discount->amount_ht=abs($lines[$i]->total_ht);
272
-	    					$discount->amount_tva=abs($lines[$i]->total_tva);
273
-	    					$discount->amount_ttc=abs($lines[$i]->total_ttc);
274
-	    					$discount->tva_tx=$lines[$i]->tva_tx;
275
-	    					$discount->fk_user=$user->id;
276
-	    					$discount->description=$desc;
277
-	    					$discountid=$discount->create($user);
278
-	    					if ($discountid > 0)
279
-	    					{
280
-	    						$result=$object->insert_discount($discountid);
281
-	    						//$result=$discount->link_to_invoice($lineid,$id);
282
-	    					}
283
-	    					else
284
-	    					{
285
-	    						setEventMessages($discount->error, $discount->errors, 'errors');
286
-	    						$error++;
287
-	    						break;
288
-	    					}
289
-	    				}
290
-	    				else
291
-	    				{
292
-	    					// Positive line
293
-	    					$product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
294
-	    					// Date start
295
-	    					$date_start=false;
296
-	    					if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue;
297
-	    					if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel;
298
-	    					if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start;
299
-	    					//Date end
300
-	    					$date_end=false;
301
-	    					if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue;
302
-	    					if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel;
303
-	    					if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end;
304
-	    					// Reset fk_parent_line for no child products and special product
305
-	    					if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9)
306
-	    					{
307
-	    						$fk_parent_line = 0;
308
-	    					}
309
-	    					$result = $object->addline(
310
-	    							$desc,
311
-	    							$lines[$i]->subprice,
312
-	    							$lines[$i]->tva_tx,
313
-	    							$lines[$i]->localtax1_tx,
314
-	    							$lines[$i]->localtax2_tx,
315
-									$lines[$i]->qty,
316
-	    							$lines[$i]->fk_product,
317
-	    							$lines[$i]->remise_percent,
318
-	    							$date_start,
319
-	    							$date_end,
320
-	    							0,
321
-	    							$lines[$i]->info_bits,
322
-	    							'HT',
323
-	    							$product_type,
324
-	    							$i,
325
-	    							false,
326
-									0,
327
-									null,
328
-	    							$lines[$i]->rowid,
329
-									0,
330
-									$lines[$i]->ref_supplier
331
-
332
-	    					);
333
-
334
-							$rcp->add_object_linked('facture_fourn_det',$result);
335
-
336
-	    					if ($result > 0)
337
-	    					{
338
-	    						$lineid=$result;
339
-	    					}
340
-	    					else
341
-	    					{
342
-	    						$lineid=0;
343
-	    						$error++;
344
-	    						break;
345
-	    					}
346
-	    					// Defined the new fk_parent_line
347
-	    					if ($result > 0 && $lines[$i]->product_type == 9)
348
-	    					{
349
-	    						$fk_parent_line = $result;
350
-	    					}
351
-	    				}
352
-	    			}
353
-    			}
354
-    		}
355
-
356
-    		//$rcp->classifyBilled($user);        // Disabled. This behavior must be set or not using the workflow module.
357
-
358
-    		if(!empty($createbills_onebythird) && empty($TFactThird[$rcp->socid])) $TFactThird[$rcp->socid] = $object;
359
-    		else $TFact[$object->id] = $object;
360
-    	}
361
-
362
-    	// Build doc with all invoices
363
-    	$TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
364
-    	$toselect = array();
365
-
366
-    	if (! $error && $validate_invoices)
367
-    	{
368
-    		$massaction = $action = 'builddoc';
369
-    		foreach($TAllFact as &$object)
370
-    		{
371
-    			$result = $object->validate($user);
372
-    			if ($result <= 0)
373
-    			{
374
-    				$error++;
375
-    				setEventMessages($object->error, $object->errors, 'errors');
376
-    				break;
377
-    			}
378
-
379
-    			$id = $object->id; // For builddoc action
380
-
381
-    			// Fac builddoc
382
-    			$donotredirect = 1;
383
-    			$upload_dir = $conf->fournisseur->facture->dir_output;
384
-    		    $permissioncreate=$user->rights->fournisseur->facture->creer;
385
-    		    include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
386
-    		}
387
-
388
-    		$massaction = $action = 'confirm_createbills';
389
-    	}
390
-
391
-    	if (! $error)
392
-    	{
393
-    		$db->commit();
394
-    		setEventMessage($langs->trans('BillCreated', $nb_bills_created));
395
-    	}
396
-    	else
397
-    	{
398
-
399
-    		$db->rollback();
400
-    		$action='create';
401
-    		$_GET["origin"]=$_POST["origin"];
402
-    		$_GET["originid"]=$_POST["originid"];
403
-    		setEventMessages($object->error, $errors, 'errors');
404
-    		$error++;
405
-    	}
158
+    if ($massaction == 'confirm_createbills') {
159
+
160
+        $receptions = GETPOST('toselect','array');
161
+        $createbills_onebythird = GETPOST('createbills_onebythird', 'int');
162
+        $validate_invoices = GETPOST('valdate_invoices', 'int');
163
+
164
+        $TFact = array();
165
+        $TFactThird = array();
166
+
167
+        $nb_bills_created = 0;
168
+
169
+        $db->begin();
170
+        $errors =array();
171
+        foreach($receptions as $id_reception)
172
+        {
173
+            $rcp = new Reception($db);
174
+                // On ne facture que les réceptions validées
175
+            if ($rcp->fetch($id_reception) <= 0 || $rcp->statut != 1){
176
+                $errors[]=$langs->trans('StatusMustBeValidate',$rcp->ref);
177
+                $error++;
178
+                continue;
179
+            }
180
+
181
+            $object = new FactureFournisseur($db);
182
+            if (!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])){
183
+                $object = $TFactThird[$rcp->socid]; // If option "one bill per third" is set, we use already created reception.
184
+                if(empty($object->rowid)&&$object->id != null)$object->rowid = $object->id;
185
+                if(!empty($object->rowid))$object->fetchObjectLinked();
186
+                $rcp->fetchObjectLinked();
187
+
188
+                if (count($rcp->linkedObjectsIds['order_supplier']) > 0)
189
+                {
190
+                    foreach ($rcp->linkedObjectsIds['order_supplier'] as $key => $value)
191
+                    {
192
+                        if(empty($object->linkedObjectsIds['order_supplier']) || !in_array($value, $object->linkedObjectsIds['order_supplier']))//Dont try to link if already linked
193
+                            $object->add_object_linked('order_supplier', $value); // add supplier order linked object
194
+                    }
195
+                }
196
+            }
197
+            else {
198
+                $object->socid = $rcp->socid;
199
+                $object->type = FactureFournisseur::TYPE_STANDARD;
200
+                $object->cond_reglement_id	= $rcp->thirdparty->cond_reglement_supplier_id;
201
+                $object->mode_reglement_id	= $rcp->thirdparty->mode_reglement_supplier_id;
202
+                $object->fk_account         = !empty($rcp->thirdparty->fk_account)?$rcp->thirdparty->fk_account:0;
203
+                $object->remise_percent 	= !empty($rcp->thirdparty->remise_percent)?$rcp->thirdparty->remise_percent:0;
204
+                $object->remise_absolue 	= !empty($rcp->thirdparty->remise_absolue)?$rcp->thirdparty->remise_absolue:0;
205
+
206
+                $object->fk_project			= $rcp->fk_project;
207
+                $object->ref_supplier		= $rcp->ref_supplier;
208
+
209
+                $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth'),GETPOST('reday'), GETPOST('reyear'));
210
+                if (empty($datefacture))
211
+                {
212
+                    $datefacture = dol_mktime(date("h"), date("M"), 0, date("m"), date("d"), date("Y"));
213
+                }
214
+
215
+                $object->date = $datefacture;
216
+                $object->origin    = 'reception';
217
+                $object->origin_id = $id_reception;
218
+
219
+                $rcp->fetchObjectLinked();
220
+                if (count($rcp->linkedObjectsIds['order_supplier']) > 0)
221
+                {
222
+                    foreach ($rcp->linkedObjectsIds['order_supplier'] as $key => $value)
223
+                    {
224
+                        $object->linked_objects['order_supplier'] = $value;
225
+                    }
226
+                }
227
+
228
+                $res = $object->create($user);
229
+                //var_dump($object->error);exit;
230
+                if($res > 0){
231
+                    $nb_bills_created++;
232
+                    $object->id = $res;
233
+                }else {
234
+                    $errors[]=$rcp->ref.' : '.$langs->trans($object->error);
235
+                    $error++;
236
+                }
237
+            }
238
+
239
+            if ($object->id > 0)
240
+            {
241
+                if(!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])){ //cause function create already add object linked for facturefournisseur
242
+                    $res = $object->add_object_linked($object->origin,$id_reception);
243
+
244
+                    if ($res==0)
245
+                    {
246
+                        $errors[]=$object->error;
247
+                        $error++;
248
+                    }
249
+                }
250
+
251
+                if (! $error)
252
+                {
253
+                    $lines = $rcp->lines;
254
+                    if (empty($lines) && method_exists($rcp, 'fetch_lines'))
255
+                    {
256
+                        $rcp->fetch_lines();
257
+                        $lines = $rcp->lines;
258
+                    }
259
+
260
+                    $fk_parent_line=0;
261
+                    $num=count($lines);
262
+
263
+                    for ($i=0;$i<$num;$i++)
264
+                    {
265
+                        $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle);
266
+                        if ($lines[$i]->subprice < 0)
267
+                        {
268
+                            // Negative line, we create a discount line
269
+                            $discount = new DiscountAbsolute($db);
270
+                            $discount->fk_soc=$object->socid;
271
+                            $discount->amount_ht=abs($lines[$i]->total_ht);
272
+                            $discount->amount_tva=abs($lines[$i]->total_tva);
273
+                            $discount->amount_ttc=abs($lines[$i]->total_ttc);
274
+                            $discount->tva_tx=$lines[$i]->tva_tx;
275
+                            $discount->fk_user=$user->id;
276
+                            $discount->description=$desc;
277
+                            $discountid=$discount->create($user);
278
+                            if ($discountid > 0)
279
+                            {
280
+                                $result=$object->insert_discount($discountid);
281
+                                //$result=$discount->link_to_invoice($lineid,$id);
282
+                            }
283
+                            else
284
+                            {
285
+                                setEventMessages($discount->error, $discount->errors, 'errors');
286
+                                $error++;
287
+                                break;
288
+                            }
289
+                        }
290
+                        else
291
+                        {
292
+                            // Positive line
293
+                            $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
294
+                            // Date start
295
+                            $date_start=false;
296
+                            if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue;
297
+                            if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel;
298
+                            if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start;
299
+                            //Date end
300
+                            $date_end=false;
301
+                            if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue;
302
+                            if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel;
303
+                            if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end;
304
+                            // Reset fk_parent_line for no child products and special product
305
+                            if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9)
306
+                            {
307
+                                $fk_parent_line = 0;
308
+                            }
309
+                            $result = $object->addline(
310
+                                    $desc,
311
+                                    $lines[$i]->subprice,
312
+                                    $lines[$i]->tva_tx,
313
+                                    $lines[$i]->localtax1_tx,
314
+                                    $lines[$i]->localtax2_tx,
315
+                                    $lines[$i]->qty,
316
+                                    $lines[$i]->fk_product,
317
+                                    $lines[$i]->remise_percent,
318
+                                    $date_start,
319
+                                    $date_end,
320
+                                    0,
321
+                                    $lines[$i]->info_bits,
322
+                                    'HT',
323
+                                    $product_type,
324
+                                    $i,
325
+                                    false,
326
+                                    0,
327
+                                    null,
328
+                                    $lines[$i]->rowid,
329
+                                    0,
330
+                                    $lines[$i]->ref_supplier
331
+
332
+                            );
333
+
334
+                            $rcp->add_object_linked('facture_fourn_det',$result);
335
+
336
+                            if ($result > 0)
337
+                            {
338
+                                $lineid=$result;
339
+                            }
340
+                            else
341
+                            {
342
+                                $lineid=0;
343
+                                $error++;
344
+                                break;
345
+                            }
346
+                            // Defined the new fk_parent_line
347
+                            if ($result > 0 && $lines[$i]->product_type == 9)
348
+                            {
349
+                                $fk_parent_line = $result;
350
+                            }
351
+                        }
352
+                    }
353
+                }
354
+            }
355
+
356
+            //$rcp->classifyBilled($user);        // Disabled. This behavior must be set or not using the workflow module.
357
+
358
+            if(!empty($createbills_onebythird) && empty($TFactThird[$rcp->socid])) $TFactThird[$rcp->socid] = $object;
359
+            else $TFact[$object->id] = $object;
360
+        }
361
+
362
+        // Build doc with all invoices
363
+        $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
364
+        $toselect = array();
365
+
366
+        if (! $error && $validate_invoices)
367
+        {
368
+            $massaction = $action = 'builddoc';
369
+            foreach($TAllFact as &$object)
370
+            {
371
+                $result = $object->validate($user);
372
+                if ($result <= 0)
373
+                {
374
+                    $error++;
375
+                    setEventMessages($object->error, $object->errors, 'errors');
376
+                    break;
377
+                }
378
+
379
+                $id = $object->id; // For builddoc action
380
+
381
+                // Fac builddoc
382
+                $donotredirect = 1;
383
+                $upload_dir = $conf->fournisseur->facture->dir_output;
384
+                $permissioncreate=$user->rights->fournisseur->facture->creer;
385
+                include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
386
+            }
387
+
388
+            $massaction = $action = 'confirm_createbills';
389
+        }
390
+
391
+        if (! $error)
392
+        {
393
+            $db->commit();
394
+            setEventMessage($langs->trans('BillCreated', $nb_bills_created));
395
+        }
396
+        else
397
+        {
398
+
399
+            $db->rollback();
400
+            $action='create';
401
+            $_GET["origin"]=$_POST["origin"];
402
+            $_GET["originid"]=$_POST["originid"];
403
+            setEventMessages($object->error, $errors, 'errors');
404
+            $error++;
405
+        }
406 406
     }
407 407
 }
408 408
 
@@ -442,20 +442,20 @@  discard block
 block discarded – undo
442 442
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.rowid = ee.fk_target";
443 443
 if (!$user->rights->societe->client->voir && !$socid)	// Internal user with no permission to see all
444 444
 {
445
-	$sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
445
+    $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
446 446
 }
447 447
 $sql.= " WHERE e.entity IN (".getEntity('reception').")";
448 448
 if (!$user->rights->societe->client->voir && !$socid)	// Internal user with no permission to see all
449 449
 {
450
-	$sql.= " AND e.fk_soc = sc.fk_soc";
451
-	$sql.= " AND sc.fk_user = " .$user->id;
450
+    $sql.= " AND e.fk_soc = sc.fk_soc";
451
+    $sql.= " AND sc.fk_user = " .$user->id;
452 452
 }
453 453
 if ($socid)
454 454
 {
455
-	$sql.= " AND e.fk_soc = ".$socid;
455
+    $sql.= " AND e.fk_soc = ".$socid;
456 456
 }
457 457
 if ($viewstatut <> '' && $viewstatut >= 0) {
458
-	$sql.= " AND e.fk_statut = ".$viewstatut;
458
+    $sql.= " AND e.fk_statut = ".$viewstatut;
459 459
 }
460 460
 if ($search_billed != '' && $search_billed >= 0) $sql.=' AND e.billed = '.$search_billed;
461 461
 if ($search_town)  $sql.= natural_search('s.town', $search_town);
@@ -502,47 +502,47 @@  discard block
 block discarded – undo
502 502
 $resql=$db->query($sql);
503 503
 if ($resql)
504 504
 {
505
-	$num = $db->num_rows($resql);
505
+    $num = $db->num_rows($resql);
506 506
 
507
-	$reception = new Reception($db);
507
+    $reception = new Reception($db);
508 508
 
509
-	$arrayofselected=is_array($toselect)?$toselect:array();
509
+    $arrayofselected=is_array($toselect)?$toselect:array();
510 510
 
511
-	$param='';
511
+    $param='';
512 512
     if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
513
-	if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
514
-	if ($sall) $param.= "&amp;sall=".$sall;
515
-	if ($search_ref_rcp) $param.= "&amp;search_ref_rcp=".$search_ref_rcp;
516
-	if ($search_ref_liv) $param.= "&amp;search_ref_liv=".$search_ref_liv;
517
-	if ($search_company) $param.= "&amp;search_company=".$search_company;
518
-	if ($optioncss != '') $param.='&amp;optioncss='.$optioncss;
519
-	if ($search_billed != '' && $search_billed >= 0)$param.= "&amp;search_billed=".$search_billed;
520
-	if ($search_town)  $param.= "&amp;search_town=".$search_town;
521
-	if ($search_zip)  $param.= "&amp;search_zip=".$search_zip;
522
-	if ($search_state) $param.= "&amp;search_state=".$search_state;
523
-	if ($viewstatut) $param.= "&amp;viewstatut=".$viewstatut;
524
-	if ($search_country) $param.= "&amp;search_country=".$search_country;
525
-	if ($search_type_thirdparty) $param.= "&amp;search_type_thirdparty=".$search_type_thirdparty;
526
-	if ($search_ref_supplier) $param.= "&amp;search_ref_supplier=".$search_ref_supplier;
527
-	// Add $param from extra fields
528
-	foreach ($search_array_options as $key => $val)
529
-	{
530
-	    $crit=$val;
531
-	    $tmpkey=preg_replace('/search_options_/','',$key);
532
-	    if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
533
-	}
534
-
535
-
536
-	$arrayofmassactions =  array(
513
+    if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
514
+    if ($sall) $param.= "&amp;sall=".$sall;
515
+    if ($search_ref_rcp) $param.= "&amp;search_ref_rcp=".$search_ref_rcp;
516
+    if ($search_ref_liv) $param.= "&amp;search_ref_liv=".$search_ref_liv;
517
+    if ($search_company) $param.= "&amp;search_company=".$search_company;
518
+    if ($optioncss != '') $param.='&amp;optioncss='.$optioncss;
519
+    if ($search_billed != '' && $search_billed >= 0)$param.= "&amp;search_billed=".$search_billed;
520
+    if ($search_town)  $param.= "&amp;search_town=".$search_town;
521
+    if ($search_zip)  $param.= "&amp;search_zip=".$search_zip;
522
+    if ($search_state) $param.= "&amp;search_state=".$search_state;
523
+    if ($viewstatut) $param.= "&amp;viewstatut=".$viewstatut;
524
+    if ($search_country) $param.= "&amp;search_country=".$search_country;
525
+    if ($search_type_thirdparty) $param.= "&amp;search_type_thirdparty=".$search_type_thirdparty;
526
+    if ($search_ref_supplier) $param.= "&amp;search_ref_supplier=".$search_ref_supplier;
527
+    // Add $param from extra fields
528
+    foreach ($search_array_options as $key => $val)
529
+    {
530
+        $crit=$val;
531
+        $tmpkey=preg_replace('/search_options_/','',$key);
532
+        if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
533
+    }
534
+
535
+
536
+    $arrayofmassactions =  array(
537 537
 //    'presend'=>$langs->trans("SendByMail"),
538 538
 );
539 539
 
540
-	if($user->rights->fournisseur->facture->creer)$arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisSupplier");
541
-	if($massaction == 'createbills') $arrayofmassactions=array();
542
-	$massactionbutton=$form->selectMassAction('', $arrayofmassactions);
543
-	//$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
540
+    if($user->rights->fournisseur->facture->creer)$arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisSupplier");
541
+    if($massaction == 'createbills') $arrayofmassactions=array();
542
+    $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
543
+    //$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
544 544
 
545
-	$i = 0;
545
+    $i = 0;
546 546
     print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
547 547
     if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
548 548
     print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -552,56 +552,56 @@  discard block
 block discarded – undo
552 552
     print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
553 553
     print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
554 554
 
555
-	print_barre_liste($langs->trans('ListOfReceptions'), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,$massactionbutton,$num, $nbtotalofrecords, '', 0, '', '', $limit);
556
-
557
-
558
-	if ($massaction == 'createbills')
559
-	{
560
-		//var_dump($_REQUEST);
561
-		print '<input type="hidden" name="massaction" value="confirm_createbills">';
562
-
563
-		print '<table class="noborder" width="100%" >';
564
-		print '<tr>';
565
-		print '<td class="titlefieldmiddle">';
566
-		print $langs->trans('DateInvoice');
567
-		print '</td>';
568
-		print '<td>';
569
-		print $form->select_date('', '', '', '', '', '', 1, 1);
570
-		print '</td>';
571
-		print '</tr>';
572
-		print '<tr>';
573
-		print '<td>';
574
-		print $langs->trans('CreateOneBillByThird');
575
-		print '</td>';
576
-		print '<td>';
577
-		print $form->selectyesno('createbills_onebythird', '', 1);
578
-		print '</td>';
579
-		print '</tr>';
580
-		print '<tr>';
581
-		print '<td>';
582
-		print $langs->trans('ValidateInvoices');
583
-		print '</td>';
584
-		print '<td>';
585
-		if (! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_BILL))
586
-		{
587
-		    print $form->selectyesno('valdate_invoices', 0, 1, 1);
588
-		    print ' ('.$langs->trans("AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation").')';
589
-		}
590
-		else
591
-		{
555
+    print_barre_liste($langs->trans('ListOfReceptions'), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,$massactionbutton,$num, $nbtotalofrecords, '', 0, '', '', $limit);
556
+
557
+
558
+    if ($massaction == 'createbills')
559
+    {
560
+        //var_dump($_REQUEST);
561
+        print '<input type="hidden" name="massaction" value="confirm_createbills">';
562
+
563
+        print '<table class="noborder" width="100%" >';
564
+        print '<tr>';
565
+        print '<td class="titlefieldmiddle">';
566
+        print $langs->trans('DateInvoice');
567
+        print '</td>';
568
+        print '<td>';
569
+        print $form->select_date('', '', '', '', '', '', 1, 1);
570
+        print '</td>';
571
+        print '</tr>';
572
+        print '<tr>';
573
+        print '<td>';
574
+        print $langs->trans('CreateOneBillByThird');
575
+        print '</td>';
576
+        print '<td>';
577
+        print $form->selectyesno('createbills_onebythird', '', 1);
578
+        print '</td>';
579
+        print '</tr>';
580
+        print '<tr>';
581
+        print '<td>';
582
+        print $langs->trans('ValidateInvoices');
583
+        print '</td>';
584
+        print '<td>';
585
+        if (! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_BILL))
586
+        {
587
+            print $form->selectyesno('valdate_invoices', 0, 1, 1);
588
+            print ' ('.$langs->trans("AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation").')';
589
+        }
590
+        else
591
+        {
592 592
             print $form->selectyesno('valdate_invoices', 0, 1);
593
-		}
594
-		print '</td>';
595
-		print '</tr>';
596
-		print '</table>';
597
-
598
-		print '<br>';
599
-		print '<div class="center">';
600
-		print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisSupplier').'">  ';
601
-		print '<input type="submit" class="button" id="cancel" name="cancel" value="'.$langs->trans('Cancel').'">';
602
-		print '</div>';
603
-		print '<br>';
604
-	}
593
+        }
594
+        print '</td>';
595
+        print '</tr>';
596
+        print '</table>';
597
+
598
+        print '<br>';
599
+        print '<div class="center">';
600
+        print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisSupplier').'">  ';
601
+        print '<input type="submit" class="button" id="cancel" name="cancel" value="'.$langs->trans('Cancel').'">';
602
+        print '</div>';
603
+        print '<br>';
604
+    }
605 605
 
606 606
     if ($sall)
607 607
     {
@@ -622,282 +622,282 @@  discard block
 block discarded – undo
622 622
 
623 623
     $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
624 624
     $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);	// This also change content of $arrayfields
625
-	$selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
625
+    $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
626 626
 
627 627
 
628 628
     print '<div class="div-table-responsive">';
629 629
     print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
630 630
 
631
-	// Lignes des champs de filtre
632
-	print '<tr class="liste_titre_filter">';
633
-	// Ref
634
-	if (! empty($arrayfields['e.ref']['checked']))
635
-	{
636
-	    print '<td class="liste_titre">';
637
-    	print '<input class="flat" size="6" type="text" name="search_ref_rcp" value="'.$search_ref_rcp.'">';
631
+    // Lignes des champs de filtre
632
+    print '<tr class="liste_titre_filter">';
633
+    // Ref
634
+    if (! empty($arrayfields['e.ref']['checked']))
635
+    {
636
+        print '<td class="liste_titre">';
637
+        print '<input class="flat" size="6" type="text" name="search_ref_rcp" value="'.$search_ref_rcp.'">';
638
+        print '</td>';
639
+    }
640
+    // Ref customer
641
+    if (! empty($arrayfields['e.ref_supplier']['checked']))
642
+    {
643
+        print '<td class="liste_titre">';
644
+        print '<input class="flat" size="6" type="text" name="search_ref_supplier" value="'.$search_ref_supplier.'">';
638 645
         print '</td>';
639
-	}
640
-	// Ref customer
641
-	if (! empty($arrayfields['e.ref_supplier']['checked']))
642
-	{
643
-	    print '<td class="liste_titre">';
644
-    	print '<input class="flat" size="6" type="text" name="search_ref_supplier" value="'.$search_ref_supplier.'">';
646
+    }
647
+    // Thirdparty
648
+    if (! empty($arrayfields['s.nom']['checked']))
649
+    {
650
+        print '<td class="liste_titre" align="left">';
651
+        print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
645 652
         print '</td>';
646
-	}
647
-	// Thirdparty
648
-	if (! empty($arrayfields['s.nom']['checked']))
649
-	{
650
-    	print '<td class="liste_titre" align="left">';
651
-    	print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
652
-    	print '</td>';
653
-	}
654
-	// Town
655
-	if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
656
-	// Zip
657
-	if (! empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
658
-	// State
653
+    }
654
+    // Town
655
+    if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
656
+    // Zip
657
+    if (! empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
658
+    // State
659 659
     if (! empty($arrayfields['state.nom']['checked']))
660 660
     {
661 661
         print '<td class="liste_titre">';
662
-    	print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
663
-    	print '</td>';
662
+        print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
663
+        print '</td>';
664 664
     }
665 665
     // Country
666 666
     if (! empty($arrayfields['country.code_iso']['checked']))
667 667
     {
668 668
         print '<td class="liste_titre" align="center">';
669
-    	print $form->select_country($search_country,'search_country','',0,'maxwidth100');
670
-    	print '</td>';
669
+        print $form->select_country($search_country,'search_country','',0,'maxwidth100');
670
+        print '</td>';
671 671
     }
672
-	// Company type
672
+    // Company type
673 673
     if (! empty($arrayfields['typent.code']['checked']))
674 674
     {
675 675
         print '<td class="liste_titre maxwidthonsmartphone" align="center">';
676
-    	print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
677
-    	print '</td>';
676
+        print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
677
+        print '</td>';
678
+    }
679
+    // Date delivery planned
680
+    if (! empty($arrayfields['e.date_delivery']['checked']))
681
+    {
682
+        print '<td class="liste_titre">&nbsp;</td>';
683
+    }
684
+    if (! empty($arrayfields['l.ref']['checked']))
685
+    {
686
+        // Delivery ref
687
+        print '<td class="liste_titre">';
688
+        print '<input class="flat" size="10" type="text" name="search_ref_liv" value="'.$search_ref_liv.'"';
689
+        print '</td>';
690
+    }
691
+    if (! empty($arrayfields['l.date_delivery']['checked']))
692
+    {
693
+        // Date received
694
+        print '<td class="liste_titre">&nbsp;</td>';
695
+    }
696
+    // Extra fields
697
+    if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
698
+    {
699
+        foreach($extrafields->attribute_label as $key => $val)
700
+        {
701
+            if (! empty($arrayfields["ef.".$key]['checked']))
702
+            {
703
+                $align=$extrafields->getAlignFlag($key);
704
+                $typeofextrafield=$extrafields->attribute_type[$key];
705
+                print '<td class="liste_titre'.($align?' '.$align:'').'">';
706
+                if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
707
+                {
708
+                    $crit=$val;
709
+                    $tmpkey=preg_replace('/search_options_/','',$key);
710
+                    $searchclass='';
711
+                    if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
712
+                    if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
713
+                    print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
714
+                }
715
+                print '</td>';
716
+            }
717
+        }
718
+    }
719
+    // Fields from hook
720
+    $parameters=array('arrayfields'=>$arrayfields);
721
+    $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters);    // Note that $action and $object may have been modified by hook
722
+    print $hookmanager->resPrint;
723
+    // Date creation
724
+    if (! empty($arrayfields['e.datec']['checked']))
725
+    {
726
+        print '<td class="liste_titre">';
727
+        print '</td>';
728
+    }
729
+    // Date modification
730
+    if (! empty($arrayfields['e.tms']['checked']))
731
+    {
732
+        print '<td class="liste_titre">';
733
+        print '</td>';
734
+    }
735
+    // Status
736
+    if (! empty($arrayfields['e.fk_statut']['checked']))
737
+    {
738
+        print '<td class="liste_titre maxwidthonsmartphone" align="right">';
739
+        print $form->selectarray('viewstatut', array('0'=>$langs->trans('StatusReceptionDraftShort'),'1'=>$langs->trans('StatusReceptionValidatedShort'),'2'=>$langs->trans('StatusReceptionProcessedShort')),$viewstatut,1);
740
+        print '</td>';
741
+    }
742
+    // Status billed
743
+    if (! empty($arrayfields['e.billed']['checked']))
744
+    {
745
+        print '<td class="liste_titre maxwidthonsmartphone" align="center">';
746
+        print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);
747
+        print '</td>';
678 748
     }
679
-	// Date delivery planned
680
-	if (! empty($arrayfields['e.date_delivery']['checked']))
681
-	{
682
-    	print '<td class="liste_titre">&nbsp;</td>';
683
-	}
684
-	if (! empty($arrayfields['l.ref']['checked']))
685
-	{
686
-    	// Delivery ref
687
-		print '<td class="liste_titre">';
688
-		print '<input class="flat" size="10" type="text" name="search_ref_liv" value="'.$search_ref_liv.'"';
689
-		print '</td>';
690
-	}
691
-	if (! empty($arrayfields['l.date_delivery']['checked']))
692
-	{
693
-	    // Date received
694
-		print '<td class="liste_titre">&nbsp;</td>';
695
-	}
696
-	// Extra fields
697
-	if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
698
-	{
699
-	    foreach($extrafields->attribute_label as $key => $val)
700
-	    {
701
-	        if (! empty($arrayfields["ef.".$key]['checked']))
702
-	        {
703
-	            $align=$extrafields->getAlignFlag($key);
704
-	            $typeofextrafield=$extrafields->attribute_type[$key];
705
-	            print '<td class="liste_titre'.($align?' '.$align:'').'">';
706
-	            if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
707
-	            {
708
-	                $crit=$val;
709
-	                $tmpkey=preg_replace('/search_options_/','',$key);
710
-	                $searchclass='';
711
-	                if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
712
-	                if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
713
-	                print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
714
-	            }
715
-	            print '</td>';
716
-	        }
717
-	    }
718
-	}
719
-	// Fields from hook
720
-	$parameters=array('arrayfields'=>$arrayfields);
721
-	$reshook=$hookmanager->executeHooks('printFieldListOption',$parameters);    // Note that $action and $object may have been modified by hook
722
-	print $hookmanager->resPrint;
723
-	// Date creation
724
-	if (! empty($arrayfields['e.datec']['checked']))
725
-	{
726
-	    print '<td class="liste_titre">';
727
-	    print '</td>';
728
-	}
729
-	// Date modification
730
-	if (! empty($arrayfields['e.tms']['checked']))
731
-	{
732
-	    print '<td class="liste_titre">';
733
-	    print '</td>';
734
-	}
735
-	// Status
736
-	if (! empty($arrayfields['e.fk_statut']['checked']))
737
-	{
738
-	    print '<td class="liste_titre maxwidthonsmartphone" align="right">';
739
-	    print $form->selectarray('viewstatut', array('0'=>$langs->trans('StatusReceptionDraftShort'),'1'=>$langs->trans('StatusReceptionValidatedShort'),'2'=>$langs->trans('StatusReceptionProcessedShort')),$viewstatut,1);
740
-	    print '</td>';
741
-	}
742
-	// Status billed
743
-	if (! empty($arrayfields['e.billed']['checked']))
744
-	{
745
-	    print '<td class="liste_titre maxwidthonsmartphone" align="center">';
746
-	    print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);
747
-	    print '</td>';
748
-	}
749
-	// Action column
750
-	print '<td class="liste_titre" align="middle">';
751
-	$searchpicto=$form->showFilterAndCheckAddButtons(0);
752
-	print $searchpicto;
749
+    // Action column
750
+    print '<td class="liste_titre" align="middle">';
751
+    $searchpicto=$form->showFilterAndCheckAddButtons(0);
752
+    print $searchpicto;
753 753
     print '</td>';
754
-	print "</tr>\n";
755
-
756
-	print '<tr class="liste_titre">';
757
-	if (! empty($arrayfields['e.ref']['checked']))            print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"],"e.ref","",$param,'',$sortfield,$sortorder);
758
-	if (! empty($arrayfields['e.ref_supplier']['checked']))   print_liste_field_titre($arrayfields['e.ref_supplier']['label'], $_SERVER["PHP_SELF"],"e.ref_supplier","",$param,'',$sortfield,$sortorder);
759
-	if (! empty($arrayfields['s.nom']['checked']))            print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"],"s.nom", "", $param,'align="left"',$sortfield,$sortorder);
760
-	if (! empty($arrayfields['s.town']['checked']))           print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
761
-	if (! empty($arrayfields['s.zip']['checked']))            print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
762
-	if (! empty($arrayfields['state.nom']['checked']))        print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
763
-	if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
764
-	if (! empty($arrayfields['typent.code']['checked']))      print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
765
-	if (! empty($arrayfields['e.date_delivery']['checked']))  print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"],"e.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
766
-	if (! empty($arrayfields['l.ref']['checked']))            print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"],"l.ref","",$param, '',$sortfield,$sortorder);
767
-	if (! empty($arrayfields['l.date_delivery']['checked']))  print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"],"l.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
768
-	// Extra fields
769
-	if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
770
-	{
771
-	    foreach($extrafields->attribute_label as $key => $val)
772
-	    {
773
-	        if (! empty($arrayfields["ef.".$key]['checked']))
774
-	        {
775
-	            $align=$extrafields->getAlignFlag($key);
776
-    			$sortonfield = "ef.".$key;
777
-    			if (! empty($extrafields->attribute_computed[$key])) $sortonfield='';
778
-    			print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
779
-	        }
780
-	    }
781
-	}
782
-	// Hook fields
783
-	$parameters=array('arrayfields'=>$arrayfields);
784
-	$reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters);    // Note that $action and $object may have been modified by hook
785
-	print $hookmanager->resPrint;
786
-	if (! empty($arrayfields['e.datec']['checked']))  print_liste_field_titre($arrayfields['e.datec']['label'],$_SERVER["PHP_SELF"],"e.date_creation","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
787
-	if (! empty($arrayfields['e.tms']['checked']))    print_liste_field_titre($arrayfields['e.tms']['label'],$_SERVER["PHP_SELF"],"e.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
788
-	if (! empty($arrayfields['e.fk_statut']['checked'])) print_liste_field_titre($arrayfields['e.fk_statut']['label'],$_SERVER["PHP_SELF"],"e.fk_statut","",$param,'align="right"',$sortfield,$sortorder);
789
-	if (! empty($arrayfields['e.billed']['checked'])) print_liste_field_titre($arrayfields['e.billed']['label'],$_SERVER["PHP_SELF"],"e.billed","",$param,'align="center"',$sortfield,$sortorder);
790
-	print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
791
-	print "</tr>\n";
792
-
793
-	$i=0;
794
-	$var=true;
795
-	$totalarray=array();
796
-	while ($i < min($num,$limit))
797
-	{
798
-		$obj = $db->fetch_object($resql);
799
-
800
-    	$reception->id=$obj->rowid;
801
-    	$reception->ref=$obj->ref;
802
-
803
-    	$companystatic->id=$obj->socid;
804
-    	$companystatic->ref=$obj->name;
805
-    	$companystatic->name=$obj->name;
806
-
807
-
808
-    	print '<tr class="oddeven">';
809
-
810
-		// Ref
811
-		if (! empty($arrayfields['e.ref']['checked']))
812
-		{
813
-    		print "<td>";
814
-    		print $reception->getNomUrl(1);
815
-    		$filename=dol_sanitizeFileName($reception->ref);
816
-    		$filedir=$conf->reception->dir_output . '/' . dol_sanitizeFileName($reception->ref);
817
-    		$urlsource=$_SERVER['PHP_SELF'].'?id='.$reception->rowid;
818
-    		print $formfile->getDocumentsLink($reception->element, $filename, $filedir);
819
-    		print "</td>\n";
820
-
821
-    		if (! $i) $totalarray['nbfield']++;
822
-		}
823
-
824
-		// Ref customer
825
-		if (! empty($arrayfields['e.ref_supplier']['checked']))
826
-		{
827
-		    print "<td>";
828
-		    print $obj->ref_supplier;
829
-		    print "</td>\n";
830
-		    if (! $i) $totalarray['nbfield']++;
831
-		}
832
-
833
-		// Third party
834
-		if (! empty($arrayfields['s.nom']['checked']))
835
-		{
836
-    		print '<td>';
837
-    		print $companystatic->getNomUrl(1);
838
-    		print '</td>';
839
-    		if (! $i) $totalarray['nbfield']++;
840
-		}
841
-		// Town
842
-		if (! empty($arrayfields['s.town']['checked']))
843
-		{
844
-		    print '<td class="nocellnopadd">';
845
-		    print $obj->town;
846
-		    print '</td>';
847
-		    if (! $i) $totalarray['nbfield']++;
848
-		}
849
-		// Zip
850
-		if (! empty($arrayfields['s.zip']['checked']))
851
-		{
852
-		    print '<td class="nocellnopadd">';
853
-		    print $obj->zip;
854
-		    print '</td>';
855
-		    if (! $i) $totalarray['nbfield']++;
856
-		}
857
-		// State
858
-		if (! empty($arrayfields['state.nom']['checked']))
859
-		{
860
-		    print "<td>".$obj->state_name."</td>\n";
861
-		    if (! $i) $totalarray['nbfield']++;
862
-		}
863
-		// Country
864
-		if (! empty($arrayfields['country.code_iso']['checked']))
865
-		{
866
-		    print '<td align="center">';
867
-		    $tmparray=getCountry($obj->fk_pays,'all');
868
-		    print $tmparray['label'];
869
-		    print '</td>';
870
-		    if (! $i) $totalarray['nbfield']++;
871
-		}
872
-		// Type ent
873
-		if (! empty($arrayfields['typent.code']['checked']))
874
-		{
875
-		    print '<td align="center">';
876
-		    if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
877
-		    print $typenArray[$obj->typent_code];
878
-		    print '</td>';
879
-		    if (! $i) $totalarray['nbfield']++;
880
-		}
881
-
882
-		// Date delivery planed
883
-		if (! empty($arrayfields['e.date_delivery']['checked']))
884
-		{
885
-    		print '<td align="center">';
886
-    		print dol_print_date($db->jdate($obj->date_livraison),"day");
887
-    		/*$now = time();
754
+    print "</tr>\n";
755
+
756
+    print '<tr class="liste_titre">';
757
+    if (! empty($arrayfields['e.ref']['checked']))            print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"],"e.ref","",$param,'',$sortfield,$sortorder);
758
+    if (! empty($arrayfields['e.ref_supplier']['checked']))   print_liste_field_titre($arrayfields['e.ref_supplier']['label'], $_SERVER["PHP_SELF"],"e.ref_supplier","",$param,'',$sortfield,$sortorder);
759
+    if (! empty($arrayfields['s.nom']['checked']))            print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"],"s.nom", "", $param,'align="left"',$sortfield,$sortorder);
760
+    if (! empty($arrayfields['s.town']['checked']))           print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
761
+    if (! empty($arrayfields['s.zip']['checked']))            print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
762
+    if (! empty($arrayfields['state.nom']['checked']))        print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
763
+    if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
764
+    if (! empty($arrayfields['typent.code']['checked']))      print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
765
+    if (! empty($arrayfields['e.date_delivery']['checked']))  print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"],"e.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
766
+    if (! empty($arrayfields['l.ref']['checked']))            print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"],"l.ref","",$param, '',$sortfield,$sortorder);
767
+    if (! empty($arrayfields['l.date_delivery']['checked']))  print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"],"l.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
768
+    // Extra fields
769
+    if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
770
+    {
771
+        foreach($extrafields->attribute_label as $key => $val)
772
+        {
773
+            if (! empty($arrayfields["ef.".$key]['checked']))
774
+            {
775
+                $align=$extrafields->getAlignFlag($key);
776
+                $sortonfield = "ef.".$key;
777
+                if (! empty($extrafields->attribute_computed[$key])) $sortonfield='';
778
+                print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
779
+            }
780
+        }
781
+    }
782
+    // Hook fields
783
+    $parameters=array('arrayfields'=>$arrayfields);
784
+    $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters);    // Note that $action and $object may have been modified by hook
785
+    print $hookmanager->resPrint;
786
+    if (! empty($arrayfields['e.datec']['checked']))  print_liste_field_titre($arrayfields['e.datec']['label'],$_SERVER["PHP_SELF"],"e.date_creation","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
787
+    if (! empty($arrayfields['e.tms']['checked']))    print_liste_field_titre($arrayfields['e.tms']['label'],$_SERVER["PHP_SELF"],"e.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
788
+    if (! empty($arrayfields['e.fk_statut']['checked'])) print_liste_field_titre($arrayfields['e.fk_statut']['label'],$_SERVER["PHP_SELF"],"e.fk_statut","",$param,'align="right"',$sortfield,$sortorder);
789
+    if (! empty($arrayfields['e.billed']['checked'])) print_liste_field_titre($arrayfields['e.billed']['label'],$_SERVER["PHP_SELF"],"e.billed","",$param,'align="center"',$sortfield,$sortorder);
790
+    print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
791
+    print "</tr>\n";
792
+
793
+    $i=0;
794
+    $var=true;
795
+    $totalarray=array();
796
+    while ($i < min($num,$limit))
797
+    {
798
+        $obj = $db->fetch_object($resql);
799
+
800
+        $reception->id=$obj->rowid;
801
+        $reception->ref=$obj->ref;
802
+
803
+        $companystatic->id=$obj->socid;
804
+        $companystatic->ref=$obj->name;
805
+        $companystatic->name=$obj->name;
806
+
807
+
808
+        print '<tr class="oddeven">';
809
+
810
+        // Ref
811
+        if (! empty($arrayfields['e.ref']['checked']))
812
+        {
813
+            print "<td>";
814
+            print $reception->getNomUrl(1);
815
+            $filename=dol_sanitizeFileName($reception->ref);
816
+            $filedir=$conf->reception->dir_output . '/' . dol_sanitizeFileName($reception->ref);
817
+            $urlsource=$_SERVER['PHP_SELF'].'?id='.$reception->rowid;
818
+            print $formfile->getDocumentsLink($reception->element, $filename, $filedir);
819
+            print "</td>\n";
820
+
821
+            if (! $i) $totalarray['nbfield']++;
822
+        }
823
+
824
+        // Ref customer
825
+        if (! empty($arrayfields['e.ref_supplier']['checked']))
826
+        {
827
+            print "<td>";
828
+            print $obj->ref_supplier;
829
+            print "</td>\n";
830
+            if (! $i) $totalarray['nbfield']++;
831
+        }
832
+
833
+        // Third party
834
+        if (! empty($arrayfields['s.nom']['checked']))
835
+        {
836
+            print '<td>';
837
+            print $companystatic->getNomUrl(1);
838
+            print '</td>';
839
+            if (! $i) $totalarray['nbfield']++;
840
+        }
841
+        // Town
842
+        if (! empty($arrayfields['s.town']['checked']))
843
+        {
844
+            print '<td class="nocellnopadd">';
845
+            print $obj->town;
846
+            print '</td>';
847
+            if (! $i) $totalarray['nbfield']++;
848
+        }
849
+        // Zip
850
+        if (! empty($arrayfields['s.zip']['checked']))
851
+        {
852
+            print '<td class="nocellnopadd">';
853
+            print $obj->zip;
854
+            print '</td>';
855
+            if (! $i) $totalarray['nbfield']++;
856
+        }
857
+        // State
858
+        if (! empty($arrayfields['state.nom']['checked']))
859
+        {
860
+            print "<td>".$obj->state_name."</td>\n";
861
+            if (! $i) $totalarray['nbfield']++;
862
+        }
863
+        // Country
864
+        if (! empty($arrayfields['country.code_iso']['checked']))
865
+        {
866
+            print '<td align="center">';
867
+            $tmparray=getCountry($obj->fk_pays,'all');
868
+            print $tmparray['label'];
869
+            print '</td>';
870
+            if (! $i) $totalarray['nbfield']++;
871
+        }
872
+        // Type ent
873
+        if (! empty($arrayfields['typent.code']['checked']))
874
+        {
875
+            print '<td align="center">';
876
+            if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
877
+            print $typenArray[$obj->typent_code];
878
+            print '</td>';
879
+            if (! $i) $totalarray['nbfield']++;
880
+        }
881
+
882
+        // Date delivery planed
883
+        if (! empty($arrayfields['e.date_delivery']['checked']))
884
+        {
885
+            print '<td align="center">';
886
+            print dol_print_date($db->jdate($obj->date_livraison),"day");
887
+            /*$now = time();
888 888
     		if ( ($now - $db->jdate($obj->date_reception)) > $conf->warnings->lim && $obj->statutid == 1 )
889 889
     		{
890 890
     		}*/
891
-    		print "</td>\n";
892
-		}
891
+            print "</td>\n";
892
+        }
893 893
 
894
-		if (! empty($arrayfields['l.ref']['checked']) || ! empty($arrayfields['l.date_delivery']['checked']))
894
+        if (! empty($arrayfields['l.ref']['checked']) || ! empty($arrayfields['l.date_delivery']['checked']))
895 895
         {
896
-		    $reception->fetchObjectLinked($reception->id,$reception->element);
896
+            $reception->fetchObjectLinked($reception->id,$reception->element);
897 897
             $receiving='';
898 898
             if (count($reception->linkedObjects['delivery']) > 0) $receiving=reset($reception->linkedObjects['delivery']);
899 899
 
900
-    		if (! empty($arrayfields['l.ref']['checked']))
900
+            if (! empty($arrayfields['l.ref']['checked']))
901 901
             {
902 902
                 // Ref
903 903
                 print '<td>';
@@ -905,90 +905,90 @@  discard block
 block discarded – undo
905 905
                 print '</td>';
906 906
             }
907 907
 
908
-    		if (! empty($arrayfields['l.date_delivery']['checked']))
908
+            if (! empty($arrayfields['l.date_delivery']['checked']))
909 909
             {
910 910
                 // Date received
911
-            	print '<td align="center">';
912
-    			print dol_print_date($db->jdate($obj->date_reception),"day");
913
-    			print '</td>'."\n";
911
+                print '<td align="center">';
912
+                print dol_print_date($db->jdate($obj->date_reception),"day");
913
+                print '</td>'."\n";
914 914
             }
915
-		}
916
-
917
-		// Extra fields
918
-		if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
919
-		{
920
-		    foreach($extrafields->attribute_label as $key => $val)
921
-		    {
922
-		        if (! empty($arrayfields["ef.".$key]['checked']))
923
-		        {
924
-		            print '<td class="tdofextrafield"';
925
-		            $align=$extrafields->getAlignFlag($key);
926
-		            if ($align) print ' align="'.$align.'"';
927
-		            print '>';
928
-		            $tmpkey='options_'.$key;
929
-		            print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
930
-		            print '</td>';
931
-		            if (! $i) $totalarray['nbfield']++;
932
-		        }
933
-		    }
934
-		}
935
-		// Fields from hook
936
-		$parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
937
-		$reshook=$hookmanager->executeHooks('printFieldListValue',$parameters);    // Note that $action and $object may have been modified by hook
938
-		print $hookmanager->resPrint;
939
-		// Date creation
940
-		if (! empty($arrayfields['e.datec']['checked']))
941
-		{
942
-		    print '<td align="center" class="nowrap">';
943
-		    print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
944
-		    print '</td>';
945
-		    if (! $i) $totalarray['nbfield']++;
946
-		}
947
-		// Date modification
948
-		if (! empty($arrayfields['e.tms']['checked']))
949
-		{
950
-		    print '<td align="center" class="nowrap">';
951
-		    print dol_print_date($db->jdate($obj->date_update), 'dayhour');
952
-		    print '</td>';
953
-		    if (! $i) $totalarray['nbfield']++;
954
-		}
955
-		// Status
956
-		if (! empty($arrayfields['e.fk_statut']['checked']))
957
-		{
958
-		    print '<td align="right" class="nowrap">'.$reception->LibStatut($obj->fk_statut,5).'</td>';
959
-		    if (! $i) $totalarray['nbfield']++;
960
-		}
961
-		// Billed
962
-		if (! empty($arrayfields['e.billed']['checked']))
963
-		{
964
-			print '<td align="center">'.yn($obj->billed).'</td>';
965
-			if (! $i) $totalarray['nbfield']++;
966
-		}
967
-
968
-		// Action column
969
-		print '<td align="center">';
970
-		if ($massactionbutton || $massaction)   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
915
+        }
916
+
917
+        // Extra fields
918
+        if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
919
+        {
920
+            foreach($extrafields->attribute_label as $key => $val)
921
+            {
922
+                if (! empty($arrayfields["ef.".$key]['checked']))
923
+                {
924
+                    print '<td class="tdofextrafield"';
925
+                    $align=$extrafields->getAlignFlag($key);
926
+                    if ($align) print ' align="'.$align.'"';
927
+                    print '>';
928
+                    $tmpkey='options_'.$key;
929
+                    print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
930
+                    print '</td>';
931
+                    if (! $i) $totalarray['nbfield']++;
932
+                }
933
+            }
934
+        }
935
+        // Fields from hook
936
+        $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
937
+        $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters);    // Note that $action and $object may have been modified by hook
938
+        print $hookmanager->resPrint;
939
+        // Date creation
940
+        if (! empty($arrayfields['e.datec']['checked']))
941
+        {
942
+            print '<td align="center" class="nowrap">';
943
+            print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
944
+            print '</td>';
945
+            if (! $i) $totalarray['nbfield']++;
946
+        }
947
+        // Date modification
948
+        if (! empty($arrayfields['e.tms']['checked']))
949
+        {
950
+            print '<td align="center" class="nowrap">';
951
+            print dol_print_date($db->jdate($obj->date_update), 'dayhour');
952
+            print '</td>';
953
+            if (! $i) $totalarray['nbfield']++;
954
+        }
955
+        // Status
956
+        if (! empty($arrayfields['e.fk_statut']['checked']))
957
+        {
958
+            print '<td align="right" class="nowrap">'.$reception->LibStatut($obj->fk_statut,5).'</td>';
959
+            if (! $i) $totalarray['nbfield']++;
960
+        }
961
+        // Billed
962
+        if (! empty($arrayfields['e.billed']['checked']))
963
+        {
964
+            print '<td align="center">'.yn($obj->billed).'</td>';
965
+            if (! $i) $totalarray['nbfield']++;
966
+        }
967
+
968
+        // Action column
969
+        print '<td align="center">';
970
+        if ($massactionbutton || $massaction)   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
971 971
         {
972 972
             $selected=0;
973
-    		if (in_array($obj->rowid, $arrayofselected)) $selected=1;
974
-    		print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
973
+            if (in_array($obj->rowid, $arrayofselected)) $selected=1;
974
+            print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
975 975
         }
976
-		print '</td>';
977
-		if (! $i) $totalarray['nbfield']++;
976
+        print '</td>';
977
+        if (! $i) $totalarray['nbfield']++;
978 978
 
979
-		print "</tr>\n";
979
+        print "</tr>\n";
980 980
 
981
-		$i++;
982
-	}
981
+        $i++;
982
+    }
983 983
 
984
-	print "</table>";
985
-	print "</div>";
986
-	print '</form>';
987
-	$db->free($resql);
984
+    print "</table>";
985
+    print "</div>";
986
+    print '</form>';
987
+    $db->free($resql);
988 988
 }
989 989
 else
990 990
 {
991
-	dol_print_error($db);
991
+    dol_print_error($db);
992 992
 }
993 993
 
994 994
 llxFooter();
Please login to merge, or discard this patch.
Braces   +290 added lines, -109 removed lines patch added patch discarded remove patch
@@ -45,7 +45,9 @@  discard block
 block discarded – undo
45 45
 
46 46
 // Security check
47 47
 $receptionid = GETPOST('id','int');
48
-if ($user->societe_id) $socid=$user->societe_id;
48
+if ($user->societe_id) {
49
+    $socid=$user->societe_id;
50
+}
49 51
 $result = restrictedArea($user, 'reception',$receptionid,'');
50 52
 
51 53
 $diroutputmassaction=$conf->reception->dir_output . '/temp/massgeneration/'.$user->id;
@@ -67,8 +69,12 @@  discard block
 block discarded – undo
67 69
 $sortfield = GETPOST('sortfield','alpha');
68 70
 $sortorder = GETPOST('sortorder','alpha');
69 71
 $page = GETPOST('page','int');
70
-if (! $sortfield) $sortfield="e.ref";
71
-if (! $sortorder) $sortorder="DESC";
72
+if (! $sortfield) {
73
+    $sortfield="e.ref";
74
+}
75
+if (! $sortorder) {
76
+    $sortorder="DESC";
77
+}
72 78
 if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
73 79
 $offset = $limit * $page;
74 80
 $pageprev = $page - 1;
@@ -93,7 +99,9 @@  discard block
 block discarded – undo
93 99
     's.nom'=>"ThirdParty",
94 100
     'e.note_public'=>'NotePublic',
95 101
 );
96
-if (empty($user->socid)) $fieldstosearchall["e.note_private"]="NotePrivate";
102
+if (empty($user->socid)) {
103
+    $fieldstosearchall["e.note_private"]="NotePrivate";
104
+}
97 105
 
98 106
 $checkedtypetiers=0;
99 107
 $arrayfields=array(
@@ -131,14 +139,18 @@  discard block
 block discarded – undo
131 139
 
132 140
 $parameters=array('socid'=>$socid);
133 141
 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
134
-if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
142
+if ($reshook < 0) {
143
+    setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
144
+}
135 145
 
136 146
 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
137 147
 
138 148
 // Purge search criteria
139
-if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
149
+if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) {
150
+    // All tests are required to be compatible with all browsers
140 151
 {
141 152
 	$search_ref_supplier='';
153
+}
142 154
     $search_ref_rcp='';
143 155
     $search_ref_liv='';
144 156
     $search_company='';
@@ -181,20 +193,26 @@  discard block
 block discarded – undo
181 193
     		$object = new FactureFournisseur($db);
182 194
     		if (!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])){
183 195
 				$object = $TFactThird[$rcp->socid]; // If option "one bill per third" is set, we use already created reception.
184
-				if(empty($object->rowid)&&$object->id != null)$object->rowid = $object->id;
185
-				if(!empty($object->rowid))$object->fetchObjectLinked();
196
+				if(empty($object->rowid)&&$object->id != null) {
197
+				    $object->rowid = $object->id;
198
+				}
199
+				if(!empty($object->rowid)) {
200
+				    $object->fetchObjectLinked();
201
+				}
186 202
 				$rcp->fetchObjectLinked();
187 203
 
188 204
 				if (count($rcp->linkedObjectsIds['order_supplier']) > 0)
189 205
 				{
190 206
 					foreach ($rcp->linkedObjectsIds['order_supplier'] as $key => $value)
191 207
 					{
192
-						if(empty($object->linkedObjectsIds['order_supplier']) || !in_array($value, $object->linkedObjectsIds['order_supplier']))//Dont try to link if already linked
193
-							$object->add_object_linked('order_supplier', $value); // add supplier order linked object
208
+						if(empty($object->linkedObjectsIds['order_supplier']) || !in_array($value, $object->linkedObjectsIds['order_supplier'])) {
209
+						    //Dont try to link if already linked
210
+							$object->add_object_linked('order_supplier', $value);
211
+						}
212
+						// add supplier order linked object
194 213
 					}
195 214
 				}
196
-			}
197
-    		else {
215
+			} else {
198 216
     			$object->socid = $rcp->socid;
199 217
     			$object->type = FactureFournisseur::TYPE_STANDARD;
200 218
     			$object->cond_reglement_id	= $rcp->thirdparty->cond_reglement_supplier_id;
@@ -230,7 +248,7 @@  discard block
 block discarded – undo
230 248
     			if($res > 0){
231 249
 					$nb_bills_created++;
232 250
 					$object->id = $res;
233
-				}else {
251
+				} else {
234 252
 					$errors[]=$rcp->ref.' : '.$langs->trans($object->error);
235 253
 					$error++;
236 254
 				}
@@ -279,28 +297,38 @@  discard block
 block discarded – undo
279 297
 	    					{
280 298
 	    						$result=$object->insert_discount($discountid);
281 299
 	    						//$result=$discount->link_to_invoice($lineid,$id);
282
-	    					}
283
-	    					else
300
+	    					} else
284 301
 	    					{
285 302
 	    						setEventMessages($discount->error, $discount->errors, 'errors');
286 303
 	    						$error++;
287 304
 	    						break;
288 305
 	    					}
289
-	    				}
290
-	    				else
306
+	    				} else
291 307
 	    				{
292 308
 	    					// Positive line
293 309
 	    					$product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
294 310
 	    					// Date start
295 311
 	    					$date_start=false;
296
-	    					if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue;
297
-	    					if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel;
298
-	    					if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start;
312
+	    					if ($lines[$i]->date_debut_prevue) {
313
+	    					    $date_start=$lines[$i]->date_debut_prevue;
314
+	    					}
315
+	    					if ($lines[$i]->date_debut_reel) {
316
+	    					    $date_start=$lines[$i]->date_debut_reel;
317
+	    					}
318
+	    					if ($lines[$i]->date_start) {
319
+	    					    $date_start=$lines[$i]->date_start;
320
+	    					}
299 321
 	    					//Date end
300 322
 	    					$date_end=false;
301
-	    					if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue;
302
-	    					if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel;
303
-	    					if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end;
323
+	    					if ($lines[$i]->date_fin_prevue) {
324
+	    					    $date_end=$lines[$i]->date_fin_prevue;
325
+	    					}
326
+	    					if ($lines[$i]->date_fin_reel) {
327
+	    					    $date_end=$lines[$i]->date_fin_reel;
328
+	    					}
329
+	    					if ($lines[$i]->date_end) {
330
+	    					    $date_end=$lines[$i]->date_end;
331
+	    					}
304 332
 	    					// Reset fk_parent_line for no child products and special product
305 333
 	    					if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9)
306 334
 	    					{
@@ -336,8 +364,7 @@  discard block
 block discarded – undo
336 364
 	    					if ($result > 0)
337 365
 	    					{
338 366
 	    						$lineid=$result;
339
-	    					}
340
-	    					else
367
+	    					} else
341 368
 	    					{
342 369
 	    						$lineid=0;
343 370
 	    						$error++;
@@ -355,8 +382,11 @@  discard block
 block discarded – undo
355 382
 
356 383
     		//$rcp->classifyBilled($user);        // Disabled. This behavior must be set or not using the workflow module.
357 384
 
358
-    		if(!empty($createbills_onebythird) && empty($TFactThird[$rcp->socid])) $TFactThird[$rcp->socid] = $object;
359
-    		else $TFact[$object->id] = $object;
385
+    		if(!empty($createbills_onebythird) && empty($TFactThird[$rcp->socid])) {
386
+    		    $TFactThird[$rcp->socid] = $object;
387
+    		} else {
388
+    		    $TFact[$object->id] = $object;
389
+    		}
360 390
     	}
361 391
 
362 392
     	// Build doc with all invoices
@@ -392,8 +422,7 @@  discard block
 block discarded – undo
392 422
     	{
393 423
     		$db->commit();
394 424
     		setEventMessage($langs->trans('BillCreated', $nb_bills_created));
395
-    	}
396
-    	else
425
+    	} else
397 426
     	{
398 427
 
399 428
     		$db->rollback();
@@ -427,27 +456,35 @@  discard block
 block discarded – undo
427 456
 $sql.= " state.code_departement as state_code, state.nom as state_name,";
428 457
 $sql.= ' e.date_creation as date_creation, e.tms as date_update';
429 458
 // Add fields from extrafields
430
-foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
459
+foreach ($extrafields->attribute_label as $key => $val) {
460
+    $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
461
+}
431 462
 // Add fields from hooks
432 463
 $parameters=array();
433 464
 $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters);    // Note that $action and $object may have been modified by hook
434 465
 $sql.=$hookmanager->resPrint;
435 466
 $sql.= " FROM ".MAIN_DB_PREFIX."reception as e";
436
-if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."reception_extrafields as ef on (e.rowid = ef.fk_object)";
467
+if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) {
468
+    $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."reception_extrafields as ef on (e.rowid = ef.fk_object)";
469
+}
437 470
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
438 471
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
439 472
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
440 473
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
441 474
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'reception' AND ee.targettype = 'delivery'";
442 475
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.rowid = ee.fk_target";
443
-if (!$user->rights->societe->client->voir && !$socid)	// Internal user with no permission to see all
476
+if (!$user->rights->societe->client->voir && !$socid) {
477
+    // Internal user with no permission to see all
444 478
 {
445 479
 	$sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
446 480
 }
481
+}
447 482
 $sql.= " WHERE e.entity IN (".getEntity('reception').")";
448
-if (!$user->rights->societe->client->voir && !$socid)	// Internal user with no permission to see all
483
+if (!$user->rights->societe->client->voir && !$socid) {
484
+    // Internal user with no permission to see all
449 485
 {
450 486
 	$sql.= " AND e.fk_soc = sc.fk_soc";
487
+}
451 488
 	$sql.= " AND sc.fk_user = " .$user->id;
452 489
 }
453 490
 if ($socid)
@@ -457,17 +494,39 @@  discard block
 block discarded – undo
457 494
 if ($viewstatut <> '' && $viewstatut >= 0) {
458 495
 	$sql.= " AND e.fk_statut = ".$viewstatut;
459 496
 }
460
-if ($search_billed != '' && $search_billed >= 0) $sql.=' AND e.billed = '.$search_billed;
461
-if ($search_town)  $sql.= natural_search('s.town', $search_town);
462
-if ($search_zip)   $sql.= natural_search("s.zip",$search_zip);
463
-if ($search_state) $sql.= natural_search("state.nom",$search_state);
464
-if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')';
465
-if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
466
-if ($search_ref_rcp) $sql .= natural_search('e.ref', $search_ref_rcp);
467
-if ($search_ref_liv) $sql .= natural_search('l.ref', $search_ref_liv);
468
-if ($search_company) $sql .= natural_search('s.nom', $search_company);
469
-if ($search_ref_supplier) $sql .= natural_search('e.ref_supplier', $search_ref_supplier);
470
-if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
497
+if ($search_billed != '' && $search_billed >= 0) {
498
+    $sql.=' AND e.billed = '.$search_billed;
499
+}
500
+if ($search_town) {
501
+    $sql.= natural_search('s.town', $search_town);
502
+}
503
+if ($search_zip) {
504
+    $sql.= natural_search("s.zip",$search_zip);
505
+}
506
+if ($search_state) {
507
+    $sql.= natural_search("state.nom",$search_state);
508
+}
509
+if ($search_country) {
510
+    $sql .= " AND s.fk_pays IN (".$search_country.')';
511
+}
512
+if ($search_type_thirdparty) {
513
+    $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
514
+}
515
+if ($search_ref_rcp) {
516
+    $sql .= natural_search('e.ref', $search_ref_rcp);
517
+}
518
+if ($search_ref_liv) {
519
+    $sql .= natural_search('l.ref', $search_ref_liv);
520
+}
521
+if ($search_company) {
522
+    $sql .= natural_search('s.nom', $search_company);
523
+}
524
+if ($search_ref_supplier) {
525
+    $sql .= natural_search('e.ref_supplier', $search_ref_supplier);
526
+}
527
+if ($sall) {
528
+    $sql .= natural_search(array_keys($fieldstosearchall), $sall);
529
+}
471 530
 
472 531
 // Add where from extra fields
473 532
 foreach ($search_array_options as $key => $val)
@@ -476,8 +535,14 @@  discard block
 block discarded – undo
476 535
     $tmpkey=preg_replace('/search_options_/','',$key);
477 536
     $typ=$extrafields->attribute_type[$tmpkey];
478 537
     $mode=0;
479
-    if (in_array($typ, array('int','double','real'))) $mode=1;    							// Search on a numeric
480
-    if (in_array($typ, array('sellist')) && $crit != '0' && $crit != '-1') $mode=2;    		// Search on a foreign key int
538
+    if (in_array($typ, array('int','double','real'))) {
539
+        $mode=1;
540
+    }
541
+    // Search on a numeric
542
+    if (in_array($typ, array('sellist')) && $crit != '0' && $crit != '-1') {
543
+        $mode=2;
544
+    }
545
+    // Search on a foreign key int
481 546
     if ($crit != '' && (! in_array($typ, array('select','sellist')) || $crit != '0'))
482 547
     {
483 548
         $sql .= natural_search('ef.'.$tmpkey, $crit, $mode);
@@ -509,27 +574,59 @@  discard block
 block discarded – undo
509 574
 	$arrayofselected=is_array($toselect)?$toselect:array();
510 575
 
511 576
 	$param='';
512
-    if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
513
-	if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
514
-	if ($sall) $param.= "&amp;sall=".$sall;
515
-	if ($search_ref_rcp) $param.= "&amp;search_ref_rcp=".$search_ref_rcp;
516
-	if ($search_ref_liv) $param.= "&amp;search_ref_liv=".$search_ref_liv;
517
-	if ($search_company) $param.= "&amp;search_company=".$search_company;
518
-	if ($optioncss != '') $param.='&amp;optioncss='.$optioncss;
519
-	if ($search_billed != '' && $search_billed >= 0)$param.= "&amp;search_billed=".$search_billed;
520
-	if ($search_town)  $param.= "&amp;search_town=".$search_town;
521
-	if ($search_zip)  $param.= "&amp;search_zip=".$search_zip;
522
-	if ($search_state) $param.= "&amp;search_state=".$search_state;
523
-	if ($viewstatut) $param.= "&amp;viewstatut=".$viewstatut;
524
-	if ($search_country) $param.= "&amp;search_country=".$search_country;
525
-	if ($search_type_thirdparty) $param.= "&amp;search_type_thirdparty=".$search_type_thirdparty;
526
-	if ($search_ref_supplier) $param.= "&amp;search_ref_supplier=".$search_ref_supplier;
577
+    if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
578
+        $param.='&contextpage='.$contextpage;
579
+    }
580
+	if ($limit > 0 && $limit != $conf->liste_limit) {
581
+	    $param.='&limit='.$limit;
582
+	}
583
+	if ($sall) {
584
+	    $param.= "&amp;sall=".$sall;
585
+	}
586
+	if ($search_ref_rcp) {
587
+	    $param.= "&amp;search_ref_rcp=".$search_ref_rcp;
588
+	}
589
+	if ($search_ref_liv) {
590
+	    $param.= "&amp;search_ref_liv=".$search_ref_liv;
591
+	}
592
+	if ($search_company) {
593
+	    $param.= "&amp;search_company=".$search_company;
594
+	}
595
+	if ($optioncss != '') {
596
+	    $param.='&amp;optioncss='.$optioncss;
597
+	}
598
+	if ($search_billed != '' && $search_billed >= 0) {
599
+	    $param.= "&amp;search_billed=".$search_billed;
600
+	}
601
+	if ($search_town) {
602
+	    $param.= "&amp;search_town=".$search_town;
603
+	}
604
+	if ($search_zip) {
605
+	    $param.= "&amp;search_zip=".$search_zip;
606
+	}
607
+	if ($search_state) {
608
+	    $param.= "&amp;search_state=".$search_state;
609
+	}
610
+	if ($viewstatut) {
611
+	    $param.= "&amp;viewstatut=".$viewstatut;
612
+	}
613
+	if ($search_country) {
614
+	    $param.= "&amp;search_country=".$search_country;
615
+	}
616
+	if ($search_type_thirdparty) {
617
+	    $param.= "&amp;search_type_thirdparty=".$search_type_thirdparty;
618
+	}
619
+	if ($search_ref_supplier) {
620
+	    $param.= "&amp;search_ref_supplier=".$search_ref_supplier;
621
+	}
527 622
 	// Add $param from extra fields
528 623
 	foreach ($search_array_options as $key => $val)
529 624
 	{
530 625
 	    $crit=$val;
531 626
 	    $tmpkey=preg_replace('/search_options_/','',$key);
532
-	    if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
627
+	    if ($val != '') {
628
+	        $param.='&search_options_'.$tmpkey.'='.urlencode($val);
629
+	    }
533 630
 	}
534 631
 
535 632
 
@@ -537,14 +634,20 @@  discard block
 block discarded – undo
537 634
 //    'presend'=>$langs->trans("SendByMail"),
538 635
 );
539 636
 
540
-	if($user->rights->fournisseur->facture->creer)$arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisSupplier");
541
-	if($massaction == 'createbills') $arrayofmassactions=array();
637
+	if($user->rights->fournisseur->facture->creer) {
638
+	    $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisSupplier");
639
+	}
640
+	if($massaction == 'createbills') {
641
+	    $arrayofmassactions=array();
642
+	}
542 643
 	$massactionbutton=$form->selectMassAction('', $arrayofmassactions);
543 644
 	//$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
544 645
 
545 646
 	$i = 0;
546 647
     print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
547
-    if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
648
+    if ($optioncss != '') {
649
+        print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
650
+    }
548 651
     print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
549 652
     print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
550 653
     print '<input type="hidden" name="action" value="list">';
@@ -586,8 +689,7 @@  discard block
 block discarded – undo
586 689
 		{
587 690
 		    print $form->selectyesno('valdate_invoices', 0, 1, 1);
588 691
 		    print ' ('.$langs->trans("AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation").')';
589
-		}
590
-		else
692
+		} else
591 693
 		{
592 694
             print $form->selectyesno('valdate_invoices', 0, 1);
593 695
 		}
@@ -605,7 +707,9 @@  discard block
 block discarded – undo
605 707
 
606 708
     if ($sall)
607 709
     {
608
-        foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
710
+        foreach($fieldstosearchall as $key => $val) {
711
+            $fieldstosearchall[$key]=$langs->trans($val);
712
+        }
609 713
         print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
610 714
     }
611 715
 
@@ -652,9 +756,13 @@  discard block
 block discarded – undo
652 756
     	print '</td>';
653 757
 	}
654 758
 	// Town
655
-	if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
759
+	if (! empty($arrayfields['s.town']['checked'])) {
760
+	    print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
761
+	}
656 762
 	// Zip
657
-	if (! empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
763
+	if (! empty($arrayfields['s.zip']['checked'])) {
764
+	    print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
765
+	}
658 766
 	// State
659 767
     if (! empty($arrayfields['state.nom']['checked']))
660 768
     {
@@ -708,8 +816,12 @@  discard block
 block discarded – undo
708 816
 	                $crit=$val;
709 817
 	                $tmpkey=preg_replace('/search_options_/','',$key);
710 818
 	                $searchclass='';
711
-	                if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
712
-	                if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
819
+	                if (in_array($typeofextrafield, array('varchar', 'select'))) {
820
+	                    $searchclass='searchstring';
821
+	                }
822
+	                if (in_array($typeofextrafield, array('int', 'double'))) {
823
+	                    $searchclass='searchnum';
824
+	                }
713 825
 	                print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
714 826
 	            }
715 827
 	            print '</td>';
@@ -754,17 +866,39 @@  discard block
 block discarded – undo
754 866
 	print "</tr>\n";
755 867
 
756 868
 	print '<tr class="liste_titre">';
757
-	if (! empty($arrayfields['e.ref']['checked']))            print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"],"e.ref","",$param,'',$sortfield,$sortorder);
758
-	if (! empty($arrayfields['e.ref_supplier']['checked']))   print_liste_field_titre($arrayfields['e.ref_supplier']['label'], $_SERVER["PHP_SELF"],"e.ref_supplier","",$param,'',$sortfield,$sortorder);
759
-	if (! empty($arrayfields['s.nom']['checked']))            print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"],"s.nom", "", $param,'align="left"',$sortfield,$sortorder);
760
-	if (! empty($arrayfields['s.town']['checked']))           print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
761
-	if (! empty($arrayfields['s.zip']['checked']))            print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
762
-	if (! empty($arrayfields['state.nom']['checked']))        print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
763
-	if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
764
-	if (! empty($arrayfields['typent.code']['checked']))      print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
765
-	if (! empty($arrayfields['e.date_delivery']['checked']))  print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"],"e.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
766
-	if (! empty($arrayfields['l.ref']['checked']))            print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"],"l.ref","",$param, '',$sortfield,$sortorder);
767
-	if (! empty($arrayfields['l.date_delivery']['checked']))  print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"],"l.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
869
+	if (! empty($arrayfields['e.ref']['checked'])) {
870
+	    print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"],"e.ref","",$param,'',$sortfield,$sortorder);
871
+	}
872
+	if (! empty($arrayfields['e.ref_supplier']['checked'])) {
873
+	    print_liste_field_titre($arrayfields['e.ref_supplier']['label'], $_SERVER["PHP_SELF"],"e.ref_supplier","",$param,'',$sortfield,$sortorder);
874
+	}
875
+	if (! empty($arrayfields['s.nom']['checked'])) {
876
+	    print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"],"s.nom", "", $param,'align="left"',$sortfield,$sortorder);
877
+	}
878
+	if (! empty($arrayfields['s.town']['checked'])) {
879
+	    print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
880
+	}
881
+	if (! empty($arrayfields['s.zip']['checked'])) {
882
+	    print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
883
+	}
884
+	if (! empty($arrayfields['state.nom']['checked'])) {
885
+	    print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
886
+	}
887
+	if (! empty($arrayfields['country.code_iso']['checked'])) {
888
+	    print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
889
+	}
890
+	if (! empty($arrayfields['typent.code']['checked'])) {
891
+	    print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
892
+	}
893
+	if (! empty($arrayfields['e.date_delivery']['checked'])) {
894
+	    print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"],"e.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
895
+	}
896
+	if (! empty($arrayfields['l.ref']['checked'])) {
897
+	    print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"],"l.ref","",$param, '',$sortfield,$sortorder);
898
+	}
899
+	if (! empty($arrayfields['l.date_delivery']['checked'])) {
900
+	    print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"],"l.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
901
+	}
768 902
 	// Extra fields
769 903
 	if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
770 904
 	{
@@ -774,7 +908,9 @@  discard block
 block discarded – undo
774 908
 	        {
775 909
 	            $align=$extrafields->getAlignFlag($key);
776 910
     			$sortonfield = "ef.".$key;
777
-    			if (! empty($extrafields->attribute_computed[$key])) $sortonfield='';
911
+    			if (! empty($extrafields->attribute_computed[$key])) {
912
+    			    $sortonfield='';
913
+    			}
778 914
     			print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
779 915
 	        }
780 916
 	    }
@@ -783,10 +919,18 @@  discard block
 block discarded – undo
783 919
 	$parameters=array('arrayfields'=>$arrayfields);
784 920
 	$reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters);    // Note that $action and $object may have been modified by hook
785 921
 	print $hookmanager->resPrint;
786
-	if (! empty($arrayfields['e.datec']['checked']))  print_liste_field_titre($arrayfields['e.datec']['label'],$_SERVER["PHP_SELF"],"e.date_creation","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
787
-	if (! empty($arrayfields['e.tms']['checked']))    print_liste_field_titre($arrayfields['e.tms']['label'],$_SERVER["PHP_SELF"],"e.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
788
-	if (! empty($arrayfields['e.fk_statut']['checked'])) print_liste_field_titre($arrayfields['e.fk_statut']['label'],$_SERVER["PHP_SELF"],"e.fk_statut","",$param,'align="right"',$sortfield,$sortorder);
789
-	if (! empty($arrayfields['e.billed']['checked'])) print_liste_field_titre($arrayfields['e.billed']['label'],$_SERVER["PHP_SELF"],"e.billed","",$param,'align="center"',$sortfield,$sortorder);
922
+	if (! empty($arrayfields['e.datec']['checked'])) {
923
+	    print_liste_field_titre($arrayfields['e.datec']['label'],$_SERVER["PHP_SELF"],"e.date_creation","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
924
+	}
925
+	if (! empty($arrayfields['e.tms']['checked'])) {
926
+	    print_liste_field_titre($arrayfields['e.tms']['label'],$_SERVER["PHP_SELF"],"e.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
927
+	}
928
+	if (! empty($arrayfields['e.fk_statut']['checked'])) {
929
+	    print_liste_field_titre($arrayfields['e.fk_statut']['label'],$_SERVER["PHP_SELF"],"e.fk_statut","",$param,'align="right"',$sortfield,$sortorder);
930
+	}
931
+	if (! empty($arrayfields['e.billed']['checked'])) {
932
+	    print_liste_field_titre($arrayfields['e.billed']['label'],$_SERVER["PHP_SELF"],"e.billed","",$param,'align="center"',$sortfield,$sortorder);
933
+	}
790 934
 	print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
791 935
 	print "</tr>\n";
792 936
 
@@ -818,7 +962,9 @@  discard block
 block discarded – undo
818 962
     		print $formfile->getDocumentsLink($reception->element, $filename, $filedir);
819 963
     		print "</td>\n";
820 964
 
821
-    		if (! $i) $totalarray['nbfield']++;
965
+    		if (! $i) {
966
+    		    $totalarray['nbfield']++;
967
+    		}
822 968
 		}
823 969
 
824 970
 		// Ref customer
@@ -827,7 +973,9 @@  discard block
 block discarded – undo
827 973
 		    print "<td>";
828 974
 		    print $obj->ref_supplier;
829 975
 		    print "</td>\n";
830
-		    if (! $i) $totalarray['nbfield']++;
976
+		    if (! $i) {
977
+		        $totalarray['nbfield']++;
978
+		    }
831 979
 		}
832 980
 
833 981
 		// Third party
@@ -836,7 +984,9 @@  discard block
 block discarded – undo
836 984
     		print '<td>';
837 985
     		print $companystatic->getNomUrl(1);
838 986
     		print '</td>';
839
-    		if (! $i) $totalarray['nbfield']++;
987
+    		if (! $i) {
988
+    		    $totalarray['nbfield']++;
989
+    		}
840 990
 		}
841 991
 		// Town
842 992
 		if (! empty($arrayfields['s.town']['checked']))
@@ -844,7 +994,9 @@  discard block
 block discarded – undo
844 994
 		    print '<td class="nocellnopadd">';
845 995
 		    print $obj->town;
846 996
 		    print '</td>';
847
-		    if (! $i) $totalarray['nbfield']++;
997
+		    if (! $i) {
998
+		        $totalarray['nbfield']++;
999
+		    }
848 1000
 		}
849 1001
 		// Zip
850 1002
 		if (! empty($arrayfields['s.zip']['checked']))
@@ -852,13 +1004,17 @@  discard block
 block discarded – undo
852 1004
 		    print '<td class="nocellnopadd">';
853 1005
 		    print $obj->zip;
854 1006
 		    print '</td>';
855
-		    if (! $i) $totalarray['nbfield']++;
1007
+		    if (! $i) {
1008
+		        $totalarray['nbfield']++;
1009
+		    }
856 1010
 		}
857 1011
 		// State
858 1012
 		if (! empty($arrayfields['state.nom']['checked']))
859 1013
 		{
860 1014
 		    print "<td>".$obj->state_name."</td>\n";
861
-		    if (! $i) $totalarray['nbfield']++;
1015
+		    if (! $i) {
1016
+		        $totalarray['nbfield']++;
1017
+		    }
862 1018
 		}
863 1019
 		// Country
864 1020
 		if (! empty($arrayfields['country.code_iso']['checked']))
@@ -867,16 +1023,22 @@  discard block
 block discarded – undo
867 1023
 		    $tmparray=getCountry($obj->fk_pays,'all');
868 1024
 		    print $tmparray['label'];
869 1025
 		    print '</td>';
870
-		    if (! $i) $totalarray['nbfield']++;
1026
+		    if (! $i) {
1027
+		        $totalarray['nbfield']++;
1028
+		    }
871 1029
 		}
872 1030
 		// Type ent
873 1031
 		if (! empty($arrayfields['typent.code']['checked']))
874 1032
 		{
875 1033
 		    print '<td align="center">';
876
-		    if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
1034
+		    if (count($typenArray)==0) {
1035
+		        $typenArray = $formcompany->typent_array(1);
1036
+		    }
877 1037
 		    print $typenArray[$obj->typent_code];
878 1038
 		    print '</td>';
879
-		    if (! $i) $totalarray['nbfield']++;
1039
+		    if (! $i) {
1040
+		        $totalarray['nbfield']++;
1041
+		    }
880 1042
 		}
881 1043
 
882 1044
 		// Date delivery planed
@@ -895,7 +1057,9 @@  discard block
 block discarded – undo
895 1057
         {
896 1058
 		    $reception->fetchObjectLinked($reception->id,$reception->element);
897 1059
             $receiving='';
898
-            if (count($reception->linkedObjects['delivery']) > 0) $receiving=reset($reception->linkedObjects['delivery']);
1060
+            if (count($reception->linkedObjects['delivery']) > 0) {
1061
+                $receiving=reset($reception->linkedObjects['delivery']);
1062
+            }
899 1063
 
900 1064
     		if (! empty($arrayfields['l.ref']['checked']))
901 1065
             {
@@ -923,12 +1087,16 @@  discard block
 block discarded – undo
923 1087
 		        {
924 1088
 		            print '<td class="tdofextrafield"';
925 1089
 		            $align=$extrafields->getAlignFlag($key);
926
-		            if ($align) print ' align="'.$align.'"';
1090
+		            if ($align) {
1091
+		                print ' align="'.$align.'"';
1092
+		            }
927 1093
 		            print '>';
928 1094
 		            $tmpkey='options_'.$key;
929 1095
 		            print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
930 1096
 		            print '</td>';
931
-		            if (! $i) $totalarray['nbfield']++;
1097
+		            if (! $i) {
1098
+		                $totalarray['nbfield']++;
1099
+		            }
932 1100
 		        }
933 1101
 		    }
934 1102
 		}
@@ -942,7 +1110,9 @@  discard block
 block discarded – undo
942 1110
 		    print '<td align="center" class="nowrap">';
943 1111
 		    print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
944 1112
 		    print '</td>';
945
-		    if (! $i) $totalarray['nbfield']++;
1113
+		    if (! $i) {
1114
+		        $totalarray['nbfield']++;
1115
+		    }
946 1116
 		}
947 1117
 		// Date modification
948 1118
 		if (! empty($arrayfields['e.tms']['checked']))
@@ -950,31 +1120,43 @@  discard block
 block discarded – undo
950 1120
 		    print '<td align="center" class="nowrap">';
951 1121
 		    print dol_print_date($db->jdate($obj->date_update), 'dayhour');
952 1122
 		    print '</td>';
953
-		    if (! $i) $totalarray['nbfield']++;
1123
+		    if (! $i) {
1124
+		        $totalarray['nbfield']++;
1125
+		    }
954 1126
 		}
955 1127
 		// Status
956 1128
 		if (! empty($arrayfields['e.fk_statut']['checked']))
957 1129
 		{
958 1130
 		    print '<td align="right" class="nowrap">'.$reception->LibStatut($obj->fk_statut,5).'</td>';
959
-		    if (! $i) $totalarray['nbfield']++;
1131
+		    if (! $i) {
1132
+		        $totalarray['nbfield']++;
1133
+		    }
960 1134
 		}
961 1135
 		// Billed
962 1136
 		if (! empty($arrayfields['e.billed']['checked']))
963 1137
 		{
964 1138
 			print '<td align="center">'.yn($obj->billed).'</td>';
965
-			if (! $i) $totalarray['nbfield']++;
1139
+			if (! $i) {
1140
+			    $totalarray['nbfield']++;
1141
+			}
966 1142
 		}
967 1143
 
968 1144
 		// Action column
969 1145
 		print '<td align="center">';
970
-		if ($massactionbutton || $massaction)   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1146
+		if ($massactionbutton || $massaction) {
1147
+		    // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
971 1148
         {
972 1149
             $selected=0;
973
-    		if (in_array($obj->rowid, $arrayofselected)) $selected=1;
1150
+		}
1151
+    		if (in_array($obj->rowid, $arrayofselected)) {
1152
+    		    $selected=1;
1153
+    		}
974 1154
     		print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
975 1155
         }
976 1156
 		print '</td>';
977
-		if (! $i) $totalarray['nbfield']++;
1157
+		if (! $i) {
1158
+		    $totalarray['nbfield']++;
1159
+		}
978 1160
 
979 1161
 		print "</tr>\n";
980 1162
 
@@ -985,8 +1167,7 @@  discard block
 block discarded – undo
985 1167
 	print "</div>";
986 1168
 	print '</form>';
987 1169
 	$db->free($resql);
988
-}
989
-else
1170
+} else
990 1171
 {
991 1172
 	dol_print_error($db);
992 1173
 }
Please login to merge, or discard this patch.
Spacing   +298 added lines, -298 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
29 29
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
30
-require DOL_BASE_PATH . '/main.inc.php';
30
+require DOL_BASE_PATH.'/main.inc.php';
31 31
 
32 32
 require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
33 33
 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
@@ -43,45 +43,45 @@  discard block
 block discarded – undo
43 43
 $langs->load('companies');
44 44
 $langs->load('bills');
45 45
 
46
-$socid=GETPOST('socid','int');
47
-$massaction=GETPOST('massaction','alpha');
46
+$socid = GETPOST('socid', 'int');
47
+$massaction = GETPOST('massaction', 'alpha');
48 48
 $toselect = GETPOST('toselect', 'array');
49 49
 
50 50
 // Security check
51
-$receptionid = GETPOST('id','int');
52
-if ($user->societe_id) $socid=$user->societe_id;
53
-$result = restrictedArea($user, 'reception',$receptionid,'');
51
+$receptionid = GETPOST('id', 'int');
52
+if ($user->societe_id) $socid = $user->societe_id;
53
+$result = restrictedArea($user, 'reception', $receptionid, '');
54 54
 
55
-$diroutputmassaction=$conf->reception->dir_output . '/temp/massgeneration/'.$user->id;
55
+$diroutputmassaction = $conf->reception->dir_output.'/temp/massgeneration/'.$user->id;
56 56
 
57 57
 $search_ref_rcp = GETPOST("search_ref_rcp");
58 58
 $search_ref_liv = GETPOST('search_ref_liv');
59 59
 $search_ref_supplier = GETPOST('search_ref_supplier');
60 60
 $search_company = GETPOST("search_company");
61
-$search_town=GETPOST('search_town','alpha');
62
-$search_zip=GETPOST('search_zip','alpha');
63
-$search_state=trim(GETPOST("search_state"));
64
-$search_country=GETPOST("search_country",'int');
65
-$search_type_thirdparty=GETPOST("search_type_thirdparty",'int');
66
-$search_billed=GETPOST("search_billed",'int');
61
+$search_town = GETPOST('search_town', 'alpha');
62
+$search_zip = GETPOST('search_zip', 'alpha');
63
+$search_state = trim(GETPOST("search_state"));
64
+$search_country = GETPOST("search_country", 'int');
65
+$search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
66
+$search_billed = GETPOST("search_billed", 'int');
67 67
 $sall = GETPOST('sall', 'alphanohtml');
68
-$optioncss = GETPOST('optioncss','alpha');
69
-
70
-$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
71
-$sortfield = GETPOST('sortfield','alpha');
72
-$sortorder = GETPOST('sortorder','alpha');
73
-$page = GETPOST('page','int');
74
-if (! $sortfield) $sortfield="e.ref";
75
-if (! $sortorder) $sortorder="DESC";
68
+$optioncss = GETPOST('optioncss', 'alpha');
69
+
70
+$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
71
+$sortfield = GETPOST('sortfield', 'alpha');
72
+$sortorder = GETPOST('sortorder', 'alpha');
73
+$page = GETPOST('page', 'int');
74
+if (!$sortfield) $sortfield = "e.ref";
75
+if (!$sortorder) $sortorder = "DESC";
76 76
 if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
77 77
 $offset = $limit * $page;
78 78
 $pageprev = $page - 1;
79 79
 $pagenext = $page + 1;
80 80
 
81 81
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
82
-$contextpage='receptionlist';
82
+$contextpage = 'receptionlist';
83 83
 
84
-$viewstatut=GETPOST('viewstatut');
84
+$viewstatut = GETPOST('viewstatut');
85 85
 
86 86
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
87 87
 $hookmanager->initHooks(array('receptionlist'));
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 
90 90
 // fetch optionals attributes and labels
91 91
 $extralabels = $extrafields->fetch_name_optionals_label('reception');
92
-$search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
92
+$search_array_options = $extrafields->getOptionalsFromPost($extralabels, '', 'search_');
93 93
 
94 94
 // List of fields to search into when doing a "search in all"
95 95
 $fieldstosearchall = array(
@@ -97,10 +97,10 @@  discard block
 block discarded – undo
97 97
     's.nom'=>"ThirdParty",
98 98
     'e.note_public'=>'NotePublic',
99 99
 );
100
-if (empty($user->socid)) $fieldstosearchall["e.note_private"]="NotePrivate";
100
+if (empty($user->socid)) $fieldstosearchall["e.note_private"] = "NotePrivate";
101 101
 
102
-$checkedtypetiers=0;
103
-$arrayfields=array(
102
+$checkedtypetiers = 0;
103
+$arrayfields = array(
104 104
     'e.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
105 105
     'e.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1),
106 106
     's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
@@ -119,9 +119,9 @@  discard block
 block discarded – undo
119 119
 // Extra fields
120 120
 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
121 121
 {
122
-    foreach($extrafields->attribute_label as $key => $val)
122
+    foreach ($extrafields->attribute_label as $key => $val)
123 123
     {
124
-        $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]);
124
+        $arrayfields["ef.".$key] = array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]);
125 125
     }
126 126
 }
127 127
 
@@ -130,38 +130,38 @@  discard block
 block discarded – undo
130 130
  * Actions
131 131
  */
132 132
 
133
-if (GETPOST('cancel')) { $action='list'; $massaction=''; }
134
-if (! GETPOST('confirmmassaction') && $massaction != 'confirm_createbills') { $massaction=''; }
133
+if (GETPOST('cancel')) { $action = 'list'; $massaction = ''; }
134
+if (!GETPOST('confirmmassaction') && $massaction != 'confirm_createbills') { $massaction = ''; }
135 135
 
136
-$parameters=array('socid'=>$socid);
137
-$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
136
+$parameters = array('socid'=>$socid);
137
+$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
138 138
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
139 139
 
140 140
 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
141 141
 
142 142
 // Purge search criteria
143
-if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
143
+if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
144 144
 {
145
-	$search_ref_supplier='';
146
-    $search_ref_rcp='';
147
-    $search_ref_liv='';
148
-    $search_company='';
149
-    $search_town='';
150
-	$search_zip="";
151
-    $search_state="";
152
-	$search_type='';
153
-	$search_country='';
154
-	$search_type_thirdparty='';
155
-	$search_billed='';
156
-    $viewstatut='';
157
-    $search_array_options=array();
145
+	$search_ref_supplier = '';
146
+    $search_ref_rcp = '';
147
+    $search_ref_liv = '';
148
+    $search_company = '';
149
+    $search_town = '';
150
+	$search_zip = "";
151
+    $search_state = "";
152
+	$search_type = '';
153
+	$search_country = '';
154
+	$search_type_thirdparty = '';
155
+	$search_billed = '';
156
+    $viewstatut = '';
157
+    $search_array_options = array();
158 158
 }
159 159
 
160 160
 if (empty($reshook))
161 161
 {
162 162
 	if ($massaction == 'confirm_createbills') {
163 163
 
164
-    	$receptions = GETPOST('toselect','array');
164
+    	$receptions = GETPOST('toselect', 'array');
165 165
     	$createbills_onebythird = GETPOST('createbills_onebythird', 'int');
166 166
     	$validate_invoices = GETPOST('valdate_invoices', 'int');
167 167
 
@@ -171,29 +171,29 @@  discard block
 block discarded – undo
171 171
     	$nb_bills_created = 0;
172 172
 
173 173
     	$db->begin();
174
-		$errors =array();
175
-    	foreach($receptions as $id_reception)
174
+		$errors = array();
175
+    	foreach ($receptions as $id_reception)
176 176
     	{
177 177
     		$rcp = new Reception($db);
178 178
 			 // On ne facture que les réceptions validées
179
-    		if ($rcp->fetch($id_reception) <= 0 || $rcp->statut != 1){
180
-				$errors[]=$langs->trans('StatusMustBeValidate',$rcp->ref);
179
+    		if ($rcp->fetch($id_reception) <= 0 || $rcp->statut != 1) {
180
+				$errors[] = $langs->trans('StatusMustBeValidate', $rcp->ref);
181 181
 				$error++;
182 182
 				continue;
183 183
 			}
184 184
 
185 185
     		$object = new FactureFournisseur($db);
186
-    		if (!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])){
186
+    		if (!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])) {
187 187
 				$object = $TFactThird[$rcp->socid]; // If option "one bill per third" is set, we use already created reception.
188
-				if(empty($object->rowid)&&$object->id != null)$object->rowid = $object->id;
189
-				if(!empty($object->rowid))$object->fetchObjectLinked();
188
+				if (empty($object->rowid) && $object->id != null)$object->rowid = $object->id;
189
+				if (!empty($object->rowid))$object->fetchObjectLinked();
190 190
 				$rcp->fetchObjectLinked();
191 191
 
192 192
 				if (count($rcp->linkedObjectsIds['order_supplier']) > 0)
193 193
 				{
194 194
 					foreach ($rcp->linkedObjectsIds['order_supplier'] as $key => $value)
195 195
 					{
196
-						if(empty($object->linkedObjectsIds['order_supplier']) || !in_array($value, $object->linkedObjectsIds['order_supplier']))//Dont try to link if already linked
196
+						if (empty($object->linkedObjectsIds['order_supplier']) || !in_array($value, $object->linkedObjectsIds['order_supplier']))//Dont try to link if already linked
197 197
 							$object->add_object_linked('order_supplier', $value); // add supplier order linked object
198 198
 					}
199 199
 				}
@@ -203,14 +203,14 @@  discard block
 block discarded – undo
203 203
     			$object->type = FactureFournisseur::TYPE_STANDARD;
204 204
     			$object->cond_reglement_id	= $rcp->thirdparty->cond_reglement_supplier_id;
205 205
     			$object->mode_reglement_id	= $rcp->thirdparty->mode_reglement_supplier_id;
206
-				$object->fk_account         = !empty($rcp->thirdparty->fk_account)?$rcp->thirdparty->fk_account:0;
207
-				$object->remise_percent 	= !empty($rcp->thirdparty->remise_percent)?$rcp->thirdparty->remise_percent:0;
208
-				$object->remise_absolue 	= !empty($rcp->thirdparty->remise_absolue)?$rcp->thirdparty->remise_absolue:0;
206
+				$object->fk_account = !empty($rcp->thirdparty->fk_account) ? $rcp->thirdparty->fk_account : 0;
207
+				$object->remise_percent 	= !empty($rcp->thirdparty->remise_percent) ? $rcp->thirdparty->remise_percent : 0;
208
+				$object->remise_absolue 	= !empty($rcp->thirdparty->remise_absolue) ? $rcp->thirdparty->remise_absolue : 0;
209 209
 
210 210
     			$object->fk_project			= $rcp->fk_project;
211
-    			$object->ref_supplier		= $rcp->ref_supplier;
211
+    			$object->ref_supplier = $rcp->ref_supplier;
212 212
 
213
-    			$datefacture = dol_mktime(12, 0, 0, GETPOST('remonth'),GETPOST('reday'), GETPOST('reyear'));
213
+    			$datefacture = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
214 214
     			if (empty($datefacture))
215 215
     			{
216 216
     				$datefacture = dol_mktime(date("h"), date("M"), 0, date("m"), date("d"), date("Y"));
@@ -231,28 +231,28 @@  discard block
 block discarded – undo
231 231
 
232 232
     			$res = $object->create($user);
233 233
 				//var_dump($object->error);exit;
234
-    			if($res > 0){
234
+    			if ($res > 0) {
235 235
 					$nb_bills_created++;
236 236
 					$object->id = $res;
237
-				}else {
238
-					$errors[]=$rcp->ref.' : '.$langs->trans($object->error);
237
+				} else {
238
+					$errors[] = $rcp->ref.' : '.$langs->trans($object->error);
239 239
 					$error++;
240 240
 				}
241 241
     		}
242 242
 
243 243
     		if ($object->id > 0)
244 244
     		{
245
-				if(!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])){ //cause function create already add object linked for facturefournisseur
246
-					$res = $object->add_object_linked($object->origin,$id_reception);
245
+				if (!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])) { //cause function create already add object linked for facturefournisseur
246
+					$res = $object->add_object_linked($object->origin, $id_reception);
247 247
 
248
-					if ($res==0)
248
+					if ($res == 0)
249 249
 					{
250
-						$errors[]=$object->error;
250
+						$errors[] = $object->error;
251 251
 						$error++;
252 252
 					}
253 253
 				}
254 254
 
255
-    			if (! $error)
255
+    			if (!$error)
256 256
     			{
257 257
 	    			$lines = $rcp->lines;
258 258
 	    			if (empty($lines) && method_exists($rcp, 'fetch_lines'))
@@ -261,27 +261,27 @@  discard block
 block discarded – undo
261 261
 	    				$lines = $rcp->lines;
262 262
 	    			}
263 263
 
264
-	    			$fk_parent_line=0;
265
-	    			$num=count($lines);
264
+	    			$fk_parent_line = 0;
265
+	    			$num = count($lines);
266 266
 
267
-	    			for ($i=0;$i<$num;$i++)
267
+	    			for ($i = 0; $i < $num; $i++)
268 268
 	    			{
269
-	    				$desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle);
269
+	    				$desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
270 270
 	    				if ($lines[$i]->subprice < 0)
271 271
 	    				{
272 272
 	    					// Negative line, we create a discount line
273 273
 	    					$discount = new DiscountAbsolute($db);
274
-	    					$discount->fk_soc=$object->socid;
275
-	    					$discount->amount_ht=abs($lines[$i]->total_ht);
276
-	    					$discount->amount_tva=abs($lines[$i]->total_tva);
277
-	    					$discount->amount_ttc=abs($lines[$i]->total_ttc);
278
-	    					$discount->tva_tx=$lines[$i]->tva_tx;
279
-	    					$discount->fk_user=$user->id;
280
-	    					$discount->description=$desc;
281
-	    					$discountid=$discount->create($user);
274
+	    					$discount->fk_soc = $object->socid;
275
+	    					$discount->amount_ht = abs($lines[$i]->total_ht);
276
+	    					$discount->amount_tva = abs($lines[$i]->total_tva);
277
+	    					$discount->amount_ttc = abs($lines[$i]->total_ttc);
278
+	    					$discount->tva_tx = $lines[$i]->tva_tx;
279
+	    					$discount->fk_user = $user->id;
280
+	    					$discount->description = $desc;
281
+	    					$discountid = $discount->create($user);
282 282
 	    					if ($discountid > 0)
283 283
 	    					{
284
-	    						$result=$object->insert_discount($discountid);
284
+	    						$result = $object->insert_discount($discountid);
285 285
 	    						//$result=$discount->link_to_invoice($lineid,$id);
286 286
 	    					}
287 287
 	    					else
@@ -294,17 +294,17 @@  discard block
 block discarded – undo
294 294
 	    				else
295 295
 	    				{
296 296
 	    					// Positive line
297
-	    					$product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
297
+	    					$product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
298 298
 	    					// Date start
299
-	    					$date_start=false;
300
-	    					if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue;
301
-	    					if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel;
302
-	    					if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start;
299
+	    					$date_start = false;
300
+	    					if ($lines[$i]->date_debut_prevue) $date_start = $lines[$i]->date_debut_prevue;
301
+	    					if ($lines[$i]->date_debut_reel) $date_start = $lines[$i]->date_debut_reel;
302
+	    					if ($lines[$i]->date_start) $date_start = $lines[$i]->date_start;
303 303
 	    					//Date end
304
-	    					$date_end=false;
305
-	    					if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue;
306
-	    					if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel;
307
-	    					if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end;
304
+	    					$date_end = false;
305
+	    					if ($lines[$i]->date_fin_prevue) $date_end = $lines[$i]->date_fin_prevue;
306
+	    					if ($lines[$i]->date_fin_reel) $date_end = $lines[$i]->date_fin_reel;
307
+	    					if ($lines[$i]->date_end) $date_end = $lines[$i]->date_end;
308 308
 	    					// Reset fk_parent_line for no child products and special product
309 309
 	    					if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9)
310 310
 	    					{
@@ -335,15 +335,15 @@  discard block
 block discarded – undo
335 335
 
336 336
 	    					);
337 337
 
338
-							$rcp->add_object_linked('facture_fourn_det',$result);
338
+							$rcp->add_object_linked('facture_fourn_det', $result);
339 339
 
340 340
 	    					if ($result > 0)
341 341
 	    					{
342
-	    						$lineid=$result;
342
+	    						$lineid = $result;
343 343
 	    					}
344 344
 	    					else
345 345
 	    					{
346
-	    						$lineid=0;
346
+	    						$lineid = 0;
347 347
 	    						$error++;
348 348
 	    						break;
349 349
 	    					}
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 
360 360
     		//$rcp->classifyBilled($user);        // Disabled. This behavior must be set or not using the workflow module.
361 361
 
362
-    		if(!empty($createbills_onebythird) && empty($TFactThird[$rcp->socid])) $TFactThird[$rcp->socid] = $object;
362
+    		if (!empty($createbills_onebythird) && empty($TFactThird[$rcp->socid])) $TFactThird[$rcp->socid] = $object;
363 363
     		else $TFact[$object->id] = $object;
364 364
     	}
365 365
 
@@ -367,10 +367,10 @@  discard block
 block discarded – undo
367 367
     	$TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
368 368
     	$toselect = array();
369 369
 
370
-    	if (! $error && $validate_invoices)
370
+    	if (!$error && $validate_invoices)
371 371
     	{
372 372
     		$massaction = $action = 'builddoc';
373
-    		foreach($TAllFact as &$object)
373
+    		foreach ($TAllFact as &$object)
374 374
     		{
375 375
     			$result = $object->validate($user);
376 376
     			if ($result <= 0)
@@ -385,14 +385,14 @@  discard block
 block discarded – undo
385 385
     			// Fac builddoc
386 386
     			$donotredirect = 1;
387 387
     			$upload_dir = $conf->fournisseur->facture->dir_output;
388
-    		    $permissioncreate=$user->rights->fournisseur->facture->creer;
388
+    		    $permissioncreate = $user->rights->fournisseur->facture->creer;
389 389
     		    include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
390 390
     		}
391 391
 
392 392
     		$massaction = $action = 'confirm_createbills';
393 393
     	}
394 394
 
395
-    	if (! $error)
395
+    	if (!$error)
396 396
     	{
397 397
     		$db->commit();
398 398
     		setEventMessage($langs->trans('BillCreated', $nb_bills_created));
@@ -401,9 +401,9 @@  discard block
 block discarded – undo
401 401
     	{
402 402
 
403 403
     		$db->rollback();
404
-    		$action='create';
405
-    		$_GET["origin"]=$_POST["origin"];
406
-    		$_GET["originid"]=$_POST["originid"];
404
+    		$action = 'create';
405
+    		$_GET["origin"] = $_POST["origin"];
406
+    		$_GET["originid"] = $_POST["originid"];
407 407
     		setEventMessages($object->error, $errors, 'errors');
408 408
     		$error++;
409 409
     	}
@@ -415,56 +415,56 @@  discard block
 block discarded – undo
415 415
  * View
416 416
  */
417 417
 
418
-$form=new Form($db);
419
-$companystatic=new Societe($db);
420
-$reception=new Reception($db);
421
-$formcompany=new FormCompany($db);
418
+$form = new Form($db);
419
+$companystatic = new Societe($db);
420
+$reception = new Reception($db);
421
+$formcompany = new FormCompany($db);
422 422
 $formfile = new FormFile($db);
423 423
 
424 424
 
425
-$helpurl='EN:Module_Receptions|FR:Module_Receptions|ES:M&oacute;dulo_Receptiones';
426
-llxHeader('',$langs->trans('ListOfReceptions'),$helpurl);
425
+$helpurl = 'EN:Module_Receptions|FR:Module_Receptions|ES:M&oacute;dulo_Receptiones';
426
+llxHeader('', $langs->trans('ListOfReceptions'), $helpurl);
427 427
 
428 428
 $sql = "SELECT e.rowid, e.ref, e.ref_supplier, e.date_reception as date_reception, e.date_delivery as date_livraison, l.date_delivery as date_reception, e.fk_statut, e.billed,";
429
-$sql.= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, ';
430
-$sql.= " typent.code as typent_code,";
431
-$sql.= " state.code_departement as state_code, state.nom as state_name,";
432
-$sql.= ' e.date_creation as date_creation, e.tms as date_update';
429
+$sql .= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, ';
430
+$sql .= " typent.code as typent_code,";
431
+$sql .= " state.code_departement as state_code, state.nom as state_name,";
432
+$sql .= ' e.date_creation as date_creation, e.tms as date_update';
433 433
 // Add fields from extrafields
434
-foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
434
+foreach ($extrafields->attribute_label as $key => $val) $sql .= ($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
435 435
 // Add fields from hooks
436
-$parameters=array();
437
-$reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters);    // Note that $action and $object may have been modified by hook
438
-$sql.=$hookmanager->resPrint;
439
-$sql.= " FROM ".MAIN_DB_PREFIX."reception as e";
440
-if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."reception_extrafields as ef on (e.rowid = ef.fk_object)";
441
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
442
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
443
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
444
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
445
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'reception' AND ee.targettype = 'delivery'";
446
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.rowid = ee.fk_target";
436
+$parameters = array();
437
+$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
438
+$sql .= $hookmanager->resPrint;
439
+$sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
440
+if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."reception_extrafields as ef on (e.rowid = ef.fk_object)";
441
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
442
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
443
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
444
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
445
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'reception' AND ee.targettype = 'delivery'";
446
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.rowid = ee.fk_target";
447 447
 if (!$user->rights->societe->client->voir && !$socid)	// Internal user with no permission to see all
448 448
 {
449
-	$sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
449
+	$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
450 450
 }
451
-$sql.= " WHERE e.entity IN (".getEntity('reception').")";
451
+$sql .= " WHERE e.entity IN (".getEntity('reception').")";
452 452
 if (!$user->rights->societe->client->voir && !$socid)	// Internal user with no permission to see all
453 453
 {
454
-	$sql.= " AND e.fk_soc = sc.fk_soc";
455
-	$sql.= " AND sc.fk_user = " .$user->id;
454
+	$sql .= " AND e.fk_soc = sc.fk_soc";
455
+	$sql .= " AND sc.fk_user = ".$user->id;
456 456
 }
457 457
 if ($socid)
458 458
 {
459
-	$sql.= " AND e.fk_soc = ".$socid;
459
+	$sql .= " AND e.fk_soc = ".$socid;
460 460
 }
461 461
 if ($viewstatut <> '' && $viewstatut >= 0) {
462
-	$sql.= " AND e.fk_statut = ".$viewstatut;
462
+	$sql .= " AND e.fk_statut = ".$viewstatut;
463 463
 }
464
-if ($search_billed != '' && $search_billed >= 0) $sql.=' AND e.billed = '.$search_billed;
465
-if ($search_town)  $sql.= natural_search('s.town', $search_town);
466
-if ($search_zip)   $sql.= natural_search("s.zip",$search_zip);
467
-if ($search_state) $sql.= natural_search("state.nom",$search_state);
464
+if ($search_billed != '' && $search_billed >= 0) $sql .= ' AND e.billed = '.$search_billed;
465
+if ($search_town)  $sql .= natural_search('s.town', $search_town);
466
+if ($search_zip)   $sql .= natural_search("s.zip", $search_zip);
467
+if ($search_state) $sql .= natural_search("state.nom", $search_state);
468 468
 if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')';
469 469
 if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
470 470
 if ($search_ref_rcp) $sql .= natural_search('e.ref', $search_ref_rcp);
@@ -476,21 +476,21 @@  discard block
 block discarded – undo
476 476
 // Add where from extra fields
477 477
 foreach ($search_array_options as $key => $val)
478 478
 {
479
-    $crit=$val;
480
-    $tmpkey=preg_replace('/search_options_/','',$key);
481
-    $typ=$extrafields->attribute_type[$tmpkey];
482
-    $mode=0;
483
-    if (in_array($typ, array('int','double','real'))) $mode=1;    							// Search on a numeric
484
-    if (in_array($typ, array('sellist')) && $crit != '0' && $crit != '-1') $mode=2;    		// Search on a foreign key int
485
-    if ($crit != '' && (! in_array($typ, array('select','sellist')) || $crit != '0'))
479
+    $crit = $val;
480
+    $tmpkey = preg_replace('/search_options_/', '', $key);
481
+    $typ = $extrafields->attribute_type[$tmpkey];
482
+    $mode = 0;
483
+    if (in_array($typ, array('int', 'double', 'real'))) $mode = 1; // Search on a numeric
484
+    if (in_array($typ, array('sellist')) && $crit != '0' && $crit != '-1') $mode = 2; // Search on a foreign key int
485
+    if ($crit != '' && (!in_array($typ, array('select', 'sellist')) || $crit != '0'))
486 486
     {
487 487
         $sql .= natural_search('ef.'.$tmpkey, $crit, $mode);
488 488
     }
489 489
 }
490 490
 // Add where from hooks
491
-$parameters=array();
492
-$reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters);    // Note that $action and $object may have been modified by hook
493
-$sql.=$hookmanager->resPrint;
491
+$parameters = array();
492
+$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
493
+$sql .= $hookmanager->resPrint;
494 494
 
495 495
 $nbtotalofrecords = '';
496 496
 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
@@ -499,51 +499,51 @@  discard block
 block discarded – undo
499 499
     $nbtotalofrecords = $db->num_rows($result);
500 500
 }
501 501
 
502
-$sql.= $db->order($sortfield,$sortorder);
503
-$sql.= $db->plimit($limit + 1,$offset);
502
+$sql .= $db->order($sortfield, $sortorder);
503
+$sql .= $db->plimit($limit + 1, $offset);
504 504
 
505 505
 //print $sql;
506
-$resql=$db->query($sql);
506
+$resql = $db->query($sql);
507 507
 if ($resql)
508 508
 {
509 509
 	$num = $db->num_rows($resql);
510 510
 
511 511
 	$reception = new Reception($db);
512 512
 
513
-	$arrayofselected=is_array($toselect)?$toselect:array();
514
-
515
-	$param='';
516
-    if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
517
-	if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
518
-	if ($sall) $param.= "&amp;sall=".$sall;
519
-	if ($search_ref_rcp) $param.= "&amp;search_ref_rcp=".$search_ref_rcp;
520
-	if ($search_ref_liv) $param.= "&amp;search_ref_liv=".$search_ref_liv;
521
-	if ($search_company) $param.= "&amp;search_company=".$search_company;
522
-	if ($optioncss != '') $param.='&amp;optioncss='.$optioncss;
523
-	if ($search_billed != '' && $search_billed >= 0)$param.= "&amp;search_billed=".$search_billed;
524
-	if ($search_town)  $param.= "&amp;search_town=".$search_town;
525
-	if ($search_zip)  $param.= "&amp;search_zip=".$search_zip;
526
-	if ($search_state) $param.= "&amp;search_state=".$search_state;
527
-	if ($viewstatut) $param.= "&amp;viewstatut=".$viewstatut;
528
-	if ($search_country) $param.= "&amp;search_country=".$search_country;
529
-	if ($search_type_thirdparty) $param.= "&amp;search_type_thirdparty=".$search_type_thirdparty;
530
-	if ($search_ref_supplier) $param.= "&amp;search_ref_supplier=".$search_ref_supplier;
513
+	$arrayofselected = is_array($toselect) ? $toselect : array();
514
+
515
+	$param = '';
516
+    if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage;
517
+	if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;
518
+	if ($sall) $param .= "&amp;sall=".$sall;
519
+	if ($search_ref_rcp) $param .= "&amp;search_ref_rcp=".$search_ref_rcp;
520
+	if ($search_ref_liv) $param .= "&amp;search_ref_liv=".$search_ref_liv;
521
+	if ($search_company) $param .= "&amp;search_company=".$search_company;
522
+	if ($optioncss != '') $param .= '&amp;optioncss='.$optioncss;
523
+	if ($search_billed != '' && $search_billed >= 0)$param .= "&amp;search_billed=".$search_billed;
524
+	if ($search_town)  $param .= "&amp;search_town=".$search_town;
525
+	if ($search_zip)  $param .= "&amp;search_zip=".$search_zip;
526
+	if ($search_state) $param .= "&amp;search_state=".$search_state;
527
+	if ($viewstatut) $param .= "&amp;viewstatut=".$viewstatut;
528
+	if ($search_country) $param .= "&amp;search_country=".$search_country;
529
+	if ($search_type_thirdparty) $param .= "&amp;search_type_thirdparty=".$search_type_thirdparty;
530
+	if ($search_ref_supplier) $param .= "&amp;search_ref_supplier=".$search_ref_supplier;
531 531
 	// Add $param from extra fields
532 532
 	foreach ($search_array_options as $key => $val)
533 533
 	{
534
-	    $crit=$val;
535
-	    $tmpkey=preg_replace('/search_options_/','',$key);
536
-	    if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
534
+	    $crit = $val;
535
+	    $tmpkey = preg_replace('/search_options_/', '', $key);
536
+	    if ($val != '') $param .= '&search_options_'.$tmpkey.'='.urlencode($val);
537 537
 	}
538 538
 
539 539
 
540
-	$arrayofmassactions =  array(
540
+	$arrayofmassactions = array(
541 541
 //    'presend'=>$langs->trans("SendByMail"),
542 542
 );
543 543
 
544
-	if($user->rights->fournisseur->facture->creer)$arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisSupplier");
545
-	if($massaction == 'createbills') $arrayofmassactions=array();
546
-	$massactionbutton=$form->selectMassAction('', $arrayofmassactions);
544
+	if ($user->rights->fournisseur->facture->creer)$arrayofmassactions['createbills'] = $langs->trans("CreateInvoiceForThisSupplier");
545
+	if ($massaction == 'createbills') $arrayofmassactions = array();
546
+	$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
547 547
 	//$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
548 548
 
549 549
 	$i = 0;
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
     print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
557 557
     print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
558 558
 
559
-	print_barre_liste($langs->trans('ListOfReceptions'), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,$massactionbutton,$num, $nbtotalofrecords, '', 0, '', '', $limit);
559
+	print_barre_liste($langs->trans('ListOfReceptions'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit);
560 560
 
561 561
 
562 562
 	if ($massaction == 'createbills')
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
 		print $langs->trans('ValidateInvoices');
587 587
 		print '</td>';
588 588
 		print '<td>';
589
-		if (! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_BILL))
589
+		if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL))
590 590
 		{
591 591
 		    print $form->selectyesno('valdate_invoices', 0, 1, 1);
592 592
 		    print ' ('.$langs->trans("AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation").')';
@@ -609,90 +609,90 @@  discard block
 block discarded – undo
609 609
 
610 610
     if ($sall)
611 611
     {
612
-        foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
613
-        print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
612
+        foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
613
+        print $langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall);
614 614
     }
615 615
 
616
-    $moreforfilter='';
617
-    if (! empty($moreforfilter))
616
+    $moreforfilter = '';
617
+    if (!empty($moreforfilter))
618 618
     {
619 619
         print '<div class="liste_titre liste_titre_bydiv centpercent">';
620 620
         print $moreforfilter;
621
-        $parameters=array('type'=>$type);
622
-        $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters);    // Note that $action and $object may have been modified by hook
621
+        $parameters = array('type'=>$type);
622
+        $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
623 623
         print $hookmanager->resPrint;
624 624
         print '</div>';
625 625
     }
626 626
 
627
-    $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
628
-    $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);	// This also change content of $arrayfields
629
-	$selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
627
+    $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
628
+    $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
629
+	$selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
630 630
 
631 631
 
632 632
     print '<div class="div-table-responsive">';
633
-    print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
633
+    print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
634 634
 
635 635
 	// Lignes des champs de filtre
636 636
 	print '<tr class="liste_titre_filter">';
637 637
 	// Ref
638
-	if (! empty($arrayfields['e.ref']['checked']))
638
+	if (!empty($arrayfields['e.ref']['checked']))
639 639
 	{
640 640
 	    print '<td class="liste_titre">';
641 641
     	print '<input class="flat" size="6" type="text" name="search_ref_rcp" value="'.$search_ref_rcp.'">';
642 642
         print '</td>';
643 643
 	}
644 644
 	// Ref customer
645
-	if (! empty($arrayfields['e.ref_supplier']['checked']))
645
+	if (!empty($arrayfields['e.ref_supplier']['checked']))
646 646
 	{
647 647
 	    print '<td class="liste_titre">';
648 648
     	print '<input class="flat" size="6" type="text" name="search_ref_supplier" value="'.$search_ref_supplier.'">';
649 649
         print '</td>';
650 650
 	}
651 651
 	// Thirdparty
652
-	if (! empty($arrayfields['s.nom']['checked']))
652
+	if (!empty($arrayfields['s.nom']['checked']))
653 653
 	{
654 654
     	print '<td class="liste_titre" align="left">';
655 655
     	print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
656 656
     	print '</td>';
657 657
 	}
658 658
 	// Town
659
-	if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
659
+	if (!empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
660 660
 	// Zip
661
-	if (! empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
661
+	if (!empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
662 662
 	// State
663
-    if (! empty($arrayfields['state.nom']['checked']))
663
+    if (!empty($arrayfields['state.nom']['checked']))
664 664
     {
665 665
         print '<td class="liste_titre">';
666 666
     	print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
667 667
     	print '</td>';
668 668
     }
669 669
     // Country
670
-    if (! empty($arrayfields['country.code_iso']['checked']))
670
+    if (!empty($arrayfields['country.code_iso']['checked']))
671 671
     {
672 672
         print '<td class="liste_titre" align="center">';
673
-    	print $form->select_country($search_country,'search_country','',0,'maxwidth100');
673
+    	print $form->select_country($search_country, 'search_country', '', 0, 'maxwidth100');
674 674
     	print '</td>';
675 675
     }
676 676
 	// Company type
677
-    if (! empty($arrayfields['typent.code']['checked']))
677
+    if (!empty($arrayfields['typent.code']['checked']))
678 678
     {
679 679
         print '<td class="liste_titre maxwidthonsmartphone" align="center">';
680
-    	print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
680
+    	print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT));
681 681
     	print '</td>';
682 682
     }
683 683
 	// Date delivery planned
684
-	if (! empty($arrayfields['e.date_delivery']['checked']))
684
+	if (!empty($arrayfields['e.date_delivery']['checked']))
685 685
 	{
686 686
     	print '<td class="liste_titre">&nbsp;</td>';
687 687
 	}
688
-	if (! empty($arrayfields['l.ref']['checked']))
688
+	if (!empty($arrayfields['l.ref']['checked']))
689 689
 	{
690 690
     	// Delivery ref
691 691
 		print '<td class="liste_titre">';
692 692
 		print '<input class="flat" size="10" type="text" name="search_ref_liv" value="'.$search_ref_liv.'"';
693 693
 		print '</td>';
694 694
 	}
695
-	if (! empty($arrayfields['l.date_delivery']['checked']))
695
+	if (!empty($arrayfields['l.date_delivery']['checked']))
696 696
 	{
697 697
 	    // Date received
698 698
 		print '<td class="liste_titre">&nbsp;</td>';
@@ -700,51 +700,51 @@  discard block
 block discarded – undo
700 700
 	// Extra fields
701 701
 	if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
702 702
 	{
703
-	    foreach($extrafields->attribute_label as $key => $val)
703
+	    foreach ($extrafields->attribute_label as $key => $val)
704 704
 	    {
705
-	        if (! empty($arrayfields["ef.".$key]['checked']))
705
+	        if (!empty($arrayfields["ef.".$key]['checked']))
706 706
 	        {
707
-	            $align=$extrafields->getAlignFlag($key);
708
-	            $typeofextrafield=$extrafields->attribute_type[$key];
709
-	            print '<td class="liste_titre'.($align?' '.$align:'').'">';
707
+	            $align = $extrafields->getAlignFlag($key);
708
+	            $typeofextrafield = $extrafields->attribute_type[$key];
709
+	            print '<td class="liste_titre'.($align ? ' '.$align : '').'">';
710 710
 	            if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
711 711
 	            {
712
-	                $crit=$val;
713
-	                $tmpkey=preg_replace('/search_options_/','',$key);
714
-	                $searchclass='';
715
-	                if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
716
-	                if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
717
-	                print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
712
+	                $crit = $val;
713
+	                $tmpkey = preg_replace('/search_options_/', '', $key);
714
+	                $searchclass = '';
715
+	                if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass = 'searchstring';
716
+	                if (in_array($typeofextrafield, array('int', 'double'))) $searchclass = 'searchnum';
717
+	                print '<input class="flat'.($searchclass ? ' '.$searchclass : '').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
718 718
 	            }
719 719
 	            print '</td>';
720 720
 	        }
721 721
 	    }
722 722
 	}
723 723
 	// Fields from hook
724
-	$parameters=array('arrayfields'=>$arrayfields);
725
-	$reshook=$hookmanager->executeHooks('printFieldListOption',$parameters);    // Note that $action and $object may have been modified by hook
724
+	$parameters = array('arrayfields'=>$arrayfields);
725
+	$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
726 726
 	print $hookmanager->resPrint;
727 727
 	// Date creation
728
-	if (! empty($arrayfields['e.datec']['checked']))
728
+	if (!empty($arrayfields['e.datec']['checked']))
729 729
 	{
730 730
 	    print '<td class="liste_titre">';
731 731
 	    print '</td>';
732 732
 	}
733 733
 	// Date modification
734
-	if (! empty($arrayfields['e.tms']['checked']))
734
+	if (!empty($arrayfields['e.tms']['checked']))
735 735
 	{
736 736
 	    print '<td class="liste_titre">';
737 737
 	    print '</td>';
738 738
 	}
739 739
 	// Status
740
-	if (! empty($arrayfields['e.fk_statut']['checked']))
740
+	if (!empty($arrayfields['e.fk_statut']['checked']))
741 741
 	{
742 742
 	    print '<td class="liste_titre maxwidthonsmartphone" align="right">';
743
-	    print $form->selectarray('viewstatut', array('0'=>$langs->trans('StatusReceptionDraftShort'),'1'=>$langs->trans('StatusReceptionValidatedShort'),'2'=>$langs->trans('StatusReceptionProcessedShort')),$viewstatut,1);
743
+	    print $form->selectarray('viewstatut', array('0'=>$langs->trans('StatusReceptionDraftShort'), '1'=>$langs->trans('StatusReceptionValidatedShort'), '2'=>$langs->trans('StatusReceptionProcessedShort')), $viewstatut, 1);
744 744
 	    print '</td>';
745 745
 	}
746 746
 	// Status billed
747
-	if (! empty($arrayfields['e.billed']['checked']))
747
+	if (!empty($arrayfields['e.billed']['checked']))
748 748
 	{
749 749
 	    print '<td class="liste_titre maxwidthonsmartphone" align="center">';
750 750
 	    print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);
@@ -752,142 +752,142 @@  discard block
 block discarded – undo
752 752
 	}
753 753
 	// Action column
754 754
 	print '<td class="liste_titre" align="middle">';
755
-	$searchpicto=$form->showFilterAndCheckAddButtons(0);
755
+	$searchpicto = $form->showFilterAndCheckAddButtons(0);
756 756
 	print $searchpicto;
757 757
     print '</td>';
758 758
 	print "</tr>\n";
759 759
 
760 760
 	print '<tr class="liste_titre">';
761
-	if (! empty($arrayfields['e.ref']['checked']))            print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"],"e.ref","",$param,'',$sortfield,$sortorder);
762
-	if (! empty($arrayfields['e.ref_supplier']['checked']))   print_liste_field_titre($arrayfields['e.ref_supplier']['label'], $_SERVER["PHP_SELF"],"e.ref_supplier","",$param,'',$sortfield,$sortorder);
763
-	if (! empty($arrayfields['s.nom']['checked']))            print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"],"s.nom", "", $param,'align="left"',$sortfield,$sortorder);
764
-	if (! empty($arrayfields['s.town']['checked']))           print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
765
-	if (! empty($arrayfields['s.zip']['checked']))            print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
766
-	if (! empty($arrayfields['state.nom']['checked']))        print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
767
-	if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
768
-	if (! empty($arrayfields['typent.code']['checked']))      print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
769
-	if (! empty($arrayfields['e.date_delivery']['checked']))  print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"],"e.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
770
-	if (! empty($arrayfields['l.ref']['checked']))            print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"],"l.ref","",$param, '',$sortfield,$sortorder);
771
-	if (! empty($arrayfields['l.date_delivery']['checked']))  print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"],"l.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
761
+	if (!empty($arrayfields['e.ref']['checked']))            print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, '', $sortfield, $sortorder);
762
+	if (!empty($arrayfields['e.ref_supplier']['checked']))   print_liste_field_titre($arrayfields['e.ref_supplier']['label'], $_SERVER["PHP_SELF"], "e.ref_supplier", "", $param, '', $sortfield, $sortorder);
763
+	if (!empty($arrayfields['s.nom']['checked']))            print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, 'align="left"', $sortfield, $sortorder);
764
+	if (!empty($arrayfields['s.town']['checked']))           print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
765
+	if (!empty($arrayfields['s.zip']['checked']))            print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
766
+	if (!empty($arrayfields['state.nom']['checked']))        print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
767
+	if (!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, 'align="center"', $sortfield, $sortorder);
768
+	if (!empty($arrayfields['typent.code']['checked']))      print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, 'align="center"', $sortfield, $sortorder);
769
+	if (!empty($arrayfields['e.date_delivery']['checked']))  print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"], "e.date_delivery", "", $param, 'align="center"', $sortfield, $sortorder);
770
+	if (!empty($arrayfields['l.ref']['checked']))            print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"], "l.ref", "", $param, '', $sortfield, $sortorder);
771
+	if (!empty($arrayfields['l.date_delivery']['checked']))  print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"], "l.date_delivery", "", $param, 'align="center"', $sortfield, $sortorder);
772 772
 	// Extra fields
773 773
 	if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
774 774
 	{
775
-	    foreach($extrafields->attribute_label as $key => $val)
775
+	    foreach ($extrafields->attribute_label as $key => $val)
776 776
 	    {
777
-	        if (! empty($arrayfields["ef.".$key]['checked']))
777
+	        if (!empty($arrayfields["ef.".$key]['checked']))
778 778
 	        {
779
-	            $align=$extrafields->getAlignFlag($key);
779
+	            $align = $extrafields->getAlignFlag($key);
780 780
     			$sortonfield = "ef.".$key;
781
-    			if (! empty($extrafields->attribute_computed[$key])) $sortonfield='';
782
-    			print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
781
+    			if (!empty($extrafields->attribute_computed[$key])) $sortonfield = '';
782
+    			print_liste_field_titre($extralabels[$key], $_SERVER["PHP_SELF"], $sortonfield, "", $param, ($align ? 'align="'.$align.'"' : ''), $sortfield, $sortorder);
783 783
 	        }
784 784
 	    }
785 785
 	}
786 786
 	// Hook fields
787
-	$parameters=array('arrayfields'=>$arrayfields);
788
-	$reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters);    // Note that $action and $object may have been modified by hook
787
+	$parameters = array('arrayfields'=>$arrayfields);
788
+	$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
789 789
 	print $hookmanager->resPrint;
790
-	if (! empty($arrayfields['e.datec']['checked']))  print_liste_field_titre($arrayfields['e.datec']['label'],$_SERVER["PHP_SELF"],"e.date_creation","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
791
-	if (! empty($arrayfields['e.tms']['checked']))    print_liste_field_titre($arrayfields['e.tms']['label'],$_SERVER["PHP_SELF"],"e.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
792
-	if (! empty($arrayfields['e.fk_statut']['checked'])) print_liste_field_titre($arrayfields['e.fk_statut']['label'],$_SERVER["PHP_SELF"],"e.fk_statut","",$param,'align="right"',$sortfield,$sortorder);
793
-	if (! empty($arrayfields['e.billed']['checked'])) print_liste_field_titre($arrayfields['e.billed']['label'],$_SERVER["PHP_SELF"],"e.billed","",$param,'align="center"',$sortfield,$sortorder);
794
-	print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
790
+	if (!empty($arrayfields['e.datec']['checked']))  print_liste_field_titre($arrayfields['e.datec']['label'], $_SERVER["PHP_SELF"], "e.date_creation", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
791
+	if (!empty($arrayfields['e.tms']['checked']))    print_liste_field_titre($arrayfields['e.tms']['label'], $_SERVER["PHP_SELF"], "e.tms", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
792
+	if (!empty($arrayfields['e.fk_statut']['checked'])) print_liste_field_titre($arrayfields['e.fk_statut']['label'], $_SERVER["PHP_SELF"], "e.fk_statut", "", $param, 'align="right"', $sortfield, $sortorder);
793
+	if (!empty($arrayfields['e.billed']['checked'])) print_liste_field_titre($arrayfields['e.billed']['label'], $_SERVER["PHP_SELF"], "e.billed", "", $param, 'align="center"', $sortfield, $sortorder);
794
+	print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
795 795
 	print "</tr>\n";
796 796
 
797
-	$i=0;
798
-	$var=true;
799
-	$totalarray=array();
800
-	while ($i < min($num,$limit))
797
+	$i = 0;
798
+	$var = true;
799
+	$totalarray = array();
800
+	while ($i < min($num, $limit))
801 801
 	{
802 802
 		$obj = $db->fetch_object($resql);
803 803
 
804
-    	$reception->id=$obj->rowid;
805
-    	$reception->ref=$obj->ref;
804
+    	$reception->id = $obj->rowid;
805
+    	$reception->ref = $obj->ref;
806 806
 
807
-    	$companystatic->id=$obj->socid;
808
-    	$companystatic->ref=$obj->name;
809
-    	$companystatic->name=$obj->name;
807
+    	$companystatic->id = $obj->socid;
808
+    	$companystatic->ref = $obj->name;
809
+    	$companystatic->name = $obj->name;
810 810
 
811 811
 
812 812
     	print '<tr class="oddeven">';
813 813
 
814 814
 		// Ref
815
-		if (! empty($arrayfields['e.ref']['checked']))
815
+		if (!empty($arrayfields['e.ref']['checked']))
816 816
 		{
817 817
     		print "<td>";
818 818
     		print $reception->getNomUrl(1);
819
-    		$filename=dol_sanitizeFileName($reception->ref);
820
-    		$filedir=$conf->reception->dir_output . '/' . dol_sanitizeFileName($reception->ref);
821
-    		$urlsource=$_SERVER['PHP_SELF'].'?id='.$reception->rowid;
819
+    		$filename = dol_sanitizeFileName($reception->ref);
820
+    		$filedir = $conf->reception->dir_output.'/'.dol_sanitizeFileName($reception->ref);
821
+    		$urlsource = $_SERVER['PHP_SELF'].'?id='.$reception->rowid;
822 822
     		print $formfile->getDocumentsLink($reception->element, $filename, $filedir);
823 823
     		print "</td>\n";
824 824
 
825
-    		if (! $i) $totalarray['nbfield']++;
825
+    		if (!$i) $totalarray['nbfield']++;
826 826
 		}
827 827
 
828 828
 		// Ref customer
829
-		if (! empty($arrayfields['e.ref_supplier']['checked']))
829
+		if (!empty($arrayfields['e.ref_supplier']['checked']))
830 830
 		{
831 831
 		    print "<td>";
832 832
 		    print $obj->ref_supplier;
833 833
 		    print "</td>\n";
834
-		    if (! $i) $totalarray['nbfield']++;
834
+		    if (!$i) $totalarray['nbfield']++;
835 835
 		}
836 836
 
837 837
 		// Third party
838
-		if (! empty($arrayfields['s.nom']['checked']))
838
+		if (!empty($arrayfields['s.nom']['checked']))
839 839
 		{
840 840
     		print '<td>';
841 841
     		print $companystatic->getNomUrl(1);
842 842
     		print '</td>';
843
-    		if (! $i) $totalarray['nbfield']++;
843
+    		if (!$i) $totalarray['nbfield']++;
844 844
 		}
845 845
 		// Town
846
-		if (! empty($arrayfields['s.town']['checked']))
846
+		if (!empty($arrayfields['s.town']['checked']))
847 847
 		{
848 848
 		    print '<td class="nocellnopadd">';
849 849
 		    print $obj->town;
850 850
 		    print '</td>';
851
-		    if (! $i) $totalarray['nbfield']++;
851
+		    if (!$i) $totalarray['nbfield']++;
852 852
 		}
853 853
 		// Zip
854
-		if (! empty($arrayfields['s.zip']['checked']))
854
+		if (!empty($arrayfields['s.zip']['checked']))
855 855
 		{
856 856
 		    print '<td class="nocellnopadd">';
857 857
 		    print $obj->zip;
858 858
 		    print '</td>';
859
-		    if (! $i) $totalarray['nbfield']++;
859
+		    if (!$i) $totalarray['nbfield']++;
860 860
 		}
861 861
 		// State
862
-		if (! empty($arrayfields['state.nom']['checked']))
862
+		if (!empty($arrayfields['state.nom']['checked']))
863 863
 		{
864 864
 		    print "<td>".$obj->state_name."</td>\n";
865
-		    if (! $i) $totalarray['nbfield']++;
865
+		    if (!$i) $totalarray['nbfield']++;
866 866
 		}
867 867
 		// Country
868
-		if (! empty($arrayfields['country.code_iso']['checked']))
868
+		if (!empty($arrayfields['country.code_iso']['checked']))
869 869
 		{
870 870
 		    print '<td align="center">';
871
-		    $tmparray=getCountry($obj->fk_pays,'all');
871
+		    $tmparray = getCountry($obj->fk_pays, 'all');
872 872
 		    print $tmparray['label'];
873 873
 		    print '</td>';
874
-		    if (! $i) $totalarray['nbfield']++;
874
+		    if (!$i) $totalarray['nbfield']++;
875 875
 		}
876 876
 		// Type ent
877
-		if (! empty($arrayfields['typent.code']['checked']))
877
+		if (!empty($arrayfields['typent.code']['checked']))
878 878
 		{
879 879
 		    print '<td align="center">';
880
-		    if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
880
+		    if (count($typenArray) == 0) $typenArray = $formcompany->typent_array(1);
881 881
 		    print $typenArray[$obj->typent_code];
882 882
 		    print '</td>';
883
-		    if (! $i) $totalarray['nbfield']++;
883
+		    if (!$i) $totalarray['nbfield']++;
884 884
 		}
885 885
 
886 886
 		// Date delivery planed
887
-		if (! empty($arrayfields['e.date_delivery']['checked']))
887
+		if (!empty($arrayfields['e.date_delivery']['checked']))
888 888
 		{
889 889
     		print '<td align="center">';
890
-    		print dol_print_date($db->jdate($obj->date_livraison),"day");
890
+    		print dol_print_date($db->jdate($obj->date_livraison), "day");
891 891
     		/*$now = time();
892 892
     		if ( ($now - $db->jdate($obj->date_reception)) > $conf->warnings->lim && $obj->statutid == 1 )
893 893
     		{
@@ -895,13 +895,13 @@  discard block
 block discarded – undo
895 895
     		print "</td>\n";
896 896
 		}
897 897
 
898
-		if (! empty($arrayfields['l.ref']['checked']) || ! empty($arrayfields['l.date_delivery']['checked']))
898
+		if (!empty($arrayfields['l.ref']['checked']) || !empty($arrayfields['l.date_delivery']['checked']))
899 899
         {
900
-		    $reception->fetchObjectLinked($reception->id,$reception->element);
901
-            $receiving='';
902
-            if (count($reception->linkedObjects['delivery']) > 0) $receiving=reset($reception->linkedObjects['delivery']);
900
+		    $reception->fetchObjectLinked($reception->id, $reception->element);
901
+            $receiving = '';
902
+            if (count($reception->linkedObjects['delivery']) > 0) $receiving = reset($reception->linkedObjects['delivery']);
903 903
 
904
-    		if (! empty($arrayfields['l.ref']['checked']))
904
+    		if (!empty($arrayfields['l.ref']['checked']))
905 905
             {
906 906
                 // Ref
907 907
                 print '<td>';
@@ -909,11 +909,11 @@  discard block
 block discarded – undo
909 909
                 print '</td>';
910 910
             }
911 911
 
912
-    		if (! empty($arrayfields['l.date_delivery']['checked']))
912
+    		if (!empty($arrayfields['l.date_delivery']['checked']))
913 913
             {
914 914
                 // Date received
915 915
             	print '<td align="center">';
916
-    			print dol_print_date($db->jdate($obj->date_reception),"day");
916
+    			print dol_print_date($db->jdate($obj->date_reception), "day");
917 917
     			print '</td>'."\n";
918 918
             }
919 919
 		}
@@ -921,64 +921,64 @@  discard block
 block discarded – undo
921 921
 		// Extra fields
922 922
 		if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
923 923
 		{
924
-		    foreach($extrafields->attribute_label as $key => $val)
924
+		    foreach ($extrafields->attribute_label as $key => $val)
925 925
 		    {
926
-		        if (! empty($arrayfields["ef.".$key]['checked']))
926
+		        if (!empty($arrayfields["ef.".$key]['checked']))
927 927
 		        {
928 928
 		            print '<td class="tdofextrafield"';
929
-		            $align=$extrafields->getAlignFlag($key);
929
+		            $align = $extrafields->getAlignFlag($key);
930 930
 		            if ($align) print ' align="'.$align.'"';
931 931
 		            print '>';
932
-		            $tmpkey='options_'.$key;
932
+		            $tmpkey = 'options_'.$key;
933 933
 		            print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
934 934
 		            print '</td>';
935
-		            if (! $i) $totalarray['nbfield']++;
935
+		            if (!$i) $totalarray['nbfield']++;
936 936
 		        }
937 937
 		    }
938 938
 		}
939 939
 		// Fields from hook
940
-		$parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
941
-		$reshook=$hookmanager->executeHooks('printFieldListValue',$parameters);    // Note that $action and $object may have been modified by hook
940
+		$parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj);
941
+		$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
942 942
 		print $hookmanager->resPrint;
943 943
 		// Date creation
944
-		if (! empty($arrayfields['e.datec']['checked']))
944
+		if (!empty($arrayfields['e.datec']['checked']))
945 945
 		{
946 946
 		    print '<td align="center" class="nowrap">';
947 947
 		    print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
948 948
 		    print '</td>';
949
-		    if (! $i) $totalarray['nbfield']++;
949
+		    if (!$i) $totalarray['nbfield']++;
950 950
 		}
951 951
 		// Date modification
952
-		if (! empty($arrayfields['e.tms']['checked']))
952
+		if (!empty($arrayfields['e.tms']['checked']))
953 953
 		{
954 954
 		    print '<td align="center" class="nowrap">';
955 955
 		    print dol_print_date($db->jdate($obj->date_update), 'dayhour');
956 956
 		    print '</td>';
957
-		    if (! $i) $totalarray['nbfield']++;
957
+		    if (!$i) $totalarray['nbfield']++;
958 958
 		}
959 959
 		// Status
960
-		if (! empty($arrayfields['e.fk_statut']['checked']))
960
+		if (!empty($arrayfields['e.fk_statut']['checked']))
961 961
 		{
962
-		    print '<td align="right" class="nowrap">'.$reception->LibStatut($obj->fk_statut,5).'</td>';
963
-		    if (! $i) $totalarray['nbfield']++;
962
+		    print '<td align="right" class="nowrap">'.$reception->LibStatut($obj->fk_statut, 5).'</td>';
963
+		    if (!$i) $totalarray['nbfield']++;
964 964
 		}
965 965
 		// Billed
966
-		if (! empty($arrayfields['e.billed']['checked']))
966
+		if (!empty($arrayfields['e.billed']['checked']))
967 967
 		{
968 968
 			print '<td align="center">'.yn($obj->billed).'</td>';
969
-			if (! $i) $totalarray['nbfield']++;
969
+			if (!$i) $totalarray['nbfield']++;
970 970
 		}
971 971
 
972 972
 		// Action column
973 973
 		print '<td align="center">';
974 974
 		if ($massactionbutton || $massaction)   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
975 975
         {
976
-            $selected=0;
977
-    		if (in_array($obj->rowid, $arrayofselected)) $selected=1;
978
-    		print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
976
+            $selected = 0;
977
+    		if (in_array($obj->rowid, $arrayofselected)) $selected = 1;
978
+    		print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
979 979
         }
980 980
 		print '</td>';
981
-		if (! $i) $totalarray['nbfield']++;
981
+		if (!$i) $totalarray['nbfield']++;
982 982
 
983 983
 		print "</tr>\n";
984 984
 
Please login to merge, or discard this patch.