個別配慮

This commit is contained in:
2025-02-15 17:36:52 +08:00
parent 41a6388d73
commit 82ce762d16
16 changed files with 3682 additions and 33 deletions

View File

@@ -18,8 +18,109 @@
headerSpace.appendChild(elements['extract-action-area']);
});
function handleButtonClick(e, { year, month }) {
const fileName = getExcelName(APP_ENV, year + month);
console.log(fileName);
async function handleButtonClick(e, { year, month }) {
loading(true, '帳票出力中...');
showError(false);
const api = new KintoneRestAPIClient();
// 本アプリからデータを読み取る
const currentAppRecords = await getRecords(api, year, month);
if (!currentAppRecords) {
// エラー
loading(false);
return e;
}
const excelName = APP_ENV.excelName;
await createExcelAndDownload({
api,
excelName,
exportName: getExcelName(excelName, year + month),
bizLogic: writeExcel(currentAppRecords, year, month),
});
loading(false);
}
async function getRecords(api, year, month) {
const firstDate = getFormatDateString(year, month, 1)
const lastDate = getFormatDateString(getLastDate(year, month));
try {
return await api.record.getAllRecordsWithId({
app: env["個別配慮"].appId,
condition: `日付 >= "${firstDate}" and 日付 <= "${lastDate}"`
});
} catch (e) {
showError(true, '本アプリのデータ読み取りエラー\n - ' + e);
}
}
function writeExcel(records, year, month) {
return async (api, worksheet) => {
if (!records || !records.length) {
return;
}
const baseCells = findCellsInfo(worksheet, ['園長', '月', '児童名']);
const signLabels = ['園長', '主幹', '指導', '担任'];
const signRow = baseCells['園長'][0].row + 1;
for (let i = 0; i < signLabels.length; i++) {
worksheet.getCell(signRow, baseCells['園長'][0].col + i).value = records[0][signLabels[i]].value; // TODO force use records[0]?
}
const pageSize = 10;
const totalPages = Math.ceil(records.length / pageSize);
if (totalPages > 2) {
const lastPage = 2;
const copyPageRowStart = baseCells['月'][lastPage - 1].row - 1;
const copyPageRowEnd = baseCells['児童名'][lastPage - 1].row + pageSize;
const rowCount = copyPageRowEnd - copyPageRowStart + 1;
let newPageRow = copyPageRowEnd + 1;
for (let p = 3; p <= totalPages; p++) {
const copyRow = pvc.lib.exceljsUtil.copyRows(worksheet, copyPageRowStart, copyPageRowEnd);
pvc.lib.exceljsUtil.insertRows(worksheet, newPageRow, copyRow);
newPageRow += rowCount;
['月', '児童名'].forEach((label) => {
const last = baseCells[label][p - 2];
baseCells[label].push({
...last,
row: last.row + rowCount
});
})
}
}
const cols = getLabelColsMapping(worksheet, baseCells['児童名'][0].row, ['児童名', '子どもの姿', '保育者援助_配慮_環境構成']);
const sortedRecords = records.sort((a, b) => Number(a['レコード番号'].value) - Number(b['レコード番号'].value));
for (let i = 0; i < totalPages; i++) {
const monthLabelCell = baseCells['月'][i];
worksheet.getCell(monthLabelCell.row, monthLabelCell.col - 1).value = Number(month);
const childLabelCell = baseCells['児童名'][i];
let currentRow = childLabelCell.row + 1;
for (let j = 0; j < pageSize; j++) {
const index = i * pageSize + j;
const record = sortedRecords[index];
if (!record) {
break;
}
const row = worksheet.getRow(currentRow);
cols.forEach(col => {
row.getCell(col.index).value = record[col.field].value;
row.getCell(col.index).alignment = { wrapText: true };;
});
currentRow++;
}
worksheet.getRow(childLabelCell.row + pageSize).addPageBreak();
}
}
}
})();