Passed
Push — master ( 49af33...3cffbe )
by Alxarafe
21:21
created
dolibarr/htdocs/margin/productMargins.php 3 patches
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -57,24 +57,24 @@  discard block
 block discarded – undo
57 57
 $pagenext = $page + 1;
58 58
 if (! $sortfield)
59 59
 {
60
-	if ($id > 0)
61
-	{
62
-		$sortfield="f.datef";
63
-		$sortorder="DESC";
64
-	}
65
-	else
66
-	{
67
-	    $sortfield="p.ref";
68
-	    $sortorder="ASC";
69
-	}
60
+    if ($id > 0)
61
+    {
62
+        $sortfield="f.datef";
63
+        $sortorder="DESC";
64
+    }
65
+    else
66
+    {
67
+        $sortfield="p.ref";
68
+        $sortorder="ASC";
69
+    }
70 70
 }
71 71
 
72 72
 $startdate=$enddate='';
73 73
 
74 74
 if (!empty($_POST['startdatemonth']))
75
-  $startdate  = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']);
75
+    $startdate  = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']);
76 76
 if (!empty($_POST['enddatemonth']))
77
-  $enddate  = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']);
77
+    $enddate  = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']);
78 78
 
79 79
 
80 80
 /*
@@ -104,19 +104,19 @@  discard block
 block discarded – undo
104 104
 
105 105
 if ($id > 0) {
106 106
 
107
-  print '<tr><td class="titlefield">'.$langs->trans('ChooseProduct/Service').'</td>';
108
-  print '<td class="maxwidthonsmartpone" colspan="4">';
109
-  print $form->select_produits($id,'id','',20,0,1,2,'',1, array(), 0, 'All');
110
-  print '</td></tr>';
107
+    print '<tr><td class="titlefield">'.$langs->trans('ChooseProduct/Service').'</td>';
108
+    print '<td class="maxwidthonsmartpone" colspan="4">';
109
+    print $form->select_produits($id,'id','',20,0,1,2,'',1, array(), 0, 'All');
110
+    print '</td></tr>';
111 111
 
112
-  if (! $sortorder) $sortorder="DESC";
113
-  if (! $sortfield) $sortfield="f.datef";
112
+    if (! $sortorder) $sortorder="DESC";
113
+    if (! $sortfield) $sortfield="f.datef";
114 114
 }
115 115
 else {
116
-	print '<tr><td class="titlefield">'.$langs->trans('ChooseProduct/Service').'</td>';
117
-	print '<td class="maxwidthonsmartphone" colspan="4">';
118
-	print $form->select_produits('','id','',20,0,1,2,'',1, array(), 0, 'All');
119
-	print '</td></tr>';
116
+    print '<tr><td class="titlefield">'.$langs->trans('ChooseProduct/Service').'</td>';
117
+    print '<td class="maxwidthonsmartphone" colspan="4">';
118
+    print $form->select_produits('','id','',20,0,1,2,'',1, array(), 0, 'All');
119
+    print '</td></tr>';
120 120
 }
121 121
 
122 122
 // Categories
@@ -156,16 +156,16 @@  discard block
 block discarded – undo
156 156
 
157 157
 // Margin Rate
158 158
 if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
159
-	print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="4">';
160
-	print '<span id="marginRate"></span>'; // set by jquery (see below)
161
-	print '</td></tr>';
159
+    print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="4">';
160
+    print '<span id="marginRate"></span>'; // set by jquery (see below)
161
+    print '</td></tr>';
162 162
 }
163 163
 
164 164
 // Mark Rate
165 165
 if (! empty($conf->global->DISPLAY_MARK_RATES)) {
166
-	print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="4">';
167
-	print '<span id="markRate"></span>'; // set by jquery (see below)
168
-	print '</td></tr>';
166
+    print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="4">';
167
+    print '<span id="markRate"></span>'; // set by jquery (see below)
168
+    print '</td></tr>';
169 169
 }
170 170
 
171 171
 print "</table>";
@@ -186,24 +186,24 @@  discard block
 block discarded – undo
186 186
 $sql.= ", ".MAIN_DB_PREFIX."facturedet as d";
187 187
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = d.fk_product";
188 188
 if (! empty($TSelectedCats)) {
189
-	$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=p.rowid';
189
+    $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=p.rowid';
190 190
 }
191 191
 $sql.= " WHERE f.fk_soc = s.rowid";
192 192
 $sql.= ' AND f.entity IN ('.getEntity('invoice').')';
193 193
 $sql.= " AND f.fk_statut > 0";
194 194
 $sql.= " AND d.fk_facture = f.rowid";
195 195
 if ($id > 0)
196
-	$sql.= " AND d.fk_product =".$id;
196
+    $sql.= " AND d.fk_product =".$id;
197 197
 if (! empty($TSelectedCats)) {
198
-	$sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats) . ')';
198
+    $sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats) . ')';
199 199
 }
200 200
 if (!empty($startdate))
201
-  $sql.= " AND f.datef >= '".$db->idate($startdate)."'";
201
+    $sql.= " AND f.datef >= '".$db->idate($startdate)."'";
202 202
 if (!empty($enddate))
203
-  $sql.= " AND f.datef <= '".$db->idate($enddate)."'";
203
+    $sql.= " AND f.datef <= '".$db->idate($enddate)."'";
204 204
 $sql .= " AND d.buy_price_ht IS NOT NULL";
205 205
 if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)
206
-	$sql .= " AND d.buy_price_ht <> 0";
206
+    $sql .= " AND d.buy_price_ht <> 0";
207 207
 if ($id > 0) $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, p.entity, d.fk_product, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut";
208 208
 else $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, p.entity";
209 209
 $sql.=$db->order($sortfield,$sortorder);
@@ -214,137 +214,137 @@  discard block
 block discarded – undo
214 214
 $result = $db->query($sql);
215 215
 if ($result)
216 216
 {
217
-	$num = $db->num_rows($result);
217
+    $num = $db->num_rows($result);
218 218
 
219
-	print '<br>';
220
-	print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "&amp;id=".$id, $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1);
219
+    print '<br>';
220
+    print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "&amp;id=".$id, $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1);
221 221
 
222
-	//var_dump($conf->global->MARGIN_TYPE);
223
-	if ($conf->global->MARGIN_TYPE == "1")
224
-	    $labelcostprice='BuyingPrice';
225
-	else   // value is 'costprice' or 'pmp'
226
-	    $labelcostprice='CostPrice';
222
+    //var_dump($conf->global->MARGIN_TYPE);
223
+    if ($conf->global->MARGIN_TYPE == "1")
224
+        $labelcostprice='BuyingPrice';
225
+    else   // value is 'costprice' or 'pmp'
226
+        $labelcostprice='CostPrice';
227 227
 
228
-	$moreforfilter='';
228
+    $moreforfilter='';
229 229
 
230
-	$i = 0;
230
+    $i = 0;
231 231
     print '<div class="div-table-responsive">';
232 232
     print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
233 233
 
234
-	print '<tr class="liste_titre">';
235
-	if ($id > 0) {
236
-  		print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&amp;id=".$id,'',$sortfield,$sortorder);
237
-  		print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&amp;id=".$id,'align="center"',$sortfield,$sortorder);
238
-  	}
239
-  	else
240
-  	{
241
-  		print_liste_field_titre("ProductService",$_SERVER["PHP_SELF"],"p.ref","","&amp;id=".$id,'',$sortfield,$sortorder);
242
-  	}
243
-	print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
244
-	print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
245
-	print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
246
-	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
247
-		print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
248
-	if (! empty($conf->global->DISPLAY_MARK_RATES))
249
-		print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
250
-	print "</tr>\n";
251
-
252
-	$cumul_achat = 0;
253
-	$cumul_vente = 0;
254
-	$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
255
-
256
-	if ($num > 0)
257
-	{
258
-		while ($i < $num /*&& $i < $conf->liste_limit*/)
259
-		{
260
-			$objp = $db->fetch_object($result);
261
-			$pa = $objp->buying_price;
262
-			$pv = $objp->selling_price;
263
-			$marge = $objp->marge;
264
-
265
-			if ($marge < 0)
266
-			{
267
-				$marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ;
268
-				$markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ;
269
-			}
270
-			else
271
-			{
272
-				$marginRate = ($pa != 0)?(100 * $marge / $pa):'' ;
273
-				$markRate = ($pv != 0)?(100 * $marge / $pv):'' ;
274
-			}
275
-
276
-			print '<tr class="oddeven">';
277
-			if ($id > 0) {
278
-				print '<td>';
279
-				$invoicestatic->id=$objp->facid;
280
-				$invoicestatic->ref=$objp->ref;
281
-				print $invoicestatic->getNomUrl(1);
282
-				print "</td>\n";
283
-				print "<td align=\"center\">";
284
-				print dol_print_date($db->jdate($objp->datef),'day')."</td>";
285
-			}
286
-			else {
287
-				print '<td>';
288
-				if ($objp->rowid > 0)
289
-				{
290
-    				$product_static->type=$objp->fk_product_type;
291
-    				$product_static->id=$objp->rowid;
292
-    				$product_static->ref=$objp->ref;
293
-    				$product_static->label=$objp->label;
294
-    				$product_static->entity=$objp->pentity;
295
-    				$text=$product_static->getNomUrl(1);
296
-    				print $text.= ' - '.$objp->label;
297
-				}
298
-				else
299
-				{
300
-				    print img_object('', 'product').' '.$langs->trans("NotPredefinedProducts");
301
-				}
302
-				print "</td>\n";
303
-				//print "<td>".$product_static->getNomUrl(1)."</td>\n";
304
-			}
305
-			print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n";
306
-			print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n";
307
-			print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n";
308
-			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
309
-				print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
310
-			if (! empty($conf->global->DISPLAY_MARK_RATES))
311
-				print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
312
-			print "</tr>\n";
313
-
314
-			$i++;
315
-			$cumul_achat += $objp->buying_price;
316
-			$cumul_vente += $objp->selling_price;
317
-		}
318
-	}
319
-
320
-	// affichage totaux marges
321
-
322
-	$totalMargin = $cumul_vente - $cumul_achat;
323
-
324
-	$marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):'';
325
-	$markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):'';
326
-
327
-	print '<tr class="liste_total">';
328
-	if ($id > 0)
329
-		print '<td colspan=2>';
330
-	else
331
-		print '<td>';
332
-	print $langs->trans('TotalMargin')."</td>";
333
-	print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n";
334
-	print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n";
335
-	print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n";
336
-	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
337
-		print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
338
-	if (! empty($conf->global->DISPLAY_MARK_RATES))
339
-		print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
340
-	print "</tr>\n";
341
-
342
-	print "</table>";
343
-	print '</div>';
234
+    print '<tr class="liste_titre">';
235
+    if ($id > 0) {
236
+            print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&amp;id=".$id,'',$sortfield,$sortorder);
237
+            print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&amp;id=".$id,'align="center"',$sortfield,$sortorder);
238
+        }
239
+        else
240
+        {
241
+            print_liste_field_titre("ProductService",$_SERVER["PHP_SELF"],"p.ref","","&amp;id=".$id,'',$sortfield,$sortorder);
242
+        }
243
+    print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
244
+    print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
245
+    print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
246
+    if (! empty($conf->global->DISPLAY_MARGIN_RATES))
247
+        print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
248
+    if (! empty($conf->global->DISPLAY_MARK_RATES))
249
+        print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
250
+    print "</tr>\n";
251
+
252
+    $cumul_achat = 0;
253
+    $cumul_vente = 0;
254
+    $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
255
+
256
+    if ($num > 0)
257
+    {
258
+        while ($i < $num /*&& $i < $conf->liste_limit*/)
259
+        {
260
+            $objp = $db->fetch_object($result);
261
+            $pa = $objp->buying_price;
262
+            $pv = $objp->selling_price;
263
+            $marge = $objp->marge;
264
+
265
+            if ($marge < 0)
266
+            {
267
+                $marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ;
268
+                $markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ;
269
+            }
270
+            else
271
+            {
272
+                $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ;
273
+                $markRate = ($pv != 0)?(100 * $marge / $pv):'' ;
274
+            }
275
+
276
+            print '<tr class="oddeven">';
277
+            if ($id > 0) {
278
+                print '<td>';
279
+                $invoicestatic->id=$objp->facid;
280
+                $invoicestatic->ref=$objp->ref;
281
+                print $invoicestatic->getNomUrl(1);
282
+                print "</td>\n";
283
+                print "<td align=\"center\">";
284
+                print dol_print_date($db->jdate($objp->datef),'day')."</td>";
285
+            }
286
+            else {
287
+                print '<td>';
288
+                if ($objp->rowid > 0)
289
+                {
290
+                    $product_static->type=$objp->fk_product_type;
291
+                    $product_static->id=$objp->rowid;
292
+                    $product_static->ref=$objp->ref;
293
+                    $product_static->label=$objp->label;
294
+                    $product_static->entity=$objp->pentity;
295
+                    $text=$product_static->getNomUrl(1);
296
+                    print $text.= ' - '.$objp->label;
297
+                }
298
+                else
299
+                {
300
+                    print img_object('', 'product').' '.$langs->trans("NotPredefinedProducts");
301
+                }
302
+                print "</td>\n";
303
+                //print "<td>".$product_static->getNomUrl(1)."</td>\n";
304
+            }
305
+            print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n";
306
+            print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n";
307
+            print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n";
308
+            if (! empty($conf->global->DISPLAY_MARGIN_RATES))
309
+                print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
310
+            if (! empty($conf->global->DISPLAY_MARK_RATES))
311
+                print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
312
+            print "</tr>\n";
313
+
314
+            $i++;
315
+            $cumul_achat += $objp->buying_price;
316
+            $cumul_vente += $objp->selling_price;
317
+        }
318
+    }
319
+
320
+    // affichage totaux marges
321
+
322
+    $totalMargin = $cumul_vente - $cumul_achat;
323
+
324
+    $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):'';
325
+    $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):'';
326
+
327
+    print '<tr class="liste_total">';
328
+    if ($id > 0)
329
+        print '<td colspan=2>';
330
+    else
331
+        print '<td>';
332
+    print $langs->trans('TotalMargin')."</td>";
333
+    print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n";
334
+    print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n";
335
+    print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n";
336
+    if (! empty($conf->global->DISPLAY_MARGIN_RATES))
337
+        print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
338
+    if (! empty($conf->global->DISPLAY_MARK_RATES))
339
+        print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
340
+    print "</tr>\n";
341
+
342
+    print "</table>";
343
+    print '</div>';
344 344
 }
345 345
 else
346 346
 {
347
-	dol_print_error($db);
347
+    dol_print_error($db);
348 348
 }
349 349
 $db->free($result);
350 350
 
Please login to merge, or discard this patch.
Braces   +67 added lines, -46 removed lines patch added patch discarded remove patch
@@ -40,7 +40,9 @@  discard block
 block discarded – undo
40 40
 // Security check
41 41
 $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
42 42
 $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
43
-if (! empty($user->societe_id)) $socid=$user->societe_id;
43
+if (! empty($user->societe_id)) {
44
+    $socid=$user->societe_id;
45
+}
44 46
 $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
45 47
 $result=restrictedArea($user,'margins');
46 48
 
@@ -61,8 +63,7 @@  discard block
 block discarded – undo
61 63
 	{
62 64
 		$sortfield="f.datef";
63 65
 		$sortorder="DESC";
64
-	}
65
-	else
66
+	} else
66 67
 	{
67 68
 	    $sortfield="p.ref";
68 69
 	    $sortorder="ASC";
@@ -71,10 +72,12 @@  discard block
 block discarded – undo
71 72
 
72 73
 $startdate=$enddate='';
73 74
 
74
-if (!empty($_POST['startdatemonth']))
75
+if (!empty($_POST['startdatemonth'])) {
75 76
   $startdate  = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']);
76
-if (!empty($_POST['enddatemonth']))
77
+}
78
+if (!empty($_POST['enddatemonth'])) {
77 79
   $enddate  = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']);
80
+}
78 81
 
79 82
 
80 83
 /*
@@ -109,10 +112,13 @@  discard block
 block discarded – undo
109 112
   print $form->select_produits($id,'id','',20,0,1,2,'',1, array(), 0, 'All');
110 113
   print '</td></tr>';
111 114
 
112
-  if (! $sortorder) $sortorder="DESC";
113
-  if (! $sortfield) $sortfield="f.datef";
114
-}
115
-else {
115
+  if (! $sortorder) {
116
+      $sortorder="DESC";
117
+  }
118
+  if (! $sortfield) {
119
+      $sortfield="f.datef";
120
+  }
121
+  } else {
116 122
 	print '<tr><td class="titlefield">'.$langs->trans('ChooseProduct/Service').'</td>';
117 123
 	print '<td class="maxwidthonsmartphone" colspan="4">';
118 124
 	print $form->select_produits('','id','',20,0,1,2,'',1, array(), 0, 'All');
@@ -175,8 +181,12 @@  discard block
 block discarded – undo
175 181
 print '</form>';
176 182
 
177 183
 $sql = "SELECT p.label, p.rowid, p.fk_product_type, p.ref, p.entity as pentity,";
178
-if ($id > 0) $sql.= " d.fk_product,";
179
-if ($id > 0) $sql.= " f.rowid as facid, f.ref, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,";
184
+if ($id > 0) {
185
+    $sql.= " d.fk_product,";
186
+}
187
+if ($id > 0) {
188
+    $sql.= " f.rowid as facid, f.ref, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,";
189
+}
180 190
 $sql.= " SUM(d.total_ht) as selling_price,";
181 191
 // Note: qty and buy_price_ht is always positive (if not your database may be corrupted, you can update this)
182 192
 $sql.= " SUM(".$db->ifsql('d.total_ht < 0','d.qty * d.buy_price_ht * -1','d.qty * d.buy_price_ht').") as buying_price,";
@@ -192,20 +202,27 @@  discard block
 block discarded – undo
192 202
 $sql.= ' AND f.entity IN ('.getEntity('invoice').')';
193 203
 $sql.= " AND f.fk_statut > 0";
194 204
 $sql.= " AND d.fk_facture = f.rowid";
195
-if ($id > 0)
205
+if ($id > 0) {
196 206
 	$sql.= " AND d.fk_product =".$id;
207
+}
197 208
 if (! empty($TSelectedCats)) {
198 209
 	$sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats) . ')';
199 210
 }
200
-if (!empty($startdate))
211
+if (!empty($startdate)) {
201 212
   $sql.= " AND f.datef >= '".$db->idate($startdate)."'";
202
-if (!empty($enddate))
213
+}
214
+if (!empty($enddate)) {
203 215
   $sql.= " AND f.datef <= '".$db->idate($enddate)."'";
216
+}
204 217
 $sql .= " AND d.buy_price_ht IS NOT NULL";
205
-if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)
218
+if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) {
206 219
 	$sql .= " AND d.buy_price_ht <> 0";
207
-if ($id > 0) $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, p.entity, d.fk_product, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut";
208
-else $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, p.entity";
220
+}
221
+if ($id > 0) {
222
+    $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, p.entity, d.fk_product, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut";
223
+} else {
224
+    $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, p.entity";
225
+}
209 226
 $sql.=$db->order($sortfield,$sortorder);
210 227
 // TODO: calculate total to display then restore pagination
211 228
 //$sql.= $db->plimit($conf->liste_limit +1, $offset);
@@ -220,10 +237,12 @@  discard block
 block discarded – undo
220 237
 	print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "&amp;id=".$id, $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1);
221 238
 
222 239
 	//var_dump($conf->global->MARGIN_TYPE);
223
-	if ($conf->global->MARGIN_TYPE == "1")
224
-	    $labelcostprice='BuyingPrice';
225
-	else   // value is 'costprice' or 'pmp'
240
+	if ($conf->global->MARGIN_TYPE == "1") {
241
+		    $labelcostprice='BuyingPrice';
242
+	} else {
243
+	    // value is 'costprice' or 'pmp'
226 244
 	    $labelcostprice='CostPrice';
245
+	}
227 246
 
228 247
 	$moreforfilter='';
229 248
 
@@ -235,18 +254,19 @@  discard block
 block discarded – undo
235 254
 	if ($id > 0) {
236 255
   		print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&amp;id=".$id,'',$sortfield,$sortorder);
237 256
   		print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&amp;id=".$id,'align="center"',$sortfield,$sortorder);
238
-  	}
239
-  	else
257
+  	} else
240 258
   	{
241 259
   		print_liste_field_titre("ProductService",$_SERVER["PHP_SELF"],"p.ref","","&amp;id=".$id,'',$sortfield,$sortorder);
242 260
   	}
243 261
 	print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
244 262
 	print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
245 263
 	print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
246
-	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
247
-		print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
248
-	if (! empty($conf->global->DISPLAY_MARK_RATES))
249
-		print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
264
+	if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
265
+			print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
266
+	}
267
+	if (! empty($conf->global->DISPLAY_MARK_RATES)) {
268
+			print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
269
+	}
250 270
 	print "</tr>\n";
251 271
 
252 272
 	$cumul_achat = 0;
@@ -266,8 +286,7 @@  discard block
 block discarded – undo
266 286
 			{
267 287
 				$marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ;
268 288
 				$markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ;
269
-			}
270
-			else
289
+			} else
271 290
 			{
272 291
 				$marginRate = ($pa != 0)?(100 * $marge / $pa):'' ;
273 292
 				$markRate = ($pv != 0)?(100 * $marge / $pv):'' ;
@@ -282,8 +301,7 @@  discard block
 block discarded – undo
282 301
 				print "</td>\n";
283 302
 				print "<td align=\"center\">";
284 303
 				print dol_print_date($db->jdate($objp->datef),'day')."</td>";
285
-			}
286
-			else {
304
+			} else {
287 305
 				print '<td>';
288 306
 				if ($objp->rowid > 0)
289 307
 				{
@@ -294,8 +312,7 @@  discard block
 block discarded – undo
294 312
     				$product_static->entity=$objp->pentity;
295 313
     				$text=$product_static->getNomUrl(1);
296 314
     				print $text.= ' - '.$objp->label;
297
-				}
298
-				else
315
+				} else
299 316
 				{
300 317
 				    print img_object('', 'product').' '.$langs->trans("NotPredefinedProducts");
301 318
 				}
@@ -305,10 +322,12 @@  discard block
 block discarded – undo
305 322
 			print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n";
306 323
 			print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n";
307 324
 			print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n";
308
-			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
309
-				print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
310
-			if (! empty($conf->global->DISPLAY_MARK_RATES))
311
-				print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
325
+			if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
326
+							print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
327
+			}
328
+			if (! empty($conf->global->DISPLAY_MARK_RATES)) {
329
+							print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
330
+			}
312 331
 			print "</tr>\n";
313 332
 
314 333
 			$i++;
@@ -325,24 +344,26 @@  discard block
 block discarded – undo
325 344
 	$markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):'';
326 345
 
327 346
 	print '<tr class="liste_total">';
328
-	if ($id > 0)
329
-		print '<td colspan=2>';
330
-	else
331
-		print '<td>';
347
+	if ($id > 0) {
348
+			print '<td colspan=2>';
349
+	} else {
350
+			print '<td>';
351
+	}
332 352
 	print $langs->trans('TotalMargin')."</td>";
333 353
 	print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n";
334 354
 	print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n";
335 355
 	print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n";
336
-	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
337
-		print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
338
-	if (! empty($conf->global->DISPLAY_MARK_RATES))
339
-		print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
356
+	if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
357
+			print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
358
+	}
359
+	if (! empty($conf->global->DISPLAY_MARK_RATES)) {
360
+			print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
361
+	}
340 362
 	print "</tr>\n";
341 363
 
342 364
 	print "</table>";
343 365
 	print '</div>';
344
-}
345
-else
366
+} else
346 367
 {
347 368
 	dol_print_error($db);
348 369
 }
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 
26 26
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
27 27
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
28
-require DOL_BASE_PATH . '/main.inc.php';
28
+require DOL_BASE_PATH.'/main.inc.php';
29 29
 
30 30
 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
31 31
 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
@@ -37,48 +37,48 @@  discard block
 block discarded – undo
37 37
 
38 38
 $id = GETPOST('id', 'int');
39 39
 $ref = GETPOST('ref', 'alpha');
40
-$action=GETPOST('action','alpha');
41
-$confirm=GETPOST('confirm','alpha');
42
-$TSelectedCats=GETPOST('categories', 'array');
40
+$action = GETPOST('action', 'alpha');
41
+$confirm = GETPOST('confirm', 'alpha');
42
+$TSelectedCats = GETPOST('categories', 'array');
43 43
 
44 44
 // Security check
45
-$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
46
-$fieldtype = (! empty($ref) ? 'ref' : 'rowid');
47
-if (! empty($user->societe_id)) $socid=$user->societe_id;
48
-$result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
49
-$result=restrictedArea($user,'margins');
45
+$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
46
+$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
47
+if (!empty($user->societe_id)) $socid = $user->societe_id;
48
+$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
49
+$result = restrictedArea($user, 'margins');
50 50
 
51 51
 $mesg = '';
52 52
 
53 53
 // Load variable for pagination
54
-$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
55
-$sortfield = GETPOST('sortfield','alpha');
56
-$sortorder = GETPOST('sortorder','alpha');
57
-$page = GETPOST('page','int');
54
+$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
55
+$sortfield = GETPOST('sortfield', 'alpha');
56
+$sortorder = GETPOST('sortorder', 'alpha');
57
+$page = GETPOST('page', 'int');
58 58
 if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
59 59
 $offset = $limit * $page;
60 60
 $pageprev = $page - 1;
61 61
 $pagenext = $page + 1;
62
-if (! $sortfield)
62
+if (!$sortfield)
63 63
 {
64 64
 	if ($id > 0)
65 65
 	{
66
-		$sortfield="f.datef";
67
-		$sortorder="DESC";
66
+		$sortfield = "f.datef";
67
+		$sortorder = "DESC";
68 68
 	}
69 69
 	else
70 70
 	{
71
-	    $sortfield="p.ref";
72
-	    $sortorder="ASC";
71
+	    $sortfield = "p.ref";
72
+	    $sortorder = "ASC";
73 73
 	}
74 74
 }
75 75
 
76
-$startdate=$enddate='';
76
+$startdate = $enddate = '';
77 77
 
78 78
 if (!empty($_POST['startdatemonth']))
79
-  $startdate  = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']);
79
+  $startdate = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']);
80 80
 if (!empty($_POST['enddatemonth']))
81
-  $enddate  = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']);
81
+  $enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']);
82 82
 
83 83
 
84 84
 /*
@@ -86,19 +86,19 @@  discard block
 block discarded – undo
86 86
  */
87 87
 
88 88
 $product_static = new Product($db);
89
-$invoicestatic=new Facture($db);
89
+$invoicestatic = new Facture($db);
90 90
 
91 91
 $form = new Form($db);
92 92
 
93
-llxHeader('',$langs->trans("Margins").' - '.$langs->trans("Products"));
93
+llxHeader('', $langs->trans("Margins").' - '.$langs->trans("Products"));
94 94
 
95
-$text=$langs->trans("Margins");
95
+$text = $langs->trans("Margins");
96 96
 //print load_fiche_titre($text);
97 97
 
98 98
 // Show tabs
99
-$head=marges_prepare_head($user);
100
-$titre=$langs->trans("Margins");
101
-$picto='margin';
99
+$head = marges_prepare_head($user);
100
+$titre = $langs->trans("Margins");
101
+$picto = 'margin';
102 102
 
103 103
 print '<form method="post" name="sel" action="'.$_SERVER['PHP_SELF'].'">';
104 104
 
@@ -110,16 +110,16 @@  discard block
 block discarded – undo
110 110
 
111 111
   print '<tr><td class="titlefield">'.$langs->trans('ChooseProduct/Service').'</td>';
112 112
   print '<td class="maxwidthonsmartpone" colspan="4">';
113
-  print $form->select_produits($id,'id','',20,0,1,2,'',1, array(), 0, 'All');
113
+  print $form->select_produits($id, 'id', '', 20, 0, 1, 2, '', 1, array(), 0, 'All');
114 114
   print '</td></tr>';
115 115
 
116
-  if (! $sortorder) $sortorder="DESC";
117
-  if (! $sortfield) $sortfield="f.datef";
116
+  if (!$sortorder) $sortorder = "DESC";
117
+  if (!$sortfield) $sortfield = "f.datef";
118 118
 }
119 119
 else {
120 120
 	print '<tr><td class="titlefield">'.$langs->trans('ChooseProduct/Service').'</td>';
121 121
 	print '<td class="maxwidthonsmartphone" colspan="4">';
122
-	print $form->select_produits('','id','',20,0,1,2,'',1, array(), 0, 'All');
122
+	print $form->select_produits('', 'id', '', 20, 0, 1, 2, '', 1, array(), 0, 'All');
123 123
 	print '</td></tr>';
124 124
 }
125 125
 
@@ -159,14 +159,14 @@  discard block
 block discarded – undo
159 159
 print '</td></tr>';
160 160
 
161 161
 // Margin Rate
162
-if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
162
+if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
163 163
 	print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="4">';
164 164
 	print '<span id="marginRate"></span>'; // set by jquery (see below)
165 165
 	print '</td></tr>';
166 166
 }
167 167
 
168 168
 // Mark Rate
169
-if (! empty($conf->global->DISPLAY_MARK_RATES)) {
169
+if (!empty($conf->global->DISPLAY_MARK_RATES)) {
170 170
 	print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="4">';
171 171
 	print '<span id="markRate"></span>'; // set by jquery (see below)
172 172
 	print '</td></tr>';
@@ -179,38 +179,38 @@  discard block
 block discarded – undo
179 179
 print '</form>';
180 180
 
181 181
 $sql = "SELECT p.label, p.rowid, p.fk_product_type, p.ref, p.entity as pentity,";
182
-if ($id > 0) $sql.= " d.fk_product,";
183
-if ($id > 0) $sql.= " f.rowid as facid, f.ref, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,";
184
-$sql.= " SUM(d.total_ht) as selling_price,";
182
+if ($id > 0) $sql .= " d.fk_product,";
183
+if ($id > 0) $sql .= " f.rowid as facid, f.ref, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,";
184
+$sql .= " SUM(d.total_ht) as selling_price,";
185 185
 // Note: qty and buy_price_ht is always positive (if not your database may be corrupted, you can update this)
186
-$sql.= " SUM(".$db->ifsql('d.total_ht < 0','d.qty * d.buy_price_ht * -1','d.qty * d.buy_price_ht').") as buying_price,";
187
-$sql.= " SUM(".$db->ifsql('d.total_ht < 0','-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty))','d.total_ht - (d.buy_price_ht * d.qty)').") as marge";
188
-$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
189
-$sql.= ", ".MAIN_DB_PREFIX."facture as f";
190
-$sql.= ", ".MAIN_DB_PREFIX."facturedet as d";
191
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = d.fk_product";
192
-if (! empty($TSelectedCats)) {
193
-	$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=p.rowid';
186
+$sql .= " SUM(".$db->ifsql('d.total_ht < 0', 'd.qty * d.buy_price_ht * -1', 'd.qty * d.buy_price_ht').") as buying_price,";
187
+$sql .= " SUM(".$db->ifsql('d.total_ht < 0', '-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty))', 'd.total_ht - (d.buy_price_ht * d.qty)').") as marge";
188
+$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
189
+$sql .= ", ".MAIN_DB_PREFIX."facture as f";
190
+$sql .= ", ".MAIN_DB_PREFIX."facturedet as d";
191
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = d.fk_product";
192
+if (!empty($TSelectedCats)) {
193
+	$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=p.rowid';
194 194
 }
195
-$sql.= " WHERE f.fk_soc = s.rowid";
196
-$sql.= ' AND f.entity IN ('.getEntity('invoice').')';
197
-$sql.= " AND f.fk_statut > 0";
198
-$sql.= " AND d.fk_facture = f.rowid";
195
+$sql .= " WHERE f.fk_soc = s.rowid";
196
+$sql .= ' AND f.entity IN ('.getEntity('invoice').')';
197
+$sql .= " AND f.fk_statut > 0";
198
+$sql .= " AND d.fk_facture = f.rowid";
199 199
 if ($id > 0)
200
-	$sql.= " AND d.fk_product =".$id;
201
-if (! empty($TSelectedCats)) {
202
-	$sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats) . ')';
200
+	$sql .= " AND d.fk_product =".$id;
201
+if (!empty($TSelectedCats)) {
202
+	$sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats).')';
203 203
 }
204 204
 if (!empty($startdate))
205
-  $sql.= " AND f.datef >= '".$db->idate($startdate)."'";
205
+  $sql .= " AND f.datef >= '".$db->idate($startdate)."'";
206 206
 if (!empty($enddate))
207
-  $sql.= " AND f.datef <= '".$db->idate($enddate)."'";
207
+  $sql .= " AND f.datef <= '".$db->idate($enddate)."'";
208 208
 $sql .= " AND d.buy_price_ht IS NOT NULL";
209 209
 if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)
210 210
 	$sql .= " AND d.buy_price_ht <> 0";
211
-if ($id > 0) $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, p.entity, d.fk_product, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut";
212
-else $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, p.entity";
213
-$sql.=$db->order($sortfield,$sortorder);
211
+if ($id > 0) $sql .= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, p.entity, d.fk_product, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut";
212
+else $sql .= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, p.entity";
213
+$sql .= $db->order($sortfield, $sortorder);
214 214
 // TODO: calculate total to display then restore pagination
215 215
 //$sql.= $db->plimit($conf->liste_limit +1, $offset);
216 216
 
@@ -225,37 +225,37 @@  discard block
 block discarded – undo
225 225
 
226 226
 	//var_dump($conf->global->MARGIN_TYPE);
227 227
 	if ($conf->global->MARGIN_TYPE == "1")
228
-	    $labelcostprice='BuyingPrice';
228
+	    $labelcostprice = 'BuyingPrice';
229 229
 	else   // value is 'costprice' or 'pmp'
230
-	    $labelcostprice='CostPrice';
230
+	    $labelcostprice = 'CostPrice';
231 231
 
232
-	$moreforfilter='';
232
+	$moreforfilter = '';
233 233
 
234 234
 	$i = 0;
235 235
     print '<div class="div-table-responsive">';
236
-    print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
236
+    print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
237 237
 
238 238
 	print '<tr class="liste_titre">';
239 239
 	if ($id > 0) {
240
-  		print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&amp;id=".$id,'',$sortfield,$sortorder);
241
-  		print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&amp;id=".$id,'align="center"',$sortfield,$sortorder);
240
+  		print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "f.ref", "", "&amp;id=".$id, '', $sortfield, $sortorder);
241
+  		print_liste_field_titre("DateInvoice", $_SERVER["PHP_SELF"], "f.datef", "", "&amp;id=".$id, 'align="center"', $sortfield, $sortorder);
242 242
   	}
243 243
   	else
244 244
   	{
245
-  		print_liste_field_titre("ProductService",$_SERVER["PHP_SELF"],"p.ref","","&amp;id=".$id,'',$sortfield,$sortorder);
245
+  		print_liste_field_titre("ProductService", $_SERVER["PHP_SELF"], "p.ref", "", "&amp;id=".$id, '', $sortfield, $sortorder);
246 246
   	}
247
-	print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
248
-	print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
249
-	print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
250
-	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
251
-		print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
252
-	if (! empty($conf->global->DISPLAY_MARK_RATES))
253
-		print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
247
+	print_liste_field_titre("SellingPrice", $_SERVER["PHP_SELF"], "selling_price", "", "&amp;id=".$id, 'align="right"', $sortfield, $sortorder);
248
+	print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "buying_price", "", "&amp;id=".$id, 'align="right"', $sortfield, $sortorder);
249
+	print_liste_field_titre("Margin", $_SERVER["PHP_SELF"], "marge", "", "&amp;id=".$id, 'align="right"', $sortfield, $sortorder);
250
+	if (!empty($conf->global->DISPLAY_MARGIN_RATES))
251
+		print_liste_field_titre("MarginRate", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$id, 'align="right"', $sortfield, $sortorder);
252
+	if (!empty($conf->global->DISPLAY_MARK_RATES))
253
+		print_liste_field_titre("MarkRate", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$id, 'align="right"', $sortfield, $sortorder);
254 254
 	print "</tr>\n";
255 255
 
256 256
 	$cumul_achat = 0;
257 257
 	$cumul_vente = 0;
258
-	$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
258
+	$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
259 259
 
260 260
 	if ($num > 0)
261 261
 	{
@@ -268,36 +268,36 @@  discard block
 block discarded – undo
268 268
 
269 269
 			if ($marge < 0)
270 270
 			{
271
-				$marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ;
272
-				$markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ;
271
+				$marginRate = ($pa != 0) ?-1 * (100 * $marge / $pa) : '';
272
+				$markRate = ($pv != 0) ?-1 * (100 * $marge / $pv) : '';
273 273
 			}
274 274
 			else
275 275
 			{
276
-				$marginRate = ($pa != 0)?(100 * $marge / $pa):'' ;
277
-				$markRate = ($pv != 0)?(100 * $marge / $pv):'' ;
276
+				$marginRate = ($pa != 0) ? (100 * $marge / $pa) : '';
277
+				$markRate = ($pv != 0) ? (100 * $marge / $pv) : '';
278 278
 			}
279 279
 
280 280
 			print '<tr class="oddeven">';
281 281
 			if ($id > 0) {
282 282
 				print '<td>';
283
-				$invoicestatic->id=$objp->facid;
284
-				$invoicestatic->ref=$objp->ref;
283
+				$invoicestatic->id = $objp->facid;
284
+				$invoicestatic->ref = $objp->ref;
285 285
 				print $invoicestatic->getNomUrl(1);
286 286
 				print "</td>\n";
287 287
 				print "<td align=\"center\">";
288
-				print dol_print_date($db->jdate($objp->datef),'day')."</td>";
288
+				print dol_print_date($db->jdate($objp->datef), 'day')."</td>";
289 289
 			}
290 290
 			else {
291 291
 				print '<td>';
292 292
 				if ($objp->rowid > 0)
293 293
 				{
294
-    				$product_static->type=$objp->fk_product_type;
295
-    				$product_static->id=$objp->rowid;
296
-    				$product_static->ref=$objp->ref;
297
-    				$product_static->label=$objp->label;
298
-    				$product_static->entity=$objp->pentity;
299
-    				$text=$product_static->getNomUrl(1);
300
-    				print $text.= ' - '.$objp->label;
294
+    				$product_static->type = $objp->fk_product_type;
295
+    				$product_static->id = $objp->rowid;
296
+    				$product_static->ref = $objp->ref;
297
+    				$product_static->label = $objp->label;
298
+    				$product_static->entity = $objp->pentity;
299
+    				$text = $product_static->getNomUrl(1);
300
+    				print $text .= ' - '.$objp->label;
301 301
 				}
302 302
 				else
303 303
 				{
@@ -309,10 +309,10 @@  discard block
 block discarded – undo
309 309
 			print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n";
310 310
 			print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n";
311 311
 			print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n";
312
-			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
313
-				print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
314
-			if (! empty($conf->global->DISPLAY_MARK_RATES))
315
-				print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
312
+			if (!empty($conf->global->DISPLAY_MARGIN_RATES))
313
+				print "<td align=\"right\">".(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
314
+			if (!empty($conf->global->DISPLAY_MARK_RATES))
315
+				print "<td align=\"right\">".(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
316 316
 			print "</tr>\n";
317 317
 
318 318
 			$i++;
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
 
326 326
 	$totalMargin = $cumul_vente - $cumul_achat;
327 327
 
328
-	$marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):'';
329
-	$markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):'';
328
+	$marginRate = ($cumul_achat != 0) ? (100 * $totalMargin / $cumul_achat) : '';
329
+	$markRate = ($cumul_vente != 0) ? (100 * $totalMargin / $cumul_vente) : '';
330 330
 
331 331
 	print '<tr class="liste_total">';
332 332
 	if ($id > 0)
@@ -337,10 +337,10 @@  discard block
 block discarded – undo
337 337
 	print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n";
338 338
 	print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n";
339 339
 	print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n";
340
-	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
341
-		print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
342
-	if (! empty($conf->global->DISPLAY_MARK_RATES))
343
-		print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
340
+	if (!empty($conf->global->DISPLAY_MARGIN_RATES))
341
+		print "<td align=\"right\">".(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
342
+	if (!empty($conf->global->DISPLAY_MARK_RATES))
343
+		print "<td align=\"right\">".(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
344 344
 	print "</tr>\n";
345 345
 
346 346
 	print "</table>";
@@ -362,8 +362,8 @@  discard block
 block discarded – undo
362 362
   });
363 363
 
364 364
   $("#totalMargin").html("'.price($totalMargin, null, null, null, null, $rounding).'");
365
-  $("#marginRate").html("'.(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%").'");
366
-  $("#markRate").html("'.(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%").'");
365
+  $("#marginRate").html("'.(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%").'");
366
+  $("#markRate").html("'.(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%").'");
367 367
 
368 368
 });
369 369
 </script>
Please login to merge, or discard this patch.
dolibarr/htdocs/margin/lib/margins.lib.php 3 patches
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -30,25 +30,25 @@  discard block
 block discarded – undo
30 30
  */
31 31
 function marges_admin_prepare_head()
32 32
 {
33
-	global $langs, $conf;
33
+    global $langs, $conf;
34 34
 
35
-	$h = 0;
36
-	$head = array();
35
+    $h = 0;
36
+    $head = array();
37 37
 
38
-	$head[$h][0] = DOL_URL_ROOT."/margin/admin/margin.php";
39
-	$head[$h][1] = $langs->trans("Parameters");
40
-	$head[$h][2] = 'parameters';
41
-	$h++;
38
+    $head[$h][0] = DOL_URL_ROOT."/margin/admin/margin.php";
39
+    $head[$h][1] = $langs->trans("Parameters");
40
+    $head[$h][2] = 'parameters';
41
+    $h++;
42 42
 
43
-	// Show more tabs from modules
44
-	// Entries must be declared in modules descriptor with line
43
+    // Show more tabs from modules
44
+    // Entries must be declared in modules descriptor with line
45 45
     // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
46 46
     // $this->tabs = array('entity:-tabname);   												to remove a tab
47
-	complete_head_from_modules($conf,$langs,'',$head,$h,'margesadmin');
47
+    complete_head_from_modules($conf,$langs,'',$head,$h,'margesadmin');
48 48
 
49
-	complete_head_from_modules($conf,$langs,'',$head,$h,'margesadmin','remove');
49
+    complete_head_from_modules($conf,$langs,'',$head,$h,'margesadmin','remove');
50 50
 
51
-	return $head;
51
+    return $head;
52 52
 }
53 53
 
54 54
 /**
@@ -58,45 +58,45 @@  discard block
 block discarded – undo
58 58
  */
59 59
 function marges_prepare_head()
60 60
 {
61
-	global $langs, $conf, $user;
62
-	$langs->load("margins");
63
-
64
-	$h = 0;
65
-	$head = array();
66
-
67
-	if ($user->rights->produit->lire) {
68
-		$head[$h][0] = DOL_URL_ROOT."/margin/productMargins.php";
69
-		$head[$h][1] = $langs->trans("ProductMargins");
70
-		$head[$h][2] = 'productMargins';
71
-		$h++;
72
-	}
73
-
74
-	if ($user->rights->societe->lire) {
75
-		$head[$h][0] = DOL_URL_ROOT."/margin/customerMargins.php";
76
-		$head[$h][1] = $langs->trans("CustomerMargins");
77
-		$head[$h][2] = 'customerMargins';
78
-		$h++;
79
-	}
80
-
81
-	if ($user->rights->margins->read->all) {
82
-		$title = 'UserMargins';
83
-	} else {
84
-		$title = 'SalesRepresentativeMargins';
85
-	}
86
-
87
-	$head[$h][0] = DOL_URL_ROOT."/margin/agentMargins.php";
88
-	$head[$h][1] = $langs->trans($title);
89
-	$head[$h][2] = 'agentMargins';
61
+    global $langs, $conf, $user;
62
+    $langs->load("margins");
63
+
64
+    $h = 0;
65
+    $head = array();
66
+
67
+    if ($user->rights->produit->lire) {
68
+        $head[$h][0] = DOL_URL_ROOT."/margin/productMargins.php";
69
+        $head[$h][1] = $langs->trans("ProductMargins");
70
+        $head[$h][2] = 'productMargins';
71
+        $h++;
72
+    }
73
+
74
+    if ($user->rights->societe->lire) {
75
+        $head[$h][0] = DOL_URL_ROOT."/margin/customerMargins.php";
76
+        $head[$h][1] = $langs->trans("CustomerMargins");
77
+        $head[$h][2] = 'customerMargins';
78
+        $h++;
79
+    }
80
+
81
+    if ($user->rights->margins->read->all) {
82
+        $title = 'UserMargins';
83
+    } else {
84
+        $title = 'SalesRepresentativeMargins';
85
+    }
86
+
87
+    $head[$h][0] = DOL_URL_ROOT."/margin/agentMargins.php";
88
+    $head[$h][1] = $langs->trans($title);
89
+    $head[$h][2] = 'agentMargins';
90 90
 
91 91
 	
92
-	if ($user->rights->margins->creer) {
93
-		$h++;
94
-		$head[$h][0] = DOL_URL_ROOT."/margin/checkMargins.php";
95
-		$head[$h][1] = $langs->trans('CheckMargins');
96
-		$head[$h][2] = 'checkMargins';
97
-	}
98
-
99
-	return $head;
92
+    if ($user->rights->margins->creer) {
93
+        $h++;
94
+        $head[$h][0] = DOL_URL_ROOT."/margin/checkMargins.php";
95
+        $head[$h][1] = $langs->trans('CheckMargins');
96
+        $head[$h][2] = 'checkMargins';
97
+    }
98
+
99
+    return $head;
100 100
 }
101 101
 
102 102
 /**
@@ -113,46 +113,46 @@  discard block
 block discarded – undo
113 113
  */
114 114
 function getMarginInfos($pvht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $paht)
115 115
 {
116
-	global $db, $conf;
117
-
118
-	$marge_tx_ret='';
119
-	$marque_tx_ret='';
120
-
121
-	if ($fk_pa > 0 && empty($paht)) {
122
-		require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
123
-		$product = new ProductFournisseur($db);
124
-		if ($product->fetch_product_fournisseur_price($fk_pa))
125
-		{
126
-			$paht_ret = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100);
127
-		}
128
-		else
129
-		{
130
-			$paht_ret = $paht;
131
-		}
132
-	}
133
-	else
134
-	{
135
-		$paht_ret = $paht;
136
-	}
137
-
138
-	// Calculate selling unit price including line discount
139
-	// We don't use calculate_price, because this function is dedicated to calculation of total with accuracy of total. We need an accuracy of a unit price.
140
-	// Also we must not apply rounding on non decimal rule defined by option MAIN_ROUNDING_RULE_TOT
141
-	$pu_ht_remise = $pvht * (1 - ($remise_percent / 100));
142
-	$pu_ht_remise = price2num($pu_ht_remise, 'MU');
143
-
144
-	// calcul marge
145
-	if ($pu_ht_remise < 0)
146
-		$marge = -1 * (abs($pu_ht_remise) - $paht_ret);
147
-	else
148
-		$marge = $pu_ht_remise - $paht_ret;
149
-
150
-	// calcul taux marge
151
-	if ($paht_ret != 0)
152
-		$marge_tx_ret = (100 * $marge) / $paht_ret;
153
-	// calcul taux marque
154
-	if ($pu_ht_remise != 0)
155
-		$marque_tx_ret = (100 * $marge) / $pu_ht_remise;
156
-
157
-	return array($paht_ret, $marge_tx_ret, $marque_tx_ret);
116
+    global $db, $conf;
117
+
118
+    $marge_tx_ret='';
119
+    $marque_tx_ret='';
120
+
121
+    if ($fk_pa > 0 && empty($paht)) {
122
+        require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
123
+        $product = new ProductFournisseur($db);
124
+        if ($product->fetch_product_fournisseur_price($fk_pa))
125
+        {
126
+            $paht_ret = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100);
127
+        }
128
+        else
129
+        {
130
+            $paht_ret = $paht;
131
+        }
132
+    }
133
+    else
134
+    {
135
+        $paht_ret = $paht;
136
+    }
137
+
138
+    // Calculate selling unit price including line discount
139
+    // We don't use calculate_price, because this function is dedicated to calculation of total with accuracy of total. We need an accuracy of a unit price.
140
+    // Also we must not apply rounding on non decimal rule defined by option MAIN_ROUNDING_RULE_TOT
141
+    $pu_ht_remise = $pvht * (1 - ($remise_percent / 100));
142
+    $pu_ht_remise = price2num($pu_ht_remise, 'MU');
143
+
144
+    // calcul marge
145
+    if ($pu_ht_remise < 0)
146
+        $marge = -1 * (abs($pu_ht_remise) - $paht_ret);
147
+    else
148
+        $marge = $pu_ht_remise - $paht_ret;
149
+
150
+    // calcul taux marge
151
+    if ($paht_ret != 0)
152
+        $marge_tx_ret = (100 * $marge) / $paht_ret;
153
+    // calcul taux marque
154
+    if ($pu_ht_remise != 0)
155
+        $marque_tx_ret = (100 * $marge) / $pu_ht_remise;
156
+
157
+    return array($paht_ret, $marge_tx_ret, $marque_tx_ret);
158 158
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
 	// Entries must be declared in modules descriptor with line
45 45
     // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
46 46
     // $this->tabs = array('entity:-tabname);   												to remove a tab
47
-	complete_head_from_modules($conf,$langs,'',$head,$h,'margesadmin');
47
+	complete_head_from_modules($conf, $langs, '', $head, $h, 'margesadmin');
48 48
 
49
-	complete_head_from_modules($conf,$langs,'',$head,$h,'margesadmin','remove');
49
+	complete_head_from_modules($conf, $langs, '', $head, $h, 'margesadmin', 'remove');
50 50
 
51 51
 	return $head;
52 52
 }
@@ -115,8 +115,8 @@  discard block
 block discarded – undo
115 115
 {
116 116
 	global $db, $conf;
117 117
 
118
-	$marge_tx_ret='';
119
-	$marque_tx_ret='';
118
+	$marge_tx_ret = '';
119
+	$marque_tx_ret = '';
120 120
 
121 121
 	if ($fk_pa > 0 && empty($paht)) {
122 122
 		require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
Please login to merge, or discard this patch.
Braces   +13 added lines, -12 removed lines patch added patch discarded remove patch
@@ -124,13 +124,11 @@  discard block
 block discarded – undo
124 124
 		if ($product->fetch_product_fournisseur_price($fk_pa))
125 125
 		{
126 126
 			$paht_ret = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100);
127
-		}
128
-		else
127
+		} else
129 128
 		{
130 129
 			$paht_ret = $paht;
131 130
 		}
132
-	}
133
-	else
131
+	} else
134 132
 	{
135 133
 		$paht_ret = $paht;
136 134
 	}
@@ -142,17 +140,20 @@  discard block
 block discarded – undo
142 140
 	$pu_ht_remise = price2num($pu_ht_remise, 'MU');
143 141
 
144 142
 	// calcul marge
145
-	if ($pu_ht_remise < 0)
146
-		$marge = -1 * (abs($pu_ht_remise) - $paht_ret);
147
-	else
148
-		$marge = $pu_ht_remise - $paht_ret;
143
+	if ($pu_ht_remise < 0) {
144
+			$marge = -1 * (abs($pu_ht_remise) - $paht_ret);
145
+	} else {
146
+			$marge = $pu_ht_remise - $paht_ret;
147
+	}
149 148
 
150 149
 	// calcul taux marge
151
-	if ($paht_ret != 0)
152
-		$marge_tx_ret = (100 * $marge) / $paht_ret;
150
+	if ($paht_ret != 0) {
151
+			$marge_tx_ret = (100 * $marge) / $paht_ret;
152
+	}
153 153
 	// calcul taux marque
154
-	if ($pu_ht_remise != 0)
155
-		$marque_tx_ret = (100 * $marge) / $pu_ht_remise;
154
+	if ($pu_ht_remise != 0) {
155
+			$marque_tx_ret = (100 * $marge) / $pu_ht_remise;
156
+	}
156 157
 
157 158
 	return array($paht_ret, $marge_tx_ret, $marque_tx_ret);
158 159
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/margin/agentMargins.php 3 patches
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -46,24 +46,24 @@  discard block
 block discarded – undo
46 46
 if (! $sortorder) $sortorder="ASC";
47 47
 if (! $sortfield)
48 48
 {
49
-	if ($agentid > 0)
50
-		$sortfield="s.nom";
51
-	else
52
-	    $sortfield="u.lastname";
49
+    if ($agentid > 0)
50
+        $sortfield="s.nom";
51
+    else
52
+        $sortfield="u.lastname";
53 53
 }
54 54
 
55 55
 $startdate=$enddate='';
56 56
 
57 57
 if (!empty($_POST['startdatemonth']))
58
-  $startdate  = dol_mktime(0, 0, 0, $_POST['startdatemonth'],  $_POST['startdateday'],  $_POST['startdateyear']);
58
+    $startdate  = dol_mktime(0, 0, 0, $_POST['startdatemonth'],  $_POST['startdateday'],  $_POST['startdateyear']);
59 59
 if (!empty($_POST['enddatemonth']))
60
-  $enddate  = dol_mktime(23, 59, 59, $_POST['enddatemonth'],  $_POST['enddateday'],  $_POST['enddateyear']);
60
+    $enddate  = dol_mktime(23, 59, 59, $_POST['enddatemonth'],  $_POST['enddateday'],  $_POST['enddateyear']);
61 61
 
62 62
 // Security check
63 63
 if ($user->rights->margins->read->all) {
64
-  $agentid = GETPOST('agentid', 'int');
64
+    $agentid = GETPOST('agentid', 'int');
65 65
 } else {
66
-  $agentid = $user->id;
66
+    $agentid = $user->id;
67 67
 }
68 68
 $result=restrictedArea($user,'margins');
69 69
 
@@ -143,22 +143,22 @@  discard block
 block discarded – undo
143 143
 $sql.= " AND sc.fk_soc = f.fk_soc";
144 144
 $sql.= " AND (d.product_type = 0 OR d.product_type = 1)";
145 145
 if (! empty($conf->global->AGENT_CONTACT_TYPE))
146
-	$sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = u.rowid) OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = u.rowid))";
146
+    $sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = u.rowid) OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = u.rowid))";
147 147
 else
148
-	$sql .= " AND sc.fk_user = u.rowid";
148
+    $sql .= " AND sc.fk_user = u.rowid";
149 149
 $sql.= " AND f.fk_statut > 0";
150 150
 $sql.= ' AND s.entity IN ('.getEntity('societe').')';
151 151
 $sql.= " AND d.fk_facture = f.rowid";
152 152
 if ($agentid > 0) {
153
-	if (! empty($conf->global->AGENT_CONTACT_TYPE))
154
-  		$sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = ".$agentid.") OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = ".$agentid."))";
155
-	else
156
-	    $sql .= " AND sc.fk_user = ".$agentid;
153
+    if (! empty($conf->global->AGENT_CONTACT_TYPE))
154
+            $sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = ".$agentid.") OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = ".$agentid."))";
155
+    else
156
+        $sql .= " AND sc.fk_user = ".$agentid;
157 157
 }
158 158
 if (!empty($startdate))
159
-  $sql.= " AND f.datef >= '".$db->idate($startdate)."'";
159
+    $sql.= " AND f.datef >= '".$db->idate($startdate)."'";
160 160
 if (!empty($enddate))
161
-  $sql.= " AND f.datef <= '".$db->idate($enddate)."'";
161
+    $sql.= " AND f.datef <= '".$db->idate($enddate)."'";
162 162
 $sql .= " AND d.buy_price_ht IS NOT NULL";
163 163
 if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0";
164 164
 if ($agentid > 0) $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname";
@@ -176,87 +176,87 @@  discard block
 block discarded – undo
176 176
 $result = $db->query($sql);
177 177
 if ($result)
178 178
 {
179
-	$num = $db->num_rows($result);
180
-
181
-	print '<br>';
182
-	print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1);
183
-
184
-	if ($conf->global->MARGIN_TYPE == "1")
185
-	    $labelcostprice='BuyingPrice';
186
-	else   // value is 'costprice' or 'pmp'
187
-	    $labelcostprice='CostPrice';
188
-
189
-	$i = 0;
190
-	print "<table class=\"noborder\" width=\"100%\">";
191
-
192
-	print '<tr class="liste_titre">';
193
-	if ($agentid > 0)
194
-		print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&amp;agentid=".$agentid,'',$sortfield,$sortorder);
195
-	else
196
-		print_liste_field_titre("SalesRepresentative",$_SERVER["PHP_SELF"],"u.lastname","","&amp;agentid=".$agentid,'',$sortfield,$sortorder);
197
-
198
-	print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
199
-	print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
200
-	print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
201
-	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
202
-		print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
203
-	if (! empty($conf->global->DISPLAY_MARK_RATES))
204
-		print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
205
-	print "</tr>\n";
206
-
207
-	$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
208
-
209
-	if ($num > 0)
210
-	{
211
-
212
-		while ($i < $num /*&& $i < $conf->liste_limit*/)
213
-		{
214
-			$objp = $db->fetch_object($result);
215
-
216
-			$pa = $objp->buying_price;
217
-			$pv = $objp->selling_price;
218
-			$marge = $objp->marge;
219
-
220
-			if ($marge < 0)
221
-			{
222
-				$marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ;
223
-				$markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ;
224
-			}
225
-			else
226
-			{
227
-				$marginRate = ($pa != 0)?(100 * $marge / $pa):'' ;
228
-				$markRate = ($pv != 0)?(100 * $marge / $pv):'' ;
229
-			}
230
-
231
-			print '<tr class="oddeven">';
232
-			if ($agentid > 0) {
233
-				$companystatic->id=$objp->socid;
234
-				$companystatic->name=$objp->name;
235
-				$companystatic->client=$objp->client;
236
-				print "<td>".$companystatic->getNomUrl(1,'customer')."</td>\n";
237
-			}
238
-			else {
239
-				$userstatic->fetch($objp->agent);
240
-				print "<td>".$userstatic->getFullName($langs,0,0,0)."</td>\n";
241
-			}
242
-
243
-			print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n";
244
-			print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n";
245
-			print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n";
246
-			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
247
-				print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
248
-			if (! empty($conf->global->DISPLAY_MARK_RATES))
249
-				print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
250
-			print "</tr>\n";
251
-
252
-			$i++;
253
-		}
254
-	}
255
-	print "</table>";
179
+    $num = $db->num_rows($result);
180
+
181
+    print '<br>';
182
+    print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1);
183
+
184
+    if ($conf->global->MARGIN_TYPE == "1")
185
+        $labelcostprice='BuyingPrice';
186
+    else   // value is 'costprice' or 'pmp'
187
+        $labelcostprice='CostPrice';
188
+
189
+    $i = 0;
190
+    print "<table class=\"noborder\" width=\"100%\">";
191
+
192
+    print '<tr class="liste_titre">';
193
+    if ($agentid > 0)
194
+        print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&amp;agentid=".$agentid,'',$sortfield,$sortorder);
195
+    else
196
+        print_liste_field_titre("SalesRepresentative",$_SERVER["PHP_SELF"],"u.lastname","","&amp;agentid=".$agentid,'',$sortfield,$sortorder);
197
+
198
+    print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
199
+    print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
200
+    print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
201
+    if (! empty($conf->global->DISPLAY_MARGIN_RATES))
202
+        print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
203
+    if (! empty($conf->global->DISPLAY_MARK_RATES))
204
+        print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
205
+    print "</tr>\n";
206
+
207
+    $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
208
+
209
+    if ($num > 0)
210
+    {
211
+
212
+        while ($i < $num /*&& $i < $conf->liste_limit*/)
213
+        {
214
+            $objp = $db->fetch_object($result);
215
+
216
+            $pa = $objp->buying_price;
217
+            $pv = $objp->selling_price;
218
+            $marge = $objp->marge;
219
+
220
+            if ($marge < 0)
221
+            {
222
+                $marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ;
223
+                $markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ;
224
+            }
225
+            else
226
+            {
227
+                $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ;
228
+                $markRate = ($pv != 0)?(100 * $marge / $pv):'' ;
229
+            }
230
+
231
+            print '<tr class="oddeven">';
232
+            if ($agentid > 0) {
233
+                $companystatic->id=$objp->socid;
234
+                $companystatic->name=$objp->name;
235
+                $companystatic->client=$objp->client;
236
+                print "<td>".$companystatic->getNomUrl(1,'customer')."</td>\n";
237
+            }
238
+            else {
239
+                $userstatic->fetch($objp->agent);
240
+                print "<td>".$userstatic->getFullName($langs,0,0,0)."</td>\n";
241
+            }
242
+
243
+            print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n";
244
+            print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n";
245
+            print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n";
246
+            if (! empty($conf->global->DISPLAY_MARGIN_RATES))
247
+                print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
248
+            if (! empty($conf->global->DISPLAY_MARK_RATES))
249
+                print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
250
+            print "</tr>\n";
251
+
252
+            $i++;
253
+        }
254
+    }
255
+    print "</table>";
256 256
 }
