Last active
October 1, 2021 00:07
-
-
Save kuniiskywalker/59907ab09b10e462dc4e6a3afddfa898 to your computer and use it in GitHub Desktop.
Saleformの工数実績から月次で稼動一覧をCSV形式で取得するためのJS(ただしコンソール出力)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
const normalize = (month, report) => { | |
return Object.keys(report).map(key => { | |
const restHour = report[key]["worktime"] && Number(report[key]["worktime"].split(':')[0]) >= 7 ? 1: 0 | |
const endHour = report[key]["worktime"]? ('00' + (Number(report[key]["worktime"].split(':')[0]) + 10 + restHour)).slice(-2) : "00"; | |
const endMinute = report[key]["worktime"]? ('00' + (Number(report[key]["worktime"].split(':')[1]))).slice(-2) : "00"; | |
return [ | |
month + "/" + key, | |
report[key]["week"], | |
report[key]["worktime"]? "10:00": "0:00", | |
endHour + ":" + endMinute, | |
restHour + ":00", | |
report[key]["worktime"]? report[key]["worktime"]: "0:00", | |
report[key]["task"] | |
] | |
}) | |
} | |
const arrToCSV = arr => { | |
return arr | |
.map(row => row.map(str => '"' + (str ? str.replace(/"/g, '""') : '') + '"')) | |
.map(row => row.join(',')) | |
.join('\n'); | |
} | |
let report = {}; | |
let activeMonth; | |
let activeDay; | |
document.querySelectorAll('.emp_work_data tr').forEach(item => { | |
let dayItem = item.querySelector('.date_label div'); | |
if (dayItem) { | |
let weekItem = item.querySelector('.yobi div'); | |
let day = dayItem.innerText; | |
activeDay = day; | |
let matches = day.match(/(\d+)\/(\d+)/); | |
if (matches) { | |
activeMonth = matches[1]; | |
day = matches[2]; | |
activeDay = day; | |
} | |
let week = weekItem.innerText; | |
report[day] = { | |
"week": week | |
} | |
} | |
let worknote = item.querySelector('div.worknote'); | |
if (worknote) { | |
if (report[activeDay] && worknote && worknote.innerText) { | |
report[activeDay]["worktime"] = worknote.innerText.match(/\(計 (\d+:\d+)\)/)[1]; | |
report[activeDay]["task"] = worknote.innerText.match(/\(計 (\d+:\d+)\)([\s\S]*)/)[2].trim().replace("\n", ","); | |
} | |
} | |
}) | |
const array = normalize(activeMonth, report); | |
const content = arrToCSV(array); | |
console.log(content) | |
}) (); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment