From: Vladimir Fomichev Date: Thu, 4 Sep 2025 07:07:30 +0000 (+0300) Subject: Кнопка очистки X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=0bf694620cccfc291630741f559ff75ef04cbd6b;p=erp24_rep%2Fyii-erp24%2F.git Кнопка очистки --- diff --git a/erp24/controllers/Products1cNomenclatureActualityController.php b/erp24/controllers/Products1cNomenclatureActualityController.php index 4de295f4..e6efb5fe 100644 --- a/erp24/controllers/Products1cNomenclatureActualityController.php +++ b/erp24/controllers/Products1cNomenclatureActualityController.php @@ -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. diff --git a/erp24/views/products1c-nomenclature-actuality/index.php b/erp24/views/products1c-nomenclature-actuality/index.php index 6aa70cef..70667730 100644 --- a/erp24/views/products1c-nomenclature-actuality/index.php +++ b/erp24/views/products1c-nomenclature-actuality/index.php @@ -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 ? '
+ +
' : ''; + $inputs = '
'; + $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 .= '
'; return $inputs; } ], diff --git a/erp24/web/js/products1cNomenclatureActuality/index.js b/erp24/web/js/products1cNomenclatureActuality/index.js index 8316b9b7..a1e89bdd 100644 --- a/erp24/web/js/products1cNomenclatureActuality/index.js +++ b/erp24/web/js/products1cNomenclatureActuality/index.js @@ -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('Произошла ошибка при удалении'); + } + }); + }); + });