This commit is contained in:
admin
2026-02-01 21:01:19 +09:00
parent a2d7b54cd3
commit cf17eef442
3 changed files with 44 additions and 25 deletions

View File

@@ -1731,9 +1731,9 @@
// 年月を解析
const [startYear, startMonth] = startYM.split("-").map(Number);
const endYM = document.getElementById("voucherEndYearMonth").value;
const [endYear, endMonth] = endYM
? endYM.split("-").map(Number)
: [startYear, startMonth];
const endParts = endYM ? endYM.split("-").map(Number) : null;
const endYear = endParts ? endParts[0] : null;
const endMonth = endParts ? endParts[1] : null;
const voucherType = document.querySelector(
"input[name='voucherType']:checked",
@@ -1751,6 +1751,8 @@
format: "preview",
};
console.log("送信ペイロード:", JSON.stringify(payload, null, 2));
const response = await fetch(`${API_BASE}/payroll/vouchers/export`, {
method: "POST",
headers: { "Content-Type": "application/json" },
@@ -1758,6 +1760,7 @@
});
const result = await response.json();
console.log("レスポンス:", result);
if (!result.has_data) {
alert(result.message || "データが見つかりません");
@@ -1845,9 +1848,8 @@
const generationDate = new Date().toLocaleDateString("ja-JP");
// グループ化: 従業員ごと、年月ごと
let currentEmployeeId = null;
let currentYearMonth = null;
// グループ化: 従業員ごと、年月ごと、給与/賞与ごと
let currentKey = null;
let pageOpen = false;
if (result.summary && Array.isArray(result.summary)) {
@@ -1864,16 +1866,15 @@
// 給与データの処理
salaries.forEach((salary) => {
const salaryYearMonth = `${salary.payroll_year}-${salary.payroll_month}`;
const currentKey_new = `${emp.employee_id}-${salaryYearMonth}-salary`;
const paymentDate = `${salary.payroll_year}${String(salary.payroll_month).padStart(2, "0")}${getLastDayOfMonth(salary.payroll_year, salary.payroll_month)}`;
if (
currentEmployeeId !== emp.employee_id ||
currentYearMonth !== salaryYearMonth
) {
// 新しいキーが異なる場合は新しいページを開く
if (currentKey !== currentKey_new) {
if (pageOpen) {
printHtml += "</div>";
}
currentEmployeeId = emp.employee_id;
currentYearMonth = salaryYearMonth;
currentKey = currentKey_new;
printHtml += '<div class="page">';
printHtml += `<div style="font-size: 11px; color: #999; margin-bottom: 10px; text-align: right;">帳票生成日: ${generationDate}</div>`;
pageOpen = true;
@@ -1978,16 +1979,15 @@
// 賞与データの処理
bonuses.forEach((bonus) => {
const bonusYearMonth = `${bonus.bonus_year}-${bonus.bonus_month}`;
const currentKey_new = `${emp.employee_id}-${bonusYearMonth}-bonus`;
const bonusPaymentDate = `${bonus.bonus_year}${String(bonus.bonus_month).padStart(2, "0")}${getLastDayOfMonth(bonus.bonus_year, bonus.bonus_month)}`;
if (
currentEmployeeId !== emp.employee_id ||
currentYearMonth !== bonusYearMonth
) {
// 新しいキーが異なる場合は新しいページを開く
if (currentKey !== currentKey_new) {
if (pageOpen) {
printHtml += "</div>";
}
currentEmployeeId = emp.employee_id;
currentYearMonth = bonusYearMonth;
currentKey = currentKey_new;
printHtml += '<div class="page">';
printHtml += `<div style="font-size: 11px; color: #999; margin-bottom: 10px; text-align: right;">帳票生成日: ${generationDate}</div>`;
pageOpen = true;
@@ -2101,9 +2101,9 @@
const [startYear, startMonth] = startYM.split("-").map(Number);
const endYM = document.getElementById("voucherEndYearMonth").value;
const [endYear, endMonth] = endYM
? endYM.split("-").map(Number)
: [startYear, startMonth];
const endParts = endYM ? endYM.split("-").map(Number) : null;
const endYear = endParts ? endParts[0] : null;
const endMonth = endParts ? endParts[1] : null;
const voucherType = document.querySelector(
"input[name='voucherType']:checked",
).value;