$model = BouquetComposition::findModel($id);
if (Yii::$app->request->isPost && $products = Yii::$app->request->post('products_quantity')) {
- $cost = Yii::$app->request->post('cost-value');
- $model->setCost($cost);
+ $cost = Yii::$app->request->post("cost-value");
+ foreach ($cost as $region_id => $price) {
+ $model->setCost($region_id, $price);
+ }
BouquetCompositionProducts::updateProducts($model->id, $products);
return $this->redirect(['view', 'id' => $id]);
}
return [
'selfcost' => round($model->getSelfCost($data), 2),
- 'cost' => round($model->getBouquetCost($data, true)),
- 'markup' => round($model->getBouquetCostMarkup($data, true), 2),
+ 'cost' => [
+ 52 => round($model->getBouquetCost(52, $data, true)),
+ 77 => round($model->getBouquetCost(77, $data, true)),
+ ],
+ 'markup' => [
+ 52 => round($model->getBouquetCostMarkup(52, $data, true), 2),
+ 77 => round($model->getBouquetCostMarkup(77, $data, true), 2),
+ ]
];
}
// return $cost;
// }
- public function setCost($cost) {
+ public function setCost($region_id, $cost) {
$priceModel = PricesDynamic::find()
- ->where(['product_id' => $this->guid])
+ ->where(['product_id' => $this->guid, 'region_id' => $region_id])
->andWhere(['=', 'active', PricesDynamic::ACTIVE])
->one();
/* @var PricesDynamic $priceModel */
$newPriceDynamic->date_from = date('Y-m-d H:i:s');
$newPriceDynamic->date_to = date('2100-01-01 00:00:00');
$newPriceDynamic->price = round($cost);
+ $newPriceDynamic->region_id = $region_id;
$newPriceDynamic->save();
}
- public function getBouquetCost($data = null, $forceDefault = false) {
+ public function getBouquetCost($region_id, $data = null, $forceDefault = false) {
$priceModel = PricesDynamic::find()
- ->where(['product_id' => $this->guid])
+ ->where(['product_id' => $this->guid, 'region_id' => $region_id])
->andWhere(['=', 'active', PricesDynamic::ACTIVE])
->one();
/* @var PricesDynamic $priceModel */
return $priceModel && !$forceDefault ? $priceModel->price : $this->getSelfCost($data) * 1.3 * 1.15;
}
- public function getBouquetCostMarkup($data = null, $forceDefault = false) {
+ public function getBouquetCostMarkup($region_id, $data = null, $forceDefault = false) {
$selfCost = $this->getSelfCost($data);
- return $selfCost > 0 ? ($this->getBouquetCost($data, $forceDefault) / (1.3 * $selfCost) - 1) * 100 : 0;
+ return $selfCost > 0 ? ($this->getBouquetCost($region_id, $data, $forceDefault) / (1.3 * $selfCost) - 1) * 100 : 0;
}
// /**
<div class="row">
<div class="col-md-6 position-relative">
+ <h4>Нижегородская обл.</h4>
<div class="pt-2 position-relative content-wrapper">
<div class="loader-overlay d-none">
<div class="spinner-border text-primary" role="status"></div>
</div>
<p class="mb-1"><strong>Себестоимость:</strong> <span class="selfcost-value"><?= round($selfCost ?? 0) ?></span> ₽</p>
<p class="mb-1"><strong>Наценка:</strong> +30% / +<span class="markup-value"><?= round(0.3 * ($selfCost ?? 0)) ?></span>₽</p>
- <p class="mb-0"><strong>Цена:</strong> <input type="number" name="cost-value" class="cost-value" value="<?= round($cost) ?>"
- min="<?= round(1.3 * ($selfCost ?? 0)) ?>" step="1" />₽. +<span class="markup-cost-value"><?= round($markUp, 2) ?></span>%</p>
+ <p class="mb-0"><strong>Цена:</strong> <input type="number" name="cost-value[52]" class="cost-value region52" value="<?= round($cost[52]) ?>"
+ min="<?= round(1.3 * ($selfCost ?? 0)) ?>" step="1" />₽. +<span class="markup-cost-value region52"><?= round($markUp[52], 2) ?></span>%</p>
</div>
</div>
- <div class="col-md-2"></div>
+</div>
+
+<div class="row mt-5">
+ <div class="col-md-6 position-relative">
+ <h4>Московская обл.</h4>
+ <div class="pt-2 position-relative content-wrapper">
+ <div class="loader-overlay d-none">
+ <div class="spinner-border text-primary" role="status"></div>
+ </div>
+ <p class="mb-1"><strong>Себестоимость:</strong> <span class="selfcost-value"><?= round($selfCost ?? 0) ?></span> ₽</p>
+ <p class="mb-1"><strong>Наценка:</strong> +30% / +<span class="markup-value"><?= round(0.3 * ($selfCost ?? 0)) ?></span>₽</p>
+ <p class="mb-0"><strong>Цена:</strong> <input type="number" name="cost-value[77]" class="cost-value region77" value="<?= round($cost[77]) ?>"
+ min="<?= round(1.3 * ($selfCost ?? 0)) ?>" step="1" />₽. +<span class="markup-cost-value region77"><?= round($markUp[77], 2) ?></span>%</p>
+ </div>
+ </div>
<?php if (!$isCreate) {?>
<div class="col-md-2 d-flex justify-content-end align-items-end px-3 w-100">
<?= Html::button('Рассчитать', ['class' => 'btn btn-warning calculate-btn w-100']) ?>
</div>
- <div class="col-md-2 d-flex justify-content-end align-items-end px-3 w-100">
- <?= Html::submitButton('Сохранить', ['class' => 'btn btn-success w-100', 'disabled' => BouquetComposition::disabledButtons()]) ?>
- </div>
+ <div class="col-md-2 d-flex justify-content-end align-items-end px-3 w-100">
+ <?= Html::submitButton('Сохранить', ['class' => 'btn btn-success w-100', 'disabled' => BouquetComposition::disabledButtons()]) ?>
+ </div>
<?php } else { ?>
<div class="col-md-4 d-flex justify-content-end align-items-end px-3 w-100">
<?= Html::button('Рассчитать', ['class' => 'btn btn-warning calculate-btn w-100']) ?>
</div>
<?php } ?>
+
</div>
+
<style>
.content-wrapper {
position: relative;
<div class="row pt-3">
<div class="col-md-8">
- <strong>Нижегородская область</strong>
+ <strong>Нижегородская обл.</strong>
<div class='self-cost pt-3' style='display: flex; gap: 10px;'>
Себестоимость: <?= round($model->getSelfCost()) ?>₽<br>
Наценка: +30% / +<?= round(0.3 * $model->getSelfCost()) ?>₽<br>
- Цена: <?= round($model->getBouquetCost()) ?>₽. +<?= round($model->getBouquetCostMarkup(), 2) ?>%<br>
+ Цена: <?= round($model->getBouquetCost(52)) ?>₽. +<?= round($model->getBouquetCostMarkup(52), 2) ?>%<br>
+ </div>
+ </div>
+</div>
+
+<div class="row pt-3">
+ <div class="col-md-8">
+ <strong>Московская обл.</strong>
+ <div class='self-cost pt-3' style='display: flex; gap: 10px;'>
+ Себестоимость: <?= round($model->getSelfCost()) ?>₽<br>
+ Наценка: +30% / +<?= round(0.3 * $model->getSelfCost()) ?>₽<br>
+ Цена: <?= round($model->getBouquetCost(77)) ?>₽. +<?= round($model->getBouquetCostMarkup(77), 2) ?>%<br>
</div>
</div>
<div class="col-md-4">
style='height: 160px; padding: 10px; overflow-y: auto; overflow-x: hidden; max-width: 100%; word-wrap: break-word;'>
{$compositionHtml}
</div>
+ <strong>Нижегородская обл.</strong>
+ <div class='self-cost pt-3 mb-2' style='display: flex; gap: 10px;'>
+ Себестоимость: " . round($model->getSelfCost()) . "₽<br>
+ Наценка: +30% / +" . round(0.3 * $model->getSelfCost()) . "₽<br>
+ Цена: " . round($model->getBouquetCost(52)) . "₽. +" . round($model->getBouquetCostMarkup(52), 2) . "%<br>
+ </div>
+ <strong>Московская обл.</strong>
<div class='self-cost pt-3' style='display: flex; gap: 10px;'>
Себестоимость: " . round($model->getSelfCost()) . "₽<br>
Наценка: +30% / +" . round(0.3 * $model->getSelfCost()) . "₽<br>
- Цена: " . round($model->getBouquetCost()) . "₽. +" . round($model->getBouquetCostMarkup(), 2) . "%<br>
+ Цена: " . round($model->getBouquetCost(77)) . "₽. +" . round($model->getBouquetCostMarkup(77), 2) . "%<br>
</div>
</div>
'isCreate' => false,
'listContainerSize' => [],
'selfCost' => $model->getSelfCost(),
- 'cost' => $model->getBouquetCost(),
- 'markUp' => $model->getBouquetCostMarkup(),
+ 'cost' => [ 52 => $model->getBouquetCost(52), 77 => $model->getBouquetCost(77)],
+ 'markUp' => [ 52 => $model->getBouquetCostMarkup(52), 77 => $model->getBouquetCostMarkup(77)],
]); ?>
<?php ActiveForm::end(); ?>
</div>
\ No newline at end of file
$('.cost-value').on('change', function () {
- const selfCost = $('.selfcost-value');
- $('.markup-cost-value').text(+selfCost.text() > 0 ? Math.round((this.value / (1.3 * (+selfCost.text())) - 1)*10000) / 100 : 0);
+ const root = $(this).parent().parent();
+ const selfCost = root.find('.selfcost-value');
+ root.find('.markup-cost-value').text(+selfCost.text() > 0 ? Math.round((this.value / (1.3 * (+selfCost.text())) - 1)*10000) / 100 : 0);
});
$('.calculate-btn').on('click', function () {
dataType: 'json',
success: function (response) {
if (response) {
- if (response.cost !== undefined) {
- $('.cost-value').val(+response.cost);
+ if (response.cost[52] !== undefined) {
+ $('.cost-value.region52').val(+response.cost[52]);
+ }
+ if (response.cost[77] !== undefined) {
+ $('.cost-value.region77').val(+response.cost[77]);
}
if (response.selfcost !== undefined) {
$('.selfcost-value').text(Math.round(response.selfcost));
$('.markup-value').text(Math.round(0.3 * (+response.selfcost)));
$('.cost-value').attr('min', Math.round(1.3 * (+response.selfcost)));
}
- if (response.markup !== undefined) {
- $('.markup-cost-value').text(Math.round(+response.markup));
+ if (response.markup[52] !== undefined) {
+ $('.markup-cost-value.region52').text(Math.round(+response.markup[52]));
+ }
+ if (response.markup[77] !== undefined) {
+ $('.markup-cost-value.region77').text(Math.round(+response.markup[77]));
}
}
},