Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
194c91cf25 | ||
|
|
68797e4fb5 | ||
|
|
af4ae1cbc3 |
@@ -230,7 +230,21 @@ window.submitTaskForm = async (event, projectId) => {
|
|||||||
alert("保存失败:" + error.message);
|
alert("保存失败:" + error.message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
window.createFinance = (event) => createResource(event, "finance");
|
window.createFinance = async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const data = Object.fromEntries(new FormData(event.currentTarget).entries());
|
||||||
|
// Map form: month(date)→month(YYYY-MM), category→category, amount, tenant
|
||||||
|
data.month = data.month.substring(0, 7);
|
||||||
|
data.project_name = state.tenant;
|
||||||
|
data.tenant = state.tenant;
|
||||||
|
data.record_type = "revenue"; // default, will be adjusted by category
|
||||||
|
try {
|
||||||
|
await api("/api/finance", { method: "POST", body: JSON.stringify({ data }) });
|
||||||
|
await load();
|
||||||
|
} catch (error) {
|
||||||
|
alert("新增失败:" + error.message);
|
||||||
|
}
|
||||||
|
};
|
||||||
window.switchTab = switchTab;
|
window.switchTab = switchTab;
|
||||||
window.switchTenant = (tenant) => {
|
window.switchTenant = (tenant) => {
|
||||||
state.tenant = tenant;
|
state.tenant = tenant;
|
||||||
@@ -405,17 +419,16 @@ function renderProducts() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderFinance() {
|
function renderFinance() {
|
||||||
const rows = state.data.finance.map((x) => [x.month, badge(x.record_type === "revenue" ? "收入" : "成本/费用"), x.category, money(x.amount), x.occurred_date, text(x.notes)]);
|
const rows = state.data.finance.map((x) => [x.month, x.category, money(x.amount), text(x.notes)]);
|
||||||
document.querySelector("#finance").innerHTML = `<div class="grid gap-4">
|
document.querySelector("#finance").innerHTML = `<div class="grid gap-4">
|
||||||
${card(`<h2 class="mb-4 text-lg font-bold">收入、毛利、成本/费用、净利月度曲线</h2><div style="position:relative;height:300px"><canvas id="financeChart2"></canvas></div>`, "p-5")}
|
${card(`<h2 class="mb-4 text-lg font-bold">收入、毛利、成本/费用、净利月度曲线</h2><div style="position:relative;height:300px"><canvas id="financeChart2"></canvas></div>`, "p-5")}
|
||||||
${card(formHtml([
|
${card(formHtml([
|
||||||
{ label: "月份", input: `<input name="month" required placeholder="YYYY-MM" pattern="\\d{4}-\\d{2}">` },
|
{ label: "日期", input: `<input name="month" type="date" required>` },
|
||||||
{ label: "类型", input: `<select name="record_type"><option value="revenue">收入</option><option value="cost_expense">成本/费用</option></select>` },
|
{ label: "类型", input: `<select name="category"><option>签单</option><option>确认收入</option><option>人力成本</option><option>费用</option><option>外部采购</option></select>` },
|
||||||
{ label: "分类", input: `<input name="category" required>` },
|
|
||||||
{ label: "金额/万", input: `<input name="amount" type="number" step="0.01" required>` },
|
{ label: "金额/万", input: `<input name="amount" type="number" step="0.01" required>` },
|
||||||
{ label: "发生日期", input: `<input name="occurred_date" type="date">` },
|
{ label: "费用说明", input: `<input name="notes" placeholder="摘要说明">` },
|
||||||
], { handler: "createFinance", text: "新增明细" }), "p-4")}
|
], { handler: "createFinance", text: "新增明细" }), "p-4")}
|
||||||
${renderTable(["月份", "类型", "分类", "金额", "发生日期", "备注"], rows)}
|
${card(`<div class="flex items-center justify-between cursor-pointer" onclick="document.querySelector('#finance-table').classList.toggle('hidden'); this.querySelector('i').classList.toggle('rotate-90')"><h3 class="font-bold text-slate-700">明细列表 <span class="text-slate-400 font-normal">(${state.data.finance.length})</span></h3><i data-lucide="chevron-down" class="transition-transform rotate-90"></i></div><div id="finance-table" class="hidden mt-3">${renderTable(["日期", "类型", "金额", "备注"], rows)}</div>`, "p-4")}
|
||||||
</div>`;
|
</div>`;
|
||||||
renderChartOn("financeChart2", state.data.financeMonthly);
|
renderChartOn("financeChart2", state.data.financeMonthly);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user