Files
Aislo/tools/stmate-test/calc_a2w.js
T

48 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* -*- coding: utf-8 -*- */
/**
* 실적단가 → 일식단가 변환등록(wM_Conv_A2W) 비목율 계산 — 화면 없이 숫자만 (calc_a2w.js)
* 근거: REA 27 conversion_component_rate_rules.json(0x4e37dc 한 줄 · 0x4e40f8 입력 정리 · 0x4e3df0 비목율 일괄적용)
* 율은 백분율 · 노무 L · 재료 M · 경비 E = 100 − (L + M) · 반올림 없음
* 금액 나눔(총액 × 율)은 근거 없음 — 율만 다룸
*/
const StmateA2W = (() => {
const n = (v) => Number(v) || 0;
// 입력칸 정리(0x4e40f8) — L·M 각 100 넘으면 100 · 합이 100 넘으면 고친 칸(sender)을 지키고 다른 칸 = 100 − 그 값
function normalizeEditor(L, M, sender = "L") {
let l = Math.min(n(L), 100),
m = Math.min(n(M), 100);
if (l + m > 100) sender === "M" ? (l = 100 - m) : (m = 100 - l);
return { L: l, M: m, E: 100 - (l + m) };
}
// 한 줄 고침(0x4e37dc) — 합이 100 넘으면 재료 칸(10)을 고친 때만 L = 100 − M · 그 밖은 M = 100 − L
function normalizeRow(L, M, editedCol) {
let l = n(L),
m = n(M);
if (l + m > 100) editedCol === 10 ? (l = 100 - m) : (m = 100 - l);
return { L: l, M: m, E: 100 - (l + m) };
}
/**
* 비목율 일괄적용(0x4e3df0) — rows: [{ sel, rateL 개별노무비율 }] · editor: { L, M, sender }
* opts.individual = 「노무비율ː개별노무비율 · 나머지ː재료비우선」 표시(전역 조건 1 과 함께일 때만)
* 고른 줄: L = 편집 L(개별이 켜졌고 개별 ≠ 0 이면 개별) · M = L + 편집 M > 100 이면 100 − L · E = 나머지
* 안 고른 줄: 세 칸 모두 0(옛 값 지키지 않음)
*/
function bulkApply(rows, editor = {}, opts = {}) {
const ed = normalizeEditor(editor.L, editor.M, editor.sender);
return (rows || []).map((r) => {
if (!r.sel) return Object.assign({}, r, { L: 0, M: 0, E: 0 });
const L = opts.individual && n(r.rateL) !== 0 ? n(r.rateL) : ed.L;
const M = L + ed.M > 100 ? 100 - L : ed.M;
return Object.assign({}, r, { L, M, E: 100 - L - M });
});
}
return { normalizeEditor, normalizeRow, bulkApply };
})();
if (typeof window !== "undefined") window.STMATE_A2W = StmateA2W;
if (typeof module !== "undefined" && module.exports) module.exports = StmateA2W;