[freeside-commits] branch master updated. 582189e6a07bf401385e220bb554ddbf0441b9fb

Ivan ivan at 420.am
Thu Aug 16 01:31:16 PDT 2012


The branch, master has been updated
       via  582189e6a07bf401385e220bb554ddbf0441b9fb (commit)
      from  022c84a3d9c8a946d5e0b3f0fff73aa771461bc5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 582189e6a07bf401385e220bb554ddbf0441b9fb
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Thu Aug 16 01:31:15 2012 -0700

    national IDs, RT#18543

diff --git a/FS/FS/cust_main/NationalID.pm b/FS/FS/cust_main/NationalID.pm
new file mode 100644
index 0000000..cc8d556
--- /dev/null
+++ b/FS/FS/cust_main/NationalID.pm
@@ -0,0 +1,60 @@
+package FS::cust_main::NationalID;
+
+use strict;
+use vars qw( $conf );
+use Date::Simple qw( days_in_month );
+use FS::UID;
+
+install_callback FS::UID sub { 
+  $conf = new FS::Conf;
+};
+
+sub set_national_id_from_cgi {
+  my( $self, $cgi ) = @_;
+
+  my $error = '';
+
+  if ( my $id_country = $conf->config('national_id-country') ) {
+    if ( $id_country eq 'MY' ) {
+  
+      if ( $cgi->param('national_id1') =~ /\S/ ) {
+        my $nric = $cgi->param('national_id1');
+        $nric =~ s/\s//g;
+        if ( $nric =~ /^(\d{2})(\d{2})(\d{2})\-?(\d{2})\-?(\d{4})$/ ) {
+          my( $y, $m, $d, $bp, $n ) = ( $1, $2, $3, $4, $5 );
+          $self->national_id( "$y$m$d-$bp-$n" );
+  
+          my @lt = localtime(time);
+          my $year = ( $y <= substr( $lt[5]+1900, -2) ) ? 2000 + $y
+                                                        : 1900 + $y;
+          $error ||= "Illegal NRIC: ". $cgi->param('national_id1')
+            if $m < 1 || $m > 12 || $d < 1 || $d > days_in_month($year, $m);
+            #$bp validation per http://en.wikipedia.org/wiki/National_Registration_Identity_Card_Number_%28Malaysia%29#Second_section:_Birthplace ?  seems like a bad idea, some could be missing or get added
+        } else {
+          $error ||= "Illegal NRIC: ". $cgi->param('national_id1');
+        }
+      } elsif ( $cgi->param('national_id2') =~ /\S/ ) {
+        my $oldic = $cgi->param('national_id2');
+        $oldic =~ s/\s//g;
+        if ( $oldic =~ /^\w\d{9}$/ ) {
+          $self->national_id($oldic);
+        } else {
+          $error ||= "Illegal Old IC/Passport: ". $cgi->param('national_id2');
+        }
+      } else {
+        $error ||= 'Either NRIC or Old IC/Passport is required';
+      }
+      
+    } else {
+      warn "unknown national_id-country $id_country";
+    }
+  } elsif ( $cgi->param('national_id0') ) {
+    $self->national_id( $cgi->param('national_id0') );
+  }
+
+  $error;
+
+}
+
+1;
+

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/cust_main/NationalID.pm |   60 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 60 insertions(+), 0 deletions(-)
 create mode 100644 FS/FS/cust_main/NationalID.pm




More information about the freeside-commits mailing list