Online Renewal - Got address changes to save in the right way
authorTerran McCanna <tmccanna@georgialibraries.org>
Thu, 1 Dec 2022 00:22:35 +0000 (19:22 -0500)
committerTerran McCanna <tmccanna@georgialibraries.org>
Thu, 1 Dec 2022 00:22:35 +0000 (19:22 -0500)
Signed-off-by: Terran McCanna <tmccanna@georgialibraries.org>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Ecard.pm

index 02a4329..692944c 100644 (file)
@@ -210,8 +210,7 @@ sub load_ecard_submit {
         return $self->compile_response if $ctx->{response}->{status};
     }
 
-
-# Add extra info to response message
+    # Add extra info to response message
     $ctx->{response}->{status} = 'OK';
 
     if ($update_type eq 'renew') {
@@ -594,33 +593,6 @@ sub update_addresses {
 
         my $val = $cgi->param($field);
 
-        if ($physical_addr->id eq $mailing_addr->id && $physical_addr->street1 eq $mailing_addr->street1) {
-            # if one address & stays at one address, just update it
-            $physical_addr->isnew(0);
-            $physical_addr->ischanged(1);
-            $mailing_addr->isnew(0);
-            $mailing_addr->ischanged(1);
-        } elsif ($physical_addr->id eq $mailing_addr->id && $physical_addr->street1 ne $mailing_addr->street1) {
-            # if the addr ids are the same, but the streets don't match, create a separate address entry for mailing
-            $physical_addr->isnew(0);
-            $physical_addr->ischanged(1);
-            $mailing_addr->isnew(1);
-            $mailing_addr->ischanged(0);
-        } elsif ($physical_addr->id ne $mailing_addr->id && $physical_addr->street1 eq $mailing_addr->street1) {
-            # if there were previously 2 addresses, but there is only one address now, delete excess entry
-            $physical_addr->isnew(0);
-            $physical_addr->ischanged(1);
-            $mailing_addr->isnew(0);
-            $mailing_addr->ischanged(0);
-            $mailing_addr->isdeleted(1);
-        } else {
-            # otherwise, update existing entries
-            $physical_addr->isnew(0);
-            $physical_addr->ischanged(1);
-            $mailing_addr->isnew(0);
-            $mailing_addr->ischanged(1);
-        }
-
         if ($field_info->{required} && !$val) {
             my $msg = "Value required for field: '$field'";
             $ctx->{response}->{status} = 'INVALID_PARAMS';
@@ -637,6 +609,32 @@ sub update_addresses {
         }
     }
 
+    # Determine what exactly to do with addresses
+    if ($physical_addr->id eq $mailing_addr->id && $physical_addr->street1 eq $mailing_addr->street1) {
+        # if one address & stays at one address, just update it (don't need to do both physical & mailing)
+        $mailing_addr->isnew(0);
+        $mailing_addr->ischanged(1);
+    } elsif ($physical_addr->id eq $mailing_addr->id && $physical_addr->street1 ne $mailing_addr->street1) {
+        # if one address splitting to two addresses, update the first and create a second address entry
+        $physical_addr->isnew(0);
+        $physical_addr->ischanged(1);
+        $mailing_addr->isnew(1);
+        $mailing_addr->id(-1);
+    } elsif ($physical_addr->id ne $mailing_addr->id && $physical_addr->street1 eq $mailing_addr->street1) {
+        # if there were previously 2 addresses, but there is only one address now, use the updated single address entry for both
+        $physical_addr->isnew(0);
+        $physical_addr->ischanged(1);
+        $mailing_addr->isnew(0);
+        $mailing_addr->ischanged(1);
+        $mailing_addr->id($physical_addr->id);
+    } else {
+        # otherwise, update existing entries
+        $physical_addr->isnew(0);
+        $physical_addr->ischanged(1);
+        $mailing_addr->isnew(0);
+        $mailing_addr->ischanged(1);
+    }
+
     # exit if there were any errors above.
     return undef if $ctx->{response}->{status};