Оглавление

Этот скрипт обрабатывает записи о рабочем времени и формирует ежедневную статистику посещаемости с временем прихода и ухода по каждому сотруднику.

You need two tables:

  • Time records: Contains columns Name, Date, and Time with the raw clocking data.
  • Statistics: Contains columns Name, Date, Clock in, and Clock out for the results.
const timeRecordsTable = base.getTableByName('Time records');
const statisticsTable = base.getTableByName('Statistics');
const view = base.getViewByName(timeRecordsTable, 'Default View');
const rows = base.getRows(timeRecordsTable, view);

// Group by date and name
const groups = {};
rows.forEach(row => {
    const name = row['Name'] || '';
    const date = row['Date'] || '';
    const time = row['Time'] || '';
    if (!name || !date || !time) return;

    const key = date + '_' + name;
    if (!groups[key]) {
        groups[key] = {name: name, date: date, times: []};
    }
    groups[key].times.push(time);
});

// Create statistics entries
Object.keys(groups).forEach(key => {
    const group = groups[key];
    const sortedTimes = group.times.sort();
    const clockIn = sortedTimes[0];
    const clockOut = sortedTimes[sortedTimes.length - 1];

    base.addRow(statisticsTable, {
        'Name': group.name,
        'Date': group.date,
        'Clock in': clockIn,
        'Clock out': clockOut
    });
});

output.text('Attendance statistics computed.');

Adjust the table and column names to match your setup. The script always appends new rows to the statistics table – if you run it multiple times, you may want to clear the statistics table first.

For the complete function reference, visit the SeaTable Developer Manual .