257 257
 else
258 258
 {
259
-	dol_print_error($db);
259
+    dol_print_error($db);
260 260
 }
261 261
 $db->free($result);
262 262
 
Please login to merge, or discard this patch.
Braces   +62 added lines, -42 removed lines patch added patch discarded remove patch
@@ -43,21 +43,26 @@  discard block
 block discarded – undo
43 43
 $offset = $limit * $page;
44 44
 $pageprev = $page - 1;
45 45
 $pagenext = $page + 1;
46
-if (! $sortorder) $sortorder="ASC";
46
+if (! $sortorder) {
47
+    $sortorder="ASC";
48
+}
47 49
 if (! $sortfield)
48 50
 {
49
-	if ($agentid > 0)
50
-		$sortfield="s.nom";
51
-	else
52
-	    $sortfield="u.lastname";
53
-}
51
+	if ($agentid > 0) {
52
+			$sortfield="s.nom";
53
+	} else {
54
+		    $sortfield="u.lastname";
55
+	}
56
+	}
54 57
 
55 58
 $startdate=$enddate='';
56 59
 
57
-if (!empty($_POST['startdatemonth']))
60
+if (!empty($_POST['startdatemonth'])) {
58 61
   $startdate  = dol_mktime(0, 0, 0, $_POST['startdatemonth'],  $_POST['startdateday'],  $_POST['startdateyear']);
59
-if (!empty($_POST['enddatemonth']))
62
+}
63
+if (!empty($_POST['enddatemonth'])) {
60 64
   $enddate  = dol_mktime(23, 59, 59, $_POST['enddatemonth'],  $_POST['enddateday'],  $_POST['enddateyear']);
65
+}
61 66
 
62 67
 // Security check
63 68
 if ($user->rights->margins->read->all) {
@@ -126,7 +131,9 @@  discard block
 block discarded – undo
126 131
 print '</form>';
127 132
 
128 133
 $sql = "SELECT";
129
-if ($agentid > 0) $sql.= " s.rowid as socid, s.nom as name, s.code_client, s.client,";
134
+if ($agentid > 0) {
135
+    $sql.= " s.rowid as socid, s.nom as name, s.code_client, s.client,";
136
+}
130 137
 $sql.= " u.rowid as agent, u.login, u.lastname, u.firstname,";
131 138
 $sql.= " sum(d.total_ht) as selling_price,";
132 139
 // Note: qty and buy_price_ht is always positive (if not your database may be corrupted, you can update this)
@@ -142,27 +149,36 @@  discard block
 block discarded – undo
142 149
 $sql.= ' AND f.entity IN ('.getEntity('invoice').')';
143 150
 $sql.= " AND sc.fk_soc = f.fk_soc";
144 151
 $sql.= " AND (d.product_type = 0 OR d.product_type = 1)";
145
-if (! empty($conf->global->AGENT_CONTACT_TYPE))
152
+if (! empty($conf->global->AGENT_CONTACT_TYPE)) {
146 153
 	$sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = u.rowid) OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = u.rowid))";
147
-else
154
+} else {
148 155
 	$sql .= " AND sc.fk_user = u.rowid";
156
+}
149 157
 $sql.= " AND f.fk_statut > 0";
150 158
 $sql.= ' AND s.entity IN ('.getEntity('societe').')';
151 159
 $sql.= " AND d.fk_facture = f.rowid";
152 160
 if ($agentid > 0) {
153
-	if (! empty($conf->global->AGENT_CONTACT_TYPE))
154
-  		$sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = ".$agentid.") OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = ".$agentid."))";
155
-	else
156
-	    $sql .= " AND sc.fk_user = ".$agentid;
157
-}
158
-if (!empty($startdate))
161
+	if (! empty($conf->global->AGENT_CONTACT_TYPE)) {
162
+	  		$sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = ".$agentid.") OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = ".$agentid."))";
163
+	} else {
164
+		    $sql .= " AND sc.fk_user = ".$agentid;
165
+	}
166
+	}
167
+if (!empty($startdate)) {
159 168
   $sql.= " AND f.datef >= '".$db->idate($startdate)."'";
160
-if (!empty($enddate))
169
+}
170
+if (!empty($enddate)) {
161 171
   $sql.= " AND f.datef <= '".$db->idate($enddate)."'";
172
+}
162 173
 $sql .= " AND d.buy_price_ht IS NOT NULL";
163
-if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0";
164
-if ($agentid > 0) $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname";
165
-else $sql.= " GROUP BY u.rowid, u.login, u.lastname, u.firstname";
174
+if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) {
175
+    $sql .= " AND d.buy_price_ht <> 0";
176
+}
177
+if ($agentid > 0) {
178
+    $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname";
179
+} else {
180
+    $sql.= " GROUP BY u.rowid, u.login, u.lastname, u.firstname";
181
+}
166 182
 $sql.=$db->order($sortfield,$sortorder);
167 183
 // TODO: calculate total to display then restore pagination
168 184
 //$sql.= $db->plimit($conf->liste_limit +1, $offset);
@@ -181,27 +197,32 @@  discard block
 block discarded – undo
181 197
 	print '<br>';
182 198
 	print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1);
183 199
 
184
-	if ($conf->global->MARGIN_TYPE == "1")
185
-	    $labelcostprice='BuyingPrice';
186
-	else   // value is 'costprice' or 'pmp'
200
+	if ($conf->global->MARGIN_TYPE == "1") {
201
+		    $labelcostprice='BuyingPrice';
202
+	} else {
203
+	    // value is 'costprice' or 'pmp'
187 204
 	    $labelcostprice='CostPrice';
205
+	}
188 206
 
189 207
 	$i = 0;
190 208
 	print "<table class=\"noborder\" width=\"100%\">";
191 209
 
192 210
 	print '<tr class="liste_titre">';
193
-	if ($agentid > 0)
194
-		print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&amp;agentid=".$agentid,'',$sortfield,$sortorder);
195
-	else
196
-		print_liste_field_titre("SalesRepresentative",$_SERVER["PHP_SELF"],"u.lastname","","&amp;agentid=".$agentid,'',$sortfield,$sortorder);
211
+	if ($agentid > 0) {
212
+			print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&amp;agentid=".$agentid,'',$sortfield,$sortorder);
213
+	} else {
214
+			print_liste_field_titre("SalesRepresentative",$_SERVER["PHP_SELF"],"u.lastname","","&amp;agentid=".$agentid,'',$sortfield,$sortorder);
215
+	}
197 216
 
198 217
 	print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
199 218
 	print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
200 219
 	print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
201
-	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
202
-		print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
203
-	if (! empty($conf->global->DISPLAY_MARK_RATES))
204
-		print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
220
+	if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
221
+			print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
222
+	}
223
+	if (! empty($conf->global->DISPLAY_MARK_RATES)) {
224
+			print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
225
+	}
205 226
 	print "</tr>\n";
206 227
 
207 228
 	$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
@@ -221,8 +242,7 @@  discard block
 block discarded – undo
221 242
 			{
222 243
 				$marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ;
223 244
 				$markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ;
224
-			}
225
-			else
245
+			} else
226 246
 			{
227 247
 				$marginRate = ($pa != 0)?(100 * $marge / $pa):'' ;
228 248
 				$markRate = ($pv != 0)?(100 * $marge / $pv):'' ;
@@ -234,8 +254,7 @@  discard block
 block discarded – undo
234 254
 				$companystatic->name=$objp->name;
235 255
 				$companystatic->client=$objp->client;
236 256
 				print "<td>".$companystatic->getNomUrl(1,'customer')."</td>\n";
237
-			}
238
-			else {
257
+			} else {
239 258
 				$userstatic->fetch($objp->agent);
240 259
 				print "<td>".$userstatic->getFullName($langs,0,0,0)."</td>\n";
241 260
 			}
@@ -243,18 +262,19 @@  discard block
 block discarded – undo
243 262
 			print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n";
244 263
 			print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n";
245 264
 			print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n";
246
-			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
247
-				print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
248
-			if (! empty($conf->global->DISPLAY_MARK_RATES))
249
-				print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
265
+			if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
266
+							print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
267
+			}
268
+			if (! empty($conf->global->DISPLAY_MARK_RATES)) {
269
+							print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
270
+			}
250 271
 			print "</tr>\n";
251 272
 
252 273
 			$i++;
253 274
 		}
254 275
 	}
255 276
 	print "</table>";
256
-}
257
-else
277
+} else
258 278
 {
259 279
 	dol_print_error($db);
260 280
 }
Please login to merge, or discard this patch.
Spacing   +72 added lines, -72 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.'/core/lib/company.lib.php';
32 32
 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
@@ -39,29 +39,29 @@  discard block
 block discarded – undo
39 39
 $mesg = '';
40 40
 
41 41
 // Load variable for pagination
42
-$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
43
-$sortfield = GETPOST('sortfield','alpha');
44
-$sortorder = GETPOST('sortorder','alpha');
45
-$page = GETPOST('page','int');
42
+$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
43
+$sortfield = GETPOST('sortfield', 'alpha');
44
+$sortorder = GETPOST('sortorder', 'alpha');
45
+$page = GETPOST('page', 'int');
46 46
 if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
47 47
 $offset = $limit * $page;
48 48
 $pageprev = $page - 1;
49 49
 $pagenext = $page + 1;
50
-if (! $sortorder) $sortorder="ASC";
51
-if (! $sortfield)
50
+if (!$sortorder) $sortorder = "ASC";
51
+if (!$sortfield)
52 52
 {
53 53
 	if ($agentid > 0)
54
-		$sortfield="s.nom";
54
+		$sortfield = "s.nom";
55 55
 	else
56
-	    $sortfield="u.lastname";
56
+	    $sortfield = "u.lastname";
57 57
 }
58 58
 
59
-$startdate=$enddate='';
59
+$startdate = $enddate = '';
60 60
 
61 61
 if (!empty($_POST['startdatemonth']))
62
-  $startdate  = dol_mktime(0, 0, 0, $_POST['startdatemonth'],  $_POST['startdateday'],  $_POST['startdateyear']);
62
+  $startdate = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']);
63 63
 if (!empty($_POST['enddatemonth']))
64
-  $enddate  = dol_mktime(23, 59, 59, $_POST['enddatemonth'],  $_POST['enddateday'],  $_POST['enddateyear']);
64
+  $enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']);
65 65
 
66 66
 // Security check
67 67
 if ($user->rights->margins->read->all) {
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 } else {
70 70
   $agentid = $user->id;
71 71
 }
72
-$result=restrictedArea($user,'margins');
72
+$result = restrictedArea($user, 'margins');
73 73
 
74 74
 
75 75
 /*
@@ -86,19 +86,19 @@  discard block
 block discarded – undo
86 86
 
87 87
 $userstatic = new User($db);
88 88
 $companystatic = new Societe($db);
89
-$invoicestatic=new Facture($db);
89
+$invoicestatic = new Facture($db);
90 90
 
91 91
 $form = new Form($db);
92 92
 
93
-llxHeader('',$langs->trans("Margins").' - '.$langs->trans("Agents"));
93
+llxHeader('', $langs->trans("Margins").' - '.$langs->trans("Agents"));
94 94
 
95
-$text=$langs->trans("Margins");
95
+$text = $langs->trans("Margins");
96 96
 //print load_fiche_titre($text);
97 97
 
98 98
 // Show tabs
99
-$head=marges_prepare_head($user);
100
-$titre=$langs->trans("Margins");
101
-$picto='margin';
99
+$head = marges_prepare_head($user);
100
+$titre = $langs->trans("Margins");
101
+$picto = 'margin';
102 102
 
103 103
 print '<form method="post" name="sel" action="'.$_SERVER['PHP_SELF'].'">';
104 104
 
@@ -130,44 +130,44 @@  discard block
 block discarded – undo
130 130
 print '</form>';
131 131
 
132 132
 $sql = "SELECT";
133
-if ($agentid > 0) $sql.= " s.rowid as socid, s.nom as name, s.code_client, s.client,";
134
-$sql.= " u.rowid as agent, u.login, u.lastname, u.firstname,";
135
-$sql.= " sum(d.total_ht) as selling_price,";
133
+if ($agentid > 0) $sql .= " s.rowid as socid, s.nom as name, s.code_client, s.client,";
134
+$sql .= " u.rowid as agent, u.login, u.lastname, u.firstname,";
135
+$sql .= " sum(d.total_ht) as selling_price,";
136 136
 // Note: qty and buy_price_ht is always positive (if not your database may be corrupted, you can update this)
137
-$sql.= " sum(".$db->ifsql('d.total_ht < 0','d.qty * d.buy_price_ht * -1','d.qty * d.buy_price_ht').") as buying_price,";
138
-$sql.= " sum(".$db->ifsql('d.total_ht < 0','-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty))','d.total_ht - (d.buy_price_ht * d.qty)').") as marge" ;
139
-$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
140
-$sql.= ", ".MAIN_DB_PREFIX."facture as f";
141
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_contact e ON e.element_id = f.rowid and e.statut = 4 and e.fk_c_type_contact = ".(empty($conf->global->AGENT_CONTACT_TYPE)?-1:$conf->global->AGENT_CONTACT_TYPE);
142
-$sql.= ", ".MAIN_DB_PREFIX."facturedet as d";
143
-$sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
144
-$sql.= ", ".MAIN_DB_PREFIX."user as u";
145
-$sql.= " WHERE f.fk_soc = s.rowid";
146
-$sql.= ' AND f.entity IN ('.getEntity('invoice').')';
147
-$sql.= " AND sc.fk_soc = f.fk_soc";
148
-$sql.= " AND (d.product_type = 0 OR d.product_type = 1)";
149
-if (! empty($conf->global->AGENT_CONTACT_TYPE))
150
-	$sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = u.rowid) OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = u.rowid))";
137
+$sql .= " sum(".$db->ifsql('d.total_ht < 0', 'd.qty * d.buy_price_ht * -1', 'd.qty * d.buy_price_ht').") as buying_price,";
138
+$sql .= " sum(".$db->ifsql('d.total_ht < 0', '-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty))', 'd.total_ht - (d.buy_price_ht * d.qty)').") as marge";
139
+$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
140
+$sql .= ", ".MAIN_DB_PREFIX."facture as f";
141
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_contact e ON e.element_id = f.rowid and e.statut = 4 and e.fk_c_type_contact = ".(empty($conf->global->AGENT_CONTACT_TYPE) ?-1 : $conf->global->AGENT_CONTACT_TYPE);
142
+$sql .= ", ".MAIN_DB_PREFIX."facturedet as d";
143
+$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
144
+$sql .= ", ".MAIN_DB_PREFIX."user as u";
145
+$sql .= " WHERE f.fk_soc = s.rowid";
146
+$sql .= ' AND f.entity IN ('.getEntity('invoice').')';
147
+$sql .= " AND sc.fk_soc = f.fk_soc";
148
+$sql .= " AND (d.product_type = 0 OR d.product_type = 1)";
149
+if (!empty($conf->global->AGENT_CONTACT_TYPE))
150
+	$sql .= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = u.rowid) OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = u.rowid))";
151 151
 else
152 152
 	$sql .= " AND sc.fk_user = u.rowid";
153
-$sql.= " AND f.fk_statut > 0";
154
-$sql.= ' AND s.entity IN ('.getEntity('societe').')';
155
-$sql.= " AND d.fk_facture = f.rowid";
153
+$sql .= " AND f.fk_statut > 0";
154
+$sql .= ' AND s.entity IN ('.getEntity('societe').')';
155
+$sql .= " AND d.fk_facture = f.rowid";
156 156
 if ($agentid > 0) {
157
-	if (! empty($conf->global->AGENT_CONTACT_TYPE))
158
-  		$sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = ".$agentid.") OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = ".$agentid."))";
157
+	if (!empty($conf->global->AGENT_CONTACT_TYPE))
158
+  		$sql .= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = ".$agentid.") OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = ".$agentid."))";
159 159
 	else
160 160
 	    $sql .= " AND sc.fk_user = ".$agentid;
161 161
 }
162 162
 if (!empty($startdate))
163
-  $sql.= " AND f.datef >= '".$db->idate($startdate)."'";
163
+  $sql .= " AND f.datef >= '".$db->idate($startdate)."'";
164 164
 if (!empty($enddate))
165
-  $sql.= " AND f.datef <= '".$db->idate($enddate)."'";
165
+  $sql .= " AND f.datef <= '".$db->idate($enddate)."'";
166 166
 $sql .= " AND d.buy_price_ht IS NOT NULL";
167 167
 if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0";
168
-if ($agentid > 0) $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname";
169
-else $sql.= " GROUP BY u.rowid, u.login, u.lastname, u.firstname";
170
-$sql.=$db->order($sortfield,$sortorder);
168
+if ($agentid > 0) $sql .= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname";
169
+else $sql .= " GROUP BY u.rowid, u.login, u.lastname, u.firstname";
170
+$sql .= $db->order($sortfield, $sortorder);
171 171
 // TODO: calculate total to display then restore pagination
172 172
 //$sql.= $db->plimit($conf->liste_limit +1, $offset);
173 173
 
@@ -186,29 +186,29 @@  discard block
 block discarded – undo
186 186
 	print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1);
187 187
 
188 188
 	if ($conf->global->MARGIN_TYPE == "1")
189
-	    $labelcostprice='BuyingPrice';
189
+	    $labelcostprice = 'BuyingPrice';
190 190
 	else   // value is 'costprice' or 'pmp'
191
-	    $labelcostprice='CostPrice';
191
+	    $labelcostprice = 'CostPrice';
192 192
 
193 193
 	$i = 0;
194 194
 	print "<table class=\"noborder\" width=\"100%\">";
195 195
 
196 196
 	print '<tr class="liste_titre">';
197 197
 	if ($agentid > 0)
198
-		print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&amp;agentid=".$agentid,'',$sortfield,$sortorder);
198
+		print_liste_field_titre("Customer", $_SERVER["PHP_SELF"], "s.nom", "", "&amp;agentid=".$agentid, '', $sortfield, $sortorder);
199 199
 	else
200
-		print_liste_field_titre("SalesRepresentative",$_SERVER["PHP_SELF"],"u.lastname","","&amp;agentid=".$agentid,'',$sortfield,$sortorder);
201
-
202
-	print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
203
-	print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
204
-	print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
205
-	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
206
-		print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
207
-	if (! empty($conf->global->DISPLAY_MARK_RATES))
208
-		print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
200
+		print_liste_field_titre("SalesRepresentative", $_SERVER["PHP_SELF"], "u.lastname", "", "&amp;agentid=".$agentid, '', $sortfield, $sortorder);
201
+
202
+	print_liste_field_titre("SellingPrice", $_SERVER["PHP_SELF"], "selling_price", "", "&amp;agentid=".$agentid, 'align="right"', $sortfield, $sortorder);
203
+	print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "buying_price", "", "&amp;agentid=".$agentid, 'align="right"', $sortfield, $sortorder);
204
+	print_liste_field_titre("Margin", $_SERVER["PHP_SELF"], "marge", "", "&amp;agentid=".$agentid, 'align="right"', $sortfield, $sortorder);
205
+	if (!empty($conf->global->DISPLAY_MARGIN_RATES))
206
+		print_liste_field_titre("MarginRate", $_SERVER["PHP_SELF"], "", "", "&amp;agentid=".$agentid, 'align="right"', $sortfield, $sortorder);
207
+	if (!empty($conf->global->DISPLAY_MARK_RATES))
208
+		print_liste_field_titre("MarkRate", $_SERVER["PHP_SELF"], "", "", "&amp;agentid=".$agentid, 'align="right"', $sortfield, $sortorder);
209 209
 	print "</tr>\n";
210 210
 
211
-	$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
211
+	$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
212 212
 
213 213
 	if ($num > 0)
214 214
 	{
@@ -223,34 +223,34 @@  discard block
 block discarded – undo
223 223
 
224 224
 			if ($marge < 0)
225 225
 			{
226
-				$marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ;
227
-				$markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ;
226
+				$marginRate = ($pa != 0) ?-1 * (100 * $marge / $pa) : '';
227
+				$markRate = ($pv != 0) ?-1 * (100 * $marge / $pv) : '';
228 228
 			}
229 229
 			else
230 230
 			{
231
-				$marginRate = ($pa != 0)?(100 * $marge / $pa):'' ;
232
-				$markRate = ($pv != 0)?(100 * $marge / $pv):'' ;
231
+				$marginRate = ($pa != 0) ? (100 * $marge / $pa) : '';
232
+				$markRate = ($pv != 0) ? (100 * $marge / $pv) : '';
233 233
 			}
234 234
 
235 235
 			print '<tr class="oddeven">';
236 236
 			if ($agentid > 0) {
237
-				$companystatic->id=$objp->socid;
238
-				$companystatic->name=$objp->name;
239
-				$companystatic->client=$objp->client;
240
-				print "<td>".$companystatic->getNomUrl(1,'customer')."</td>\n";
237
+				$companystatic->id = $objp->socid;
238
+				$companystatic->name = $objp->name;
239
+				$companystatic->client = $objp->client;
240
+				print "<td>".$companystatic->getNomUrl(1, 'customer')."</td>\n";
241 241
 			}
242 242
 			else {
243 243
 				$userstatic->fetch($objp->agent);
244
-				print "<td>".$userstatic->getFullName($langs,0,0,0)."</td>\n";
244
+				print "<td>".$userstatic->getFullName($langs, 0, 0, 0)."</td>\n";
245 245
 			}
246 246
 
247 247
 			print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n";
248 248
 			print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n";
249 249
 			print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n";
250
-			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
251
-				print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
252
-			if (! empty($conf->global->DISPLAY_MARK_RATES))
253
-				print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
250
+			if (!empty($conf->global->DISPLAY_MARGIN_RATES))
251
+				print "<td align=\"right\">".(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
252
+			if (!empty($conf->global->DISPLAY_MARK_RATES))
253
+				print "<td align=\"right\">".(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
254 254
 			print "</tr>\n";
255 255
 
256 256
 			$i++;
Please login to merge, or discard this patch.
dolibarr/htdocs/margin/tabs/productMargins.php 3 patches
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -67,32 +67,32 @@  discard block
 block discarded – undo
67 67
     $result = $object->fetch($id, $ref);
68 68
 
69 69
     $title = $langs->trans('ProductServiceCard');
70
-	$helpurl = '';
71
-	$shortlabel = dol_trunc($object->label,16);
72
-	if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT))
73
-	{
74
-		$title = $langs->trans('Product')." ". $shortlabel ." - ".$langs->trans('Card');
75
-		$helpurl='EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
76
-	}
77
-	if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE))
78
-	{
79
-		$title = $langs->trans('Service')." ". $shortlabel ." - ".$langs->trans('Card');
80
-		$helpurl='EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
81
-	}
82
-
83
-	llxHeader('', $title, $helpurl);
84
-
85
-	/*
70
+    $helpurl = '';
71
+    $shortlabel = dol_trunc($object->label,16);
72
+    if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT))
73
+    {
74
+        $title = $langs->trans('Product')." ". $shortlabel ." - ".$langs->trans('Card');
75
+        $helpurl='EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
76
+    }
77
+    if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE))
78
+    {
79
+        $title = $langs->trans('Service')." ". $shortlabel ." - ".$langs->trans('Card');
80
+        $helpurl='EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
81
+    }
82
+
83
+    llxHeader('', $title, $helpurl);
84
+
85
+    /*
86 86
 	 *  En mode visu
87 87
 	 */
88
-	if ($result > 0)
89
-	{
90
-		$head=product_prepare_head($object);
91
-		$titre=$langs->trans("CardProduct".$object->type);
92
-		$picto=($object->type== Product::TYPE_SERVICE?'service':'product');
93
-		dol_fiche_head($head, 'margin', $titre, -1, $picto);
88
+    if ($result > 0)
89
+    {
90
+        $head=product_prepare_head($object);
91
+        $titre=$langs->trans("CardProduct".$object->type);
92
+        $picto=($object->type== Product::TYPE_SERVICE?'service':'product');
93
+        dol_fiche_head($head, 'margin', $titre, -1, $picto);
94 94
 
95
-		$linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
95
+        $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
96 96
 
97 97
         dol_banner_tab($object, 'ref', $linkback, ($user->societe_id?0:1), 'ref');
98 98
 
@@ -102,31 +102,31 @@  discard block
 block discarded – undo
102 102
         print '<div class="underbanner clearboth"></div>';
103 103
         print '<table class="border tableforfield" width="100%">';
104 104
 
105
-		// Total Margin
106
-		print '<tr><td class="titlefield">'.$langs->trans("TotalMargin").'</td><td colspan="3">';
107
-		print '<span id="totalMargin"></span>'; // set by jquery (see below)
108
-		print '</td></tr>';
105
+        // Total Margin
106
+        print '<tr><td class="titlefield">'.$langs->trans("TotalMargin").'</td><td colspan="3">';
107
+        print '<span id="totalMargin"></span>'; // set by jquery (see below)
108
+        print '</td></tr>';
109 109
 
110
-		// Margin Rate
111
-		if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
112
-			print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="3">';
113
-			print '<span id="marginRate"></span>'; // set by jquery (see below)
114
-			print '</td></tr>';
115
-		}
110
+        // Margin Rate
111
+        if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
112
+            print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="3">';
113
+            print '<span id="marginRate"></span>'; // set by jquery (see below)
114
+            print '</td></tr>';
115
+        }
116 116
 
117
-		// Mark Rate
118
-		if (! empty($conf->global->DISPLAY_MARK_RATES)) {
119
-			print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="3">';
120
-			print '<span id="markRate"></span>'; // set by jquery (see below)
121
-			print '</td></tr>';
122
-		}
117
+        // Mark Rate
118
+        if (! empty($conf->global->DISPLAY_MARK_RATES)) {
119
+            print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="3">';
120
+            print '<span id="markRate"></span>'; // set by jquery (see below)
121
+            print '</td></tr>';
122
+        }
123 123
 
124
-		print "</table>";
124
+        print "</table>";
125 125
 
126 126
         print '</div>';
127 127
         print '<div style="clear:both"></div>';
128 128
 
129
-		dol_fiche_end();
129
+        dol_fiche_end();
130 130
 
131 131
 
