diff options
author | Matthew Somerville <matthew@mysociety.org> | 2020-06-19 14:56:07 +0100 |
---|---|---|
committer | M Somerville <matthew-github@dracos.co.uk> | 2020-11-11 10:29:20 +0000 |
commit | d90e1157ee31c374248da0db42b70456c37ddd5b (patch) | |
tree | 40ca64ade09bc11fc9cae0064b46d05e6fd6ee2e /perllib | |
parent | d7aca19faade6fb8f4aa47213d0f38b14cb9854a (diff) |
[Bromley] Look for open events.
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Waste.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bromley.pm | 37 | ||||
-rw-r--r-- | perllib/Integrations/Echo.pm | 40 |
3 files changed, 79 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Waste.pm b/perllib/FixMyStreet/App/Controller/Waste.pm index 7556781cf..7587795c8 100644 --- a/perllib/FixMyStreet/App/Controller/Waste.pm +++ b/perllib/FixMyStreet/App/Controller/Waste.pm @@ -136,7 +136,7 @@ sub construct_bin_request_form { my $field_list = []; foreach (@{$c->stash->{service_data}}) { - next unless $_->{next}; + next unless $_->{next} && !$_->{request_open}; my $name = $_->{service_name}; my $containers = $_->{request_containers}; my $max = $_->{request_max}; @@ -217,7 +217,7 @@ sub construct_bin_report_form { my $field_list = []; foreach (@{$c->stash->{service_data}}) { - next unless $_->{last} && $_->{report_allowed}; + next unless $_->{last} && $_->{report_allowed} && !$_->{report_open}; my $id = $_->{service_id}; my $name = $_->{service_name}; push @$field_list, "service-$id" => { diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm index 263549e71..8b6924f2d 100644 --- a/perllib/FixMyStreet/Cobrand/Bromley.pm +++ b/perllib/FixMyStreet/Cobrand/Bromley.pm @@ -522,6 +522,9 @@ sub bin_services_for_address { my $result = $echo->GetServiceUnitsForObject($property->{uprn}); return [] unless @$result; + my $events = $echo->GetEventsForObject($property->{id}); + my $open = $self->_parse_open_events($events); + my @out; foreach (@$result) { next unless $_->{ServiceTasks}; @@ -532,12 +535,15 @@ sub bin_services_for_address { next unless $schedules->{next} or $schedules->{last}; my $containers = $service_to_containers{$_->{ServiceId}}; + my ($open_request) = grep { $_ } map { $open->{request}->{$_} } @$containers; my $row = { id => $_->{Id}, service_id => $_->{ServiceId}, service_name => $service_name_override{$_->{ServiceId}} || $_->{ServiceName}, report_allowed => within_working_days($schedules->{last}{date}, 2), + report_open => $open->{missed}->{$_->{ServiceId}}, request_allowed => $request_allowed{$_->{ServiceId}}, + request_open => $open_request, request_containers => $containers, request_max => $quantity_max{$_->{ServiceId}}, service_task_id => $servicetask->{Id}, @@ -553,6 +559,37 @@ sub bin_services_for_address { return \@out; } +sub _parse_open_events { + my $self = shift; + my $events = shift; + my $open; + foreach (@$events) { + next if $_->{ResolvedDate} || $_->{ResolutionCodeId}; # Is this the right field? + my $event_type = $_->{EventTypeId}; + my $service_id = $_->{ServiceId}; + if ($event_type == 2104) { # Request + my $data = $_->{Data}{ExtensibleDatum}; + my $container; + DATA: foreach (@$data) { + if ($_->{ChildData}) { + foreach (@{$_->{ChildData}{ExtensibleDatum}}) { + if ($_->{DatatypeName} eq 'Container Type') { + $container = $_->{Value}; + last DATA; + } + } + } + } + my $report = $self->problems->search({ external_id => $_->{Guid} })->first; + $open->{request}->{$container} = $report ? { report => $report } : 1; + } elsif (2095 <= $event_type && $event_type <= 2103) { # Missed collection + my $report = $self->problems->search({ external_id => $_->{Guid} })->first; + $open->{missed}->{$service_id} = $report ? { report => $report } : 1; + } + } + return $open; +} + sub _parse_schedules { my $servicetask = shift; my $schedules = $servicetask->{ServiceTaskSchedules}{ServiceTaskSchedule}; diff --git a/perllib/Integrations/Echo.pm b/perllib/Integrations/Echo.pm index 7dc2e6948..205e1178f 100644 --- a/perllib/Integrations/Echo.pm +++ b/perllib/Integrations/Echo.pm @@ -291,6 +291,46 @@ sub GetServiceTaskInstances { return force_arrayref($res, 'ServiceTaskInstances'); } +sub GetEventsForObject { + my ($self, $id, $type) = @_; + my $from = DateTime->now->set_time_zone(FixMyStreet->local_time_zone)->subtract(months => 3); + return [ { + # Missed collection for service 542 + EventTypeId => 2100, + ServiceId => 542, + }, { + # Request for a new paper container + EventTypeId => 2104, + Data => { ExtensibleDatum => [ + { Value => 2, DatatypeName => 'Source' }, + { + ChildData => { ExtensibleDatum => [ + { Value => 1, DatatypeName => 'Action' }, + { Value => 12, DatatypeName => 'Container Type' }, + ] }, + }, + ] }, + ServiceId => 535, + } ] if $self->sample_data; + # uncoverable statement + my $res = $self->call('GetEventsForObject', + objectRef => ixhash( + Key => 'Id', + Type => 'PointAddress', + Value => { 'msArray:anyType' => $id }, + ), + query => ixhash( + $type ? (EventTypeRef => ixhash( + Key => 'Id', + Type => 'EventType', + Value => { 'msArray:anyType' => $type }, + )) : (), + From => dt_to_hash($from), + ), + ); + return force_arrayref($res, 'Event'); +} + sub ixhash { tie (my %data, 'Tie::IxHash', @_); return \%data; |