From: Vladimir Fomichev Date: Wed, 30 Jul 2025 14:20:03 +0000 (+0300) Subject: Заполнение данных активности X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=57766b42e4f1f6afbdcb00f9026300787c77747a;p=erp24_rep%2Fyii-erp24%2F.git Заполнение данных активности --- diff --git a/erp24/controllers/Products1cNomenclatureActualityController.php b/erp24/controllers/Products1cNomenclatureActualityController.php index 24407d04..d2a6cfd9 100644 --- a/erp24/controllers/Products1cNomenclatureActualityController.php +++ b/erp24/controllers/Products1cNomenclatureActualityController.php @@ -3,6 +3,8 @@ namespace app\controllers; use Yii; +use yii\db\Query; +use yii_app\api3\modules\v1\models\Sales; use yii_app\records\Products1cAdditionalCharacteristics; use yii_app\records\Products1cNomenclature; use yii_app\records\Products1cNomenclatureActuality; @@ -208,6 +210,81 @@ class Products1cNomenclatureActualityController extends Controller ]); } + public function actionAddActivity() + { + $request = Yii::$app->request; + + if (!$request->get('historyDays') || !$request->get('intervalMonths')) { + return $this->render('add-activity', [ + 'historyDays' => $historyDays ?? 14, + 'intervalMonths' => $intervalMonths ?? 4, + ]); + } + + $historyDays = (int)$request->get('historyDays'); + $intervalMonths = (int)$request->get('intervalMonths'); + + $endDate = date('Y-m-d'); + $startDate = date('Y-m-d', strtotime("-{$historyDays} days", strtotime($endDate))); + + $storeIds = array_map(fn($s) => $s->id, $this->getVisibleStores()); + $countStores = count($storeIds); + + $productIds = (new Query()) + ->select('sp.product_id') + ->from(['s' => 'sales']) + ->innerJoin(['sp' => 'sales_products'], 's.id = sp.check_id') + ->andWhere(['s.store_id' => $storeIds]) + ->andWhere(['between', 's.date', "{$startDate} 00:00:00", "{$endDate} 23:59:59"]) + ->groupBy('sp.product_id') + ->having(['=', new \yii\db\Expression('COUNT(DISTINCT s.store_id)'), $countStores]) + ->column(); + + if (empty($productIds)) { + Yii::$app->session->setFlash('info', 'Нет товаров, удовлетворяющих условиям.'); + return $this->render('add-activity', [ + 'historyDays' => $historyDays, + 'intervalMonths' => $intervalMonths, + ]); + } + + $now = new \DateTime(); + $from = (clone $now)->modify("-{$intervalMonths} months") + ->modify('first day of this month')->setTime(0,0,0) + ->format('Y-m-d H:i:s'); + $to = (clone $now)->modify("+{$intervalMonths} months") + ->modify('last day of this month')->setTime(23,59,59) + ->format('Y-m-d H:i:s'); + + $userId = Yii::$app->user->id; + $createdAt = date('Y-m-d H:i:s'); + $rows = []; + foreach ($productIds as $pid) { + $rows[] = [ + 'guid' => $pid, + 'date_from' => $from, + 'date_end' => $to, + 'active' => 1, + 'created_at' => $createdAt, + 'created_by' => $userId, + ]; + } + + Yii::$app->db->createCommand() + ->batchInsert( + Products1cNomenclatureActuality::tableName(), + ['guid','date_from','date_end','active','created_at','created_by'], + $rows + ) + ->execute(); + + Yii::$app->session->setFlash('success', 'Таблица актуальности заполнена.'); + return $this->render('add-activity', [ + 'historyDays' => $historyDays, + 'intervalMonths' => $intervalMonths, + ]); + } + /** diff --git a/erp24/views/products1c-nomenclature-actuality/add-activity.php b/erp24/views/products1c-nomenclature-actuality/add-activity.php new file mode 100644 index 00000000..035f02d2 --- /dev/null +++ b/erp24/views/products1c-nomenclature-actuality/add-activity.php @@ -0,0 +1,35 @@ +title = 'Заполнить актуальность'; +?> +
+

title) ?>

+ + 'get', + 'action' => ['add-activity'], + 'options' => ['class' => 'form-inline'], +]); ?> + +
+
+ field(new \yii\base\DynamicModel(['historyDays'=>$historyDays]), 'historyDays') + ->textInput(['type'=>'number','min'=>1,'value'=>$historyDays]) + ->label('История (дней)') ?> +
+
+ field(new \yii\base\DynamicModel(['intervalMonths'=>$intervalMonths]), 'intervalMonths') + ->textInput(['type'=>'number','min'=>1,'value'=>$intervalMonths]) + ->label('Интервал (месяцы)') ?> +
+
+ 'btn btn-success']) ?> +
+ +
\ No newline at end of file