]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
replace pdo with ar in shipment/division, fields
authorAlexander Smirnov <fredeom@mail.ru>
Mon, 5 Feb 2024 14:56:11 +0000 (17:56 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Mon, 5 Feb 2024 14:56:11 +0000 (17:56 +0300)
erp24/records/StoreOrdersColors.php [new file with mode: 0644]
erp24/records/StoreOrdersFieldsDataLogi.php [new file with mode: 0644]
erp24/records/StoreOrdersItem.php [new file with mode: 0644]
erp24/records/StoreOrdersPrices.php [new file with mode: 0644]
erp24/views/shipment/ajax-edit-field-value.php
erp24/views/shipment/division.php
erp24/views/shipment/fields.php

diff --git a/erp24/records/StoreOrdersColors.php b/erp24/records/StoreOrdersColors.php
new file mode 100644 (file)
index 0000000..9a27808
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "store_orders_colors".
+ *
+ * @property string $product_id
+ * @property int $order_id
+ * @property string $store_id
+ * @property int $field_id
+ * @property string $color
+ * @property int $provider_id ID поставщика
+ * @property int $quantity
+ * @property string $date
+ */
+class StoreOrdersColors extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'store_orders_colors';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['product_id', 'order_id', 'store_id', 'field_id', 'color', 'provider_id', 'quantity', 'date'], 'required'],
+            [['order_id', 'field_id', 'provider_id', 'quantity'], 'integer'],
+            [['date'], 'safe'],
+            [['product_id', 'store_id'], 'string', 'max' => 36],
+            [['color'], 'string', 'max' => 45],
+            [['product_id', 'order_id', 'store_id', 'field_id', 'color', 'provider_id'], 'unique', 'targetAttribute' => ['product_id', 'order_id', 'store_id', 'field_id', 'color', 'provider_id']],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'product_id' => 'Product ID',
+            'order_id' => 'Order ID',
+            'store_id' => 'Store ID',
+            'field_id' => 'Field ID',
+            'color' => 'Color',
+            'provider_id' => 'Provider ID',
+            'quantity' => 'Quantity',
+            'date' => 'Date',
+        ];
+    }
+}
diff --git a/erp24/records/StoreOrdersFieldsDataLogi.php b/erp24/records/StoreOrdersFieldsDataLogi.php
new file mode 100644 (file)
index 0000000..2e91c9e
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "store_orders_fields_data_logi".
+ *
+ * @property int $id
+ * @property int $order_id
+ * @property int $field_id
+ * @property string $product_id
+ * @property string $store_id
+ * @property string $color
+ * @property string $value
+ * @property string $value_old
+ * @property string $date_add
+ * @property int $admin_id 12
+ */
+class StoreOrdersFieldsDataLogi extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'store_orders_fields_data_logi';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['order_id', 'field_id', 'product_id', 'store_id', 'color', 'value', 'value_old', 'date_add', 'admin_id'], 'required'],
+            [['order_id', 'field_id', 'admin_id'], 'integer'],
+            [['date_add'], 'safe'],
+            [['product_id', 'store_id'], 'string', 'max' => 36],
+            [['color', 'value_old'], 'string', 'max' => 120],
+            [['value'], 'string', 'max' => 255],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'order_id' => 'Order ID',
+            'field_id' => 'Field ID',
+            'product_id' => 'Product ID',
+            'store_id' => 'Store ID',
+            'color' => 'Color',
+            'value' => 'Value',
+            'value_old' => 'Value Old',
+            'date_add' => 'Date Add',
+            'admin_id' => 'Admin ID',
+        ];
+    }
+}
diff --git a/erp24/records/StoreOrdersItem.php b/erp24/records/StoreOrdersItem.php
new file mode 100644 (file)
index 0000000..d4c9cfa
--- /dev/null
@@ -0,0 +1,90 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "store_orders_item".
+ *
+ * @property string $product_id
+ * @property string $store_id
+ * @property int $order_id
+ * @property int $provider_id
+ * @property string $colors_json JSON массив с характеристиками по цветам
+ * @property int $quantity
+ * @property int $quantity_purchase Ко-во заказанное кустовым
+ * @property int $quantity_fact Количество фактическое
+ * @property int $quantity_storage Количество на складе
+ * @property int $admin_id ID сотрудника
+ * @property string $date дата внесения
+ * @property int $status 1 - создал и отправил
+ * @property int $status_zakup Статус закупщика
+ * @property int $sales_cnt Продажи в штуках
+ * @property int $sales_amount Продажи в рублях
+ * @property int $write_downs Спиание в штуках
+ * @property int $goods_in_transit Товар в пути
+ * @property float $sales_day Остаток в количестве дней продаж
+ * @property int $division_auto Авто деление по формуле
+ * @property int $division_hand Ручная добавка по делению кустовыми
+ * @property int $division_fact факт ледение кустовыми
+ * @property int $division_quantity Кол-во итого распредления
+ */
+class StoreOrdersItem extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'store_orders_item';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['product_id', 'store_id', 'order_id', 'provider_id', 'colors_json', 'quantity', 'quantity_purchase', 'quantity_fact', 'quantity_storage', 'admin_id', 'date', 'sales_cnt', 'sales_amount', 'write_downs', 'goods_in_transit', 'sales_day', 'division_auto', 'division_hand', 'division_fact', 'division_quantity'], 'required'],
+            [['order_id', 'provider_id', 'quantity', 'quantity_purchase', 'quantity_fact', 'quantity_storage', 'admin_id', 'status', 'status_zakup', 'sales_cnt', 'sales_amount', 'write_downs', 'goods_in_transit', 'division_auto', 'division_hand', 'division_fact', 'division_quantity'], 'integer'],
+            [['colors_json'], 'string'],
+            [['date'], 'safe'],
+            [['sales_day'], 'number'],
+            [['product_id', 'store_id'], 'string', 'max' => 36],
+            [['product_id', 'store_id', 'order_id'], 'unique', 'targetAttribute' => ['product_id', 'store_id', 'order_id']],
+            [['product_id', 'store_id', 'order_id', 'provider_id'], 'unique', 'targetAttribute' => ['product_id', 'store_id', 'order_id', 'provider_id']],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'product_id' => 'Product ID',
+            'store_id' => 'Store ID',
+            'order_id' => 'Order ID',
+            'provider_id' => 'Provider ID',
+            'colors_json' => 'Colors Json',
+            'quantity' => 'Quantity',
+            'quantity_purchase' => 'Quantity Purchase',
+            'quantity_fact' => 'Quantity Fact',
+            'quantity_storage' => 'Quantity Storage',
+            'admin_id' => 'Admin ID',
+            'date' => 'Date',
+            'status' => 'Status',
+            'status_zakup' => 'Status Zakup',
+            'sales_cnt' => 'Sales Cnt',
+            'sales_amount' => 'Sales Amount',
+            'write_downs' => 'Write Downs',
+            'goods_in_transit' => 'Goods In Transit',
+            'sales_day' => 'Sales Day',
+            'division_auto' => 'Division Auto',
+            'division_hand' => 'Division Hand',
+            'division_fact' => 'Division Fact',
+            'division_quantity' => 'Division Quantity',
+        ];
+    }
+}
diff --git a/erp24/records/StoreOrdersPrices.php b/erp24/records/StoreOrdersPrices.php
new file mode 100644 (file)
index 0000000..9e8f216
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "store_orders_prices".
+ *
+ * @property string $product_id
+ * @property int $order_id
+ * @property int $provider_id
+ * @property float $purchase_price
+ * @property float $purchase_summ
+ * @property float $purchase_price_zakup
+ * @property float $price_zakup_summ
+ * @property int $quantity_purchase_summ заказ о кустовых
+ * @property int $quantity_zakup
+ * @property int $quantity_zakup_fact
+ * @property string $comment_zakup
+ * @property string $comment_discrepancy_polnogramm Комментарий по расхождению полнограмм
+ * @property int $quantity_warehouseman_fact
+ * @property int $quantity_rejection
+ * @property int $quantity_zakup_info куплено по факту
+ * @property float $cost_price себестоимость
+ * @property int $additional_quantity Дозакупка в шт.
+ */
+class StoreOrdersPrices extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'store_orders_prices';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['product_id', 'order_id', 'purchase_price', 'purchase_summ', 'purchase_price_zakup', 'price_zakup_summ', 'quantity_purchase_summ', 'quantity_zakup', 'quantity_zakup_fact', 'comment_zakup', 'comment_discrepancy_polnogramm', 'quantity_warehouseman_fact', 'quantity_rejection', 'quantity_zakup_info', 'cost_price', 'additional_quantity'], 'required'],
+            [['order_id', 'provider_id', 'quantity_purchase_summ', 'quantity_zakup', 'quantity_zakup_fact', 'quantity_warehouseman_fact', 'quantity_rejection', 'quantity_zakup_info', 'additional_quantity'], 'integer'],
+            [['purchase_price', 'purchase_summ', 'purchase_price_zakup', 'price_zakup_summ', 'cost_price'], 'number'],
+            [['comment_zakup', 'comment_discrepancy_polnogramm'], 'string'],
+            [['product_id'], 'string', 'max' => 36],
+            [['product_id', 'order_id'], 'unique', 'targetAttribute' => ['product_id', 'order_id']],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'product_id' => 'Product ID',
+            'order_id' => 'Order ID',
+            'provider_id' => 'Provider ID',
+            'purchase_price' => 'Purchase Price',
+            'purchase_summ' => 'Purchase Summ',
+            'purchase_price_zakup' => 'Purchase Price Zakup',
+            'price_zakup_summ' => 'Price Zakup Summ',
+            'quantity_purchase_summ' => 'Quantity Purchase Summ',
+            'quantity_zakup' => 'Quantity Zakup',
+            'quantity_zakup_fact' => 'Quantity Zakup Fact',
+            'comment_zakup' => 'Comment Zakup',
+            'comment_discrepancy_polnogramm' => 'Comment Discrepancy Polnogramm',
+            'quantity_warehouseman_fact' => 'Quantity Warehouseman Fact',
+            'quantity_rejection' => 'Quantity Rejection',
+            'quantity_zakup_info' => 'Quantity Zakup Info',
+            'cost_price' => 'Cost Price',
+            'additional_quantity' => 'Additional Quantity',
+        ];
+    }
+}
index f5c75e20de59ad7eb97f0d4600fea8b7dd867510..e1582a9dde1ffd01e7dcaf11d371564a8e939854 100644 (file)
@@ -1,5 +1,9 @@
 <?php
 
