|
@@ -164,9 +164,8 @@ print "</table>";
|
|
|
print '</form>';
|
|
|
|
|
|
$sql = "SELECT p.label, p.rowid, p.fk_product_type, p.ref,";
|
|
|
-$sql.= " d.fk_product,";
|
|
|
-$sql.= " f.rowid as facid, f.facnumber, f.total as total_ht,";
|
|
|
-$sql.= " f.datef, f.paye, f.fk_statut as statut,";
|
|
|
+if ($id > 0) $sql.= " d.fk_product,";
|
|
|
+if ($id > 0) $sql.= " f.rowid as facid, f.facnumber, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,";
|
|
|
$sql.= " sum(d.total_ht) as selling_price,";
|
|
|
$sql.= " sum(".$db->ifsql('d.total_ht <=0','d.qty * d.buy_price_ht * -1','d.qty * d.buy_price_ht').") as buying_price,";
|
|
|
$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,11 +187,9 @@ if (!empty($enddate))
|
|
|
$sql .= " AND d.buy_price_ht IS NOT NULL";
|
|
|
if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)
|
|
|
$sql .= " AND d.buy_price_ht <> 0";
|
|
|
-if ($id > 0)
|
|
|
- $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, d.fk_product, f.rowid, f.facnumber, f.total, f.datef, f.paye, f.fk_statut";
|
|
|
-else
|
|
|
- $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref";
|
|
|
-$sql.= " ORDER BY ".$sortfield." ".$sortorder;
|
|
|
+if ($id > 0) $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, d.fk_product, f.rowid, f.facnumber, f.total, f.datef, f.paye, f.fk_statut";
|
|
|
+else $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref";
|
|
|
+$sql.=$db->order($sortfield,$sortorder);
|
|
|
// TODO: calculate total to display then restore pagination
|
|
|
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
|
|
|
|