diff --git a/src/6.個別配慮/main.js b/src/6.個別配慮/main.js index e5ccc02..32be35c 100644 --- a/src/6.個別配慮/main.js +++ b/src/6.個別配慮/main.js @@ -1,6 +1,8 @@ (function () { "use strict"; const APP_ENV = env["個別配慮"]; + // 20250911に追加された、月次サフィックスを持つフィールドのリスト + const monthlyField = ['子どもの姿', '保育者援助_配慮_環境構成', '反省_評価', '主幹', '園長', '担任', '指導'] kintone.events.on("app.record.index.show", (event) => { const headerSpace = getHeaderSpace('single-label-line'); @@ -23,27 +25,58 @@ showError(false); const api = new KintoneRestAPIClient(); + const monthNumber = Number(month); + const yearNumber = Number(year); // 本アプリからデータを読み取る - const currentAppRecords = await getRecords(api, year, month); + const currentAppRecords = await getYearlyRecords(api, yearNumber, monthNumber); if (!currentAppRecords) { // エラー loading(false); return e; } + const eachChildUniqueRecord = {}; + // 各児童の最新の記録を取得する(日付フィールドに基づく) + for (const record of currentAppRecords) { + const key = record['園児ユニークキー'].value; + const existData = eachChildUniqueRecord[key]; + if (!existData || existData['日付'].value < record['日付'].value) { + eachChildUniqueRecord[key] = record; + } + } + const records = Object.values(eachChildUniqueRecord); + + // 指定された月のデータを、月次サフィックスのないフィールドにマッピングする(例:「子どもの姿_5月」=>「子どもの姿」) + // 既存のコード(元々は月次サフィックスのないフィールドを使用)を極力変更しないようにするため + // 4月のデータはデフォルトで月次サフィックスのないフィールドに格納されているため、4月の処理はスキップする + if (monthNumber !== 4) { + for (const field of monthlyField) { + for (const record of records) { + record[field].value = record[`${field}_${monthNumber}月`].value; + } + } + } + const excelName = APP_ENV.excelName; await createExcelAndDownload({ api, excelName, exportName: getExcelName(excelName, year + month), - bizLogic: writeExcel(currentAppRecords, year, month), + bizLogic: writeExcel(records, year, month), }); loading(false); } - async function getRecords(api, year, month) { - const firstDate = getFormatDateString(year, month, 1) - const lastDate = getFormatDateString(getLastDate(year, month)); + async function getYearlyRecords(api, year, month) { + let fromYear = year; + let toYear = year; + if (month < 4) { + fromYear--; + } else { + toYear++; + } + const firstDate = getFormatDateString(fromYear, 4, 1) + const lastDate = getFormatDateString(getLastDate(toYear, 3)); try { return await api.record.getAllRecordsWithId({ app: env["個別配慮"].appId, @@ -123,7 +156,6 @@ const sortedRecords = records.sort((a, b) => Number(a['出席番号'].value) - Number(b['出席番号'].value)); // 2. sort by 学年 - debugger; const termOrder = {}; termItems.forEach((item, index) => { termOrder[item.value] = index;