]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Добавление цен во вью
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 6 Dec 2024 10:22:25 +0000 (13:22 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 6 Dec 2024 10:22:25 +0000 (13:22 +0300)
erp24/controllers/crud/Product1cReplacementController.php
erp24/views/crud/product1c-replacement/view.php

index 204851df79ce765ed3bcd8837d2e23a69dafd338..615d2b8a828736f19cd1c4752a3a3f1b9ca84508 100644 (file)
@@ -6,6 +6,7 @@ use Yii;
 use yii\behaviors\TimestampBehavior;
 use yii\data\ActiveDataProvider;
 use yii_app\records\Admin;
+use yii_app\records\Prices;
 use yii_app\records\Product1cReplacement;
 use yii_app\records\Product1cReplacementLog;
 use yii_app\records\Product1cReplacementSearch;
@@ -92,6 +93,10 @@ class Product1cReplacementController extends Controller
             ],
         ]);
 
+        $productPrice = Prices::find()
+            ->select(['price'])
+            ->where(['product_id' => $id])
+            ->one();
 
         $replacements = $replacementsQuery->all();
         $lastLogs = [];
@@ -101,18 +106,28 @@ class Product1cReplacementController extends Controller
                 ->orderBy(['date' => SORT_DESC])
                 ->one();
 
-            if ($lastLog) {
+            $productReplacementPrice = Prices::find()
+                ->select(['price'])
+                ->where(['product_id' => $replacement->guid_replacement])
+                ->one();
+
+            $priceDifference = null;
+            if ($productPrice !== null && $productReplacementPrice !== null) {
+                $priceDifference = $productPrice - $productReplacementPrice->price;
+            }
 
+            if ($lastLog) {
                 $adminName = null;
                 if ($lastLog->admin_id) {
                     $admin = Admin::findOne($lastLog->admin_id);
                     $adminName = $admin ? $admin->name : 'Неизвестно';
                 }
 
-
                 $lastLogs[$replacement->id] = [
                     'lastLog' => $lastLog,
                     'adminName' => $adminName,
+                    'productReplacementPrice' => $productReplacementPrice,
+                    'priceDifference' => $priceDifference,
                 ];
             }
         }
@@ -121,6 +136,7 @@ class Product1cReplacementController extends Controller
             'model' => $this->findModelByGuid($id),
             'replacements' => $replacementsDataProvider,
             'lastLogs' => $lastLogs,
+            'productPrice' => $productPrice,
         ]);
     }
 
index babebf2d0b00c3cb87c91cd4412b364993ff7853..54fe0c69599815a6c61c74223173c726306116b0 100644 (file)
@@ -9,6 +9,7 @@ use yii_app\records\Products1c;
 /** @var yii_app\records\Product1cReplacement $model */
 /** @var yii\data\ActiveDataProvider $replacements */
 /** @var array $lastLogs */
+/** @var array $productPrice */
 
 $this->title = $model->product->name;
 $this->params['breadcrumbs'][] = ['label' => 'Product1c Replacements', 'url' => ['index']];
@@ -19,58 +20,82 @@ $this->params['breadcrumbs'][] = $this->title;
 ?>
 <div class="product1-creplacement-view p-4">
     <?= Html::a('Назад', ['index'], ['class' => 'btn btn-danger mb-4']) ?>
-    <h1>Замены для <?= Html::encode($this->title) ?></h1>
+    <div class="d-flex py-4 align-items-center gap-3">
+        <h1>Замены для <?= Html::encode($this->title) ?> </h1>
+        <button class="btn btn-small btn-primary mb-4 mx-3-3">
+            Цена: <?= Html::encode($productPrice->price ?? 'Нет данных' ) ?>
+        </button>
+    </div>
+
     <p>
         <?= Html::a('Редактировать', ['update', 'id' => $model->guid], ['class' => 'btn btn-primary']) ?>
         <?= Html::a('Просмотр логов', ['log-history', 'guid' => $model->guid], ['class' => 'btn btn-success']) ?>
     </p>
 
     <div id="grid-container">
