]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-272] подсчёт процентов на лету
authorAlexander Smirnov <fredeom@mail.ru>
Fri, 17 Jan 2025 07:46:24 +0000 (10:46 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Fri, 17 Jan 2025 07:46:24 +0000 (10:46 +0300)
erp24/views/sales-write-offs-plan/index.php
erp24/web/js/sales-write-offs-plan/index.js

index d06647d5f6fd3c0b4e248a4c6a2951bc5c714a30..aecdec0c053eba3812507a20945b8bb3bbc82b6f 100644 (file)
@@ -90,31 +90,31 @@ function colorScheme2($p) {
                     <td><?= Html::textInput('total_sales_plan', $total_sales_plan, ['readonly' => true, 'style' => 'background: lightgray;']) ?></td>
                     <td>
                         <?= Html::hiddenInput('total_sales_fact', $total_sales_fact) ?>
-                        <span style="color:<?= colorScheme1($p1) ?>">
+                        <span class="p1" style="color:<?= colorScheme1($p1) ?>">
                             <?= number_format(round($p1 * 100), 0, '.', ' ') ?>
                         </span>%
                     </td>
                     <td><?= Html::textInput('write_offs_plan', $write_offs_plan, ['type' => 'number', 'min' => 0, 'onchange' => 'editField(this);']) ?></td>
                     <td>
-                        <span style="color:<?= colorScheme2($p2) ?>">
+                        <span class="p2" style="color:<?= colorScheme2($p2) ?>">
                             <?= number_format(round($p2 * 100), 1, '.', ' ') ?>
                         </span>%
                     </td>
                     <td><?= Html::textInput('offline_sales_plan', $offline_sales_plan, ['type' => 'number', 'min' => 0, 'onchange' => 'editField(this);']) ?></td>
                     <td>
-                        <span style="color:<?= colorScheme1($p3) ?>">
+                        <span class="p3" style="color:<?= colorScheme1($p3) ?>">
                             <?= number_format(round($p3 * 100), 0, '.', ' ') ?>
                         </span>%
                     </td>
                     <td><?= Html::textInput('online_sales_shop_plan', $online_sales_shop_plan, ['type' => 'number', 'min' => 0, 'onchange' => 'editField(this);']) ?></td>
                     <td>
-                        <span style="color:<?= colorScheme1($p4) ?>">
+                        <span class="p4" style="color:<?= colorScheme1($p4) ?>">
                             <?= number_format(round($p4 * 100), 0, '.', ' ') ?>
                         </span>%
                     </td>
                     <td><?= Html::textInput('online_sales_marketplace_plan', $online_sales_marketplace_plan, ['type' => 'number', 'min' => 0, 'onchange' => 'editField(this);']) ?></td>
                     <td>
-                        <span style="color:<?= colorScheme1($p5) ?>">
+                        <span class="p5" style="color:<?= colorScheme1($p5) ?>">
                             <?= number_format(round($p5 * 100), 0, '.', ' ') ?>
                         </span>%
                     </td>
index 3296989caadbe0b9fd006bcd5f84fae951490a8a..c2015936144aa6f7a30b6cd62fa74d9f597127e0 100644 (file)
@@ -7,6 +7,21 @@ function isNumeric(value) {
     return /^-?\d+\.?\d*$/.test(value);
 }
 
+function colorScheme1(p) {
+    p = Math.round(100 * p);
+    if (p <= 90) { return 'red'; }
+    if (p < 99) { return '#aaaa00'; }
+    return 'green';
+}
+
+function colorScheme2(p) {
+    p = Math.round(100 * p, 1);
+    if (p > 10) { return 'red'; }
+    if (p > 9) { return '#aaaa00'; }
+    return 'green';
+}
+
+
 function editField(zis) {
     const tr = zis.parentNode.parentNode;
     const store_id = tr.querySelector("[name=store_id]").value;
@@ -34,6 +49,32 @@ function editField(zis) {
     });
     if (succ) {
         total_sales_plan.value = +offline_sales_plan.value + (+online_sales_shop_plan.value) + (+online_sales_marketplace_plan.value);
+        ////////////////////////////////////////////////
+        const p1 = document.querySelector('.p1');
+        const p1Value = total_sales_fact.value > 0 ? total_sales_plan.value / total_sales_fact.value : 0;
+        p1.innerHTML = new Intl.NumberFormat().format(Number((p1Value * 100).toFixed(0)));
+        p1.style.color = colorScheme1(p1Value);
+
+        const p2 = document.querySelector('.p2');
+        const p2Value = total_sales_plan.value > 0 ? write_offs_plan.value / total_sales_plan.value : 0;
+        p2.innerHTML = new Intl.NumberFormat().format(Number((p2Value * 100).toFixed(1)));
+        p2.style.color = colorScheme2(p2Value);
+
+        const p3 = document.querySelector('.p3');
+        const p3Value = total_sales_fact.value > 0 ? offline_sales_plan.value / total_sales_fact.value : 0;
+        p3.innerHTML = new Intl.NumberFormat().format(Number((p3Value * 100).toFixed(0)));
+        p3.style.color = colorScheme1(p3Value);
+
+        const p4 = document.querySelector('.p4');
+        const p4Value = total_sales_fact.value > 0 ? online_sales_shop_plan.value / total_sales_fact.value : 0;
+        p4.innerHTML = new Intl.NumberFormat().format(Number((p4Value * 100).toFixed(0)));
+        p4.style.color = colorScheme1(p4Value);
+
+        const p5 = document.querySelector('.p5');
+        const p5Value = total_sales_fact.value > 0 ? online_sales_marketplace_plan.value / total_sales_fact.value : 0;
+        p5.innerHTML = new Intl.NumberFormat().format(Number((p5Value * 100).toFixed(0)));
+        p5.style.color = colorScheme1(p5Value);
+        ////////////////////////////////////////////////
         $.ajax({
             method: "POST",
             url: '/sales-write-offs-plan/save-fields',