[freeside-commits] branch FREESIDE_3_BRANCH updated. 96ea0f9a414ab077c28ea20e1d6f14d281c114bc

Jonathan Prykop jonathan at 420.am
Mon Sep 12 16:58:59 PDT 2016


The branch, FREESIDE_3_BRANCH has been updated
       via  96ea0f9a414ab077c28ea20e1d6f14d281c114bc (commit)
       via  73df7e1288401feb3c2a15a47b20e98e04c30c91 (commit)
      from  fb58099843c95a31260b426a15d47647effd0337 (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 96ea0f9a414ab077c28ea20e1d6f14d281c114bc
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 v3]

diff --git a/debian/control b/debian/control
index e1cd4b8..4c9d771 100644
--- a/debian/control
+++ b/debian/control
@@ -88,7 +88,8 @@ Depends: aspell-en,gnupg,ghostscript,gsfonts,gzip,latex-xcolor,
  libparams-classify-perl (>= 0.013-5.1), 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
 Suggests: libbusiness-onlinepayment-perl
 Description: Libraries for Freeside billing and trouble ticketing
  Freeside is a web-based billing and trouble ticketing application.

commit 73df7e1288401feb3c2a15a47b20e98e04c30c91
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