-    <?= GridView::widget([
-        'dataProvider' => $replacements,
-        'columns' => [
-            [
-                'label' => 'GUIDы замены',
-                'attribute' => 'replacement_guid',
-                'value' => function ($model) {
+        <?= GridView::widget([
+            'dataProvider' => $replacements,
+            'columns' => [
+                [
+                    'label' => 'GUIDы замены',
+                    'attribute' => 'replacement_guid',
+                    'value' => function ($model) {
+                        $product = Products1c::findOne(['id' => $model->guid_replacement, 'tip' => 'products']);
+                        if ($product) {
+                            $code = $product->code ? $product->code : '';
+                            $articule = $product->articule ? (', ' . $product->articule) : '';
+                            return Html::encode($product->name . ' (' . $code . $articule . ')');
+                        }
+                        return Html::encode($model->guid_replacement);
+                    },
+                    'format' => 'raw',
+                ],
+                [
+                    'label' => 'Цена товара',
+                    'value' => function ($model) use ($lastLogs) {
+                        if (isset($lastLogs[$model->id]['productReplacementPrice'])) {
+                            return Html::encode($lastLogs[$model->id]['productReplacementPrice']->price);
+                        }
+                        return '<span style="color:red"> Нет данных</span>';
+                    },
+                    'format' => 'raw',
+                ],
+                [
+                    'label' => 'Разница цены',
+                    'value' => function ($model) use ($lastLogs) {
+                        if (isset($lastLogs[$model->id]['priceDifference'])) {
+                            return Html::encode($lastLogs[$model->id]['priceDifference']);
+                        }
+                        return '<span style="color:red"> Нет данных</span>';
+                    },
+                    'format' => 'raw',
+                ],
+                [
+                    'label' => 'Последнее редактирование',
+                    'value' => function ($model) use ($lastLogs) {
+                        if (isset($lastLogs[$model->id]['lastLog'])) {
+                            return Html::encode($lastLogs[$model->id]['lastLog']->date);
+                        }
+                        return '<span style="color:red"> Нет данных</span>';
+                    },
+                    'format' => 'raw',
+                ],
+                [
+                    'label' => 'Пользователь',
+                    'value' => function ($model) use ($lastLogs) {
+                        if (isset($lastLogs[$model->id]['adminName'])) {
+                            return Html::encode($lastLogs[$model->id]['adminName']);
+                        }
+                        return '<span style="color:red">Неизвестно</span>';
+                    },
+                    'format' => 'raw',
+                ],
 
-                    $product = Products1c::findOne(['id' => $model->guid_replacement, 'tip' => 'products']);
-                    if ($product) {
-                        $code = $product->code ?  $product->code : '';
-                        $articule = $product->articule ? (', ' . $product->articule) : '';
-                        return Html::encode($product->name . ' (' . $code . $articule . ')');
-                    }
-                    return Html::encode($model->guid_replacement);
-                },
-                'format' => 'raw',
-            ],
-            [
-                'label' => 'Последнее редактирование',
-                'value' => function ($model) use ($lastLogs) {
-                    if (isset($lastLogs[$model->id])) {
-                        return Html::encode($lastLogs[$model->id]['lastLog']->date);
-                    }
-                    return 'Нет данных';
-                },
-                'format' => 'raw',
             ],
-            [
-                'label' => 'Пользователь',
-                'value' => function ($model) use ($lastLogs) {
-                    if (isset($lastLogs[$model->id])) {
-                        return Html::encode($lastLogs[$model->id]['adminName']);
-                    }
-                    return 'Неизвестно';
-                },
-                'format' => 'raw',
-            ],
-
-        ],
-    ]);
-
+        ]);
 
 
-    ?>
+        ?>
 
 
     </div>