diff --git a/perllib/Integrations/Whitespace.pm b/perllib/Integrations/Whitespace.pm index d432336d5..25c7ab2aa 100644 --- a/perllib/Integrations/Whitespace.pm +++ b/perllib/Integrations/Whitespace.pm @@ -92,6 +92,14 @@ sub CreateWorksheet { die "No service_item_name provided"; } + # EXAMPLE FOR conf/council-bexley_whitespace.yml + # service_mapping: + # PG-240: + # service_item_id: 802 # Plastics & glass 240 ltr wheeled bin + # service_id: 319 # Missed Collection Plastics & Glass + # delivery_service_id: 331 # Deliver Plastics & Glass 240 ltr Bin + # collection_service_id: 339 # Collect Plastics & Glass 240 ltr Bin + my $service_mapping = $self->config->{service_mapping}; my $service_params = $service_mapping->{$params->{service_item_name}}; @@ -100,36 +108,62 @@ sub CreateWorksheet { die "No service mapping found for $params->{service_item_name}"; } - my $worksheet = ixhash( - Uprn => $params->{uprn}, - ServiceId => $service_params->{service_id}, + my %common_params = ( + Uprn => $params->{uprn}, WorksheetReference => $params->{worksheet_reference}, - WorksheetMessage => $params->{worksheet_message}, - ServiceItemInputs => ixhash( - 'wsap:Input.CreateWorksheetInput.ServiceItemInput' => [ - ixhash( - 'wsap:ServiceItemId' => $service_params->{service_item_id}, - 'wsap:ServiceItemName' => '', - 'wsap:ServiceItemQuantity' => 1, - ) - ] - ), - ServicePropertyInputs => [ - { - 'wsap:Input.CreateWorksheetInput.ServicePropertyInput' => ixhash( - 'wsap:ServicePropertyId' => 79, - 'wsap:ServicePropertyValue' => $params->{assisted_yn}, - ), - }, - { - 'wsap:Input.CreateWorksheetInput.ServicePropertyInput' => ixhash( - 'wsap:ServicePropertyId' => 80, - 'wsap:ServicePropertyValue' => $params->{location_of_containers}, - ), - }, - ], + WorksheetMessage => $params->{worksheet_message}, ); + my $worksheet; + if ( $params->{service_code} eq 'request_new_container' ) { + + # TODO Worksheet for collection as well + + $worksheet = ixhash( + %common_params, + ServiceId => $service_params->{delivery_service_id}, + ServiceItemInputs => ixhash( + 'wsap:Input.CreateWorksheetInput.ServiceItemInput' => [ + ixhash( + 'wsap:ServiceItemId' => $service_params->{service_item_id}, + 'wsap:ServiceItemName' => '', + 'wsap:ServiceItemQuantity' => 1, + ) + ] + ), + # TODO ServicePropertyInputs? + ); + } else { + # Missed collection + $worksheet = ixhash( + %common_params, + ServiceId => $service_params->{service_id}, + ServiceItemInputs => ixhash( + 'wsap:Input.CreateWorksheetInput.ServiceItemInput' => [ + ixhash( + 'wsap:ServiceItemId' => $service_params->{service_item_id}, + 'wsap:ServiceItemName' => '', + 'wsap:ServiceItemQuantity' => 1, + ) + ] + ), + ServicePropertyInputs => [ + { + 'wsap:Input.CreateWorksheetInput.ServicePropertyInput' => ixhash( + 'wsap:ServicePropertyId' => 79, + 'wsap:ServicePropertyValue' => $params->{assisted_yn}, + ), + }, + { + 'wsap:Input.CreateWorksheetInput.ServicePropertyInput' => ixhash( + 'wsap:ServicePropertyId' => 80, + 'wsap:ServicePropertyValue' => $params->{location_of_containers}, + ), + }, + ], + ); + } + my $res = $self->call('CreateWorksheet', worksheetInput => $worksheet); $self->logger->debug("CreateWorksheet response: " . encode_json($res)); diff --git a/perllib/Open311/Endpoint/Integration/Whitespace.pm b/perllib/Open311/Endpoint/Integration/Whitespace.pm index f923b0787..1a0dc2b52 100644 --- a/perllib/Open311/Endpoint/Integration/Whitespace.pm +++ b/perllib/Open311/Endpoint/Integration/Whitespace.pm @@ -78,14 +78,29 @@ sub post_service_request { my $integration = $self->get_integration; - my $worksheet_id = $integration->CreateWorksheet({ - uprn => $args->{attributes}->{uprn}, - service_item_name => $args->{attributes}->{service_item_name}, - worksheet_reference => $args->{attributes}->{fixmystreet_id}, - worksheet_message => $self->_worksheet_message($args), - assisted_yn => $args->{attributes}->{assisted_yn}, - location_of_containers => $args->{attributes}->{location_of_containers}, - }); + my %worksheet_params; + if ( $args->{service_code} eq 'request_new_container' ) { + %worksheet_params = ( + uprn => $args->{attributes}->{uprn}, + service_item_name => $args->{attributes}->{service_item_name}, + worksheet_reference => $args->{attributes}->{fixmystreet_id}, + worksheet_message => '# TODO', + service_code => $args->{service_code}, + ); + } else { + # Missed collection + %worksheet_params = ( + uprn => $args->{attributes}->{uprn}, + service_item_name => $args->{attributes}->{service_item_name}, + worksheet_reference => $args->{attributes}->{fixmystreet_id}, + worksheet_message => $self->_worksheet_message($args), + assisted_yn => $args->{attributes}->{assisted_yn}, + location_of_containers => + $args->{attributes}->{location_of_containers}, + ); + } + + my $worksheet_id = $integration->CreateWorksheet( \%worksheet_params ); my $request = $self->new_request( service_request_id => $worksheet_id, @@ -94,6 +109,8 @@ sub post_service_request { return $request; } +# TODO Is this the sub we use, or the identically named sub in +# Open311/Endpoint/Integration/UK/Bexley/Whitespace.pm? sub _worksheet_message { my ($self, $args) = @_;