return $this->redirect(Yii::$app->request->referrer);
}
+
+ public function actionGetProductListData()
+ {
+ Yii::$app->response->format = Response::FORMAT_JSON;
+ $request = Yii::$app->request;
+
+ $bouquet_id = (int) $request->get('id');
+ $month = (int) $request->get('month');
+ $year = (int) $request->get('year');
+
+ $products = BouquetCompositionProducts::find()->where(['bouquet_id' => $bouquet_id])->all();
+
+ $data = [];
+
+ foreach ($products as $product) {
+ $data[] = [
+ 'product_guid' => $product->product_guid,
+ 'buildPercentage' => $product->getBuildPercentage($year, $month),
+ 'averageNumberOfPieces' => $product->getAverageNumberOfPieces($year, $month),
+ ];
+ }
+
+ return $data;
+ }
}
\ No newline at end of file
return round($medianProfitability, 2);
}
- public function getBuildPercentage(): float
+ public function getBuildPercentage(int $year = null, int $month = null): float
{
- $totalAssemblies = BouquetCompositionProducts::find()->count();
+ $year = $year ?? date('Y');
+ $month = $month ?? date('m');
+ $periodBouquets = BouquetForecast::find()
+ ->andWhere(['year' => $year, 'month' => $month])
+ ->select('bouquet_id')
+ ->distinct()
+ ->column();
+
+ $totalAssemblies = BouquetCompositionProducts::find()
+ ->count();
+
$assembliesWithProduct = BouquetCompositionProducts::find()
- ->where(['product_guid' => $this->product_guid])
+ ->andWhere(['product_guid' => $this->product_guid])
+ ->andWhere(['bouquet_id' => $periodBouquets])
->count();
return $totalAssemblies ? round(($assembliesWithProduct / $totalAssemblies) * 100, 2) : 0;
}
- public function getAverageNumberOfPieces(): float
+ public function getAverageNumberOfPieces(int $year = null, int $month = null): float
{
+ $year = $year ?? date('Y');
+ $month = $month ?? date('m');
+ $periodBouquets = BouquetForecast::find()
+ ->andWhere(['year' => $year, 'month' => $month])
+ ->select('bouquet_id')
+ ->distinct()
+ ->column();
+
$totalCount = BouquetCompositionProducts::find()
->where(['product_guid' => $this->product_guid])
->sum('count');
$assembliesWithProduct = BouquetCompositionProducts::find()
- ->where(['product_guid' => $this->product_guid])
+ ->andWhere(['product_guid' => $this->product_guid])
+ ->andWhere(['bouquet_id' => $periodBouquets])
->count();
return $assembliesWithProduct ? round($totalCount / $assembliesWithProduct, 2) : 0;
<div class="col-md-2 text-center font-weight-bold">ср.шт. в сборке</div>
</div>
-<div class="bg-white border rounded shadow-sm" style="height: 400px; overflow-y: auto; overflow-x: hidden;">
+<div class="products-list bg-white border rounded shadow-sm" style="height: 400px; overflow-y: auto; overflow-x: hidden;">
<?php
use yii\helpers\Html;
use yii\helpers\Url;
use yii_app\records\WriteOffsErp;
foreach ($bouquetCompositionProducts as $product) { ?>
- <div class="d-flex border-bottom ms-1 py-2" style="gap: 0;">
+ <div class="d-flex border-bottom ms-1 py-2" style="gap: 0;" data-product-guid="<?= Html::encode($product->product_guid) ?>">
<div class="text-center" style="width: 33.33%;"><?= Html::encode($product->product->name) ?></div>
<div class="text-center" style="width: 16.66%;"><?= Html::encode($product->count) ?></div>
<div class="text-center" style="width: 8.33%;"><?= Html::encode($product->getWriteOffPercentage()) ?></div>
<div class="text-center" style="width: 16.66%;"><?= Html::encode($product->getProfitability())?> </div>
- <div class="text-center" style="width: 16.66%;"><?= Html::encode($product->getBuildPercentage()) ?>%</div>
- <div class="text-center" style="width: 8.33%;"><?= Html::encode($product->getAverageNumberOfPieces()) ?></div>
+ <div class="text-center build-percentage" style="width: 16.66%;"><?= Html::encode($product->getBuildPercentage()) ?>%</div>
+ <div class="text-center average-pieces" style="width: 8.33%;"><?= Html::encode($product->getAverageNumberOfPieces()) ?></div>
</div>
<?php } ?>
</div>
console.error("Ошибка загрузки данных:", status, error);
}
});
+
+ $.ajax({
+ url: '/bouquet/get-product-list-data',
+ type: 'GET',
+ data: { year: year, month: month, id: id },
+ dataType: 'json',
+ success: function (response) {
+ if (response) {
+ console.log(response);
+
+ response.forEach(item => {
+ let row = $(`.d-flex[data-product-guid="${item.product_guid}"]`);
+ if (row.length) {
+ row.find('.build-percentage').text(item.buildPercentage + '%');
+ row.find('.average-pieces').text(item.averageNumberOfPieces);
+ }
+ });
+ }
+ },
+ error: function (xhr, status, error) {
+ console.error("Ошибка загрузки данных:", status, error);
+ }
+ });
});
}
});