]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-305] редактируемые проценты feature_smirnov_erp-305_response_on_category_plan
authorAlexander Smirnov <fredeom@mail.ru>
Mon, 17 Feb 2025 09:44:16 +0000 (12:44 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Mon, 17 Feb 2025 09:44:16 +0000 (12:44 +0300)
erp24/views/category-plan/index.php
erp24/web/js/category-plan/index.js

index 24615c836eedb3962bf89ffb59b65b96ab2b3193..7376ad2331b3d6c2386472d14500b76f8f0e328e 100644 (file)
@@ -186,20 +186,20 @@ input[readonly] {
                             $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; ?>
index 4734a5db424ff4110867646cda3e1d784ab65ea7..df3c96d174d6facbf5f791dc9cd4f419f3b4cb02 100644 (file)
@@ -58,9 +58,9 @@ function editField(zis) {
         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",
@@ -83,6 +83,19 @@ function editField(zis) {
     }
 }
 
+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,