diff --git a/src/Billing/Utils.js b/src/Billing/Utils.js index fd6289c..5dbee95 100644 --- a/src/Billing/Utils.js +++ b/src/Billing/Utils.js @@ -41,7 +41,7 @@ function include(filename) { * @return {Array} array with name of all clients */ function getClients() { - return Utils.sort(Utils.convertObjectsToArrayByProperty(Utils.findClients(), 'name')); + return Utils.sort(Utils.convertObjectsToArrayByProperty(Utils.findClients(['name']), 'name')); } /** diff --git a/src/Billing/WriteBilling.js b/src/Billing/WriteBilling.js index 4f97837..05903be 100644 --- a/src/Billing/WriteBilling.js +++ b/src/Billing/WriteBilling.js @@ -7,9 +7,12 @@ * @return {string} url of new spreadsheet */ function createBilling(from, to, client) { - const spreadsheetData = Utils.extractAllSpreadsheetData(from, to); + const groups = Utils.convertObjectsToArrayByProperty(Utils.findGroupClients(['group'], { name: client }), 'group'); + const groupSet = new Set(groups); + const spreadsheetData = Utils.extractAllSpreadsheetData(from, to, groupSet); const ss = Utils.createSpreadsheet({ - type: 'Fakturace' + type: 'Fakturace', + details: client }); const sheet = ss.getActiveSheet(); diff --git a/src/Billing/appsscript.json b/src/Billing/appsscript.json index 56d9438..6794902 100644 --- a/src/Billing/appsscript.json +++ b/src/Billing/appsscript.json @@ -5,7 +5,7 @@ { "userSymbol": "Utils", "libraryId": "1WquYtBor0ObwHMo1oIhKnCgboR5zBx2wjh5Hu-rbb0oSA5cY0d2PM6dZ", - "version": 87 + "version": 89 } ] }, diff --git a/src/CalendarAndFilesScheduler/appsscript.json b/src/CalendarAndFilesScheduler/appsscript.json index f289c58..685e26f 100644 --- a/src/CalendarAndFilesScheduler/appsscript.json +++ b/src/CalendarAndFilesScheduler/appsscript.json @@ -5,7 +5,7 @@ { "userSymbol": "Utils", "libraryId": "1WquYtBor0ObwHMo1oIhKnCgboR5zBx2wjh5Hu-rbb0oSA5cY0d2PM6dZ", - "version": 87 + "version": 89 } ] }, diff --git a/src/ConsistencyChecker/appsscript.json b/src/ConsistencyChecker/appsscript.json index f0f0890..32002ef 100644 --- a/src/ConsistencyChecker/appsscript.json +++ b/src/ConsistencyChecker/appsscript.json @@ -7,7 +7,7 @@ { "userSymbol": "Utils", "libraryId": "1WquYtBor0ObwHMo1oIhKnCgboR5zBx2wjh5Hu-rbb0oSA5cY0d2PM6dZ", - "version": 87 + "version": 89 } ] } diff --git a/src/Create/appsscript.json b/src/Create/appsscript.json index 56d9438..6794902 100644 --- a/src/Create/appsscript.json +++ b/src/Create/appsscript.json @@ -5,7 +5,7 @@ { "userSymbol": "Utils", "libraryId": "1WquYtBor0ObwHMo1oIhKnCgboR5zBx2wjh5Hu-rbb0oSA5cY0d2PM6dZ", - "version": 87 + "version": 89 } ] }, diff --git a/src/Delete/appsscript.json b/src/Delete/appsscript.json index 56d9438..6794902 100644 --- a/src/Delete/appsscript.json +++ b/src/Delete/appsscript.json @@ -5,7 +5,7 @@ { "userSymbol": "Utils", "libraryId": "1WquYtBor0ObwHMo1oIhKnCgboR5zBx2wjh5Hu-rbb0oSA5cY0d2PM6dZ", - "version": 87 + "version": 89 } ] }, diff --git a/src/EmailSender/appsscript.json b/src/EmailSender/appsscript.json index 56d9438..6794902 100644 --- a/src/EmailSender/appsscript.json +++ b/src/EmailSender/appsscript.json @@ -5,7 +5,7 @@ { "userSymbol": "Utils", "libraryId": "1WquYtBor0ObwHMo1oIhKnCgboR5zBx2wjh5Hu-rbb0oSA5cY0d2PM6dZ", - "version": 87 + "version": 89 } ] }, diff --git a/src/PdfBackuper/Code.js b/src/PdfBackuper/Code.js index 48d25ba..73ed281 100644 --- a/src/PdfBackuper/Code.js +++ b/src/PdfBackuper/Code.js @@ -31,7 +31,7 @@ function doGet(e) { function processForm(formObject) { try { var errorMsg = {fromErr:'',toErr:''}; - var from,to; + var from, to, group, groupHumanReadableName; from = Utils.validate(errorMsg,formObject.fromBox,{ actions:['validateDate',], @@ -55,9 +55,24 @@ function processForm(formObject) { errorMsg.fromErr = '*datum od je větší než datum do'; } + group = formObject.selectBox; + if (group == null) { + group = ''; + } + if (group != '') { + group = Utils.validate(errorMsg,formObject.selectBox,{ + actions:['notUnique'], + actionObjs:[{uniqueArray:getGroups()}], + actionErrors:[{selectErr:'*zadejte validní skupinu'}] + }); + groupHumanReadableName = group; + } else { + groupHumanReadableName = "Všechny Skupiny"; + } + if (Utils.isObjErrorFree(errorMsg)) { - errorMsg.success = backupToPdf(from,to); - Utils.log('Backuped to pdf in time span ' + from + ' - ' + to ); + errorMsg.success = backupToPdf(from,to, group, groupHumanReadableName); + Utils.log('Backuped to pdf for group ' + groupHumanReadableName + ' in time span ' + from + ' - ' + to); } return errorMsg; diff --git a/src/PdfBackuper/PdfBackuper.js b/src/PdfBackuper/PdfBackuper.js index a9ec583..3fd22f0 100644 --- a/src/PdfBackuper/PdfBackuper.js +++ b/src/PdfBackuper/PdfBackuper.js @@ -1,8 +1,13 @@ -function backupToPdf (from, to) { +function backupToPdf (from, to, group, groupHumanReadableName) { + groupSet = null; + if (group != '') { + groupSet = new Set([group]) + } + const time = new Date().toISOString(); const ROZPIS = 'Rozpis' - const folder = DriveApp.createFolder('Záloha_' + time); + const folder = DriveApp.createFolder('Záloha_' + time + '_' + groupHumanReadableName); const tmpSS = SpreadsheetApp.create('Tmp'); const tmpSSId = tmpSS.getId(); @@ -14,6 +19,9 @@ function backupToPdf (from, to) { Utils.findFiles([], { type: ROZPIS }).filter(function (file) { + if (groupSet != null && !groupSet.has(file.group)) { + return false; + } return Utils.isWeekWithinDates(from, to, file.year, file.week); }).forEach(function (file) { diff --git a/src/PdfBackuper/Utils.js b/src/PdfBackuper/Utils.js index 7dfe7fd..0c14046 100644 --- a/src/PdfBackuper/Utils.js +++ b/src/PdfBackuper/Utils.js @@ -8,6 +8,13 @@ function include(filename) { return HtmlService.createHtmlOutputFromFile(filename).getContent(); } +/** + * @return {Array} array with name of all groups + */ +function getGroups() { + return Utils.sort(Utils.convertObjectsToArrayByProperty(Utils.findGroups(['group']), 'group')); +} + /** * Creates presentable HTML for a browser * *cannot be run from library, becaouse of filename diff --git a/src/PdfBackuper/appsscript.json b/src/PdfBackuper/appsscript.json index 56d9438..6794902 100644 --- a/src/PdfBackuper/appsscript.json +++ b/src/PdfBackuper/appsscript.json @@ -5,7 +5,7 @@ { "userSymbol": "Utils", "libraryId": "1WquYtBor0ObwHMo1oIhKnCgboR5zBx2wjh5Hu-rbb0oSA5cY0d2PM6dZ", - "version": 87 + "version": 89 } ] }, diff --git a/src/PdfBackuper/main.html b/src/PdfBackuper/main.html index ce6ed9c..7d02543 100644 --- a/src/PdfBackuper/main.html +++ b/src/PdfBackuper/main.html @@ -19,6 +19,14 @@

+

+ +
+ + +

@@ -38,3 +46,4 @@ + diff --git a/src/PdfBackuper/pdfbackuper-js.html b/src/PdfBackuper/pdfbackuper-js.html new file mode 100644 index 0000000..c5c66cd --- /dev/null +++ b/src/PdfBackuper/pdfbackuper-js.html @@ -0,0 +1,9 @@ + + diff --git a/src/RenameGroup/appsscript.json b/src/RenameGroup/appsscript.json index 8e61bec..12d8846 100644 --- a/src/RenameGroup/appsscript.json +++ b/src/RenameGroup/appsscript.json @@ -5,7 +5,7 @@ { "userSymbol": "Utils", "libraryId": "1WquYtBor0ObwHMo1oIhKnCgboR5zBx2wjh5Hu-rbb0oSA5cY0d2PM6dZ", - "version": 87 + "version": 89 } ] }, diff --git a/src/SheetRedirect/appsscript.json b/src/SheetRedirect/appsscript.json index 56d9438..6794902 100644 --- a/src/SheetRedirect/appsscript.json +++ b/src/SheetRedirect/appsscript.json @@ -5,7 +5,7 @@ { "userSymbol": "Utils", "libraryId": "1WquYtBor0ObwHMo1oIhKnCgboR5zBx2wjh5Hu-rbb0oSA5cY0d2PM6dZ", - "version": 87 + "version": 89 } ] }, diff --git a/src/Statistics/Stat.js b/src/Statistics/Stat.js index 8bd0735..607ab26 100644 --- a/src/Statistics/Stat.js +++ b/src/Statistics/Stat.js @@ -6,7 +6,7 @@ */ function process(formObject) { var errorMsg = {fromErr:'',toErr:''}; - var from,to; + var from, to, group, groupHumanReadableName; from = Utils.validate(errorMsg,formObject.fromBox,{ actions:['validateDate',], @@ -30,9 +30,24 @@ function process(formObject) { errorMsg.fromErr = '*datum od je větší než datum do'; } + group = formObject.selectBox; + if (group == null) { + group = ''; + } + if (group != '') { + group = Utils.validate(errorMsg,formObject.selectBox,{ + actions:['notUnique'], + actionObjs:[{uniqueArray:getGroups()}], + actionErrors:[{selectErr:'*zadejte validní skupinu'}] + }); + groupHumanReadableName = group; + } else { + groupHumanReadableName = "Všechny Skupiny"; + } + if(Utils.isObjErrorFree(errorMsg)) { - errorMsg.success = createStatistics(from,to); - Utils.log('Generated stats in time span ' + from + ' - ' + to ); + errorMsg.success = createStatistics(from,to, group, groupHumanReadableName); + Utils.log('Generated stats for group ' + groupHumanReadableName + ' in time span ' + from + ' - ' + to ); } return errorMsg; diff --git a/src/Statistics/Utils.js b/src/Statistics/Utils.js index 7fb6c0d..1ea6ceb 100644 --- a/src/Statistics/Utils.js +++ b/src/Statistics/Utils.js @@ -56,6 +56,13 @@ function include(filename) { return HtmlService.createHtmlOutputFromFile(filename).getContent(); } +/** + * @return {Array} array with name of all groups + */ +function getGroups() { + return Utils.sort(Utils.convertObjectsToArrayByProperty(Utils.findGroups(['group']), 'group')); +} + /** * Creates presentable HTML for a browser * *cannot be run from library, becaouse of filename diff --git a/src/Statistics/WriteStats.js b/src/Statistics/WriteStats.js index 25c1c85..edb92e6 100644 --- a/src/Statistics/WriteStats.js +++ b/src/Statistics/WriteStats.js @@ -2,13 +2,21 @@ * Creates statistics spreadsheet in user's google drive and generates data into it * * @param from from which day stats are going to be created - * @param to to which day stats are going to be created + * @param to to which day stats are going to be created + * @param groups stats are going to be created only for this group if not empty + * @param groupHumanReadableName group name or an identifier for all groups * @return {string} url of new spreadsheet */ -function createStatistics(from, to) { - let spreadsheetData = Utils.extractAllSpreadsheetData(from, to); // can throw timeout +function createStatistics(from, to, group, groupHumanReadableName) { + groupSet = null; + if (group != '') { + groupSet = new Set([group]) + } + + let spreadsheetData = Utils.extractAllSpreadsheetData(from, to, groupSet); // can throw timeout const ss = Utils.createSpreadsheet({ - type: 'Statistika' + type: 'Statistika', + details: groupHumanReadableName }); const clientsSheet = ss.getActiveSheet(); const clientsSheet2 = ss.insertSheet('Klienti Počet návštěv'); @@ -25,9 +33,9 @@ function createStatistics(from, to) { return !eventsMap[item['event']]; }); - writeStats(spreadsheetData, clientsSheet, 'event', from, to, false); - writeStats(spreadsheetData, clientsSheet2, 'event', from, to, true); - writeStats(spreadsheetData, assistantsSheet, 'employee', from, to, false); + writeStats(spreadsheetData, clientsSheet, 'event', from, to, false, groupHumanReadableName); + writeStats(spreadsheetData, clientsSheet2, 'event', from, to, true, groupHumanReadableName); + writeStats(spreadsheetData, assistantsSheet, 'employee', from, to, false, groupHumanReadableName); return ss.getUrl(); } @@ -40,8 +48,9 @@ function createStatistics(from, to) { * @param from from which data to write stats * @param to to which data to write stats * @param onlyCount measure occurences count instead of duration + * @param groupHumanReadableName group name or an identifier for all groups */ -function writeStats(spreadsheetData, sheet, type, from, to, onlyCount) { +function writeStats(spreadsheetData, sheet, type, from, to, onlyCount, groupHumanReadableName) { const months = Utils.getMonthsNames(); // stats = { // "John": { @@ -133,7 +142,7 @@ function writeStats(spreadsheetData, sheet, type, from, to, onlyCount) { color: '#E2F3FF' }); } - writeToCell(sheet, sortedFoundNames.length + 8, 1, '* Statistika v časovém období: ' + Utils.getFormatedDate(from, true) + ' - ' + Utils.getFormatedDate( + writeToCell(sheet, sortedFoundNames.length + 8, 1, '* Statistika pro ' + groupHumanReadableName + ' v časovém období: ' + Utils.getFormatedDate(from, true) + ' - ' + Utils.getFormatedDate( to, true)); } diff --git a/src/Statistics/appsscript.json b/src/Statistics/appsscript.json index 56d9438..6794902 100644 --- a/src/Statistics/appsscript.json +++ b/src/Statistics/appsscript.json @@ -5,7 +5,7 @@ { "userSymbol": "Utils", "libraryId": "1WquYtBor0ObwHMo1oIhKnCgboR5zBx2wjh5Hu-rbb0oSA5cY0d2PM6dZ", - "version": 87 + "version": 89 } ] }, diff --git a/src/Statistics/main.html b/src/Statistics/main.html index cd65eb4..cdb2f03 100644 --- a/src/Statistics/main.html +++ b/src/Statistics/main.html @@ -19,6 +19,14 @@

+

+ +
+ + +

@@ -38,3 +46,4 @@ + diff --git a/src/Statistics/statistics-js.html b/src/Statistics/statistics-js.html new file mode 100644 index 0000000..c5c66cd --- /dev/null +++ b/src/Statistics/statistics-js.html @@ -0,0 +1,9 @@ + + diff --git a/src/TableScript/appsscript.json b/src/TableScript/appsscript.json index 56d9438..6794902 100644 --- a/src/TableScript/appsscript.json +++ b/src/TableScript/appsscript.json @@ -5,7 +5,7 @@ { "userSymbol": "Utils", "libraryId": "1WquYtBor0ObwHMo1oIhKnCgboR5zBx2wjh5Hu-rbb0oSA5cY0d2PM6dZ", - "version": 87 + "version": 89 } ] }, diff --git a/src/Update/appsscript.json b/src/Update/appsscript.json index 56d9438..6794902 100644 --- a/src/Update/appsscript.json +++ b/src/Update/appsscript.json @@ -5,7 +5,7 @@ { "userSymbol": "Utils", "libraryId": "1WquYtBor0ObwHMo1oIhKnCgboR5zBx2wjh5Hu-rbb0oSA5cY0d2PM6dZ", - "version": 87 + "version": 89 } ] }, diff --git a/src/Utils/SpreadSheet.js b/src/Utils/SpreadSheet.js index 1825f88..388d945 100644 --- a/src/Utils/SpreadSheet.js +++ b/src/Utils/SpreadSheet.js @@ -14,7 +14,7 @@ function createSpreadsheet(obj) { break; case 'Statistika': case 'Fakturace': - filename = obj.type + '_' + getFormatedDate(new Date()); + filename = obj.type + '_' + getFormatedDate(new Date()) + '_' + obj.details; break; default: return; @@ -41,15 +41,19 @@ function createSpreadsheet(obj) { * * @param from from which date to start extracting * @param to to which date extract data + * @param groups to which groups to extract data from * @return {Array} array of extracted data */ -function extractAllSpreadsheetData(from, to) { +function extractAllSpreadsheetData(from, to, groups) { const result = []; const stopTimer = measureTime(); findFiles([], { type: 'Rozpis' }).filter(function(file) { + if (groups != null && !groups.has(file.group)) { + return false; + } return isWeekWithinDates(from, to, file.year, file.week); }).forEach(function(item) { const ss = openSpreadsheet(item.id);