[freeside-commits] branch FREESIDE_4_BRANCH updated. 70a34c5128f11c32ce199b6b87d205c98cd41357

Jonathan Prykop jonathan at 420.am
Mon Sep 12 16:44:21 PDT 2016


The branch, FREESIDE_4_BRANCH has been updated
       via  70a34c5128f11c32ce199b6b87d205c98cd41357 (commit)
       via  5cd19c26283661da5d242f031d1c81a4129782fd (commit)
      from  a0e9787492ab306e94f41492ac7f59fb6a3e4802 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 70a34c5128f11c32ce199b6b87d205c98cd41357
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Mon Sep 12 18:20:17 2016 -0500

    71720: Prevent billing events from running on holidays [debian]

diff --git a/debian/control b/debian/control
index 4de8fee..538a12d 100644
--- a/debian/control
+++ b/debian/control
@@ -97,7 +97,8 @@ Depends: aspell-en,gnupg,ghostscript,gsfonts,gzip,latex-xcolor,
  libcpanel-json-xs-perl, libarchive-zip-perl,
  libtry-tiny-perl, libnumber-phone-perl, libxml-libxml-simple-perl,
  libxml-writer-perl, libio-socket-ssl-perl,
- libmap-splat-perl
+ libmap-splat-perl,
+ libdatetime-format-ical-perl
 Conflicts: libparams-classify-perl (>= 0.013-6)
 Suggests: libbusiness-onlinepayment-perl
 Description: Libraries for Freeside billing and trouble ticketing

commit 5cd19c26283661da5d242f031d1c81a4129782fd
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Mon Sep 12 17:42:16 2016 -0500

    71720: Prevent billing events from running on holidays

diff --git a/FS/FS/part_event/Condition/holiday.pm b/FS/FS/part_event/Condition/holiday.pm
new file mode 100644
index 0000000..1639a17
--- /dev/null
+++ b/FS/FS/part_event/Condition/holiday.pm
@@ -0,0 +1,90 @@
+package FS::part_event::Condition::holiday;
+
+use strict;
+use base qw( FS::part_event::Condition );
+use DateTime;
+use DateTime::Format::ICal;
+use Tie::IxHash;
+
+# rules lifted from DateTime::Event::Holiday::US,
+# but their list is unordered, and contains duplicates and frivolous holidays
+# it's better for future development for us to use our own hard-coded list,
+# and the actual code beyond the list is just trivial use of DateTime::Format::ICal
+
+tie my %holidays, 'Tie::IxHash', 
+  'New Year\'s Day'
+    => { 'rule' => 'RRULE:FREQ=YEARLY;BYMONTH=1;BYMONTHDAY=1' },   # January 1
+  'Birthday of Martin Luther King, Jr.'
+    => { 'rule' => 'RRULE:FREQ=YEARLY;BYMONTH=1;BYDAY=3mo' },      # Third Monday in January
+  'Washington\'s Birthday' 
+    => { 'rule' => 'RRULE:FREQ=YEARLY;BYMONTH=2;BYDAY=3mo' },      # Third Monday in February
+  'Memorial Day'
+    => { 'rule' => 'RRULE:FREQ=YEARLY;BYMONTH=5;BYDAY=-1mo' },     # Last Monday in May
+  'Independence Day'
+    => { 'rule' => 'RRULE:FREQ=YEARLY;BYMONTH=7;BYMONTHDAY=4' },   # July 4
+  'Labor Day'
+    => { 'rule' => 'RRULE:FREQ=YEARLY;BYMONTH=9;BYDAY=1mo' },      # First Monday in September
+  'Columbus Day'
+    => { 'rule' => 'RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=2mo' },     # Second Monday in October
+  'Veterans Day'
+    => { 'rule' => 'RRULE:FREQ=YEARLY;BYMONTH=11;BYMONTHDAY=11' }, # November 11
+  'Thanksgiving Day'
+    => { 'rule' => 'RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=4th' },     # Fourth Thursday in November
+  'Christmas'
+    => { 'rule' => 'RRULE:FREQ=YEARLY;BYMONTH=12;BYMONTHDAY=25' }, # December 25
+;
+
+my $oneday = DateTime::Duration->new(days => 1);
+
+sub description {
+  "Do not run on holidays",
+}
+
+sub option_fields {
+  (
+    'holidays' => {
+       label         => 'Do not run on',
+       type          => 'checkbox-multiple',
+       options       => [ keys %holidays ],
+       option_labels => { map { $_ => $_ } keys %holidays },
+       default_value => { map { $_ => 1  } keys %holidays }
+    },
+  );
+}
+
+sub condition {
+  my( $self, $object, %opt ) = @_;
+  my $today = DateTime->from_epoch(
+    epoch     => $opt{'time'} || time,
+    time_zone => 'local'
+  )->truncate( to => 'day' );
+
+  # if fri/mon, also check sat/sun respectively
+  # federal holidays on weekends "move" to nearest weekday
+  # eg Christmas 2016 is Mon Dec 26
+  # we'll check both, so eg both Dec 25 & 26 are holidays in 2016
+  my $offday;
+  if ($today->day_of_week == 1) {
+    $offday = $today->clone->subtract_duration($oneday);
+  } elsif ($today->day_of_week == 5) {
+    $offday = $today->clone->add_duration($oneday);
+  }
+
+  foreach my $holiday (keys %{$self->option('holidays')}) {
+    $holidays{$holiday}{'set'} ||= 
+      DateTime::Format::ICal->parse_recurrence(
+        'recurrence' => $holidays{$holiday}{'rule'}
+      );
+    my $set = $holidays{$holiday}{'set'};
+    return ''
+      if $set->contains($today) or $offday && $set->contains($offday);
+  }
+
+  return 1;
+
+}
+
+
+# no condition_sql
+
+1;
diff --git a/httemplate/elements/tr-checkbox-multiple.html b/httemplate/elements/tr-checkbox-multiple.html
index bb90a82..4d754b0 100644
--- a/httemplate/elements/tr-checkbox-multiple.html
+++ b/httemplate/elements/tr-checkbox-multiple.html
@@ -33,6 +33,8 @@ my $onchange = $opt{'onchange'}
 
 my $value = $opt{'curr_value'} || $opt{'value'};
 
+$value = $opt{default_value} if $opt{default_value} && !defined($value);
+
 my $labels = $opt{'option_labels'} || $opt{'labels'};
 
 my $style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : '';

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/part_event/Condition/holiday.pm         |   90 +++++++++++++++++++++++++
 debian/control                                |    3 +-
 httemplate/elements/tr-checkbox-multiple.html |    2 +
 3 files changed, 94 insertions(+), 1 deletion(-)
 create mode 100644 FS/FS/part_event/Condition/holiday.pm




More information about the freeside-commits mailing list