132 132
         if ($user->rights->facture->lire) {
@@ -193,8 +193,8 @@  discard block
 block discarded – undo
193 193
                     while ($i < $num /*&& $i < $conf->liste_limit*/) {
194 194
                         $objp = $db->fetch_object($result);
195 195
 
196
-						$marginRate = ($objp->buying_price != 0)?(100 * $objp->marge / $objp->buying_price):'' ;
197
-						$markRate = ($objp->selling_price != 0)?(100 * $objp->marge / $objp->selling_price):'' ;
196
+                        $marginRate = ($objp->buying_price != 0)?(100 * $objp->marge / $objp->buying_price):'' ;
197
+                        $markRate = ($objp->selling_price != 0)?(100 * $objp->marge / $objp->selling_price):'' ;
198 198
 
199 199
                         print '<tr class="oddeven">';
200 200
                         print '<td>';
@@ -204,17 +204,17 @@  discard block
 block discarded – undo
204 204
                         print "</td>\n";
205 205
                         print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->name,44).'</a></td>';
206 206
                         print "<td>".$objp->code_client."</td>\n";
207
-						print "<td align=\"center\">";
208
-						print dol_print_date($db->jdate($objp->datef),'day')."</td>";
209
-						print "<td align=\"right\">".price($objp->selling_price, null, null, null, null, $rounding)."</td>\n";
210
-						print "<td align=\"right\">".price($objp->buying_price, null, null, null, null, $rounding)."</td>\n";
211
-						print "<td align=\"right\">".price($objp->qty, null, null, null, null, $rounding)."</td>\n";
212
-						print "<td align=\"right\">".price($objp->marge, null, null, null, null, $rounding)."</td>\n";
213
-						if (! empty($conf->global->DISPLAY_MARGIN_RATES))
214
-							print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
215
-						if (! empty($conf->global->DISPLAY_MARK_RATES))
216
-							print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
217
-						print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>';
207
+                        print "<td align=\"center\">";
208
+                        print dol_print_date($db->jdate($objp->datef),'day')."</td>";
209
+                        print "<td align=\"right\">".price($objp->selling_price, null, null, null, null, $rounding)."</td>\n";
210
+                        print "<td align=\"right\">".price($objp->buying_price, null, null, null, null, $rounding)."</td>\n";
211
+                        print "<td align=\"right\">".price($objp->qty, null, null, null, null, $rounding)."</td>\n";
212
+                        print "<td align=\"right\">".price($objp->marge, null, null, null, null, $rounding)."</td>\n";
213
+                        if (! empty($conf->global->DISPLAY_MARGIN_RATES))
214
+                            print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
215
+                        if (! empty($conf->global->DISPLAY_MARK_RATES))
216
+                            print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
217
+                        print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>';
218 218
                         print "</tr>\n";
219 219
                         $i++;
220 220
                         $cumul_achat += $objp->buying_price;
Please login to merge, or discard this patch.
Braces   +46 added lines, -23 removed lines patch added patch discarded remove patch
@@ -36,7 +36,9 @@  discard block
 block discarded – undo
36 36
 // Security check
37 37
 $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
38 38
 $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
39
-if (! empty($user->societe_id)) $socid=$user->societe_id;
39
+if (! empty($user->societe_id)) {
40
+    $socid=$user->societe_id;
41
+}
40 42
 $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
41 43
 
42 44
 $object = new Product($db);
@@ -50,8 +52,12 @@  discard block
 block discarded – undo
50 52
 $offset = $conf->liste_limit * $page;
51 53
 $pageprev = $page - 1;
52 54
 $pagenext = $page + 1;
53
-if (! $sortorder) $sortorder="DESC";
54
-if (! $sortfield) $sortfield="f.datef";
55
+if (! $sortorder) {
56
+    $sortorder="DESC";
57
+}
58
+if (! $sortfield) {
59
+    $sortfield="f.datef";
60
+}
55 61
 
56 62
 
57 63
 /*
@@ -133,7 +139,9 @@  discard block
 block discarded – undo
133 139
             $sql = "SELECT s.nom as name, s.rowid as socid, s.code_client,";
134 140
             $sql.= " f.rowid as facid, f.ref, f.total as total_ht,";
135 141
             $sql.= " f.datef, f.paye, f.fk_statut as statut, f.type,";
136
-            if (!$user->rights->societe->client->voir && !$socid) $sql.= " sc.fk_soc, sc.fk_user,";
142
+            if (!$user->rights->societe->client->voir && !$socid) {
143
+                $sql.= " sc.fk_soc, sc.fk_user,";
144
+            }
137 145
             $sql.= " sum(d.total_ht) as selling_price,";							// may be negative or positive
138 146
             $sql.= " IF(f.type = 2, -1, 1) * sum(d.qty) as qty,";						// not always positive in case of Credit note
139 147
             $sql.= " IF(f.type = 2, -1, 1) * sum(d.qty * d.buy_price_ht) as buying_price,";			// not always positive in case of Credit note
@@ -141,18 +149,28 @@  discard block
 block discarded – undo
141 149
             $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
142 150
             $sql.= ", ".MAIN_DB_PREFIX."facture as f";
143 151
             $sql.= ", ".MAIN_DB_PREFIX."facturedet as d";
144
-            if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
152
+            if (!$user->rights->societe->client->voir && !$socid) {
153
+                $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
154
+            }
145 155
             $sql.= " WHERE f.fk_soc = s.rowid";
146 156
             $sql.= " AND f.fk_statut > 0";
147 157
             $sql.= " AND s.entity = ".$conf->entity;
148 158
             $sql.= " AND d.fk_facture = f.rowid";
149 159
             $sql.= " AND d.fk_product =".$object->id;
150
-            if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
151
-            if (! empty($socid)) $sql.= " AND f.fk_soc = $socid";
160
+            if (!$user->rights->societe->client->voir && !$socid) {
161
+                $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
162
+            }
163
+            if (! empty($socid)) {
164
+                $sql.= " AND f.fk_soc = $socid";
165
+            }
152 166
             $sql .= " AND d.buy_price_ht IS NOT NULL";
153
-            if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0";
167
+            if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) {
168
+                $sql .= " AND d.buy_price_ht <> 0";
169
+            }
154 170
             $sql.= " GROUP BY s.nom, s.rowid, s.code_client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut, f.type";
155
-            if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user";
171
+            if (!$user->rights->societe->client->voir && !$socid) {
172
+                $sql.= ", sc.fk_soc, sc.fk_user";
173
+            }
156 174
             $sql.= $db->order($sortfield,$sortorder);
157 175
             // TODO: calculate total to display then restore pagination
158 176
             //$sql.= $db->plimit($conf->liste_limit +1, $offset);
@@ -177,10 +195,12 @@  discard block
 block discarded – undo
177 195
                 print_liste_field_titre("BuyingPrice",$_SERVER["PHP_SELF"],"buying_price","","&amp;id=".$object->id,'align="right"',$sortfield,$sortorder);
178 196
                 print_liste_field_titre("Qty",$_SERVER["PHP_SELF"],"d.qty","","&amp;id=".$object->id,'align="right"',$sortfield,$sortorder);
179 197
                 print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;id=".$object->id,'align="right"',$sortfield,$sortorder);
180
-                if (! empty($conf->global->DISPLAY_MARGIN_RATES))
181
-                    print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$object->id,'align="right"',$sortfield,$sortorder);
182
-                if (! empty($conf->global->DISPLAY_MARK_RATES))
183
-                    print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$object->id,'align="right"',$sortfield,$sortorder);
198
+                if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
199
+                                    print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$object->id,'align="right"',$sortfield,$sortorder);
200
+                }
201
+                if (! empty($conf->global->DISPLAY_MARK_RATES)) {
202
+                                    print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$object->id,'align="right"',$sortfield,$sortorder);
203
+                }
184 204
                 print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&amp;id=".$object->id,'align="right"',$sortfield,$sortorder);
185 205
                 print "</tr>\n";
186 206
 
@@ -210,10 +230,12 @@  discard block
 block discarded – undo
210 230
 						print "<td align=\"right\">".price($objp->buying_price, null, null, null, null, $rounding)."</td>\n";
211 231
 						print "<td align=\"right\">".price($objp->qty, null, null, null, null, $rounding)."</td>\n";
212 232
 						print "<td align=\"right\">".price($objp->marge, null, null, null, null, $rounding)."</td>\n";
213
-						if (! empty($conf->global->DISPLAY_MARGIN_RATES))
214
-							print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
215
-						if (! empty($conf->global->DISPLAY_MARK_RATES))
216
-							print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
233
+						if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
234
+													print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
235
+						}
236
+						if (! empty($conf->global->DISPLAY_MARK_RATES)) {
237
+													print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
238
+						}
217 239
 						print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>';
218 240
                         print "</tr>\n";
219 241
                         $i++;
@@ -230,8 +252,7 @@  discard block
 block discarded – undo
230 252
                 {
231 253
                     $marginRate = ($cumul_achat != 0)?-1*(100 * $totalMargin / $cumul_achat):'';
232 254
                     $markRate = ($cumul_vente != 0)?-1*(100 * $totalMargin / $cumul_vente):'';
233
-                }
234
-                else
255
+                } else
235 256
                 {
236 257
                     $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):'';
237 258
                     $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):'';
@@ -242,10 +263,12 @@  discard block
 block discarded – undo
242 263
                 print '<td align="right">'.price($cumul_achat, null, null, null, null, $rounding)."</td>\n";
243 264
                 print '<td align="right">'.price($cumul_qty, null, null, null, null, $rounding)."</td>\n";
244 265
                 print '<td align="right">'.price($totalMargin, null, null, null, null, $rounding)."</td>\n";
245
-                if (! empty($conf->global->DISPLAY_MARGIN_RATES))
246
-                    print '<td align="right">'.(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
247
-                if (! empty($conf->global->DISPLAY_MARK_RATES))
248
-                    print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
266
+                if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
267
+                                    print '<td align="right">'.(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
268
+                }
269
+                if (! empty($conf->global->DISPLAY_MARK_RATES)) {
270
+                                    print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
271
+                }
249 272
                 print '<td align="right">&nbsp;</td>';
250 273
                 print "</tr>\n";
251 274
                 print "</table>";
Please login to merge, or discard this patch.
Spacing   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 
25 25
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
26 26
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
27
-require DOL_BASE_PATH . '/main.inc.php';
27
+require DOL_BASE_PATH.'/main.inc.php';
28 28
 require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
29 29
 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
30 30
 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
@@ -33,54 +33,54 @@  discard block
 block discarded – undo
33 33
 
34 34
 $id = GETPOST('id', 'int');
35 35
 $ref = GETPOST('ref', 'alpha');
36
-$action=GETPOST('action','alpha');
37
-$confirm=GETPOST('confirm','alpha');
36
+$action = GETPOST('action', 'alpha');
37
+$confirm = GETPOST('confirm', 'alpha');
38 38
 
39 39
 // Security check
40
-$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
41
-$fieldtype = (! empty($ref) ? 'ref' : 'rowid');
42
-if (! empty($user->societe_id)) $socid=$user->societe_id;
43
-$result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
40
+$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
41
+$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
42
+if (!empty($user->societe_id)) $socid = $user->societe_id;
43
+$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
44 44
 
45 45
 $object = new Product($db);
46 46
 
47 47
 $mesg = '';
48 48
 
49
-$sortfield = GETPOST("sortfield",'alpha');
50
-$sortorder = GETPOST("sortorder",'alpha');
51
-$page = GETPOST("page",'int');
49
+$sortfield = GETPOST("sortfield", 'alpha');
50
+$sortorder = GETPOST("sortorder", 'alpha');
51
+$page = GETPOST("page", 'int');
52 52
 if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
53 53
 $offset = $conf->liste_limit * $page;
54 54
 $pageprev = $page - 1;
55 55
 $pagenext = $page + 1;
56
-if (! $sortorder) $sortorder="DESC";
57
-if (! $sortfield) $sortfield="f.datef";
56
+if (!$sortorder) $sortorder = "DESC";
57
+if (!$sortfield) $sortfield = "f.datef";
58 58
 
59 59
 
60 60
 /*
61 61
  * View
62 62
  */
63 63
 
64
-$invoicestatic=new Facture($db);
64
+$invoicestatic = new Facture($db);
65 65
 
66 66
 $form = new Form($db);
67 67
 
68
-if ($id > 0 || ! empty($ref))
68
+if ($id > 0 || !empty($ref))
69 69
 {
70 70
     $result = $object->fetch($id, $ref);
71 71
 
72 72
     $title = $langs->trans('ProductServiceCard');
73 73
 	$helpurl = '';
74
-	$shortlabel = dol_trunc($object->label,16);
74
+	$shortlabel = dol_trunc($object->label, 16);
75 75
 	if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT))
76 76
 	{
77
-		$title = $langs->trans('Product')." ". $shortlabel ." - ".$langs->trans('Card');
78
-		$helpurl='EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
77
+		$title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Card');
78
+		$helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
79 79
 	}
80 80
 	if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE))
81 81
 	{
82
-		$title = $langs->trans('Service')." ". $shortlabel ." - ".$langs->trans('Card');
83
-		$helpurl='EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
82
+		$title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Card');
83
+		$helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
84 84
 	}
85 85
 
86 86
 	llxHeader('', $title, $helpurl);
@@ -90,14 +90,14 @@  discard block
 block discarded – undo
90 90
 	 */
91 91
 	if ($result > 0)
92 92
 	{
93
-		$head=product_prepare_head($object);
94
-		$titre=$langs->trans("CardProduct".$object->type);
95
-		$picto=($object->type== Product::TYPE_SERVICE?'service':'product');
93
+		$head = product_prepare_head($object);
94
+		$titre = $langs->trans("CardProduct".$object->type);
95
+		$picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
96 96
 		dol_fiche_head($head, 'margin', $titre, -1, $picto);
97 97
 
98 98
 		$linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
99 99
 
100
-        dol_banner_tab($object, 'ref', $linkback, ($user->societe_id?0:1), 'ref');
100
+        dol_banner_tab($object, 'ref', $linkback, ($user->societe_id ? 0 : 1), 'ref');
101 101
 
102 102
 
103 103
         print '<div class="fichecenter">';
@@ -111,14 +111,14 @@  discard block
 block discarded – undo
111 111
 		print '</td></tr>';
112 112
 
113 113
 		// Margin Rate
114
-		if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
114
+		if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
115 115
 			print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="3">';
116 116
 			print '<span id="marginRate"></span>'; // set by jquery (see below)
117 117
 			print '</td></tr>';
118 118
 		}
119 119
 
120 120
 		// Mark Rate
121
-		if (! empty($conf->global->DISPLAY_MARK_RATES)) {
121
+		if (!empty($conf->global->DISPLAY_MARK_RATES)) {
122 122
 			print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="3">';
123 123
 			print '<span id="markRate"></span>'; // set by jquery (see below)
124 124
 			print '</td></tr>';
@@ -134,29 +134,29 @@  discard block
 block discarded – undo
134 134
 
135 135
         if ($user->rights->facture->lire) {
136 136
             $sql = "SELECT s.nom as name, s.rowid as socid, s.code_client,";
137
-            $sql.= " f.rowid as facid, f.ref, f.total as total_ht,";
138
-            $sql.= " f.datef, f.paye, f.fk_statut as statut, f.type,";
139
-            if (!$user->rights->societe->client->voir && !$socid) $sql.= " sc.fk_soc, sc.fk_user,";
140
-            $sql.= " sum(d.total_ht) as selling_price,";							// may be negative or positive
141
-            $sql.= " IF(f.type = 2, -1, 1) * sum(d.qty) as qty,";						// not always positive in case of Credit note
142
-            $sql.= " IF(f.type = 2, -1, 1) * sum(d.qty * d.buy_price_ht) as buying_price,";			// not always positive in case of Credit note
143
-            $sql.= " IF(f.type = 2, -1, 1) * sum(abs(d.total_ht) - (d.buy_price_ht * d.qty)) as marge" ;	// not always positive in case of Credit note
144
-            $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
145
-            $sql.= ", ".MAIN_DB_PREFIX."facture as f";
146
-            $sql.= ", ".MAIN_DB_PREFIX."facturedet as d";
147
-            if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
148
-            $sql.= " WHERE f.fk_soc = s.rowid";
149
-            $sql.= " AND f.fk_statut > 0";
150
-            $sql.= " AND s.entity = ".$conf->entity;
151
-            $sql.= " AND d.fk_facture = f.rowid";
152
-            $sql.= " AND d.fk_product =".$object->id;
153
-            if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
154
-            if (! empty($socid)) $sql.= " AND f.fk_soc = $socid";
137
+            $sql .= " f.rowid as facid, f.ref, f.total as total_ht,";
138
+            $sql .= " f.datef, f.paye, f.fk_statut as statut, f.type,";
139
+            if (!$user->rights->societe->client->voir && !$socid) $sql .= " sc.fk_soc, sc.fk_user,";
140
+            $sql .= " sum(d.total_ht) as selling_price,"; // may be negative or positive
141
+            $sql .= " IF(f.type = 2, -1, 1) * sum(d.qty) as qty,"; // not always positive in case of Credit note
142
+            $sql .= " IF(f.type = 2, -1, 1) * sum(d.qty * d.buy_price_ht) as buying_price,"; // not always positive in case of Credit note
143
+            $sql .= " IF(f.type = 2, -1, 1) * sum(abs(d.total_ht) - (d.buy_price_ht * d.qty)) as marge"; // not always positive in case of Credit note
144
+            $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
145
+            $sql .= ", ".MAIN_DB_PREFIX."facture as f";
146
+            $sql .= ", ".MAIN_DB_PREFIX."facturedet as d";
147
+            if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
148
+            $sql .= " WHERE f.fk_soc = s.rowid";
149
+            $sql .= " AND f.fk_statut > 0";
150
+            $sql .= " AND s.entity = ".$conf->entity;
151
+            $sql .= " AND d.fk_facture = f.rowid";
152
+            $sql .= " AND d.fk_product =".$object->id;
153
+            if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
154
+            if (!empty($socid)) $sql .= " AND f.fk_soc = $socid";
155 155
             $sql .= " AND d.buy_price_ht IS NOT NULL";
156 156
             if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0";
157
-            $sql.= " GROUP BY s.nom, s.rowid, s.code_client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut, f.type";
158
-            if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user";
159
-            $sql.= $db->order($sortfield,$sortorder);
157
+            $sql .= " GROUP BY s.nom, s.rowid, s.code_client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut, f.type";
158
+            if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
159
+            $sql .= $db->order($sortfield, $sortorder);
160 160
             // TODO: calculate total to display then restore pagination
161 161
             //$sql.= $db->plimit($conf->liste_limit +1, $offset);
162 162
             dol_syslog('margin:tabs:productMargins.php', LOG_DEBUG);
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
             if ($result) {
165 165
                 $num = $db->num_rows($result);
166 166
 
167
-                print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&amp;id=$object->id",$sortfield,$sortorder,'',0,0,'');
167
+                print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "&amp;id=$object->id", $sortfield, $sortorder, '', 0, 0, '');
168 168
 
169 169
                 $i = 0;
170 170
 
@@ -172,52 +172,52 @@  discard block
 block discarded – undo
172 172
                 print '<table class="noborder" width="100%">';
173 173
 
174 174
                 print '<tr class="liste_titre">';
175
-                print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&amp;id=".$object->id,'',$sortfield,$sortorder);
176
-                print_liste_field_titre("Company",$_SERVER["PHP_SELF"],"s.nom","","&amp;id=".$object->id,'',$sortfield,$sortorder);
177
-                print_liste_field_titre("CustomerCode",$_SERVER["PHP_SELF"],"s.code_client","","&amp;id=".$object->id,'',$sortfield,$sortorder);
178
-                print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&amp;id=".$object->id,'align="center"',$sortfield,$sortorder);
179
-                print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&amp;id=".$object->id,'align="right"',$sortfield,$sortorder);
180
-                print_liste_field_titre("BuyingPrice",$_SERVER["PHP_SELF"],"buying_price","","&amp;id=".$object->id,'align="right"',$sortfield,$sortorder);
181
-                print_liste_field_titre("Qty",$_SERVER["PHP_SELF"],"d.qty","","&amp;id=".$object->id,'align="right"',$sortfield,$sortorder);
182
-                print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;id=".$object->id,'align="right"',$sortfield,$sortorder);
183
-                if (! empty($conf->global->DISPLAY_MARGIN_RATES))
184
-                    print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$object->id,'align="right"',$sortfield,$sortorder);
185
-                if (! empty($conf->global->DISPLAY_MARK_RATES))
186
-                    print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$object->id,'align="right"',$sortfield,$sortorder);
187
-                print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&amp;id=".$object->id,'align="right"',$sortfield,$sortorder);
175
+                print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "f.ref", "", "&amp;id=".$object->id, '', $sortfield, $sortorder);
176
+                print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&amp;id=".$object->id, '', $sortfield, $sortorder);
177
+                print_liste_field_titre("CustomerCode", $_SERVER["PHP_SELF"], "s.code_client", "", "&amp;id=".$object->id, '', $sortfield, $sortorder);
178
+                print_liste_field_titre("DateInvoice", $_SERVER["PHP_SELF"], "f.datef", "", "&amp;id=".$object->id, 'align="center"', $sortfield, $sortorder);
179
+                print_liste_field_titre("SellingPrice", $_SERVER["PHP_SELF"], "selling_price", "", "&amp;id=".$object->id, 'align="right"', $sortfield, $sortorder);
180
+                print_liste_field_titre("BuyingPrice", $_SERVER["PHP_SELF"], "buying_price", "", "&amp;id=".$object->id, 'align="right"', $sortfield, $sortorder);
181
+                print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", "&amp;id=".$object->id, 'align="right"', $sortfield, $sortorder);
182
+                print_liste_field_titre("Margin", $_SERVER["PHP_SELF"], "marge", "", "&amp;id=".$object->id, 'align="right"', $sortfield, $sortorder);
183
+                if (!empty($conf->global->DISPLAY_MARGIN_RATES))
184
+                    print_liste_field_titre("MarginRate", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$object->id, 'align="right"', $sortfield, $sortorder);
185
+                if (!empty($conf->global->DISPLAY_MARK_RATES))
186
+                    print_liste_field_titre("MarkRate", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$object->id, 'align="right"', $sortfield, $sortorder);
187
+                print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "f.paye,f.fk_statut", "", "&amp;id=".$object->id, 'align="right"', $sortfield, $sortorder);
188 188
                 print "</tr>\n";
189 189
 
190 190
                 $cumul_achat = 0;
191 191
                 $cumul_vente = 0;
192 192
                 $cumul_qty = 0;
193
-                $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
193
+                $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
194 194
 
195 195
                 if ($num > 0) {
196 196
                     while ($i < $num /*&& $i < $conf->liste_limit*/) {
197 197
                         $objp = $db->fetch_object($result);
198 198
 
199
-						$marginRate = ($objp->buying_price != 0)?(100 * $objp->marge / $objp->buying_price):'' ;
200
-						$markRate = ($objp->selling_price != 0)?(100 * $objp->marge / $objp->selling_price):'' ;
199
+						$marginRate = ($objp->buying_price != 0) ? (100 * $objp->marge / $objp->buying_price) : '';
200
+						$markRate = ($objp->selling_price != 0) ? (100 * $objp->marge / $objp->selling_price) : '';
201 201
 
202 202
                         print '<tr class="oddeven">';
203 203
                         print '<td>';
204
-                        $invoicestatic->id=$objp->facid;
205
-                        $invoicestatic->ref=$objp->ref;
204
+                        $invoicestatic->id = $objp->facid;
205
+                        $invoicestatic->ref = $objp->ref;
206 206
                         print $invoicestatic->getNomUrl(1);
207 207
                         print "</td>\n";
208
-                        print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->name,44).'</a></td>';
208
+                        print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.dol_trunc($objp->name, 44).'</a></td>';
209 209
                         print "<td>".$objp->code_client."</td>\n";
210 210
 						print "<td align=\"center\">";
211
-						print dol_print_date($db->jdate($objp->datef),'day')."</td>";
211
+						print dol_print_date($db->jdate($objp->datef), 'day')."</td>";
212 212
 						print "<td align=\"right\">".price($objp->selling_price, null, null, null, null, $rounding)."</td>\n";
213 213
 						print "<td align=\"right\">".price($objp->buying_price, null, null, null, null, $rounding)."</td>\n";
214 214
 						print "<td align=\"right\">".price($objp->qty, null, null, null, null, $rounding)."</td>\n";
215 215
 						print "<td align=\"right\">".price($objp->marge, null, null, null, null, $rounding)."</td>\n";
216
-						if (! empty($conf->global->DISPLAY_MARGIN_RATES))
217
-							print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
218
-						if (! empty($conf->global->DISPLAY_MARK_RATES))
219
-							print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
220
-						print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>';
216
+						if (!empty($conf->global->DISPLAY_MARGIN_RATES))
217
+							print "<td align=\"right\">".(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
218
+						if (!empty($conf->global->DISPLAY_MARK_RATES))
219
+							print "<td align=\"right\">".(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
220
+						print '<td align="right">'.$invoicestatic->LibStatut($objp->paye, $objp->statut, 5).'</td>';
221 221
                         print "</tr>\n";
222 222
                         $i++;
223 223
                         $cumul_achat += $objp->buying_price;
@@ -231,13 +231,13 @@  discard block
 block discarded – undo
231 231
                 $totalMargin = $cumul_vente - $cumul_achat;
232 232
                 if ($totalMargin < 0)
233 233
                 {
234
-                    $marginRate = ($cumul_achat != 0)?-1*(100 * $totalMargin / $cumul_achat):'';
235
-                    $markRate = ($cumul_vente != 0)?-1*(100 * $totalMargin / $cumul_vente):'';
234
+                    $marginRate = ($cumul_achat != 0) ?-1 * (100 * $totalMargin / $cumul_achat) : '';
235
+                    $markRate = ($cumul_vente != 0) ?-1 * (100 * $totalMargin / $cumul_vente) : '';
236 236
                 }
237 237
                 else
238 238
                 {
239
-                    $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):'';
240
-                    $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):'';
239
+                    $marginRate = ($cumul_achat != 0) ? (100 * $totalMargin / $cumul_achat) : '';
240
+                    $markRate = ($cumul_vente != 0) ? (100 * $totalMargin / $cumul_vente) : '';
241 241
                 }
242 242
                 print '<tr class="liste_total">';
243 243
                 print '<td colspan=4>'.$langs->trans('TotalMargin')."</td>";
@@ -245,10 +245,10 @@  discard block
 block discarded – undo
245 245
                 print '<td align="right">'.price($cumul_achat, null, null, null, null, $rounding)."</td>\n";
246 246
                 print '<td align="right">'.price($cumul_qty, null, null, null, null, $rounding)."</td>\n";
247 247
                 print '<td align="right">'.price($totalMargin, null, null, null, null, $rounding)."</td>\n";
248
-                if (! empty($conf->global->DISPLAY_MARGIN_RATES))
249
-                    print '<td align="right">'.(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
250
-                if (! empty($conf->global->DISPLAY_MARK_RATES))
251
-                    print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
248
+                if (!empty($conf->global->DISPLAY_MARGIN_RATES))
249
+                    print '<td align="right">'.(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
250
+                if (!empty($conf->global->DISPLAY_MARK_RATES))
251
+                    print "<td align=\"right\">".(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
252 252
                 print '<td align="right">&nbsp;</td>';
253 253
                 print "</tr>\n";
254 254
                 print "</table>";
@@ -267,8 +267,8 @@  discard block
 block discarded – undo
267 267
     <script type="text/javascript">
268 268
     $(document).ready(function() {
269 269
         $("#totalMargin").html("'. price($totalMargin, null, null, null, null, $rounding).'");
270
-        $("#marginRate").html("'.(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%").'");
271
-        $("#markRate").html("'.(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%").'");
270
+        $("#marginRate").html("'.(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%").'");
271
+        $("#markRate").html("'.(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%").'");
272 272
     });
273 273
     </script>
274 274
 ';
Please login to merge, or discard this patch.
dolibarr/htdocs/margin/tabs/thirdpartyMargins.php 3 patches
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -122,16 +122,16 @@  discard block
 block discarded – undo
122 122
 
123 123
     // Margin Rate
124 124
     if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
125
-    	print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="3">';
126
-    	print '<span id="marginRate"></span>'; // set by jquery (see below)
127
-    	print '</td></tr>';
125
+        print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="3">';
126
+        print '<span id="marginRate"></span>'; // set by jquery (see below)
127
+        print '</td></tr>';
128 128
     }
129 129
 
130 130
     // Mark Rate
131 131
     if (! empty($conf->global->DISPLAY_MARK_RATES)) {
132
-    	print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="3">';
133
-    	print '<span id="markRate"></span>'; // set by jquery (see below)
134
-    	print '</td></tr>';
132
+        print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="3">';
133
+        print '<span id="markRate"></span>'; // set by jquery (see below)
134
+        print '</td></tr>';
135 135
     }
136 136
 
137 137
     print "</table>";
@@ -168,99 +168,99 @@  discard block
 block discarded – undo
168 168
     $result = $db->query($sql);
169 169
     if ($result)
170 170
     {
171
-    	$num = $db->num_rows($result);
172
-
173
-    	print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&amp;socid=".$object->id,$sortfield,$sortorder,'',0,0,'');
174
-
175
-    	$i = 0;
176
-    	print '<div class="div-table-responsive">';		// You can use div-table-responsive-no-min if you dont need reserved height for your table
177
-    	print "<table class=\"noborder\" width=\"100%\">";
178
-
179
-    	print '<tr class="liste_titre">';
180
-    	print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&amp;socid=".$_REQUEST["socid"],'',$sortfield,$sortorder);
181
-    	print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&amp;socid=".$_REQUEST["socid"],'align="center"',$sortfield,$sortorder);
182
-    	print_liste_field_titre("SoldAmount",$_SERVER["PHP_SELF"],"selling_price","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
183
-    	print_liste_field_titre("PurchasedAmount",$_SERVER["PHP_SELF"],"buying_price","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
184
-    	print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
185
-    	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
186
-    		print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
187
-    	if (! empty($conf->global->DISPLAY_MARK_RATES))
188
-    		print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
189
-    	print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
190
-    	print "</tr>\n";
191
-
192
-    	$cumul_achat = 0;
193
-    	$cumul_vente = 0;
194
-
195
-    	$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
196
-
197
-    	if ($num > 0)
198
-    	{
199
-    		while ($i < $num /*&& $i < $conf->liste_limit*/)
200
-    		{
201
-    			$objp = $db->fetch_object($result);
202
-
203
-    			$marginRate = ($objp->buying_price != 0)?(100 * $objp->marge / $objp->buying_price):'' ;
204
-    			$markRate = ($objp->selling_price != 0)?(100 * $objp->marge / $objp->selling_price):'' ;
205
-
206
-    			$sign = '';
207
-    			if ($objp->type == Facture::TYPE_CREDIT_NOTE){
208
-    			    $sign = '-';
209
-    			}
210
-
211
-    			print '<tr class="oddeven">';
212
-    			print '<td>';
213
-    			$invoicestatic->id=$objp->facid;
214
-    			$invoicestatic->ref=$objp->ref;
215
-    			print $invoicestatic->getNomUrl(1);
216
-    			print "</td>\n";
217
-    			print "<td align=\"center\">";
218
-    			print dol_print_date($db->jdate($objp->datef),'day')."</td>";
219
-    			print "<td align=\"right\">".price($objp->selling_price, null, null, null, null, $rounding)."</td>\n";
220
-    			print "<td align=\"right\">".price(($objp->type == 2 ? -1 : 1) * $objp->buying_price, null, null, null, null, $rounding)."</td>\n";
221
-    			print "<td align=\"right\">".$sign.price($objp->marge, null, null, null, null, $rounding)."</td>\n";
222
-    			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
223
-    			    print "<td align=\"right\">".(($marginRate === '')?'n/a':$sign.price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
224
-    			if (! empty($conf->global->DISPLAY_MARK_RATES))
225
-    			    print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
226
-    			print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>';
227
-    			print "</tr>\n";
228
-    			$i++;
229
-    			$cumul_vente += $objp->selling_price;
230
-    			$cumul_achat += ($objp->type == 2 ? -1 : 1) * $objp->buying_price;
231
-    		}
232
-    	}
233
-
234
-    	// affichage totaux marges
235
-
236
-    	$totalMargin = $cumul_vente - $cumul_achat;
237
-    	if ($totalMargin < 0)
238
-    	{
239
-    		$marginRate = ($cumul_achat != 0)?-1*(100 * $totalMargin / $cumul_achat):'';
240
-    		$markRate = ($cumul_vente != 0)?-1*(100 * $totalMargin / $cumul_vente):'';
241
-    	}
242
-    	else
243
-    	{
244
-    		$marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):'';
245
-    		$markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):'';
246
-    	}
247
-
248
-    	// Total
249
-    	print '<tr class="liste_total">';
250
-    	print '<td colspan=2>'.$langs->trans('TotalMargin')."</td>";
251
-    	print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n";
252
-    	print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n";
253
-    	print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n";
254
-    	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
255
-    		print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
256
-    	if (! empty($conf->global->DISPLAY_MARK_RATES))
257
-    		print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
258
-    	print '<td align="right">&nbsp;</td>';
259
-    	print "</tr>\n";
171
+        $num = $db->num_rows($result);
172
+
173
+        print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&amp;socid=".$object->id,$sortfield,$sortorder,'',0,0,'');
174
+
175
+        $i = 0;
176
+        print '<div class="div-table-responsive">';		// You can use div-table-responsive-no-min if you dont need reserved height for your table
177
+        print "<table class=\"noborder\" width=\"100%\">";
178
+
179
+        print '<tr class="liste_titre">';
180
+        print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&amp;socid=".$_REQUEST["socid"],'',$sortfield,$sortorder);
181
+        print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&amp;socid=".$_REQUEST["socid"],'align="center"',$sortfield,$sortorder);
182
+        print_liste_field_titre("SoldAmount",$_SERVER["PHP_SELF"],"selling_price","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
183
+        print_liste_field_titre("PurchasedAmount",$_SERVER["PHP_SELF"],"buying_price","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
184
+        print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
185
+        if (! empty($conf->global->DISPLAY_MARGIN_RATES))
186
+            print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
187
+        if (! empty($conf->global->DISPLAY_MARK_RATES))
188
+            print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
189
+        print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
190
+        print "</tr>\n";
191
+
192
+        $cumul_achat = 0;
193
+        $cumul_vente = 0;
194
+
195
+        $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
196
+
197
+        if ($num > 0)
198
+        {
199
+            while ($i < $num /*&& $i < $conf->liste_limit*/)
200
+            {
201
+                $objp = $db->fetch_object($result);
202
+
203
+                $marginRate = ($objp->buying_price != 0)?(100 * $objp->marge / $objp->buying_price):'' ;
204
+                $markRate = ($objp->selling_price != 0)?(100 * $objp->marge / $objp->selling_price):'' ;
205
+
206
+                $sign = '';
207
+                if ($objp->type == Facture::TYPE_CREDIT_NOTE){
208
+                    $sign = '-';
209
+                }
210
+
211
+                print '<tr class="oddeven">';
212
+                print '<td>';
213
+                $invoicestatic->id=$objp->facid;
214
+                $invoicestatic->ref=$objp->ref;
215
+                print $invoicestatic->getNomUrl(1);
216
+                print "</td>\n";
217
+                print "<td align=\"center\">";
218
+                print dol_print_date($db->jdate($objp->datef),'day')."</td>";
219
+                print "<td align=\"right\">".price($objp->selling_price, null, null, null, null, $rounding)."</td>\n";
220
+                print "<td align=\"right\">".price(($objp->type == 2 ? -1 : 1) * $objp->buying_price, null, null, null, null, $rounding)."</td>\n";
221
+                print "<td align=\"right\">".$sign.price($objp->marge, null, null, null, null, $rounding)."</td>\n";
222
+                if (! empty($conf->global->DISPLAY_MARGIN_RATES))
223
+                    print "<td align=\"right\">".(($marginRate === '')?'n/a':$sign.price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
224
+                if (! empty($conf->global->DISPLAY_MARK_RATES))
225
+                    print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
226
+                print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>';
227
+                print "</tr>\n";
228
+                $i++;
229
+                $cumul_vente += $objp->selling_price;
230
+                $cumul_achat += ($objp->type == 2 ? -1 : 1) * $objp->buying_price;
231
+            }
232
+        }
233
+
234
+        // affichage totaux marges
235
+
236
+        $totalMargin = $cumul_vente - $cumul_achat;
237
+        if ($totalMargin < 0)
238
+        {
239
+            $marginRate = ($cumul_achat != 0)?-1*(100 * $totalMargin / $cumul_achat):'';
240
+            $markRate = ($cumul_vente != 0)?-1*(100 * $totalMargin / $cumul_vente):'';
241
+        }
242
+        else
243
+        {
244
+            $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):'';
245
+            $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):'';
246
+        }
247
+
248
+        // Total
249
+        print '<tr class="liste_total">';
250
+        print '<td colspan=2>'.$langs->trans('TotalMargin')."</td>";
251
+        print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n";
252
+        print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n";
253
+        print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n";
254
+        if (! empty($conf->global->DISPLAY_MARGIN_RATES))
255
+            print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
256
+        if (! empty($conf->global->DISPLAY_MARK_RATES))
257
+            print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
258
+        print '<td align="right">&nbsp;</td>';
259
+        print "</tr>\n";
260 260
     }
261 261
     else
262 262
     {
263
-    	dol_print_error($db);
263
+        dol_print_error($db);
264 264
     }
265 265
     print "</table>";
266 266
     print '</div>';
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 }
271 271
 else
272 272
 {
273
-	dol_print_error('', 'Parameter socid not defined');
273
+    dol_print_error('', 'Parameter socid not defined');
274 274
 }
275 275
 
276 276
 
Please login to merge, or discard this patch.
Braces   +48 added lines, -27 removed lines patch added patch discarded remove patch
@@ -30,7 +30,9 @@  discard block
 block discarded – undo
30 30
 
31 31
 // Security check
32 32
 $socid = GETPOST('socid','int');
33
-if (! empty($user->societe_id)) $socid=$user->societe_id;
33
+if (! empty($user->societe_id)) {
34
+    $socid=$user->societe_id;
35
+}
34 36
 $result = restrictedArea($user, 'societe','','');
35 37
 
36 38
 
@@ -43,11 +45,17 @@  discard block
 block discarded – undo
43 45
 $offset = $conf->liste_limit * $page;
44 46
 $pageprev = $page - 1;
45 47
 $pagenext = $page + 1;
46
-if (! $sortorder) $sortorder="DESC";
47
-if (! $sortfield) $sortfield="f.datef";
48
+if (! $sortorder) {
49
+    $sortorder="DESC";
50
+}
51
+if (! $sortfield) {
52
+    $sortfield="f.datef";
53
+}
48 54
 
49 55
 $object = new Societe($db);
50
-if ($socid > 0) $object->fetch($socid);
56
+if ($socid > 0) {
57
+    $object->fetch($socid);
58
+}
51 59
 
52 60
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
53 61
 $hookmanager->initHooks(array('thirdpartymargins','globalcard'));
@@ -59,7 +67,9 @@  discard block
 block discarded – undo
59 67
 
60 68
 $parameters=array('id'=>$socid);
61 69
 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
62
-if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
70
+if ($reshook < 0) {
71
+    setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
72
+}
63 73
 
64 74
 
65 75
 
@@ -71,7 +81,9 @@  discard block
 block discarded – undo
71 81
 $form = new Form($db);
72 82
 
73 83
 $title=$langs->trans("ThirdParty").' - '.$langs->trans("Margins");
74
-if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name.' - '.$langs->trans("Files");
84
+if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) {
85
+    $title=$object->name.' - '.$langs->trans("Files");
86
+}
75 87
 $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
76 88
 llxHeader('',$title,$help_url);
77 89
 
@@ -102,7 +114,9 @@  discard block
 block discarded – undo
102 114
         print '<tr><td class="titlefield">';
103 115
         print $langs->trans('CustomerCode').'</td><td colspan="3">';
104 116
         print $object->code_client;
105
-        if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
117
+        if ($object->check_codeclient() <> 0) {
118
+            print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
119
+        }
106 120
         print '</td></tr>';
107 121
     }
108 122
 
@@ -111,7 +125,9 @@  discard block
 block discarded – undo
111 125
         print '<tr><td class="titlefield">';
112 126
         print $langs->trans('SupplierCode').'</td><td colspan="3">';
113 127
         print $object->code_fournisseur;
114
-        if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
128
+        if ($object->check_codefournisseur() <> 0) {
129
+            print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
130
+        }
115 131
         print '</td></tr>';
116 132
     }
117 133
 
@@ -158,7 +174,9 @@  discard block
 block discarded – undo
158 174
     $sql.= " AND d.fk_facture = f.rowid";
159 175
     $sql.= " AND f.fk_soc = $socid";
160 176
     $sql.= " AND d.buy_price_ht IS NOT NULL";
161
-    if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0";
177
+    if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) {
178
+        $sql .= " AND d.buy_price_ht <> 0";
179
+    }
162 180
     $sql.= " GROUP BY s.nom, s.rowid, s.code_client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut, f.type";
