From: Alexander Smirnov Date: Thu, 16 May 2024 17:59:59 +0000 (+0300) Subject: fix data calculation among fields X-Git-Tag: 1.1~27^2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=583bce5f762343c9956458fb198722cfb3feb350;p=erp24_rep%2Fyii-erp24%2F.git fix data calculation among fields --- diff --git a/erp24/controllers/ShipmentController.php b/erp24/controllers/ShipmentController.php index 321aaf5e..22abb643 100755 --- a/erp24/controllers/ShipmentController.php +++ b/erp24/controllers/ShipmentController.php @@ -30,4 +30,5 @@ class ShipmentController extends Controller public function actionStoreProductsFactEdit() { return $this->renderPartial('store-products-fact-edit'); } public function actionAjaxField() { return $this->renderPartial('ajax-field'); } public function actionPolnogramm() { return $this->render('polnogramm'); } + public function actionAjaxUpdateStoreZakup() { return $this->renderPartial('ajax-update-store-zakup'); } } \ No newline at end of file diff --git a/erp24/modul/shipment/ajaxUpdateStoreZakup.php b/erp24/modul/shipment/ajaxUpdateStoreZakup.php index b9b54b3b..1ca60e1c 100644 --- a/erp24/modul/shipment/ajaxUpdateStoreZakup.php +++ b/erp24/modul/shipment/ajaxUpdateStoreZakup.php @@ -1,15 +1,19 @@ -"; + foreach ($arrayFiledsUpdate as $key => $Field) { + $f = "modul/shipment/fields/$Field.php"; + if (is_file($f)) { + $data_up = []; -echo""; -foreach($arrayFiledsUpdate as $key => $Field) { - $f="modul/shipment/fields/$Field.php"; - if(is_file($f)) { - $data_up=[]; - - echo""; - - if(!empty($data_up)) { insert_store_orders_fields($data_up,$Field); // вносим данные в таблицу - } - echo" "; - - } else { - - echo""; - } -} -echo"
"; - include_once($f); // получаем данные в массив $data_up - echo"
".$fieldsRows[$Field]["name"]." ".$fieldsRows[$Field]["name_eng"]." посчитано"; - - if(empty($data_up)) echo"пусто"; - echo"
!!нет файла $f
"; + echo ""; + include_once($f); // получаем данные в массив $data_up + echo ""; + if (!empty($data_up)) { + insert_store_orders_fields($data_up, $Field); // вносим данные в таблицу + } + echo " " . $fieldsRows[$Field]["name"] . " " . $fieldsRows[$Field]["name_eng"] . " посчитано"; + + if (empty($data_up)) echo "пусто"; + echo " "; + + } else { + + echo " !!нет файла $f"; + + } + echo ""; + } +} catch (Exception $ex) { + echo $ex->getFile(). ' ' . $ex->getLine() . ' ' . $ex->getMessage(); + die; +} $output = ob_get_contents(); ob_end_clean(); diff --git a/erp24/modul/shipment/fields/color_percent.php b/erp24/modul/shipment/fields/color_percent.php index babf1ada..46c87759 100644 --- a/erp24/modul/shipment/fields/color_percent.php +++ b/erp24/modul/shipment/fields/color_percent.php @@ -1,4 +1,6 @@ -0 AND colors!='' AND id $whereInProductsId group by id order by id"); - +$html = ''; foreach($data4 as $row2) { $colors=explode(";",$row2["colors"]); $productId=$row2["id"]; @@ -31,7 +33,7 @@ AND id $whereInProductsId group by id order by id"); $html .=""; - + foreach($colors as $color) { $color=trim($color); diff --git a/erp24/modul/shipment/fields/division_auto.php b/erp24/modul/shipment/fields/division_auto.php index 3ba94e18..3ddedc4c 100644 --- a/erp24/modul/shipment/fields/division_auto.php +++ b/erp24/modul/shipment/fields/division_auto.php @@ -1,4 +1,7 @@ - $name) { // echo"

$name

"; foreach($orderStoresArrayRelation as $storeId ) { - $division_ratio=$FiledsDataArray["division_ratio"][$productId]; + $division_ratio=$FiledsDataArray["division_ratio"][$productId] ?? 0; if(empty($division_ratio)) $division_ratio=1; - $d=$FiledsDataArray["division_auto_need"][$productId][$storeId] * $division_ratio; + $d=($FiledsDataArray["division_auto_need"][$productId][$storeId] ?? 0) * $division_ratio; $data_up[$productId][$storeId][0]=ceilCoef($d,$min_lot[$productId]); diff --git a/erp24/modul/shipment/fields/division_auto_all.php b/erp24/modul/shipment/fields/division_auto_all.php index 5ebfe85d..1092e485 100644 --- a/erp24/modul/shipment/fields/division_auto_all.php +++ b/erp24/modul/shipment/fields/division_auto_all.php @@ -1,18 +1,18 @@ -0 AND store_id $orderStoresArrayRelation_in - AND order_id='$orderId' AND store_id!='' group by product_id"); - foreach($data as $row) { - - if(empty($row["color"])) { - $data_up[$row["product_id"]][0][0] +=(int)$row["value"]; - } - else { - $data_up[$row["product_id"]][0][$row["color"]] +=(int)$row["value"]; - - } - - - } + AND order_id='$orderId' AND store_id!='' group by product_id, color"; +// var_dump($sql); die; + $data=$db::getRows($sql); + + foreach($data as $row) { + if(empty($row["color"])) { + $data_up[$row["product_id"]][0][0] = ($data_up[$row["product_id"]][0][0] ?? 0) + (int)$row["value"]; + } else { + $data_up[$row["product_id"]][0][$row["color"]] = ($data_up[$row["product_id"]][0][$row["color"]] ?? 0) + (int)$row["value"]; + } + } diff --git a/erp24/modul/shipment/fields/division_auto_need.php b/erp24/modul/shipment/fields/division_auto_need.php index 21e51f3d..3ea04437 100644 --- a/erp24/modul/shipment/fields/division_auto_need.php +++ b/erp24/modul/shipment/fields/division_auto_need.php @@ -1,4 +1,6 @@ -division_auto_need"; @@ -24,8 +26,8 @@ foreach($dataF as $row) { //print_r($FiledsData); $storesArray[0]="Всего"; foreach($products as $product_id => $name) { - $min_order = $FiledsDataArray["min_order"][$product_id][""]; - $min_lot=$FiledsDataArray["min_lot"][$product_id][""]; + $min_order = $FiledsDataArray["min_order"][$product_id][""] ?? 0; + $min_lot=$FiledsDataArray["min_lot"][$product_id][""] ?? 0; echo"
$name
формула = продажи_7_дней + запас_на_2дня + полнограмма - продажи_7дней минимальный заказ $min_order шт., квант (мин. лот деления) = $min_lot "; @@ -35,9 +37,9 @@ foreach($products as $product_id => $name) {
"; foreach($orderStoresArrayRelation as $storeId) { - $sale_7day = $FiledsDataArray["sales_cnt"][$product_id][$storeId]; - $quantity = $FiledsDataArray["quantity"][$product_id][$storeId]; - $quantity_fact =$FiledsDataArray["quantity_fact"][$product_id][$storeId]; + $sale_7day = $FiledsDataArray["sales_cnt"][$product_id][$storeId] ?? 0; + $quantity = $FiledsDataArray["quantity"][$product_id][$storeId] ?? 0; + $quantity_fact =$FiledsDataArray["quantity_fact"][$product_id][$storeId] ?? 0; // считаем запас на 2 дня $sale_2day=ceil(2*($sale_7day/7)); // если факт продаж будет больше чем факт - перприсваеиваем @@ -55,10 +57,10 @@ foreach($products as $product_id => $name) { $data_up[$product_id][$storeId][0] =$zakaz; - $data_up[$product_id][0][0] +=$zakaz; + $data_up[$product_id][0][0] = ($data_up[$product_id][0][0] ?? 0) + $zakaz; // формула = продажи_7_дней + запас_на_2дня + полнограмма - продажи_7дней - echo" + echo"
цветмагазин пол-макол-во по цвету% от полнограммы
магазинпродажи 7 дней запас 2 дня полнограмма потребность
".$storesOrderArray[$storeId]."$sale_7day
".($storesOrderArray[$storeId]??'')."$sale_7day $sale_2day$quantity"; if(!empty($zakaz)) echo"$zakaz"; diff --git a/erp24/modul/shipment/fields/division_auto_need_all.php b/erp24/modul/shipment/fields/division_auto_need_all.php index 57b56b23..cfbb915c 100644 --- a/erp24/modul/shipment/fields/division_auto_need_all.php +++ b/erp24/modul/shipment/fields/division_auto_need_all.php @@ -1,18 +1,17 @@ -0 AND store_id $orderStoresArrayRelation_in - AND order_id='$orderId' AND store_id!='' group by product_id"); - foreach($data as $row) { - - if(empty($row["color"])) { - $data_up[$row["product_id"]][0][0] +=(int)$row["value"]; - } - else { - $data_up[$row["product_id"]][0][$row["color"]] +=(int)$row["value"]; - + AND order_id='$orderId' AND store_id!='' group by product_id, color"; +// var_dump($sql); die; + $data=$db::getRows($sql); + foreach($data as $row) { + if (empty($row["color"])) { + $data_up[$row["product_id"]][0][0] = ($data_up[$row["product_id"]][0][0] ?? 0) + (int)$row["value"]; + } else { + $data_up[$row["product_id"]][0][$row["color"]] = ($data_up[$row["product_id"]][0][$row["color"]] ?? 0) + (int)$row["value"]; } - - - } + } diff --git a/erp24/modul/shipment/fields/division_hand.php b/erp24/modul/shipment/fields/division_hand.php index a6cc0ebb..d9de1371 100644 --- a/erp24/modul/shipment/fields/division_hand.php +++ b/erp24/modul/shipment/fields/division_hand.php @@ -1,4 +1,4 @@ -0 @@ -6,6 +6,6 @@ AND order_id='$orderId' AND store_id!='' group by product_id, store_id,color"); foreach($data as $row) { if(empty($row["color"])) $row["color"]=0; - $data_up[$row["product_id"]][0][$row["color"]] +=(int)$row["value"]; - $data_up[$row["product_id"]][0][0] +=(int)$row["value"]; + $data_up[$row["product_id"]][0][$row["color"]] = ($data_up[$row["product_id"]][0][$row["color"]] ?? 0) + (int)$row["value"]; + $data_up[$row["product_id"]][0][0] = ($data_up[$row["product_id"]][0][0] ?? 0) + (int)$row["value"]; } \ No newline at end of file diff --git a/erp24/modul/shipment/fields/division_price_summ.php b/erp24/modul/shipment/fields/division_price_summ.php index 624115d6..331b2416 100644 --- a/erp24/modul/shipment/fields/division_price_summ.php +++ b/erp24/modul/shipment/fields/division_price_summ.php @@ -1,4 +1,6 @@ - $name) { - foreach($orderStoresArrayRelation as $storeId ) { - $division_summ=$FiledsDataArray["division_summ"][$productId][$storeId]; + foreach($orderStoresArrayRelation ?? [] as $storeId ) { + + $division_summ = $FiledsDataArray["division_summ"][$productId][$storeId] ?? 0; $s=round($prices[$productId] * $division_summ); - $data_up[$productId][0][0] +=$s ; - $data_up[$productId][$storeId][0] =$s ; + $data_up[$productId][0][0] = ($data_up[$productId][0][0] ?? 0) + $s; + $data_up[$productId][$storeId][0] = $s; } - } \ No newline at end of file diff --git a/erp24/modul/shipment/fields/division_ratio.php b/erp24/modul/shipment/fields/division_ratio.php index 95dcb50a..8d59ed6d 100644 --- a/erp24/modul/shipment/fields/division_ratio.php +++ b/erp24/modul/shipment/fields/division_ratio.php @@ -1,4 +1,6 @@ - $quantity_warehouseman_fact) { $division_ratio=round($quantity_warehouseman_fact/$division_auto_need_all,2); $html .="-меньше!"; -$html .=" применяем коэффициент $division_ratio = ".$FiledsDataArray["division_ratio"][$productId][0]." "; +$html .=" применяем коэффициент $division_ratio = ".($FiledsDataArray["division_ratio"][$productId][0] ?? '')." "; } $data_up[$productId][0][0] =$division_ratio; - foreach($productsColorsArray[$productId] as $color) { + foreach($productsColorsArray[$productId] ?? [] as $color) { $color=trim($color); $division_ratio=1; if($FiledsDataArray["division_auto_need_all"][$productId][$color] > $FiledsDataArray["quantity_warehouseman_fact"][$productId][$color]) { diff --git a/erp24/modul/shipment/fields/division_store.php b/erp24/modul/shipment/fields/division_store.php index 2b363bac..d9de0b26 100644 --- a/erp24/modul/shipment/fields/division_store.php +++ b/erp24/modul/shipment/fields/division_store.php @@ -54,9 +54,9 @@ foreach($products as $productId => $name) { foreach($orderStoresArrayRelation as $storeId ) { // $s = $FiledsDataArray["division_store"][$productId][$storeId][0]; - $ceil=$FiledsDataArray["quantity_zakup_new"][$productId][$storeId][0] * $FiledsDataArray["division_store_ratio"][$productId][0][0]; + $ceil = ($FiledsDataArray["quantity_zakup_new"][$productId][$storeId][0] ?? 0) * ($FiledsDataArray["division_store_ratio"][$productId][0][0] ?? 0); //округляем до мини мального лота деления - $ceil=roundCoefficientLot2($ceil,$FiledsDataArray["min_lot"][$productId][0][0]); + $ceil=roundCoefficientLot2($ceil,$FiledsDataArray["min_lot"][$productId][0][0] ?? 0); $data_up[$productId][$storeId][0] =$ceil; @@ -66,7 +66,7 @@ foreach($products as $productId => $name) { $data_up[$productId][0][0] +=$ceil ; // цикл по цвету товара - foreach($productsColorsArray[$productId] as $color) { + foreach($productsColorsArray[$productId] ?? [] as $color) { $color=trim($color); $ceil=$FiledsDataArray["quantity_zakup_new"][$productId][$storeId][$color] * $FiledsDataArray["division_store_ratio"][$productId][0][$color]; diff --git a/erp24/modul/shipment/fields/division_store_ratio.php b/erp24/modul/shipment/fields/division_store_ratio.php index ab736a4a..f2066253 100644 --- a/erp24/modul/shipment/fields/division_store_ratio.php +++ b/erp24/modul/shipment/fields/division_store_ratio.php @@ -1,5 +1,6 @@ -Коэффицент деления division_stpore_ratio"; $FiledsDataArray=[]; @@ -28,7 +29,7 @@ $potreb=[]; //пробегаемся по всем продуктам foreach($products as $productId => $name) { - $potreb_all=$potreb[$productId][0]; + $potreb_all = $potreb[$productId][0] ?? 0; $quantity_warehouseman_fact=$FiledsDataArray["quantity_warehouseman_fact"][$productId][0]; @@ -43,7 +44,7 @@ $html .="коэффициент $division_store_ratio"; $data_up[$productId][0][0] =$division_store_ratio; - foreach($productsColorsArray[$productId] as $color) { + foreach($productsColorsArray[$productId] ?? [] as $color) { $color=trim($color); $division_store_ratio=1; if($potreb[$productId][$color] > $FiledsDataArray["quantity_warehouseman_fact"][$productId][$color]) { diff --git a/erp24/modul/shipment/fields/division_store_summ.php b/erp24/modul/shipment/fields/division_store_summ.php index 8aa1e3e0..ec6dae01 100644 --- a/erp24/modul/shipment/fields/division_store_summ.php +++ b/erp24/modul/shipment/fields/division_store_summ.php @@ -1,4 +1,7 @@ - $name) { // $data_up[$productId][$storeId][0] +=$s ; // $data_up[$productId][0][0] +=$s ; - foreach($productsColorsArray[$productId] as $color) { + foreach($productsColorsArray[$productId] ?? [] as $color) { $color=trim($color); - $s = $FiledsDataArray["division_store"][$productId][$storeId][$color] + $FiledsDataArray["division_store_hand"][$productId][$storeId][$color]; - $data_up[$productId][$storeId][$color] +=$s ; - $data_up[$productId][0][$color] +=$s ; + $s = ($FiledsDataArray["division_store"][$productId][$storeId][$color] ?? 0) + ($FiledsDataArray["division_store_hand"][$productId][$storeId][$color] ?? 0); + $data_up[$productId][$storeId][$color] = ($data_up[$productId][$storeId][$color] ?? 0) + $s; + $data_up[$productId][0][$color] = ($data_up[$productId][0][$color] ?? 0) + $s; @@ -62,9 +65,9 @@ foreach($dataF as $row) { foreach($products as $productId => $name) { // echo"

$name

"; foreach($orderStoresArrayRelation as $storeId ) { - $s = $FiledsDataArray["division_store"][$productId][$storeId][0] + $FiledsDataArray["division_store_hand"][$productId][$storeId][0]; - $data_up[$productId][$storeId][0] +=(int)$s ; - $data_up[$productId][0][0] +=(int)$s ; + $s = ($FiledsDataArray["division_store"][$productId][$storeId][0] ?? 0) + ($FiledsDataArray["division_store_hand"][$productId][$storeId][0] ?? 0); + $data_up[$productId][$storeId][0] = ($data_up[$productId][$storeId][0] ?? 0) + (int)$s; + $data_up[$productId][0][0] = ($data_up[$productId][0][0] ?? 0) + (int)$s; } } diff --git a/erp24/modul/shipment/fields/division_summ.php b/erp24/modul/shipment/fields/division_summ.php index 93d1af10..b3dd2c75 100644 --- a/erp24/modul/shipment/fields/division_summ.php +++ b/erp24/modul/shipment/fields/division_summ.php @@ -1,4 +1,6 @@ - $name) { - $s = $FiledsDataArray["division_auto"][$productId][$storeId] + $FiledsDataArray["division_hand"][$productId][$storeId]; - $data_up[$productId][$storeId][0] +=$s ; - $data_up[$productId][0][0] +=$s ; + $s = ($FiledsDataArray["division_auto"][$productId][$storeId] ?? 0) + ($FiledsDataArray["division_hand"][$productId][$storeId] ?? 0); + $data_up[$productId][$storeId][0] = ($data_up[$productId][$storeId][0] ?? 0) + $s ; + $data_up[$productId][0][0] = ($data_up[$productId][0][0] ?? 0) + $s ; diff --git a/erp24/modul/shipment/fields/division_summ_all.php b/erp24/modul/shipment/fields/division_summ_all.php index 7657af5c..1de15abd 100644 --- a/erp24/modul/shipment/fields/division_summ_all.php +++ b/erp24/modul/shipment/fields/division_summ_all.php @@ -1,11 +1,16 @@ -0 AND store_id $orderStoresArrayRelation_in AND order_id='$orderId' - AND store_id!='' group by product_id"); + AND store_id!='' group by product_id, color"); foreach($data as $row) { - - if(empty($row["color"])) $data_up[$row["product_id"]][0][0] +=(int)$row["value"]; - else $data_up[$row["product_id"]][0][$row["color"]] +=(int)$row["value"]; - } + if (empty($row["color"])) { + $data_up[$row["product_id"]][0][0] = ($data_up[$row["product_id"]][0][0] ?? 0) + (int)$row["value"]; + } else { + $data_up[$row["product_id"]][0][$row["color"]] = ($data_up[$row["product_id"]][0][$row["color"]] ?? 0) + (int)$row["value"]; + } + } diff --git a/erp24/modul/shipment/fields/goods_in_transit.php b/erp24/modul/shipment/fields/goods_in_transit.php index de2dea80..f7ccc564 100644 --- a/erp24/modul/shipment/fields/goods_in_transit.php +++ b/erp24/modul/shipment/fields/goods_in_transit.php @@ -1,8 +1,12 @@ -='$order_date_add' - interval 7 day"); +global $orderId, $order_date_add; + +if(!empty($order_date_add) && $order_date_add!='000-00-00') { +$sql = "SELECT id FROM store_orders +WHERE date_add<='$order_date_add' AND date_add>='$order_date_add' - interval 7 day"; +var_dump($sql); die; +$dataOrders2=$db::getRows($sql); //echo"Товар в пути участвуют заказы:"; $k=0; $w_orders=""; diff --git a/erp24/modul/shipment/fields/order_supplier_sum.php b/erp24/modul/shipment/fields/order_supplier_sum.php index 5bb31fff..d244444f 100644 --- a/erp24/modul/shipment/fields/order_supplier_sum.php +++ b/erp24/modul/shipment/fields/order_supplier_sum.php @@ -1,14 +1,19 @@ -0 AND order_id='$orderId' AND store_id='' AND color='' group by product_id"); + $sql = "SELECT product_id, value FROM store_orders_fields_data WHERE field_name='purchase_price' AND value>0 AND order_id='$orderId' AND store_id='' AND color='' group by product_id, value"; +// var_dump($sql); die; + $data=$db::getRows($sql); foreach($data as $row) $prices[$row["product_id"]]=$row["value"]; - - $data=$db::getRows("SELECT product_id,sum(value) as value, store_id FROM store_orders_fields_data WHERE field_name='quantity_zakup_new' AND value>0 - AND order_id='$orderId' AND color='' AND store_id!='' group by product_id,store_id"); + $sql = "SELECT product_id,sum(value) as value, store_id FROM store_orders_fields_data WHERE field_name='quantity_zakup_new' AND value>0 + AND order_id='$orderId' AND color='' AND store_id!='' group by product_id,store_id"; +// var_dump($sql); die; + $data=$db::getRows($sql); foreach($data as $row) { $s=intval($row["value"] * $prices[$row["product_id"]]); // echo"
".$row["product_id"]." ".$row["value"]." * ".$prices[$row["product_id"]]." = $s "; $data_up[$row["product_id"]][$row["store_id"]][0] =$s; - $data_up[$row["product_id"]][0][0] +=$s; + $data_up[$row["product_id"]][0][0] = ($data_up[$row["product_id"]][0][0] ?? 0) + $s; } diff --git a/erp24/modul/shipment/fields/purchase_summ.php b/erp24/modul/shipment/fields/purchase_summ.php index 51e5c359..e17f955c 100644 --- a/erp24/modul/shipment/fields/purchase_summ.php +++ b/erp24/modul/shipment/fields/purchase_summ.php @@ -1,4 +1,7 @@ -0 AND product_id $whereInProductsId AND store_id $orderStoresArrayRelation_in"); foreach($data2 as $row2) { -$data_up[$row2["product_id"]][$row2["store_id"]][0]+=$row2["quantity"]; -$data_up[$row2["product_id"]][0][0]+=$row2["quantity"]; +$data_up[$row2["product_id"]][$row2["store_id"]][0] = ($data_up[$row2["product_id"]][$row2["store_id"]][0] ?? 0) + $row2["quantity"]; +$data_up[$row2["product_id"]][0][0] = ($data_up[$row2["product_id"]][0][0] ?? 0) + $row2["quantity"]; } \ No newline at end of file diff --git a/erp24/modul/shipment/fields/sales_7day_amount_division.php b/erp24/modul/shipment/fields/sales_7day_amount_division.php index 6ea118b8..e26d4553 100644 --- a/erp24/modul/shipment/fields/sales_7day_amount_division.php +++ b/erp24/modul/shipment/fields/sales_7day_amount_division.php @@ -1,7 +1,10 @@ -$pArray) { -$day_sales=$configGroupProducts[$group]["day_sales"]; +$day_sales=$configGroupProducts[$group]["day_sales"] ?? 0; //echo"
+++

$group дней $day_sales

"; //собираем условие по выборке товаров @@ -10,18 +13,20 @@ $j=0; foreach($pArray as $prodId) {if($j>0) $whereInProductsId_in .=","; $whereInProductsId_in .="'$prodId'"; $j++;} if(!empty($whereInProductsId_in)) { -$data2=$db::getRows("SELECT i.product_id, sum(if(s.operation='Продажа',i.summ,0)) as sale, s.store_id_1c as store_id, sum(if(s.operation='Возврат', i.summ ,0)) as vozvr +$sql = "SELECT i.product_id, sum(CASE WHEN s.operation='Продажа' THEN i.summ ELSE 0 END) as sale, s.store_id_1c as store_id, sum(CASE WHEN s.operation='Возврат' THEN i.summ ELSE 0 END) as vozvr FROM sales as s, sales_products as i WHERE s.id=i.check_id AND i.product_id in($whereInProductsId_in) AND s.store_id_1c $orderStoresArrayRelation_in - AND s.date<='$date_start_division 00:00:00' AND s.date>='$date_start_division' -interval $day_sales day group BY i.product_id, s.store_id, s.operation"); + AND s.date<='$date_start_division 00:00:00' AND s.date>='$date_start_division'::date -interval '$day_sales day' group BY i.product_id, s.store_id, s.operation, s.store_id_1c"; +//var_dump($sql); die; +$data2=$db::getRows($sql); foreach($data2 as $row2) { $sale=$row2["sale"]-$row2["vozvr"]; $sale=(int)$sale; if(!empty($sale)) { $data_up[$row2["product_id"]][$row2["store_id"]][0]=$sale; -$data_up[$row2["product_id"]][0][0] +=$sale; +$data_up[$row2["product_id"]][0][0] = ($data_up[$row2["product_id"]][0][0] ?? 0) + $sale; } } } diff --git a/erp24/modul/shipment/fields/sales_7day_division.php b/erp24/modul/shipment/fields/sales_7day_division.php index bdaa8dc5..3884e7fa 100644 --- a/erp24/modul/shipment/fields/sales_7day_division.php +++ b/erp24/modul/shipment/fields/sales_7day_division.php @@ -1,8 +1,10 @@ -$pArray) { -$day_sales=$configGroupProducts[$group]["day_sales"]; +foreach($productGroupArray as $group =>$pArray) { +$day_sales=$configGroupProducts[$group]["day_sales"] ?? 0; //echo"
+++

$group дней $day_sales

"; //собираем условие по выборке товаров @@ -12,19 +14,19 @@ foreach($pArray as $prodId) {if($j>0) $whereInProductsId_in .=","; $whereIn if(!empty($whereInProductsId_in)) { -$data2=$db::getRows("SELECT i.product_id, s.store_id_1c as store_id, sum(if(s.operation='Продажа',i.quantity,0)) as sale_cnt, -sum(if(s.operation='Возврат',i.quantity,0)) as vozvr_cnt +$data2=$db::getRows("SELECT i.product_id, s.store_id_1c as store_id, sum(CASE WHEN s.operation='Продажа' THEN i.quantity ELSE 0 END) as sale_cnt, +sum(CASE WHEN s.operation='Возврат' THEN i.quantity ELSE 0 END) as vozvr_cnt FROM sales as s, sales_products as i WHERE s.id=i.check_id AND i.product_id in($whereInProductsId_in) AND s.store_id_1c $orderStoresArrayRelation_in AND s.date<='$date_start_division 00:00:00' -AND s.date>='$date_start_division' -interval $day_sales day group BY i.product_id, s.store_id_1c, s.operation "); +AND s.date>='$date_start_division'::date -interval '$day_sales day' group BY i.product_id, s.store_id_1c, s.operation "); 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; + $data_up[$row2["product_id"]][0][0] = ($data_up[$row2["product_id"]][0][0] ?? 0) + $cnt; } } } diff --git a/erp24/modul/shipment/fields/sales_division_4weeks_cnt_avg.php b/erp24/modul/shipment/fields/sales_division_4weeks_cnt_avg.php index 1fbb25ac..30f578cb 100644 --- a/erp24/modul/shipment/fields/sales_division_4weeks_cnt_avg.php +++ b/erp24/modul/shipment/fields/sales_division_4weeks_cnt_avg.php @@ -12,7 +12,7 @@ AND s.date<='$date_start_division 00:00:00' AND s.date>=('$date_start_division': 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; + $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; } } diff --git a/erp24/modul/shipment/fields/scheduled_delivery_cnt.php b/erp24/modul/shipment/fields/scheduled_delivery_cnt.php index fbc22593..18047680 100644 --- a/erp24/modul/shipment/fields/scheduled_delivery_cnt.php +++ b/erp24/modul/shipment/fields/scheduled_delivery_cnt.php @@ -1,8 +1,12 @@ -='$date_start_sale' -interval 27 day */ + $data=$db::getRows("SELECT id FROM store_orders WHERE status=5"); $whereInOrderId=""; $i=0; @@ -14,12 +18,14 @@ foreach($data as $row) { if(!empty($whereInOrderId)) { -$data=$db::getRows("SELECT product_id, store_id, value FROM store_orders_fields_data WHERE +$sql = "SELECT product_id, store_id, value FROM store_orders_fields_data WHERE order_id IN ($whereInOrderId) AND product_id $whereInProductsId -AND field_name='quantity_zakup_new' AND color='' AND value>0 group by product_id, store_id"); +AND field_name='quantity_zakup_new' AND color='' AND value>0 group by product_id, store_id, value"; +//var_dump($sql); die; +$data=$db::getRows($sql); foreach($data as $row) { $data_up[$row["product_id"]][$row["store_id"]]["0"]=$row["value"]; - $data_up[$row["product_id"]][0]["0"] +=$row["value"]; // echo"
".$row["product_id"]." = store_id=".$row["store_id"]." ".$row["value"].""; + $data_up[$row["product_id"]][0]["0"] = ($data_up[$row["product_id"]][0]["0"] ?? 0) + $row["value"]; // echo"
".$row["product_id"]." = store_id=".$row["store_id"]." ".$row["value"].""; } } \ No newline at end of file diff --git a/erp24/modul/shipment/fields/storehouse_balance.php b/erp24/modul/shipment/fields/storehouse_balance.php index 71a76dc6..b4a55a81 100644 --- a/erp24/modul/shipment/fields/storehouse_balance.php +++ b/erp24/modul/shipment/fields/storehouse_balance.php @@ -1,5 +1,6 @@ - $nameProduct) { // echo"
$nameProduct ".$FiledsDataArray["quantity_warehouseman_fact"][$productId][0] ." - ".$FiledsDataArray["division_store_summ"][$productId][0].""; $data_up[$productId][0][0]=$FiledsDataArray["quantity_warehouseman_fact"][$productId][0] - $FiledsDataArray["division_summ"][$productId][0]; - foreach($productsColorsArray[$productId] as $color) { + foreach($productsColorsArray[$productId] ?? [] as $color) { $color=trim($color); $data_up[$productId][0][$color]=$FiledsDataArray["quantity_warehouseman_fact"][$productId][$color] - $FiledsDataArray["division_summ"][$productId][$color]; } diff --git a/erp24/modul/shipment/fields/storehouse_balance_store.php b/erp24/modul/shipment/fields/storehouse_balance_store.php index 843b9221..77b13ffc 100644 --- a/erp24/modul/shipment/fields/storehouse_balance_store.php +++ b/erp24/modul/shipment/fields/storehouse_balance_store.php @@ -38,7 +38,7 @@ foreach($dataF as $row) { //echo"

Storehouse_balance

"; foreach($products as $productId => $nameProduct) { - foreach($productsColorsArray[$productId] as $color) { + foreach($productsColorsArray[$productId] ?? [] as $color) { $color=trim($color); $data_up[$productId][0][$color]=$FiledsDataArray["quantity_warehouseman_fact"][$productId][$color] - $FiledsDataArray["division_store_summ"][$productId][$color]; } diff --git a/erp24/modul/shipment/fields/write_offs_comments.php b/erp24/modul/shipment/fields/write_offs_comments.php index a985429f..27ee3d65 100644 --- a/erp24/modul/shipment/fields/write_offs_comments.php +++ b/erp24/modul/shipment/fields/write_offs_comments.php @@ -1,7 +1,9 @@ -$pArray) { - $periodDaysStats=$configGroupProducts[$group]["day_write_offs"]; +global $productGroupArray, $configGroupProducts, $orderStoresArrayRelation_in, $data_up; + +foreach($productGroupArray as $group =>$pArray) { + $periodDaysStats=$configGroupProducts[$group]["day_write_offs"] ?? 0; //echo"
+++

Списание $group дней $periodDaysStats

"; //собираем условие по выборке товаров $whereInProductsId_in=""; @@ -13,7 +15,7 @@ foreach($productGroupArray as $group =>$pArray) { else $periodDaysStats_where=$periodDaysStats; $date_start_sale2=date("Y-m-d"); - $data2=$db::getRows("SELECT p.product_id,sum(c.quantity) as cnt, w.store_id, c.comment_id + $sql = "SELECT p.product_id,sum(c.quantity) as cnt, w.store_id, c.comment_id FROM write_offs as w, write_offs_products as p, write_offs_comments as c WHERE p.write_offs_id=w.id AND w.type='Брак' @@ -22,11 +24,13 @@ foreach($productGroupArray as $group =>$pArray) { AND p.product_id in($whereInProductsId_in) AND w.store_id $orderStoresArrayRelation_in AND w.date<='$date_start_sale2 00:00:00' - AND w.date>='$date_start_sale2' -interval $periodDaysStats_where day - group BY p.product_id,w.store_id, c.comment_id"); - foreach($data2 as $row2) { + AND w.date>='$date_start_sale2'::date -interval '$periodDaysStats_where day' + group BY p.product_id,w.store_id, c.comment_id"; +// var_dump($sql); die; + $data2=$db::getRows($sql); + foreach($data2 as $row2) { $a=$row2["comment_id"]."=".$row2["cnt"]."шт. "; if(!empty($a)) $data_up[$row2["product_id"]][$row2["store_id"]][0] .=$a; } - } + } } \ No newline at end of file diff --git a/erp24/modul/shipment/fields/write_offs_division.php b/erp24/modul/shipment/fields/write_offs_division.php index 9c743bd9..6ac851e3 100644 --- a/erp24/modul/shipment/fields/write_offs_division.php +++ b/erp24/modul/shipment/fields/write_offs_division.php @@ -1,8 +1,10 @@ -$pArray) { -$periodDaysStats=$configGroupProducts[$group]["day_write_offs"]; +$periodDaysStats=$configGroupProducts[$group]["day_write_offs"] ?? '0'; //echo"
+++

$group дней $periodDaysStats

"; //собираем условие по выборке товаров @@ -11,12 +13,14 @@ $j=0; foreach($pArray as $prodId) {if($j>0) $whereInProductsId_in .=","; $whereInProductsId_in .="'$prodId'"; $j++;} if(!empty($whereInProductsId_in)) { - $data2=$db::getRows("SELECT p.product_id,sum(p.quantity) as cnt, w.store_id + $sql = "SELECT p.product_id,sum(p.quantity) as cnt, w.store_id FROM write_offs as w, write_offs_products as p WHERE p.write_offs_id=w.id AND w.type='Брак' AND p.product_id in($whereInProductsId_in) AND w.store_id $orderStoresArrayRelation_in - AND w.date<='$date_start_division 00:00:00' AND w.date>='$date_start_division' -interval $periodDaysStats day group BY p.product_id,w.store_id"); + AND w.date<='$date_start_division 00:00:00' AND w.date>='$date_start_division'::date -interval '$periodDaysStats day' group BY p.product_id,w.store_id"; +// var_dump($sql); die; +$data2=$db::getRows($sql); $valAll=0; foreach($data2 as $row2) { $a=ceil($row2["cnt"]); diff --git a/erp24/modul/shipment/fields/write_offs_sum.php b/erp24/modul/shipment/fields/write_offs_sum.php index feb806b5..67df15d6 100644 --- a/erp24/modul/shipment/fields/write_offs_sum.php +++ b/erp24/modul/shipment/fields/write_offs_sum.php @@ -1,4 +1,6 @@ -='$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=$row2["summ"]; $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; } } \ No newline at end of file diff --git a/erp24/modul/shipment/functionsShipment.php b/erp24/modul/shipment/functionsShipment.php index 52095026..f2157ff4 100644 --- a/erp24/modul/shipment/functionsShipment.php +++ b/erp24/modul/shipment/functionsShipment.php @@ -22,8 +22,8 @@ $orderStoresArrayRelation, // массив с гуидами магазинов $orderStoresArrayRelation_in // SQL условие для выборки по магазинам IN('store_id') , $productGroupArray // массив с ID подгруппы группы товаров для автозакупки Короткие розы ,$related_order_id -,$date_start_division, -$param +,$date_start_division +//,$param ; @@ -201,7 +201,7 @@ foreach($products as $pid => $pName) { //узнаем категорибю товара $categoryId=$ProductsOptions[$pid]["parent_id"]; // по категории узнаем тип товара горшечка или упаковка -$tip=$products_class[$categoryId]; +$tip=$products_class[$categoryId] ?? ''; // если это срезка у нее нет группы if(empty($tip)) { $daysCounterSales=7; $daysCounterWriteOffs=7; // дней продаж и дней на списание для этой категории @@ -216,7 +216,7 @@ return $productGroupArray; } -//$productGroupArray=getProductGroupArray($products); +$productGroupArray = getProductGroupArray($products); if ($whereInProductsId != " in ()") { @@ -795,7 +795,7 @@ foreach($massivSQL as $productId =>$array) { } catch (Exception $e) { - echo 'Ошибка вставки данных field_name='.$field_name.' '.print_r($param).' error='. $e->getMessage(); + echo 'Ошибка вставки данных field_name='.$field_name.' '.print_r($param ?? '').' error='. $e->getMessage(); } diff --git a/erp24/modul/shipment/shipment.php b/erp24/modul/shipment/shipment.php index f3ddcef1..c330fb4f 100644 --- a/erp24/modul/shipment/shipment.php +++ b/erp24/modul/shipment/shipment.php @@ -294,12 +294,14 @@ $_CONFIG["jscss"] ="