diff --git a/perllib/WasteWorks/Costs.pm b/perllib/WasteWorks/Costs.pm index f5bd4fbf166..22988e48cc4 100644 --- a/perllib/WasteWorks/Costs.pm +++ b/perllib/WasteWorks/Costs.pm @@ -36,9 +36,10 @@ sub _build_has_pro_rata_modify { $_[0]->cobrand->moniker eq 'bromley' } sub bins { my ($self, $count) = @_; $count ||= 1; - my $cost = $self->get_cost('ggw_cost'); - $cost *= $count; - return $self->apply_garden_discount($cost); + my $per_bin = $self->get_cost('ggw_cost') ; + my $first_cost = $self->get_cost('ggw_cost_first') || $per_bin; + my $cost = $self->_first_diff_calc($first_cost, $per_bin, $count); + return $cost; } sub sacks { @@ -56,8 +57,11 @@ sub _renewal { $end_date //= $self->service->{end_date}; my $cost = $self->get_cost($prefix . '_renewal', $end_date) || $self->get_cost($prefix, $end_date); - $cost *= $count; - return $self->apply_garden_discount($cost); + my $first_cost = $self->get_cost($prefix . '_renewal_first', $end_date) + || $self->get_cost($prefix . '_first', $end_date) + || $cost; + $cost = $self->_first_diff_calc($first_cost, $cost, $count); + return $cost; } elsif ($type eq 'sacks') { return $self->sacks($count); } else { @@ -83,11 +87,17 @@ sub new_bin_admin_fee { $count ||= 0; my $per_new_bin_cost = $self->get_cost('ggw_new_bin_cost'); + my $cost = $self->_first_diff_calc($per_new_bin_first_cost, $per_new_bin_cost, $count); + return $cost; +} + +sub _first_diff_calc { + my ($self, $first_cost, $rest_cost, $count) = @_; my $cost = 0; if ($count > 0) { - $cost += $per_new_bin_first_cost; + $cost += $first_cost; if ($count > 1) { - $cost += $per_new_bin_cost * ($count - 1); + $cost += $rest_cost * ($count - 1); } } return $self->apply_garden_discount($cost); @@ -129,6 +139,9 @@ sub apply_garden_discount { return $discounted; } +# Next month does not currently handle a first bin being a different price, if +# those two ever get used together. + sub next_month { my $self = shift; my $per_bin = $self->get_cost('ggw_cost'); @@ -172,7 +185,16 @@ sub garden_cost_pa_in_one_month { # Functions used for display of bin pricing/calculation during flow (all begin per_) # $_[0] is the self instance, just without setting a variable -sub per_bin { $_[0]->bins(1) } +sub per_bin { + $_[0]->apply_garden_discount($_[0]->get_cost('ggw_cost')); +} +sub per_bin_first { + $_[0]->apply_garden_discount( + $_[0]->get_cost('ggw_cost_first') + || $_[0]->get_cost('ggw_cost') + ); +} + sub per_sack { $_[0]->sacks(1) } sub per_new_bin_first { @@ -182,7 +204,24 @@ sub per_new_bin { $_[0]->apply_garden_discount($_[0]->get_cost('ggw_new_bin_cost')); } -sub per_bin_renewal { $_[0]->bins_renewal(1) } +sub per_bin_renewal { + my $self = shift; + my $end_date; + $end_date = $self->service->{end_date} if $self->renewal_type eq 'subscription_end'; + my $cost = $self->get_cost('ggw_cost_renewal', $end_date) + || $self->get_cost('ggw_cost', $end_date); + return $self->apply_garden_discount($cost); +} +sub per_bin_renewal_first { + my $self = shift; + my $end_date; + $end_date = $self->service->{end_date} if $self->renewal_type eq 'subscription_end'; + my $first_cost = $self->get_cost('ggw_cost_renewal_first', $end_date) + || $self->get_cost('ggw_cost_first', $end_date); + return $self->per_bin_renewal unless $first_cost; + return $self->apply_garden_discount($first_cost); +} + sub per_sack_renewal { $_[0]->sacks_renewal(1) } sub per_pro_rata_bin { $_[0]->pro_rata_cost(1) } diff --git a/t/wasteworks/costs.t b/t/wasteworks/costs.t index 464c296746f..dd8b9bd8f5c 100644 --- a/t/wasteworks/costs.t +++ b/t/wasteworks/costs.t @@ -7,6 +7,7 @@ my $brent = FixMyStreet::Cobrand::Brent->new; # Discount my $kingston = FixMyStreet::Cobrand::Kingston->new; # Renews with end date, admin fee my $sutton = FixMyStreet::Cobrand::Sutton->new; # Next month my $merton = FixMyStreet::Cobrand::Merton->new; +my $bexley = FixMyStreet::Cobrand::Bexley->new; set_fixed_time("2025-01-14T12:00:00Z"); @@ -29,6 +30,7 @@ FixMyStreet::override_config { { start_date => '2025-01-01 00:00', cost => 1500 }, { start_date => '2025-02-01 00:00', cost => 1700 }, ] }, + bexley => { ggw_cost_first => 7500, ggw_cost => 5500 }, }, waste_features => { brent => { ggw_discount_as_percent => 20 }, @@ -51,6 +53,12 @@ FixMyStreet::override_config { is $costs->pro_rata_cost(3), 7200; }; + subtest 'first bin a different price' => sub { + my $costs = WasteWorks::Costs->new({ cobrand => $bexley }); + is $costs->bins, 7500; + is $costs->bins(2), 7500+5500; + }; + subtest 'sacks' => sub { my $costs = WasteWorks::Costs->new({ cobrand => $merton }); is $costs->sacks(1), 750; diff --git a/templates/web/base/waste/garden/modify.html b/templates/web/base/waste/garden/modify.html index c341f17d0f0..6905c662db8 100644 --- a/templates/web/base/waste/garden/modify.html +++ b/templates/web/base/waste/garden/modify.html @@ -13,6 +13,7 @@
diff --git a/templates/web/base/waste/garden/subscribe_details.html b/templates/web/base/waste/garden/subscribe_details.html index d910b87a237..9398e388c27 100644 --- a/templates/web/base/waste/garden/subscribe_details.html +++ b/templates/web/base/waste/garden/subscribe_details.html @@ -12,6 +12,7 @@
diff --git a/web/js/waste.js b/web/js/waste.js index b9e4d8838b4..91b063b1643 100644 --- a/web/js/waste.js +++ b/web/js/waste.js @@ -13,6 +13,7 @@ $(function() { var costs = $('.js-bin-costs'), cost = costs.data('per_bin_cost') / 100, + first_cost = costs.data('per_bin_first_cost') / 100, per_new_bin_first_cost = costs.data('per_new_bin_first_cost') / 100, per_new_bin_cost = costs.data('per_new_bin_cost') / 100, pro_rata_bin_cost = costs.data('pro_rata_bin_cost') / 100; @@ -20,7 +21,7 @@ $(function() { var total_bins = parseInt($('#bins_wanted').val() || 0); var existing_bins = parseInt($('#current_bins').val() || 0); var new_bins = total_bins - existing_bins; - var total_per_year = total_bins * cost; + var total_per_year = (total_bins-1) * cost + first_cost; var admin_fee = 0; if (new_bins > 0 && per_new_bin_first_cost) { admin_fee += per_new_bin_first_cost; @@ -42,7 +43,7 @@ $(function() { var existing_bins = parseInt($('#current_bins').val() || 0); var new_bins = total_bins - existing_bins; var pro_rata_cost = 0; - var total_per_year = total_bins * cost; + var total_per_year = (total_bins-1) * cost + first_cost; var admin_fee = 0; var new_bin_text = new_bins == 1 ? 'bin' : 'bins'; $('#new_bin_text').text(new_bin_text);