-
-
Notifications
You must be signed in to change notification settings - Fork 280
Expand file tree
/
Copy pathBrent.pm
More file actions
207 lines (182 loc) · 7.03 KB
/
Copy pathBrent.pm
File metadata and controls
207 lines (182 loc) · 7.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package FixMyStreet::App::Form::Waste::Request::Brent;
use utf8;
use HTML::FormHandler::Moose;
extends 'FixMyStreet::App::Form::Waste::Request';
use Readonly;
Readonly::Scalar my $CONTAINER_GREY_BIN => 16;
Readonly::Scalar my $CONTAINER_BLUE_BIN => 6;
Readonly::Scalar my $CONTAINER_CLEAR_SACK => 8;
Readonly::Scalar my $CONTAINER_FOOD_CADDY => 11;
Readonly::Scalar my $CONTAINER_GREEN_BIN => 13;
Readonly::Scalar my $CONTAINER_BLUE_SACK => 46;
my %new_build_ordered_months = (
$CONTAINER_FOOD_CADDY => 2,
$CONTAINER_BLUE_BIN => 6,
$CONTAINER_BLUE_SACK => 2,
);
my %ordered_months = (
$CONTAINER_GREEN_BIN => 6,
$CONTAINER_FOOD_CADDY => 3,
$CONTAINER_BLUE_BIN => 6,
$CONTAINER_BLUE_SACK => 3,
);
my %refusal_contamination_months = (
$CONTAINER_FOOD_CADDY => 3,
$CONTAINER_BLUE_BIN => 3,
$CONTAINER_BLUE_SACK => 3,
);
has_page about_you => (
fields => ['name', 'email', 'phone', 'continue'],
title => 'About you',
# Look up any cost here, once we have all the data from previous steps
update_field_list => sub {
my $form = shift;
my $data = $form->saved_data;
my $c = $form->{c};
my $choice = $data->{"container-choice"};
my $how_long = $data->{how_long_lived} || '';
my $ordered = $data->{ordered_previously};
# We only ask for immediate payment if it's not a referral
if (!FixMyStreet::Cobrand::Brent::request_referral($choice, $data)) {
my ($cost) = $c->cobrand->request_cost($choice);
$data->{payment} = $cost if $cost;
}
return {};
},
next => 'summary',
);
has_page request_extra_refusal => (
fields => [],
template => 'waste/refuse_extra_container.html',
);
has_page replacement => (
fields => ['request_reason', 'continue'],
title => 'Reason for request',
next => sub {
my $data = shift;
my $choice = $data->{"container-choice"};
my $reason = $data->{request_reason};
if ($choice == $CONTAINER_GREY_BIN && $reason eq 'extra') {
return 'request_extra_refusal' if $data->{refuse_outcome};
return 'request_refuse_container';
}
return 'about_you' if $choice == $CONTAINER_CLEAR_SACK;
return 'how_long_lived' if $reason eq 'new_build';
return 'request_extra_refusal' if $reason eq 'extra' && $data->{ordered_previously};
# return 'request_extra_refusal' if $reason eq 'extra' && $data->{contamination_reports} >= 3;
return 'about_you';
},
);
has_field request_reason => (
required => 1,
type => 'Select',
widget => 'RadioGroup',
build_label_method => sub {
my $self = shift;
my $choice = $self->parent->saved_data->{'container-choice'};
return 'Why do you need more sacks?' if $choice == $CONTAINER_CLEAR_SACK;
return 'Why do you need a replacement container?';
},
validate_method => sub {
my $self = shift;
my $c = $self->form->c;
return if $self->has_errors;
my $value = $self->value;
my $saved_data = $self->form->saved_data;
my $echo = $c->cobrand->feature('echo');
$echo = Integrations::Echo->new(%$echo);
my $choice = $saved_data->{'container-choice'};
my $months = $value eq 'new_build' ? $new_build_ordered_months{$choice} : $ordered_months{$choice};
return unless $months;
my $events = $echo->GetEventsForObject(PointAddress => $c->stash->{property}{id}, 2936, $months);
$events = $c->cobrand->_parse_events($events, { include_closed_requests => 1 });
$saved_data->{ordered_previously} = $events->filter({ containers => [$choice] }) ? 1 : 0;
if ($value eq 'extra' || $value eq 'missing') {
my $services = $c->stash->{service_data};
my @tasks;
foreach (@$services) {
my $container = $_->{request_containers}->[0];
push @tasks, $_->{service_task_id} if $container == $choice;
}
# The below is not currently in use, FD-3672
# my $months = $refusal_contamination_months{$choice};
# my $end = DateTime->now->set_time_zone(FixMyStreet->local_time_zone)->truncate( to => 'day' );
# my $start = $end->clone->add(months => -$months);
# my $result = $echo->GetServiceTaskInstances($start, $end, @tasks);
# my $num = 0;
# foreach (@$result) {
# my $task_id = $_->{ServiceTaskRef}{Value}{anyType};
# my $tasks = Integrations::Echo::force_arrayref($_->{Instances}, 'ScheduledTaskInfo');
# foreach (@$tasks) {
# $num++ if ($_->{Resolution}||0) == 1148;
# }
# }
# $saved_data->{contamination_reports} = $num;
}
},
);
sub options_request_reason {
my $form = shift;
my $data = $form->saved_data;
my $choice = $data->{'container-choice'} || 0;
my @options;
if ($choice == $CONTAINER_CLEAR_SACK) {
push @options, { value => 'new_build', label => 'I am a new resident without any' };
push @options, { value => 'extra', label => 'I have used all the sacks provided' };
} elsif ($choice == $CONTAINER_GREEN_BIN) {
push @options, { value => 'damaged', label => 'My container is damaged' };
push @options, { value => 'missing', label => 'My container is missing' };
} else {
push @options, { value => 'new_build', label => 'I am a new resident without a container' } unless $choice == $CONTAINER_GREY_BIN;
push @options, { value => 'damaged', label => 'My container is damaged' };
push @options, { value => 'missing', label => 'My container is missing' };
push @options, { value => 'extra', label => 'I would like an extra container' };
}
return @options;
}
has_page how_long_lived => (
fields => ['how_long_lived', 'continue'],
title => 'Reason for request',
next => 'about_you',
);
has_field how_long_lived => (
required => 1,
type => 'Select',
widget => 'RadioGroup',
label => 'How long have you lived at this address?',
options => [
{ value => 'less3', label => 'Less than 3 months' },
{ value => '3more', label => '3 months or more' },
],
);
has_page request_refuse_container => (
title => 'Household details',
intro => 'refuse_call_us.html',
fields => [ 'property_people', 'property_children', 'continue'],
next => 'about_you',
);
has_field property_people =>(
required => 1,
type => 'Select',
label => 'How many people live at your property?',
options => [
{ value => '1', label => 'Up to 5' },
{ value => '6', label => '6 or more' }
],
);
has_field property_children =>(
required => 1,
type => 'Select',
label => 'Do any children live at the property?',
options => [
{ value => 'No', label => 'No' },
{ value => 'Yes', label => 'Yes' }
],
);
has_field submit => (
type => 'Submit',
value => 'Request container',
element_attr => { class => 'govuk-button' },
order => 999,
);
1;