修正
This commit is contained in:
@@ -64,9 +64,34 @@ from app.modules.opening_balances.lock_router import router as opening_balance_l
|
|||||||
app.include_router(opening_balance_lock_router)
|
app.include_router(opening_balance_lock_router)
|
||||||
|
|
||||||
from app.routers import journal_entries
|
from app.routers import journal_entries
|
||||||
|
from app.routers import cash
|
||||||
|
from app.routers import accounts
|
||||||
|
|
||||||
app.include_router(journal_entries.router)
|
app.include_router(journal_entries.router)
|
||||||
|
app.include_router(cash.router)
|
||||||
|
app.include_router(accounts.router)
|
||||||
|
|
||||||
|
|
||||||
from app.routers import month_locks
|
from app.routers import month_locks
|
||||||
app.include_router(month_locks.router)
|
app.include_router(month_locks.router)
|
||||||
|
|
||||||
|
from app.routers import year_locks
|
||||||
|
app.include_router(year_locks.router)
|
||||||
|
|
||||||
|
from app.routers import cash
|
||||||
|
app.include_router(cash.router)
|
||||||
|
|
||||||
|
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
|
||||||
|
app.mount(
|
||||||
|
"/",
|
||||||
|
StaticFiles(directory="app/static", html=True),
|
||||||
|
name="static",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
from fastapi import APIRouter
|
||||||
|
from app.core.database import get_connection
|
||||||
|
|
||||||
|
router = APIRouter(prefix="/accounts", tags=["科目"])
|
||||||
|
|
||||||
|
@router.get("", summary="科目一覧取得")
|
||||||
|
def get_accounts():
|
||||||
|
"""
|
||||||
|
科目マスタ一覧を返す
|
||||||
|
"""
|
||||||
|
with get_connection() as conn, conn.cursor() as cur:
|
||||||
|
cur.execute("""
|
||||||
|
SELECT
|
||||||
|
account_id,
|
||||||
|
account_code,
|
||||||
|
account_name,
|
||||||
|
account_type
|
||||||
|
FROM accounts
|
||||||
|
ORDER BY account_code
|
||||||
|
""")
|
||||||
|
rows = cur.fetchall()
|
||||||
|
|
||||||
|
return rows
|
||||||
|
|||||||
105
backend/app/routers/cash.py
Normal file
105
backend/app/routers/cash.py
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
from fastapi import APIRouter, Query
|
||||||
|
from datetime import date
|
||||||
|
from app.core.database import get_connection
|
||||||
|
|
||||||
|
router = APIRouter(prefix="/cash", tags=["资金"])
|
||||||
|
|
||||||
|
|
||||||
|
# ※ 临时方案:资金系科目(现金 / 银行)
|
||||||
|
CASH_ACCOUNT_IDS = [101, 102]
|
||||||
|
|
||||||
|
|
||||||
|
# -------------------------
|
||||||
|
# 资金余额
|
||||||
|
# -------------------------
|
||||||
|
@router.get("/balance", summary="资金余额取得")
|
||||||
|
def get_cash_balance():
|
||||||
|
"""
|
||||||
|
取得当前资金余额(现金・银行)
|
||||||
|
"""
|
||||||
|
with get_connection() as conn, conn.cursor() as cur:
|
||||||
|
cur.execute("""
|
||||||
|
SELECT
|
||||||
|
a.account_id,
|
||||||
|
a.account_name,
|
||||||
|
COALESCE(SUM(l.debit), 0) - COALESCE(SUM(l.credit), 0) AS balance
|
||||||
|
FROM accounts a
|
||||||
|
LEFT JOIN journal_lines l
|
||||||
|
ON l.account_id = a.account_id
|
||||||
|
LEFT JOIN journal_entries e
|
||||||
|
ON e.journal_id = l.journal_id
|
||||||
|
AND e.is_deleted = false
|
||||||
|
WHERE a.account_id = ANY(%s)
|
||||||
|
GROUP BY a.account_id, a.account_name
|
||||||
|
ORDER BY a.account_id
|
||||||
|
""", (CASH_ACCOUNT_IDS,))
|
||||||
|
|
||||||
|
rows = cur.fetchall()
|
||||||
|
|
||||||
|
total = sum(r["balance"] for r in rows)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"items": rows,
|
||||||
|
"total_balance": total
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# -------------------------
|
||||||
|
# 资金流水
|
||||||
|
# -------------------------
|
||||||
|
@router.get("/transactions", summary="资金流水取得")
|
||||||
|
def get_cash_transactions(
|
||||||
|
account_id: int = Query(..., description="资金账户ID"),
|
||||||
|
from_date: date | None = Query(None, alias="from"),
|
||||||
|
to_date: date | None = Query(None, alias="to"),
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
指定资金账户的资金流水
|
||||||
|
"""
|
||||||
|
with get_connection() as conn, conn.cursor() as cur:
|
||||||
|
sql = """
|
||||||
|
SELECT
|
||||||
|
e.journal_date,
|
||||||
|
e.description,
|
||||||
|
l.debit,
|
||||||
|
l.credit,
|
||||||
|
COALESCE(a2.account_name, '(未指定)') AS counter_account
|
||||||
|
FROM journal_lines l
|
||||||
|
JOIN journal_entries e
|
||||||
|
ON e.journal_id = l.journal_id
|
||||||
|
LEFT JOIN journal_lines l2
|
||||||
|
ON l2.journal_id = l.journal_id
|
||||||
|
AND l2.account_id <> l.account_id
|
||||||
|
LEFT JOIN accounts a2
|
||||||
|
ON a2.account_id = l2.account_id
|
||||||
|
WHERE l.account_id = %s
|
||||||
|
AND e.is_deleted = false
|
||||||
|
"""
|
||||||
|
|
||||||
|
params = [account_id]
|
||||||
|
|
||||||
|
if from_date:
|
||||||
|
sql += " AND e.journal_date >= %s"
|
||||||
|
params.append(from_date)
|
||||||
|
|
||||||
|
if to_date:
|
||||||
|
sql += " AND e.journal_date <= %s"
|
||||||
|
params.append(to_date)
|
||||||
|
|
||||||
|
sql += " ORDER BY e.journal_date, e.journal_id"
|
||||||
|
|
||||||
|
cur.execute(sql, params)
|
||||||
|
rows = cur.fetchall()
|
||||||
|
|
||||||
|
result = []
|
||||||
|
for r in rows:
|
||||||
|
amount = r["debit"] - r["credit"]
|
||||||
|
result.append({
|
||||||
|
"journal_date": r["journal_date"],
|
||||||
|
"description": r["description"],
|
||||||
|
"counter_account": r["counter_account"],
|
||||||
|
"amount": amount,
|
||||||
|
"direction": "in" if amount > 0 else "out" if amount < 0 else "none",
|
||||||
|
})
|
||||||
|
|
||||||
|
return result
|
||||||
49
backend/app/routers/year_locks.py
Normal file
49
backend/app/routers/year_locks.py
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
from fastapi import APIRouter, HTTPException
|
||||||
|
from app.core.database import get_connection
|
||||||
|
|
||||||
|
router = APIRouter(prefix="/year-locks", tags=["年度锁定"])
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("", summary="年度锁定一覧")
|
||||||
|
def get_year_locks():
|
||||||
|
with get_connection() as conn, conn.cursor() as cur:
|
||||||
|
cur.execute("""
|
||||||
|
SELECT fiscal_year, is_locked, locked_at, locked_by
|
||||||
|
FROM year_locks
|
||||||
|
ORDER BY fiscal_year
|
||||||
|
""")
|
||||||
|
return cur.fetchall()
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/lock", summary="年度锁定")
|
||||||
|
def lock_year(fiscal_year: int):
|
||||||
|
with get_connection() as conn, conn.cursor() as cur:
|
||||||
|
cur.execute("""
|
||||||
|
INSERT INTO year_locks (fiscal_year, is_locked, locked_at, locked_by)
|
||||||
|
VALUES (%s, true, NOW(), %s)
|
||||||
|
ON CONFLICT (fiscal_year)
|
||||||
|
DO UPDATE
|
||||||
|
SET is_locked = true,
|
||||||
|
locked_at = NOW(),
|
||||||
|
locked_by = EXCLUDED.locked_by
|
||||||
|
""", (fiscal_year, "system"))
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
return {"status": "locked", "fiscal_year": fiscal_year}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/unlock", summary="年度解锁")
|
||||||
|
def unlock_year(fiscal_year: int):
|
||||||
|
with get_connection() as conn, conn.cursor() as cur:
|
||||||
|
cur.execute("""
|
||||||
|
UPDATE year_locks
|
||||||
|
SET is_locked = false
|
||||||
|
WHERE fiscal_year = %s
|
||||||
|
""", (fiscal_year,))
|
||||||
|
|
||||||
|
if cur.rowcount == 0:
|
||||||
|
raise HTTPException(status_code=404, detail="指定年度不存在")
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
return {"status": "unlocked", "fiscal_year": fiscal_year}
|
||||||
96
backend/app/static/cash-transactions.html
Normal file
96
backend/app/static/cash-transactions.html
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="ja">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<title>资金流水</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>📄 资金流水</h2>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label>账户ID:</label>
|
||||||
|
<input id="accountId" type="number" value="101" style="width: 80px" />
|
||||||
|
<label>从:</label>
|
||||||
|
<input id="fromDate" type="date" />
|
||||||
|
<label>到:</label>
|
||||||
|
<input id="toDate" type="date" />
|
||||||
|
<button onclick="loadTransactions()">查询</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table
|
||||||
|
border="1"
|
||||||
|
cellpadding="6"
|
||||||
|
style="margin-top: 10px; border-collapse: collapse"
|
||||||
|
>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>日期</th>
|
||||||
|
<th>摘要</th>
|
||||||
|
<th style="text-align: right">金额</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="txBody">
|
||||||
|
<tr>
|
||||||
|
<td colspan="3">请输入条件后查询</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function formatYen(v) {
|
||||||
|
return "¥ " + Number(v).toLocaleString("ja-JP");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadTransactions() {
|
||||||
|
const accountId = document.getElementById("accountId").value;
|
||||||
|
const from = document.getElementById("fromDate").value;
|
||||||
|
const to = document.getElementById("toDate").value;
|
||||||
|
|
||||||
|
let url = `/cash/transactions?account_id=${accountId}`;
|
||||||
|
if (from) url += `&from=${from}`;
|
||||||
|
if (to) url += `&to=${to}`;
|
||||||
|
|
||||||
|
const body = document.getElementById("txBody");
|
||||||
|
body.innerHTML = "<tr><td colspan='3'>读取中...</td></tr>";
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(url);
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
|
body.innerHTML = "";
|
||||||
|
if (data.length === 0) {
|
||||||
|
body.innerHTML = "<tr><td colspan='3'>无数据</td></tr>";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.forEach((row) => {
|
||||||
|
const tr = document.createElement("tr");
|
||||||
|
tr.innerHTML = `
|
||||||
|
<td>${row.journal_date}</td>
|
||||||
|
<td>${row.description}</td>
|
||||||
|
<td style="text-align:right;color:${row.amount < 0 ? "red" : "black"};">
|
||||||
|
${formatYen(row.amount)}
|
||||||
|
</td>
|
||||||
|
`;
|
||||||
|
body.appendChild(tr);
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
body.innerHTML = "<tr><td colspan='3'>读取失败</td></tr>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getQueryParam(name) {
|
||||||
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
return params.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.onload = () => {
|
||||||
|
const accountId = getQueryParam("account_id");
|
||||||
|
if (accountId) {
|
||||||
|
document.getElementById("accountId").value = accountId;
|
||||||
|
loadTransactions();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
76
backend/app/static/cash.html
Normal file
76
backend/app/static/cash.html
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="ja">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<title>资金余额</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>💰 当前资金状况</h2>
|
||||||
|
|
||||||
|
<table border="1" cellpadding="6" style="border-collapse: collapse">
|
||||||
|
<thead>
|
||||||
|
<tr style="background: #f5f5f5">
|
||||||
|
<th>账户</th>
|
||||||
|
<th style="text-align: right">余额</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="cashBalanceBody">
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">读取中...</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr style="font-weight: bold">
|
||||||
|
<td>合计</td>
|
||||||
|
<td id="cashBalanceTotal" style="text-align: right">-</td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const API_BASE = "http://127.0.0.1:8080";
|
||||||
|
|
||||||
|
function formatYen(v) {
|
||||||
|
return "¥ " + Number(v).toLocaleString("ja-JP");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadCashBalance() {
|
||||||
|
const body = document.getElementById("cashBalanceBody");
|
||||||
|
const totalEl = document.getElementById("cashBalanceTotal");
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch("/cash/balance");
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
|
body.innerHTML = "";
|
||||||
|
|
||||||
|
data.items.forEach((item) => {
|
||||||
|
const tr = document.createElement("tr");
|
||||||
|
|
||||||
|
tr.style.cursor = "pointer";
|
||||||
|
tr.onclick = () => {
|
||||||
|
window.location.href = `/cash-transactions.html?account_id=${item.account_id}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
tr.innerHTML = `
|
||||||
|
<td style="color:#007acc; text-decoration:underline;">
|
||||||
|
${item.account_name}
|
||||||
|
</td>
|
||||||
|
<td style="text-align:right;">
|
||||||
|
${formatYen(item.balance)}
|
||||||
|
</td>
|
||||||
|
`;
|
||||||
|
|
||||||
|
tbody.appendChild(tr);
|
||||||
|
});
|
||||||
|
|
||||||
|
totalEl.innerText = formatYen(data.total_balance);
|
||||||
|
} catch (e) {
|
||||||
|
body.innerHTML = `<tr><td colspan="2">读取失败</td></tr>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("DOMContentLoaded", loadCashBalance);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -30,7 +30,67 @@
|
|||||||
<tbody></tbody>
|
<tbody></tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<h3>💰 当前资金状况</h3>
|
||||||
|
|
||||||
|
<table border="1" cellpadding="6" style="border-collapse: collapse">
|
||||||
|
<thead>
|
||||||
|
<tr style="background: #f5f5f5">
|
||||||
|
<th>账户</th>
|
||||||
|
<th style="text-align: right">余额</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="cashBalanceBody">
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">读取中...</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr style="font-weight: bold">
|
||||||
|
<td>合计</td>
|
||||||
|
<td id="cashBalanceTotal" style="text-align: right">-</td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
|
||||||
<script src="js/api.js"></script>
|
<script src="js/api.js"></script>
|
||||||
<script src="js/trial_balance.js"></script>
|
<script src="js/trial_balance.js"></script>
|
||||||
|
<script>
|
||||||
|
const API_BASE = "http://127.0.0.1:18080";
|
||||||
|
|
||||||
|
function formatYen(v) {
|
||||||
|
return "¥ " + Number(v).toLocaleString("ja-JP");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadCashBalance() {
|
||||||
|
const body = document.getElementById("cashBalanceBody");
|
||||||
|
const totalEl = document.getElementById("cashBalanceTotal");
|
||||||
|
|
||||||
|
body.innerHTML = "<tr><td colspan='2'>读取中...</td></tr>";
|
||||||
|
totalEl.innerText = "-";
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${API_BASE}/cash/balance`);
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
|
body.innerHTML = "";
|
||||||
|
|
||||||
|
data.items.forEach((item) => {
|
||||||
|
const tr = document.createElement("tr");
|
||||||
|
tr.innerHTML = `
|
||||||
|
<td>${item.account_name}</td>
|
||||||
|
<td style="text-align:right;">${formatYen(item.balance)}</td>
|
||||||
|
`;
|
||||||
|
body.appendChild(tr);
|
||||||
|
});
|
||||||
|
|
||||||
|
totalEl.innerText = formatYen(data.total_balance);
|
||||||
|
} catch (e) {
|
||||||
|
body.innerHTML = `<tr><td colspan="2">读取失败</td></tr>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 页面加载时自动读取
|
||||||
|
window.addEventListener("DOMContentLoaded", loadCashBalance);
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -4,20 +4,50 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title>仕訳入力</title>
|
<title>仕訳入力</title>
|
||||||
<style>
|
<style>
|
||||||
body { font-family: sans-serif; margin: 24px; }
|
body {
|
||||||
h2 { margin: 0 0 12px; }
|
font-family: sans-serif;
|
||||||
table { border-collapse: collapse; width: 100%; margin-top: 12px; }
|
margin: 24px;
|
||||||
th, td { border: 1px solid #ccc; padding: 6px; text-align: center; }
|
}
|
||||||
th { background: #f5f5f5; }
|
h2 {
|
||||||
input, select, button { padding: 6px; }
|
margin: 0 0 12px;
|
||||||
.right { text-align: right; }
|
}
|
||||||
.row { margin: 8px 0; display: flex; gap: 16px; align-items: center; }
|
table {
|
||||||
.row label { min-width: 120px; }
|
border-collapse: collapse;
|
||||||
.tax-row { background: #f0f8ff; }
|
width: 100%;
|
||||||
|
margin-top: 12px;
|
||||||
|
}
|
||||||
|
th,
|
||||||
|
td {
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
padding: 6px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
th {
|
||||||
|
background: #f5f5f5;
|
||||||
|
}
|
||||||
|
input,
|
||||||
|
select,
|
||||||
|
button {
|
||||||
|
padding: 6px;
|
||||||
|
}
|
||||||
|
.right {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
.row {
|
||||||
|
margin: 8px 0;
|
||||||
|
display: flex;
|
||||||
|
gap: 16px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.row label {
|
||||||
|
min-width: 120px;
|
||||||
|
}
|
||||||
|
.tax-row {
|
||||||
|
background: #f0f8ff;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h2>仕訳入力</h2>
|
<h2>仕訳入力</h2>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -27,7 +57,12 @@
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<label>摘要</label>
|
<label>摘要</label>
|
||||||
<input type="text" id="description" style="flex:1" placeholder="例:売上入金/経費支払 など" />
|
<input
|
||||||
|
type="text"
|
||||||
|
id="description"
|
||||||
|
style="flex: 1"
|
||||||
|
placeholder="例:売上入金/経費支払 など"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -37,7 +72,7 @@
|
|||||||
<label>仮受消費税等 勘定</label>
|
<label>仮受消費税等 勘定</label>
|
||||||
<select id="taxReceivedSelect"></select>
|
<select id="taxReceivedSelect"></select>
|
||||||
</div>
|
</div>
|
||||||
<div style="margin-bottom: 10px;">
|
<div style="margin-bottom: 10px">
|
||||||
<label>消費税 端数処理:</label>
|
<label>消費税 端数処理:</label>
|
||||||
<select id="roundingMode">
|
<select id="roundingMode">
|
||||||
<option value="round">四捨五入</option>
|
<option value="round">四捨五入</option>
|
||||||
@@ -60,51 +95,97 @@
|
|||||||
<tbody></tbody>
|
<tbody></tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div style="margin-top:10px; display:flex; gap:8px;">
|
<div style="margin-top: 10px; display: flex; gap: 8px">
|
||||||
<button onclick="addRow()">+ 行追加</button>
|
<button onclick="addRow()">+ 行追加</button>
|
||||||
<button onclick="submitJournal()">登録</button>
|
<button onclick="submitJournal()">登録</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h3>月次锁定管理</h3>
|
<h3>月次锁定管理</h3>
|
||||||
|
|
||||||
<div style="margin-bottom: 8px;">
|
<div style="margin-bottom: 8px">
|
||||||
<label>年度:</label>
|
<label>年度:</label>
|
||||||
<input type="number" id="lockYear" value="2025" style="width:80px;">
|
<input type="number" id="lockYear" value="2025" style="width: 80px" />
|
||||||
|
|
||||||
<label>月份:</label>
|
<label>月份:</label>
|
||||||
<input type="number" id="lockMonth" min="1" max="12" value="6" style="width:60px;">
|
<input
|
||||||
|
type="number"
|
||||||
|
id="lockMonth"
|
||||||
|
min="1"
|
||||||
|
max="12"
|
||||||
|
value="6"
|
||||||
|
style="width: 60px"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button onclick="lockMonth()">🔒 锁定</button>
|
<button onclick="lockMonth()">🔒 锁定</button>
|
||||||
<button onclick="unlockMonth()">🔓 解锁</button>
|
<button onclick="unlockMonth()">🔓 解锁</button>
|
||||||
|
|
||||||
|
<div id="lockResult" style="margin-top: 10px; color: #333"></div>
|
||||||
|
|
||||||
|
<div style="margin-top: 12px">
|
||||||
|
|
||||||
<div id="lockResult" style="margin-top:10px;color:#333;"></div>
|
|
||||||
|
|
||||||
<div style="margin-top:12px;">
|
|
||||||
<button onclick="refreshMonthLocks()">🔄 刷新锁定列表</button>
|
<button onclick="refreshMonthLocks()">🔄 刷新锁定列表</button>
|
||||||
<pre id="lockList" style="background:#f7f7f7;padding:8px;"></pre>
|
<pre id="lockList" style="background: #f7f7f7; padding: 8px"></pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="monthLockBanner"
|
<div
|
||||||
style="display:none;
|
id="monthLockBanner"
|
||||||
|
style="
|
||||||
|
display: none;
|
||||||
margin: 8px 0;
|
margin: 8px 0;
|
||||||
padding: 6px 10px;
|
padding: 6px 10px;
|
||||||
background: #ffecec;
|
background: #ffecec;
|
||||||
border: 1px solid #ffaaaa;
|
border: 1px solid #ffaaaa;
|
||||||
color:#a00000;">
|
color: #a00000;
|
||||||
|
"
|
||||||
|
>
|
||||||
🔒 该月份已锁定,不能编辑仕訳
|
🔒 该月份已锁定,不能编辑仕訳
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
let rowSeq = 0; // 各行唯一ID
|
let rowSeq = 0; // 各行唯一ID
|
||||||
|
|
||||||
const API = "http://127.0.0.1:18080";
|
const API = "http://127.0.0.1:18080";
|
||||||
|
|
||||||
let accounts = [];
|
let accounts = [];
|
||||||
|
|
||||||
|
const ACCOUNT_GROUPS = [
|
||||||
|
{
|
||||||
|
label: "💰 資金",
|
||||||
|
codes: ["101", "102", "103", "104"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "📦 流動資産",
|
||||||
|
codes: ["201", "202", "203", "204", "205"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "🏗 固定資産",
|
||||||
|
codes: ["401", "402", "403", "404", "405", "406", "407", "408"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "💳 負債",
|
||||||
|
codes: [
|
||||||
|
"501",
|
||||||
|
"502",
|
||||||
|
"503",
|
||||||
|
"504",
|
||||||
|
"505",
|
||||||
|
"506",
|
||||||
|
"507",
|
||||||
|
"508",
|
||||||
|
"509",
|
||||||
|
"210",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "🏢 資本",
|
||||||
|
codes: ["601", "602"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "📈 収益",
|
||||||
|
codes: ["701"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
let taxPaidAccounts = [];
|
let taxPaidAccounts = [];
|
||||||
let taxReceivedAccounts = [];
|
let taxReceivedAccounts = [];
|
||||||
|
|
||||||
@@ -117,26 +198,32 @@ async function init() {
|
|||||||
alert("科目一覧の取得に失敗しました");
|
alert("科目一覧の取得に失敗しました");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
accounts = await res.json();
|
|
||||||
|
|
||||||
// 消費税用勘定を抽出(名前は「仮払」「仮受」を含む想定)
|
const data = await res.json();
|
||||||
// 仮払消費税等:资产 + code 504(或你实际的 code)
|
|
||||||
taxPaidAccounts = accounts.filter(
|
// 🔴 ここ重要:items がある場合と無い場合の両対応
|
||||||
a => a.account_code === "504"
|
accounts = data.items ?? data;
|
||||||
|
|
||||||
|
// 仮払消費税等(あなたの DB では 505 は「未払消費税等」)
|
||||||
|
taxPaidAccounts = accounts.filter((a) =>
|
||||||
|
a.account_name.includes("仮払")
|
||||||
);
|
);
|
||||||
|
|
||||||
// 仮受消費税等:负债 + code 505(或你实际的 code)
|
// 仮受消費税等
|
||||||
taxReceivedAccounts = accounts.filter(
|
taxReceivedAccounts = accounts.filter((a) =>
|
||||||
a => a.account_code === "505"
|
a.account_name.includes("仮受")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
setupTaxSelectors();
|
setupTaxSelectors();
|
||||||
addRow();
|
addRow();
|
||||||
|
|
||||||
// 仕訳日:既定で今日
|
document.getElementById("entryDate").value = new Date()
|
||||||
document.getElementById("entryDate").value = new Date().toISOString().slice(0,10);
|
.toISOString()
|
||||||
|
.slice(0, 10);
|
||||||
|
|
||||||
|
await onEntryDateChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
@@ -145,15 +232,21 @@ init();
|
|||||||
function setupTaxSelectors() {
|
function setupTaxSelectors() {
|
||||||
document.getElementById("taxPaidSelect").innerHTML =
|
document.getElementById("taxPaidSelect").innerHTML =
|
||||||
`<option value="">-- 選択してください --</option>` +
|
`<option value="">-- 選択してください --</option>` +
|
||||||
taxPaidAccounts.map(a =>
|
taxPaidAccounts
|
||||||
|
.map(
|
||||||
|
(a) =>
|
||||||
`<option value="${a.account_id}">${a.account_code} ${a.account_name}</option>`
|
`<option value="${a.account_id}">${a.account_code} ${a.account_name}</option>`
|
||||||
).join("");
|
)
|
||||||
|
.join("");
|
||||||
|
|
||||||
document.getElementById("taxReceivedSelect").innerHTML =
|
document.getElementById("taxReceivedSelect").innerHTML =
|
||||||
`<option value="">-- 選択してください --</option>` +
|
`<option value="">-- 選択してください --</option>` +
|
||||||
taxReceivedAccounts.map(a =>
|
taxReceivedAccounts
|
||||||
|
.map(
|
||||||
|
(a) =>
|
||||||
`<option value="${a.account_id}">${a.account_code} ${a.account_name}</option>`
|
`<option value="${a.account_id}">${a.account_code} ${a.account_name}</option>`
|
||||||
).join("");
|
)
|
||||||
|
.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
@@ -173,13 +266,15 @@ function addRow(isTaxRow = false, taxInfo = null, parentId = null) {
|
|||||||
tr.innerHTML = `
|
tr.innerHTML = `
|
||||||
<td>
|
<td>
|
||||||
<select class="account" ${isTaxRow ? "disabled" : ""}>
|
<select class="account" ${isTaxRow ? "disabled" : ""}>
|
||||||
${accounts.map(a =>
|
${buildAccountOptions()}
|
||||||
`<option value="${a.account_id}">${a.account_code} ${a.account_name}</option>`
|
|
||||||
).join("")}
|
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
<td><input type="number" class="debit right" min="0" ${isTaxRow ? "readonly" : ""}></td>
|
<td><input type="number" class="debit right" min="0" ${
|
||||||
<td><input type="number" class="credit right" min="0" ${isTaxRow ? "readonly" : ""}></td>
|
isTaxRow ? "readonly" : ""
|
||||||
|
}></td>
|
||||||
|
<td><input type="number" class="credit right" min="0" ${
|
||||||
|
isTaxRow ? "readonly" : ""
|
||||||
|
}></td>
|
||||||
<td>
|
<td>
|
||||||
<select class="taxType" ${isTaxRow ? "disabled" : ""}>
|
<select class="taxType" ${isTaxRow ? "disabled" : ""}>
|
||||||
<option value="none">対象外</option>
|
<option value="none">対象外</option>
|
||||||
@@ -194,7 +289,9 @@ function addRow(isTaxRow = false, taxInfo = null, parentId = null) {
|
|||||||
<option value="received">仮受(売上)</option>
|
<option value="received">仮受(売上)</option>
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
<td>${isTaxRow ? "" : `<button onclick="removeRow(this)">削除</button>`}</td>
|
<td>${
|
||||||
|
isTaxRow ? "" : `<button onclick="removeRow(this)">削除</button>`
|
||||||
|
}</td>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
tbody.appendChild(tr);
|
tbody.appendChild(tr);
|
||||||
@@ -203,8 +300,10 @@ function addRow(isTaxRow = false, taxInfo = null, parentId = null) {
|
|||||||
if (isTaxRow && taxInfo) {
|
if (isTaxRow && taxInfo) {
|
||||||
const acc = tr.querySelector(".account");
|
const acc = tr.querySelector(".account");
|
||||||
acc.value = taxInfo.accountId || "";
|
acc.value = taxInfo.accountId || "";
|
||||||
if (taxInfo.side === "debit") tr.querySelector(".debit").value = taxInfo.amount;
|
if (taxInfo.side === "debit")
|
||||||
if (taxInfo.side === "credit") tr.querySelector(".credit").value = taxInfo.amount;
|
tr.querySelector(".debit").value = taxInfo.amount;
|
||||||
|
if (taxInfo.side === "credit")
|
||||||
|
tr.querySelector(".credit").value = taxInfo.amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 普通行:绑定事件
|
// 普通行:绑定事件
|
||||||
@@ -223,7 +322,9 @@ function addRow(isTaxRow = false, taxInfo = null, parentId = null) {
|
|||||||
function removeTaxRowsOf(row) {
|
function removeTaxRowsOf(row) {
|
||||||
const id = row.dataset.rowId;
|
const id = row.dataset.rowId;
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
document.querySelectorAll(`tr.tax-row[data-parent-id="${id}"]`).forEach(r => r.remove());
|
document
|
||||||
|
.querySelectorAll(`tr.tax-row[data-parent-id="${id}"]`)
|
||||||
|
.forEach((r) => r.remove());
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeRow(btn) {
|
function removeRow(btn) {
|
||||||
@@ -232,7 +333,6 @@ function removeRow(btn) {
|
|||||||
row.remove();
|
row.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
// 税行 自動生成/更新(10%/8%のみ、四捨五入)
|
// 税行 自動生成/更新(10%/8%のみ、四捨五入)
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
@@ -250,16 +350,21 @@ function handleTax(row) {
|
|||||||
const totalAmount = debit || credit;
|
const totalAmount = debit || credit;
|
||||||
if (!totalAmount) return;
|
if (!totalAmount) return;
|
||||||
|
|
||||||
const rate = taxType === "8" ? 0.08 : 0.10;
|
const rate = taxType === "8" ? 0.08 : 0.1;
|
||||||
const roundingMode = document.getElementById("roundingMode").value;
|
const roundingMode = document.getElementById("roundingMode").value;
|
||||||
|
|
||||||
// 税込 → 税額逆算
|
// 税込 → 税額逆算
|
||||||
const rawTax = totalAmount * rate / (1 + rate);
|
const rawTax = (totalAmount * rate) / (1 + rate);
|
||||||
let taxAmount;
|
let taxAmount;
|
||||||
switch (roundingMode) {
|
switch (roundingMode) {
|
||||||
case "floor": taxAmount = Math.floor(rawTax); break;
|
case "floor":
|
||||||
case "ceil": taxAmount = Math.ceil(rawTax); break;
|
taxAmount = Math.floor(rawTax);
|
||||||
default: taxAmount = Math.round(rawTax);
|
break;
|
||||||
|
case "ceil":
|
||||||
|
taxAmount = Math.ceil(rawTax);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
taxAmount = Math.round(rawTax);
|
||||||
}
|
}
|
||||||
|
|
||||||
const parentId = row.dataset.rowId;
|
const parentId = row.dataset.rowId;
|
||||||
@@ -267,19 +372,23 @@ function handleTax(row) {
|
|||||||
if (taxDir === "paid") {
|
if (taxDir === "paid") {
|
||||||
const taxAcc = document.getElementById("taxPaidSelect").value;
|
const taxAcc = document.getElementById("taxPaidSelect").value;
|
||||||
if (!taxAcc) return alert("仮払消費税等 勘定を選択してください");
|
if (!taxAcc) return alert("仮払消費税等 勘定を選択してください");
|
||||||
addRow(true, { accountId: taxAcc, amount: taxAmount, side: "debit" }, parentId);
|
addRow(
|
||||||
|
true,
|
||||||
|
{ accountId: taxAcc, amount: taxAmount, side: "debit" },
|
||||||
|
parentId
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (taxDir === "received") {
|
if (taxDir === "received") {
|
||||||
const taxAcc = document.getElementById("taxReceivedSelect").value;
|
const taxAcc = document.getElementById("taxReceivedSelect").value;
|
||||||
if (!taxAcc) return alert("仮受消費税等 勘定を選択してください");
|
if (!taxAcc) return alert("仮受消費税等 勘定を選択してください");
|
||||||
addRow(true, { accountId: taxAcc, amount: taxAmount, side: "credit" }, parentId);
|
addRow(
|
||||||
|
true,
|
||||||
|
{ accountId: taxAcc, amount: taxAmount, side: "credit" },
|
||||||
|
parentId
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 税行は常に「直後の1行」を使う
|
// 税行は常に「直後の1行」を使う
|
||||||
function removeTaxRow(row) {
|
function removeTaxRow(row) {
|
||||||
const id = row.dataset.rowId;
|
const id = row.dataset.rowId;
|
||||||
@@ -287,7 +396,7 @@ function removeTaxRow(row) {
|
|||||||
|
|
||||||
document
|
document
|
||||||
.querySelectorAll(`tr.tax-row[data-parent-id="${id}"]`)
|
.querySelectorAll(`tr.tax-row[data-parent-id="${id}"]`)
|
||||||
.forEach(tr => tr.remove());
|
.forEach((tr) => tr.remove());
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeRow(btn) {
|
function removeRow(btn) {
|
||||||
@@ -303,18 +412,26 @@ async function submitJournal() {
|
|||||||
const entryDate = document.getElementById("entryDate").value;
|
const entryDate = document.getElementById("entryDate").value;
|
||||||
const description = document.getElementById("description").value.trim();
|
const description = document.getElementById("description").value.trim();
|
||||||
|
|
||||||
if (!entryDate) { alert("仕訳日を入力してください"); return; }
|
if (!entryDate) {
|
||||||
|
alert("仕訳日を入力してください");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 明細収集
|
// 明細収集
|
||||||
const rows = document.querySelectorAll("#linesTable tbody tr");
|
const rows = document.querySelectorAll("#linesTable tbody tr");
|
||||||
const lines = [];
|
const lines = [];
|
||||||
let totalDebit = 0, totalCredit = 0;
|
let totalDebit = 0,
|
||||||
|
totalCredit = 0;
|
||||||
|
|
||||||
rows.forEach(row => {
|
rows.forEach((row) => {
|
||||||
|
if (row.classList.contains("tax-row")) return;
|
||||||
const accountId = Number(row.querySelector(".account").value);
|
const accountId = Number(row.querySelector(".account").value);
|
||||||
const debit = Number(row.querySelector(".debit").value || 0);
|
const debit = Number(row.querySelector(".debit").value || 0);
|
||||||
const credit = Number(row.querySelector(".credit").value || 0);
|
const credit = Number(row.querySelector(".credit").value || 0);
|
||||||
|
if (debit > 0 && credit > 0) {
|
||||||
|
alert("同一行不能同时填写借方和贷方");
|
||||||
|
throw new Error("invalid line");
|
||||||
|
}
|
||||||
if (debit === 0 && credit === 0) return;
|
if (debit === 0 && credit === 0) return;
|
||||||
|
|
||||||
lines.push({ account_id: accountId, debit: debit, credit: credit });
|
lines.push({ account_id: accountId, debit: debit, credit: credit });
|
||||||
@@ -322,11 +439,19 @@ async function submitJournal() {
|
|||||||
totalCredit += credit;
|
totalCredit += credit;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (lines.length === 0) { alert("仕訳明細がありません"); return; }
|
if (lines.length === 0) {
|
||||||
|
alert("仕訳明細がありません");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (lines.length < 2) {
|
||||||
|
alert("至少需要借方和贷方各一行");
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 借貸一致チェック(最小)
|
// 借貸一致チェック(最小)
|
||||||
if (totalDebit !== totalCredit) {
|
if (totalDebit !== totalCredit) {
|
||||||
alert(`借方(${totalDebit.toLocaleString()})と貸方(${totalCredit.toLocaleString()})が一致しません`);
|
alert(
|
||||||
|
`借方(${totalDebit.toLocaleString()})と貸方(${totalCredit.toLocaleString()})が一致しません`
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,19 +460,19 @@ async function submitJournal() {
|
|||||||
const res = await fetch(`${API}/journal-entries`, {
|
const res = await fetch(`${API}/journal-entries`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify(payload)
|
body: JSON.stringify(payload),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res.ok) { alert("登録に失敗しました"); return; }
|
if (!res.ok) {
|
||||||
|
alert("登録に失敗しました");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const result = await res.json();
|
const result = await res.json();
|
||||||
alert(`登録完了(ID=${result.journal_entry_id})`);
|
alert(`登録完了(ID=${result.journal_entry_id})`);
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const API_BASE = "http://127.0.0.1:18080";
|
const API_BASE = "http://127.0.0.1:18080";
|
||||||
|
|
||||||
async function callApi(path) {
|
async function callApi(path) {
|
||||||
@@ -355,7 +480,11 @@ async function callApi(path) {
|
|||||||
const res = await fetch(`${API_BASE}${path}`, { method: "POST" });
|
const res = await fetch(`${API_BASE}${path}`, { method: "POST" });
|
||||||
const text = await res.text();
|
const text = await res.text();
|
||||||
let data = {};
|
let data = {};
|
||||||
try { data = text ? JSON.parse(text) : {}; } catch { data = { detail: text }; }
|
try {
|
||||||
|
data = text ? JSON.parse(text) : {};
|
||||||
|
} catch {
|
||||||
|
data = { detail: text };
|
||||||
|
}
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
throw new Error(data.detail || `HTTP ${res.status}`);
|
throw new Error(data.detail || `HTTP ${res.status}`);
|
||||||
@@ -390,7 +519,9 @@ async function unlockMonth() {
|
|||||||
el.innerText = "处理中...";
|
el.innerText = "处理中...";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await callApi(`/month-locks/unlock?fiscal_year=${year}&month=${month}`);
|
await callApi(
|
||||||
|
`/month-locks/unlock?fiscal_year=${year}&month=${month}`
|
||||||
|
);
|
||||||
el.innerText = `✅ ${year}年${month}月 已解锁`;
|
el.innerText = `✅ ${year}年${month}月 已解锁`;
|
||||||
await refreshMonthLocks(); // 可选:自动刷新列表
|
await refreshMonthLocks(); // 可选:自动刷新列表
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -398,7 +529,6 @@ async function unlockMonth() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function refreshMonthLocks() {
|
async function refreshMonthLocks() {
|
||||||
const el = document.getElementById("lockList");
|
const el = document.getElementById("lockList");
|
||||||
el.textContent = "读取中...";
|
el.textContent = "读取中...";
|
||||||
@@ -408,7 +538,7 @@ async function refreshMonthLocks() {
|
|||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
// 只显示 locked 的,避免太长
|
// 只显示 locked 的,避免太长
|
||||||
const locked = (data || []).filter(x => x.is_locked);
|
const locked = (data || []).filter((x) => x.is_locked);
|
||||||
|
|
||||||
if (locked.length === 0) {
|
if (locked.length === 0) {
|
||||||
el.textContent = "(当前没有锁定月份)";
|
el.textContent = "(当前没有锁定月份)";
|
||||||
@@ -416,15 +546,19 @@ async function refreshMonthLocks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
el.textContent = locked
|
el.textContent = locked
|
||||||
.map(x => `${x.fiscal_year}-${String(x.month).padStart(2, "0")} locked_by=${x.locked_by ?? ""}`)
|
.map(
|
||||||
|
(x) =>
|
||||||
|
`${x.fiscal_year}-${String(x.month).padStart(
|
||||||
|
2,
|
||||||
|
"0"
|
||||||
|
)} locked_by=${x.locked_by ?? ""}`
|
||||||
|
)
|
||||||
.join("\n");
|
.join("\n");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
el.textContent = `读取失败:${e.message || e}`;
|
el.textContent = `读取失败:${e.message || e}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function checkMonthLockByDate(dateStr) {
|
async function checkMonthLockByDate(dateStr) {
|
||||||
if (!dateStr) return false;
|
if (!dateStr) return false;
|
||||||
|
|
||||||
@@ -436,7 +570,7 @@ async function checkMonthLockByDate(dateStr) {
|
|||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
return (data || []).some(
|
return (data || []).some(
|
||||||
x => x.fiscal_year === year && x.month === month && x.is_locked
|
(x) => x.fiscal_year === year && x.month === month && x.is_locked
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,7 +589,6 @@ async function onEntryDateChanged() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function setJournalReadonly(readonly) {
|
function setJournalReadonly(readonly) {
|
||||||
// 保存按钮
|
// 保存按钮
|
||||||
const saveBtn = document.getElementById("saveButton");
|
const saveBtn = document.getElementById("saveButton");
|
||||||
@@ -466,16 +599,50 @@ function setJournalReadonly(readonly) {
|
|||||||
if (addRowBtn) addRowBtn.disabled = readonly;
|
if (addRowBtn) addRowBtn.disabled = readonly;
|
||||||
|
|
||||||
// 所有“删除行”按钮
|
// 所有“删除行”按钮
|
||||||
document.querySelectorAll(".delete-row-btn").forEach(btn => {
|
document.querySelectorAll(".delete-row-btn").forEach((btn) => {
|
||||||
btn.disabled = readonly;
|
btn.disabled = readonly;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 所有仕訳输入项(金额 / 科目等)
|
// 所有仕訳输入项(金额 / 科目等)
|
||||||
document.querySelectorAll(".journal-input").forEach(input => {
|
document.querySelectorAll(".journal-input").forEach((input) => {
|
||||||
input.disabled = readonly;
|
input.disabled = readonly;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
|
||||||
|
|
||||||
|
function buildAccountOptions() {
|
||||||
|
let html = "";
|
||||||
|
|
||||||
|
// 已分组的科目
|
||||||
|
ACCOUNT_GROUPS.forEach((group) => {
|
||||||
|
html += `<optgroup label="${group.label}">`;
|
||||||
|
accounts
|
||||||
|
.filter((a) => group.codes.includes(a.account_code))
|
||||||
|
.forEach((a) => {
|
||||||
|
html += `<option value="${a.account_id}">
|
||||||
|
${a.account_code} ${a.account_name}
|
||||||
|
</option>`;
|
||||||
|
});
|
||||||
|
html += `</optgroup>`;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 未分组的其他科目
|
||||||
|
const groupedCodes = ACCOUNT_GROUPS.flatMap((g) => g.codes);
|
||||||
|
const others = accounts.filter(
|
||||||
|
(a) => !groupedCodes.includes(a.account_code)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (others.length > 0) {
|
||||||
|
html += `<optgroup label="📚 その他">`;
|
||||||
|
others.forEach((a) => {
|
||||||
|
html += `<option value="${a.account_id}">
|
||||||
|
${a.account_code} ${a.account_name}
|
||||||
|
</option>`;
|
||||||
|
});
|
||||||
|
html += `</optgroup>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
0
frontend/pages/cash-transactions.html
Normal file
0
frontend/pages/cash-transactions.html
Normal file
202
frontend/pages/cash.html
Normal file
202
frontend/pages/cash.html
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="ja">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<title>資金状況</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: sans-serif;
|
||||||
|
margin: 24px;
|
||||||
|
}
|
||||||
|
h2,
|
||||||
|
h3 {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
width: 100%;
|
||||||
|
margin-top: 12px;
|
||||||
|
}
|
||||||
|
th,
|
||||||
|
td {
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
padding: 6px;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
th {
|
||||||
|
background: #f5f5f5;
|
||||||
|
}
|
||||||
|
th.left,
|
||||||
|
td.left {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
.total {
|
||||||
|
font-weight: bold;
|
||||||
|
background: #f0f0f0;
|
||||||
|
}
|
||||||
|
.filter {
|
||||||
|
margin: 8px 0;
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
input,
|
||||||
|
select,
|
||||||
|
button {
|
||||||
|
padding: 4px 6px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h2>💰 現在の資金状況</h2>
|
||||||
|
|
||||||
|
<!-- 残高 -->
|
||||||
|
<table id="balanceTable">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="left">口座</th>
|
||||||
|
<th>残高</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody></tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr class="total">
|
||||||
|
<td class="left">合計</td>
|
||||||
|
<td id="totalBalance">-</td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
|
||||||
|
<h3>📄 資金流水</h3>
|
||||||
|
|
||||||
|
<!-- 条件 -->
|
||||||
|
<div class="filter">
|
||||||
|
<label>口座:</label>
|
||||||
|
<select id="accountSelect"></select>
|
||||||
|
|
||||||
|
<label>期間:</label>
|
||||||
|
<input type="date" id="fromDate" />
|
||||||
|
〜
|
||||||
|
<input type="date" id="toDate" />
|
||||||
|
|
||||||
|
<button onclick="reloadTransactions()">表示</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 流水表 -->
|
||||||
|
<table id="txTable">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="left">日付</th>
|
||||||
|
<th class="left">摘要</th>
|
||||||
|
<th class="left">相手科目</th>
|
||||||
|
<th>入金</th>
|
||||||
|
<th>出金</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody></tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const API = "http://127.0.0.1:8000";
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
// 初期化
|
||||||
|
// --------------------
|
||||||
|
async function init() {
|
||||||
|
await loadBalances();
|
||||||
|
await loadAccounts();
|
||||||
|
|
||||||
|
// 初期期間:当月
|
||||||
|
const now = new Date();
|
||||||
|
const first = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||||
|
document.getElementById("fromDate").value = first
|
||||||
|
.toISOString()
|
||||||
|
.slice(0, 10);
|
||||||
|
document.getElementById("toDate").value = now
|
||||||
|
.toISOString()
|
||||||
|
.slice(0, 10);
|
||||||
|
}
|
||||||
|
init();
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
// 残高
|
||||||
|
// --------------------
|
||||||
|
async function loadBalances() {
|
||||||
|
const res = await fetch(`${API}/cash/balance`);
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
|
const tbody = document.querySelector("#balanceTable tbody");
|
||||||
|
tbody.innerHTML = "";
|
||||||
|
|
||||||
|
data.items.forEach((i) => {
|
||||||
|
tbody.innerHTML += `
|
||||||
|
<tr>
|
||||||
|
<td class="left">${i.account_name}</td>
|
||||||
|
<td>${Number(i.balance).toLocaleString()}</td>
|
||||||
|
</tr>`;
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById("totalBalance").innerText = Number(
|
||||||
|
data.total_balance
|
||||||
|
).toLocaleString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
// 口座一覧
|
||||||
|
// --------------------
|
||||||
|
async function loadAccounts() {
|
||||||
|
const res = await fetch(`${API}/cash/balance`);
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
|
const sel = document.getElementById("accountSelect");
|
||||||
|
sel.innerHTML = data.items
|
||||||
|
.map(
|
||||||
|
(i) => `<option value="${i.account_id}">${i.account_name}</option>`
|
||||||
|
)
|
||||||
|
.join("");
|
||||||
|
|
||||||
|
reloadTransactions();
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
// 再表示
|
||||||
|
// --------------------
|
||||||
|
function reloadTransactions() {
|
||||||
|
const accountId = document.getElementById("accountSelect").value;
|
||||||
|
const from = document.getElementById("fromDate").value;
|
||||||
|
const to = document.getElementById("toDate").value;
|
||||||
|
|
||||||
|
loadTransactions(accountId, from, to);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
// 流水
|
||||||
|
// --------------------
|
||||||
|
async function loadTransactions(accountId, from, to) {
|
||||||
|
let url = `${API}/cash/transactions?account_id=${accountId}`;
|
||||||
|
if (from) url += `&from=${from}`;
|
||||||
|
if (to) url += `&to=${to}`;
|
||||||
|
|
||||||
|
const res = await fetch(url);
|
||||||
|
const rows = await res.json();
|
||||||
|
|
||||||
|
const tbody = document.querySelector("#txTable tbody");
|
||||||
|
tbody.innerHTML = "";
|
||||||
|
|
||||||
|
rows.forEach((r) => {
|
||||||
|
tbody.innerHTML += `
|
||||||
|
<tr>
|
||||||
|
<td class="left">${r.journal_date}</td>
|
||||||
|
<td class="left">${r.description}</td>
|
||||||
|
<td class="left">${r.counter_account}</td>
|
||||||
|
<td>${r.amount > 0 ? r.amount.toLocaleString() : ""}</td>
|
||||||
|
<td>${r.amount < 0 ? (-r.amount).toLocaleString() : ""}</td>
|
||||||
|
</tr>`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -2,13 +2,18 @@
|
|||||||
<html lang="ja">
|
<html lang="ja">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title>试算表</title>
|
<title>試算表</title>
|
||||||
<style>
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: sans-serif;
|
||||||
|
margin: 24px;
|
||||||
|
}
|
||||||
table {
|
table {
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
th, td {
|
th,
|
||||||
|
td {
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
padding: 6px 10px;
|
padding: 6px 10px;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
@@ -26,16 +31,17 @@
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h2>試算表</h2>
|
<h2>試算表</h2>
|
||||||
|
|
||||||
<table id="trialBalanceTable">
|
<table id="trialBalanceTable">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>科目代码</th>
|
<th class="left">科目コード</th>
|
||||||
<th>科目名称</th>
|
<th class="left">科目名称</th>
|
||||||
<th>借方合计</th>
|
<th>期首残高</th>
|
||||||
<th>贷方合计</th>
|
<th>借方合計</th>
|
||||||
|
<th>贷方合計</th>
|
||||||
|
<th>期末残高</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -43,14 +49,59 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">合计</td>
|
<td colspan="2" class="left">合計</td>
|
||||||
|
<td id="totalOpening">0</td>
|
||||||
<td id="totalDebit">0</td>
|
<td id="totalDebit">0</td>
|
||||||
<td id="totalCredit">0</td>
|
<td id="totalCredit">0</td>
|
||||||
|
<td id="totalClosing">0</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<script src="./js/trial-balance.js"></script>
|
<script>
|
||||||
|
const API_BASE = "http://127.0.0.1:18080"; // 和你后端一致
|
||||||
|
|
||||||
|
async function loadTrialBalance() {
|
||||||
|
const res = await fetch(`${API_BASE}/trial-balance`);
|
||||||
|
if (!res.ok) {
|
||||||
|
alert("試算表の取得に失敗しました");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
|
const tbody = document.querySelector("#trialBalanceTable tbody");
|
||||||
|
tbody.innerHTML = "";
|
||||||
|
|
||||||
|
data.accounts.forEach((acc) => {
|
||||||
|
const tr = document.createElement("tr");
|
||||||
|
tr.innerHTML = `
|
||||||
|
<td class="left">${acc.account_code}</td>
|
||||||
|
<td class="left">${acc.account_name}</td>
|
||||||
|
<td>${Number(acc.opening_balance).toLocaleString()}</td>
|
||||||
|
<td>${Number(acc.debit).toLocaleString()}</td>
|
||||||
|
<td>${Number(acc.credit).toLocaleString()}</td>
|
||||||
|
<td>${Number(acc.closing_balance).toLocaleString()}</td>
|
||||||
|
`;
|
||||||
|
tbody.appendChild(tr);
|
||||||
|
});
|
||||||
|
|
||||||
|
// totals
|
||||||
|
document.getElementById("totalOpening").innerText = Number(
|
||||||
|
data.totals.opening_balance
|
||||||
|
).toLocaleString();
|
||||||
|
document.getElementById("totalDebit").innerText = Number(
|
||||||
|
data.totals.debit
|
||||||
|
).toLocaleString();
|
||||||
|
document.getElementById("totalCredit").innerText = Number(
|
||||||
|
data.totals.credit
|
||||||
|
).toLocaleString();
|
||||||
|
document.getElementById("totalClosing").innerText = Number(
|
||||||
|
data.totals.closing_balance
|
||||||
|
).toLocaleString();
|
||||||
|
}
|
||||||
|
|
||||||
|
loadTrialBalance();
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
20
メモ.txt
20
メモ.txt
@@ -119,3 +119,23 @@ updated_reason:
|
|||||||
可空
|
可空
|
||||||
|
|
||||||
例如:金额修正、补录摘要、对账调整
|
例如:金额修正、补录摘要、对账调整
|
||||||
|
|
||||||
|
|
||||||
|
-------------------------------
|
||||||
|
/volume1/docker/rc_ollama_bot/
|
||||||
|
bot.py
|
||||||
|
① 停掉并删除旧容器(非常关键)
|
||||||
|
docker stop ollama-rc-bot
|
||||||
|
docker rm ollama-rc-bot
|
||||||
|
docker build --no-cache -t ollama-rc-bot .
|
||||||
|
② 重新 build 镜像(必须)
|
||||||
|
docker build --no-cache -t ollama-rc-bot .
|
||||||
|
③ 重新启动容器
|
||||||
|
docker run -d \
|
||||||
|
--name ollama-rc-bot \
|
||||||
|
-p 5100:5005 \
|
||||||
|
ollama-rc-bot
|
||||||
|
|
||||||
|
docker run -d --name ollama-rc-bot -p 5100:5005 ollama-rc-bot
|
||||||
|
④ 看日志,确认新代码真的在跑
|
||||||
|
docker logs -f ollama-rc-bot
|
||||||
|
|||||||
Reference in New Issue
Block a user