Skip to content

Commit

Permalink
[Waste] [Bromley] Enable a minimum cost for bulky per-item charging.
Browse files Browse the repository at this point in the history
  • Loading branch information
neprune committed Oct 9, 2023
1 parent 82feff7 commit 3cc1b12
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 33 deletions.
3 changes: 2 additions & 1 deletion perllib/FixMyStreet/App/Controller/Admin/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ sub edit : Chained('body') : PathPart('') : Args(0) {
$new_cfg = $c->stash->{body}->get_extra_metadata("wasteworks_config", {});
my %keys = (
per_item_costs => 'bool',
per_item_min_collection_price => 'int',
base_price => 'int',
daily_slots => 'int',
items_per_collection_max => 'int',
Expand Down Expand Up @@ -224,7 +225,7 @@ sub stash_body_config_json : Private {
} else {
$c->stash->{body_config_json} = JSON->new->utf8(1)->pretty->canonical->encode($cfg);
}
foreach (qw(free_mode per_item_costs base_price daily_slots items_per_collection_max food_bags_disabled show_location_page band1_price band1_max)) {
foreach (qw(free_mode per_item_costs per_item_min_collection_price base_price daily_slots items_per_collection_max food_bags_disabled show_location_page band1_price band1_max)) {
$c->stash->{$_} = $c->get_param($_) || $cfg->{$_};
}
}
Expand Down
6 changes: 1 addition & 5 deletions perllib/FixMyStreet/Cobrand/Bromley.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1008,11 +1008,7 @@ sub bulky_free_collection_available { 0 }
sub bulky_hide_later_dates { 1 }
sub bulky_send_before_payment { 1 }

# TODO: Enforce the minumum charge.
sub bulky_minimum_charge {
my $self = shift;
$self->feature('waste_features')->{bulky_minimum_charge};
}
sub bulky_minimum_charge { $_[0]->wasteworks_config->{per_item_min_collection_price} }

sub bulky_can_refund_collection {
my ($self, $collection) = @_;
Expand Down
17 changes: 14 additions & 3 deletions perllib/FixMyStreet/Roles/CobrandBulkyWaste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ sub bulky_pricing_strategy {
my $band1_max = $self->wasteworks_config->{band1_max};
my $max = $self->bulky_items_maximum;
if ($self->bulky_per_item_costs) {
return encode_json({ strategy => 'per_item' });
my $min_collection_price = $self->wasteworks_config->{per_item_min_collection_price} || 0;
return encode_json({ strategy => 'per_item', min => $min_collection_price });
} elsif (my $band1_price = $self->wasteworks_config->{band1_price}) {
return encode_json({ strategy => 'banded', bands => [ { max => $band1_max, price => $band1_price }, { max => $max, price => $base_price } ] });
} else {
Expand Down Expand Up @@ -146,8 +147,13 @@ sub bulky_minimum_cost {
# Get the item with the lowest cost
my @sorted = sort { $a <=> $b }
map { $_->{$price_key} } @{ $self->bulky_items_master_list };
my $min_item_price = $sorted[0] // 0;
my $min_collection_price = $cfg->{per_item_min_collection_price};
if ($min_collection_price && $min_collection_price > $min_item_price) {
return $min_collection_price;
}
return $min_item_price;

return $sorted[0] // 0;
} elsif ( $cfg->{band1_price} ) {
return $cfg->{band1_price};
} else {
Expand Down Expand Up @@ -175,7 +181,12 @@ sub bulky_total_cost {
my $item = $data->{"item_$_"} or next;
$total += $prices{$item};
}
$c->stash->{payment} = $total;
my $min_collection_price = $cfg->{per_item_min_collection_price};
if ($min_collection_price && $min_collection_price > $total) {
$c->stash->{payment} = $min_collection_price;
} else {
$c->stash->{payment} = $total;
}
} elsif ($cfg->{band1_price}) {
my $count = 0;
my $max = $self->bulky_items_maximum;
Expand Down
55 changes: 32 additions & 23 deletions t/app/controller/waste_bromley_bulky.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ END { FixMyStreet::App->log->enable('info'); }
my $mech = FixMyStreet::TestMech->new;
my $sample_file = path(__FILE__)->parent->child("sample.jpg");
my $sample_file_2 = path(__FILE__)->parent->child("sample2.jpg");
my $minimum_charge = 3600;
my $minimum_charge = 500;

my $user = $mech->create_user_ok('[email protected]');

Expand All @@ -20,6 +20,7 @@ my $body = $mech->create_body_ok( 2482, 'Bromley Council',
$body->set_extra_metadata(
wasteworks_config => {
per_item_costs => 1,
per_item_min_collection_price => $minimum_charge,
items_per_collection_max => 8,
show_location_page => 'users',
item_list => [
Expand Down Expand Up @@ -91,7 +92,6 @@ FixMyStreet::override_config {
waste => { bromley => 1 },
waste_features => {
bromley => {
bulky_minimum_charge => $minimum_charge,
bulky_trade_service_id => 532,
bulky_enabled => 1,
bulky_tandc_link => 'tandc_link',
Expand Down Expand Up @@ -456,7 +456,7 @@ FixMyStreet::override_config {
$mech->get_ok('/waste/12345/bulky/cancel/' . $report->id);
$mech->content_contains(
'Cancellations within 24 hours of collection are only eligibile to ' .
'be refunded the amount paid above the minimum charge £36.00.'
'be refunded the amount paid above the minimum charge £5.00.'
);
$mech->content_contains('If you cancel you will be refunded £0.01.');
};
Expand All @@ -478,7 +478,7 @@ FixMyStreet::override_config {
my $text = $email->as_string;

# =C2=A3 is the quoted printable for '£'.
like $text, qr/Payment Amount: =C2=A336.01/, "Correct payment amount";
like $text, qr/Payment Amount: =C2=A35.01/, "Correct payment amount";
like $text, qr/Capita SCP Response: 12345/,
'Correct SCP response';
# XXX Not picking up on mocked time
Expand All @@ -495,31 +495,40 @@ FixMyStreet::override_config {
$report->comments->delete;
$report->delete;

subtest 'Different pricing depending on domestic or trade property' => sub {
sub test_prices {
my ($minimum_cost, $total_cost) = @_;
$mech->get_ok('/waste/12345');
$mech->content_contains('From ' . $minimum_cost);
$mech->get_ok('/waste/12345/bulky');
$mech->submit_form_ok; # Intro page.
$mech->submit_form_ok({ with_fields => { name => 'Bob Marge', email => $user->email }});
$mech->submit_form_ok(
{ with_fields => { chosen_date => '2023-07-01T00:00:00;reserve1==;2023-06-25T10:10:00' } }
);
$mech->submit_form_ok(
{ with_fields => {
'item_1' => 'BBQ',
},
sub test_prices {
my ($minimum_cost, $total_cost) = @_;
$mech->get_ok('/waste/12345');
$mech->content_contains('From ' . $minimum_cost);
$mech->get_ok('/waste/12345/bulky');
$mech->submit_form_ok; # Intro page.
$mech->submit_form_ok({ with_fields => { name => 'Bob Marge', email => $user->email }});
$mech->submit_form_ok(
{ with_fields => { chosen_date => '2023-07-01T00:00:00;reserve1==;2023-06-25T10:10:00' } }
);
$mech->submit_form_ok(
{ with_fields => {
'item_1' => 'BBQ',
},
);
$mech->submit_form_ok({ with_fields => { location => 'in the middle of the drive' } });
$mech->content_contains($total_cost); # Summary page.
}
},
);
$mech->submit_form_ok({ with_fields => { location => 'in the middle of the drive' } });
$mech->content_contains($total_cost); # Summary page.
}

subtest 'Different pricing depending on domestic or trade property' => sub {
$echo->mock('GetServiceUnitsForObject', \&trade_waste_service_units );
test_prices('£20.00', '£20.00');
$echo->mock('GetServiceUnitsForObject', \&domestic_waste_service_units );
test_prices('£10.00', '£10.00');
};

subtest 'Minimum charged enforced' => sub {
my $cfg = $body->get_extra_metadata('wasteworks_config');
$cfg->{per_item_min_collection_price} = 5000;
$body->set_extra_metadata(wasteworks_config => $cfg);
$body->update;
test_prices('£50.00', '£50.00');
};
};

done_testing;
Expand Down
2 changes: 1 addition & 1 deletion t/app/controller/waste_peterborough.t
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ FixMyStreet::override_config {
daily_slots => 50,
free_mode => 0, # not checked
food_bags_disabled => 0, # not checked
base_price => 1234, per_item_costs => 1, items_per_collection_max => 7 };
base_price => 1234, per_item_costs => 1, per_item_min_collection_price => '', items_per_collection_max => 7 };
};
};
};
Expand Down
6 changes: 6 additions & 0 deletions templates/web/base/admin/waste/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ <h3>Bulky Collections</h3>
[% 'checked' IF per_item_costs %]>
<label class="inline" for="waste_per_item_costs">Charge per item, not per collection</label>

<div>
<label for="waste_per_item_min_collection_price">Minimum price for a per-item charged collection (in <strong>pence</strong>)</label>
<input class="form-control" type=text name="per_item_min_collection_price" id="waste_per_item_min_collection_price"
value="[% per_item_min_collection_price %]">
</div>

<p>
<label for="show_location_page">[% loc('Show location information page') %]</label>
<select class="form-control" name="show_location_page" id="waste_show_location_page">
Expand Down
3 changes: 3 additions & 0 deletions templates/web/base/waste/bulky/items.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
<p>
Total cost: £<span data-pricing="[% c.cobrand.bulky_pricing_strategy %]" id="js-bulky-total">[% pounds(total) %]</span>
</p>
<p>
<span hidden id="js-bulky-total-detail"></span>
</p>

[% PROCESS form override_fields = [ 'continue', 'saved_data', 'token', 'process', 'unique_id' ] %]
</form>
Expand Down
16 changes: 16 additions & 0 deletions web/js/waste.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ $(function() {

function updateTotal() {
var totalId = $('#js-bulky-total');
var totalDetailId = $('#js-bulky-total-detail');
var pricing = totalId.data('pricing');
// Update total
var total = 0;
Expand All @@ -98,7 +99,21 @@ $(function() {
total += price;
}
});
if (pricing.min) {
if (total < pricing.min) {
var itemTotal = total;
total = pricing.min;
totalDetailId.text(
'You will be charged £' + (pricing.min / 100).toFixed(2) + ' as this is the minimum charge ' +
'and your selected items add up to £' + (itemTotal / 100).toFixed(2) + '. '
);
totalDetailId.show();
} else {
totalDetailId.hide();
}
}
totalId.text((total / 100).toFixed(2));

} else if (pricing.strategy === 'banded') {
var count = 0;
$('.govuk-select[name^="item_"] option:selected').each(function(i, e) {
Expand All @@ -115,6 +130,7 @@ $(function() {
totalId.text((total / 100).toFixed(2));
}
}
updateTotal();

$('.govuk-select[name^="item_"]').change(function(e) {
var $this = $(this);
Expand Down

0 comments on commit 3cc1b12

Please sign in to comment.