$data = $categoryPlan[$type]['offline'];
$p1 = $offline_sale <= 0 ? 0 : 1.0 * $data / $offline_sale * 100;
?>
- <td data-p1 data-offline="<?= $offline_sale ?>"><?= number_format($p1, 0, '.', ' ') ?>%</td>
+ <td data-p1 data-offline="<?= $offline_sale ?>"><?= Html::textInput('p1', number_format($p1, 0, '.', ''), ['type' => 'number', 'style' => 'max-width: 80px;', 'readonly' => !$isEditable, 'onchange' => 'editProcent(this, 1);']) ?>%</td>
<td><?= Html::textInput('offline', number_format($categoryPlan[$type]['offline'], 0, '.', ''), ['type' => 'number', 'readonly' => !$isEditable, 'onchange' => 'editField(this);']) ?></td>
<?php
$data2 = $categoryPlan[$type]['internet_shop'];
$p2 = $online_sale <= 0 ? 0 : $data2 / $online_sale * 100;
?>
- <td data-p2 data-online="<?= $online_sale ?>"><?= number_format($p2, 0, '.', ' ') ?>%</td>
+ <td data-p2 data-online="<?= $online_sale ?>"><?= Html::textInput('p2', number_format($p2, 0, '.', ''), ['type' => 'number', 'style' => 'max-width: 80px;', 'readonly' => !$isEditable, 'onchange' => 'editProcent(this, 2);']) ?>%</td>
<td><?= Html::textInput('internet_shop', number_format($categoryPlan[$type]['internet_shop'], 0, '.', ''), ['type' => 'number', 'readonly' => !$isEditable, 'onchange' => 'editField(this);']) ?></td>
<?php //<td></td><td></td> ?>
<?php
$data4 = $categoryPlan[$type]['write_offs'];
$p3 = $write_offs <= 0 ? 0 : $data4 / $write_offs * 100;
?>
- <td data-p3 data-writeoffs="<?= $write_offs ?>"><?= number_format($p3, 0, '.', ' ') ?>%</td>
+ <td data-p3 data-writeoffs="<?= $write_offs ?>"><?= Html::textInput('p3', number_format($p3, 0, '.', ''), ['type' => 'number', 'style' => 'max-width: 80px;', 'readonly' => !$isEditable, 'onchange' => 'editProcent(this, 3);']) ?>%</td>
<td><?= Html::textInput('write_offs', number_format($categoryPlan[$type]['write_offs'], 0, '.', ''), ['type' => 'number', 'readonly' => !$isEditable, 'onchange' => 'editField(this);']) ?></td>
</tr>
<?php endforeach; ?>
const p1 = tr.querySelector("[data-p1]");
const p2 = tr.querySelector("[data-p2]");
const p3 = tr.querySelector("[data-p3]");
- p1.textContent = (p1.dataset.offline > 0 ? Math.round(100.0 * offline / +p1.dataset.offline) : 0) + '%';
- p2.textContent = (p2.dataset.online > 0 ? Math.round(100.0 * internet_shop / +p2.dataset.online) : 0) + '%';
- p3.textContent = (p3.dataset.writeoffs > 0 ? Math.round(100.0 * write_offs / +p3.dataset.writeoffs) : 0) + '%';
+ p1.querySelector('input').value = (p1.dataset.offline > 0 ? Math.round(100.0 * offline / +p1.dataset.offline) : 0);
+ p2.querySelector('input').value = (p2.dataset.online > 0 ? Math.round(100.0 * internet_shop / +p2.dataset.online) : 0);
+ p3.querySelector('input').value = (p3.dataset.writeoffs > 0 ? Math.round(100.0 * write_offs / +p3.dataset.writeoffs) : 0);
$.ajax({
method: "POST",
}
}
+function editProcent(zis, num) {
+ const tr = zis.parentNode.parentNode;
+ const p1 = tr.querySelector("[data-p1]");
+ const p2 = tr.querySelector("[data-p2]");
+ const p3 = tr.querySelector("[data-p3]");
+ switch (num) {
+ case 1: tr.querySelector("input[name=offline]").value = Math.round(p1.querySelector('input').value / 100.0 * (+p1.dataset.offline)); break;
+ case 2: tr.querySelector("input[name=internet_shop]").value = Math.round(p2.querySelector('input').value / 100.0 * (+p2.dataset.online)); break;
+ case 3: tr.querySelector("input[name=write_offs]").value = Math.round(p3.querySelector('input').value / 100.0 * (+p3.dataset.writeoffs)); break;
+ }
+ editField(zis);
+}
+
$(document).ready(() => {
$('#categoryPlan').DataTable({
sorting: false,