Skip to content

Commit

Permalink
[Merton] Garden waste.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed May 14, 2024
1 parent d350640 commit a0749cd
Show file tree
Hide file tree
Showing 16 changed files with 1,671 additions and 112 deletions.
7 changes: 2 additions & 5 deletions perllib/FixMyStreet/App/Controller/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ sub garden_modify : Chained('garden_setup') : Args(0) {

$c->stash->{per_bin_cost} = $c->cobrand->garden_waste_cost_pa;

if (($c->cobrand->moniker eq 'kingston' || $c->cobrand->moniker eq 'sutton') && $service->{garden_container} == 28) { # SLWP Sack
if ($c->stash->{slwp_garden_sacks} && $service->{garden_container} == 28) { # SLWP Sack
if ($c->cobrand->moniker eq 'kingston') {
my $payment_method = 'credit_card';
$c->forward('check_if_staff_can_pay', [ $payment_method ]); # Should always be okay here
Expand Down Expand Up @@ -1290,8 +1290,6 @@ sub process_garden_cancellation : Private {
if (!$c->stash->{slwp_garden_sacks} || $service->{garden_container} == 26 || $service->{garden_container} == 27) {
my $bin_count = $c->cobrand->get_current_garden_bins;
$data->{new_bins} = $bin_count * -1;
} else {
$data->{slwp_garden_sacks} = 1;
}
$c->forward('setup_garden_sub_params', [ $data, undef ]);

Expand Down Expand Up @@ -1383,8 +1381,7 @@ sub process_garden_modification : Private {
my $payment_method;
# Needs to check current subscription too
my $service = $c->cobrand->garden_current_subscription;
if (($c->cobrand->moniker eq 'kingston' || $c->cobrand->moniker eq 'sutton') && $service->{garden_container} == 28) { # SLWP Sack
$data->{slwp_garden_sacks} = 1;
if ($c->stash->{slwp_garden_sacks} && $service->{garden_container} == 28) { # SLWP Sack
$data->{bin_count} = 1;
$data->{new_bins} = 1;
$payment = $c->cobrand->garden_waste_sacks_cost_pa();
Expand Down
22 changes: 5 additions & 17 deletions perllib/FixMyStreet/App/Form/Waste/Garden/Sacks.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use HTML::FormHandler::Moose;
extends 'FixMyStreet::App::Form::Waste::Garden';

sub with_sacks_choice { 1 }
sub with_bins_wanted { 0 }
sub with_bins_wanted {
my $cobrand = $_[0]->c->cobrand->moniker;
return $cobrand eq 'merton';
}

has_page choice => (
title_ggw => 'Subscribe to the %s',
Expand All @@ -22,22 +25,7 @@ has_page choice => (
}
);

has_field container_choice => (
type => 'Select',
label => 'Would you like to subscribe for bins or sacks?',
required => 1,
widget => 'RadioGroup',
);

sub options_container_choice {
my $cobrand = $_[0]->{c}->cobrand->moniker;
my $num = $cobrand eq 'sutton' ? 20 :
$cobrand eq 'kingston' ? 10 : '';
[
{ value => 'bin', label => 'Bins', hint => '240L capacity, which is about the same size as a standard wheelie bin' },
{ value => 'sack', label => 'Sacks', hint => "Buy a roll of $num sacks and use them anytime within your subscription year" },
];
}
with 'FixMyStreet::App::Form::Waste::Garden::Sacks::Choice';

has_page sacks_details => (
title_ggw => 'Subscribe to the %s',
Expand Down
37 changes: 37 additions & 0 deletions perllib/FixMyStreet/App/Form/Waste/Garden/Sacks/Choice.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package FixMyStreet::App::Form::Waste::Garden::Sacks::Choice;

use utf8;
use HTML::FormHandler::Moose::Role;

has_field container_choice => (
type => 'Select',
label => 'Would you like to subscribe for bins or sacks?',
required => 1,
widget => 'RadioGroup',
);

my %sack_num = (
sutton => 20,
kingston => 10,
merton => 25,
brent => '',
);

sub options_container_choice {
my $cobrand = $_[0]->{c}->cobrand->moniker;
my $num = $sack_num{$cobrand};
my @containers;
if ($cobrand eq 'merton') {
push @containers,
{ value => 'bin140', label => '140L bin', hint => 'About the same size as a small wheelie bin' },
{ value => 'bin240', label => '240L bin', hint => 'About the same size as a standard wheelie bin' };
} else {
push @containers,
{ value => 'bin', label => 'Bins', hint => '240L capacity, which is about the same size as a standard wheelie bin' };
}
push @containers,
{ value => 'sack', label => 'Sacks', hint => "Buy a roll of $num sacks and use them anytime within your subscription year" };
return \@containers;
}

1;
22 changes: 5 additions & 17 deletions perllib/FixMyStreet/App/Form/Waste/Garden/Sacks/Renew.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use utf8;
use HTML::FormHandler::Moose;
extends 'FixMyStreet::App::Form::Waste::Garden::Renew';

sub with_bins_wanted { 0 }
sub with_bins_wanted {
my $cobrand = $_[0]->c->cobrand->moniker;
return $cobrand eq 'merton';
}

has_page sacks_choice => (
title_ggw => 'Subscribe to the %s',
Expand All @@ -28,22 +31,7 @@ has_page sacks_choice => (
},
);

has_field container_choice => (
type => 'Select',
label => 'Would you like to subscribe for bins or sacks?',
required => 1,
widget => 'RadioGroup',
);

sub options_container_choice {
my $cobrand = $_[0]->{c}->cobrand->moniker;
my $num = $cobrand eq 'sutton' ? 20 :
$cobrand eq 'kingston' ? 10 : '';
[
{ value => 'bin', label => 'Bins', hint => '240L capacity, which is about the same size as a standard wheelie bin' },
{ value => 'sack', label => 'Sacks', hint => "Buy a roll of $num sacks and use them anytime within your subscription year" },
];
}
with 'FixMyStreet::App::Form::Waste::Garden::Sacks::Choice';

has_page sacks_details => (
title => 'Renew your green garden waste subscription',
Expand Down
44 changes: 43 additions & 1 deletion perllib/FixMyStreet/Cobrand/Merton/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@ package FixMyStreet::Cobrand::Merton::Waste;

use Moo::Role;
with 'FixMyStreet::Roles::Cobrand::SLWP';
with 'FixMyStreet::Roles::Cobrand::Adelante';

use FixMyStreet::App::Form::Waste::Report::Merton;
use FixMyStreet::App::Form::Waste::Request::Merton;

has lpi_value => ( is => 'ro', default => 'MERTON' );

sub waste_check_staff_payment_permissions {
my $self = shift;
my $c = $self->{c};

return unless $c->stash->{is_staff};

$c->stash->{staff_payments_allowed} = 'cnp';
}

sub waste_auto_confirm_report { 1 }

sub service_name_override {
Expand Down Expand Up @@ -113,15 +123,34 @@ sub _closed_event {
}

# TODO
sub garden_container_data_extract { }
sub waste_bulky_missed_blocked_codes {}

sub garden_collection_time { '6:30am' }
sub garden_waste_new_bin_admin_fee { 0 }

sub waste_quantity_max {
return (
2247 => 3, # Garden waste maximum
);
}

# Not in the function below because it needs to set things needed before then
# (perhaps could be refactored better at some point). Used for new/renew
sub waste_garden_sub_payment_params {
my ($self, $data) = @_;
my $c = $self->{c};

# Special sack form handling
my $container = $data->{container_choice} || '';
if ($container eq 'sack') {
$data->{bin_count} = $data->{bins_wanted};
$data->{new_bins} = $data->{bins_wanted};
my $cost_pa = $c->cobrand->garden_waste_sacks_cost_pa() * $data->{bin_count};
($cost_pa) = $c->cobrand->apply_garden_waste_discount($cost_pa) if $data->{apply_discount};
$c->set_param('payment', $cost_pa);
}
}

sub waste_request_form_first_next {
my $self = shift;
return sub {
Expand Down Expand Up @@ -213,4 +242,17 @@ sub waste_munge_enquiry_data {
$data->{detail} = $detail;
}

=head2 Payment information
=cut

sub waste_payment_ref_council_code { 'LBM' }

sub waste_cc_payment_reference {
my ($self, $p) = @_;
my $type = 'GWS'; # Garden
$type = 'BWC' if $p->category eq 'Bulky collection';
return $self->waste_payment_ref_council_code . "-$type-" . $p->id;
}

1;
64 changes: 0 additions & 64 deletions perllib/FixMyStreet/Roles/Cobrand/KingstonSutton.pm
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ sub available_permissions {

sub waste_auto_confirm_report { 1 }

sub waste_staff_choose_payment_method { 1 }
sub waste_cheque_payments { shift->{c}->stash->{staff_payments_allowed} }

use constant CONTAINER_REFUSE_140 => 1;
use constant CONTAINER_REFUSE_180 => 35;
use constant CONTAINER_REFUSE_240 => 2;
Expand Down Expand Up @@ -261,20 +258,6 @@ sub waste_munge_bin_services_open_requests {
}
}

sub garden_container_data_extract {
my ($self, $data, $containers, $quantities, $schedules) = @_;
# Assume garden will only have one container data
my $garden_container = $containers->[0];
my $garden_bins = $quantities->{$containers->[0]};
if ($garden_container == CONTAINER_GARDEN_SACK) {
my $garden_cost = $self->garden_waste_renewal_sacks_cost_pa($schedules->{end_date}) / 100;
return ($garden_bins, 1, $garden_cost, $garden_container);
} else {
my $garden_cost = $self->garden_waste_renewal_cost_pa($schedules->{end_date}, $garden_bins) / 100;
return ($garden_bins, 0, $garden_cost, $garden_container);
}
}

# Not in the function below because it needs to set things needed before then
# (perhaps could be refactored better at some point). Used for new/renew
sub waste_garden_sub_payment_params {
Expand All @@ -284,7 +267,6 @@ sub waste_garden_sub_payment_params {
# Special sack form handling
my $container = $data->{container_choice} || '';
if ($container eq 'sack') {
$data->{slwp_garden_sacks} = 1;
$data->{bin_count} = 1;
$data->{new_bins} = 1;
my $cost_pa = $c->cobrand->garden_waste_sacks_cost_pa();
Expand All @@ -293,46 +275,6 @@ sub waste_garden_sub_payment_params {
}
}

sub waste_garden_sub_params {
my ($self, $data, $type) = @_;
my $c = $self->{c};

my $service = $self->garden_current_subscription;
my $existing = $service ? $service->{garden_container} : undef;
my $container = $data->{slwp_garden_sacks} ? CONTAINER_GARDEN_SACK : $existing || CONTAINER_GARDEN_BIN;
my $container_actions = {
deliver => 1,
remove => 2
};

$c->set_param('Request_Type', $type);
$c->set_param('Subscription_Details_Containers', $container);
$c->set_param('Subscription_Details_Quantity', $data->{bin_count});
if ( $data->{new_bins} ) {
my $action = ($data->{new_bins} > 0) ? 'deliver' : 'remove';
$c->set_param('Bin_Delivery_Detail_Containers', $container_actions->{$action});
$c->set_param('Bin_Delivery_Detail_Container', $container);
$c->set_param('Bin_Delivery_Detail_Quantity', abs($data->{new_bins}));
}
}

sub waste_garden_subscribe_form_setup {
my ($self) = @_;
my $c = $self->{c};
if ($c->stash->{slwp_garden_sacks}) {
$c->stash->{form_class} = 'FixMyStreet::App::Form::Waste::Garden::Sacks';
}
}

sub waste_garden_renew_form_setup {
my ($self) = @_;
my $c = $self->{c};
if ($c->stash->{slwp_garden_sacks}) {
$c->stash->{first_page} = 'sacks_choice';
$c->stash->{form_class} = 'FixMyStreet::App::Form::Waste::Garden::Sacks::Renew';
}
}

=head2 waste_munge_report_form_fields
We use a custom report form to add some text to the "About you" page.
Expand Down Expand Up @@ -362,12 +304,6 @@ sub waste_report_form_first_next {
};
}

# Same as full cost
sub waste_get_pro_rata_cost {
my ($self, $bins, $end) = @_;
return $self->garden_waste_cost_pa($bins);
}

sub garden_waste_new_bin_admin_fee {
my ($self, $new_bins) = @_;
$new_bins ||= 0;
Expand Down

0 comments on commit a0749cd

Please sign in to comment.