Files
Aislo/B08_wf5_Quantity/B08_wf5_Quantity_UI_Tab_UnitCost.ts
T

97 lines
3.0 KiB
TypeScript

import { B08Api } from "./B08_wf5_Quantity_Api";
import { el, formData, input, section, select, table } from "./B08_wf5_Quantity_UI_Dom";
import { TabContext } from "./B08_wf5_Quantity_Types";
export function renderUnitCost(ctx: TabContext) {
const root = section("일위대가", "재료·노무·장비·경비의 투입계수로 단위당 비용을 계산합니다.");
const components: any[] = [];
const f = el("form", "b08-form-grid") as HTMLFormElement;
f.append(
input("code", "일위대가 코드"),
input("name", "명칭"),
input("specification", "규격"),
input("unit", "단위"),
select("rounding_mode", "금액 처리", [
["FLOOR", "절사"],
["ROUND", "반올림"],
["CEILING", "올림"],
]),
input("rounding_unit", "처리 단위", "number", "1"),
select("status", "상태", [
["DRAFT", "작성중"],
["CONFIRMED", "확정"],
]),
);
const cf = componentForm(components, root);
const btn = el(
"button",
"b08-button b08-button--primary",
"일위대가 저장·계산",
) as HTMLButtonElement;
btn.type = "submit";
f.append(btn);
f.onsubmit = async (e) => {
e.preventDefault();
if (!components.length) throw new Error("구성요소를 추가하세요.");
const x = formData(f);
const result = await B08Api.saveUnitCost(ctx.state.projectId, {
...x,
rounding_unit: Number(x.rounding_unit),
status: x.status,
version_no: 1,
components,
});
ctx.message(`일위대가 계산 완료: ${result.total.toLocaleString()}원`);
await ctx.refresh();
};
root.append(
f,
cf,
table(
["코드", "명칭", "규격", "단위", "상태"],
ctx.state.data.costing.unit_costs.map((x: any) => [
x.unit_cost_code,
x.name,
x.specification,
x.unit,
x.status,
]),
),
);
return root;
}
function componentForm(rows: any[], root: HTMLElement) {
const box = section("구성요소", "적용단가와 투입계수를 입력합니다.");
const f = el("form", "b08-inline-form") as HTMLFormElement;
f.append(
select("component_type", "유형", [
["CATALOG", "기초단가"],
["EQUIPMENT", "중기"],
["UNIT_COST", "일위대가"],
]),
input("reference_id", "참조 ID"),
input("reference_name", "참조명"),
input("quantity", "투입계수", "number"),
select("cost_type", "비용", [
["LABOR", "노무"],
["MATERIAL", "재료"],
["EXPENSE", "경비"],
]),
);
const b = el("button", "b08-button", "구성 추가") as HTMLButtonElement;
b.type = "submit";
f.append(b);
f.onsubmit = (e) => {
e.preventDefault();
const x = formData(f);
rows.push({
...x,
quantity: Number(x.quantity),
unit_price: 0,
sort_order: rows.length,
});
root.querySelector(".b08-component-count")!.textContent = `구성 ${rows.length}건`;
};
box.append(f, el("p", "b08-component-count", "구성 0건"));
return box;
}