+use \yii_app\records\StoreOrdersFields;
+use \yii_app\records\StoreOrdersFieldsData;
+use \yii_app\records\StoreOrdersFieldsDataLogi;
+
 include_once(dirname(__DIR__, 2) . "/startup.php");
 include_once(dirname(__DIR__, 2) . "/inc/db.php");
 
@@ -34,7 +38,8 @@ if(!empty($_REQUEST["id"]) and !empty($_REQUEST["product_id"])) {
 //echo"$name_eng=$value $product_id $store_id";
     if(!empty($store_id)) {
         global $dependent_fields;
-        $data=$db::getRows("SELECT id, dependent_fields, name_eng FROM store_orders_fields WHERE 1");
+        $data = StoreOrdersFields::find()->select(['id', 'dependent_fields', 'name_eng'])->asArray()->all();
+//        $data=$db::getRows("SELECT id, dependent_fields, name_eng FROM store_orders_fields WHERE 1");
         foreach($data as $row) {
             $dependent_fields[$row["id"]]=explode(",",$row["dependent_fields"]);
             $fieldRows[$row["id"]]=$row["name_eng"];
@@ -51,8 +56,8 @@ if(!empty($_REQUEST["id"]) and !empty($_REQUEST["product_id"])) {
 
 
 
-
-        $row=$db::getRow("SELECT id, tip FROM store_orders_fields WHERE name_eng=?",[$name_eng]);
+        $row = StoreOrdersFields::find()->select(['id', 'tip'])->where(['name_eng' => $name_eng])->asArray()->one();
+//        $row=$db::getRow("SELECT id, tip FROM store_orders_fields WHERE name_eng=?",[$name_eng]);
         if(is_array($row)) {
             $tip=$row["tip"];
             $fieldId=$row["id"];
@@ -115,20 +120,46 @@ if(!empty($_REQUEST["id"]) and !empty($_REQUEST["product_id"])) {
 
 
 
-                $value_old=$db::getValue("SELECT $pole FROM store_orders_fields_data WHERE product_id=? AND order_id=? AND store_id=? AND field_name=? AND field_id=? AND color=? LIMIT 1",[$product_id,$id,$store_id,$name_eng,$fieldId,$color]);
+                $value_old_pole = StoreOrdersFieldsData::find()->select([$pole])->where(['product_id' => $product_id, 'order_id' => $id, 'store_id' => $store_id, 'field_name' => $name_eng, 'field_id' => $fieldId, 'color' => $color])->asArray()->one();
+                $value_old = $value_old_pole[$pole];
+                //$value_old=$db::getValue("SELECT $pole FROM store_orders_fields_data WHERE product_id=? AND order_id=? AND store_id=? AND field_name=? AND field_id=? AND color=? LIMIT 1",[$product_id,$id,$store_id,$name_eng,$fieldId,$color]);
                 $value_old=str_replace('.000','',$value_old);
-                $sql="INSERT IGNORE INTO store_orders_fields_data SET  ";
-                $up2 =" $pole='$value'";
-                $up .= ",".$up2;
-                $sql .="$up ON DUPLICATE KEY UPDATE $up2";
-                $db::sql($sql);
-//echo'сохранили '.$name_eng.' store_id='.$store_id.' '.$name_eng.'  color='.$color.' value='.$value.'  ';
-
 
+                $storeOrdersFieldsData = StoreOrdersFieldsData::find()->where(['order_id' => $id, 'product_id' => $product_id,
+                    'store_id' => $store_id, 'field_id' => $fieldId, 'field_name' => $name_eng, 'color' => $color])->one();
+                if (!$storeOrdersFieldsData) {
+                    $storeOrdersFieldsData = new StoreOrdersFieldsData;
+                    $storeOrdersFieldsData->order_id = $id;
+                    $storeOrdersFieldsData->product_id = $product_id;
+                    $storeOrdersFieldsData->store_id = $store_id;
+                    $storeOrdersFieldsData->field_id = $fieldId;
+                    $storeOrdersFieldsData->field_name = $name_eng;
+                    $storeOrdersFieldsData->color = $color;
+                }
+                $storeOrdersFieldsData->$pole = $value;
+                $storeOrdersFieldsData->save();
+//                $sql="INSERT IGNORE INTO store_orders_fields_data SET  ";
+//                $up2 =" $pole='$value'";
+//                $up .= ",".$up2;
+//                $sql .="$up ON DUPLICATE KEY UPDATE $up2";
+//                $db::sql($sql);
+//echo'сохранили '.$name_eng.' store_id='.$store_id.' '.$name_eng.'  color='.$color.' value='.$value.'  ';
 
-                $db::sql("INSERT INTO store_orders_fields_data_logi
-(product_id,field_id,order_id,store_id,color,value,value_old,date_add,admin_id)
-VALUES(?,?,?,?,?, ?, ?, NOW(), ?)", [$product_id,$fieldId,$id,$store_id,$color,$value,$value_old,$_SESSION["admin_id"]]);
+                $storeOrdersFieldsDataLogi = new StoreOrdersFieldsDataLogi;
+                $storeOrdersFieldsDataLogi->product_id = $product_id;
+                $storeOrdersFieldsDataLogi->field_id = $fieldId;
+                $storeOrdersFieldsDataLogi->order_id = $id;
+                $storeOrdersFieldsDataLogi->store_id = $store_id;
+                $storeOrdersFieldsDataLogi->color = $color;
+                $storeOrdersFieldsDataLogi->value = $value;
+                $storeOrdersFieldsDataLogi->value_old = $value_old;
+                $storeOrdersFieldsDataLogi->date_add = date('Y-m-d H:i:s');
+                $storeOrdersFieldsDataLogi->admin_id = $_SESSION["admin_id"];
+                $storeOrdersFieldsDataLogi->save();
+
+//                $db::sql("INSERT INTO store_orders_fields_data_logi
+//(product_id,field_id,order_id,store_id,color,value,value_old,date_add,admin_id)
+//VALUES(?,?,?,?,?, ?, ?, NOW(), ?)", [$product_id,$fieldId,$id,$store_id,$color,$value,$value_old,$_SESSION["admin_id"]]);
 
             }
 
index 91abc5129eb0f0a266b8193d965476b8b1f6eee6..0a4083ac5bbe0fe365dca151860bbc900014377d 100644 (file)
@@ -1,5 +1,19 @@
 <?php
 
+use yii\helpers\ArrayHelper;
+use yii\db\Expression;
+use yii_app\records\AdminGroup;
+use yii_app\records\Products1c;
+use yii_app\records\StoreOrdersStatuses;
+use yii_app\records\StoreOrders;
+use yii_app\records\ShipmentProviders;
+use yii_app\records\Products1cOptions;
+use yii_app\records\StoreOrdersItem;
+use yii_app\records\StoreOrdersPrices;
+use yii_app\records\StoreOrdersFields;
+use yii_app\records\StoreOrdersColors;
+use yii_app\records\Sales;
+
 include_once(dirname(__DIR__, 2) . "/startup.php");
 include_once(dirname(__DIR__, 2) . "/inc/db.php");
 include_once(dirname(__DIR__, 2) . "/inc/base_new.php");
@@ -11,10 +25,13 @@ include_once(dirname(__DIR__, 2) . "/inc/shipment.php");
 global $products;
 $act='division';
 $modul='shipment';
-$roles=$db::mapping("SELECT id, name FROM admin_group WHERE id=7 or id=30 or id=17 or id=70 or id=71  or id=9  or id=51 or id=1  or id=10");
-$storesAll=$db::mapping("SELECT name,id FROM products_1c WHERE tip='city_store' AND view='1' order by name ASC");
+$roles = ArrayHelper::map(AdminGroup::find()->select(['id', 'name'])->where(['in', 'id', [7, 30, 17, 70, 71, 9, 51, 1, 10]])->all(), 'id', 'name');
+//$roles=$db::mapping("SELECT id, name FROM admin_group WHERE id=7 or id=30 or id=17 or id=70 or id=71  or id=9  or id=51 or id=1  or id=10");
+$storesAll = ArrayHelper::map(Products1c::find()->select(['id', 'name'])->where(['tip' => 'city_store', 'view' => '1'])->orderBy(['name' => SORT_ASC])->all(), 'id', 'name');
+//$storesAll=$db::mapping("SELECT name,id FROM products_1c WHERE tip='city_store' AND view='1' order by name ASC");
 
-$data3=$db::getRows("SELECT * FROM store_orders_statuses");
+$data3 = StoreOrdersStatuses::find()->asArray()->all();
+//$data3=$db::getRows("SELECT * FROM store_orders_statuses");
 foreach($data3 as $row) {
     $store_orders_statuses[$row["id"]]=$row["name"];
     $statuses_groups[$row["id"]]=explode(",",$row["groups"]);
@@ -33,7 +50,10 @@ if(!empty($_REQUEST["id"])) $id=(int)$_REQUEST["id"];
 $OrderId=$id;
 
 global $status_order_id;
-$row=$db::getRow("SELECT name,id,providers_arr, status, DATE_FORMAT(date_start, '%Y-%m-%d') as date_start, parent_id FROM store_orders WHERE id=?",[$id]);
+
+$row = StoreOrders::find()->select(['name', 'id', 'providers_arr', 'status', 'DATE_FORMAT(date_start, \'%Y-%m-%d\') as date_start', 'parent_id'])
+    ->where(['id' => $id])->asArray()->one();
+//$row=$db::getRow("SELECT name,id,providers_arr, status, DATE_FORMAT(date_start, '%Y-%m-%d') as date_start, parent_id FROM store_orders WHERE id=?",[$id]);
 $in=explode(",",$row["providers_arr"]);
 $status_order_id=$row["status"];
 $k=0;
@@ -50,10 +70,14 @@ if(!empty($where)) $where =" AND ( $where )";
 
 
 //$users_group=$db::mapping("SELECT id,name FROM admin_group order by name ASC");
-$stores=$db::mapping("SELECT name,id FROM products_1c WHERE tip='city_store' $where AND view='1' order by name ASC");
+$stores = ArrayHelper::map(Products1c::find()->select(['name', 'id'])->where(['tip' => 'city_store', 'view' => '1'])
+    ->andWhere(['in', 'id', $_SESSION["store_arr_guid_dostup"]])->orderBy(['name' => SORT_ASC])->all(), 'id', 'name');
+//$stores=$db::mapping("SELECT name,id FROM products_1c WHERE tip='city_store' $where AND view='1' order by name ASC");
 
 $kustArray=array();
-$data2=$db::getRows("SELECT parent_id, id FROM products_1c WHERE tip='city_store' AND parent_id!='' AND view='1' order by parent_id ASC, name ASC");
+$data2 = Products1c::find()->select(['parent_id', 'id'])->where(['tip' => 'city_store', 'view' => '1'])
+    ->andWhere(['!=', 'parent_id', ''])->orderBy(['parent_id' => SORT_ASC, 'name' => SORT_ASC])->asArray()->all();
+//$data2=$db::getRows("SELECT parent_id, id FROM products_1c WHERE tip='city_store' AND parent_id!='' AND view='1' order by parent_id ASC, name ASC");
 foreach($data2 as $row2) {
     $kustArray[$row2["parent_id"]][]=$row2["id"];
     $kustArrayReverse[$row2["id"]]=$row2["parent_id"];
@@ -94,7 +118,8 @@ echo'<h1 class="page-title mb-0 text-primary">Остаток склада '.$row
 
 $w="";
 
-$da=$db::getRows("SELECT id,name,valuta FROM shipment_providers");
+$da = ShipmentProviders::find()->select(['id', 'name', 'valuta'])->asArray()->all();
+//$da=$db::getRows("SELECT id,name,valuta FROM shipment_providers");
 foreach($da as $r) {
     $providers[$r["id"]]=$r["name"];
     $providers_valuta[$r["id"]]=$r["valuta"];
@@ -111,8 +136,11 @@ foreach($in as $pid) {
 
 $w2="";
 
-$data2=$db::getRows("SELECT p.id, p.name, o.provider_id, o.colors, o.min_lot FROM products_1c_options as o, products_1c as p 
-WHERE ($w) AND p.id=o.id order by o.provider_id ASC, p.name ASC");
+$data2 = Products1cOptions::find()->alias('o')->select(['p.id', 'p.name', 'o.provider_id', 'o.colors', 'o.min_lot'])
+    ->innerJoin('products_1c p', 'p.id = o.id')->where(['in', 'o.provider_id', $in])
+    ->orderBy(['o.provider_id' => SORT_ASC, 'p.name' => SORT_ASC])->asArray()->all();
+//$data2=$db::getRows("SELECT p.id, p.name, o.provider_id, o.colors, o.min_lot FROM products_1c_options as o, products_1c as p
+//WHERE ($w) AND p.id=o.id order by o.provider_id ASC, p.name ASC");
 $k=0;
 foreach($data2 as $row) {
     if($k!=0) $w2 .=" OR ";
@@ -126,7 +154,10 @@ foreach($data2 as $row) {
 }
 
 $division=array();
-$data=$db::getRows("SELECT division_fact as division_fact,store_id,product_id FROM store_orders_item WHERE order_id=? AND store_id!=''",[$OrderId]);
+$division_prod = [];
+$data = StoreOrdersItem::find()->select(['division_fact as division_fact', 'store_id', 'product_id'])->where(['order_id' => $OrderId])
+    ->andWhere(['!=', 'store_id', ''])->asArray()->all();
+//$data=$db::getRows("SELECT division_fact as division_fact,store_id,product_id FROM store_orders_item WHERE order_id=? AND store_id!=''",[$OrderId]);
 foreach($data as $row) {
     $division[$row["product_id"]][$row["store_id"]]=(int)$row["division_fact"];
 
@@ -137,8 +168,10 @@ foreach($data as $row) {
 
 // quantity_purchase_summ AND division_fact>0 or (quantity_purchase_summ>0 and division_fact='0')
 
-$data=$db::getRows("SELECT sum(quantity_warehouseman_fact) as quantity_warehouseman_fact, product_id, 
-sum(quantity_purchase_summ) as quantity_purchase_summ FROM store_orders_prices WHERE order_id=? group by product_id",[$OrderId]);
+$data = StoreOrdersPrices::find()->select(['sum(quantity_warehouseman_fact) as quantity_warehouseman_fact', 'product_id', 'sum(quantity_purchase_summ) as quantity_purchase_summ'])
+    ->where(['order_id' => $OrderId])->groupBy(['product_id'])->asArray()->all();
+//$data=$db::getRows("SELECT sum(quantity_warehouseman_fact) as quantity_warehouseman_fact, product_id,
+//sum(quantity_purchase_summ) as quantity_purchase_summ FROM store_orders_prices WHERE order_id=? group by product_id",[$OrderId]);
 $quantity_warehouseman_fact = [];
 $products_no = [];
 foreach($data as $row) {
@@ -151,15 +184,18 @@ foreach($data as $row) {
 
 }
 
-
-$data=$db::getRows("SELECT sum(division_fact) as division_fact,product_id FROM store_orders_item WHERE order_id=? group by product_id",[$OrderId]);
+$data = StoreOrdersItem::find()->select(['sum(division_fact) as division_fact', 'product_id'])->where(['order_id' => $OrderId])
+    ->groupBy(['product_id'])->asArray()->all();
+//$data=$db::getRows("SELECT sum(division_fact) as division_fact,product_id FROM store_orders_item WHERE order_id=? group by product_id",[$OrderId]);
 foreach($data as $row) {
     $QuantitySumm[$row["product_id"]]=$row["division_fact"];
 
 }
 
 global $quantityPurchase;
-$data=$db::getRows("SELECT product_id, store_id, quantity_purchase FROM store_orders_item WHERE order_id=?",[$OrderId]);
+$data = StoreOrdersItem::find()->select(['product_id', 'store_id', 'quantity_purchase'])->where(['order_id' => $OrderId])->asArray()->all();
+//$data=$db::getRows("SELECT product_id, store_id, quantity_purchase FROM store_orders_item WHERE order_id=?",[$OrderId]);
+$quantityPurchaseAll = [];
 foreach($data as $row) {
     $quantityPurchase[$row["product_id"]][$row["store_id"]]=$quantityPurchase[$row["product_id"]][$row["store_id"]]+$row["quantity_purchase"];
     $quantityPurchaseAll[$row["product_id"]]=$quantityPurchaseAll[$row["product_id"]]+$row["quantity_purchase"];
@@ -189,7 +225,9 @@ if(!empty($_REQUEST["fieldIdThisDivision"])) $fieldIdThisDivision=(int)$_REQUEST
 
 $_SESSION["fieldIdThisDivision"]=$fieldIdThisDivision;
 
-$data=$db::getRow("SELECT name_full, description, name_eng,sql_table_values FROM `store_orders_fields` WHERE id=?",[$fieldIdThisDivision]);
+$data = StoreOrdersFields::find()->select(['name_full', 'description', 'name_eng', 'sql_table_values'])
+    ->where(['id' => $fieldIdThisDivision])->asArray()->one();
+//$data=$db::getRow("SELECT name_full, description, name_eng,sql_table_values FROM `store_orders_fields` WHERE id=?",[$fieldIdThisDivision]);
 
 $arrField=["20"=>"Деление закупшик", "22"=>"Деление кустовых Пришло по фактку кладовщик ", 4=>"Заказ кустовых" ];
 foreach($arrField as $fid =>$name){
@@ -204,8 +242,13 @@ echo' <br> <b>'.$data["name_full"].'</b> '.$data["description"].' <b>'.$data["sq
 
 global $dataColorsValuesAll,$dataColorsValuesStores;
 //field_id='4' - заказ цвета от кустового , field_id='20' - деление факт
-$data5=$db::getRows("SELECT product_id,provider_id,color,field_id, quantity,store_id FROM store_orders_colors WHERE order_id=? and store_id!='undefined' and store_id!=''
-and (field_id='4' or field_id='$fieldIdThisDivision' or field_id='17' or field_id='20' or field_id='22')  group by product_id,provider_id, store_id, color, field_id",[$OrderId]);
+$data5 = StoreOrdersColors::find()->select(['product_id', 'provider_id', 'color', 'field_id', 'quantity', 'store_id'])
+    ->where(['order_id' => $OrderId])->andWhere(['not in', 'store_id', ['undefined', '']])
+    ->andWhere(['in', 'field_id', ['4', "" . $fieldIdThisDivision, '17', '20', '22']])
+    ->groupBy(['product_id', 'provider_id', 'store_id', 'color', 'field_id'])
+    ->asArray()->all();
+//$data5=$db::getRows("SELECT product_id,provider_id,color,field_id, quantity,store_id FROM store_orders_colors WHERE order_id=? and store_id!='undefined' and store_id!=''
+//and (field_id='4' or field_id='$fieldIdThisDivision' or field_id='17' or field_id='20' or field_id='22')  group by product_id,provider_id, store_id, color, field_id",[$OrderId]);
 foreach($data5 as $row5) {
 
 
@@ -219,8 +262,12 @@ foreach($data5 as $row5) {
 
 
 //field_id='4' - заказ цвета от кустового , field_id='20' - деление факт
-$data5=$db::getRows("SELECT product_id,color,field_id, quantity,store_id FROM store_orders_colors WHERE order_id=? and store_id!='undefined' and store_id!=''
-and (field_id='$fieldIdThisDivision')  group by product_id,provider_id, store_id, color",[$OrderId]);
+$data5 = StoreOrdersColors::find()->select(['product_id', 'color', 'field_id', 'quantity', 'store_id'])->where(['order_id' => $OrderId])
+    ->andWhere(['not in', 'store_id', ['undefined', '']])->andWhere(['field_id' => "" . $fieldIdThisDivision])
+    ->groupBy(['product_id', 'provider_id', 'store_id', 'color'])
+    ->asArray()->all();
+//$data5=$db::getRows("SELECT product_id,color,field_id, quantity,store_id FROM store_orders_colors WHERE order_id=? and store_id!='undefined' and store_id!=''
+//and (field_id='$fieldIdThisDivision')  group by product_id,provider_id, store_id, color",[$OrderId]);
 foreach($data5 as $row5) {
     $ColorsArr[$row5["product_id"]][$row5["color"]][$row5["field_id"]][$row5["store_id"]] =$ColorsArr[$row5["product_id"]][$row5["color"]][$row5["field_id"]][$row5["store_id"]] + $row5["quantity"];
 }
@@ -232,15 +279,22 @@ foreach($data5 as $row5) {
 
 
 $dataColorsValuesAll=array();
-$data5=$db::getRows("SELECT product_id,provider_id,color,field_id, sum(quantity) as quantity,store_id FROM store_orders_colors WHERE order_id=? and store_id!='undefined'
-and store_id='0'
-and (field_id='$fieldIdThisDivision')  group by product_id,provider_id, store_id, color,field_id",[$OrderId]);
+$data5 = StoreOrdersColors::find()->select(['product_id', 'provider_id', 'color', 'field_id', 'sum(quantity) as quantity', 'store_id'])
+    ->where(['order_id' => $OrderId])
+    ->andWhere(['store_id' => '0'])
+    ->andWhere(['field_id' => "" . $fieldIdThisDivision])
+    ->groupBy(['product_id', 'provider_id', 'store_id', 'color', 'field_id'])
+    ->asArray()->all();
+//$data5=$db::getRows("SELECT product_id,provider_id,color,field_id, sum(quantity) as quantity,store_id FROM store_orders_colors WHERE order_id=? and store_id!='undefined'
+//and store_id='0'
+//and (field_id='$fieldIdThisDivision')  group by product_id,provider_id, store_id, color,field_id",[$OrderId]);
 foreach($data5 as $row5) {
     $dataColorsValuesAll[$row5["product_id"]][$row5["color"]][$row5["field_id"]]=$row5["quantity"];
 }
 
 global $storesArr,$whereStores,$productsArrayStores;
-$storesArr=$db::mapping("SELECT id,name FROM products_1c WHERE tip='city_store' AND view='1' AND name!='09 Доставка букетов' AND name!='19 Пр. Октября 9а'");
+$storesArr = ArrayHelper::map(Products1c::find()->select(['id', 'name'])->where(['tip' => 'city_store', 'view' => '1'])->andWhere(['not in', 'name', ['09 Доставка букетов', '19 Пр. Октября 9а']])->all(), 'id', 'name');
+//$storesArr=$db::mapping("SELECT id,name FROM products_1c WHERE tip='city_store' AND view='1' AND name!='09 Доставка букетов' AND name!='19 Пр. Октября 9а'");
 $whereStores=" AND ( store_id_1c='-99' ";
 foreach($storesArr as $storeIdGuid => $nameStore) $whereStores .=" or s.store_id_1c='$storeIdGuid' ";
 $whereStores .=" ) ";
@@ -251,11 +305,18 @@ foreach($products as $productId =>$nameProduct) {
 }
 $whereProducts .=" )";
 
-
-$data=$db::getRows("SELECT sum(p.quantity) as squantity,s.store_id_1c, p.product_id 
-FROM sales as s, sales_products as p 
-WHERE s.id=p.check_id AND s.operation='Продажа' $whereProducts  AND s.date>=NOW() - INTERVAL 14 day $whereStores  group BY p.product_id, s.store_id_1c order by 
-squantity DESC");
+$data = Sales::find()->alias('s')->select(['sum(p.quantity) as squantity', 's.store_id_1c', 'p.product_id'])
+    ->innerJoin('sales_products p', 's.id = p.check_id')
+    ->where(['s.operation' => 'Продажа'])
+    ->andWhere(['in', 'p.product_id', array_keys($products)])
+    ->andWhere(['>=', 's.date', new Expression('NOW() - INTERVAL 14 day')])
+    ->groupBy(['p.product_id', 's.store_id_1c'])
+    ->orderBy(['squantity' => SORT_DESC])
+    ->asArray()->all();
+//$data=$db::getRows("SELECT sum(p.quantity) as squantity,s.store_id_1c, p.product_id
+//FROM sales as s, sales_products as p
+//WHERE s.id=p.check_id AND s.operation='Продажа' $whereProducts  AND s.date>=NOW() - INTERVAL 14 day $whereStores  group BY p.product_id, s.store_id_1c order by
+//squantity DESC");
 foreach($data as $row){
     $productsArrayStores[$row["product_id"]][$row["store_id_1c"]]=$row["squantity"];
 
@@ -374,10 +435,19 @@ function autoDivision($productId,$quantityArr,$formulaFact,$formulaPurchase,$for
 
     $thiasQuantity=0;
     $massivAddQuantity=array();
-    $data=$db::getRows("SELECT sum(p.quantity) as squantity,s.store_id_1c 
-FROM sales as s, sales_products as p 
-WHERE s.id=p.check_id AND s.operation='Продажа' AND p.product_id=? AND s.date>=NOW() - INTERVAL 14 day $whereStores  group BY p.product_id, s.store_id_1c order by 
-squantity DESC",[$productId]);
+    $data = Sales::find()->alias('s')->select(['sum(p.quantity) as squantity', 's.store_id_1c'])
+        ->innerJoin('sales_products p', 's.id = p.check_id')
+        ->where(['s.operation' => 'Продажа'])
+        ->andWhere(['p.product_id' => $productId])
+        ->andWhere(['>=', 's.date', new Expression('NOW() - INTERVAL 14 day')])
+        ->andWhere(['in', 's.store_id_1c', array_keys($storesArr)])
+        ->groupBy(['p.product_id', 's.store_id_1c'])
+        ->orderBy(['squantity' => SORT_DESC])
+        ->asArray()->all();
+//    $data=$db::getRows("SELECT sum(p.quantity) as squantity,s.store_id_1c
+//FROM sales as s, sales_products as p
+//WHERE s.id=p.check_id AND s.operation='Продажа' AND p.product_id=? AND s.date>=NOW() - INTERVAL 14 day $whereStores  group BY p.product_id, s.store_id_1c order by
+//squantity DESC",[$productId]);
     foreach($data as $row){
         $txt .="<br> $i) ".$storesArr[$row["store_id_1c"]]." ".(int)$row["squantity"]." шт. ";
         $storeArr[$row["store_id_1c"]]=$row["squantity"];
index b9eb34014765fff79620c7526e7572497ba6318e..e82195ebb541d5cdff68f0543851553b0395ad0d 100644 (file)
@@ -1,5 +1,10 @@
 <?php
 
+use \yii\helpers\ArrayHelper;
+use \yii_app\records\AdminGroup;
+use \yii_app\records\StoreOrdersFields;
+use \yii_app\records\StoreOrdersStatuses;
+
 include_once(dirname(__DIR__, 2) . "/startup.php");
 include_once(dirname(__DIR__, 2) . "/inc/db.php");
 include_once(dirname(__DIR__, 2) . "/inc/base_new.php");
@@ -9,7 +14,8 @@ include_once(dirname(__DIR__, 2) . "/inc/design_new.php");
 
 //if($_SESSION["group_id"]>2) exit("У вас нет доступа");
 
-$roles=$db::mapping("SELECT id, name FROM admin_group WHERE id=7 or id=30 or id=17 or id=70 or id=71  or id=9  or id=51 or id=1 or id=10");
+$roles = ArrayHelper::map(AdminGroup::find()->select(['id', 'name'])->where(['in', 'id', [7, 30, 17, 70, 71, 9, 51, 1, 10]])->all(), 'id', 'name');
+//$roles=$db::mapping("SELECT id, name FROM admin_group WHERE id=7 or id=30 or id=17 or id=70 or id=71  or id=9  or id=51 or id=1 or id=10");
 
 echo "<div class='m-5'>";
 
@@ -20,14 +26,16 @@ if(!empty($_POST["save"])){
 
     foreach($_POST["description"] as $idr => $val) {
 
-        $db::sql("UPDATE store_orders_fields SET description=? WHERE id=?",[$val,$idr]);
+        StoreOrdersFields::updateAll(['description' => $val], ['id' => $idr]);
+//        $db::sql("UPDATE store_orders_fields SET description=? WHERE id=?",[$val,$idr]);
 
     }
 
 
 }
 
-$data=$db::getRows("SELECT id, dostup FROM `store_orders_statuses` WHERE 1");
+$data = StoreOrdersStatuses::find()->select(['id', 'dostup'])->asArray()->all();
+//$data=$db::getRows("SELECT id, dostup FROM `store_orders_statuses` WHERE 1");
 foreach($data as $row) {
     $dostup[$row["id"]] = json_decode($row["dostup"], true);
 
@@ -38,7 +46,8 @@ echo'<form method=post action="/shipment/fields/">';
 ?><input type="hidden" name="_csrf" value="<?=Yii::$app->request->getCsrfToken()?>" /><?php
 
 
-$data=$db::getRows("SELECT * FROM store_orders_fields");
+$data = StoreOrdersFields::find()->asArray()->all();
+//$data=$db::getRows("SELECT * FROM store_orders_fields");
 echo'<table class="table table-hover"><thead><th width=100>название кратко</th>
 <th>name_eng</th>
 <th>SQL таблица сохранения</th>