]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Кнопка очистки
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 4 Sep 2025 07:07:30 +0000 (10:07 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 4 Sep 2025 07:07:30 +0000 (10:07 +0300)
erp24/controllers/Products1cNomenclatureActualityController.php
erp24/views/products1c-nomenclature-actuality/index.php
erp24/web/js/products1cNomenclatureActuality/index.js

index 4de295f449bb863e793f8546b2daf139ace1b766..e6efb5fe6a353e013ae8fa1399e4781ca4f3b537 100644 (file)
@@ -4,6 +4,7 @@ namespace app\controllers;
 
 use Yii;
 use yii\db\Query;
+use yii\web\Response;
 use yii_app\api3\modules\v1\models\Sales;
 use yii_app\records\Products1cAdditionalCharacteristics;
 use yii_app\records\Products1cNomenclature;
@@ -538,6 +539,26 @@ class Products1cNomenclatureActualityController extends Controller
         return $this->redirect(['index']);
     }
 
+    public function actionAjaxDelete($id)
+    {
+        Yii::$app->response->format = Response::FORMAT_JSON;
+
+        try {
+            $model = $this->findModel($id);
+            $model->delete();
+
+            return [
+                'success' => true,
+                'message' => 'Запись успешно удалена',
+            ];
+        } catch (\Throwable $e) {
+            return [
+                'success' => false,
+                'message' => $e->getMessage(),
+            ];
+        }
+    }
+
     /**
      * Finds the Products1cNomenclatureActuality model based on its primary key value.
      * If the model is not found, a 404 HTTP exception will be thrown.
index 6aa70cef4add5628d462e61ea1c37b9cd54a95e1..70667730b355b591739cfdfd69ee64cb3022d3e4 100644 (file)
@@ -25,8 +25,10 @@ $this->registerJsFile('/js/products1cNomenclatureActuality/index.js', ['position
 function monthList()
 {
     $list = [];
-    $start = new DateTime('2025-01');
-    $end = new DateTime('2026-12');
+    $tz  = new DateTimeZone('Europe/Moscow');
+    $now = new DateTime('now', $tz);
+    $start = (clone $now)->modify('first day of january last year');
+    $end  = (clone $now)->modify('last day of december next year');
     while ($start <= $end) {
         $key = $start->format('Y-m');
         $list[$key] = $start->format('Y‑m');
@@ -282,7 +284,11 @@ foreach ($months as $k => $v) {
                     $actuality = $row['actuality'];
                     $from = $actuality ? substr($actuality->date_from, 0, 7) : null;
                     $to   = $actuality ? substr($actuality->date_to, 0, 7)   : null;
-                    $inputs = Html::hiddenInput("actuality[$i][guid]", $product->id);
+                    $clearBtn = $actuality ? '<div class="ms-2 d-flex justify-content-center align-items-center  clear-interval-btn" data-id="' . $actuality->id . '" >
+                        <i class="fa fa-times"></i>
+                    </div>' : '';
+                    $inputs = '<div class="d-flex justify-content-center align-items-center">';
+                    $inputs .= Html::hiddenInput("actuality[$i][guid]", $product->id);
                     if ($actuality) {
                         $inputs .= Html::hiddenInput("actuality[$i][id]", $actuality->id);
                     }
@@ -300,7 +306,8 @@ foreach ($months as $k => $v) {
                             'style' => 'width:auto;display:inline-block'
                         ]),
                         ['class'=>'d-flex align-items-center']
-                    );
+                    ) . $clearBtn ;
+                    $inputs .= '</div>';
                     return $inputs;
                 }
             ],
index 8316b9b745bb3c9e9764aa1b6be620eec8341a92..a1e89bddf7c04e00a84eb0a78e20954e31c5f4ef 100644 (file)
@@ -260,6 +260,33 @@ document.addEventListener("DOMContentLoaded", () => {
         }
     }
 
+    $(document).on('click', '.clear-interval-btn', function () {
+        let btn = $(this);
+        let id = btn.data('id');
+
+        if (!confirm('Удалить запись?')) {
+            return;
+        }
+
+        $.ajax({
+            url: '/products1c-nomenclature-actuality/ajax-delete', // поменяй на свой роут
+            type: 'POST',
+            data: {id: id, _csrf: yii.getCsrfToken()},
+            success: function (response) {
+                if (response.success) {
+                    btn.closest('tr, .item-row').fadeOut(300, function () {
+                        $(this).remove();
+                    });
+                } else {
+                    alert('Ошибка: ' + response.message);
+                }
+            },
+            error: function () {
+                alert('Произошла ошибка при удалении');
+            }
+        });
+    });
+
 
 
 });