From: fomichev Date: Fri, 6 Dec 2024 10:22:25 +0000 (+0300) Subject: Добавление цен во вью X-Git-Tag: 1.7~93^2~6 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=64fe49a56d5ea9598a071a3838d44f9ed5dcc9f5;p=erp24_rep%2Fyii-erp24%2F.git Добавление цен во вью --- diff --git a/erp24/controllers/crud/Product1cReplacementController.php b/erp24/controllers/crud/Product1cReplacementController.php index 204851df..615d2b8a 100644 --- a/erp24/controllers/crud/Product1cReplacementController.php +++ b/erp24/controllers/crud/Product1cReplacementController.php @@ -6,6 +6,7 @@ use Yii; use yii\behaviors\TimestampBehavior; use yii\data\ActiveDataProvider; use yii_app\records\Admin; +use yii_app\records\Prices; use yii_app\records\Product1cReplacement; use yii_app\records\Product1cReplacementLog; use yii_app\records\Product1cReplacementSearch; @@ -92,6 +93,10 @@ class Product1cReplacementController extends Controller ], ]); + $productPrice = Prices::find() + ->select(['price']) + ->where(['product_id' => $id]) + ->one(); $replacements = $replacementsQuery->all(); $lastLogs = []; @@ -101,18 +106,28 @@ class Product1cReplacementController extends Controller ->orderBy(['date' => SORT_DESC]) ->one(); - if ($lastLog) { + $productReplacementPrice = Prices::find() + ->select(['price']) + ->where(['product_id' => $replacement->guid_replacement]) + ->one(); + + $priceDifference = null; + if ($productPrice !== null && $productReplacementPrice !== null) { + $priceDifference = $productPrice - $productReplacementPrice->price; + } + if ($lastLog) { $adminName = null; if ($lastLog->admin_id) { $admin = Admin::findOne($lastLog->admin_id); $adminName = $admin ? $admin->name : 'Неизвестно'; } - $lastLogs[$replacement->id] = [ 'lastLog' => $lastLog, 'adminName' => $adminName, + 'productReplacementPrice' => $productReplacementPrice, + 'priceDifference' => $priceDifference, ]; } } @@ -121,6 +136,7 @@ class Product1cReplacementController extends Controller 'model' => $this->findModelByGuid($id), 'replacements' => $replacementsDataProvider, 'lastLogs' => $lastLogs, + 'productPrice' => $productPrice, ]); } diff --git a/erp24/views/crud/product1c-replacement/view.php b/erp24/views/crud/product1c-replacement/view.php index babebf2d..54fe0c69 100644 --- a/erp24/views/crud/product1c-replacement/view.php +++ b/erp24/views/crud/product1c-replacement/view.php @@ -9,6 +9,7 @@ use yii_app\records\Products1c; /** @var yii_app\records\Product1cReplacement $model */ /** @var yii\data\ActiveDataProvider $replacements */ /** @var array $lastLogs */ +/** @var array $productPrice */ $this->title = $model->product->name; $this->params['breadcrumbs'][] = ['label' => 'Product1c Replacements', 'url' => ['index']]; @@ -19,58 +20,82 @@ $this->params['breadcrumbs'][] = $this->title; ?>
'btn btn-danger mb-4']) ?> -

Замены для title) ?>

+
+

Замены для title) ?>

+ +
+

$model->guid], ['class' => 'btn btn-primary']) ?> $model->guid], ['class' => 'btn btn-success']) ?>

- $replacements, - 'columns' => [ - [ - 'label' => 'GUIDы замены', - 'attribute' => 'replacement_guid', - 'value' => function ($model) { + $replacements, + 'columns' => [ + [ + 'label' => 'GUIDы замены', + 'attribute' => 'replacement_guid', + 'value' => function ($model) { + $product = Products1c::findOne(['id' => $model->guid_replacement, 'tip' => 'products']); + if ($product) { + $code = $product->code ? $product->code : ''; + $articule = $product->articule ? (', ' . $product->articule) : ''; + return Html::encode($product->name . ' (' . $code . $articule . ')'); + } + return Html::encode($model->guid_replacement); + }, + 'format' => 'raw', + ], + [ + 'label' => 'Цена товара', + 'value' => function ($model) use ($lastLogs) { + if (isset($lastLogs[$model->id]['productReplacementPrice'])) { + return Html::encode($lastLogs[$model->id]['productReplacementPrice']->price); + } + return ' Нет данных'; + }, + 'format' => 'raw', + ], + [ + 'label' => 'Разница цены', + 'value' => function ($model) use ($lastLogs) { + if (isset($lastLogs[$model->id]['priceDifference'])) { + return Html::encode($lastLogs[$model->id]['priceDifference']); + } + return ' Нет данных'; + }, + 'format' => 'raw', + ], + [ + 'label' => 'Последнее редактирование', + 'value' => function ($model) use ($lastLogs) { + if (isset($lastLogs[$model->id]['lastLog'])) { + return Html::encode($lastLogs[$model->id]['lastLog']->date); + } + return ' Нет данных'; + }, + 'format' => 'raw', + ], + [ + 'label' => 'Пользователь', + 'value' => function ($model) use ($lastLogs) { + if (isset($lastLogs[$model->id]['adminName'])) { + return Html::encode($lastLogs[$model->id]['adminName']); + } + return 'Неизвестно'; + }, + 'format' => 'raw', + ], - $product = Products1c::findOne(['id' => $model->guid_replacement, 'tip' => 'products']); - if ($product) { - $code = $product->code ? $product->code : ''; - $articule = $product->articule ? (', ' . $product->articule) : ''; - return Html::encode($product->name . ' (' . $code . $articule . ')'); - } - return Html::encode($model->guid_replacement); - }, - 'format' => 'raw', - ], - [ - 'label' => 'Последнее редактирование', - 'value' => function ($model) use ($lastLogs) { - if (isset($lastLogs[$model->id])) { - return Html::encode($lastLogs[$model->id]['lastLog']->date); - } - return 'Нет данных'; - }, - 'format' => 'raw', ], - [ - 'label' => 'Пользователь', - 'value' => function ($model) use ($lastLogs) { - if (isset($lastLogs[$model->id])) { - return Html::encode($lastLogs[$model->id]['adminName']); - } - return 'Неизвестно'; - }, - 'format' => 'raw', - ], - - ], - ]); - + ]); - ?> + ?>