From f7ec0e04e4472d93ef77ac2d24dbaefbcfd85a8e Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Fri, 11 Oct 2024 12:43:54 +0300 Subject: [PATCH] =?utf8?q?[ERP-222]=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84?= =?utf8?q?=D0=B5=D0=B9=D1=81=20=D0=B8=20=D0=B0=D0=BF=D0=B8=20=D0=B4=D0=BB?= =?utf8?q?=D1=8F=20=D0=BF=D0=BE=D0=B4=D0=BF=D0=B8=D1=81=D0=BA=D0=B8=20?= =?utf8?q?=D0=BD=D0=B0=20=D0=BE=D1=82=D1=87=D1=91=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../weeklyReport/SubscriptionAction.php | 54 +++++++++++++++++++ .../v1/controllers/WeeklyReportController.php | 12 +++++ erp24/controllers/WeeklyReportController.php | 15 ++++++ ...reate_table_weekly_report_subscribtion.php | 32 +++++++++++ erp24/records/WeeklyReportSubscription.php | 50 +++++++++++++++++ erp24/views/weekly-report/subscription.php | 53 ++++++++++++++++++ erp24/web/js/weekly-report/subscription.js | 38 +++++++++++++ 7 files changed, 254 insertions(+) create mode 100644 erp24/actions/weeklyReport/SubscriptionAction.php create mode 100644 erp24/api3/modules/v1/controllers/WeeklyReportController.php create mode 100644 erp24/controllers/WeeklyReportController.php create mode 100755 erp24/migrations/m241010_150710_create_table_weekly_report_subscribtion.php create mode 100644 erp24/records/WeeklyReportSubscription.php create mode 100644 erp24/views/weekly-report/subscription.php create mode 100644 erp24/web/js/weekly-report/subscription.js diff --git a/erp24/actions/weeklyReport/SubscriptionAction.php b/erp24/actions/weeklyReport/SubscriptionAction.php new file mode 100644 index 00000000..a960a502 --- /dev/null +++ b/erp24/actions/weeklyReport/SubscriptionAction.php @@ -0,0 +1,54 @@ +request->isPost) { + $action = Yii::$app->request->post('action'); + if ($action == "addNew") { + $name = Yii::$app->request->post('name'); + $chatId = Yii::$app->request->post('chat_id'); + + $sub = new WeeklyReportSubscription; + $sub->name = $name; + $sub->chat_id = $chatId; + $sub->active = 0; + + $sub->save(); + if ($sub->getErrors()) { + throw new \Exception(Json::encode($sub->getErrors())); + } + return $this->controller->redirect('subscription'); + } + if ($action == "changeSub") { + $subId = Yii::$app->request->post('id'); + $name = Yii::$app->request->post('name'); + $chatId = Yii::$app->request->post('chatId'); + $active = Yii::$app->request->post('active'); + + $sub = WeeklyReportSubscription::findOne($subId); + $sub->name = $name; + $sub->chat_id = $chatId; + $sub->active = $active; + $sub->save(); + if ($sub->getErrors()) { + throw new \Exception(Json::encode($sub->getErrors())); + } + + return 'ok'; + } + } + + $subscriptions = WeeklyReportSubscription::find()->orderBy(['id' => SORT_DESC])->all(); + + return $this->controller->render('subscription', compact('subscriptions')); + } +} \ No newline at end of file diff --git a/erp24/api3/modules/v1/controllers/WeeklyReportController.php b/erp24/api3/modules/v1/controllers/WeeklyReportController.php new file mode 100644 index 00000000..d114d78d --- /dev/null +++ b/erp24/api3/modules/v1/controllers/WeeklyReportController.php @@ -0,0 +1,12 @@ +where(['active' => 1])->all(); + } +} \ No newline at end of file diff --git a/erp24/controllers/WeeklyReportController.php b/erp24/controllers/WeeklyReportController.php new file mode 100644 index 00000000..377ee09d --- /dev/null +++ b/erp24/controllers/WeeklyReportController.php @@ -0,0 +1,15 @@ + \yii_app\actions\weeklyReport\SubscriptionAction::class, + ]; + } +} \ No newline at end of file diff --git a/erp24/migrations/m241010_150710_create_table_weekly_report_subscribtion.php b/erp24/migrations/m241010_150710_create_table_weekly_report_subscribtion.php new file mode 100755 index 00000000..eadf9016 --- /dev/null +++ b/erp24/migrations/m241010_150710_create_table_weekly_report_subscribtion.php @@ -0,0 +1,32 @@ +createTable(self::TABLE_NAME, [ + 'id' => $this->primaryKey(), + 'name' => $this->string(36)->notNull()->comment('Имя пользователя'), + 'chat_id' => $this->integer()->notNull()->comment('chat_id пользователя'), + 'active' => $this->tinyInteger()->notNull()->defaultValue(0)->comment('0 - не активен, 1 - активен') + ]); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropTable(self::TABLE_NAME); + } +} diff --git a/erp24/records/WeeklyReportSubscription.php b/erp24/records/WeeklyReportSubscription.php new file mode 100644 index 00000000..a4522d06 --- /dev/null +++ b/erp24/records/WeeklyReportSubscription.php @@ -0,0 +1,50 @@ + null], + [['chat_id', 'active'], 'integer'], + [['name'], 'string', 'max' => 36], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'name' => 'Name', + 'chat_id' => 'Chat ID', + 'active' => 'Active', + ]; + } +} diff --git a/erp24/views/weekly-report/subscription.php b/erp24/views/weekly-report/subscription.php new file mode 100644 index 00000000..64cc061b --- /dev/null +++ b/erp24/views/weekly-report/subscription.php @@ -0,0 +1,53 @@ +registerJsFile('/js/weekly-report/subscription.js', ['position' => \yii\web\View::POS_END]); + +?> + +
+ + + +
+
+ Имя: + chat_id: 'number'])?> +
+
+ 'btn btn-success btn-sm', 'name' => 'action', 'value' => 'addNew'])?> +
+
+ + + +
+
+ + + + + + + + + + + + + + + + + +
Имяchat_idАктивен
active == 1 ? 'checked="checked"' : '' ?> onclick="saveChanges(this)" />
+
+
+ +
diff --git a/erp24/web/js/weekly-report/subscription.js b/erp24/web/js/weekly-report/subscription.js new file mode 100644 index 00000000..185a4383 --- /dev/null +++ b/erp24/web/js/weekly-report/subscription.js @@ -0,0 +1,38 @@ +/* jshint esversion: 6 */ + +const param23 = $('meta[name=csrf-param]').attr('content'); +const token23 = $('meta[name=csrf-token]').attr('content'); + +$(document).ready(() => { + $("#subscriptionTable").DataTable({ + sorting: false, + info: false, + paging: true, + searching: true, + language: data_table_language + }) +}) + +function saveChanges(self) { + const root = $(self).parent().parent(); + const id = root.data('id'); + const name = root.find('input[type=text]'); + const chatId = root.find('input[type=number]'); + const active = root.find('input[type=checkbox]'); + $.ajax({ + url: window.location.href, + method: 'post', + data: { + action: 'changeSub', + id, + name: name.val(), + chatId: chatId.val(), + active: (active.is(':checked') ? 1 : 0), + [param23]: token23 + }, + dataType: 'text', + success: (data) => { + console.log(data); + } + }) +} \ No newline at end of file -- 2.39.5