163 181
     $sql.= $db->order($sortfield,$sortorder);
164 182
     // TODO: calculate total to display then restore pagination
@@ -182,10 +200,12 @@  discard block
 block discarded – undo
182 200
     	print_liste_field_titre("SoldAmount",$_SERVER["PHP_SELF"],"selling_price","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
183 201
     	print_liste_field_titre("PurchasedAmount",$_SERVER["PHP_SELF"],"buying_price","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
184 202
     	print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
185
-    	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
186
-    		print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
187
-    	if (! empty($conf->global->DISPLAY_MARK_RATES))
188
-    		print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
203
+    	if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
204
+    	    		print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
205
+    	}
206
+    	if (! empty($conf->global->DISPLAY_MARK_RATES)) {
207
+    	    		print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
208
+    	}
189 209
     	print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
190 210
     	print "</tr>\n";
191 211
 
@@ -219,10 +239,12 @@  discard block
 block discarded – undo
219 239
     			print "<td align=\"right\">".price($objp->selling_price, null, null, null, null, $rounding)."</td>\n";
220 240
     			print "<td align=\"right\">".price(($objp->type == 2 ? -1 : 1) * $objp->buying_price, null, null, null, null, $rounding)."</td>\n";
221 241
     			print "<td align=\"right\">".$sign.price($objp->marge, null, null, null, null, $rounding)."</td>\n";
222
-    			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
223
-    			    print "<td align=\"right\">".(($marginRate === '')?'n/a':$sign.price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
224
-    			if (! empty($conf->global->DISPLAY_MARK_RATES))
225
-    			    print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
242
+    			if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
243
+    			    			    print "<td align=\"right\">".(($marginRate === '')?'n/a':$sign.price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
244
+    			}
245
+    			if (! empty($conf->global->DISPLAY_MARK_RATES)) {
246
+    			    			    print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
247
+    			}
226 248
     			print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>';
227 249
     			print "</tr>\n";
228 250
     			$i++;
@@ -238,8 +260,7 @@  discard block
 block discarded – undo
238 260
     	{
239 261
     		$marginRate = ($cumul_achat != 0)?-1*(100 * $totalMargin / $cumul_achat):'';
240 262
     		$markRate = ($cumul_vente != 0)?-1*(100 * $totalMargin / $cumul_vente):'';
241
-    	}
242
-    	else
263
+    	} else
243 264
     	{
244 265
     		$marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):'';
245 266
     		$markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):'';
@@ -251,14 +272,15 @@  discard block
 block discarded – undo
251 272
     	print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n";
252 273
     	print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n";
253 274
     	print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n";
254
-    	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
255
-    		print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
256
-    	if (! empty($conf->global->DISPLAY_MARK_RATES))
257
-    		print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
275
+    	if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
276
+    	    		print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
277
+    	}
278
+    	if (! empty($conf->global->DISPLAY_MARK_RATES)) {
279
+    	    		print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
280
+    	}
258 281
     	print '<td align="right">&nbsp;</td>';
259 282
     	print "</tr>\n";
260
-    }
261
-    else
283
+    } else
262 284
     {
263 285
     	dol_print_error($db);
264 286
     }
@@ -267,8 +289,7 @@  discard block
 block discarded – undo
267 289
 
268 290
     print '<br>';
269 291
     $db->free($result);
270
-}
271
-else
292
+} else
272 293
 {
273 294
 	dol_print_error('', 'Parameter socid not defined');
274 295
 }
Please login to merge, or discard this patch.
Spacing   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 
26 26
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
27 27
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
28
-require DOL_BASE_PATH . '/main.inc.php';
28
+require DOL_BASE_PATH.'/main.inc.php';
29 29
 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
30 30
 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
31 31
 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
@@ -33,36 +33,36 @@  discard block
 block discarded – undo
33 33
 $langs->loadLangs(array("companies", "bills", "products", "margins"));
34 34
 
35 35
 // Security check
36
-$socid = GETPOST('socid','int');
37
-if (! empty($user->societe_id)) $socid=$user->societe_id;
38
-$result = restrictedArea($user, 'societe','','');
36
+$socid = GETPOST('socid', 'int');
37
+if (!empty($user->societe_id)) $socid = $user->societe_id;
38
+$result = restrictedArea($user, 'societe', '', '');
39 39
 
40 40
 
41 41
 $mesg = '';
42 42
 
43
-$sortfield = GETPOST("sortfield",'alpha');
44
-$sortorder = GETPOST("sortorder",'alpha');
45
-$page = GETPOST("page",'int');
43
+$sortfield = GETPOST("sortfield", 'alpha');
44
+$sortorder = GETPOST("sortorder", 'alpha');
45
+$page = GETPOST("page", 'int');
46 46
 if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
47 47
 $offset = $conf->liste_limit * $page;
48 48
 $pageprev = $page - 1;
49 49
 $pagenext = $page + 1;
50
-if (! $sortorder) $sortorder="DESC";
51
-if (! $sortfield) $sortfield="f.datef";
50
+if (!$sortorder) $sortorder = "DESC";
51
+if (!$sortfield) $sortfield = "f.datef";
52 52
 
53 53
 $object = new Societe($db);
54 54
 if ($socid > 0) $object->fetch($socid);
55 55
 
56 56
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
57
-$hookmanager->initHooks(array('thirdpartymargins','globalcard'));
57
+$hookmanager->initHooks(array('thirdpartymargins', 'globalcard'));
58 58
 
59 59
 
60 60
 /*
61 61
  * Actions
62 62
  */
63 63
 
64
-$parameters=array('id'=>$socid);
65
-$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
64
+$parameters = array('id'=>$socid);
65
+$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
66 66
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
67 67
 
68 68
 
@@ -71,13 +71,13 @@  discard block
 block discarded – undo
71 71
  * View
72 72
  */
73 73
 
74
-$invoicestatic=new Facture($db);
74
+$invoicestatic = new Facture($db);
75 75
 $form = new Form($db);
76 76
 
77
-$title=$langs->trans("ThirdParty").' - '.$langs->trans("Margins");
78
-if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name.' - '.$langs->trans("Files");
79
-$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
80
-llxHeader('',$title,$help_url);
77
+$title = $langs->trans("ThirdParty").' - '.$langs->trans("Margins");
78
+if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->name.' - '.$langs->trans("Files");
79
+$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
80
+llxHeader('', $title, $help_url);
81 81
 
82 82
 if ($socid > 0)
83 83
 {
@@ -93,9 +93,9 @@  discard block
 block discarded – undo
93 93
     dol_fiche_head($head, 'margin', $langs->trans("ThirdParty"), -1, 'company');
94 94
 
95 95
     // $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
96
-    $linkback = '<a href="' . BASE_URI . '?controller=societe&method=list&restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>';
96
+    $linkback = '<a href="'.BASE_URI.'?controller=societe&method=list&restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
97 97
 
98
-    dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
98
+    dol_banner_tab($object, 'socid', $linkback, ($user->societe_id ? 0 : 1), 'rowid', 'nom');
99 99
 
100 100
     print '<div class="fichecenter">';
101 101
 
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
         print '</td></tr>';
112 112
     }
113 113
 
114
-    if (! empty($conf->fournisseur->enabled) && $object->fournisseur && ! empty($user->rights->fournisseur->lire))
114
+    if (!empty($conf->fournisseur->enabled) && $object->fournisseur && !empty($user->rights->fournisseur->lire))
115 115
     {
116 116
         print '<tr><td class="titlefield">';
117 117
         print $langs->trans('SupplierCode').'</td><td colspan="3">';
@@ -126,14 +126,14 @@  discard block
 block discarded – undo
126 126
     print '</td></tr>';
127 127
 
128 128
     // Margin Rate
129
-    if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
129
+    if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
130 130
     	print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="3">';
131 131
     	print '<span id="marginRate"></span>'; // set by jquery (see below)
132 132
     	print '</td></tr>';
133 133
     }
134 134
 
135 135
     // Mark Rate
136
-    if (! empty($conf->global->DISPLAY_MARK_RATES)) {
136
+    if (!empty($conf->global->DISPLAY_MARK_RATES)) {
137 137
     	print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="3">';
138 138
     	print '<span id="markRate"></span>'; // set by jquery (see below)
139 139
     	print '</td></tr>';
@@ -149,23 +149,23 @@  discard block
 block discarded – undo
149 149
     print '<br>';
150 150
 
151 151
     $sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client,";
152
-    $sql.= " f.rowid as facid, f.ref, f.total as total_ht,";
153
-    $sql.= " f.datef, f.paye, f.fk_statut as statut, f.type,";
154
-    $sql.= " sum(d.total_ht) as selling_price,";						// may be negative or positive
155
-    $sql.= " sum(d.qty * d.buy_price_ht) as buying_price,";				// always positive
156
-    $sql.= " sum(abs(d.total_ht) - (d.buy_price_ht * d.qty)) as marge";	// always positive
157
-    $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
158
-    $sql.= ", ".MAIN_DB_PREFIX."facture as f";
159
-    $sql.= ", ".MAIN_DB_PREFIX."facturedet as d";
160
-    $sql.= " WHERE f.fk_soc = s.rowid";
161
-    $sql.= " AND f.fk_statut > 0";
162
-    $sql.= " AND f.entity = ".$conf->entity;
163
-    $sql.= " AND d.fk_facture = f.rowid";
164
-    $sql.= " AND f.fk_soc = $socid";
165
-    $sql.= " AND d.buy_price_ht IS NOT NULL";
152
+    $sql .= " f.rowid as facid, f.ref, f.total as total_ht,";
153
+    $sql .= " f.datef, f.paye, f.fk_statut as statut, f.type,";
154
+    $sql .= " sum(d.total_ht) as selling_price,"; // may be negative or positive
155
+    $sql .= " sum(d.qty * d.buy_price_ht) as buying_price,"; // always positive
156
+    $sql .= " sum(abs(d.total_ht) - (d.buy_price_ht * d.qty)) as marge"; // always positive
157
+    $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
158
+    $sql .= ", ".MAIN_DB_PREFIX."facture as f";
159
+    $sql .= ", ".MAIN_DB_PREFIX."facturedet as d";
160
+    $sql .= " WHERE f.fk_soc = s.rowid";
161
+    $sql .= " AND f.fk_statut > 0";
162
+    $sql .= " AND f.entity = ".$conf->entity;
163
+    $sql .= " AND d.fk_facture = f.rowid";
164
+    $sql .= " AND f.fk_soc = $socid";
165
+    $sql .= " AND d.buy_price_ht IS NOT NULL";
166 166
     if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0";
167
-    $sql.= " GROUP BY s.nom, s.rowid, s.code_client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut, f.type";
168
-    $sql.= $db->order($sortfield,$sortorder);
167
+    $sql .= " GROUP BY s.nom, s.rowid, s.code_client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut, f.type";
168
+    $sql .= $db->order($sortfield, $sortorder);
169 169
     // TODO: calculate total to display then restore pagination
170 170
     //$sql.= $db->plimit($conf->liste_limit +1, $offset);
171 171
 
@@ -175,29 +175,29 @@  discard block
 block discarded – undo
175 175
     {
176 176
     	$num = $db->num_rows($result);
177 177
 
178
-    	print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&amp;socid=".$object->id,$sortfield,$sortorder,'',0,0,'');
178
+    	print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "&amp;socid=".$object->id, $sortfield, $sortorder, '', 0, 0, '');
179 179
 
180 180
     	$i = 0;
181
-    	print '<div class="div-table-responsive">';		// You can use div-table-responsive-no-min if you dont need reserved height for your table
181
+    	print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
182 182
     	print "<table class=\"noborder\" width=\"100%\">";
183 183
 
184 184
     	print '<tr class="liste_titre">';
185
-    	print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&amp;socid=".$_REQUEST["socid"],'',$sortfield,$sortorder);
186
-    	print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&amp;socid=".$_REQUEST["socid"],'align="center"',$sortfield,$sortorder);
187
-    	print_liste_field_titre("SoldAmount",$_SERVER["PHP_SELF"],"selling_price","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
188
-    	print_liste_field_titre("PurchasedAmount",$_SERVER["PHP_SELF"],"buying_price","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
189
-    	print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
190
-    	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
191
-    		print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
192
-    	if (! empty($conf->global->DISPLAY_MARK_RATES))
193
-    		print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
194
-    	print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
185
+    	print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "f.ref", "", "&amp;socid=".$_REQUEST["socid"], '', $sortfield, $sortorder);
186
+    	print_liste_field_titre("DateInvoice", $_SERVER["PHP_SELF"], "f.datef", "", "&amp;socid=".$_REQUEST["socid"], 'align="center"', $sortfield, $sortorder);
187
+    	print_liste_field_titre("SoldAmount", $_SERVER["PHP_SELF"], "selling_price", "", "&amp;socid=".$_REQUEST["socid"], 'align="right"', $sortfield, $sortorder);
188
+    	print_liste_field_titre("PurchasedAmount", $_SERVER["PHP_SELF"], "buying_price", "", "&amp;socid=".$_REQUEST["socid"], 'align="right"', $sortfield, $sortorder);
189
+    	print_liste_field_titre("Margin", $_SERVER["PHP_SELF"], "marge", "", "&amp;socid=".$_REQUEST["socid"], 'align="right"', $sortfield, $sortorder);
190
+    	if (!empty($conf->global->DISPLAY_MARGIN_RATES))
191
+    		print_liste_field_titre("MarginRate", $_SERVER["PHP_SELF"], "", "", "&amp;socid=".$_REQUEST["socid"], 'align="right"', $sortfield, $sortorder);
192
+    	if (!empty($conf->global->DISPLAY_MARK_RATES))
193
+    		print_liste_field_titre("MarkRate", $_SERVER["PHP_SELF"], "", "", "&amp;socid=".$_REQUEST["socid"], 'align="right"', $sortfield, $sortorder);
194
+    	print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "f.paye,f.fk_statut", "", "&amp;socid=".$_REQUEST["socid"], 'align="right"', $sortfield, $sortorder);
195 195
     	print "</tr>\n";
196 196
 
197 197
     	$cumul_achat = 0;
198 198
     	$cumul_vente = 0;
199 199
 
200
-    	$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
200
+    	$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
201 201
 
202 202
     	if ($num > 0)
203 203
     	{
@@ -205,30 +205,30 @@  discard block
 block discarded – undo
205 205
     		{
206 206
     			$objp = $db->fetch_object($result);
207 207
 
208
-    			$marginRate = ($objp->buying_price != 0)?(100 * $objp->marge / $objp->buying_price):'' ;
209
-    			$markRate = ($objp->selling_price != 0)?(100 * $objp->marge / $objp->selling_price):'' ;
208
+    			$marginRate = ($objp->buying_price != 0) ? (100 * $objp->marge / $objp->buying_price) : '';
209
+    			$markRate = ($objp->selling_price != 0) ? (100 * $objp->marge / $objp->selling_price) : '';
210 210
 
211 211
     			$sign = '';
212
-    			if ($objp->type == Facture::TYPE_CREDIT_NOTE){
212
+    			if ($objp->type == Facture::TYPE_CREDIT_NOTE) {
213 213
     			    $sign = '-';
214 214
     			}
215 215
 
216 216
     			print '<tr class="oddeven">';
217 217
     			print '<td>';
218
-    			$invoicestatic->id=$objp->facid;
219
-    			$invoicestatic->ref=$objp->ref;
218
+    			$invoicestatic->id = $objp->facid;
219
+    			$invoicestatic->ref = $objp->ref;
220 220
     			print $invoicestatic->getNomUrl(1);
221 221
     			print "</td>\n";
222 222
     			print "<td align=\"center\">";
223
-    			print dol_print_date($db->jdate($objp->datef),'day')."</td>";
223
+    			print dol_print_date($db->jdate($objp->datef), 'day')."</td>";
224 224
     			print "<td align=\"right\">".price($objp->selling_price, null, null, null, null, $rounding)."</td>\n";
225 225
     			print "<td align=\"right\">".price(($objp->type == 2 ? -1 : 1) * $objp->buying_price, null, null, null, null, $rounding)."</td>\n";
226 226
     			print "<td align=\"right\">".$sign.price($objp->marge, null, null, null, null, $rounding)."</td>\n";
227
-    			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
228
-    			    print "<td align=\"right\">".(($marginRate === '')?'n/a':$sign.price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
229
-    			if (! empty($conf->global->DISPLAY_MARK_RATES))
230
-    			    print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
231
-    			print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>';
227
+    			if (!empty($conf->global->DISPLAY_MARGIN_RATES))
228
+    			    print "<td align=\"right\">".(($marginRate === '') ? 'n/a' : $sign.price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
229
+    			if (!empty($conf->global->DISPLAY_MARK_RATES))
230
+    			    print "<td align=\"right\">".(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
231
+    			print '<td align="right">'.$invoicestatic->LibStatut($objp->paye, $objp->statut, 5).'</td>';
232 232
     			print "</tr>\n";
233 233
     			$i++;
234 234
     			$cumul_vente += $objp->selling_price;
@@ -241,13 +241,13 @@  discard block
 block discarded – undo
241 241
     	$totalMargin = $cumul_vente - $cumul_achat;
242 242
     	if ($totalMargin < 0)
243 243
     	{
244
-    		$marginRate = ($cumul_achat != 0)?-1*(100 * $totalMargin / $cumul_achat):'';
245
-    		$markRate = ($cumul_vente != 0)?-1*(100 * $totalMargin / $cumul_vente):'';
244
+    		$marginRate = ($cumul_achat != 0) ?-1 * (100 * $totalMargin / $cumul_achat) : '';
245
+    		$markRate = ($cumul_vente != 0) ?-1 * (100 * $totalMargin / $cumul_vente) : '';
246 246
     	}
247 247
     	else
248 248
     	{
249
-    		$marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):'';
250
-    		$markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):'';
249
+    		$marginRate = ($cumul_achat != 0) ? (100 * $totalMargin / $cumul_achat) : '';
250
+    		$markRate = ($cumul_vente != 0) ? (100 * $totalMargin / $cumul_vente) : '';
251 251
     	}
252 252
 
253 253
     	// Total
@@ -256,10 +256,10 @@  discard block
 block discarded – undo
256 256
     	print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n";
257 257
     	print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n";
258 258
     	print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n";
259
-    	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
260
-    		print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
261
-    	if (! empty($conf->global->DISPLAY_MARK_RATES))
262
-    		print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
259
+    	if (!empty($conf->global->DISPLAY_MARGIN_RATES))
260
+    		print "<td align=\"right\">".(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
261
+    	if (!empty($conf->global->DISPLAY_MARK_RATES))
262
+    		print "<td align=\"right\">".(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
263 263
     	print '<td align="right">&nbsp;</td>';
264 264
     	print "</tr>\n";
265 265
     }
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
     <script type="text/javascript">
284 284
     $(document).ready(function() {
285 285
         $("#totalMargin").html("'. price($totalMargin, null, null, null, null, $rounding).'");
286
-        $("#marginRate").html("'.(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%").'");
287
-        $("#markRate").html("'.(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%").'");
286
+        $("#marginRate").html("'.(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%").'");
287
+        $("#markRate").html("'.(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%").'");
288 288
     });
289 289
     </script>
290 290
 ';
Please login to merge, or discard this patch.
dolibarr/htdocs/margin/admin/margin.php 3 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 {
72 72
     if (dolibarr_set_const($db, 'MARGIN_METHODE_FOR_DISCOUNT', $_POST['MARGIN_METHODE_FOR_DISCOUNT'], 'chaine', 0, '', $conf->entity) > 0)
73 73
     {
74
-          setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
74
+            setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
75 75
     }
76 76
     else
77 77
     {
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 {
84 84
     if (dolibarr_set_const($db, 'MARGIN_TYPE', $_POST['MARGIN_TYPE'], 'chaine', 0, '', $conf->entity) > 0)
85 85
     {
86
-          setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
86
+            setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
87 87
     }
88 88
     else
89 89
     {
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 {
96 96
     if (dolibarr_set_const($db, 'AGENT_CONTACT_TYPE', $_POST['AGENT_CONTACT_TYPE'], 'chaine', 0, '', $conf->entity) > 0)
97 97
     {
98
-          setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
98
+            setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
99 99
     }
100 100
     else
101 101
     {
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 print '<td>';
138 138
 print ' <input type="radio" name="MARGIN_TYPE" value="1" ';
139 139
 if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '1')
140
-	print 'checked ';
140
+    print 'checked ';
141 141
 print '/> ';
142 142
 print $langs->trans('MargeType1');
143 143
 print '<br>';
@@ -165,18 +165,18 @@  discard block
 block discarded – undo
165 165
 print '<td colspan="2" align="center">';
166 166
 if (! empty($conf->use_javascript_ajax))
167 167
 {
168
-	print ajax_constantonoff('DISPLAY_MARGIN_RATES');
168
+    print ajax_constantonoff('DISPLAY_MARGIN_RATES');
169 169
 }
170 170
 else
171 171
 {
172
-	if (empty($conf->global->DISPLAY_MARGIN_RATES))
173
-	{
174
-		print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>';
175
-	}
176
-	else
177
-	{
178
-		print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>';
179
-	}
172
+    if (empty($conf->global->DISPLAY_MARGIN_RATES))
173
+    {
174
+        print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>';
175
+    }
176
+    else
177
+    {
178
+        print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>';
179
+    }
180 180
 }
181 181
 print '</td>';
182 182
 print '<td>'.$langs->trans('MarginRate').' = '.$langs->trans('Margin').' / '.$langs->trans('BuyingPrice').'</td>';
@@ -188,18 +188,18 @@  discard block
 block discarded – undo
188 188
 print '<td colspan="2" align="center">';
189 189
 if (! empty($conf->use_javascript_ajax))
190 190
 {
191
-	print ajax_constantonoff('DISPLAY_MARK_RATES');
191
+    print ajax_constantonoff('DISPLAY_MARK_RATES');
192 192
 }
193 193
 else
194 194
 {
195
-	if (empty($conf->global->DISPLAY_MARK_RATES))
196
-	{
197
-		print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>';
198
-	}
199
-	else
200
-	{
201
-		print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>';
202
-	}
195
+    if (empty($conf->global->DISPLAY_MARK_RATES))
196
+    {
197
+        print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>';
198
+    }
199
+    else
200
+    {
201
+        print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>';
202
+    }
203 203
 }
204 204
 print '</td>';
205 205
 print '<td>'.$langs->trans('MarkRate').' = '.$langs->trans('Margin').' / '.$langs->trans('SellingPrice').'</td>';
@@ -211,18 +211,18 @@  discard block
 block discarded – undo
211 211
 print '<td colspan="2" align="center">';
212 212
 if (! empty($conf->use_javascript_ajax))
213 213
 {
214
-	print ajax_constantonoff('ForceBuyingPriceIfNull');
214
+    print ajax_constantonoff('ForceBuyingPriceIfNull');
215 215
 }
216 216
 else
217 217
 {
218
-	if (empty($conf->global->ForceBuyingPriceIfNull))
219
-	{
220
-		print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Disabled"),'off').'</a>';
221
-	}
222
-	else
223
-	{
224
-		print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Enabled"),'on').'</a>';
225
-	}
218
+    if (empty($conf->global->ForceBuyingPriceIfNull))
219
+    {
220
+        print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Disabled"),'off').'</a>';
221
+    }
222
+    else
223
+    {
224
+        print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Enabled"),'on').'</a>';
225
+    }
226 226
 }
227 227
 print '</td>';
228 228
 print '<td>'.$langs->trans('ForceBuyingPriceIfNullDetails').'</td>';
@@ -230,9 +230,9 @@  discard block
 block discarded – undo
230 230
 
231 231
 // GLOBAL DISCOUNT MANAGEMENT
232 232
 $methods = array(
233
-	1 => $langs->trans('UseDiscountAsProduct'),
234
-	2 => $langs->trans('UseDiscountAsService'),
235
-	3 => $langs->trans('UseDiscountOnTotal')
233
+    1 => $langs->trans('UseDiscountAsProduct'),
234
+    2 => $langs->trans('UseDiscountAsService'),
235
+    3 => $langs->trans('UseDiscountOnTotal')
236 236
 );
237 237
 
238 238
 
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -31,17 +31,17 @@  discard block
 block discarded – undo
31 31
 
32 32
 $langs->loadLangs(array("admin", "bills", "margins", "stocks"));
33 33
 
34
-if (! $user->admin) accessforbidden();
34
+if (!$user->admin) accessforbidden();
35 35
 
36
-$action=GETPOST('action','alpha');
36
+$action = GETPOST('action', 'alpha');
37 37
 
38 38
 
39 39
 /*
40 40
  * Action
41 41
  */
42
-if (preg_match('/set_([a-z0-9_\-]+)/i',$action,$reg))
42
+if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg))
43 43
 {
44
-    $code=$reg[1];
44
+    $code = $reg[1];
45 45
     if (dolibarr_set_const($db, $code, 1, 'yesno', 0, '', $conf->entity) > 0)
46 46
     {
47 47
         header("Location: ".$_SERVER["PHP_SELF"]);
@@ -53,9 +53,9 @@  discard block
 block discarded – undo
53 53
     }
54 54
 }
55 55
 
56
-if (preg_match('/del_([a-z0-9_\-]+)/i',$action,$reg))
56
+if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg))
57 57
 {
58
-    $code=$reg[1];
58
+    $code = $reg[1];
59 59
     if (dolibarr_del_const($db, $code, $conf->entity) > 0)
60 60
     {
61 61
         header("Location: ".$_SERVER["PHP_SELF"]);
@@ -107,18 +107,18 @@  discard block
 block discarded – undo
107 107
  * View
108 108
  */
109 109
 
110
-llxHeader('',$langs->trans("margesSetup"));
110
+llxHeader('', $langs->trans("margesSetup"));
111 111
 
112 112
 
113
-$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
114
-print load_fiche_titre($langs->trans("margesSetup"),$linkback,'title_setup');
113
+$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
114
+print load_fiche_titre($langs->trans("margesSetup"), $linkback, 'title_setup');
115 115
 
116 116
 
117 117
 $head = marges_admin_prepare_head();
118 118
 
119 119
 dol_fiche_head($head, 'parameters', $langs->trans("Margins"), -1, 'margin');
120 120
 
121
-print load_fiche_titre($langs->trans("MemberMainOptions"),'','');
121
+print load_fiche_titre($langs->trans("MemberMainOptions"), '', '');
122 122
 print '<table class="noborder" width="100%">';
123 123
 print '<tr class="liste_titre">';
124 124
 print '<td width=300>'.$langs->trans("Description").'</td>';
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 print '<tr class="oddeven">';
164 164
 print '<td>'.$langs->trans("DisplayMarginRates").'</td>';
165 165
 print '<td colspan="2" align="center">';
166
-if (! empty($conf->use_javascript_ajax))
166
+if (!empty($conf->use_javascript_ajax))
167 167
 {
168 168
 	print ajax_constantonoff('DISPLAY_MARGIN_RATES');
169 169
 }
@@ -171,11 +171,11 @@  discard block
 block discarded – undo
171 171
 {
172 172
 	if (empty($conf->global->DISPLAY_MARGIN_RATES))
173 173
 	{
174
-		print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>';
174
+		print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
175 175
 	}
176 176
 	else
177 177
 	{
178
-		print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>';
178
+		print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
179 179
 	}
180 180
 }
181 181
 print '</td>';
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 print '<tr class="oddeven">';
187 187
 print '<td>'.$langs->trans("DisplayMarkRates").'</td>';
188 188
 print '<td colspan="2" align="center">';
189
-if (! empty($conf->use_javascript_ajax))
189
+if (!empty($conf->use_javascript_ajax))
190 190
 {
191 191
 	print ajax_constantonoff('DISPLAY_MARK_RATES');
192 192
 }
@@ -194,11 +194,11 @@  discard block
 block discarded – undo
194 194
 {
195 195
 	if (empty($conf->global->DISPLAY_MARK_RATES))
196 196
 	{
197
-		print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>';
197
+		print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
198 198
 	}
199 199
 	else
200 200
 	{
201
-		print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>';
201
+		print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
202 202
 	}
203 203
 }
204 204
 print '</td>';
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 print '<tr class="oddeven">';
210 210
 print '<td>'.$langs->trans("ForceBuyingPriceIfNull").'</td>';
211 211
 print '<td colspan="2" align="center">';
212
-if (! empty($conf->use_javascript_ajax))
212
+if (!empty($conf->use_javascript_ajax))
213 213
 {
214 214
 	print ajax_constantonoff('ForceBuyingPriceIfNull');
215 215
 }
@@ -217,11 +217,11 @@  discard block
 block discarded – undo
217 217
 {
218 218
 	if (empty($conf->global->ForceBuyingPriceIfNull))
219 219
 	{
220
-		print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Disabled"),'off').'</a>';
220
+		print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
221 221
 	}
222 222
 	else
223 223
 	{
224
-		print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Enabled"),'on').'</a>';
224
+		print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
225 225
 	}
226 226
 }
227 227
 print '</td>';
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 print '<td align="left">';
261 261
 $formcompany = new FormCompany($db);
262 262
 $facture = new Facture($db);
263
-print $formcompany->selectTypeContact($facture, $conf->global->AGENT_CONTACT_TYPE, "AGENT_CONTACT_TYPE","internal","code",1);
263
+print $formcompany->selectTypeContact($facture, $conf->global->AGENT_CONTACT_TYPE, "AGENT_CONTACT_TYPE", "internal", "code", 1);
264 264
 print '</td>';
265 265
 print '<td>';
266 266
 print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
Please login to merge, or discard this patch.
Braces   +22 added lines, -26 removed lines patch added patch discarded remove patch
@@ -31,7 +31,9 @@  discard block
 block discarded – undo
31 31
 
32 32
 $langs->loadLangs(array("admin", "bills", "margins", "stocks"));
33 33
 
34
-if (! $user->admin) accessforbidden();
34
+if (! $user->admin) {
35
+    accessforbidden();
36
+}
35 37
 
36 38
 $action=GETPOST('action','alpha');
37 39
 
@@ -46,8 +48,7 @@  discard block
 block discarded – undo
46 48
     {
47 49
         header("Location: ".$_SERVER["PHP_SELF"]);
48 50
         exit;
49
-    }
50
-    else
51
+    } else
51 52
     {
52 53
         dol_print_error($db);
53 54
     }
@@ -60,8 +61,7 @@  discard block
 block discarded – undo
60 61
     {
61 62
         header("Location: ".$_SERVER["PHP_SELF"]);
62 63
         exit;
63
-    }
64
-    else
64
+    } else
65 65
     {
66 66
         dol_print_error($db);
67 67
     }
@@ -72,8 +72,7 @@  discard block
 block discarded – undo
72 72
     if (dolibarr_set_const($db, 'MARGIN_METHODE_FOR_DISCOUNT', $_POST['MARGIN_METHODE_FOR_DISCOUNT'], 'chaine', 0, '', $conf->entity) > 0)
73 73
     {
74 74
           setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
75
-    }
76
-    else
75
+    } else
77 76
     {
78 77
         dol_print_error($db);
79 78
     }
@@ -84,8 +83,7 @@  discard block
 block discarded – undo
84 83
     if (dolibarr_set_const($db, 'MARGIN_TYPE', $_POST['MARGIN_TYPE'], 'chaine', 0, '', $conf->entity) > 0)
85 84
     {
86 85
           setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
87
-    }
88
-    else
86
+    } else
89 87
     {
90 88
         dol_print_error($db);
91 89
     }
@@ -96,8 +94,7 @@  discard block
 block discarded – undo
96 94
     if (dolibarr_set_const($db, 'AGENT_CONTACT_TYPE', $_POST['AGENT_CONTACT_TYPE'], 'chaine', 0, '', $conf->entity) > 0)
97 95
     {
98 96
           setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
99
-    }
100
-    else
97
+    } else
101 98
     {
102 99
         dol_print_error($db);
103 100
     }
@@ -136,18 +133,23 @@  discard block
 block discarded – undo
136 133
 print '<td>'.$langs->trans("MARGIN_TYPE").'</td>';
137 134
 print '<td>';
138 135
 print ' <input type="radio" name="MARGIN_TYPE" value="1" ';
139
-if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '1')
136
+if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '1') {
140 137
 	print 'checked ';
138
+}
141 139
 print '/> ';
142 140
 print $langs->trans('MargeType1');
143 141
 print '<br>';
144 142
 print ' <input type="radio" name="MARGIN_TYPE" value="pmp" ';
145
-if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp') print 'checked ';
143
+if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp') {
144
+    print 'checked ';
145
+}
146 146
 print '/> ';
147 147
 print $langs->trans('MargeType2');
148 148
 print '<br>';
149 149
 print ' <input type="radio" name="MARGIN_TYPE" value="costprice" ';
150
-if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'costprice') print 'checked ';
150
+if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'costprice') {
151
+    print 'checked ';
152
+}
151 153
 print '/> ';
