Skip to content

Commit

Permalink
Merge branch 'bexley-ww-container-requests' into commercial-staging
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Nov 19, 2024
2 parents bec96a6 + 25f375b commit 934d706
Show file tree
Hide file tree
Showing 13 changed files with 290 additions and 103 deletions.
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/App/Form/Waste/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ sub validate {
foreach ($self->all_fields) {
# Either a container-* has been selected, or
# Kingston/Merton/Bexley special cases for first-page question
$any = 1 if $_->name =~ /^container-|how_many_exchange|household_size|medical_condition/ && ($_->value || $self->saved_data->{$_->name});
$any = 1 if $_->name =~ /^container-|parent-|how_many_exchange|household_size|medical_condition/ && ($_->value || $self->saved_data->{$_->name});
}
$self->add_form_error('Please specify what you need')
unless $any;
Expand Down
62 changes: 62 additions & 0 deletions perllib/FixMyStreet/App/Form/Waste/Request/Bexley.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,38 @@ has_field request_reason => (
label => 'Why do you need new bins?',
);

has_page letterbox_location => (
fields => ['letterbox_location', 'continue'],
title => 'Letterbox location',
next => 'about_you',
);

has_field letterbox_location => (
type => 'Select',
widget => 'RadioGroup',
required => 1,
label => 'Where is your letterbox?',
);

has_page summary => (
fields => ['declaration', 'submit'],
title => 'Submit bin request',
template => 'waste/summary_request.html',
finished => sub {
return $_[0]->wizard_finished('process_request_data');
},
next => 'done',
);

has_field declaration => (
type => 'Checkbox',
label => label_declaration(),
option_label => 'I confirm I have read and understood the above statements',
required => 1,
tags => { safe => 'label' },
messages => { required => 'Please read and accept the declaration' },
);

has_field submit => (
type => 'Submit',
value => 'Request bin delivery or removal',
Expand All @@ -67,4 +99,34 @@ sub options_request_reason {
return map { { label => $_, value => $_ } } @options;
}

sub options_letterbox_location {
my $form = shift;

my @options = (
'At the front',
'At the rear',
'At the side',
'On the first floor balcony',
'Communal entrance',
);
return map { { label => $_, value => $_ } } @options;
}

sub label_declaration {
my $text = <<HTML;
<div class="govuk-summary-list__key">Declaration</div>
<div>
By continuing with your request:
<br>
<ul>
<li>I agree that containers will only be used for the storage of waste and recycling for collection and will not be used for any other purposes</li>
<li>I understand that all waste and recycling containers remain the property of the London Borough of Bexley</li>
<li>I understand that if I have more than the permitted number of containers or misuse containers they may be removed from my property without prior notice</li>
<li>I understand that I will not necessarily receive brand-new waste containers. Where second-hand containers are delivered they will be clean and undamaged, but may have markings from their previous use</li>
</ul>
</div>
HTML
return $text;
}

1;
136 changes: 90 additions & 46 deletions perllib/FixMyStreet/Cobrand/Bexley/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ HTML
description => 'Glass bottles and jars',
},
'MDR-SACK' => {
name => 'Clear Sack(s)',
name => 'Clear Sacks',
description => $clear_sack_desc,
description_contains_html => 1,
},
Expand Down Expand Up @@ -1094,7 +1094,7 @@ HTML
description => 'Non-recyclable waste',
},
'RES-SACK' => {
name => 'Black Sack(s)',
name => 'Black Sacks',
description => 'Non-recyclable waste',
},
};
Expand Down Expand Up @@ -1283,17 +1283,19 @@ sub construct_bin_request_form {
my $include_removal = @$removal_field_list;

# Above-shop properties get a single default reason, so no need to send
# them to reason selection
my $include_reason
= $self->{c}->stash->{property}{above_shop} ? 0 : 1;
# them to reason selection. They need to be sent to letterbox location
# selection instead.
my $above_shop
= $self->{c}->stash->{property}{above_shop} ? 1 : 0;

my $next
= $include_removal
? 'request_removal'
: ( $include_reason ? 'request_reason' : 'about_you' );
: ( $above_shop ? 'letterbox_location' : 'request_reason' );

$page_list = [
request => {
intro => 'container_delivery_intro.html',
fields => [ grep { ! ref $_ } @$delivery_field_list, 'continue' ],
title => 'Which bins do you need?',
check_unique_id => 0,
Expand All @@ -1315,7 +1317,7 @@ sub construct_bin_request_form {
fields => [ grep { ! ref $_ } @$removal_field_list, 'continue' ],
title => 'Which bins do you need to be removed?',
check_unique_id => 0,
next => ( $include_reason ? 'request_reason' : 'about_you' ),
next => ( $above_shop ? 'about_you' : 'request_reason' ),
},
);
push @$full_field_list, @$removal_field_list;
Expand Down Expand Up @@ -1400,7 +1402,7 @@ sub _construct_bin_request_form_delivery {
tags => {
hint => "You can request a maximum of "
. NUMWORDS($max)
. " bins",
. ( $container->{name} eq 'Recycling Box Lids' ? ' lids' : ' bins' ),
initial_hidden => 1,
},
options => [
Expand Down Expand Up @@ -1434,38 +1436,60 @@ sub _construct_bin_request_form_removal {
my $open_key = $container->{service_item_name} || $container->{name};
my $disabled = $open_reports->{$open_key} ? 1 : 0;

# For containers with subtypes, choose the ID ('service_item_name')
# that the property currently has
my $id
= $container->{subtypes}
? $service_names_to_ids{ $container->{name} }
: $container->{service_item_name};

$id .= '-removal';

push @$field_list, "container-$id" => {
type => 'Checkbox',
label => $container->{name},
option_label => $container->{description},
tags => { toggle => "form-quantity-$id-row" },
disabled => $disabled,
};
if ($container->{subtypes}) {
my $id = $container->{name} =~ s/ /-/gr;
$id .= '-removal';

my $max = $container->{max} || 1;
if ( $max > 1 ) {
push @$field_list, "quantity-$id" => {
type => 'Select',
label => 'Quantity',
tags => {
hint => "You can request removal of a maximum of " . NUMWORDS($max) . " bins",
initial_hidden => 1,
},
push @$field_list, "parent-$id" => {
type => 'Checkbox',
label => $container->{name},
option_label => $container->{description},
tags => { toggle => "form-bin-size-$id-row" },
disabled => $disabled,
};

push @$field_list, "bin-size-$id" => {
type => 'Select',
label => 'Bin Size',
tags => { initial_hidden => 1 },
options => [
map { { value => $_, label => $_ } }
( 1 .. $max ),
map {
label => $_->{size},
value => $_->{service_item_name},
},
@{ $container->{subtypes} }
],
required_when => { "container-$id" => 1 },
required_when => { "parent-$id" => 1 },
};

} else {
my $id = $container->{service_item_name} . '-removal';

push @$field_list, "container-$id" => {
type => 'Checkbox',
label => $container->{name},
option_label => $container->{description},
tags => { toggle => "form-quantity-$id-row" },
disabled => $disabled,
};

my $max = $container->{max} || 1;
if ( $max > 1 ) {
push @$field_list, "quantity-$id" => {
type => 'Select',
label => 'Quantity',
tags => {
hint => "You can request removal of a maximum of " . NUMWORDS($max) . " bins",
initial_hidden => 1,
},
options => [
map { { value => $_, label => $_ } }
( 1 .. $max ),
],
required_when => { "container-$id" => 1 },
};
}

}
}

Expand Down Expand Up @@ -1511,7 +1535,12 @@ sub waste_munge_request_form_data {
next unless $parent_id && $data->{"parent-$parent_id"};

my $subtype_id = $data->{"bin-size-$parent_id"};
$data->{"container-$subtype_id"} = 1 if $subtype_id;

if ($subtype_id) {
$parent_id =~ /-removal/
? $data->{"container-$subtype_id-removal"} = 1
: $data->{"container-$subtype_id"} = 1;
}
}
}

Expand Down Expand Up @@ -1578,18 +1607,25 @@ sub waste_munge_request_data {
$data->{category} = $data->{category_removal};
}

my $reason;
my $letterbox_location;
if ( $c->stash->{property}{above_shop} ) {
$reason = 'I need more sacks';
$letterbox_location = $data->{letterbox_location};
} else {
$reason = $data->{request_reason};
}

my $address = $c->stash->{property}{address};
my $reason
= $c->stash->{property}{above_shop}
? 'I need more sacks'
: $data->{request_reason};
my $quantity = $data->{"quantity-$id"} || 1;
my $household_size = $data->{household_size};
$data->{detail} = "$data->{title}\n\n$address";
$data->{detail} .= "\n\nReason: $reason";
$data->{detail} .= "\n\nQuantity: $quantity";
$data->{detail} .= "\n\nHousehold size: $household_size"
if $household_size;
$data->{detail} .= "\n\nLocation of letterbox: $letterbox_location"
if $letterbox_location;

my $assisted_yn = $c->stash->{services}{ $service->{service_item_name} }
{assisted_collection}
Expand All @@ -1599,6 +1635,7 @@ sub waste_munge_request_data {
$c->set_param( 'service_item_name', $service->{service_item_name} );
$c->set_param( 'quantity', $quantity );
$c->set_param( 'assisted_yn', $assisted_yn );
$c->set_param( 'location_of_letterbox', $letterbox_location || '' );
}

sub _set_request_containers {
Expand Down Expand Up @@ -1678,7 +1715,7 @@ sub _set_request_containers {

} elsif ( $service_id eq 'MDR-SACK' ) {
$container_info
= _containers_for_requests()->{'Clear Sack(s)'};
= _containers_for_requests()->{'Clear Sacks'};
push @containers_for_delivery, $container_info;

$service->{delivery_allowed} = 1;
Expand Down Expand Up @@ -1714,7 +1751,7 @@ sub _set_request_containers {
push @containers_for_delivery,
_containers_for_requests()->{'Recycling Box Lids'};

$property->{can_order_lids} = 1;
$property->{has_boxes} = 1;
}

$boxes_done = 1;
Expand Down Expand Up @@ -1763,7 +1800,9 @@ sub requests_for_display {

my $subtype_id = $data->{"bin-size-$parent_id"};
my %container = %{ $by_id{$subtype_id} };
push @requested_deliveries, \%container;
$parent_id =~ /-removal/
? ( push @requested_removals, \%container )
: ( push @requested_deliveries, \%container );
}

return \@requested_deliveries, \@requested_removals;
Expand Down Expand Up @@ -1871,33 +1910,38 @@ sub _containers_for_requests {
description => 'Paper and card',
service_item_name => 'PA-55',
service_id_removal => '181',
max => 3,
},
{ name => 'Maroon Recycling Box',
description => 'Plastics and cans',
service_item_name => 'PL-55',
service_id_removal => '192',
max => 3,
},
{ name => 'Black Recycling Box',
description => 'Glass bottles and jars',
service_item_name => 'GL-55',
service_id_removal => '166',
max => 3,
},
{ name => 'White Recycling Box',
description => 'Plastics, cans and glass',
service_item_name => 'PG-55',
service_id_delivery => '328',
service_id_removal => '336',
max => 3,
},
{ name => 'Blue Recycling Box',
description => 'Paper and card',
service_item_name => 'PC-55',
service_id_delivery => '324',
service_id_removal => '332',
max => 3,
},
],

'Clear Sack(s)' => {
name => 'Clear Sack(s)',
'Clear Sacks' => {
name => 'Clear Sacks',
description => 'Mixed recycling',
service_item_name => 'MDR-SACK',
service_id_delivery => '243',
Expand Down
2 changes: 1 addition & 1 deletion t/app/controller/waste_bexley.t
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ FixMyStreet::override_config {
$email_submit = $mech->get_html_body_from_email($email_submit);
$email_logged = $mech->get_text_body_from_email($email_logged);
like $email_logged, qr{Containers requested: $joined};
like $email_submit, qr{Containers requested:</h2>\s*<p[^>]*>\s*$joined};
like $email_submit, qr{<td>New/replacement container</td> <td>$joined};
like $email_submit, qr{<td>UPRN</td> <td>$_->{id}</td>}
};
}
Expand Down
Loading

0 comments on commit 934d706

Please sign in to comment.