@@ -129,6 +129,41 @@ module default {
129
129
projectContext := __new__.projectContext,
130
130
}
131
131
);
132
+
133
+ trigger createPeriodicReportsOnInsert after insert for each do (
134
+ with
135
+ interval := (select
136
+ if __new__.financialReportPeriod = default::ReportPeriod.Monthly then '1' else '3'),
137
+ reportRanges := Project::create_periodic_report_ranges(
138
+ __new__.mouStart,
139
+ __new__.mouEnd,
140
+ interval
141
+ )
142
+ for reportRange in reportRanges
143
+ union (
144
+ (insert default::FinancialReport {
145
+ createdAt := datetime_of_statement(),
146
+ modifiedAt := datetime_of_statement(),
147
+ createdBy := assert_exists(global currentActor),
148
+ modifiedBy := assert_exists(global currentActor),
149
+ project := __new__,
150
+ projectContext := __new__.projectContext,
151
+ container := __new__,
152
+ period := reportRange
153
+ #receivedDate := __new__.financialReportReceivedAt, //TODO - what is this at the project level?
154
+ }),
155
+ (insert default::NarrativeReport {
156
+ createdAt := datetime_of_statement(),
157
+ modifiedAt := datetime_of_statement(),
158
+ createdBy := assert_exists(global currentActor),
159
+ modifiedBy := assert_exists(global currentActor),
160
+ project := __new__,
161
+ projectContext := __new__.projectContext,
162
+ container := __new__,
163
+ period := reportRange
164
+ })
165
+ )
166
+ )
132
167
}
133
168
134
169
abstract type TranslationProject extending Project {
@@ -216,4 +251,22 @@ module Project {
216
251
on target delete allow;
217
252
};
218
253
}
254
+
255
+ # creates the ranges for the given start and end dates based upon the given month interval
256
+ function create_periodic_report_ranges(startDate: cal::local_date, endDate: cal::local_date,
257
+ monthInterval: str) -> set of range<cal::local_date>
258
+ using (
259
+ with
260
+ reportingPeriod := range(<cal::local_date>startDate, <cal::local_date>endDate),
261
+ reportPeriodStartDates := range_unpack(reportingPeriod, <cal::date_duration>(monthInterval ++ ' month')),
262
+ reportPeriodRanges := (
263
+ for firstDayOfMonth in reportPeriodStartDates
264
+ union (
265
+ with
266
+ firstDayOfNextMonth := (select firstDayOfMonth + <cal::relative_duration>(monthInterval ++ ' month')),
267
+ lastDayOfMonth := firstDayOfNextMonth - <cal::relative_duration>'1 day'
268
+ select range(<cal::local_date>firstDayOfMonth, <cal::local_date>lastDayOfMonth)
269
+ ))
270
+ select reportPeriodRanges
271
+ )
219
272
}
0 commit comments