From: Alexander Smirnov Date: Fri, 17 May 2024 09:27:47 +0000 (+0300) Subject: fix supplier calculation data X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=7b2e5b8639b1c78b3cd21c6d4e693c77ba537a93;p=yii-erp24%2F.git fix supplier calculation data --- diff --git a/erp24/modul/shipment/fields/delta_sales4week_supplier.php b/erp24/modul/shipment/fields/delta_sales4week_supplier.php index 578007f..213c952 100644 --- a/erp24/modul/shipment/fields/delta_sales4week_supplier.php +++ b/erp24/modul/shipment/fields/delta_sales4week_supplier.php @@ -1,9 +1,11 @@ -0 AND order_id='$orderId' AND color='' AND store_id!='' group by product_id,store_id"); foreach($data as $row) { diff --git a/erp24/modul/shipment/fields/delta_sales7_and_supplier.php b/erp24/modul/shipment/fields/delta_sales7_and_supplier.php index 7412a9b..157fd7a 100644 --- a/erp24/modul/shipment/fields/delta_sales7_and_supplier.php +++ b/erp24/modul/shipment/fields/delta_sales7_and_supplier.php @@ -1,8 +1,10 @@ -0 AND order_id='$orderId' AND color='' AND store_id!='' group by product_id,store_id"); foreach($data as $row) { diff --git a/erp24/modul/shipment/fields/entrance_cnt_7days.php b/erp24/modul/shipment/fields/entrance_cnt_7days.php index 87781ab..fb9b659 100644 --- a/erp24/modul/shipment/fields/entrance_cnt_7days.php +++ b/erp24/modul/shipment/fields/entrance_cnt_7days.php @@ -1,16 +1,22 @@ - Получено за 7 дней entrance_cnt_7day*/ -$data=$db::getRows("SELECT id FROM store_orders WHERE status>=6 AND date_start <='$date_start_sale' AND date_start>='$date_start_sale' -interval 7 day"); -$whereInOrderId=""; $i=0; -foreach($data as $row) { - $whereInOrderId .=" '".$row["id"]."' "; - if($i<(count($data)-1)) $whereInOrderId .=" , "; - $i++; +if (!empty($date_start_sale)) { + $sql = "SELECT id FROM store_orders WHERE status>=6 AND date_start <='$date_start_sale' AND date_start>='$date_start_sale'::date -interval '7 day'"; + $data = $db::getRows($sql); + $whereInOrderId = ""; + $i = 0; + foreach ($data as $row) { + $whereInOrderId .= " '" . $row["id"] . "' "; + if ($i < (count($data) - 1)) $whereInOrderId .= " , "; + $i++; + } } diff --git a/erp24/modul/shipment/fields/sales_4weeks_cnt.php b/erp24/modul/shipment/fields/sales_4weeks_cnt.php index fe58a81..c42895e 100644 --- a/erp24/modul/shipment/fields/sales_4weeks_cnt.php +++ b/erp24/modul/shipment/fields/sales_4weeks_cnt.php @@ -1,20 +1,23 @@ -='$date_start_sale' -interval $day_sales day group BY i.product_id, s.store_id_1c "); - foreach($data2 as $row2) { - $cnt=round(($row2["sale_cnt"]-$row2["vozvr_cnt"])/4); - if(!empty($cnt)) { - $data_up[$row2["product_id"]][$row2["store_id"]][0] +=$cnt; - $data_up[$row2["product_id"]][0][0] +=$cnt; - - // echo"
".$products[$row2["product_id"]]." ".$row2["store_id"]." =$cnt "; - } - } - +AND s.date<='$date_start_sale 00:00:00' AND s.date>='$date_start_sale'::date -interval '$day_sales day' group BY i.product_id, s.store_id_1c "); + foreach ($data2 as $row2) { + $cnt = round(($row2["sale_cnt"] - $row2["vozvr_cnt"]) / 4); + if (!empty($cnt)) { + $data_up[$row2["product_id"]][$row2["store_id"]][0] = ($data_up[$row2["product_id"]][$row2["store_id"]][0] ?? 0) + $cnt; + $data_up[$row2["product_id"]][0][0] = ($data_up[$row2["product_id"]][0][0] ?? 0) + $cnt; + // echo"
".$products[$row2["product_id"]]." ".$row2["store_id"]." =$cnt "; + } + } +} \ No newline at end of file diff --git a/erp24/modul/shipment/fields/sales_amount.php b/erp24/modul/shipment/fields/sales_amount.php index 049c660..95d1e17 100644 --- a/erp24/modul/shipment/fields/sales_amount.php +++ b/erp24/modul/shipment/fields/sales_amount.php @@ -1,4 +1,6 @@ -$pArray) { @@ -16,23 +18,23 @@ $day_sales=$configGroupProducts[$group]["day_sales"]; // массив групп } } - -$data2=$db::getRows("SELECT i.product_id, s.store_id_1c as store_id,sum(if(s.operation='Продажа',i.summ,0)) as sale_cnt, sum(if(s.operation='Возврат',i.summ,0)) as vozvr_cnt +if (!empty($date_start_sale)) { + $data2 = $db::getRows("SELECT i.product_id, s.store_id_1c as store_id,sum(CASE WHEN s.operation='Продажа' THEN i.summ ELSE 0 END) as sale_cnt, sum(CASE WHEN s.operation='Возврат' THEN i.summ ELSE 0 END) as vozvr_cnt FROM sales as s, sales_products as i WHERE s.id=i.check_id AND i.product_id $whereInProductsId AND s.store_id_1c $orderStoresArrayRelation_in -AND s.date<='$date_start_sale 00:00:00' AND s.date>='$date_start_sale' -interval 7 day group BY i.product_id, s.store_id_1c "); - foreach($data2 as $row2) { - $cnt=$row2["sale_cnt"]-$row2["vozvr_cnt"]; - $cnt=(int)$cnt; - if(!empty($cnt)) { - $data_up[$row2["product_id"]][$row2["store_id"]][0] +=$cnt; - $data_up[$row2["product_id"]][0][0] +=$cnt; - - // echo"
sales_amount ".$products[$row2["product_id"]]." ".$row2["store_id"]." $cnt "; - } - } - +AND s.date<='$date_start_sale 00:00:00' AND s.date>='$date_start_sale'::date -interval '7 day' group BY i.product_id, s.store_id_1c "); + foreach ($data2 as $row2) { + $cnt = $row2["sale_cnt"] - $row2["vozvr_cnt"]; + $cnt = (int)$cnt; + if (!empty($cnt)) { + $data_up[$row2["product_id"]][$row2["store_id"]][0] = ($data_up[$row2["product_id"]][$row2["store_id"]][0] ?? 0) + $cnt; + $data_up[$row2["product_id"]][0][0] = ($data_up[$row2["product_id"]][0][0] ?? 0) + $cnt; + + // echo"
sales_amount ".$products[$row2["product_id"]]." ".$row2["store_id"]." $cnt "; + } + } +} \ No newline at end of file diff --git a/erp24/modul/shipment/fields/sales_cnt.php b/erp24/modul/shipment/fields/sales_cnt.php index f3edda1..0edbca3 100644 --- a/erp24/modul/shipment/fields/sales_cnt.php +++ b/erp24/modul/shipment/fields/sales_cnt.php @@ -1,17 +1,23 @@ -='$date_start_sale' -interval $day_sales day group BY i.product_id, s.store_id_1c "); - foreach($data2 as $row2) { - $cnt=$row2["sale_cnt"]-$row2["vozvr_cnt"]; - $cnt=(int)$cnt; - if(!empty($cnt)) { - $data_up[$row2["product_id"]][$row2["store_id"]][0] +=$cnt; - $data_up[$row2["product_id"]][0][0] +=$cnt; - } - } +AND s.date<='$date_start_sale 00:00:00' AND s.date>='$date_start_sale'::date -interval '$day_sales day' group BY i.product_id, s.store_id_1c "; + $data2 = $db::getRows($sql); + foreach ($data2 as $row2) { + $cnt = $row2["sale_cnt"] - $row2["vozvr_cnt"]; + $cnt = (int)$cnt; + if (!empty($cnt)) { + $data_up[$row2["product_id"]][$row2["store_id"]][0] = ($data_up[$row2["product_id"]][$row2["store_id"]][0] ?? 0) + $cnt; + $data_up[$row2["product_id"]][0][0] = ($data_up[$row2["product_id"]][0][0] ?? 0) + $cnt; + } + } +} \ No newline at end of file diff --git a/erp24/modul/shipment/fields/write_downs.php b/erp24/modul/shipment/fields/write_downs.php index e8f9ac2..d27dfd5 100644 --- a/erp24/modul/shipment/fields/write_downs.php +++ b/erp24/modul/shipment/fields/write_downs.php @@ -1,19 +1,21 @@ -='$date_start_sale' -interval $periodDaysStats day group BY p.product_id,w.store_id"); +AND w.date<='$date_start_sale 00:00:00' AND w.date>='$date_start_sale'::date -interval '$periodDaysStats day' group BY p.product_id,w.store_id"); foreach($data2 as $row2) { $a=round($row2["cnt"]); if(!empty($a)) { - $data_up[$row2["product_id"]][$row2["store_id"]][0] +=$a; - $data_up[$row2["product_id"]][0][0] +=$a; + $data_up[$row2["product_id"]][$row2["store_id"]][0] = ($data_up[$row2["product_id"]][$row2["store_id"]][0] ?? 0) + $a; + $data_up[$row2["product_id"]][0][0] = ($data_up[$row2["product_id"]][0][0] ?? 0) + $a; } } } \ No newline at end of file diff --git a/erp24/modul/shipment/fields/write_offs_4week_cnt_avg.php b/erp24/modul/shipment/fields/write_offs_4week_cnt_avg.php index f53647e..8f4d18f 100644 --- a/erp24/modul/shipment/fields/write_offs_4week_cnt_avg.php +++ b/erp24/modul/shipment/fields/write_offs_4week_cnt_avg.php @@ -1,8 +1,10 @@ -='$date_start_sale' -interval $periodDaysStats day group BY p.product_id,w.store_id"); +AND w.date>='$date_start_sale'::date -interval '$periodDaysStats day' group BY p.product_id,w.store_id"); foreach($data2 as $row2) { $a=round($row2["cnt"]/4); if(!empty($a)) { $data_up[$row2["product_id"]][$row2["store_id"]][0]=$a; - $data_up[$row2["product_id"]][0][0] +=$a; + $data_up[$row2["product_id"]][0][0] = ($data_up[$row2["product_id"]][0][0] ?? 0) + $a; } } diff --git a/erp24/modul/shipment/fields/write_offs_4week_sum.php b/erp24/modul/shipment/fields/write_offs_4week_sum.php index 2f64f96..d799f08 100644 --- a/erp24/modul/shipment/fields/write_offs_4week_sum.php +++ b/erp24/modul/shipment/fields/write_offs_4week_sum.php @@ -1,14 +1,17 @@ -='$date_start_sale' -interval $periodDaysStats day group BY p.product_id,w.store_id"); +AND w.date>='$date_start_sale'::date -interval '$periodDaysStats day' group BY p.product_id,w.store_id"); foreach($data2 as $row2) { $a=round ($row2["summ"]/4) ; if(!empty($a)) {