152 154
 print $langs->trans('MargeType3');
153 155
 print '</td>';
@@ -166,14 +168,12 @@  discard block
 block discarded – undo
166 168
 if (! empty($conf->use_javascript_ajax))
167 169
 {
168 170
 	print ajax_constantonoff('DISPLAY_MARGIN_RATES');
169
-}
170
-else
171
+} else
171 172
 {
172 173
 	if (empty($conf->global->DISPLAY_MARGIN_RATES))
173 174
 	{
174 175
 		print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>';
175
-	}
176
-	else
176
+	} else
177 177
 	{
178 178
 		print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>';
179 179
 	}
@@ -189,14 +189,12 @@  discard block
 block discarded – undo
189 189
 if (! empty($conf->use_javascript_ajax))
190 190
 {
191 191
 	print ajax_constantonoff('DISPLAY_MARK_RATES');
192
-}
193
-else
192
+} else
194 193
 {
195 194
 	if (empty($conf->global->DISPLAY_MARK_RATES))
196 195
 	{
197 196
 		print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>';
198
-	}
199
-	else
197
+	} else
200 198
 	{
201 199
 		print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>';
202 200
 	}
@@ -212,14 +210,12 @@  discard block
 block discarded – undo
212 210
 if (! empty($conf->use_javascript_ajax))
213 211
 {
214 212
 	print ajax_constantonoff('ForceBuyingPriceIfNull');
215
-}
216
-else
213
+} else
217 214
 {
218 215
 	if (empty($conf->global->ForceBuyingPriceIfNull))
219 216
 	{
220 217
 		print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Disabled"),'off').'</a>';
221
-	}
222
-	else
218
+	} else
223 219
 	{
224 220
 		print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Enabled"),'on').'</a>';
225 221
 	}
Please login to merge, or discard this patch.
dolibarr/htdocs/margin/customerMargins.php 3 patches
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -58,9 +58,9 @@  discard block
 block discarded – undo
58 58
 $startdate=$enddate='';
59 59
 
60 60
 if (!empty($_POST['startdatemonth']))
61
-  $startdate  = dol_mktime(0, 0, 0, $_POST['startdatemonth'],  $_POST['startdateday'],  $_POST['startdateyear']);
61
+    $startdate  = dol_mktime(0, 0, 0, $_POST['startdatemonth'],  $_POST['startdateday'],  $_POST['startdateyear']);
62 62
 if (!empty($_POST['enddatemonth']))
63
-  $enddate  = dol_mktime(23, 59, 59, $_POST['enddatemonth'],  $_POST['enddateday'],  $_POST['enddateyear']);
63
+    $enddate  = dol_mktime(23, 59, 59, $_POST['enddatemonth'],  $_POST['enddateday'],  $_POST['enddateyear']);
64 64
 
65 65
 
66 66
 /*
@@ -92,28 +92,28 @@  discard block
 block discarded – undo
92 92
 $client = false;
93 93
 if ($socid > 0) {
94 94
 
95
-	$soc = new Societe($db);
96
-	$soc->fetch($socid);
97
-
98
-	if ($soc->client)
99
-	{
100
-		print '<tr><td class="titlefield">'.$langs->trans('ThirdPartyName').'</td>';
101
-		print '<td class="maxwidthonsmartphone" colspan="4">';
102
-		print $form->select_company($socid, 'socid', 'client=1 OR client=3', 1, 0, 0);
103
-		//$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$socid,$socid,'socid','client=1 OR client=3',1,0,1);
104
-		print '</td></tr>';
105
-
106
-		$client = true;
107
-		if (! $sortorder) $sortorder="DESC";
108
-		if (! $sortfield) $sortfield="f.datef";
109
-	}
95
+    $soc = new Societe($db);
96
+    $soc->fetch($socid);
97
+
98
+    if ($soc->client)
99
+    {
100
+        print '<tr><td class="titlefield">'.$langs->trans('ThirdPartyName').'</td>';
101
+        print '<td class="maxwidthonsmartphone" colspan="4">';
102
+        print $form->select_company($socid, 'socid', 'client=1 OR client=3', 1, 0, 0);
103
+        //$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$socid,$socid,'socid','client=1 OR client=3',1,0,1);
104
+        print '</td></tr>';
105
+
106
+        $client = true;
107
+        if (! $sortorder) $sortorder="DESC";
108
+        if (! $sortfield) $sortfield="f.datef";
109
+    }
110 110
 }
111 111
 else {
112
-	print '<tr><td class="titlefield">'.$langs->trans('ThirdPartyName').'</td>';
113
-	print '<td class="maxwidthonsmartphone" colspan="4">';
114
-	print $form->select_company(null, 'socid', 'client=1 OR client=3', 1, 0, 0);
115
-	//$form->form_thirdparty($_SERVER['PHP_SELF'],null,'socid','client=1 OR client=3',1,0,1);
116
-	print '</td></tr>';
112
+    print '<tr><td class="titlefield">'.$langs->trans('ThirdPartyName').'</td>';
113
+    print '<td class="maxwidthonsmartphone" colspan="4">';
114
+    print $form->select_company(null, 'socid', 'client=1 OR client=3', 1, 0, 0);
115
+    //$form->form_thirdparty($_SERVER['PHP_SELF'],null,'socid','client=1 OR client=3',1,0,1);
116
+    print '</td></tr>';
117 117
 }
118 118
 
119 119
 $sortfield = GETPOST("sortfield",'alpha');
@@ -121,16 +121,16 @@  discard block
 block discarded – undo
121 121
 if (! $sortorder) $sortorder="ASC";
122 122
 if (! $sortfield)
123 123
 {
124
-	if ($client)
125
-	{
126
-		$sortfield="f.datef";
127
-		$sortorder="DESC";
128
-	}
129
-	else
130
-	{
131
-	    $sortfield="s.nom";
132
-	    $sortorder="ASC";
133
-	}
124
+    if ($client)
125
+    {
126
+        $sortfield="f.datef";
127
+        $sortorder="DESC";
128
+    }
129
+    else
130
+    {
131
+        $sortfield="s.nom";
132
+        $sortorder="ASC";
133
+    }
134 134
 }
135 135
 
136 136
 // Products
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 
139 139
 $TProducts = array();
140 140
 foreach($TRes as $prod) {
141
-	$TProducts[$prod['key']] = $prod['label'];
141
+    $TProducts[$prod['key']] = $prod['label'];
142 142
 }
143 143
 
144 144
 print '<tr><td class="titlefield">'.$langs->trans('ChooseProduct/Service').'</td>';
@@ -182,16 +182,16 @@  discard block
 block discarded – undo
182 182
 
183 183
 // Margin Rate
184 184
 if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
185
-	print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="4">';
186
-	print '<span id="marginRate"></span>'; // set by jquery (see below)
187
-	print '</td></tr>';
185
+    print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="4">';
186
+    print '<span id="marginRate"></span>'; // set by jquery (see below)
187
+    print '</td></tr>';
188 188
 }
189 189
 
190 190
 // Mark Rate
191 191
 if (! empty($conf->global->DISPLAY_MARK_RATES)) {
192
-	print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="4">';
193
-	print '<span id="markRate"></span>'; // set by jquery (see below)
194
-	print '</td></tr>';
192
+    print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="4">';
193
+    print '<span id="markRate"></span>'; // set by jquery (see below)
194
+    print '</td></tr>';
195 195
 }
196 196
 
197 197
 print "</table>";
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 $sql.= ", ".MAIN_DB_PREFIX."facture as f";
212 212
 $sql.= ", ".MAIN_DB_PREFIX."facturedet as d";
213 213
 if(! empty($TSelectedCats)) {
214
-	$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=d.fk_product';
214
+    $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=d.fk_product';
215 215
 }
216 216
 
217 217
 if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
@@ -223,10 +223,10 @@  discard block
 block discarded – undo
223 223
 $sql.= " AND d.fk_facture = f.rowid";
224 224
 $sql.= " AND (d.product_type = 0 OR d.product_type = 1)";
225 225
 if(! empty($TSelectedProducts)) {
226
-	$sql .= ' AND d.fk_product IN ('.implode(',', $TSelectedProducts) . ')';
226
+    $sql .= ' AND d.fk_product IN ('.implode(',', $TSelectedProducts) . ')';
227 227
 }
228 228
 if(! empty($TSelectedCats)) {
229
-	$sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats) . ')';
229
+    $sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats) . ')';
230 230
 }
231 231
 if (!empty($startdate))
232 232
 $sql.= " AND f.datef >= '".$db->idate($startdate)."'";
@@ -245,127 +245,127 @@  discard block
 block discarded – undo
245 245
 $result = $db->query($sql);
246 246
 if ($result)
247 247
 {
248
-	$num = $db->num_rows($result);
249
-
250
-  	print '<br>';
251
-	print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1);
252
-
253
-	if ($conf->global->MARGIN_TYPE == "1")
254
-	    $labelcostprice='BuyingPrice';
255
-	else   // value is 'costprice' or 'pmp'
256
-	    $labelcostprice='CostPrice';
257
-
258
-	$i = 0;
259
-	print "<table class=\"noborder\" width=\"100%\">";
260
-
261
-	print '<tr class="liste_titre">';
262
-	if (! empty($client)) {
263
-  		print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&amp;socid=".$socid,'',$sortfield,$sortorder);
264
-  		print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&amp;socid=".$socid,'align="center"',$sortfield,$sortorder);
265
-	}
266
-	else
267
-  		print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&amp;socid=".$socid,'',$sortfield,$sortorder);
268
-	print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
269
-	print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
270
-	print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
271
-	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
272
-		print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
273
-	if (! empty($conf->global->DISPLAY_MARK_RATES))
274
-		print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
275
-	print "</tr>\n";
276
-
277
-	$cumul_achat = 0;
278
-	$cumul_vente = 0;
279
-
280
-	$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
281
-
282
-	if ($num > 0)
283
-	{
284
-		while ($i < $num /*&& $i < $conf->liste_limit*/)
285
-		{
286
-			$objp = $db->fetch_object($result);
287
-
288
-			$pa = $objp->buying_price;
289
-			$pv = $objp->selling_price;
290
-			$marge = $objp->marge;
291
-
292
-			if ($marge < 0)
293
-			{
294
-				$marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ;
295
-				$markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ;
296
-			}
297
-			else
298
-			{
299
-				$marginRate = ($pa != 0)?(100 * $marge / $pa):'' ;
300
-				$markRate = ($pv != 0)?(100 * $marge / $pv):'' ;
301
-			}
302
-
303
-			print '<tr class="oddeven">';
304
-			if ($client) {
305
-		        print '<td>';
306
-				$invoicestatic->id=$objp->facid;
307
-				$invoicestatic->ref=$objp->ref;
308
-				print $invoicestatic->getNomUrl(1);
309
-				print "</td>\n";
310
-				print "<td align=\"center\">";
311
-				print dol_print_date($db->jdate($objp->datef),'day')."</td>";
312
-		  	}
313
-		  	else {
314
-				$companystatic->id=$objp->socid;
315
-				$companystatic->name=$objp->name;
316
-				$companystatic->client=$objp->client;
317
-		   		print "<td>".$companystatic->getNomUrl(1,'margin')."</td>\n";
318
-		  	}
319
-
320
-			print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n";
321
-			print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n";
322
-			print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n";
323
-			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
324
-				print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
325
-			if (! empty($conf->global->DISPLAY_MARK_RATES))
326
-				print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
327
-			print "</tr>\n";
328
-
329
-			$i++;
330
-			$cumul_achat += $objp->buying_price;
331
-			$cumul_vente += $objp->selling_price;
332
-		}
333
-	}
334
-
335
-	// affichage totaux marges
336
-
337
-	$totalMargin = $cumul_vente - $cumul_achat;
338
-	/*if ($totalMargin < 0)
248
+    $num = $db->num_rows($result);
249
+
250
+        print '<br>';
251
+    print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1);
252
+
253
+    if ($conf->global->MARGIN_TYPE == "1")
254
+        $labelcostprice='BuyingPrice';
255
+    else   // value is 'costprice' or 'pmp'
256
+        $labelcostprice='CostPrice';
257
+
258
+    $i = 0;
259
+    print "<table class=\"noborder\" width=\"100%\">";
260
+
261
+    print '<tr class="liste_titre">';
262
+    if (! empty($client)) {
263
+            print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&amp;socid=".$socid,'',$sortfield,$sortorder);
264
+            print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&amp;socid=".$socid,'align="center"',$sortfield,$sortorder);
265
+    }
266
+    else
267
+            print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&amp;socid=".$socid,'',$sortfield,$sortorder);
268
+    print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
269
+    print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
270
+    print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
271
+    if (! empty($conf->global->DISPLAY_MARGIN_RATES))
272
+        print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
273
+    if (! empty($conf->global->DISPLAY_MARK_RATES))
274
+        print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
275
+    print "</tr>\n";
276
+
277
+    $cumul_achat = 0;
278
+    $cumul_vente = 0;
279
+
280
+    $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
281
+
282
+    if ($num > 0)
283
+    {
284
+        while ($i < $num /*&& $i < $conf->liste_limit*/)
285
+        {
286
+            $objp = $db->fetch_object($result);
287
+
288
+            $pa = $objp->buying_price;
289
+            $pv = $objp->selling_price;
290
+            $marge = $objp->marge;
291
+
292
+            if ($marge < 0)
293
+            {
294
+                $marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ;
295
+                $markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ;
296
+            }
297
+            else
298
+            {
299
+                $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ;
300
+                $markRate = ($pv != 0)?(100 * $marge / $pv):'' ;
301
+            }
302
+
303
+            print '<tr class="oddeven">';
304
+            if ($client) {
305
+                print '<td>';
306
+                $invoicestatic->id=$objp->facid;
307
+                $invoicestatic->ref=$objp->ref;
308
+                print $invoicestatic->getNomUrl(1);
309
+                print "</td>\n";
310
+                print "<td align=\"center\">";
311
+                print dol_print_date($db->jdate($objp->datef),'day')."</td>";
312
+                }
313
+                else {
314
+                $companystatic->id=$objp->socid;
315
+                $companystatic->name=$objp->name;
316
+                $companystatic->client=$objp->client;
317
+                    print "<td>".$companystatic->getNomUrl(1,'margin')."</td>\n";
318
+                }
319
+
320
+            print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n";
321
+            print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n";
322
+            print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n";
323
+            if (! empty($conf->global->DISPLAY_MARGIN_RATES))
324
+                print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
325
+            if (! empty($conf->global->DISPLAY_MARK_RATES))
326
+                print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
327
+            print "</tr>\n";
328
+
329
+            $i++;
330
+            $cumul_achat += $objp->buying_price;
331
+            $cumul_vente += $objp->selling_price;
332
+        }
333
+    }
334
+
335
+    // affichage totaux marges
336
+
337
+    $totalMargin = $cumul_vente - $cumul_achat;
338
+    /*if ($totalMargin < 0)
339 339
 	{
340 340
 		$marginRate = ($cumul_achat != 0)?-1*(100 * $totalMargin / $cumul_achat):'';
341 341
 		$markRate = ($cumul_vente != 0)?-1*(100 * $totalMargin / $cumul_vente):'';
342 342
 	}
343 343
 	else
344 344
 	{*/
345
-		$marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):'';
346
-		$markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):'';
347
-	//}
348
-
349
-	print '<tr class="liste_total">';
350
-	if ($client)
351
-	    print '<td colspan=2>';
352
-  	else
353
-    	print '<td>';
354
-  	print $langs->trans('TotalMargin')."</td>";
355
-	print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n";
356
-	print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n";
357
-	print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n";
358
-	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
359
-		print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
360
-	if (! empty($conf->global->DISPLAY_MARK_RATES))
361
-		print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
362
-	print "</tr>\n";
363
-
364
-  print "</table>";
345
+        $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):'';
346
+        $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):'';
347
+    //}
348
+
349
+    print '<tr class="liste_total">';
350
+    if ($client)
351
+        print '<td colspan=2>';
352
+        else
353
+        print '<td>';
354
+        print $langs->trans('TotalMargin')."</td>";
355
+    print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n";
356
+    print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n";
357
+    print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n";
358
+    if (! empty($conf->global->DISPLAY_MARGIN_RATES))
359
+        print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
360
+    if (! empty($conf->global->DISPLAY_MARK_RATES))
361
+        print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
362
+    print "</tr>\n";
363
+
364
+    print "</table>";
365 365
 }
366 366
 else
367 367
 {
368
-	dol_print_error($db);
368
+    dol_print_error($db);
369 369
 }
370 370
 $db->free($result);
371 371
 
Please login to merge, or discard this patch.
Braces   +84 added lines, -51 removed lines patch added patch discarded remove patch
@@ -36,7 +36,9 @@  discard block
 block discarded – undo
36 36
 $TSelectedProducts = GETPOST('products', 'array');
37 37
 $TSelectedCats = GETPOST('categories', 'array');
38 38
 
39
-if (! empty($user->societe_id)) $socid=$user->societe_id;
39
+if (! empty($user->societe_id)) {
40
+    $socid=$user->societe_id;
41
+}
40 42
 $result = restrictedArea($user, 'societe','','');
41 43
 $result = restrictedArea($user,'margins');
42 44
 
@@ -52,15 +54,22 @@  discard block
 block discarded – undo
52 54
 $offset = $limit * $page;
53 55
 $pageprev = $page - 1;
54 56
 $pagenext = $page + 1;
55
-if (! $sortfield) $sortfield="s.nom"; // Set here default search field
56
-if (! $sortorder) $sortorder="ASC";
57
+if (! $sortfield) {
58
+    $sortfield="s.nom";
59
+}
60
+// Set here default search field
61
+if (! $sortorder) {
62
+    $sortorder="ASC";
63
+}
57 64
 
58 65
 $startdate=$enddate='';
59 66
 
60
-if (!empty($_POST['startdatemonth']))
67
+if (!empty($_POST['startdatemonth'])) {
61 68
   $startdate  = dol_mktime(0, 0, 0, $_POST['startdatemonth'],  $_POST['startdateday'],  $_POST['startdateyear']);
62
-if (!empty($_POST['enddatemonth']))
69
+}
70
+if (!empty($_POST['enddatemonth'])) {
63 71
   $enddate  = dol_mktime(23, 59, 59, $_POST['enddatemonth'],  $_POST['enddateday'],  $_POST['enddateyear']);
72
+}
64 73
 
65 74
 
