]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Добавили расчет продаж
authorvladfo <fvv2011@gmail.com>
Fri, 11 Oct 2024 13:57:06 +0000 (16:57 +0300)
committervladfo <fvv2011@gmail.com>
Fri, 11 Oct 2024 13:57:06 +0000 (16:57 +0300)
erp24/actions/motivation/TestSelfCostAction.php
erp24/views/motivation/test-self-cost.php

index f88f442151eec82a511c259fb35c3cb042260ae2..09cd8c1d5d5b70b5d3eb5af98ecea18ba0119119 100644 (file)
@@ -64,6 +64,7 @@ class TestSelfCostAction extends Action
                         'product_id' => $productId,
                         'product_name' => $item['product_name'],
                         'price' => $item['price'],
+                        'm_price' => $item['m_price'],
                         'quantity' => $item['quantity'],
                     ];
                 } else {
index 8e0180ec18f88c9465c875cb1dabbf1b9072352e..bc17c5daa0ecda36b94f7e270e61fe8debfa226d 100644 (file)
@@ -2,6 +2,7 @@
 use yii\helpers\Html;
 use yii\widgets\ActiveForm;
 use kartik\select2\Select2;
+use yii\grid\GridView;
 
 /* @var $this yii\web\View */
 /* @var $storeList array */
@@ -41,55 +42,75 @@ $this->title = 'Себестоимость товаров по магазина
 
     <?php if (!empty($data)): ?>
         <h2>Результаты (Полные данные)</h2>
-        <table class="table table-bordered">
-            <thead>
-            <tr>
-                <th>ID товара</th>
-                <th>ID чека</th>
-                <th>Название</th>
-                <th>Себестоимость</th>
-                <th>Цена</th>
-                <th>Кол-во</th>
-                <th>Дата</th>
-            </tr>
-            </thead>
-            <tbody>
-            <?php foreach ($data as $item): ?>
-                <tr>
-                    <td><?= Html::encode($item['product_id']) ?></td>
-                    <td><?= Html::encode($item['check_id']) ?></td>
-                    <td><?= Html::encode($item['product_name']) ?></td>
-                    <td><?= Html::encode($item['price']) ?></td>
-                    <td><?= Html::encode($item['m_price']) ?></td>
-                    <td><?= Html::encode($item['quantity']) ?></td>
-                    <td><?= Html::encode($item['date']) ?></td>
-                </tr>
-            <?php endforeach; ?>
-            </tbody>
-        </table>
+        <?= 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' => '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>
 
         <h2>Результаты (Уникальные товары)</h2>
-        <table class="table table-bordered">
-            <thead>
-            <tr>
-                <th>ID товара</th>
-                <th>Название</th>
-                <th>Цена</th>
-                <th>Общее кол-во</th>
-            </tr>
-            </thead>
-            <tbody>
-            <?php foreach ($uniqueProductsData as $item): ?>
-                <tr>
-                    <td><?= Html::encode($item['product_id']) ?></td>
-                    <td><?= Html::encode($item['product_name']) ?></td>
-                    <td><?= Html::encode($item['price']) ?></td>
-                    <td><?= Html::encode($item['quantity']) ?></td>
-                </tr>
-            <?php endforeach; ?>
-            </tbody>
-        </table>
+        <?= GridView::widget([
+            'dataProvider' => new \yii\data\ArrayDataProvider([
+                'allModels' => $uniqueProductsData,
+                'pagination' => false,
+            ]),
+            'showFooter' => true,
+            'columns' => [
+                ['attribute' => 'product_id', 'label' => 'ID товара'],
+                ['attribute' => 'product_name', 'label' => 'Название'],
+                ['attribute' => 'price', 'label' => 'Себестоимость ед'],
+                ['attribute' => 'm_price', 'label' => 'Цена ед'],
+                [
+                    'attribute' => 'quantity',
+                    'label' => 'Общее кол-во',
+                    'footer' => array_sum(array_column($uniqueProductsData, 'quantity')),
+                ],
+                [
+                    'label' => 'Себестоимость * Кол-во',
+                    'value' => function ($model) {
+                        return $model['price'] * $model['quantity'];
+                    },
+                    'footer' => array_sum(array_map(function ($item) {
+                        return $item['price'] * $item['quantity'];
+                    }, $uniqueProductsData)),
+                ],
+                [
+                    'label' => 'Цена * Кол-во',
+                    'value' => function ($model) {
+                        return $model['m_price'] * $model['quantity'];
+                    },
+                    'footer' => array_sum(array_map(function ($item) {
+                        return $item['m_price'] * $item['quantity'];
+                    }, $uniqueProductsData)),
+                ],
+            ],
+        ]); ?>
     <?php endif; ?>
 </div>
\ No newline at end of file