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;
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.
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');
$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);
}
'style' => 'width:auto;display:inline-block'
]),
['class'=>'d-flex align-items-center']
- );
+ ) . $clearBtn ;
+ $inputs .= '</div>';
return $inputs;
}
],
}
}
+ $(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('Произошла ошибка при удалении');
+ }
+ });
+ });
+
});