Skip to content

Commit

Permalink
more formatted reports
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed Jun 11, 2021
1 parent efa4b1b commit bce8437
Show file tree
Hide file tree
Showing 21 changed files with 466 additions and 138 deletions.
25 changes: 20 additions & 5 deletions helpers/reportDefinitions/amendmentReports.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,29 @@ export const reports = {
"amendments-all": {
sql: "select * from LotteryLicenceAmendments"
},
"amendments-formatted": {
sql: "select a.licenceID, l.externalLicenceNumber," +
" o.organizationName," +
" amendmentDate, amendmentTime," +
" amendmentType, amendment," +
" isHidden" +
" from LotteryLicenceAmendments a" +
" left join LotteryLicences l on a.licenceID = l.licenceID" +
" left join Organizations o on l.organizationID = o.organizationID" +
" where a.recordDelete_timeMillis is null" +
" and l.recordDelete_timeMillis is null"
},
"amendments-byLicence": {
sql: "select licenceID, amendmentIndex, amendmentDate, amendmentTime," +
sql: "select licenceID, l.externalLicenceNumber," +
" o.organizationName," +
" amendmentDate, amendmentTime," +
" amendmentType, amendment," +
" isHidden," +
" recordCreate_userName, recordCreate_timeMillis, recordUpdate_userName, recordUpdate_timeMillis" +
" from LotteryLicenceAmendments" +
" where recordDelete_timeMillis is null" +
" and licenceID = ?",
" from LotteryLicenceAmendments a" +
" left join LotteryLicences l on a.licenceID = l.licenceID" +
" left join Organizations o on l.organizationID = o.organizationID" +
" where a.recordDelete_timeMillis is null" +
" and a.licenceID = ?",
params: (req) => [req.query.licenceID]
}
};
Expand Down
27 changes: 22 additions & 5 deletions helpers/reportDefinitions/amendmentReports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,32 @@ export const reports: { [reportName: string]: ConfigReportDefinition } = {
sql: "select * from LotteryLicenceAmendments"
},

"amendments-formatted": {

sql: "select a.licenceID, l.externalLicenceNumber," +
" o.organizationName," +
" amendmentDate, amendmentTime," +
" amendmentType, amendment," +
" isHidden" +
" from LotteryLicenceAmendments a" +
" left join LotteryLicences l on a.licenceID = l.licenceID" +
" left join Organizations o on l.organizationID = o.organizationID" +
" where a.recordDelete_timeMillis is null" +
" and l.recordDelete_timeMillis is null"
},