66 75
 /*
@@ -104,11 +113,14 @@  discard block
 block discarded – undo
104 113
 		print '</td></tr>';
105 114
 
106 115
 		$client = true;
107
-		if (! $sortorder) $sortorder="DESC";
108
-		if (! $sortfield) $sortfield="f.datef";
116
+		if (! $sortorder) {
117
+		    $sortorder="DESC";
118
+		}
119
+		if (! $sortfield) {
120
+		    $sortfield="f.datef";
121
+		}
109 122
 	}
110
-}
111
-else {
123
+} else {
112 124
 	print '<tr><td class="titlefield">'.$langs->trans('ThirdPartyName').'</td>';
113 125
 	print '<td class="maxwidthonsmartphone" colspan="4">';
114 126
 	print $form->select_company(null, 'socid', 'client=1 OR client=3', 1, 0, 0);
@@ -118,15 +130,16 @@  discard block
 block discarded – undo
118 130
 
119 131
 $sortfield = GETPOST("sortfield",'alpha');
120 132
 $sortorder = GETPOST("sortorder",'alpha');
121
-if (! $sortorder) $sortorder="ASC";
133
+if (! $sortorder) {
134
+    $sortorder="ASC";
135
+}
122 136
 if (! $sortfield)
123 137
 {
124 138
 	if ($client)
125 139
 	{
126 140
 		$sortfield="f.datef";
127 141
 		$sortorder="DESC";
128
-	}
129
-	else
142
+	} else
130 143
 	{
131 144
 	    $sortfield="s.nom";
132 145
 	    $sortorder="ASC";
@@ -202,7 +215,9 @@  discard block
 block discarded – undo
202 215
 
203 216
 $sql = "SELECT";
204 217
 $sql.= " s.rowid as socid, s.nom as name, s.code_client, s.client,";
205
-if ($client) $sql.= " f.rowid as facid, f.ref, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,";
218
+if ($client) {
219
+    $sql.= " f.rowid as facid, f.ref, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,";
220
+}
206 221
 $sql.= " sum(d.total_ht) as selling_price,";
207 222
 // Note: qty and buy_price_ht is always positive (if not, your database may be corrupted, you can update this)
208 223
 $sql.= " sum(".$db->ifsql('d.total_ht < 0','d.qty * d.buy_price_ht * -1','d.qty * d.buy_price_ht').") as buying_price,";
@@ -214,10 +229,16 @@  discard block
 block discarded – undo
214 229
 	$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=d.fk_product';
215 230
 }
216 231
 
217
-if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
232
+if (! $user->rights->societe->client->voir && ! $socid) {
233
+    $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
234
+}
218 235
 $sql.= " WHERE f.fk_soc = s.rowid";
219
-if ($socid > 0) $sql.= ' AND s.rowid = '.$socid;
220
-if (!$user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
236
+if ($socid > 0) {
237
+    $sql.= ' AND s.rowid = '.$socid;
238
+}
239
+if (!$user->rights->societe->client->voir && ! $socid) {
240
+    $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
241
+}
221 242
 $sql.= " AND f.fk_statut > 0";
222 243
 $sql.= ' AND s.entity IN ('.getEntity('societe').')';
223 244
 $sql.= " AND d.fk_facture = f.rowid";
@@ -228,15 +249,21 @@  discard block
 block discarded – undo
228 249
 if(! empty($TSelectedCats)) {
229 250
 	$sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats) . ')';
230 251
 }
231
-if (!empty($startdate))
232
-$sql.= " AND f.datef >= '".$db->idate($startdate)."'";
233
-if (!empty($enddate))
234
-$sql.= " AND f.datef <= '".$db->idate($enddate)."'";
252
+if (!empty($startdate)) {
253
+    $sql.= " AND f.datef >= '".$db->idate($startdate)."'";
254
+}
255
+if (!empty($enddate)) {
256
+    $sql.= " AND f.datef <= '".$db->idate($enddate)."'";
257
+}
235 258
 $sql .= " AND d.buy_price_ht IS NOT NULL";
236
-if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)
237
-$sql .= " AND d.buy_price_ht <> 0";
238
-if ($client) $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut";
239
-else $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client";
259
+if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) {
260
+    $sql .= " AND d.buy_price_ht <> 0";
261
+}
262
+if ($client) {
263
+    $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut";
264
+} else {
265
+    $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client";
266
+}
240 267
 $sql.=$db->order($sortfield,$sortorder);
241 268
 // TODO: calculate total to display then restore pagination
242 269
 //$sql.= $db->plimit($conf->liste_limit +1, $offset);
@@ -250,10 +277,12 @@  discard block
 block discarded – undo
250 277
   	print '<br>';
251 278
 	print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1);
252 279
 
253
-	if ($conf->global->MARGIN_TYPE == "1")
254
-	    $labelcostprice='BuyingPrice';
255
-	else   // value is 'costprice' or 'pmp'
280
+	if ($conf->global->MARGIN_TYPE == "1") {
281
+		    $labelcostprice='BuyingPrice';
282
+	} else {
283
+	    // value is 'costprice' or 'pmp'
256 284
 	    $labelcostprice='CostPrice';
285
+	}
257 286
 
258 287
 	$i = 0;
259 288
 	print "<table class=\"noborder\" width=\"100%\">";
@@ -262,16 +291,18 @@  discard block
 block discarded – undo
262 291
 	if (! empty($client)) {
263 292
   		print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&amp;socid=".$socid,'',$sortfield,$sortorder);
264 293
   		print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&amp;socid=".$socid,'align="center"',$sortfield,$sortorder);
294
+	} else {
295
+	  		print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&amp;socid=".$socid,'',$sortfield,$sortorder);
265 296
 	}
266
-	else
267
-  		print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&amp;socid=".$socid,'',$sortfield,$sortorder);
268 297
 	print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
269 298
 	print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
270 299
 	print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
271
-	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
272
-		print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
273
-	if (! empty($conf->global->DISPLAY_MARK_RATES))
274
-		print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
300
+	if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
301
+			print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
302
+	}
303
+	if (! empty($conf->global->DISPLAY_MARK_RATES)) {
304
+			print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
305
+	}
275 306
 	print "</tr>\n";
276 307
 
277 308
 	$cumul_achat = 0;
@@ -293,8 +324,7 @@  discard block
 block discarded – undo
293 324
 			{
294 325
 				$marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ;
295 326
 				$markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ;
296
-			}
297
-			else
327
+			} else
298 328
 			{
299 329
 				$marginRate = ($pa != 0)?(100 * $marge / $pa):'' ;
300 330
 				$markRate = ($pv != 0)?(100 * $marge / $pv):'' ;
@@ -309,8 +339,7 @@  discard block
 block discarded – undo
309 339
 				print "</td>\n";
310 340
 				print "<td align=\"center\">";
311 341
 				print dol_print_date($db->jdate($objp->datef),'day')."</td>";
312
-		  	}
313
-		  	else {
342
+		  	} else {
314 343
 				$companystatic->id=$objp->socid;
315 344
 				$companystatic->name=$objp->name;
316 345
 				$companystatic->client=$objp->client;
@@ -320,10 +349,12 @@  discard block
 block discarded – undo
320 349
 			print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n";
321 350
 			print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n";
322 351
 			print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n";
323
-			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
324
-				print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
325
-			if (! empty($conf->global->DISPLAY_MARK_RATES))
326
-				print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
352
+			if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
353
+							print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
354
+			}
355
+			if (! empty($conf->global->DISPLAY_MARK_RATES)) {
356
+							print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
357
+			}
327 358
 			print "</tr>\n";
328 359
 
329 360
 			$i++;
@@ -347,23 +378,25 @@  discard block
 block discarded – undo
347 378
 	//}
348 379
 
349 380
 	print '<tr class="liste_total">';
350
-	if ($client)
351
-	    print '<td colspan=2>';
352
-  	else
353
-    	print '<td>';
381
+	if ($client) {
382
+		    print '<td colspan=2>';
383
+	} else {
384
+  	    	print '<td>';
385
+  	}
354 386
   	print $langs->trans('TotalMargin')."</td>";
355 387
 	print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n";
356 388
 	print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n";
357 389
 	print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n";
358
-	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
359
-		print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
360
-	if (! empty($conf->global->DISPLAY_MARK_RATES))
361
-		print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
390
+	if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
391
+			print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
392
+	}
393
+	if (! empty($conf->global->DISPLAY_MARK_RATES)) {
394
+			print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
395
+	}
362 396
 	print "</tr>\n";
363 397
 
364 398
   print "</table>";
365
-}
366
-else
399
+} else
367 400
 {
368 401
 	dol_print_error($db);
369 402
 }
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 
26 26
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
27 27
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
28
-require DOL_BASE_PATH . '/main.inc.php';
28
+require DOL_BASE_PATH.'/main.inc.php';
29 29
 
30 30
 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
31 31
 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
@@ -36,35 +36,35 @@  discard block
 block discarded – undo
36 36
 $langs->loadLangs(array('companies', 'bills', 'products', 'margins'));
37 37
 
38 38
 // Security check
39
-$socid = GETPOST('socid','int');
39
+$socid = GETPOST('socid', 'int');
40 40
 $TSelectedProducts = GETPOST('products', 'array');
41 41
 $TSelectedCats = GETPOST('categories', 'array');
42 42
 
43
-if (! empty($user->societe_id)) $socid=$user->societe_id;
44
-$result = restrictedArea($user, 'societe','','');
45
-$result = restrictedArea($user,'margins');
43
+if (!empty($user->societe_id)) $socid = $user->societe_id;
44
+$result = restrictedArea($user, 'societe', '', '');
45
+$result = restrictedArea($user, 'margins');
46 46
 
47 47
 
48 48
 $mesg = '';
49 49
 
50 50
 // Load variable for pagination
51
-$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
52
-$sortfield = GETPOST('sortfield','alpha');
53
-$sortorder = GETPOST('sortorder','alpha');
54
-$page = GETPOST('page','int');
51
+$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
52
+$sortfield = GETPOST('sortfield', 'alpha');
53
+$sortorder = GETPOST('sortorder', 'alpha');
54
+$page = GETPOST('page', 'int');
55 55
 if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
56 56
 $offset = $limit * $page;
57 57
 $pageprev = $page - 1;
58 58
 $pagenext = $page + 1;
59
-if (! $sortfield) $sortfield="s.nom"; // Set here default search field
60
-if (! $sortorder) $sortorder="ASC";
59
+if (!$sortfield) $sortfield = "s.nom"; // Set here default search field
60
+if (!$sortorder) $sortorder = "ASC";
61 61
 
62
-$startdate=$enddate='';
62
+$startdate = $enddate = '';
63 63
 
64 64
 if (!empty($_POST['startdatemonth']))
65
-  $startdate  = dol_mktime(0, 0, 0, $_POST['startdatemonth'],  $_POST['startdateday'],  $_POST['startdateyear']);
65
+  $startdate = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']);
66 66
 if (!empty($_POST['enddatemonth']))
67
-  $enddate  = dol_mktime(23, 59, 59, $_POST['enddatemonth'],  $_POST['enddateday'],  $_POST['enddateyear']);
67
+  $enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']);
68 68
 
69 69
 
70 70
 /*
@@ -72,19 +72,19 @@  discard block
 block discarded – undo
72 72
  */
73 73
 
74 74
 $companystatic = new Societe($db);
75
-$invoicestatic=new Facture($db);
75
+$invoicestatic = new Facture($db);
76 76
 
77 77
 $form = new Form($db);
78 78
 
79
-llxHeader('',$langs->trans("Margins").' - '.$langs->trans("Clients"));
79
+llxHeader('', $langs->trans("Margins").' - '.$langs->trans("Clients"));
80 80
 
81
-$text=$langs->trans("Margins");
81
+$text = $langs->trans("Margins");
82 82
 //print load_fiche_titre($text);
83 83
 
84 84
 // Show tabs
85
-$head=marges_prepare_head($user);
86
-$titre=$langs->trans("Margins");
87
-$picto='margin';
85
+$head = marges_prepare_head($user);
86
+$titre = $langs->trans("Margins");
87
+$picto = 'margin';
88 88
 
89 89
 
90 90
 print '<form method="post" name="sel" action="'.$_SERVER['PHP_SELF'].'">';
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 		print '</td></tr>';
109 109
 
110 110
 		$client = true;
111
-		if (! $sortorder) $sortorder="DESC";
112
-		if (! $sortfield) $sortfield="f.datef";
111
+		if (!$sortorder) $sortorder = "DESC";
112
+		if (!$sortfield) $sortfield = "f.datef";
113 113
 	}
114 114
 }
115 115
 else {
@@ -120,28 +120,28 @@  discard block
 block discarded – undo
120 120
 	print '</td></tr>';
121 121
 }
122 122
 
123
-$sortfield = GETPOST("sortfield",'alpha');
124
-$sortorder = GETPOST("sortorder",'alpha');
125
-if (! $sortorder) $sortorder="ASC";
126
-if (! $sortfield)
123
+$sortfield = GETPOST("sortfield", 'alpha');
124
+$sortorder = GETPOST("sortorder", 'alpha');
125
+if (!$sortorder) $sortorder = "ASC";
126
+if (!$sortfield)
127 127
 {
128 128
 	if ($client)
129 129
 	{
130
-		$sortfield="f.datef";
131
-		$sortorder="DESC";
130
+		$sortfield = "f.datef";
131
+		$sortorder = "DESC";
132 132
 	}
133 133
 	else
134 134
 	{
135
-	    $sortfield="s.nom";
136
-	    $sortorder="ASC";
135
+	    $sortfield = "s.nom";
136
+	    $sortorder = "ASC";
137 137
 	}
138 138
 }
139 139
 
140 140
 // Products
141
-$TRes = $form->select_produits_list('','','',20,0,'',1,2,1,0,'', 1);
141
+$TRes = $form->select_produits_list('', '', '', 20, 0, '', 1, 2, 1, 0, '', 1);
142 142
 
143 143
 $TProducts = array();
144
-foreach($TRes as $prod) {
144
+foreach ($TRes as $prod) {
145 145
 	$TProducts[$prod['key']] = $prod['label'];
146 146
 }
147 147
 
@@ -185,14 +185,14 @@  discard block
 block discarded – undo
185 185
 print '</td></tr>';
186 186
 
187 187
 // Margin Rate
188
-if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
188
+if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
189 189
 	print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="4">';
190 190
 	print '<span id="marginRate"></span>'; // set by jquery (see below)
191 191
 	print '</td></tr>';
192 192
 }
193 193
 
194 194
 // Mark Rate
195
-if (! empty($conf->global->DISPLAY_MARK_RATES)) {
195
+if (!empty($conf->global->DISPLAY_MARK_RATES)) {
196 196
 	print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="4">';
197 197
 	print '<span id="markRate"></span>'; // set by jquery (see below)
198 198
 	print '</td></tr>';
@@ -205,43 +205,43 @@  discard block
 block discarded – undo
205 205
 print '</form>';
206 206
 
207 207
 $sql = "SELECT";
208
-$sql.= " s.rowid as socid, s.nom as name, s.code_client, s.client,";
209
-if ($client) $sql.= " f.rowid as facid, f.ref, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,";
210
-$sql.= " sum(d.total_ht) as selling_price,";
208
+$sql .= " s.rowid as socid, s.nom as name, s.code_client, s.client,";
209
+if ($client) $sql .= " f.rowid as facid, f.ref, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,";
210
+$sql .= " sum(d.total_ht) as selling_price,";
211 211
 // Note: qty and buy_price_ht is always positive (if not, your database may be corrupted, you can update this)
212
-$sql.= " sum(".$db->ifsql('d.total_ht < 0','d.qty * d.buy_price_ht * -1','d.qty * d.buy_price_ht').") as buying_price,";
213
-$sql.= " sum(".$db->ifsql('d.total_ht < 0','-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty))','d.total_ht - (d.buy_price_ht * d.qty)').") as marge";
214
-$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
215
-$sql.= ", ".MAIN_DB_PREFIX."facture as f";
216
-$sql.= ", ".MAIN_DB_PREFIX."facturedet as d";
217
-if(! empty($TSelectedCats)) {
212
+$sql .= " sum(".$db->ifsql('d.total_ht < 0', 'd.qty * d.buy_price_ht * -1', 'd.qty * d.buy_price_ht').") as buying_price,";
213
+$sql .= " sum(".$db->ifsql('d.total_ht < 0', '-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty))', 'd.total_ht - (d.buy_price_ht * d.qty)').") as marge";
214
+$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
215
+$sql .= ", ".MAIN_DB_PREFIX."facture as f";
216
+$sql .= ", ".MAIN_DB_PREFIX."facturedet as d";
217
+if (!empty($TSelectedCats)) {
218 218
 	$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=d.fk_product';
219 219
 }
220 220
 
221
-if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
222
-$sql.= " WHERE f.fk_soc = s.rowid";
223
-if ($socid > 0) $sql.= ' AND s.rowid = '.$socid;
224
-if (!$user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
225
-$sql.= " AND f.fk_statut > 0";
226
-$sql.= ' AND s.entity IN ('.getEntity('societe').')';
227
-$sql.= " AND d.fk_facture = f.rowid";
228
-$sql.= " AND (d.product_type = 0 OR d.product_type = 1)";
229
-if(! empty($TSelectedProducts)) {
230
-	$sql .= ' AND d.fk_product IN ('.implode(',', $TSelectedProducts) . ')';
221
+if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
222
+$sql .= " WHERE f.fk_soc = s.rowid";
223
+if ($socid > 0) $sql .= ' AND s.rowid = '.$socid;
224
+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
225
+$sql .= " AND f.fk_statut > 0";
226
+$sql .= ' AND s.entity IN ('.getEntity('societe').')';
227
+$sql .= " AND d.fk_facture = f.rowid";
228
+$sql .= " AND (d.product_type = 0 OR d.product_type = 1)";
229
+if (!empty($TSelectedProducts)) {
230
+	$sql .= ' AND d.fk_product IN ('.implode(',', $TSelectedProducts).')';
231 231
 }
232
-if(! empty($TSelectedCats)) {
233
-	$sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats) . ')';
232
+if (!empty($TSelectedCats)) {
233
+	$sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats).')';
234 234
 }
235 235
 if (!empty($startdate))
236
-$sql.= " AND f.datef >= '".$db->idate($startdate)."'";
236
+$sql .= " AND f.datef >= '".$db->idate($startdate)."'";
237 237
 if (!empty($enddate))
238
-$sql.= " AND f.datef <= '".$db->idate($enddate)."'";
238
+$sql .= " AND f.datef <= '".$db->idate($enddate)."'";
239 239
 $sql .= " AND d.buy_price_ht IS NOT NULL";
240 240
 if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)
241 241
 $sql .= " AND d.buy_price_ht <> 0";
242
-if ($client) $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut";
243
-else $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client";
244
-$sql.=$db->order($sortfield,$sortorder);
242
+if ($client) $sql .= " GROUP BY s.rowid, s.nom, s.code_client, s.client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut";
243
+else $sql .= " GROUP BY s.rowid, s.nom, s.code_client, s.client";
244
+$sql .= $db->order($sortfield, $sortorder);
245 245
 // TODO: calculate total to display then restore pagination
246 246
 //$sql.= $db->plimit($conf->liste_limit +1, $offset);
247 247
 
@@ -255,33 +255,33 @@  discard block
 block discarded – undo
255 255
 	print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1);
256 256
 
257 257
 	if ($conf->global->MARGIN_TYPE == "1")
258
-	    $labelcostprice='BuyingPrice';
258
+	    $labelcostprice = 'BuyingPrice';
259 259
 	else   // value is 'costprice' or 'pmp'
260
-	    $labelcostprice='CostPrice';
260
+	    $labelcostprice = 'CostPrice';
261 261
 
262 262
 	$i = 0;
263 263
 	print "<table class=\"noborder\" width=\"100%\">";
264 264
 
265 265
 	print '<tr class="liste_titre">';
266
-	if (! empty($client)) {
267
-  		print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&amp;socid=".$socid,'',$sortfield,$sortorder);
268
-  		print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&amp;socid=".$socid,'align="center"',$sortfield,$sortorder);
266
+	if (!empty($client)) {
267
+  		print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "f.ref", "", "&amp;socid=".$socid, '', $sortfield, $sortorder);
268
+  		print_liste_field_titre("DateInvoice", $_SERVER["PHP_SELF"], "f.datef", "", "&amp;socid=".$socid, 'align="center"', $sortfield, $sortorder);
269 269
 	}
270 270
 	else
271
-  		print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&amp;socid=".$socid,'',$sortfield,$sortorder);
272
-	print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
273
-	print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
274
-	print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
275
-	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
276
-		print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
277
-	if (! empty($conf->global->DISPLAY_MARK_RATES))
278
-		print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;socid=".$socid,'align="right"',$sortfield,$sortorder);
271
+  		print_liste_field_titre("Customer", $_SERVER["PHP_SELF"], "s.nom", "", "&amp;socid=".$socid, '', $sortfield, $sortorder);
272
+	print_liste_field_titre("SellingPrice", $_SERVER["PHP_SELF"], "selling_price", "", "&amp;socid=".$socid, 'align="right"', $sortfield, $sortorder);
273
+	print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "buying_price", "", "&amp;socid=".$socid, 'align="right"', $sortfield, $sortorder);
274
+	print_liste_field_titre("Margin", $_SERVER["PHP_SELF"], "marge", "", "&amp;socid=".$socid, 'align="right"', $sortfield, $sortorder);
275
+	if (!empty($conf->global->DISPLAY_MARGIN_RATES))
276
+		print_liste_field_titre("MarginRate", $_SERVER["PHP_SELF"], "", "", "&amp;socid=".$socid, 'align="right"', $sortfield, $sortorder);
277
+	if (!empty($conf->global->DISPLAY_MARK_RATES))
278
+		print_liste_field_titre("MarkRate", $_SERVER["PHP_SELF"], "", "", "&amp;socid=".$socid, 'align="right"', $sortfield, $sortorder);
279 279
 	print "</tr>\n";
280 280
 
281 281
 	$cumul_achat = 0;
282 282
 	$cumul_vente = 0;
283 283
 
284
-	$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
284
+	$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
285 285
 
286 286
 	if ($num > 0)
287 287
 	{
@@ -295,39 +295,39 @@  discard block
 block discarded – undo
295 295
 
296 296
 			if ($marge < 0)
297 297
 			{
298
-				$marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ;
299
-				$markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ;
298
+				$marginRate = ($pa != 0) ?-1 * (100 * $marge / $pa) : '';
299
+				$markRate = ($pv != 0) ?-1 * (100 * $marge / $pv) : '';
300 300
 			}
301 301
 			else
302 302
 			{
303
-				$marginRate = ($pa != 0)?(100 * $marge / $pa):'' ;
304
-				$markRate = ($pv != 0)?(100 * $marge / $pv):'' ;
303
+				$marginRate = ($pa != 0) ? (100 * $marge / $pa) : '';
304
+				$markRate = ($pv != 0) ? (100 * $marge / $pv) : '';
305 305
 			}
306 306
 
307 307
 			print '<tr class="oddeven">';
308 308
 			if ($client) {
309 309
 		        print '<td>';
310
-				$invoicestatic->id=$objp->facid;
311
-				$invoicestatic->ref=$objp->ref;
310
+				$invoicestatic->id = $objp->facid;
311
+				$invoicestatic->ref = $objp->ref;
312 312
 				print $invoicestatic->getNomUrl(1);
313 313
 				print "</td>\n";
314 314
 				print "<td align=\"center\">";
315
-				print dol_print_date($db->jdate($objp->datef),'day')."</td>";
315
+				print dol_print_date($db->jdate($objp->datef), 'day')."</td>";
316 316
 		  	}
317 317
 		  	else {
318
-				$companystatic->id=$objp->socid;
319
-				$companystatic->name=$objp->name;
320
-				$companystatic->client=$objp->client;
321
-		   		print "<td>".$companystatic->getNomUrl(1,'margin')."</td>\n";
318
+				$companystatic->id = $objp->socid;
319
+				$companystatic->name = $objp->name;
320
+				$companystatic->client = $objp->client;
321
+		   		print "<td>".$companystatic->getNomUrl(1, 'margin')."</td>\n";
322 322
 		  	}
323 323
 
324 324
 			print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n";
325 325
 			print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n";
326 326
 			print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n";
327
-			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
328
-				print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
329
-			if (! empty($conf->global->DISPLAY_MARK_RATES))
330
-				print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
327
+			if (!empty($conf->global->DISPLAY_MARGIN_RATES))
328
+				print "<td align=\"right\">".(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
329
+			if (!empty($conf->global->DISPLAY_MARK_RATES))
330
+				print "<td align=\"right\">".(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
331 331
 			print "</tr>\n";
332 332
 
333 333
 			$i++;
@@ -346,8 +346,8 @@  discard block
 block discarded – undo
346 346
 	}
347 347
 	else
348 348
 	{*/
349
-		$marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):'';
350
-		$markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):'';
349
+		$marginRate = ($cumul_achat != 0) ? (100 * $totalMargin / $cumul_achat) : '';
350
+		$markRate = ($cumul_vente != 0) ? (100 * $totalMargin / $cumul_vente) : '';
351 351
 	//}
352 352
 
353 353
 	print '<tr class="liste_total">';
@@ -359,10 +359,10 @@  discard block
 block discarded – undo
359 359
 	print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n";
360 360
 	print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n";
361 361
 	print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n";
362
-	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
363
-		print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
364
-	if (! empty($conf->global->DISPLAY_MARK_RATES))
365
-		print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
362
+	if (!empty($conf->global->DISPLAY_MARGIN_RATES))
363
+		print "<td align=\"right\">".(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
364
+	if (!empty($conf->global->DISPLAY_MARK_RATES))
365
+		print "<td align=\"right\">".(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
366 366
 	print "</tr>\n";
367 367
 
368 368
   print "</table>";
@@ -381,8 +381,8 @@  discard block
 block discarded – undo
381 381
 	});*/
382 382
 
383 383
 	$("#totalMargin").html("'.price($totalMargin, null, null, null, null, $rounding).'");
384
-	$("#marginRate").html("'.(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%").'");
385
-	$("#markRate").html("'.(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%").'");
384
+	$("#marginRate").html("'.(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%").'");
385
+	$("#markRate").html("'.(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%").'");
386 386
 });
387 387
 </script>
388 388
 ';
Please login to merge, or discard this patch.
dolibarr/htdocs/margin/checkMargins.php 3 patches
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -201,115 +201,115 @@
 block discarded – undo
201 201
 $nbtotalofrecords = '';
202 202
 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
203 203
 
204
-	dol_syslog(__FILE__, LOG_DEBUG);
205
-	$result = $db->query($sql);
206
-	$nbtotalofrecords = $db->num_rows($result);
207
-	if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0
208
-	{
209
-		$page = 0;
210
-		$offset = 0;
211
-	}
204
+    dol_syslog(__FILE__, LOG_DEBUG);
205
+    $result = $db->query($sql);
206
+    $nbtotalofrecords = $db->num_rows($result);
207
+    if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0
208
+    {
209
+        $page = 0;
210
+        $offset = 0;
211
+    }
212 212
 }
213 213
 
214 214
 $sql .= $db->plimit($limit+1, $offset);
215 215
 
216 216
 $result = $db->query($sql);
217 217
 if ($result) {
218
-	$num = $db->num_rows($result);
218
+    $num = $db->num_rows($result);
219 219
 
220
-	print '<br>';
221
-	print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit);
220
+    print '<br>';
221
+    print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit);
222 222
 
223
-	if ($conf->global->MARGIN_TYPE == "1")
224
-	    $labelcostprice='BuyingPrice';
225
-	else   // value is 'costprice' or 'pmp'
226
-	    $labelcostprice='CostPrice';
223
+    if ($conf->global->MARGIN_TYPE == "1")
224
+        $labelcostprice='BuyingPrice';
225
+    else   // value is 'costprice' or 'pmp'
226
+        $labelcostprice='CostPrice';
227 227
 
228
-	$moreforfilter='';
228
+    $moreforfilter='';
229 229
 
230
-	$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
231
-	//$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);	// This also change content of $arrayfields
232
-	//if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
233
-	$selectedfields='';
230
+    $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
231
+    //$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);	// This also change content of $arrayfields
232
+    //if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
233
+    $selectedfields='';
234 234
 
235 235
     print '<div class="div-table-responsive">';
236 236
     print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
237 237
 
238
-	print '<tr class="liste_titre liste_titre_search">';
239
-	print '<td><input type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
240
-	print '<td></td>';
241
-	print '<td></td>';
242
-	print '<td></td>';
243
-	print '<td></td>';
244
-	print '<td></td>';
238
+    print '<tr class="liste_titre liste_titre_search">';
239
+    print '<td><input type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
240
+    print '<td></td>';
241
+    print '<td></td>';
242
+    print '<td></td>';
243
+    print '<td></td>';
244
+    print '<td></td>';
245 245
     print '<td class="liste_titre" align="middle">';
246 246
     $searchpitco=$form->showFilterButtons();
247 247
     print $searchpitco;
248 248
     print '</td>';
249
-	print "</tr>\n";
250
-
251
-	print '<tr class="liste_titre">';
252
-	print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
253
-	print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "", "", $param, 'width=20%', $sortfield, $sortorder);
254
-	print_liste_field_titre("UnitPriceHT", $_SERVER["PHP_SELF"], "d.subprice", "", $param, 'align="right"', $sortfield, $sortorder);
255
-	print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "d.buy_price_ht", "", $param, 'align="right"', $sortfield, $sortorder);
256
-	print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", $param, 'align="right"', $sortfield, $sortorder);
257
-	print_liste_field_titre("AmountTTC", $_SERVER["PHP_SELF"], "d.total_ht", "", $param, 'align="right"', $sortfield, $sortorder);
258
-	print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'',$param,'align="center"',$sortfield,$sortorder,'maxwidthsearch ');
259
-	print "</tr>\n";
249
+    print "</tr>\n";
250
+
251
+    print '<tr class="liste_titre">';
252
+    print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
253
+    print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "", "", $param, 'width=20%', $sortfield, $sortorder);
254
+    print_liste_field_titre("UnitPriceHT", $_SERVER["PHP_SELF"], "d.subprice", "", $param, 'align="right"', $sortfield, $sortorder);
255
+    print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "d.buy_price_ht", "", $param, 'align="right"', $sortfield, $sortorder);
256
+    print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", $param, 'align="right"', $sortfield, $sortorder);
257
+    print_liste_field_titre("AmountTTC", $_SERVER["PHP_SELF"], "d.total_ht", "", $param, 'align="right"', $sortfield, $sortorder);
258
+    print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'',$param,'align="center"',$sortfield,$sortorder,'maxwidthsearch ');
259
+    print "</tr>\n";
260 260
 
261 261
     $i=0;
