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 */
</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([
}, $uniqueProductsData)),
],
],
- ]); ?>
- <?php endif; ?>
-
+ ]);
+ endif; ?>
<?php if (!empty($salesRecords)): ?>
<h2>Продажи за период</h2>
<?= GridView::widget([