@@ -6,15 +6,102 @@ FixMyStreet::Cobrand::Bexley::Garden - code specific to Bexley WasteWorks GGW
6
6
7
7
package FixMyStreet::Cobrand::Bexley::Garden ;
8
8
9
+ use DateTime::Format::Strptime;
10
+ use Integrations::Agile;
11
+ use FixMyStreet::App::Form::Waste::Garden::Cancel::Bexley;
12
+
9
13
use Moo::Role;
10
14
with ' FixMyStreet::Roles::Cobrand::SCP' ,
11
15
' FixMyStreet::Roles::Cobrand::Paye' ;
12
16
17
+ has agile => (
18
+ is => ' lazy' ,
19
+ default => sub {
20
+ my $self = shift ;
21
+ my $cfg = $self -> feature(' agile' );
22
+ return Integrations::Agile-> new(%$cfg );
23
+ },
24
+ );
25
+
13
26
sub garden_service_name { ' garden waste collection service' }
14
27
15
- # TODO No current subscription look up here
16
- #
17
- sub garden_current_subscription { undef }
28
+ sub garden_service_ids {
29
+ return [ ' GA-140' , ' GA-240' ];
30
+ }
31
+
32
+ sub garden_current_subscription {
33
+ my $self = shift ;
34
+
35
+ my $current = $self -> {c }-> stash-> {property }{garden_current_subscription };
36
+ return $current if $current ;
37
+
38
+ my $uprn = $self -> {c }-> stash-> {property }{uprn };
39
+ return undef unless $uprn ;
40
+
41
+ # TODO Fetch active subscription from DB for UPRN
42
+ # (get_original_sub() in Controller/Waste.pm needs to handle Bexley UPRN).
43
+ # Could be more than one customer, so match against email.
44
+ # Could be more than one contract, so match against reference.
45
+
46
+ my $results = $self -> agile-> CustomerSearch($uprn );
47
+ return undef unless $results && $results -> {Customers };
48
+ my $customer = $results -> {Customers }[0];
49
+ return undef unless $customer && $customer -> {ServiceContracts };
50
+ my $contract = $customer -> {ServiceContracts }[0];
51
+ return unless $contract ;
52
+
53
+ my $parser
54
+ = DateTime::Format::Strptime-> new( pattern => ' %d/%m/%Y %H:%M' );
55
+ my $end_date = $parser -> parse_datetime( $contract -> {EndDate } );
56
+
57
+ # Agile says there is a subscription; now get service data from
58
+ # Whitespace
59
+ my $services = $self -> {c }-> stash-> {services };
60
+ for ( @{ $self -> garden_service_ids } ) {
61
+ if ( my $srv = $services -> {$_ } ) {
62
+ $srv -> {customer_external_ref }
63
+ = $customer -> {CustomerExternalReference };
64
+ $srv -> {end_date } = $end_date ;
65
+ return $srv ;
66
+ }
67
+ }
68
+
69
+ return {
70
+ agile_only => 1,
71
+ customer_external_ref => $customer -> {CustomerExternalReference },
72
+ end_date => $end_date ,
73
+ };
74
+ }
75
+
76
+ # TODO This is a placeholder
77
+ sub get_current_garden_bins { 1 }
78
+
79
+ sub waste_cancel_asks_staff_for_user_details { 1 }
80
+
81
+ sub waste_cancel_form_class {
82
+ ' FixMyStreet::App::Form::Waste::Garden::Cancel::Bexley' ;
83
+ }
84
+
85
+ sub waste_garden_sub_params {
86
+ my ( $self , $data , $type ) = @_ ;
87
+
88
+ my $c = $self -> {c };
89
+
90
+ if ( $data -> {category } eq ' Cancel Garden Subscription' ) {
91
+ my $srv = $self -> garden_current_subscription;
92
+
93
+ my $parser = DateTime::Format::Strptime-> new( pattern => ' %d/%m/%Y' );
94
+ my $due_date_str = $parser -> format_datetime( $srv -> {end_date } );
95
+
96
+ my $reason = $data -> {reason };
97
+ $reason .= ' : ' . $data -> {reason_further_details }
98
+ if $data -> {reason_further_details };
99
+
100
+ $c -> set_param( ' customer_external_ref' , $srv -> {customer_external_ref } );
101
+ $c -> set_param( ' due_date' , $due_date_str );
102
+ $c -> set_param( ' reason' , $reason );
103
+ }
104
+ }
18
105
19
106
=item * You can order a maximum of five bins
20
107
0 commit comments