<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>
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;
});
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',