From b63f8ffb0f8c446a43cffd372cac89af5fee75d2 Mon Sep 17 00:00:00 2001 From: fomichev Date: Fri, 29 Nov 2024 15:30:20 +0300 Subject: [PATCH] =?utf8?q?=D0=A4=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B8=D1=80?= =?utf8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/controllers/ProductsController.php | 309 +++++++++++------------ erp24/records/Products1cOptions.php | 4 +- erp24/web/js/products/products-1c.js | 292 ++++++++++----------- 3 files changed, 293 insertions(+), 312 deletions(-) diff --git a/erp24/controllers/ProductsController.php b/erp24/controllers/ProductsController.php index 4d0743bd..bf79b5ff 100755 --- a/erp24/controllers/ProductsController.php +++ b/erp24/controllers/ProductsController.php @@ -4,7 +4,6 @@ namespace app\controllers; use Yii; use yii\helpers\ArrayHelper; -use yii\helpers\Html; use yii\web\Controller; use yii_app\records\ExportImportTable; use yii_app\records\Prices; @@ -18,30 +17,24 @@ use yii_app\records\ShipmentProviders; class ProductsController extends Controller { - public function actionProducts1c() { - + public function actionProducts1c() + { $id = Yii::$app->request->get('id', null); if (!empty($id)) { - $id = (int) $id; + $id = (int)$id; } - - $productsClassData = ProductsClass::find()->all(); $products_class_row = []; foreach ($productsClassData as $row) { - $products_class_row[$row->category_id][] = $row->tip; } - $pricesData = Prices::find()->all(); $prices = []; foreach ($pricesData as $row) { - $prices[$row->product_id] = $row->price; } - $groupsData = Products1c::find() ->select(['id', 'name', 'parent_id']) ->where(['tip' => 'products_group']) @@ -51,13 +44,10 @@ class ProductsController extends Controller $groups = []; $groups_arr = []; foreach ($groupsData as $row) { - $groups[$row->id] = $row->name; - $groups_arr[$row->parent_id][$row->id] = $row; } - return $this->render('products-1c', [ 'id' => $id, 'products_class_row' => $products_class_row, @@ -65,138 +55,139 @@ class ProductsController extends Controller 'groups' => $groups, 'groups_arr' => $groups_arr, ]); - - } // Старый функционал //TODO Просмотр опций - кнопку убрал - public function actionAjaxProductProvider() - { - $id = Yii::$app->request->post('id'); - if (!empty($id)) { - $id = htmlentities($id); - - - $providers = ShipmentProviders::find() - ->select(['id', 'name']) - ->indexBy('id') - // ->asArray() - ->all(); - $providers = ArrayHelper::map($providers, 'id', 'name'); - - - $data = Products1cOptions::find() - ->where(['id' => $id]) - ->one(); - - - $view = Products1c::find() - ->select('view') - ->where(['id' => $id]) - ->scalar(); - - - $productColorsArray = explode(';', $data->colors ?? ''); - - - $productGroups = [ - "1" => "Голландия/Израиль", - 2 => "Кения", - 3 => "Эквадор/Колумбия", - 4 => "Россия", - 5 => "Горшечка", - 6 => "Сопутка", - 7 => "Фейерверки", - 10 => "Матрица" - ]; - - - - $dataResponse = '
'; - $dataResponse .= '
Поставщик
-
'; + foreach ($providers as $idv => $name) { + $dataResponse .= "
"; - - - $dataResponse .= '
Основной товар?
+ } + $dataResponse .= ""; + $dataResponse .= '
Основной товар?
-
минимальный заказ в шт.
-
- -
-
Цена закупки в долл. или евро (зависит от поставщика) пример 1.25
-
- -
-
Цвета разделитель ; - -
-
Опции - -
-
-Сорта по цветам'; - - foreach($productColorsArray as $color) { - $color=trim($color); - if(!empty($color)) { - $dataResponse .= "
$color"; - } + if (empty($data['main'])) { + $dataResponse .= " selected"; + $dataResponse .= '>нет
+
минимальный лот деления в шт. (кол-во шт в месте)
+
+
+
минимальный заказ в шт.
+
+ +
+
Цена закупки в долл. или евро (зависит от поставщика) пример 1.25
+
+ +
+
Цвета разделитель ; + +
+
Опции + +
+
Сорта по цветам'; + + foreach ($productColorsArray as $color) { + $color = trim($color); + if (!empty($color)) { + $dataResponse .= "
$color"; } - $dataResponse .= '
'; - $dataResponse .= "asArray() ->all(); - if (empty($characteristics)) { return $this->asJson(['error' => 'Нет свойств для данного товара']); } - $properties = Products1cPropType::find() ->select(['id', 'name']) ->all(); $properties = ArrayHelper::map($properties, 'id', 'name'); - $result = []; foreach ($characteristics as $characteristic) { $propertyName = $properties[$characteristic['property_id']] ?? 'Неизвестное свойство'; @@ -233,15 +221,13 @@ class ProductsController extends Controller 'value' => $characteristic['value'], ]; } - return $this->asJson(['characteristics' => $result]); } - return $this->asJson(['error' => 'Некорректный запрос']); } - public function actionAjaxGroupConfig() { - + public function actionAjaxGroupConfig() + { if (Yii::$app->request->isAjax) { $id = Yii::$app->request->post('id'); if (!empty($id)) { @@ -250,14 +236,13 @@ class ProductsController extends Controller $data = ProductsClass::find()->where(['category_id' => $id])->all(); $data2 = []; + foreach ($data as $row) { $data2[$row->tip] = $id; } - $hints = ProductsClass::getHints(); - return $this->asJson([ 'id' => $id, 'data2' => $data2, @@ -270,8 +255,8 @@ class ProductsController extends Controller } - public function actionAjaxProductsInGroup() { - + public function actionAjaxProductsInGroup() + { if (Yii::$app->request->isAjax) { $parent_id = Yii::$app->request->post('parent_id'); if (!empty($parent_id)) { @@ -282,26 +267,23 @@ class ProductsController extends Controller ->alias('p') ->select(['p.id', 'p.name', 'alias.entity_id', 'p.view']) ->leftJoin(['alias' => ExportImportTable::find() - ->select(['export_id', 'export_val', 'entity', 'entity_id' ])], + ->select(['export_id', 'export_val', 'entity', 'entity_id'])], "alias.export_id::text = p.id AND alias.export_val = '1' AND alias.entity = 'products'") ->where(['p.tip' => 'products', 'p.parent_id' => $parent_id]) ->orderBy(['p.name' => SORT_ASC]) ->asArray() ->all(); - $prices = Prices::find() ->select(['product_id', 'price']) ->indexBy('product_id') ->column(); - $providers = ShipmentProviders::find() ->select(['id', 'name']) ->indexBy('id') ->column(); - $optionsData = Products1cOptions::find() ->select(['id', 'colors']) ->all(); @@ -311,18 +293,16 @@ class ProductsController extends Controller $colorsProducts[$option->id] = explode(';', $option->colors); } - $varietiesData = ProductsVarieties::find() ->select(['product_id', 'color', 'name']) ->orderBy(['posit' => SORT_DESC]) ->all(); - $dataResponse = ''; + $products_varieties = []; foreach ($varietiesData as $variety) { $products_varieties[$variety->product_id][$variety->color][] = $variety->name; } - return $this->asJson([ 'data' => $data, 'prices' => $prices, @@ -347,22 +327,18 @@ class ProductsController extends Controller $tip = Yii::$app->request->post('tip', 'wrap'); if (!empty($parent_id)) { - $productClass = ProductsClass::findOne(['category_id' => $parent_id]); if (!$productClass) { - $productClass = new ProductsClass(); $productClass->category_id = $parent_id; } - $productClass->tip = $tip; if ($productClass->save()) { return "ok"; } else { - return "Ошибка сохранения: " . implode(', ', $productClass->getFirstErrors()); } } @@ -381,10 +357,8 @@ class ProductsController extends Controller $tip = Yii::$app->request->post('tip'); if (!empty($id) && !empty($tip)) { - $productClass = ProductsClass::findOne(['category_id' => $id, 'tip' => $tip]); - if ($productClass) { if ($productClass->delete()) { return "ok"; @@ -404,15 +378,24 @@ class ProductsController extends Controller // Старый функционал //TODO Удалить - public function actionAjaxAddProduct() { return $this->renderPartial('ajax-add-product'); } + public function actionAjaxAddProduct() + { + return $this->renderPartial('ajax-add-product'); + } // Старый функционал //TODO Удалить - public function actionAjaxRemoveProduct() { return $this->renderPartial('ajax-remove-product'); } + public function actionAjaxRemoveProduct() + { + return $this->renderPartial('ajax-remove-product'); + } // Старый функционал //TODO Удалить - public function actionAjaxRemoveExport() { return $this->renderPartial('ajax-remove-export'); } + public function actionAjaxRemoveExport() + { + return $this->renderPartial('ajax-remove-export'); + } // Старый функционал //TODO Добавление поставщиков - кнопку убрал @@ -432,21 +415,18 @@ class ProductsController extends Controller $view = Yii::$app->request->post('view') === 'on' ? 1 : 0; if (!empty($id)) { - $product = Products1c::findOne(['id' => $id]); if ($product) { $product->view = $view; $product->save(); } - $productOption = Products1cOptions::findOne(['id' => $id]); if (!$productOption) { $productOption = new Products1cOptions(); $productOption->id = $id; } - $productOption->options = $options; $productOption->provider_id = $provider_id; $productOption->expiration_days = $expiration_days; @@ -457,13 +437,10 @@ class ProductsController extends Controller $productOption->group_id = $group_id; $productOption->main = $main; - // var_dump($productOption); die(); if ($productOption->save(false)) { return "Запись сохранена"; } else { $errors = $productOption->getErrors(); - - $errorMessages = []; foreach ($errors as $attribute => $messages) { foreach ($messages as $message) { @@ -471,7 +448,6 @@ class ProductsController extends Controller } } - return implode("\n", $errorMessages); } } @@ -481,7 +457,4 @@ class ProductsController extends Controller return "Некорректный запрос."; } - - - } diff --git a/erp24/records/Products1cOptions.php b/erp24/records/Products1cOptions.php index e2b19555..5c8f41c7 100644 --- a/erp24/records/Products1cOptions.php +++ b/erp24/records/Products1cOptions.php @@ -35,8 +35,8 @@ class Products1cOptions extends \yii\db\ActiveRecord { return [ - [['id', 'options', 'provider_id', 'expiration_days', 'min_lot', 'colors', 'price_zakup', 'min_order', 'group_id', 'main'], 'safe'], - [['id'], 'required'], + [['id', 'options', 'provider_id', 'expiration_days', 'min_lot', + 'colors', 'price_zakup', 'min_order', 'group_id', 'main'], 'required'], [['options', 'colors'], 'string'], [['provider_id', 'expiration_days', 'min_lot', 'min_order', 'group_id', 'main'], 'integer'], [['price_zakup'], 'number'], diff --git a/erp24/web/js/products/products-1c.js b/erp24/web/js/products/products-1c.js index ad502291..80cab8ac 100644 --- a/erp24/web/js/products/products-1c.js +++ b/erp24/web/js/products/products-1c.js @@ -1,27 +1,29 @@ //document.addEventListener('DOMContentLoaded', function () { +/* jshint esversion: 6 */ function capitalizeFirstLetter(string) { return string.charAt(0).toUpperCase() + string.slice(1) } - function ajax_product_provider(id) { - $('#modal-7').modal('show', {backdrop: 'static'}); - $('#modal-7 .modal-title').text('Поставщики'); - - const param3 = $('meta[name=csrf-param]').attr('content'); - const token3 = $('meta[name=csrf-token]').attr('content'); - - $.ajax({ - url: '/products/ajax-product-provider/', - method: 'post', - dataType: 'html', - data: {id: '' + id + '', [param3]: token3}, - success: function(data) { - $('#modal-7 .modal-body').html(data); - } - }); - } + +function ajax_product_provider(id){ + $('#modal-7').modal('show', {backdrop: 'static'}); + $('#modal-7 .modal-title').text('Поставщики'); + + const param3 = $('meta[name=csrf-param]').attr('content'); + const token3 = $('meta[name=csrf-token]').attr('content'); + + $.ajax({ + url: '/products/ajax-product-provider/', + method: 'post', + dataType: 'html', + data: {id: '' + id + '', [param3]: token3}, + success: function (data) { + $('#modal-7 .modal-body').html(data); + } + }); +} function ajax_product_characteristics(id) { - $('#modal-7').modal('show', { backdrop: 'static' }); + $('#modal-7').modal('show', {backdrop: 'static'}); $('#modal-7 .modal-title').text('Характеристики товара'); const param3 = $('meta[name=csrf-param]').attr('content'); @@ -31,14 +33,13 @@ function ajax_product_characteristics(id) { url: '/products/ajax-product-characteristics/', method: 'post', dataType: 'json', - data: { id: id, [param3]: token3 }, - success: function(response) { + data: {id: id, [param3]: token3}, + success: function (response) { if (response.error) { $('#modal-7 .modal-body').html(`

${response.error}

`); return; } - const characteristics = response.characteristics; let tableHtml = ` @@ -63,14 +64,14 @@ function ajax_product_characteristics(id) { tableHtml += '
'; $('#modal-7 .modal-body').html(tableHtml); }, - error: function() { + error: function () { $('#modal-7 .modal-body').html('

Ошибка при выполнении запроса.

'); } }); } function ajax_group_config(id) { - $('#modal-7').modal('show', { backdrop: 'static' }); + $('#modal-7').modal('show', {backdrop: 'static'}); $('#modal-7 .modal-title').text('Настройка категории'); const param3 = $('meta[name=csrf-param]').attr('content'); @@ -80,19 +81,17 @@ function ajax_group_config(id) { url: '/products/ajax-group-config/', method: 'post', dataType: 'json', - data: { id: id, [param3]: token3 }, - success: function(response) { + data: {id: id, [param3]: token3}, + success: function (response) { if (response.error) { $('#modal-7 .modal-body').html('

Ошибка: ' + response.error + '

'); return; } - let html = '
'; const classes = response.classes; const data2 = response.data2; - for (const [key, name] of Object.entries(classes)) { html += `
@@ -108,64 +107,62 @@ function ajax_group_config(id) { html += '
'; - - $('#modal-7 .modal-body').html(html); }, - error: function() { + error: function () { $('#modal-7 .modal-body').html('

Ошибка при выполнении запроса.

'); } }); } - function ajax_products_in_group(parent_id) { - const param3 = $('meta[name=csrf-param]').attr('content'); - const token3 = $('meta[name=csrf-token]').attr('content'); - - $.ajax({ - url: '/products/ajax-products-in-group/', - method: 'post', - dataType: 'json', - data: {parent_id: parent_id, [param3]: token3}, - success: function(response) { - if (response.error) { - alert(response.error); - return; - } +function ajax_products_in_group(parent_id){ + const param3 = $('meta[name=csrf-param]').attr('content'); + const token3 = $('meta[name=csrf-token]').attr('content'); - const { data, prices, providers, colorsProducts, productsVarieties } = response; + $.ajax({ + url: '/products/ajax-products-in-group/', + method: 'post', + dataType: 'json', + data: {parent_id: parent_id, [param3]: token3}, + success: function (response) { + if (response.error) { + alert(response.error); + return; + } + + const {data, prices, providers, colorsProducts, productsVarieties} = response; - let tableHtml = ''; + let tableHtml = '
'; - data.forEach((row) => { - const isHidden = row.view === 0 ? 'скрыто' : ''; - /*const providerButton = `
- + поставщика ${providers[row.id] ? providers[row.id] : ''}
`;*/ - const addCharButton = `
{ + const isHidden = row.view === 0 ? 'скрыто' : ''; + /*const providerButton = `
+ + поставщика ${providers[row.id] ? providers[row.id] : ''}
`;*/ + const addCharButton = `
Доп. характеристики
`; - let colorsHtml = ''; - if (colorsProducts[row.id]) { - colorsProducts[row.id].forEach((color) => { - color = color.trim(); - if (color) { - colorsHtml += `${color}`; - if (productsVarieties[row.id] && productsVarieties[row.id][color]) { - productsVarieties[row.id][color].forEach((variety) => { - colorsHtml += `${variety}`; - }); - } + let colorsHtml = ''; + if (colorsProducts[row.id]) { + colorsProducts[row.id].forEach((color) => { + color = color.trim(); + if (color) { + colorsHtml += `${color}`; + if (productsVarieties[row.id] && productsVarieties[row.id][color]) { + productsVarieties[row.id][color].forEach((variety) => { + colorsHtml += `${variety}`; + }); } - }); - - if (colorsHtml) { - colorsHtml += `+ добавить сорта`; } + }); + + if (colorsHtml) { + colorsHtml += `+ добавить сорта`; } + } - tableHtml += ` + tableHtml += `
`; - }); - - tableHtml += '
${row.name} ${isHidden} @@ -175,18 +172,18 @@ function ajax_group_config(id) {
'; - $(`#tr_${parent_id}`).after(`${tableHtml}`); - }, - error: function() { - alert('Ошибка при выполнении запроса.'); - }, - }); - } - -function ajax_class_group(parent_id, tip) { + }); + + tableHtml += ''; + $(`#tr_${parent_id}`).after(`${tableHtml}`); + }, + error: function () { + alert('Ошибка при выполнении запроса.'); + }, + }); +} + +function ajax_class_group(parent_id, tip){ const param3 = $('meta[name=csrf-param]').attr('content'); const token3 = $('meta[name=csrf-token]').attr('content'); @@ -194,7 +191,7 @@ function ajax_class_group(parent_id, tip) { url: '/products/ajax-class-group/', method: 'post', dataType: 'html', - data: { parent_id: parent_id, tip: tip, [param3]: token3 }, + data: {parent_id: parent_id, tip: tip, [param3]: token3}, success: function (data) { if (data === 'ok') { const button = $(`.dd${parent_id}${tip}`); @@ -213,7 +210,7 @@ function ajax_class_group(parent_id, tip) { } -function ajax_class_group_remove(id, tip) { +function ajax_class_group_remove(id, tip){ const param3 = $('meta[name=csrf-param]').attr('content'); const token3 = $('meta[name=csrf-token]').attr('content'); @@ -221,7 +218,7 @@ function ajax_class_group_remove(id, tip) { url: '/products/ajax-class-group-remove/', method: 'post', dataType: 'html', - data: { id: id, tip: tip, [param3]: token3 }, + data: {id: id, tip: tip, [param3]: token3}, success: function (data) { if (data === 'ok') { const button = $(`.dd${id}${tip}`); @@ -239,79 +236,90 @@ function ajax_class_group_remove(id, tip) { }); } - function save_providerder(){ - - const param3 = $('meta[name=csrf-param]').attr('content'); - const token3 = $('meta[name=csrf-token]').attr('content'); +function save_providerder(){ - $.ajax({ - url: '/products/ajax-product-provider-add/', - method: 'post', - dataType: 'html', - data: {id: '', - provider_id: $('#provider_id').val(), - options: $('#options').val(), - expiration_days: $('#expiration_days').val(), - min_lot: $('#min_lot').val(), - colors: $('#colors').val(), - min_order: $('#min_order').val(), - price_zakup: $('#price_zakup').val(), - group_id: $('#group_id').val() , - main: $('#main').val() , view: $('#view').val(), [param3]:token3 }, - success: function(data){ - $('#result_prov').html(data); - }}); - } + const param3 = $('meta[name=csrf-param]').attr('content'); + const token3 = $('meta[name=csrf-token]').attr('content'); + $.ajax({ + url: '/products/ajax-product-provider-add/', + method: 'post', + dataType: 'html', + data: { + id: '', + provider_id: $('#provider_id').val(), + options: $('#options').val(), + expiration_days: $('#expiration_days').val(), + min_lot: $('#min_lot').val(), + colors: $('#colors').val(), + min_order: $('#min_order').val(), + price_zakup: $('#price_zakup').val(), + group_id: $('#group_id').val(), + main: $('#main').val(), view: $('#view').val(), [param3]: token3 + }, + success: function (data) { + $('#result_prov').html(data); + } + }); +} - function ajax_add_product(id,parent_id,name,price){ - const param3 = $('meta[name=csrf-param]').attr('content'); - const token3 = $('meta[name=csrf-token]').attr('content'); +function ajax_add_product(id, parent_id, name, price) { - $.ajax({ - url: '/products/ajax-add-product/', - method: 'post', - dataType: 'html', - data: {id: ''+id+'', name: ''+name+'',parent_id: ''+parent_id+'',price: ''+price+'', [param3]:token3}, - success: function(data){ - $('#diver_'+id+'').html(data); + const param3 = $('meta[name=csrf-param]').attr('content'); + const token3 = $('meta[name=csrf-token]').attr('content'); - }}); - } - function ajax_remove_product(id){ + $.ajax({ + url: '/products/ajax-add-product/', + method: 'post', + dataType: 'html', + data: { + id: '' + id + '', + name: '' + name + '', + parent_id: '' + parent_id + '', + price: '' + price + '', + [param3]: token3 + }, + success: function (data) { + $('#diver_' + id + '').html(data); - const param3 = $('meta[name=csrf-param]').attr('content'); - const token3 = $('meta[name=csrf-token]').attr('content'); + } + }); +} - $.ajax({ - url: '/products/ajax-remove-product/', - method: 'post', - dataType: 'html', - data: {id: ''+id+'', [param3]:token3}, - success: function(data){ - $('#diver_'+id+'').html(data); +function ajax_remove_product(id) { - }}); - } + const param3 = $('meta[name=csrf-param]').attr('content'); + const token3 = $('meta[name=csrf-token]').attr('content'); + $.ajax({ + url: '/products/ajax-remove-product/', + method: 'post', + dataType: 'html', + data: {id: '' + id + '', [param3]: token3}, + success: function (data) { + $('#diver_' + id + '').html(data); - function ajaxRemoveExport(id){ + } + }); +} - const param3 = $('meta[name=csrf-param]').attr('content'); - const token3 = $('meta[name=csrf-token]').attr('content'); - $.ajax({ - url: '/products/ajax-remove-export/', - method: 'post', - dataType: 'html', - data: {id: ''+id+'', [param3]:token3}, - success: function(data){ - $('#diver2_'+id+'').html(data); +function ajaxRemoveExport(id) { - }}); - } + const param3 = $('meta[name=csrf-param]').attr('content'); + const token3 = $('meta[name=csrf-token]').attr('content'); + $.ajax({ + url: '/products/ajax-remove-export/', + method: 'post', + dataType: 'html', + data: {id: '' + id + '', [param3]: token3}, + success: function (data) { + $('#diver2_' + id + '').html(data); + } + }); +} -//}); \ No newline at end of file +//}); -- 2.39.5