]> gitweb.erp-flowers.ru Git - yii-erp24/.git/commitdiff
fix part 015
authorAlexander Smirnov <fredeom@mail.ru>
Tue, 21 May 2024 18:26:07 +0000 (21:26 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Tue, 21 May 2024 18:26:07 +0000 (21:26 +0300)
erp24/modul/shipment/fields/delta_sales7_and_supplier.php

index 157fd7a8637ce4eb84694d2898f5cd83146029a9..a4e18a24d742664d0c474ea6c7eebd3cee783b34 100644 (file)
@@ -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"<br> ".$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"<br> ".$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"<br> ".$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"<br> ".$row["product_id"]." =  $z";
+    }
 
 insert_store_orders_fields($data_up,"delta_sales7_and_supplier_percent");