"amendments-byLicence": {

sql: "select licenceID, amendmentIndex, amendmentDate, amendmentTime," +
sql: "select licenceID, l.externalLicenceNumber," +
" o.organizationName," +
" amendmentDate, amendmentTime," +
" amendmentType, amendment," +
" isHidden," +
" recordCreate_userName, recordCreate_timeMillis, recordUpdate_userName, recordUpdate_timeMillis" +
" from LotteryLicenceAmendments" +
" where recordDelete_timeMillis is null" +
" and licenceID = ?",
" from LotteryLicenceAmendments a" +
" left join LotteryLicences l on a.licenceID = l.licenceID" +
" left join Organizations o on l.organizationID = o.organizationID" +
" where a.recordDelete_timeMillis is null" +
" and a.licenceID = ?",

params: (req) => [req.query.licenceID]
}
Expand Down
23 changes: 22 additions & 1 deletion helpers/reportDefinitions/bankRecordReports.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import * as configFns from "../configFns.js";
const sql_bankRecordsFlat = (() => {
const bankRecordTypes = configFns.getProperty("bankRecordTypes");
const sql = "select o.organizationName," +
" b.accountNumber, b.bankingYear, b.bankingMonth" +
bankRecordTypes.reduce((soFar, bankRecordType) => {
const bankRecordTypeKey = bankRecordType.bankRecordType;
return soFar +
", max(case when bankRecordType = '" + bankRecordTypeKey + "' then recordDate end) as " + bankRecordTypeKey + "_recordDate" +
", max(case when bankRecordType = '" + bankRecordTypeKey + "' then recordIsNA end) as " + bankRecordTypeKey + "_recordIsNA" +
", max(case when bankRecordType = '" + bankRecordTypeKey + "' then recordNote end) as " + bankRecordTypeKey + "_recordNote";
}, "") +
" from OrganizationBankRecords b" +
" left join Organizations o on b.organizationID = o.organizationID" +
" where b.recordDelete_timeMillis is null" +
" and o.recordDelete_timeMillis is null" +
" group by b.organizationID, o.organizationName, b.accountNumber, b.bankingYear, b.bankingMonth";
return sql;
})();
const sql_bankRecordsFlatByOrganization = (() => {
const bankRecordTypes = configFns.getProperty("bankRecordTypes");
const sql = "select b.organizationID, o.organizationName," +
const sql = "select o.organizationName," +
" b.accountNumber, b.bankingYear, b.bankingMonth" +
bankRecordTypes.reduce((soFar, bankRecordType) => {
const bankRecordTypeKey = bankRecordType.bankRecordType;
Expand All @@ -21,6 +39,9 @@ export const reports = {
"bankRecords-all": {
sql: "select * from OrganizationBankRecords"
},
"bankRecordsFlat-formatted": {
sql: sql_bankRecordsFlat
},
"bankRecordsFlat-byOrganization": {
sql: sql_bankRecordsFlatByOrganization,
params: (req) => [req.query.organizationID]
Expand Down
34 changes: 31 additions & 3 deletions helpers/reportDefinitions/bankRecordReports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,37 @@ import * as configFns from "../configFns.js";
import type { ConfigReportDefinition } from "../../types/configTypes";


const sql_bankRecordsFlat = (() => {

const bankRecordTypes = configFns.getProperty("bankRecordTypes");

const sql = "select o.organizationName," +
" b.accountNumber, b.bankingYear, b.bankingMonth" +
bankRecordTypes.reduce((soFar, bankRecordType) => {

const bankRecordTypeKey = bankRecordType.bankRecordType;

return soFar +
", max(case when bankRecordType = '" + bankRecordTypeKey + "' then recordDate end) as " + bankRecordTypeKey + "_recordDate" +
", max(case when bankRecordType = '" + bankRecordTypeKey + "' then recordIsNA end) as " + bankRecordTypeKey + "_recordIsNA" +
", max(case when bankRecordType = '" + bankRecordTypeKey + "' then recordNote end) as " + bankRecordTypeKey + "_recordNote";

}, "") +
" from OrganizationBankRecords b" +
" left join Organizations o on b.organizationID = o.organizationID" +
" where b.recordDelete_timeMillis is null" +
" and o.recordDelete_timeMillis is null" +
" group by b.organizationID, o.organizationName, b.accountNumber, b.bankingYear, b.bankingMonth";

return sql;
})();


const sql_bankRecordsFlatByOrganization = (() => {

const bankRecordTypes = configFns.getProperty("bankRecordTypes");

const sql = "select b.organizationID, o.organizationName," +
const sql = "select o.organizationName," +
" b.accountNumber, b.bankingYear, b.bankingMonth" +
bankRecordTypes.reduce((soFar, bankRecordType) => {

Expand Down Expand Up @@ -35,10 +61,12 @@ export const reports: { [reportName: string]: ConfigReportDefinition } = {
sql: "select * from OrganizationBankRecords"
},

"bankRecordsFlat-byOrganization": {
"bankRecordsFlat-formatted": {
sql: sql_bankRecordsFlat
},

"bankRecordsFlat-byOrganization": {
sql: sql_bankRecordsFlatByOrganization,

params: (req) => [req.query.organizationID]
}
};
Expand Down
27 changes: 12 additions & 15 deletions helpers/reportDefinitions/eventReports.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import * as dateTimeFns from "@cityssm/expressjs-server-js/dateTimeFns.js";
import * as reportFns from "../reportFns.js";
const baseFunctions = () => {
const func = new Map();
func.set("userFn_licenceTypeKeyToLicenceType", reportFns.userFn_licenceTypeKeyToLicenceType);
return func;
};
export const reports = {
"events-all": {
sql: "select * from LotteryEvents"
},
"events-upcoming": {
functions: () => {
const func = new Map();
func.set("userFn_licenceTypeKeyToLicenceType", reportFns.userFn_licenceTypeKeyToLicenceType);
return func;
},
sql: "select e.licenceID," +
functions: baseFunctions,
sql: "select e.licenceID, l.externalLicenceNumber," +
" o.organizationName," +
" e.eventDate, l.startTime, l.endTime," +
" l.externalLicenceNumber, o.organizationName," +
" userFn_licenceTypeKeyToLicenceType(l.licenceTypeKey) as licenceType," +
" l.licenceDetails" +
" from LotteryEvents e" +
Expand All @@ -24,17 +25,13 @@ export const reports = {
params: () => [dateTimeFns.dateToInteger(new Date())]
},
"events-pastUnreported": {
functions: () => {
const func = new Map();
func.set("userFn_licenceTypeKeyToLicenceType", reportFns.userFn_licenceTypeKeyToLicenceType);
return func;
},
sql: "select e.licenceID, e.eventDate, e.reportDate," +
functions: baseFunctions,
sql: "select e.licenceID, l.externalLicenceNumber," +
" e.eventDate, e.reportDate," +
" e.bank_name, e.bank_address, e.bank_accountNumber, e.bank_accountBalance," +
" l.externalLicenceNumber," +
" userFn_licenceTypeKeyToLicenceType(l.licenceTypeKey) as licenceType," +
" l.licenceDetails," +
" o.organizationID, o.organizationName," +
" o.organizationName," +
" o.organizationAddress1, o.organizationAddress2," +
" o.organizationCity, o.organizationProvince, o.organizationPostalCode," +
" r.representativeName, r.representativeTitle, r.representativeAddress1, r.representativeAddress2," +
Expand Down
29 changes: 14 additions & 15 deletions helpers/reportDefinitions/eventReports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ import * as reportFns from "../reportFns.js";
import type { ConfigReportDefinition } from "../../types/configTypes";


const baseFunctions = () => {
const func = new Map();
func.set("userFn_licenceTypeKeyToLicenceType", reportFns.userFn_licenceTypeKeyToLicenceType);
return func;
};


export const reports: { [reportName: string]: ConfigReportDefinition } = {

"events-all": {
sql: "select * from LotteryEvents"
},

"events-upcoming": {
functions: () => {
const func = new Map();
func.set("userFn_licenceTypeKeyToLicenceType", reportFns.userFn_licenceTypeKeyToLicenceType);
return func;
},
sql: "select e.licenceID," +
functions: baseFunctions,
sql: "select e.licenceID, l.externalLicenceNumber," +
" o.organizationName," +
" e.eventDate, l.startTime, l.endTime," +
" l.externalLicenceNumber, o.organizationName," +
" userFn_licenceTypeKeyToLicenceType(l.licenceTypeKey) as licenceType," +
" l.licenceDetails" +
" from LotteryEvents e" +
Expand All @@ -32,17 +35,13 @@ export const reports: { [reportName: string]: ConfigReportDefinition } = {
},

"events-pastUnreported": {
functions: () => {
const func = new Map();
func.set("userFn_licenceTypeKeyToLicenceType", reportFns.userFn_licenceTypeKeyToLicenceType);
return func;
},
sql: "select e.licenceID, e.eventDate, e.reportDate," +
functions: baseFunctions,
sql: "select e.licenceID, l.externalLicenceNumber," +
" e.eventDate, e.reportDate," +
" e.bank_name, e.bank_address, e.bank_accountNumber, e.bank_accountBalance," +
" l.externalLicenceNumber," +
" userFn_licenceTypeKeyToLicenceType(l.licenceTypeKey) as licenceType," +
" l.licenceDetails," +
" o.organizationID, o.organizationName," +
" o.organizationName," +
" o.organizationAddress1, o.organizationAddress2," +
" o.organizationCity, o.organizationProvince, o.organizationPostalCode," +
" r.representativeName, r.representativeTitle, r.representativeAddress1, r.representativeAddress2," +
Expand Down
5 changes: 2 additions & 3 deletions helpers/reportDefinitions/licenceReports.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ const baseFunctions = () => {
};
const baseSQL = "select" +
" l.licenceID, l.externalLicenceNumber," +
" o.organizationID, o.organizationName," +
" o.organizationName," +
" l.applicationDate," +
" userFn_licenceTypeKeyToLicenceType(l.licenceTypeKey) as licenceType," +
" l.startDate, l.endDate, l.startTime, l.endTime," +
" lo.locationName, lo.locationAddress1," +
" l.municipality, l.licenceDetails, l.termsConditions," +
" l.totalPrizeValue, l.licenceFee, l.issueDate," +
" l.recordCreate_userName, l.recordCreate_timeMillis, l.recordUpdate_userName, l.recordUpdate_timeMillis" +
" l.totalPrizeValue, l.licenceFee, l.issueDate" +
" from LotteryLicences l" +
" left join Locations lo on l.locationID = lo.locationID" +
" left join Organizations o on l.organizationID = o.organizationID" +
Expand Down
5 changes: 2 additions & 3 deletions helpers/reportDefinitions/licenceReports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ const baseFunctions = () => {

const baseSQL = "select" +
" l.licenceID, l.externalLicenceNumber," +
" o.organizationID, o.organizationName," +
" o.organizationName," +
" l.applicationDate," +
" userFn_licenceTypeKeyToLicenceType(l.licenceTypeKey) as licenceType," +
" l.startDate, l.endDate, l.startTime, l.endTime," +
" lo.locationName, lo.locationAddress1," +
" l.municipality, l.licenceDetails, l.termsConditions," +
" l.totalPrizeValue, l.licenceFee, l.issueDate," +
" l.recordCreate_userName, l.recordCreate_timeMillis, l.recordUpdate_userName, l.recordUpdate_timeMillis" +
" l.totalPrizeValue, l.licenceFee, l.issueDate" +
" from LotteryLicences l" +
" left join Locations lo on l.locationID = lo.locationID" +
" left join Organizations o on l.organizationID = o.organizationID" +
Expand Down
21 changes: 15 additions & 6 deletions helpers/reportDefinitions/remarkReports.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@ export const reports = {
"remarks-all": {
sql: "select * from OrganizationRemarks"
},
"remarks-formatted": {
sql: "select o.organizationName," +
" remarkDate, remarkTime," +
" remark, isImportant" +
" from OrganizationRemarks r" +
" left join Organizations o on r.organizationID = o.organizationID" +
" where r.recordDelete_timeMillis is null" +
" and o.recordDelete_timeMillis is null"
},
"remarks-byOrganization": {
sql: "select organizationID, remarkIndex," +
sql: "select o.organizationName," +
" remarkDate, remarkTime," +
" remark, isImportant," +
" recordCreate_userName, recordCreate_timeMillis, recordUpdate_userName, recordUpdate_timeMillis" +
" from OrganizationRemarks" +
" where recordDelete_timeMillis is null" +
" and organizationID = ?",
" remark, isImportant" +
" from OrganizationRemarks r" +
" left join Organizations o on r.organizationID = o.organizationID" +
" where r.recordDelete_timeMillis is null" +
" and r.organizationID = ?",
params: (req) => [req.query.organizationID]
}
};
Expand Down
23 changes: 17 additions & 6 deletions helpers/reportDefinitions/remarkReports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,26 @@ export const reports: { [reportName: string]: ConfigReportDefinition } = {
sql: "select * from OrganizationRemarks"
},

"remarks-formatted": {

sql: "select o.organizationName," +
" remarkDate, remarkTime," +
" remark, isImportant" +
" from OrganizationRemarks r" +
" left join Organizations o on r.organizationID = o.organizationID" +
" where r.recordDelete_timeMillis is null" +
" and o.recordDelete_timeMillis is null"
},

"remarks-byOrganization": {

sql: "select organizationID, remarkIndex," +
sql: "select o.organizationName," +
" remarkDate, remarkTime," +
" remark, isImportant," +
" recordCreate_userName, recordCreate_timeMillis, recordUpdate_userName, recordUpdate_timeMillis" +
" from OrganizationRemarks" +
" where recordDelete_timeMillis is null" +
" and organizationID = ?",
" remark, isImportant" +
" from OrganizationRemarks r" +
" left join Organizations o on r.organizationID = o.organizationID" +
" where r.recordDelete_timeMillis is null" +
" and r.organizationID = ?",

params: (req) => [req.query.organizationID]
}
Expand Down
Loading

0 comments on commit bce8437

Please sign in to comment.