use yii\helpers\Url;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
+use yii\web\Response;
use yii\web\UploadedFile;
use yii_app\helpers\DataHelper;
use yii_app\records\BouquetComposition;
return ArrayHelper::map($query->asArray()->all(), 'id', 'name');
}
+
+ public function actionGetSalesData()
+ {
+ Yii::$app->response->format = Response::FORMAT_JSON;
+
+ $year = Yii::$app->request->post('year');
+ $month = Yii::$app->request->post('month');
+ $id = Yii::$app->request->post('id');
+
+ if (!$year || !$month || !$id) {
+ return ['success' => false, 'message' => 'Некорректные параметры'];
+ }
+
+ $storesTypeList = BouquetForecast::getStoresList($id, BouquetForecast::OFFLINE_STORES, StoreType::class, [], $month, $year);
+ $marketplaceList = BouquetForecast::getStoresList($id, BouquetForecast::MARKETPLACE, CityStore::class, ['visible' => CityStore::IS_VISIBLE], $month, $year);
+ $onlineStoresList = BouquetForecast::getStoresList($id, BouquetForecast::ONLINE_STORES, CityStore::class, ['visible' => CityStore::IS_VISIBLE], $month, $year);
+
+ return [
+ 'success' => true,
+ 'offline' => $storesTypeList,
+ 'online' => $onlineStoresList,
+ 'marketplace' => $marketplaceList,
+ ];
+ }
}
{
return $this->hasMany(BouquetForecast::class, ['bouquet_id' => 'id']);
}
+
+ public static function getYears()
+ {
+ $currentYear = date('Y');
+ $years = range($currentYear - 5, $currentYear + 5);
+ return array_combine($years, $years);
+ }
}
];
}
- public static function getStoresList($id, $typeSales, $defaultModel, $defaultCondition)
+ public static function getStoresList($id, $typeSales, $defaultModel, $defaultCondition, $month = null, $year = null)
{
$joinTable = $defaultModel === CityStore::class ? 'city_store' : 'store_type';
+
$list = BouquetForecast::find()
- ->andWhere(['bouquet_id' => $id, 'type_sales' => $typeSales])
+ ->andWhere(['bouquet_id' => $id])
+ ->andWhere(['type_sales' => $typeSales])
+ ->andWhere(['month' => $month ?? date('m')])
+ ->andWhere([ 'year' => $year ?? date('Y')])
->leftJoin("$joinTable AS df", "df.id = bouquet_forecast.type_sales_id")
->select(["df.name AS name", 'type_sales_value AS value', 'type_sales_id AS id'])
->orderBy('type_sales_id')
<div class="row">
<div class="col-md-5">
<div class="col-md-3"><?= Html::label("Год", null, ['class' => 'font-weight-bold pt-3 h6']) ?></div>
- <div class="col-md-9"> <?= Html::dropDownList("year", $model?->forecastMonthAndYear->year ?? null, [2024 => 2024, 2025 => 2025], ['class' => 'form-control']) ?></div>
+ <div class="col-md-9"> <?= Html::dropDownList("year", date('Y') ?? null, BouquetComposition::getYears(), ['class' => 'form-control year-picker']) ?></div>
</div>
<div class="col-md-7">
<div class="col-md-3"><?= Html::label("Месяц", null, ['class' => 'font-weight-bold pt-3 h6']) ?></div>
- <div class="col-md-9"><?= Html::dropDownList("month", $model?->forecastMonthAndYear->month ?? null, \yii_app\helpers\DateHelper::MONTH_NUMBER_NAMES, ['class' => 'form-control']) ?></div>
+ <div class="col-md-9"><?= Html::dropDownList("month", date('m') ?? null, \yii_app\helpers\DateHelper::MONTH_NUMBER_NAMES, ['class' => 'form-control month-picker']) ?></div>
</div>
</div>
<div class="row">
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
+use yii_app\records\BouquetComposition;
use yii_app\records\Files;
use yii_app\records\MatrixType;
use yii_app\records\Products1c;
<div class="col-md-2">
<div class="form-group mb-0">
- <?= Html::dropDownList("year", Yii::$app->request->get('year'), [2024 => 2024, 2025 => 2025], [
+ <?= Html::dropDownList("year", Yii::$app->request->get('year'), BouquetComposition::getYears(), [
'class' => 'form-control',
'prompt' => 'Год'
]) ?>
$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Букеты', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
+$this->registerJsFile('/js/bouquet/bouquet.js', ['position' => \yii\web\View::POS_END]);
?>
<div class="bouquet-view border-bottom-4 p-7">
});
});
});
+$(document).ready(function () {
+ if (window.location.pathname.includes('/bouquet/view')) {
+ $('.year-picker, .month-picker').on('change', function () {
+ let year = $('.year-picker').val();
+ let month = $('.month-picker').val();
+ let urlParams = new URLSearchParams(window.location.search);
+ let id = urlParams.get('id');
+
+ if (!id) {
+ return;
+ }
+
+ $.ajax({
+ url: '/bouquet/get-sales-data',
+ type: 'POST',
+ data: { year: year, month: month, id: id },
+ dataType: 'json',
+ success: function(response) {
+ console.log("Ответ сервера:", response);
+ if (response) {
+ ['offline', 'online', 'marketplace'].forEach(type => {
+ $.each(response[type], function(_, value) {
+ let inputSelector = `input[name='BouquetForecast[type_sales_value][${type}][${value.id}]']`;
+ console.log(`Поиск инпута: ${inputSelector}, установка значения: ${value.value}`);
+ $(inputSelector).val(value.value);
+ });
+ });
+ }
+ },
+ error: function(xhr, status, error) {
+ console.error("Ошибка загрузки данных:", status, error);
+ }
+ });
+ });
+ }
+});