</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([
'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([
'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' => 'Дата'],
],
]); ?>
]),
'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