]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Добавил номер чека
authorvladfo <fvv2011@gmail.com>
Mon, 14 Oct 2024 14:53:31 +0000 (17:53 +0300)
committervladfo <fvv2011@gmail.com>
Mon, 14 Oct 2024 14:53:31 +0000 (17:53 +0300)
erp24/views/motivation/test-self-cost.php

index 200dc18690ccb2a7100799f37403d7068f0a11e7..a9b2abd92fe26192880c24c9f3d63552cd4f6d45 100644 (file)
@@ -3,6 +3,7 @@ use yii\helpers\Html;
 use yii\widgets\ActiveForm;
 use kartik\select2\Select2;
 use yii\grid\GridView;
+use yii_app\records\Sales;
 
 /* @var $this yii\web\View */
 /* @var $storeList array */
@@ -43,41 +44,58 @@ $this->title = 'Себестоимость товаров по магазина
     </div>
 
     <?php if (!empty($data)): ?>
-        <h2>Результаты (Полные данные)</h2>
-        <?= GridView::widget([
-            'dataProvider' => new \yii\data\ArrayDataProvider([
-                'allModels' => $data,
-                'pagination' => false,
-            ]),
-            'showFooter' => true,
-            'columns' => [
-                ['attribute' => 'product_id', 'label' => 'ID товара'],
-                ['attribute' => 'check_id', 'label' => 'ID чека'],
-                ['attribute' => 'product_name', 'label' => 'Название'],
-                ['attribute' => 'm_price', 'label' => 'Цена'],
-                ['attribute' => 'summ', 'label' => 'Сумма', 'footer' => array_sum(array_column($data, 'summ')),],
-                ['attribute' => 'discount', 'label' => 'Скидка', 'footer' => array_sum(array_column($data, 'discount')),],
-                ['attribute' => 'price', 'label' => 'Себестоимость ед'],
-                [
-                    'attribute' => 'quantity',
-                    'label' => 'Кол-во',
-                    'footer' => array_sum(array_column($data, 'quantity')),
-                ],
-                [
-                    'label' => 'Себестоимость итого',
-                    'value' => function ($model) {
-                        return $model['price'] * $model['quantity'];
-                    },
-                    'footer' => array_sum(array_map(function ($item) {
-                        return $item['price'] * $item['quantity'];
-                    }, $data)),
-                ],
-                ['attribute' => 'date', 'label' => 'Дата'],
+    <h2>Результаты (Полные данные)</h2>
+    <?= GridView::widget([
+        'dataProvider' => new \yii\data\ArrayDataProvider([
+            'allModels' => $data,
+            'pagination' => false,
+        ]),
+        'showFooter' => true,
+        'columns' => [
+            ['attribute' => 'product_id', 'label' => 'ID товара'],
+            ['attribute' => 'check_id', 'label' => 'ID чека'],
+            [
+                'label' => 'Номер чека',
+                'value' => function ($model) {
+                    // Выполняем запрос к таблице Sales для получения номера чека
+                    $salesRecord = Sales::findOne($model['check_id']);
+                    return $salesRecord ? $salesRecord->number : 'Неизвестно';
+                },
             ],
-        ]); ?>
+            ['attribute' => 'product_name', 'label' => 'Название'],
+            ['attribute' => 'm_price', 'label' => 'Цена'],
+            [
+                'attribute' => 'summ',
+                'label' => 'Сумма',
+                'footer' => array_sum(array_column($data, 'summ')),
+            ],
+            [
+                'attribute' => 'discount',
+                'label' => 'Скидка',
+                'footer' => array_sum(array_column($data, 'discount')),
+            ],
+            ['attribute' => 'price', 'label' => 'Себестоимость ед'],
+            [
+                'attribute' => 'quantity',
+                'label' => 'Кол-во',
+                'footer' => array_sum(array_column($data, 'quantity')),
+            ],
+            [
+                'label' => 'Себестоимость итого',
+                'value' => function ($model) {
+                    return $model['price'] * $model['quantity'];
+                },
+                'footer' => array_sum(array_map(function ($item) {
+                    return $item['price'] * $item['quantity'];
+                }, $data)),
+            ],
+            ['attribute' => 'date', 'label' => 'Дата'],
+        ],
+    ]);
+   ?>
 
-        <h3>Общая стоимость: <?= Html::encode($totalSum) ?></h3>
-        <h3>Сумма всех товаров: <?= Html::encode($totalProductsSum) ?></h3>
+        <h3>Общая стоимость: <?= Html::encode(round($totalSum, 2)) ?></h3>
+        <h3>Сумма всех товаров: <?= Html::encode(round($totalProductsSum, 2)) ?></h3>
 
         <h2>Результаты (Уникальные товары)</h2>
         <?= GridView::widget([
@@ -115,9 +133,8 @@ $this->title = 'Себестоимость товаров по магазина
                     }, $uniqueProductsData)),
                 ],
             ],
-        ]); ?>
-    <?php endif; ?>
-
+        ]);
+        endif; ?>
     <?php if (!empty($salesRecords)): ?>
         <h2>Продажи за период</h2>
         <?= GridView::widget([