From 4e56ed66e59299bdd3cf9f30f14b8df98dfd9856 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Tue, 21 May 2024 21:26:07 +0300 Subject: [PATCH] fix part 015 --- .../fields/delta_sales7_and_supplier.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/erp24/modul/shipment/fields/delta_sales7_and_supplier.php b/erp24/modul/shipment/fields/delta_sales7_and_supplier.php index 157fd7a..a4e18a2 100644 --- a/erp24/modul/shipment/fields/delta_sales7_and_supplier.php +++ b/erp24/modul/shipment/fields/delta_sales7_and_supplier.php @@ -2,21 +2,21 @@ global $orderId, $data_up; - $data=$db::getRows("SELECT product_id, store_id, + $sql = "SELECT product_id, store_id, sum(CASE WHEN field_name='quantity_zakup_new' THEN value ELSE 0 END) as quantity_zakup_new, sum(CASE WHEN field_name='sales_cnt' THEN value ELSE 0 END) as sales_cnt FROM store_orders_fields_data WHERE field_name in('quantity_zakup_new','sales_cnt') AND value>0 - AND order_id='$orderId' AND color='' AND store_id!='' group by product_id,store_id"); - foreach($data as $row) { - $delta_percent=round(($row["quantity_zakup_new"]/$row["sales_cnt"])*100); - $data_up[$row["product_id"]][$row["store_id"]]["0"] =$delta_percent; - $data_up[$row["product_id"]][0][0] +=$delta_percent; // echo"
".$row["product_id"]." = $z"; - $delta=round($row["quantity_zakup_new"]-$row["sales_cnt"]); - $data_up[$row["product_id"]][$row["store_id"]]["0"] =$delta; - $data_up[$row["product_id"]][0][0] +=$delta; // echo"
".$row["product_id"]." = $z"; + AND order_id='$orderId' AND color='' AND store_id!='' group by product_id,store_id"; - - - } + $data=$db::getRows($sql); + + foreach($data as $row) { + $delta_percent=($row["sales_cnt"] ?? 0) > 0 ? round(($row["quantity_zakup_new"]/$row["sales_cnt"])*100) : 0; + $data_up[$row["product_id"]][$row["store_id"]]["0"] = $delta_percent; + $data_up[$row["product_id"]][0][0] = ($data_up[$row["product_id"]][0][0] ?? 0) + $delta_percent; // echo"
".$row["product_id"]." = $z"; + $delta=round(($row["quantity_zakup_new"] ?? 0) - ($row["sales_cnt"] ?? 0)); + $data_up[$row["product_id"]][$row["store_id"]]["0"] = $delta; + $data_up[$row["product_id"]][0][0] = ($data_up[$row["product_id"]][0][0] ?? 0) + $delta; // echo"
".$row["product_id"]." = $z"; + } insert_store_orders_fields($data_up,"delta_sales7_and_supplier_percent"); -- 2.39.5