0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

レバテックプラットフォーム勤怠自動入力スクリプト

Last updated at Posted at 2023-06-30

consoleに貼り付けて実行。
fillForm(csvData, '202306')のような形式

// CSVデータをパースする関数を定義します。
function parseCSVData(csvData) {
    let lines = csvData.split('\n');
    let timeData = lines.map(line => line.split(',')).filter(arr => arr.length === 3);
    return timeData;
}

// CSVデータを用いてフォームを自動入力する関数を定義します。
function fillForm(csvData, yearMonth) {
    // CSVデータをパースします。
    let timeData = parseCSVData(csvData);

    // 各日付に対して入力データをセットします。
    for (let i = 0; i < timeData.length; i++) {
        let startTime = timeData[i][0];
        let endTime = timeData[i][1];
        let relaxTime = timeData[i][2];

        // HTML要素を取得します。
        let startTimeInput = document.querySelector(`input[name='data[DailyReport][${yearMonth}${String(i + 1).padStart(2, '0')}][start_time]']`);
        let endTimeInput = document.querySelector(`input[name='data[DailyReport][${yearMonth}${String(i + 1).padStart(2, '0')}][end_time]']`);
        let relaxTimeInput = document.querySelector(`input[name='data[DailyReport][${yearMonth}${String(i + 1).padStart(2, '0')}][relax_time]']`);

        // データが空でなければ値をセットします。
        if (startTime.trim() !== '' && startTimeInput) startTimeInput.value = startTime;
        if (endTime.trim() !== '' && endTimeInput) endTimeInput.value = endTime;
        if (relaxTime.trim() !== '' && relaxTimeInput) relaxTimeInput.value = relaxTime;
    }
}

想定データ

開始、終了、休憩順のcsvデータ

let csvData = `
10:00,18:00,01:00
10:00,18:00,01:00
,,
,,
10:00,18:00,01:00
10:00,18:00,01:00
10:00,18:00,01:00
,,
,,
10:00,18:00,01:00
10:00,18:00,01:00
10:00,18:00,01:00
,,
,,
10:00,18:00,01:00
10:00,18:00,01:00
10:00,18:00,01:00
,,
,,
10:00,18:00,01:00
10:00,18:00,01:00
10:00,18:00,01:00
,,
,,
10:00,18:00,01:00
`;

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?