262
-	while ($i < min($num, $limit))
263
-	{
264
-	    $objp = $db->fetch_object($result);
265
-
266
-		print '<tr class="oddeven">';
267
-		print '<td>';
268
-		$result_inner = $invoicestatic->fetch($objp->invoiceid);
269
-		if ($result_inner < 0) {
270
-			setEventMessages($invoicestatic->error, null, 'errors');
271
-		} else {
272
-			print $invoicestatic->getNomUrl(1);
273
-		}
274
-		print '</td>';
275
-		print '<td>';
276
-		if (! empty($objp->fk_product)) {
277
-			$result_inner = $productstatic->fetch($objp->fk_product);
278
-			if ($result_inner < 0) {
279
-				setEventMessages($productstatic->error, null, 'errors');
280
-			} else {
281
-				print $productstatic->getNomUrl(1);
282
-			}
283
-		} else {
284
-			print $objp->label;
285
-			print '&nbsp;';
286
-			print $objp->description;
287
-		}
288
-		print '</td>';
289
-		print '<td align="right">';
290
-		print price($objp->subprice);
291
-		print '</td>';
292
-		print '<td align="right">';
293
-		print '<input type="text" name="buyingprice_' . $objp->invoicedetid . '" id="buyingprice_' . $objp->invoicedetid . '" size="6" value="' . price($objp->buy_price_ht) . '" class="right flat">';
294
-		print '</td>';
295
-		print '<td align="right">';
296
-		print $objp->qty;
297
-		print '</td>';
298
-		print '<td align="right">';
299
-		print price($objp->total_ht);
300
-		print '</td>';
301
-		print '<td></td>';
302
-
303
-		print "</tr>\n";
304
-
305
-		$i ++;
306
-	}
307
-
308
-	print "</table>";
309
-
310
-	print "</div>";
262
+    while ($i < min($num, $limit))
263
+    {
264
+        $objp = $db->fetch_object($result);
265
+
266
+        print '<tr class="oddeven">';
267
+        print '<td>';
268
+        $result_inner = $invoicestatic->fetch($objp->invoiceid);
269
+        if ($result_inner < 0) {
270
+            setEventMessages($invoicestatic->error, null, 'errors');
271
+        } else {
272
+            print $invoicestatic->getNomUrl(1);
273
+        }
274
+        print '</td>';
275
+        print '<td>';
276
+        if (! empty($objp->fk_product)) {
277
+            $result_inner = $productstatic->fetch($objp->fk_product);
278
+            if ($result_inner < 0) {
279
+                setEventMessages($productstatic->error, null, 'errors');
280
+            } else {
281
+                print $productstatic->getNomUrl(1);
282
+            }
283
+        } else {
284
+            print $objp->label;
285
+            print '&nbsp;';
286
+            print $objp->description;
287
+        }
288
+        print '</td>';
289
+        print '<td align="right">';
290
+        print price($objp->subprice);
291
+        print '</td>';
292
+        print '<td align="right">';
293
+        print '<input type="text" name="buyingprice_' . $objp->invoicedetid . '" id="buyingprice_' . $objp->invoicedetid . '" size="6" value="' . price($objp->buy_price_ht) . '" class="right flat">';
294
+        print '</td>';
295
+        print '<td align="right">';
296
+        print $objp->qty;
297
+        print '</td>';
298
+        print '<td align="right">';
299
+        print price($objp->total_ht);
300
+        print '</td>';
301
+        print '<td></td>';
302
+
303
+        print "</tr>\n";
304
+
305
+        $i ++;
306
+    }
307
+
308
+    print "</table>";
309
+
310
+    print "</div>";
311 311
 } else {
312
-	dol_print_error($db);
312
+    dol_print_error($db);
313 313
 }
314 314
 
315 315
 
Please login to merge, or discard this patch.
Braces   +47 added lines, -17 removed lines patch added patch discarded remove patch
@@ -48,8 +48,12 @@  discard block
 block discarded – undo
48 48
 $offset = $limit * $page;
49 49
 $pageprev = $page - 1;
50 50
 $pagenext = $page + 1;
51
-if (! $sortorder) $sortorder = "DESC";
52
-if (! $sortfield) $sortfield = 'f.ref';
51
+if (! $sortorder) {
52
+    $sortorder = "DESC";
53
+}
54
+if (! $sortfield) {
55
+    $sortfield = 'f.ref';
56
+}
53 57
 
54 58
 $startdate = $enddate = '';
55 59
 
@@ -78,7 +82,9 @@  discard block
 block discarded – undo
78 82
 
79 83
 $parameters=array();
80 84
 $reshook=$hookmanager->executeHooks('doActions',$parameters, $object, $action);    // Note that $action and $object may have been modified by some hooks
81
-if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
85
+if ($reshook < 0) {
86
+    setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
87
+}
82 88
 
83 89
 if (empty($reshook))
84 90
 {
@@ -108,9 +114,11 @@  discard block
 block discarded – undo
108 114
     }
109 115
 
110 116
     // Purge search criteria
111
-    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
117
+    if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) {
118
+        // All tests are required to be compatible with all browsers
112 119
     {
113 120
         $search_ref='';
121
+    }
114 122
         $search_array_options=array();
115 123
     }
116 124
 
@@ -146,12 +154,24 @@  discard block
 block discarded – undo
146 154
 // print_fiche_titre($text);
147 155
 
148 156
 $param='';
149
-if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
150
-if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
151
-if ($search_ref != '')   $param.='&search_ref='.urlencode($search_ref);
152
-if (! empty($startdate)) $param .= '&startdatemonth=' . GETPOST('startdatemonth', 'int') . '&startdateday=' . GETPOST('startdateday', 'int') . '&startdateyear=' . GETPOST('startdateyear', 'int');
153
-if (! empty($enddate))   $param .= '&enddatemonth=' . GETPOST('enddatemonth', 'int') . '&enddateday=' . GETPOST('enddateday', 'int') . '&enddateyear=' . GETPOST('enddateyear', 'int');
154
-if ($optioncss != '')    $param.='&optioncss='.$optioncss;
157
+if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
158
+    $param.='&contextpage='.$contextpage;
159
+}
160
+if ($limit > 0 && $limit != $conf->liste_limit) {
161
+    $param.='&limit='.$limit;
162
+}
163
+if ($search_ref != '') {
164
+    $param.='&search_ref='.urlencode($search_ref);
165
+}
166
+if (! empty($startdate)) {
167
+    $param .= '&startdatemonth=' . GETPOST('startdatemonth', 'int') . '&startdateday=' . GETPOST('startdateday', 'int') . '&startdateyear=' . GETPOST('startdateyear', 'int');
168
+}
169
+if (! empty($enddate)) {
170
+    $param .= '&enddatemonth=' . GETPOST('enddatemonth', 'int') . '&enddateday=' . GETPOST('enddateday', 'int') . '&enddateyear=' . GETPOST('enddateyear', 'int');
171
+}
172
+if ($optioncss != '') {
173
+    $param.='&optioncss='.$optioncss;
174
+}
155 175
 
156 176
 // Show tabs
157 177
 $head = marges_prepare_head($user);
@@ -192,9 +212,15 @@  discard block
 block discarded – undo
192 212
 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON d.fk_product = p.rowid";
193 213
 $sql .= " WHERE f.fk_statut > 0";
194 214
 $sql .= " AND f.entity IN (" . getEntity('invoice') . ") ";
195
-if (! empty($startdate)) $sql .= " AND f.datef >= '" . $db->idate($startdate) . "'";
196
-if (! empty($enddate))   $sql .= " AND f.datef <= '" . $db->idate($enddate) . "'";
197
-if ($search_ref) $sql.=natural_search('f.ref', $search_ref);
215
+if (! empty($startdate)) {
216
+    $sql .= " AND f.datef >= '" . $db->idate($startdate) . "'";
217
+}
218
+if (! empty($enddate)) {
219
+    $sql .= " AND f.datef <= '" . $db->idate($enddate) . "'";
220
+}
221
+if ($search_ref) {
222
+    $sql.=natural_search('f.ref', $search_ref);
223
+}
198 224
 $sql .= " AND d.buy_price_ht IS NOT NULL";
199 225
 $sql .= $db->order($sortfield, $sortorder);
200 226
 
@@ -204,9 +230,11 @@  discard block
 block discarded – undo
204 230
 	dol_syslog(__FILE__, LOG_DEBUG);
205 231
 	$result = $db->query($sql);
206 232
 	$nbtotalofrecords = $db->num_rows($result);
207
-	if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0
233
+	if (($page * $limit) > $nbtotalofrecords) {
234
+	    // if total resultset is smaller then paging size (filtering), goto and load page 0
208 235
 	{
209 236
 		$page = 0;
237
+	}
210 238
 		$offset = 0;
211 239
 	}
212 240
 }
@@ -220,10 +248,12 @@  discard block
 block discarded – undo
220 248
 	print '<br>';
221 249
 	print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit);
222 250
 
223
-	if ($conf->global->MARGIN_TYPE == "1")
224
-	    $labelcostprice='BuyingPrice';
225
-	else   // value is 'costprice' or 'pmp'
251
+	if ($conf->global->MARGIN_TYPE == "1") {
252
+		    $labelcostprice='BuyingPrice';
253
+	} else {
254
+	    // value is 'costprice' or 'pmp'
226 255
 	    $labelcostprice='CostPrice';
256
+	}
227 257
 
228 258
 	$moreforfilter='';
229 259
 
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -26,44 +26,44 @@  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
-require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
32
-require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
33
-require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
34
-require_once DOL_DOCUMENT_ROOT . '/margin/lib/margins.lib.php';
31
+require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
32
+require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
33
+require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
34
+require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
35 35
 
36 36
 // Load translation files required by the page
37 37
 $langs->loadLangs(array('companies', 'bills', 'products', 'margins'));
38 38
 
39
-$action     = GETPOST('action','alpha');
40
-$massaction = GETPOST('massaction','alpha');
39
+$action     = GETPOST('action', 'alpha');
40
+$massaction = GETPOST('massaction', 'alpha');
41 41
 $toselect   = GETPOST('toselect', 'array');
42
-$contextpage= GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'margindetail';   // To manage different context of search
43
-$backtopage = GETPOST('backtopage','alpha');
44
-$optioncss  = GETPOST('optioncss','alpha');
42
+$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'margindetail'; // To manage different context of search
43
+$backtopage = GETPOST('backtopage', 'alpha');
44
+$optioncss  = GETPOST('optioncss', 'alpha');
45 45
 
46 46
 // Load variable for pagination
47
-$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
48
-$sortfield = GETPOST('sortfield','alpha');
49
-$sortorder = GETPOST('sortorder','alpha');
50
-$page = GETPOST('page','int');
47
+$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
48
+$sortfield = GETPOST('sortfield', 'alpha');
49
+$sortorder = GETPOST('sortorder', 'alpha');
50
+$page = GETPOST('page', 'int');
51 51
 if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
52 52
 $offset = $limit * $page;
53 53
 $pageprev = $page - 1;
54 54
 $pagenext = $page + 1;
55
-if (! $sortorder) $sortorder = "DESC";
56
-if (! $sortfield) $sortfield = 'f.ref';
55
+if (!$sortorder) $sortorder = "DESC";
56
+if (!$sortfield) $sortfield = 'f.ref';
57 57
 
58 58
 $startdate = $enddate = '';
59 59
 
60 60
 $startdate = dol_mktime(0, 0, 0, GETPOST('startdatemonth', 'int'), GETPOST('startdateday', 'int'), GETPOST('startdateyear', 'int'));
61 61
 $enddate = dol_mktime(23, 59, 59, GETPOST('enddatemonth', 'int'), GETPOST('enddateday', 'int'), GETPOST('enddateyear', 'int'));
62 62
 
63
-$search_ref = GETPOST('search_ref','alpha');
63
+$search_ref = GETPOST('search_ref', 'alpha');
64 64
 
65 65
 // Security check
66
-$result=restrictedArea($user,'margins');
66
+$result = restrictedArea($user, 'margins');
67 67
 
68 68
 // Both test are required to be compatible with all browsers
69 69
 if (GETPOST("button_search_x") || GETPOST("button_search")) {
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
  * Actions
78 78
  */
79 79
 
80
-if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
81
-if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
80
+if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
81
+if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
82 82
 
83
-$parameters=array();
84
-$reshook=$hookmanager->executeHooks('doActions',$parameters, $object, $action);    // Note that $action and $object may have been modified by some hooks
83
+$parameters = array();
84
+$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
85 85
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
86 86
 
87 87
 if (empty($reshook))
@@ -92,15 +92,15 @@  discard block
 block discarded – undo
92 92
     if ($action == 'update') {
93 93
         $datapost = $_POST;
94 94
 
95
-        foreach ( $datapost as $key => $value ) {
95
+        foreach ($datapost as $key => $value) {
96 96
             if (strpos($key, 'buyingprice_') !== false) {
97 97
                 $tmp_array = explode('_', $key);
98 98
                 if (count($tmp_array) > 0) {
99 99
                     $invoicedet_id = $tmp_array[1];
100
-                    if (! empty($invoicedet_id)) {
101
-                        $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facturedet';
102
-                        $sql .= ' SET buy_price_ht=\'' . price2num($value) . '\'';
103
-                        $sql .= ' WHERE rowid=' . $invoicedet_id;
100
+                    if (!empty($invoicedet_id)) {
101
+                        $sql = 'UPDATE '.MAIN_DB_PREFIX.'facturedet';
102
+                        $sql .= ' SET buy_price_ht=\''.price2num($value).'\'';
103
+                        $sql .= ' WHERE rowid='.$invoicedet_id;
104 104
                         $result = $db->query($sql);
105 105
                         if (!$result) {
106 106
                             setEventMessages($db->lasterror, null, 'errors');
@@ -112,10 +112,10 @@  discard block
 block discarded – undo
112 112
     }
113 113
 
114 114
     // Purge search criteria
115
-    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
115
+    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
116 116
     {
117
-        $search_ref='';
118
-        $search_array_options=array();
117
+        $search_ref = '';
118
+        $search_array_options = array();
119 119
     }
120 120
 
121 121
     // Mass actions
@@ -149,34 +149,34 @@  discard block
 block discarded – undo
149 149
 
150 150
 // print_fiche_titre($text);
151 151
 
152
-$param='';
153
-if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
154
-if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
155
-if ($search_ref != '')   $param.='&search_ref='.urlencode($search_ref);
156
-if (! empty($startdate)) $param .= '&startdatemonth=' . GETPOST('startdatemonth', 'int') . '&startdateday=' . GETPOST('startdateday', 'int') . '&startdateyear=' . GETPOST('startdateyear', 'int');
157
-if (! empty($enddate))   $param .= '&enddatemonth=' . GETPOST('enddatemonth', 'int') . '&enddateday=' . GETPOST('enddateday', 'int') . '&enddateyear=' . GETPOST('enddateyear', 'int');
158
-if ($optioncss != '')    $param.='&optioncss='.$optioncss;
152
+$param = '';
153
+if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage;
154
+if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;
155
+if ($search_ref != '')   $param .= '&search_ref='.urlencode($search_ref);
156
+if (!empty($startdate)) $param .= '&startdatemonth='.GETPOST('startdatemonth', 'int').'&startdateday='.GETPOST('startdateday', 'int').'&startdateyear='.GETPOST('startdateyear', 'int');
157
+if (!empty($enddate))   $param .= '&enddatemonth='.GETPOST('enddatemonth', 'int').'&enddateday='.GETPOST('enddateday', 'int').'&enddateyear='.GETPOST('enddateyear', 'int');
158
+if ($optioncss != '')    $param .= '&optioncss='.$optioncss;
159 159
 
160 160
 // Show tabs
161 161
 $head = marges_prepare_head($user);
162 162
 $picto = 'margin';
163 163
 
164
-print '<form method="post" name="sel" action="' . $_SERVER['PHP_SELF'] . '">';
164
+print '<form method="post" name="sel" action="'.$_SERVER['PHP_SELF'].'">';
165 165
 
166 166
 dol_fiche_head($head, $langs->trans('checkMargins'), $title, 0, $picto);
167 167
 
168 168
 print '<table class="border" width="100%">';
169 169
 
170
-print '<tr><td class="titlefield">' . $langs->trans('DateStart') . ' (' . $langs->trans("DateValidation") . ')</td>';
170
+print '<tr><td class="titlefield">'.$langs->trans('DateStart').' ('.$langs->trans("DateValidation").')</td>';
171 171
 print '<td>';
172 172
 print $form->selectDate($startdate, 'startdate', '', '', 1, "sel", 1, 1);
173 173
 print '</td>';
174
-print '<td>' . $langs->trans('DateEnd') . ' (' . $langs->trans("DateValidation") . ')</td>';
174
+print '<td>'.$langs->trans('DateEnd').' ('.$langs->trans("DateValidation").')</td>';
175 175
 print '<td>';
176 176
 print $form->selectDate($enddate, 'enddate', '', '', 1, "sel", 1, 1);
177 177
 print '</td>';
178 178
 print '<td style="text-align: center;">';
179
-print '<input type="submit" class="button" value="' . dol_escape_htmltag($langs->trans('Refresh')) . '" name="button_search" />';
179
+print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans('Refresh')).'" name="button_search" />';
180 180
 print '</td>';
181 181
 print '</tr>';
182 182
 print "</table>";
@@ -184,21 +184,21 @@  discard block
 block discarded – undo
184 184
 dol_fiche_end();
185 185
 
186 186
 
187
-$arrayfields=array();
188
-$massactionbutton='';
187
+$arrayfields = array();
188
+$massactionbutton = '';
189 189
 
190 190
 
191 191
 $sql = "SELECT";
192 192
 $sql .= " f.ref, f.rowid as invoiceid, d.rowid as invoicedetid, d.buy_price_ht, d.total_ht, d.subprice, d.label, d.description , d.qty";
193 193
 $sql .= " ,d.fk_product";
194
-$sql .= " FROM " . MAIN_DB_PREFIX . "facture as f ";
195
-$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facturedet as d  ON d.fk_facture = f.rowid";
196
-$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON d.fk_product = p.rowid";
194
+$sql .= " FROM ".MAIN_DB_PREFIX."facture as f ";
195
+$sql .= " INNER JOIN ".MAIN_DB_PREFIX."facturedet as d  ON d.fk_facture = f.rowid";
196
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON d.fk_product = p.rowid";
197 197
 $sql .= " WHERE f.fk_statut > 0";
198
-$sql .= " AND f.entity IN (" . getEntity('invoice') . ") ";
199
-if (! empty($startdate)) $sql .= " AND f.datef >= '" . $db->idate($startdate) . "'";
200
-if (! empty($enddate))   $sql .= " AND f.datef <= '" . $db->idate($enddate) . "'";
201
-if ($search_ref) $sql.=natural_search('f.ref', $search_ref);
198
+$sql .= " AND f.entity IN (".getEntity('invoice').") ";
199
+if (!empty($startdate)) $sql .= " AND f.datef >= '".$db->idate($startdate)."'";
200
+if (!empty($enddate))   $sql .= " AND f.datef <= '".$db->idate($enddate)."'";
201
+if ($search_ref) $sql .= natural_search('f.ref', $search_ref);
202 202
 $sql .= " AND d.buy_price_ht IS NOT NULL";
203 203
 $sql .= $db->order($sortfield, $sortorder);
204 204
 
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 	}
216 216
 }
217 217
 
218
-$sql .= $db->plimit($limit+1, $offset);
218
+$sql .= $db->plimit($limit + 1, $offset);
219 219
 
220 220
 $result = $db->query($sql);
221 221
 if ($result) {
@@ -225,19 +225,19 @@  discard block
 block discarded – undo
225 225
 	print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit);
226 226
 
227 227
 	if ($conf->global->MARGIN_TYPE == "1")
228
-	    $labelcostprice='BuyingPrice';
228
+	    $labelcostprice = 'BuyingPrice';
229 229
 	else   // value is 'costprice' or 'pmp'
230
-	    $labelcostprice='CostPrice';
230
+	    $labelcostprice = 'CostPrice';
231 231
 
232
-	$moreforfilter='';
232
+	$moreforfilter = '';
233 233
 
234
-	$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
234
+	$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
235 235
 	//$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);	// This also change content of $arrayfields
236 236
 	//if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
237
-	$selectedfields='';
237
+	$selectedfields = '';
238 238
 
239 239
     print '<div class="div-table-responsive">';
240
-    print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
240
+    print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
241 241
 
242 242
 	print '<tr class="liste_titre liste_titre_search">';
243 243
 	print '<td><input type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 	print '<td></td>';
248 248
 	print '<td></td>';
249 249
     print '<td class="liste_titre" align="middle">';
250
-    $searchpitco=$form->showFilterButtons();
250
+    $searchpitco = $form->showFilterButtons();
251 251
     print $searchpitco;
252 252
     print '</td>';
253 253
 	print "</tr>\n";
@@ -259,10 +259,10 @@  discard block
 block discarded – undo
259 259
 	print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "d.buy_price_ht", "", $param, 'align="right"', $sortfield, $sortorder);
260 260
 	print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", $param, 'align="right"', $sortfield, $sortorder);
261 261
 	print_liste_field_titre("AmountTTC", $_SERVER["PHP_SELF"], "d.total_ht", "", $param, 'align="right"', $sortfield, $sortorder);
262
-	print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'',$param,'align="center"',$sortfield,$sortorder,'maxwidthsearch ');
262
+	print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
263 263
 	print "</tr>\n";
264 264
 
265
-    $i=0;
265
+    $i = 0;
266 266
 	while ($i < min($num, $limit))
267 267
 	{
268 268
 	    $objp = $db->fetch_object($result);
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 		}
278 278
 		print '</td>';
279 279
 		print '<td>';
280
-		if (! empty($objp->fk_product)) {
280
+		if (!empty($objp->fk_product)) {
281 281
 			$result_inner = $productstatic->fetch($objp->fk_product);
282 282
 			if ($result_inner < 0) {
283 283
 				setEventMessages($productstatic->error, null, 'errors');
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 		print price($objp->subprice);
295 295
 		print '</td>';
296 296
 		print '<td align="right">';
297
-		print '<input type="text" name="buyingprice_' . $objp->invoicedetid . '" id="buyingprice_' . $objp->invoicedetid . '" size="6" value="' . price($objp->buy_price_ht) . '" class="right flat">';
297
+		print '<input type="text" name="buyingprice_'.$objp->invoicedetid.'" id="buyingprice_'.$objp->invoicedetid.'" size="6" value="'.price($objp->buy_price_ht).'" class="right flat">';
298 298
 		print '</td>';
299 299
 		print '<td align="right">';
300 300
 		print $objp->qty;
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 
307 307
 		print "</tr>\n";
308 308
 
309
-		$i ++;
309
+		$i++;
310 310
 	}
311 311
 
312 312
 	print "</table>";
@@ -317,8 +317,8 @@  discard block
 block discarded – undo
317 317
 }
318 318
 
319 319
 
320
-print '<div class="center">' . "\n";
321
-print '<input type="submit" class="button" name="button_updatemagins" id="button_updatemagins" value="' . $langs->trans("Update") . '">';
320
+print '<div class="center">'."\n";
321
+print '<input type="submit" class="button" name="button_updatemagins" id="button_updatemagins" value="'.$langs->trans("Update").'">';
322 322
 print '</div>';
323 323
 
324 324
 print '</form>';
Please login to merge, or discard this patch.
dolibarr/htdocs/core/actions_setmoduleoptions.inc.php 3 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -29,29 +29,29 @@
 block discarded – undo
29 29
 
30 30
 if ($action == 'update' && is_array($arrayofparameters))
31 31
 {
32
-	$db->begin();
32
+    $db->begin();
33 33
 
34
-	$ok=true;
35
-	foreach($arrayofparameters as $key => $val)
36
-	{
37
-		$result=dolibarr_set_const($db,$key,GETPOST($key, 'alpha'),'chaine',0,'',$conf->entity);
38
-		if ($result < 0)
39
-		{
40
-			$ok=false;
41
-			break;
42
-		}
43
-	}
34
+    $ok=true;
35
+    foreach($arrayofparameters as $key => $val)
36
+    {
37
+        $result=dolibarr_set_const($db,$key,GETPOST($key, 'alpha'),'chaine',0,'',$conf->entity);
38
+        if ($result < 0)
39
+        {
40
+            $ok=false;
41
+            break;
42
+        }
43
+    }
44 44
 
45
-	if (! $error)
46
-	{
47
-		$db->commit();
48
-		if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
49
-	}
50
-	else
51
-	{
52
-		$db->rollback();
53
-		if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
54
-	}
45
+    if (! $error)
46
+    {
47
+        $db->commit();
48
+        if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
49
+    }
50
+    else
51
+    {
52
+        $db->rollback();
53
+        if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
54
+    }
55 55
 }
56 56
 
57 57
 // Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...)
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -31,18 +31,18 @@  discard block
 block discarded – undo
31 31
 {
32 32
 	$db->begin();
33 33
 
34
-	$ok=true;
35
-	foreach($arrayofparameters as $key => $val)
34
+	$ok = true;
35
+	foreach ($arrayofparameters as $key => $val)
36 36
 	{
37
-		$result=dolibarr_set_const($db,$key,GETPOST($key, 'alpha'),'chaine',0,'',$conf->entity);
37
+		$result = dolibarr_set_const($db, $key, GETPOST($key, 'alpha'), 'chaine', 0, '', $conf->entity);
38 38
 		if ($result < 0)
39 39
 		{
40
-			$ok=false;
40
+			$ok = false;
41 41
 			break;
42 42
 		}
43 43
 	}
44 44
 
45
-	if (! $error)
45
+	if (!$error)
46 46
 	{
47 47
 		$db->commit();
48 48
 		if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
@@ -62,38 +62,38 @@  discard block
 block discarded – undo
62 62
     // Process common param fields
63 63
     if (is_array($_POST))
64 64
     {
65
-        foreach($_POST as $key => $val)
65
+        foreach ($_POST as $key => $val)
66 66
         {
67 67
             if (preg_match('/^param(\d*)$/', $key, $reg))    // Works for POST['param'], POST['param1'], POST['param2'], ...
68 68
             {
69
-                $param=GETPOST("param".$reg[1],'alpha');
70
-                $value=GETPOST("value".$reg[1],'alpha');
69
+                $param = GETPOST("param".$reg[1], 'alpha');
70
+                $value = GETPOST("value".$reg[1], 'alpha');
71 71
                 if ($param)
72 72
                 {
73
-                    $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity);
74
-                    if (! $res > 0) $error++;
73
+                    $res = dolibarr_set_const($db, $param, $value, 'chaine', 0, '', $conf->entity);
74
+                    if (!$res > 0) $error++;
75 75
                 }
76 76
             }
77 77
         }
78 78
     }
79 79
 
80 80
     // Process upload fields
81
-    if (GETPOST('upload','alpha') && GETPOST('keyforuploaddir','aZ09'))
81
+    if (GETPOST('upload', 'alpha') && GETPOST('keyforuploaddir', 'aZ09'))
82 82
     {
83 83
         include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
84
-        $keyforuploaddir=GETPOST('keyforuploaddir','aZ09');
85
-        $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->$keyforuploaddir)));
86
-        foreach($listofdir as $key=>$tmpdir)
84
+        $keyforuploaddir = GETPOST('keyforuploaddir', 'aZ09');
85
+        $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->$keyforuploaddir)));
86
+        foreach ($listofdir as $key=>$tmpdir)
87 87
         {
88
-            $tmpdir=trim($tmpdir);
89
-            $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
90
-            if (! $tmpdir) {
88
+            $tmpdir = trim($tmpdir);
89
+            $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
90
+            if (!$tmpdir) {
91 91
                 unset($listofdir[$key]); continue;
92 92
             }
93
-            if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
93
+            if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0);
94 94
             else
95 95
             {
96
-                $upload_dir=$tmpdir;
96
+                $upload_dir = $tmpdir;
97 97
             }
98 98
         }
99 99
         if ($upload_dir)
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
         }
104 104
     }
105 105
 
106
-    if (! $error)
106
+    if (!$error)
107 107
     {
108 108
         $db->commit();
109 109
         if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
Please login to merge, or discard this patch.
Braces   +26 added lines, -13 removed lines patch added patch discarded remove patch
@@ -45,12 +45,15 @@  discard block
 block discarded – undo
45 45
 	if (! $error)
46 46
 	{
47 47
 		$db->commit();
48
-		if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
49
-	}
50
-	else
48
+		if (empty($nomessageinupdate)) {
49
+		    setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
50
+		}
51
+	} else
51 52
 	{
52 53
 		$db->rollback();
53
-		if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
54
+		if (empty($nomessageinupdate)) {
55
+		    setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
56
+		}
54 57
 	}
55 58
 }
56 59
 
@@ -64,14 +67,18 @@  discard block
 block discarded – undo
64 67
     {
65 68
         foreach($_POST as $key => $val)
66 69
         {
67
-            if (preg_match('/^param(\d*)$/', $key, $reg))    // Works for POST['param'], POST['param1'], POST['param2'], ...
70
+            if (preg_match('/^param(\d*)$/', $key, $reg)) {
71
+                // Works for POST['param'], POST['param1'], POST['param2'], ...
68 72
             {
69 73
                 $param=GETPOST("param".$reg[1],'alpha');
74
+            }
70 75
                 $value=GETPOST("value".$reg[1],'alpha');
71 76
                 if ($param)
72 77
                 {
73 78
                     $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity);
74
-                    if (! $res > 0) $error++;
79
+                    if (! $res > 0) {
80
+                        $error++;
81
+                    }
75 82
                 }
76 83
             }
77 84
         }
@@ -90,8 +97,9 @@  discard block
 block discarded – undo
90 97
             if (! $tmpdir) {
91 98
                 unset($listofdir[$key]); continue;
92 99
             }
93
-            if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
94
-            else
100
+            if (! is_dir($tmpdir)) {
101
+                $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
102
+            } else
95 103
             {
96 104
                 $upload_dir=$tmpdir;
97 105
             }
@@ -99,19 +107,24 @@  discard block
 block discarded – undo
99 107
         if ($upload_dir)
100 108
         {
101 109
             $result = dol_add_file_process($upload_dir, 0, 1, 'uploadfile', '');
102
-            if ($result <= 0) $error++;
110
+            if ($result <= 0) {
111
+                $error++;
112
+            }
103 113
         }
104 114
     }
105 115
 
106 116
     if (! $error)
107 117
     {
108 118
         $db->commit();
109
-        if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
110
-    }
111
-    else
119
+        if (empty($nomessageinsetmoduleoptions)) {
120
+            setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
121
+        }
122
+    } else
112 123
     {
113 124
         $db->rollback();
114
-        if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
125
+        if (empty($nomessageinsetmoduleoptions)) {
126
+            setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
127
+        }
115 128
     }
116 129
 }
117 130
 
Please login to merge, or discard this patch.