Skip to content

Commit

Permalink
[Merton] Garden waste.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Apr 17, 2024
1 parent c42e7db commit 702fec8
Show file tree
Hide file tree
Showing 15 changed files with 1,626 additions and 96 deletions.
4 changes: 2 additions & 2 deletions perllib/FixMyStreet/App/Controller/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,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 @@ -1383,7 +1383,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
if ($c->stash->{slwp_garden_sacks} && $service->{garden_container} == 28) { # SLWP Sack
$data->{slwp_garden_sacks} = 1;
$data->{bin_count} = 1;
$data->{new_bins} = 1;
Expand Down
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/App/Form/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ sub validate {
my $c = $self->c;
my $cobrand = $c->cobrand->moniker;
my $is_staff_user = ($c->user_exists && ($c->user->from_body || $c->user->is_superuser));
my $staff_provide_email = (ref $self) =~ /Garden/ && ($c->cobrand->moniker eq 'kingston' || $c->cobrand->moniker eq 'sutton');
my $staff_provide_email = (ref $self) =~ /Garden/ && $c->cobrand->call_hook('garden_staff_provide_email');

$email->add_error('Please provide an email address')
unless $email->is_inactive || $email->value || ($is_staff_user && !$staff_provide_email);
Expand Down
8 changes: 8 additions & 0 deletions perllib/FixMyStreet/App/Form/Waste/Billing.pm
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
=head1 NAME
FixMyStreet::App::Form::Waste::Billing - billing information for garden subs and renewals
=head1 DESCRIPTION
=cut

package FixMyStreet::App::Form::Waste::Billing;

use utf8;
Expand Down
5 changes: 5 additions & 0 deletions perllib/FixMyStreet/Cobrand/Brent.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,11 @@ sub garden_service_name { 'Garden waste collection service' }
sub garden_subscription_event_id { 1159 }
sub garden_due_days { 90 }

sub waste_show_garden_modify {
my ($self, $unit) = @_;
return $self->{c}->stash->{is_staff};
}

sub waste_cc_payment_line_item_ref {
my ($self, $p) = @_;
return "Brent-" . $p->id;
Expand Down
27 changes: 26 additions & 1 deletion perllib/FixMyStreet/Cobrand/Merton/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ package FixMyStreet::Cobrand::Merton::Waste;

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

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 @@ -112,9 +122,11 @@ 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
Expand All @@ -132,4 +144,17 @@ sub waste_request_form_first_next {

sub garden_due_days { 30 }

=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;
81 changes: 0 additions & 81 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_240 => 2;
use constant CONTAINER_REFUSE_360 => 3;
Expand Down Expand Up @@ -248,78 +245,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 == 28) {
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 {
my ($self, $data) = @_;
my $c = $self->{c};

# 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();
($cost_pa) = $c->cobrand->apply_garden_waste_discount($cost_pa) if $data->{apply_discount};
$c->set_param('payment', $cost_pa);
}
}

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} ? 28 : $existing || 26;
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 @@ -449,12 +374,6 @@ sub waste_munge_request_form_data {
$data->{"container-$container_id"} = 1;
}

# 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
91 changes: 91 additions & 0 deletions perllib/FixMyStreet/Roles/Cobrand/SLWP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ around look_up_property => sub {
return $data;
};

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

sub waste_event_state_map {
return {
New => { New => 'confirmed' },
Expand Down Expand Up @@ -67,6 +70,12 @@ sub waste_service_to_containers { () }

sub garden_subscription_event_id { 1638 }

sub waste_show_garden_modify {
my ($self, $unit) = @_;
return 1 if $self->moniker eq 'kingston';
return $unit->{garden_sacks} ? 0 : 1;
}

sub waste_relevant_serviceunits {
my ($self, $result) = @_;
my @rows;
Expand Down Expand Up @@ -350,6 +359,7 @@ sub waste_munge_report_data {

sub garden_service_name { 'garden waste collection service' }
sub garden_echo_container_name { 'SLWP - Containers' }
sub garden_staff_provide_email { 1 }

sub garden_current_service_from_service_units {
my ($self, $services) = @_;
Expand All @@ -367,6 +377,87 @@ sub garden_current_service_from_service_units {
return $garden;
}

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 == 28) {
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);
}
}

# We don't have overdue renewals here
sub waste_sub_overdue { 0 }

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

# 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->{slwp_garden_sacks} = 1;
$data->{bin_count} = 1;
$data->{new_bins} = 1;
my $cost_pa = $c->cobrand->garden_waste_sacks_cost_pa();
($cost_pa) = $c->cobrand->apply_garden_waste_discount($cost_pa) if $data->{apply_discount};
$c->set_param('payment', $cost_pa);
}
}

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} ? 28 : $existing || 26;
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';
}
}

=item * When a garden subscription is sent to Echo, we include payment details
=cut
Expand Down
17 changes: 14 additions & 3 deletions perllib/FixMyStreet/Roles/CobrandEcho.pm
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ sub bin_services_for_address {
my @rows = $self->waste_relevant_serviceunits($result);
foreach (@rows) {
my $schedules = $_->{Schedules};
if ($self->moniker ne 'sutton' && $self->moniker ne 'kingston') { # K&S don't use overdue
$_->{expired} = 1 if $self->waste_sub_overdue( $schedules->{end_date}, weeks => 4 );
}
$_->{expired} = 1 if $self->waste_sub_overdue( $schedules->{end_date}, weeks => 4 );

next unless $schedules->{next} or $schedules->{last};
$_->{active} = 1;
Expand Down Expand Up @@ -768,6 +766,12 @@ sub waste_get_next_dd_day {
return $next_day;
}

=head2 waste_sub_due
Returns true/false if now is less than garden_due_days before DATE.
=cut

sub waste_sub_due {
my ($self, $date) = @_;

Expand All @@ -778,6 +782,13 @@ sub waste_sub_due {
return $diff <= $self->garden_due_days;
}

=head2 waste_sub_overdue
Returns true/false if now is past DATE and (if provided)
less than COUNT INTERVAL after.
=cut

sub waste_sub_overdue {
my ($self, $date, $interval, $count) = @_;

Expand Down

0 comments on commit 702fec8

Please sign in to comment.