Skip to content

Commit

Permalink
[Merton] Initial code for bulky waste.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Apr 24, 2024
1 parent 4a35910 commit ee495cf
Show file tree
Hide file tree
Showing 10 changed files with 1,015 additions and 208 deletions.
8 changes: 0 additions & 8 deletions perllib/FixMyStreet/Cobrand/Brent.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1550,14 +1550,6 @@ sub collection_date {

sub _bulky_refund_cutoff_date { }

sub _bulky_date_to_dt {
my ($self, $date) = @_;
$date = (split(";", $date))[0];
my $parser = DateTime::Format::Strptime->new( pattern => '%FT%T', time_zone => FixMyStreet->local_time_zone);
my $dt = $parser->parse_datetime($date);
return $dt ? $dt->truncate( to => 'day' ) : undef;
}

sub waste_munge_bulky_data {
my ($self, $data) = @_;

Expand Down
8 changes: 0 additions & 8 deletions perllib/FixMyStreet/Cobrand/Bromley.pm
Original file line number Diff line number Diff line change
Expand Up @@ -943,14 +943,6 @@ sub collection_date {

sub _bulky_refund_cutoff_date { }

sub _bulky_date_to_dt {
my ($self, $date) = @_;
$date = (split(";", $date))[0];
my $parser = DateTime::Format::Strptime->new( pattern => '%FT%T', time_zone => FixMyStreet->local_time_zone);
my $dt = $parser->parse_datetime($date);
return $dt ? $dt->truncate( to => 'day' ) : undef;
}

sub waste_munge_bulky_data {
my ($self, $data) = @_;

Expand Down
34 changes: 33 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';

Check warning on line 17 in perllib/FixMyStreet/Cobrand/Merton/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Merton/Waste.pm#L17

Added line #L17 was not covered by tests
}

sub waste_auto_confirm_report { 1 }

sub service_name_override {
Expand Down Expand Up @@ -113,7 +123,6 @@ sub _closed_event {

# TODO
sub garden_container_data_extract { }
sub waste_bulky_missed_blocked_codes {}

sub waste_quantity_max {
return (
Expand All @@ -132,4 +141,27 @@ 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;
}

=head2 Bulky waste collection
Merton has a 6am collection and cut-off for cancellation time.
Everything else is configured in SLWPEcho.pm
=cut

sub bulky_collection_time { { hours => 6, minutes => 0 } }
sub bulky_cancellation_cutoff_time { { hours => 6, minutes => 0, days_before => 0 } }

1;
184 changes: 0 additions & 184 deletions perllib/FixMyStreet/Roles/Cobrand/KingstonSutton.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ package FixMyStreet::Roles::Cobrand::KingstonSutton;

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

use FixMyStreet::App::Form::Waste::Garden::Sacks;
use FixMyStreet::App::Form::Waste::Garden::Sacks::Renew;
Expand Down Expand Up @@ -210,29 +209,6 @@ sub waste_quantity_max {
);
}

sub waste_bulky_missed_blocked_codes {
return {
# Partially completed
12399 => {
507 => 'Not all items presented',
380 => 'Some items too heavy',
},
# Completed
12400 => {
606 => 'More items presented than booked',
},
# Not Completed
12401 => {
460 => 'Nothing out',
379 => 'Item not as described',
100 => 'No access',
212 => 'Too heavy',
473 => 'Damage on site',
234 => 'Hazardous waste',
},
};
}

sub waste_munge_bin_services_open_requests {
my ($self, $open_requests) = @_;
if ($self->moniker eq 'sutton') {
Expand Down Expand Up @@ -584,164 +560,4 @@ sub dashboard_export_problems_add_columns {
});
}

=head2 Bulky waste collection
SLWP looks 8 weeks ahead for collection dates, and cancels by sending an
update, not a new report. It sends the event to the backend before collecting
payment, and does not refund on cancellations. It has a hard-coded list of
property types allowed to book collections.
=cut

sub bulky_collection_window_days { 56 }

sub bulky_cancel_by_update { 1 }
sub bulky_send_before_payment { 1 }
sub bulky_show_location_field_mandatory { 1 }

sub bulky_can_refund { 0 }
sub _bulky_refund_cutoff_date { }

=head2 bulky_collection_window_start_date
K&S have an 11pm cut-off for looking to book next day collections.
=cut

sub bulky_collection_window_start_date {
my $self = shift;
my $now = DateTime->now( time_zone => FixMyStreet->local_time_zone );
my $start_date = $now->clone->truncate( to => 'day' )->add( days => 1 );
# If past 11pm, push start date one day later
if ($now->hour >= 23) {
$start_date->add( days => 1 );
}
return $start_date;
}

sub bulky_allowed_property {
my ( $self, $property ) = @_;

return if $property->{has_no_services};
my $cfg = $self->feature('echo');

my $type = $property->{type_id} || 0;
my $valid_type = grep { $_ == $type } @{ $cfg->{bulky_address_types} || [] };
my $domestic_farm = $type != 7 || $property->{domestic_refuse_bin};
return $self->bulky_enabled && $valid_type && $domestic_farm;
}

sub collection_date {
my ($self, $p) = @_;
return $self->_bulky_date_to_dt($p->get_extra_field_value('Collection_Date'));
}

sub bulky_free_collection_available { 0 }

sub bulky_hide_later_dates { 1 }

sub _bulky_date_to_dt {
my ($self, $date) = @_;
$date = (split(";", $date))[0];
my $parser = DateTime::Format::Strptime->new( pattern => '%FT%T', time_zone => FixMyStreet->local_time_zone);
my $dt = $parser->parse_datetime($date);
return $dt ? $dt->truncate( to => 'day' ) : undef;
}

=head2 Sending to Echo
We use the reserved slot GUID and reference,
and the provided date/location information.
Items are sent through with their notes as individual entries
=cut

sub waste_munge_bulky_data {
my ($self, $data) = @_;

my $c = $self->{c};
my ($date, $ref, $expiry) = split(";", $data->{chosen_date});

my $guid_key = $self->council_url . ":echo:bulky_event_guid:" . $c->stash->{property}->{id};
$data->{extra_GUID} = $self->{c}->session->{$guid_key};
$data->{extra_reservation} = $ref;

$data->{title} = "Bulky goods collection";
$data->{detail} = "Address: " . $c->stash->{property}->{address};
$data->{category} = "Bulky collection";
$data->{extra_Collection_Date} = $date;
$data->{extra_Exact_Location} = $data->{location};

my $first_date = $self->{c}->session->{first_date_returned};
$first_date = DateTime::Format::W3CDTF->parse_datetime($first_date);
my $dt = DateTime::Format::W3CDTF->parse_datetime($date);
$data->{'extra_First_Date_Returned_to_Customer'} = $first_date->strftime("%d/%m/%Y");
$data->{'extra_Customer_Selected_Date_Beyond_SLA?'} = $dt > $first_date ? 1 : 0;

my @items_list = @{ $self->bulky_items_master_list };
my %items = map { $_->{name} => $_->{bartec_id} } @items_list;

my @notes;
my @ids;
my @photos;

my $max = $self->bulky_items_maximum;
for (1..$max) {
if (my $item = $data->{"item_$_"}) {
push @notes, $data->{"item_notes_$_"} || '';
push @ids, $items{$item};
push @photos, $data->{"item_photos_$_"} || '';
};
}
$data->{extra_Bulky_Collection_Notes} = join("::", @notes);
$data->{extra_Bulky_Collection_Bulky_Items} = join("::", @ids);
$data->{extra_Image} = join("::", @photos);
$self->bulky_total_cost($data);
}

sub waste_reconstruct_bulky_data {
my ($self, $p) = @_;

my $saved_data = {
"chosen_date" => $p->get_extra_field_value('Collection_Date'),
"location" => $p->get_extra_field_value('Exact_Location'),
"location_photo" => $p->get_extra_metadata("location_photo"),
};

my @fields = split /::/, $p->get_extra_field_value('Bulky_Collection_Bulky_Items');
my @notes = split /::/, $p->get_extra_field_value('Bulky_Collection_Notes');
for my $id (1..@fields) {
$saved_data->{"item_$id"} = $p->get_extra_metadata("item_$id");
$saved_data->{"item_notes_$id"} = $notes[$id-1];
$saved_data->{"item_photo_$id"} = $p->get_extra_metadata("item_photo_$id");
}

$saved_data->{name} = $p->name;
$saved_data->{email} = $p->user->email;
$saved_data->{phone} = $p->phone_waste;

return $saved_data;
}

=head2 suppress_report_sent_email
For Bulky Waste reports, we want to send the email after payment has been confirmed, so we
suppress the email here.
=cut

sub suppress_report_sent_email {
my ($self, $report) = @_;

if ($report->cobrand_data eq 'waste' && $report->category eq 'Bulky collection') {
return 1;
}

return 0;
}

sub bulky_location_photo_prompt {
'Help us by attaching a photo of where the items will be left for collection.';
}

1;

0 comments on commit ee495cf

Please sign in to comment.