--- /dev/null
+<?php
+
+namespace yii_app\actions\motivation;
+
+use Yii;
+use yii\base\Action;
+use yii\base\DynamicModel;
+use yii\helpers\ArrayHelper;
+use yii_app\records\Motivation;
+use yii_app\services\MotivationService;
+
+class TestFactAction extends Action
+{
+ public function run() {
+
+ // Получаем текущую дату
+ $currentDate = new \DateTime();
+
+ $model = DynamicModel::validateData([
+ 'year' => $currentDate->format('Y'), // Текущий год
+ 'month' => $currentDate->format('n') // Текущий месяц (1-12)
+ ], [
+ [['year', 'month'], 'safe']
+ ]);
+
+ $motivations = Motivation::find()->all();
+ $possibleYears = ArrayHelper::getColumn($motivations, 'year');
+ $years = array_filter(range(2023, 20100), function ($k) use ($possibleYears) {
+ return in_array($k, $possibleYears);
+ });
+ $years = array_combine($years, $years);
+ $possibleMonth = ArrayHelper::getColumn($motivations, 'month');
+ $months = array_filter([1 => 'Январь', 2 => 'Февраль', 3 => 'Март', 4 => 'Апрель', 5 => 'Май', 6 => 'Июнь', 7 => 'Июль', 8 => 'Август', 9 => 'Сентябрь', 10 => 'Октябрь', 11 => 'Ноябрь', 12 => 'Декабрь'], function ($k, $v) use ($possibleMonth) {
+ return in_array($v, $possibleMonth);
+ }, ARRAY_FILTER_USE_BOTH);
+
+ // Загружаем данные из GET-запроса, если они есть
+ if (Yii::$app->request->get()) {
+ $model->load(Yii::$app->request->get());
+
+ if ($model->year === '') {
+ $model->year = $currentDate->format('Y');
+ } else {
+ $model->year = intval($model->year);
+ // Проверяем, что год находится в допустимом диапазоне
+ if (!in_array($model->year, $years)) {
+ $model->year = $currentDate->format('Y');
+ }
+ }
+
+ $model->month = intval($model->month);
+
+ MotivationService::calculateMonthSales($model->year, $model->month);
+
+ MotivationService::calculateMonthServices($model->year, $model->month);
+
+ MotivationService::calculateMonthDefect($model->year, $model->month);
+ }
+
+ return $this->controller->render('test-fact', compact('model', 'years', 'months'));
+ }
+}
\ No newline at end of file
$returnSales = Sales::find()->where(['operation' => Sales::OPERATION_RETURN, 'sales_check' => $salesIds])->all();
$returnSalesIds = ArrayHelper::getColumn($returnSales, 'sales_check');
- $salesOffline = Sales::find()->select(['SUM(summ) as total'])
+ $salesOffline = Sales::find()->select(['SUM(summ) as total', 'store_id'])
->where(['between', 'date', $monthStart, $monthEnd])
->andWhere(['operation' => Sales::OPERATION_SALE])
->andWhere(['order_id' => ['', '0']])
- ->andWhere(['NOT IN', 'check_id', $returnSalesIds])
+ ->andWhere(['NOT IN', 'id', $returnSalesIds])
->groupBy(['store_id'])
->indexBy('store_id')
->asArray()->all();
- $salesOnline = Sales::find()->select(['SUM(summ) as total'])
+ $salesOnline = Sales::find()->select(['SUM(summ) as total', 'store_id'])
->where(['between', 'date', $monthStart, $monthEnd])
->andWhere(['operation' => Sales::OPERATION_SALE])
->andWhere(['NOT IN', 'order_id', ['', '0']])
- ->andWhere(['NOT IN', 'check_id', $returnSalesIds])
+ ->andWhere(['NOT IN', 'id', $returnSalesIds])
->groupBy(['store_id'])
->indexBy('store_id')
->asArray()->all();
// Ищем продукты из категории services
$salesProduct = SalesProducts::find()->alias('p')
- ->select(['SUM(summ) as total'])
+ ->select(['SUM(p.summ) as total', 'store_id'])
->leftJoin('sales s', 's.id = p.check_id')
->where(['check_id' => $salesIds])
->andWhere(['NOT IN', 'check_id', $returnSalesIds])
->andWhere(['product_id' => array_keys($products1c)])
- ->groupBy(['s.store_id'])
- ->indexBy('s.store_id')
- ->asArray()->one();
+ ->groupBy(['store_id'])
+ ->indexBy('store_id')
+ ->asArray()->all();
// Ищем продажи по продуктовым гуидам по каталог-гуидам категории services_delivery
$salesDelivery = Sales::find()->alias('s')
// Ищем продукты из категории services_delivery
$salesProductDelivery = SalesProducts::find()->alias('p')
- ->select(['SUM(summ) as total'])
+ ->select(['SUM(p.summ) as total', 'store_id'])
->leftJoin('sales s', 's.id = p.check_id')
->where(['check_id' => $salesIdsDelivery])
->andWhere(['NOT IN', 'check_id', $returnSalesIdsDelivery])
->andWhere(['product_id' => array_keys($products1cDelivery)])
- ->groupBy(['s.store_id'])
- ->indexBy('s.store_id')
- ->asArray()->one();
+ ->groupBy(['store_id'])
+ ->indexBy('store_id')
+ ->asArray()->all();
$motivations = Motivation::find()->where(['year' => $year, 'month' => $month])->indexBy('store_id')->all();
$motivations = Motivation::find()->where(['year' => $year, 'month' => $month])->indexBy('store_id')->all();
$motivationValueGroup = MotivationValueGroup::find()->where(['alias' => 'fact'])->one();
- $exportImportTables = ExportImportTable::find()->select(['export_val'])->where(['entity' => 'city_store',
+ $exportImportTables = ExportImportTable::find()->select(['export_val', 'entity_id'])->where(['entity' => 'city_store',
'entity_id' => array_keys($motivations), 'export_id' => 1])->indexBy('entity_id')->all();
/** @var $exportImportTables ExportImportTable[] */
foreach ($exportImportTables as $store_id => $store_guid) {
- $writeOffs = WriteOffs::find()->select(['sum(summ) as total', 'type'])
- ->where(['between', 'date', $monthStart, $monthEnd])
- ->andWhere(['store_id' => $store_guid])
- ->groupBy(['type'])
- ->indexBy('type')
- ->asArray()->all();
-
- foreach ($writeOffs as $key => $data) {
- $motivationItemType = MotivationCostsItem::writeOffsToMotivationItemMap($key);
- if (empty($motivationItemType)) {
- continue;
- }
- $motivationCostsItem = MotivationCostsItem::find()->where(['name' => $motivationItemType])->one();
- /** @var $motivationCostsItem MotivationCostsItem */
- if (isset($motivations[$store_id])) {
+ if (isset($motivations[$store_id])) {
+ $writeOffs = WriteOffs::find()->select(['sum(summ) as total', 'type'])
+ ->where(['between', 'date', $monthStart, $monthEnd])
+ ->andWhere(['store_id' => $store_guid])
+ ->groupBy(['type'])
+ ->indexBy('type')
+ ->asArray()->all();
+ foreach ($writeOffs as $key => $data) {
+ $motivationItemType = MotivationCostsItem::writeOffsToMotivationItemMap($key);
+ if (empty($motivationItemType)) {
+ continue;
+ }
+ $motivationCostsItem = MotivationCostsItem::find()->where(['name' => $motivationItemType])->one();
+ /** @var $motivationCostsItem MotivationCostsItem */
$motivationValue = MotivationValue::find()->where(['motivation_id' => $motivations[$store_id]->id,
'motivation_group_id' => $motivationValueGroup->id, 'value_id' => $motivationCostsItem->code])->one();
if (!$motivationValue) {
--- /dev/null
+<?php
+
+use kartik\select2\Select2;
+
+use yii\helpers\Html;
+use yii\widgets\ActiveForm;
+use yii\base\DynamicModel;
+
+/** @var $model DynamicModel */
+/** @var $years array */
+/** @var $months array */
+
+
+?>
+
+<div class="motivationTestFact m-5">
+
+ <?php $form = ActiveForm::begin(['method' => 'GET', 'action' => '/motivation/test-fact']) ?>
+
+ <div class="row">
+ <div class="col-4 d-flex justify-content-between align-items-center gap-4">
+ <div class="d-flex justify-content-around align-items-center gap-2">
+ <div class="mb-3">Год:</div>
+ <div style="display: inline-block">
+ <?= $form->field($model, 'year')->widget(Select2::class, [
+ 'data' => $years,
+ 'language' => 'ru',
+ 'options' => ['placeholder' => 'Год...'],
+ 'pluginOptions' => [
+ 'allowClear' => true
+ ],
+ ])->label(false) ?>
+ </div>
+ <div class="d-flex justify-content-around align-items-center gap-2">
+ <div class="mb-3">Месяц:</div>
+ <div style="display: inline-block">
+ <?= $form->field($model, 'month')->widget(Select2::class, [
+ 'data' => $months,
+ 'language' => 'ru',
+ 'options' => ['placeholder' => 'Месяц...'],
+ 'pluginOptions' => [
+ 'allowClear' => true
+ ],
+ ])->label(false) ?>
+ </div>
+ </div>
+ <div class="d-flex justify-content-around align-items-center gap-2">
+ <div class="mb-3"><?= Html::submitButton('Применить', ['class' => 'btn btn-secondary btn-sm']) ?></div>
+ </div>
+ </div>
+ </div>
+
+ <?php ActiveForm::end() ?>
+
+
+</div>