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;
],
]);
+ $productPrice = Prices::find()
+ ->select(['price'])
+ ->where(['product_id' => $id])
+ ->one();
$replacements = $replacementsQuery->all();
$lastLogs = [];
->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,
];
}
}
'model' => $this->findModelByGuid($id),
'replacements' => $replacementsDataProvider,
'lastLogs' => $lastLogs,
+ 'productPrice' => $productPrice,
]);
}
/** @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']];
?>
<div class="product1-creplacement-view p-4">
<?= Html::a('Назад', ['index'], ['class' => 'btn btn-danger mb-4']) ?>
- <h1>Замены для <?= Html::encode($this->title) ?></h1>
+ <div class="d-flex py-4 align-items-center gap-3">
+ <h1>Замены для <?= Html::encode($this->title) ?> </h1>
+ <button class="btn btn-small btn-primary mb-4 mx-3-3">
+ Цена: <?= Html::encode($productPrice->price ?? 'Нет данных' ) ?>
+ </button>
+ </div>
+
<p>
<?= Html::a('Редактировать', ['update', 'id' => $model->guid], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Просмотр логов', ['log-history', 'guid' => $model->guid], ['class' => 'btn btn-success']) ?>
</p>
<div id="grid-container">
- <?= GridView::widget([
- 'dataProvider' => $replacements,
- 'columns' => [
- [
- 'label' => 'GUIDы замены',
- 'attribute' => 'replacement_guid',
- 'value' => function ($model) {
+ <?= GridView::widget([
+ 'dataProvider' => $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 '<span style="color:red"> Нет данных</span>';
+ },
+ 'format' => 'raw',
+ ],
+ [
+ 'label' => 'Разница цены',
+ 'value' => function ($model) use ($lastLogs) {
+ if (isset($lastLogs[$model->id]['priceDifference'])) {
+ return Html::encode($lastLogs[$model->id]['priceDifference']);
+ }
+ return '<span style="color:red"> Нет данных</span>';
+ },
+ 'format' => 'raw',
+ ],
+ [
+ 'label' => 'Последнее редактирование',
+ 'value' => function ($model) use ($lastLogs) {
+ if (isset($lastLogs[$model->id]['lastLog'])) {
+ return Html::encode($lastLogs[$model->id]['lastLog']->date);
+ }
+ return '<span style="color:red"> Нет данных</span>';
+ },
+ 'format' => 'raw',
+ ],
+ [
+ 'label' => 'Пользователь',
+ 'value' => function ($model) use ($lastLogs) {
+ if (isset($lastLogs[$model->id]['adminName'])) {
+ return Html::encode($lastLogs[$model->id]['adminName']);
+ }
+ return '<span style="color:red">Неизвестно</span>';
+ },
+ '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',
- ],
-
- ],
- ]);
-
+ ]);
- ?>
+ ?>
</div>