]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Правки по таблице
authorvladfo <fvv2011@gmail.com>
Tue, 15 Oct 2024 07:58:38 +0000 (10:58 +0300)
committervladfo <fvv2011@gmail.com>
Tue, 15 Oct 2024 07:58:38 +0000 (10:58 +0300)
erp24/views/motivation/test-self-cost.php

index a9b2abd92fe26192880c24c9f3d63552cd4f6d45..584101224d25aa6892e48373af5bfa1ea2595e64 100644 (file)
@@ -44,59 +44,70 @@ $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 чека'],
-            [
-                '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)),
+        <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) {
+                        $salesRecord = Sales::findOne($model['check_id']);
+                        return $salesRecord ? $salesRecord->number : 'Неизвестно';
+                    },
+                ],
+                ['attribute' => 'product_name', 'label' => 'Название'],
+                [
+                    'attribute' => 'm_price',
+                    'label' => 'Цена',
+                    'format' => ['decimal', 2],
+                ],
+                [
+                    'attribute' => 'summ',
+                    'label' => 'Сумма',
+                    'format' => ['decimal', 2],
+                    'footer' => round(array_sum(array_column($data, 'summ')), 2),
+                ],
+                [
+                    'attribute' => 'discount',
+                    'label' => 'Скидка',
+                    'format' => ['decimal', 2],
+                    'footer' => round(array_sum(array_column($data, 'discount')), 2),
+                ],
+                [
+                    'attribute' => 'price',
+                    'label' => 'Себестоимость ед',
+                    'format' => ['decimal', 2],
+                ],
+                [
+                    'attribute' => 'quantity',
+                    'label' => 'Кол-во',
+                    'format' => ['decimal', 2],
+                    'footer' => round(array_sum(array_column($data, 'quantity')), 2),
+                ],
+                [
+                    'label' => 'Себестоимость итого',
+                    'value' => function ($model) {
+                        return round($model['price'] * $model['quantity'], 2);
+                    },
+                    'format' => ['decimal', 2],
+                    'footer' => round(array_sum(array_map(function ($item) {
+                        return $item['price'] * $item['quantity'];
+                    }, $data)), 2),
+                ],
+                ['attribute' => 'date', 'label' => 'Дата'],
             ],
-            ['attribute' => 'date', 'label' => 'Дата'],
-        ],
-    ]);
-   ?>
+        ]);
+        ?>
 
-        <h3>Общая стоимость: <?= Html::encode(round($totalSum, 2)) ?></h3>
-        <h3>Сумма всех товаров: <?= Html::encode(round($totalProductsSum, 2)) ?></h3>
+        <h3>Общая себестоимость: <?= Html::encode(round($totalSum, 2)) ?></h3>
 
+ <br>
         <h2>Результаты (Уникальные товары)</h2>
         <?= GridView::widget([
             'dataProvider' => new \yii\data\ArrayDataProvider([
@@ -107,34 +118,45 @@ $this->title = 'Себестоимость товаров по магазина
             'columns' => [
                 ['attribute' => 'product_id', 'label' => 'ID товара'],
                 ['attribute' => 'product_name', 'label' => 'Название'],
-                ['attribute' => 'price', 'label' => 'Себестоимость ед'],
-                ['attribute' => 'm_price', 'label' => 'Цена ед'],
+                [
+                    'attribute' => 'price',
+                    'label' => 'Себестоимость ед',
+                    'format' => ['decimal', 2],
+                ],
+                [
+                    'attribute' => 'm_price',
+                    'label' => 'Цена ед',
+                    'format' => ['decimal', 2],
+                ],
                 [
                     'attribute' => 'quantity',
                     'label' => 'Общее кол-во',
-                    'footer' => array_sum(array_column($uniqueProductsData, 'quantity')),
+                    'format' => ['decimal', 2],
+                    'footer' => round(array_sum(array_column($uniqueProductsData, 'quantity')), 2),
                 ],
                 [
                     'label' => 'Себестоимость * Кол-во',
                     'value' => function ($model) {
-                        return $model['price'] * $model['quantity'];
+                        return round($model['price'] * $model['quantity'], 2);
                     },
-                    'footer' => array_sum(array_map(function ($item) {
+                    'format' => ['decimal', 2],
+                    'footer' => round(array_sum(array_map(function ($item) {
                         return $item['price'] * $item['quantity'];
-                    }, $uniqueProductsData)),
+                    }, $uniqueProductsData)), 2),
                 ],
                 [
                     'label' => 'Цена * Кол-во',
                     'value' => function ($model) {
-                        return $model['m_price'] * $model['quantity'];
+                        return round($model['m_price'] * $model['quantity'], 2);
                     },
-                    'footer' => array_sum(array_map(function ($item) {
+                    'format' => ['decimal', 2],
+                    'footer' => round(array_sum(array_map(function ($item) {
                         return $item['m_price'] * $item['quantity'];
-                    }, $uniqueProductsData)),
+                    }, $uniqueProductsData)), 2),
                 ],
             ],
         ]);
-        endif; ?>
+    endif; ?>
     <?php if (!empty($salesRecords)): ?>
         <h2>Продажи за период</h2>
         <?= GridView::widget([
@@ -142,17 +164,19 @@ $this->title = 'Себестоимость товаров по магазина
                 'allModels' => $salesRecords,
                 'pagination' => false,
             ]),
-            'showFooter' => true, // Показываем подвал таблицы
+            'showFooter' => true,
             'columns' => [
                 ['attribute' => 'id', 'label' => 'ID продажи'],
+                ['attribute' => 'number', 'label' => 'Номер чека'],
                 ['attribute' => 'operation', 'label' => 'Операция'],
                 ['attribute' => 'status', 'label' => 'Статус'],
                 [
                     'attribute' => 'summ',
                     'label' => 'Сумма',
-                    'footer' => array_sum(array_column($salesRecords, 'summ')), // Сумма всех значений столбца "Сумма"
+                    'format' => ['decimal', 2],
+                    'footer' => round(array_sum(array_column($salesRecords, 'summ')), 2),
                 ],
-                ['attribute' => 'sales_check', 'label' => 'Чек возврата'],
+
                 ['attribute' => 'date', 'label' => 'Дата'],
             ],
         ]); ?>
@@ -167,11 +191,17 @@ $this->title = 'Себестоимость товаров по магазина
             ]),
             'columns' => [
                 ['attribute' => 'id', 'label' => 'ID возврата'],
+                ['attribute' => 'number', 'label' => 'Номер чека'],
                 ['attribute' => 'date', 'label' => 'Дата'],
+                [
+                    'attribute' => 'summ',
+                    'label' => 'Сумма',
+                    'format' => ['decimal', 2],
+                    'footer' => round(array_sum(array_column($salesRecords, 'summ')), 2),
+                ],
                 ['attribute' => 'sales_check', 'label' => 'ID продажи'],
             ],
         ]); ?>
     <?php endif; ?>
 
-
 </div>
\ No newline at end of file