Skip to content

Commit

Permalink
[Waste] Add separate first garden bin cost.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Jan 13, 2025
1 parent d4eeb60 commit d6cf430
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 12 deletions.
56 changes: 46 additions & 10 deletions perllib/WasteWorks/Costs.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ sub _build_has_pro_rata_modify { $_[0]->cobrand->moniker eq 'bromley' }
sub bins {
my ($self, $count) = @_;
$count ||= 1;
my $cost = $self->cobrand->_get_cost('ggw_cost');
$cost *= $count;
return $self->apply_garden_waste_discount($cost);
my $per_bin = $self->cobrand->_get_cost('ggw_cost') ;
my $first_cost = $self->cobrand->_get_cost('ggw_cost_first') || $per_bin;
my $cost = $self->_first_diff_calc($first_cost, $per_bin, $count);
return $cost;
}

sub sacks {
Expand All @@ -40,8 +41,11 @@ sub _renewal {
if ($self->renewal_type eq 'subscription_end') {
my $cost = $self->cobrand->_get_cost($prefix . '_renewal', $end_date)
|| $self->cobrand->_get_cost($prefix, $end_date);
$cost *= $count;
return $self->apply_garden_waste_discount($cost);
my $first_cost = $self->cobrand->_get_cost($prefix . '_renewal_first', $end_date)
|| $self->cobrand->_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 {
Expand All @@ -60,11 +64,17 @@ sub new_bin_admin_fee {

$count ||= 0;
my $per_new_bin_cost = $self->cobrand->_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_waste_discount($cost);
Expand Down Expand Up @@ -148,17 +158,43 @@ sub garden_waste_cost_pa_in_one_month {

# Functions used for display of bin pricing/calculation during flow (all begin per_)

sub per_bin { $_[0]->bins(1) }
sub per_bin {
$_[0]->apply_garden_waste_discount($_[0]->cobrand->_get_cost('ggw_cost'));
}
sub per_bin_first {
$_[0]->apply_garden_waste_discount(
$_[0]->cobrand->_get_cost('ggw_cost_first')
|| $_[0]->cobrand->_get_cost('ggw_cost')
);
}

sub per_sack { $_[0]->sacks(1) }

sub per_new_bin_first {
$_[0]->apply_garden_waste_discount($_[0]->cobrand->_get_cost('ggw_new_bin_first_cost') || $_[0]->per_new_bin);
$_[0]->apply_garden_waste_discount($_[0]->cobrand->_get_cost('ggw_new_bin_first_cost'));
}
sub per_new_bin {
$_[0]->apply_garden_waste_discount($_[0]->cobrand->_get_cost('ggw_new_bin_cost'));
}

sub per_bin_renewal { $_[0]->bins_renewal(1, $_[0]->service->{end_date}) }
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->cobrand->_get_cost('ggw_cost_renewal', $end_date)
|| $self->cobrand->_get_cost('ggw_cost', $end_date);
return $self->apply_garden_waste_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->cobrand->_get_cost('ggw_cost_renewal_first', $end_date)
|| $self->cobrand->_get_cost('ggw_cost_first', $end_date);
return $self->per_bin_renewal unless $first_cost;
return $self->apply_garden_waste_discount($first_cost);

Check warning on line 195 in perllib/WasteWorks/Costs.pm

View check run for this annotation

Codecov / codecov/patch

perllib/WasteWorks/Costs.pm#L195

Added line #L195 was not covered by tests
}

sub per_sack_renewal { $_[0]->sacks_renewal(1, $_[0]->service->{end_date}) }
sub per_pro_rata_bin { $_[0]->pro_rata_cost(1, $_[0]->service->{end_date}) }

Expand Down
1 change: 1 addition & 0 deletions templates/web/base/waste/garden/modify.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<hr class="fieldset-hr">
<div class="cost-pa__total js-bin-costs"
data-per_bin_cost="[% garden_costs.per_bin %]"
data-per_bin_first_cost="[% garden_costs.per_bin_first %]"
data-per_new_bin_first_cost="[% garden_costs.per_new_bin_first %]"
data-per_new_bin_cost="[% garden_costs.per_new_bin %]"
data-pro_rata_bin_cost="[% garden_costs.per_pro_rata_bin %]"
Expand Down
1 change: 1 addition & 0 deletions templates/web/base/waste/garden/renew.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<hr class="fieldset-hr">
<div class="cost-pa__total js-bin-costs"
data-per_bin_cost="[% garden_costs.per_bin_renewal %]"
data-per_bin_first_cost="[% garden_costs.per_bin_renewal_first %]"
data-per_new_bin_first_cost="[% garden_costs.per_new_bin_first %]"
data-per_new_bin_cost="[% garden_costs.per_new_bin %]"
>
Expand Down
1 change: 1 addition & 0 deletions templates/web/base/waste/garden/subscribe_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<div class="cost-pa__total js-bin-costs"
data-per_bin_cost="[% garden_costs.per_bin %]"
data-per_bin_first_cost="[% garden_costs.per_bin_first %]"
data-per_new_bin_first_cost="[% garden_costs.per_new_bin_first %]"
data-per_new_bin_cost="[% garden_costs.per_new_bin %]"
>
Expand Down
5 changes: 3 additions & 2 deletions web/js/waste.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ $(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;
function bin_cost_new() {
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;
Expand All @@ -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);
Expand Down

0 comments on commit d6cf430

Please sign in to comment.