diff --git a/perllib/FixMyStreet/Cobrand/Brent.pm b/perllib/FixMyStreet/Cobrand/Brent.pm index 0f3941008a9..e76be2c329b 100644 --- a/perllib/FixMyStreet/Cobrand/Brent.pm +++ b/perllib/FixMyStreet/Cobrand/Brent.pm @@ -887,55 +887,10 @@ sub waste_subscription_types { }; } -sub _closed_event { - my $event = shift; - return 1 if $event->{ResolvedDate}; - return 0; -} - -sub _parse_events { - my $self = shift; - my $events_data = shift; - my $events; - foreach (@$events_data) { - my $event_type = $_->{EventTypeId}; - my $type = 'enquiry'; - $type = 'request' if $event_type == 1062; - $type = 'missed' if $event_type == 918; - - # Only care about open requests/enquiries - my $closed = _closed_event($_); - next if $type ne 'missed' && $closed; - - if ($type eq 'request') { - my $data = Integrations::Echo::force_arrayref($_->{Data}, 'ExtensibleDatum'); - my $container; - DATA: foreach (@$data) { - my $moredata = Integrations::Echo::force_arrayref($_->{ChildData}, 'ExtensibleDatum'); - foreach (@$moredata) { - if ($_->{DatatypeName} eq 'Container Type') { - $container = $_->{Value}; - last DATA; - } - } - } - my $report = $self->problems->search({ external_id => $_->{Guid} })->first; - $events->{request}->{$container} = $report ? { report => $report } : 1; - } elsif ($type eq 'missed') { - my $report = $self->problems->search({ external_id => $_->{Guid} })->first; - my $service_id = $_->{ServiceId}; - my $data = { - closed => $closed, - date => construct_bin_date($_->{EventDate}), - }; - $data->{report} = $report if $report; - push @{$events->{missed}->{$service_id}}, $data; - } else { # General enquiry of some sort - $events->{enquiry}->{$event_type} = 1; - } - } - return $events; -} +sub missed_event_types { { + 1062 => 'request', + 918 => 'missed', +} } sub image_for_unit { my ($self, $unit) = @_; @@ -956,8 +911,6 @@ sub image_for_unit { return $images->{$service_id}; } -sub bin_day_format { '%A, %-d~~~ %B' } - sub service_name_override { my ($self, $service) = @_; diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm index 94d0f0301b0..baea3b90138 100644 --- a/perllib/FixMyStreet/Cobrand/Bromley.pm +++ b/perllib/FixMyStreet/Cobrand/Bromley.pm @@ -700,57 +700,25 @@ sub assisted_collection { } sub _closed_event { - my $event = shift; + my ($self, $event) = @_; return 1 if $event->{ResolvedDate}; return 1 if $event->{ResolutionCodeId} && $event->{ResolutionCodeId} != 584; # Out of Stock return 0; } -sub _parse_events { - my $self = shift; - my $events_data = shift; - my $events; - foreach (@$events_data) { - my $event_type = $_->{EventTypeId}; - my $type = 'enquiry'; - $type = 'request' if $event_type == 2104; - $type = 'missed' if 2095 <= $event_type && $event_type <= 2103; - - # Only care about open requests/enquiries - my $closed = _closed_event($_); - next if $type ne 'missed' && $closed; - - if ($type eq 'request') { - my $data = Integrations::Echo::force_arrayref($_->{Data}, 'ExtensibleDatum'); - my $container; - DATA: foreach (@$data) { - my $moredata = Integrations::Echo::force_arrayref($_->{ChildData}, 'ExtensibleDatum'); - foreach (@$moredata) { - if ($_->{DatatypeName} eq 'Container Type') { - $container = $_->{Value}; - last DATA; - } - } - } - my $report = $self->problems->search({ external_id => $_->{Guid} })->first; - $events->{request}->{$container} = $report ? { report => $report } : 1; - } elsif ($type eq 'missed') { - my $report = $self->problems->search({ external_id => $_->{Guid} })->first; - my $service_id = $_->{ServiceId}; - my $data = { - closed => $closed, - date => construct_bin_date($_->{EventDate}), - }; - $data->{report} = $report if $report; - push @{$events->{missed}->{$service_id}}, $data; - } else { # General enquiry of some sort - $events->{enquiry}->{$event_type} = 1; - } - } - return $events; -} +sub missed_event_types { { + 2095 => 'missed', + 2096 => 'missed', + 2097 => 'missed', + 2098 => 'missed', + 2099 => 'missed', + 2100 => 'missed', + 2101 => 'missed', + 2102 => 'missed', + 2103 => 'missed', + 2104 => 'request', -sub bin_day_format { '%A, %-d~~~ %B' } +} } =over diff --git a/perllib/FixMyStreet/Roles/CobrandEcho.pm b/perllib/FixMyStreet/Roles/CobrandEcho.pm index 4d35579156e..dd6b0a34982 100644 --- a/perllib/FixMyStreet/Roles/CobrandEcho.pm +++ b/perllib/FixMyStreet/Roles/CobrandEcho.pm @@ -17,6 +17,8 @@ FixMyStreet::Roles::CobrandEcho - shared code between cobrands using an Echo bac =cut +sub bin_day_format { '%A, %-d~~~ %B' } + sub bin_addresses_for_postcode { my $self = shift; my $pc = shift; @@ -104,6 +106,60 @@ sub _get_current_service_task { return $current; } +sub missed_event_types {} + +sub _closed_event { + my ($self, $event) = @_; + return 1 if $event->{ResolvedDate}; + return 0; +} + +sub _parse_events { + my $self = shift; + my $events_data = shift; + my $events = {}; + my $missed_event_types = $self->missed_event_types; + foreach (@$events_data) { + my $event_type = $_->{EventTypeId}; + my $type = $missed_event_types->{$event_type} || 'enquiry'; + + # Only care about open requests/enquiries + my $closed = $self->_closed_event($_); + next if $type ne 'missed' && $closed; + + if ($type eq 'request') { + my $report = $self->problems->search({ external_id => $_->{Guid} })->first; + my $data = Integrations::Echo::force_arrayref($_->{Data}, 'ExtensibleDatum'); + foreach (@$data) { + my $moredata = Integrations::Echo::force_arrayref($_->{ChildData}, 'ExtensibleDatum'); + foreach (@$moredata) { + if ($_->{DatatypeName} eq 'Container Type') { + my $container = $_->{Value}; + $events->{request}->{$container} = $report ? { report => $report } : 1; + } + } + } + } elsif ($type eq 'missed') { + $self->parse_event_missed($_, $closed, $events); + } else { # General enquiry of some sort + $events->{enquiry}->{$event_type} = 1; + } + } + return $events; +} + +sub parse_event_missed { + my ($self, $event, $closed, $events) = @_; + my $report = $self->problems->search({ external_id => $event->{Guid} })->first; + my $service_id = $event->{ServiceId}; + my $data = { + closed => $closed, + date => construct_bin_date($event->{EventDate}), + }; + $data->{report} = $report if $report; + push @{$events->{missed}->{$service_id}}, $data; +} + sub _events_since_date { my ($self, $last_date, $events) = @_; my @since_events = grep { $_->{date} >= $last_date } @$events; diff --git a/perllib/FixMyStreet/Roles/CobrandSLWP.pm b/perllib/FixMyStreet/Roles/CobrandSLWP.pm index 42152687009..2d9f6e23694 100644 --- a/perllib/FixMyStreet/Roles/CobrandSLWP.pm +++ b/perllib/FixMyStreet/Roles/CobrandSLWP.pm @@ -561,88 +561,56 @@ sub bin_services_for_address { return \@out; } -sub _closed_event { - my $event = shift; - return 1 if $event->{ResolvedDate}; -# return 1 if $event->{ResolutionCodeId} && $event->{ResolutionCodeId} != 584; # Out of Stock TODO Check this - return 0; -} - -sub _parse_events { - my $self = shift; - my $events_data = shift; - my $events; - foreach (@$events_data) { - my $event_type = $_->{EventTypeId}; - my $type = 'enquiry'; - $type = 'request' if $event_type == 1635; - $type = 'missed' if $event_type == 1566 || $event_type == 1568; - - # Only care about open requests/enquiries - my $closed = _closed_event($_); - next if $type ne 'missed' && $closed; - - if ($type eq 'request') { - my $report = $self->problems->search({ external_id => $_->{Guid} })->first; - my $data = Integrations::Echo::force_arrayref($_->{Data}, 'ExtensibleDatum'); - foreach (@$data) { - my $moredata = Integrations::Echo::force_arrayref($_->{ChildData}, 'ExtensibleDatum'); - foreach (@$moredata) { - if ($_->{DatatypeName} eq 'Container Type') { - my $container = $_->{Value}; - $events->{request}->{$container} = $report ? { report => $report } : 1; - } - } - } - } elsif ($type eq 'missed') { - my $report = $self->problems->search({ external_id => $_->{Guid} })->first; - my $event = { - closed => $closed, - date => construct_bin_date($_->{EventDate}), - }; - $event->{report} = $report if $report; - - my $service_id = $_->{ServiceId}; - if ($service_id == 405) { - push @{$events->{missed}->{2238}}, $event; - push @{$events->{missed}->{2242}}, $event; - push @{$events->{missed}->{3576}}, $event; - } elsif ($service_id == 406) { - push @{$events->{missed}->{2243}}, $event; - } elsif ($service_id == 409) { - push @{$events->{missed}->{2247}}, $event; - } elsif ($service_id == 420) { # TODO Will food events come in as this? +sub missed_event_types { { + 1635 => 'request', + 1566 => 'missed', + 1568 => 'missed', + 1571 => 'missed', +} } + +sub parse_event_missed { + my ($self, $echo_event, $closed, $events) = @_; + my $report = $self->problems->search({ external_id => $echo_event->{Guid} })->first; + my $event = { + closed => $closed, + date => construct_bin_date($echo_event->{EventDate}), + }; + $event->{report} = $report if $report; + + my $service_id = $echo_event->{ServiceId}; + if ($service_id == 405) { + push @{$events->{missed}->{2238}}, $event; + push @{$events->{missed}->{2242}}, $event; + push @{$events->{missed}->{3576}}, $event; + } elsif ($service_id == 406) { + push @{$events->{missed}->{2243}}, $event; + } elsif ($service_id == 409) { + push @{$events->{missed}->{2247}}, $event; + } elsif ($service_id == 420) { # TODO Will food events come in as this? + push @{$events->{missed}->{2239}}, $event; + push @{$events->{missed}->{2248}}, $event; + } elsif ($service_id == 408 || $service_id == 410) { + my $data = Integrations::Echo::force_arrayref($echo_event->{Data}, 'ExtensibleDatum'); + foreach (@$data) { + if ($_->{DatatypeName} eq 'Paper' && $_->{Value} == 1) { + push @{$events->{missed}->{2240}}, $event; + push @{$events->{missed}->{2249}}, $event; + push @{$events->{missed}->{2632}}, $event; + } elsif ($_->{DatatypeName} eq 'Container Mix' && $_->{Value} == 1) { + push @{$events->{missed}->{2241}}, $event; + push @{$events->{missed}->{2246}}, $event; + push @{$events->{missed}->{2250}}, $event; + push @{$events->{missed}->{3571}}, $event; + } elsif ($_->{DatatypeName} eq 'Food' && $_->{Value} == 1) { push @{$events->{missed}->{2239}}, $event; push @{$events->{missed}->{2248}}, $event; - } elsif ($service_id == 408 || $service_id == 410) { - my $data = Integrations::Echo::force_arrayref($_->{Data}, 'ExtensibleDatum'); - foreach (@$data) { - if ($_->{DatatypeName} eq 'Paper' && $_->{Value} == 1) { - push @{$events->{missed}->{2240}}, $event; - push @{$events->{missed}->{2249}}, $event; - push @{$events->{missed}->{2632}}, $event; - } elsif ($_->{DatatypeName} eq 'Container Mix' && $_->{Value} == 1) { - push @{$events->{missed}->{2241}}, $event; - push @{$events->{missed}->{2246}}, $event; - push @{$events->{missed}->{2250}}, $event; - push @{$events->{missed}->{3571}}, $event; - } elsif ($_->{DatatypeName} eq 'Food' && $_->{Value} == 1) { - push @{$events->{missed}->{2239}}, $event; - push @{$events->{missed}->{2248}}, $event; - } - } - } else { - push @{$events->{missed}->{$service_id}}, $event; } - } else { # General enquiry of some sort - $events->{enquiry}->{$event_type} = 1; } + } else { + push @{$events->{missed}->{$service_id}}, $event; } - return $events; } -sub bin_day_format { '%A, %-d~~~ %B' } - =head2 within_working_days Given a DateTime object and a number, return true if today is less than or