Skip to content

Commit

Permalink
[Bexley] Only show active GGW subs from Agile
Browse files Browse the repository at this point in the history
  • Loading branch information
davea committed Feb 21, 2025
1 parent 49544b0 commit 07c25ad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 19 additions & 5 deletions perllib/FixMyStreet/Cobrand/Bexley/Garden.pm
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,26 @@ sub lookup_subscription_for_uprn {
};


my ( $customer, $contract );

my $results = $self->agile->CustomerSearch($uprn);
return undef unless $results && $results->{Customers};
my $customer = $results->{Customers}[0];
return undef unless $customer && $customer->{ServiceContracts};
my $contract = $customer->{ServiceContracts}[0];
return unless $contract;

# find the first 'ACTIVATED' Customer with an 'ACTIVE'/'PRECONTRACT' contract
my $customers = $results->{Customers} || [];
OUTER: for ( @$customers ) {
next unless $_->{CustomertStatus} eq 'ACTIVATED'; # CustomertStatus (sic) options seem to be ACTIVATED/INACTIVE
my $contracts = $_->{ServiceContracts} || [];
next unless $contracts;
$customer = $_;
for ( @$contracts ) {
next unless $_->{ServiceContractStatus} =~ /(ACTIVE|PRECONTRACT)/; # Options seem to be ACTIVE/NOACTIVE/PRECONTRACT
$contract = $_;
# use the first matching customer/contract
last OUTER if $customer && $contract;
}
}

return unless $customer && $contract;

# XXX should maybe sort by CreatedDate rather than assuming first is OK
$sub->{cost} = try {
Expand Down
2 changes: 2 additions & 0 deletions t/app/controller/waste_bexley_garden.t
Original file line number Diff line number Diff line change
Expand Up @@ -651,9 +651,11 @@ FixMyStreet::override_config {
Customers => [
{
CustomerExternalReference => 'CUSTOMER_123',
CustomertStatus => 'ACTIVATED',
ServiceContracts => [
{
EndDate => '12/12/2025 12:21',
ServiceContractStatus => 'ACTIVE',
},
],
},
Expand Down

0 comments on commit 07c25ad

Please sign in to comment.