[freeside-commits] freeside/FS/FS contact.pm, 1.1, 1.2 Mason.pm, 1.54, 1.55 Schema.pm, 1.237, 1.238 cust_main.pm, 1.562, 1.563 contact_phone.pm, 1.1, 1.2 Misc.pm, 1.41, 1.42

Ivan,,, ivan at wavetail.420.am
Wed Oct 13 18:14:29 PDT 2010


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv4104/FS/FS

Modified Files:
	contact.pm Mason.pm Schema.pm cust_main.pm contact_phone.pm 
	Misc.pm 
Log Message:
more contact work and preliminary business card upload

Index: Mason.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Mason.pm,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -w -d -r1.54 -r1.55
--- Mason.pm	22 Sep 2010 19:16:17 -0000	1.54
+++ Mason.pm	14 Oct 2010 01:14:27 -0000	1.55
@@ -126,7 +126,7 @@
   use FS::UI::Web::small_custview qw(small_custview);
   use FS::UI::bytecount;
   use FS::Msgcat qw(gettext geterror);
-  use FS::Misc qw( send_email send_fax
+  use FS::Misc qw( send_email send_fax ocr_image
                    states_hash counties cities state_label
                  );
   use FS::Misc::eps2png qw( eps2png );

Index: contact_phone.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/contact_phone.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- contact_phone.pm	28 Dec 2009 19:18:18 -0000	1.1
+++ contact_phone.pm	14 Oct 2010 01:14:27 -0000	1.2
@@ -120,7 +120,7 @@
     || $self->ut_number('phonetypenum')
     || $self->ut_text('countrycode')
     || $self->ut_text('phonenum')
-    || $self->ut_text('extension')
+    || $self->ut_textn('extension')
   ;
   return $error if $error;
 

Index: contact.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/contact.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- contact.pm	28 Dec 2009 19:18:18 -0000	1.1
+++ contact.pm	14 Oct 2010 01:14:27 -0000	1.2
@@ -2,10 +2,12 @@
 
 use strict;
 use base qw( FS::Record );
-use FS::Record qw( qsearch qsearchs );
+use FS::Record qw( qsearch qsearchs dbh );
 use FS::prospect_main;
 use FS::cust_main;
 use FS::cust_location;
+use FS::contact_phone;
+use FS::contact_email;
 
 =head1 NAME
 
@@ -96,7 +98,59 @@
 
 =cut
 
-# the insert method can be inherited from FS::Record
+sub insert {
+  my $self = shift;
+
+  local $SIG{INT} = 'IGNORE';
+  local $SIG{QUIT} = 'IGNORE';
+  local $SIG{TERM} = 'IGNORE';
+  local $SIG{TSTP} = 'IGNORE';
+  local $SIG{PIPE} = 'IGNORE';
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  my $error = $self->SUPER::insert;
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  foreach my $pf ( grep { /^phonetypenum(\d+)$/ && $self->get($_) =~ /\S/ }
+                        keys %{ $self->hashref } ) {
+    $pf =~ /^phonetypenum(\d+)$/ or die "wtf (daily, the)";
+    my $phonetypenum = $1;
+
+    my $contact_phone = new FS::contact_phone {
+      'contactnum' => $self->contactnum,
+      'phonetypenum' => $phonetypenum,
+      _parse_phonestring( $self->get($pf) ),
+    };
+    $error = $contact_phone->insert;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
+  }
+
+  if ( $self->get('emailaddress') =~ /\S/ ) {
+    my $contact_email = new FS::contact_email {
+      'contactnum'   => $self->contactnum,
+      'emailaddress' => $self->get('emailaddress'),
+    };
+    $error = $contact_email->insert;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+  '';
+
+}
 
 =item delete
 
@@ -106,6 +160,8 @@
 
 # the delete method can be inherited from FS::Record
 
+# XXX delete contact_phone, contact_email
+
 =item replace OLD_RECORD
 
 Replaces the OLD_RECORD with this one in the database.  If there is an error,
@@ -113,7 +169,76 @@
 
 =cut
 
-# the replace method can be inherited from FS::Record
+sub replace {
+  my $self = shift;
+
+  local $SIG{INT} = 'IGNORE';
+  local $SIG{QUIT} = 'IGNORE';
+  local $SIG{TERM} = 'IGNORE';
+  local $SIG{TSTP} = 'IGNORE';
+  local $SIG{PIPE} = 'IGNORE';
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  my $error = $self->SUPER::replace(@_);
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  foreach my $pf ( grep { /^phonetypenum(\d+)$/ && $self->get($_) }
+                        keys %{ $self->hashref } ) {
+    $pf =~ /^phonetypenum(\d+)$/ or die "wtf (daily, the)";
+    my $phonetypenum = $1;
+
+    my %cp = ( 'contactnum'   => $self->contactnum,
+               'phonetypenum' => $phonetypenum,
+             );
+    my $contact_phone = qsearchs('contact_phone', \%cp)
+                        || new FS::contact_phone   \%cp;
+
+    my %cpd = _parse_phonestring( $self->get($pf) );
+    $contact_phone->set( $_ => $cpd{$_} ) foreach keys %cpd;
+
+    my $method = $contact_phone->contactphonenum ? 'replace' : 'insert';
+
+    $error = $contact_phone->$method;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+  '';
+
+}
+
+#i probably belong in contact_phone.pm
+sub _parse_phonestring {
+  my $value = shift;
+
+  my($countrycode, $extension) = ('1', '');
+
+  #countrycode
+  if ( $value =~ s/^\s*\+\s*(\d+)// ) {
+    $countrycode = $1;
+  } else {
+    $value =~ s/^\s*1//;
+  }
+  #extension
+  if ( $value =~ s/\s*(ext|x)\s*(\d+)\s*$//i ) {
+     $extension = $2;
+  }
+
+  ( 'countrycode' => $countrycode,
+    'phonenum'    => $value,
+    'extension'   => $extension,
+  );
+}
 
 =item check
 
@@ -165,8 +290,6 @@
 
 =head1 BUGS
 
-The author forgot to customize this manpage.
-
 =head1 SEE ALSO
 
 L<FS::Record>, schema.html from the base documentation.

Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.562
retrieving revision 1.563
diff -u -w -d -r1.562 -r1.563
--- cust_main.pm	14 Oct 2010 00:59:06 -0000	1.562
+++ cust_main.pm	14 Oct 2010 01:14:27 -0000	1.563
@@ -26,7 +26,7 @@
 use Digest::MD5 qw(md5_base64);
 use Date::Format;
 #use Date::Manip;
-use File::Temp qw( tempfile );
+use File::Temp; #qw( tempfile );
 use Business::CreditCard 0.28;
 use Locale::Country;
 use FS::UID qw( getotaker dbh driver_name );

Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.237
retrieving revision 1.238
diff -u -w -d -r1.237 -r1.238
--- Schema.pm	12 Oct 2010 01:15:16 -0000	1.237
+++ Schema.pm	14 Oct 2010 01:14:27 -0000	1.238
@@ -831,8 +831,8 @@
         'last',      'varchar',     '', $char_d, '', '', 
 #        'middle',    'varchar', 'NULL', $char_d, '', '', 
         'first',     'varchar',     '', $char_d, '', '', 
-        'title',     'varchar',     '', $char_d, '', '', #eg Head Bottle Washer
-        'comment',   'varchar',     '', $char_d, '', '', 
+        'title',     'varchar', 'NULL', $char_d, '', '', #eg Head Bottle Washer
+        'comment',   'varchar', 'NULL', $char_d, '', '', 
         'disabled',     'char', 'NULL',       1, '', '', 
       ],
       'primary_key' => 'contactnum',
@@ -849,7 +849,7 @@
         'phonetypenum',       'int', '', '', '', '',
         'countrycode',    'varchar', '',  3, '', '', 
         'phonenum',       'varchar', '', 14, '', '', 
-        'extension',      'varchar', '',  7, '', '',
+        'extension',      'varchar', 'NULL',  7, '', '',
         #?#'comment',   'varchar',     '', $char_d, '', '', 
       ],
       'primary_key' => 'contactphonenum',

Index: Misc.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Misc.pm,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -w -d -r1.41 -r1.42
--- Misc.pm	16 Aug 2010 17:49:02 -0000	1.41
+++ Misc.pm	14 Oct 2010 01:14:27 -0000	1.42
@@ -20,6 +20,7 @@
                  pkg_freqs
                  generate_ps generate_pdf do_print
                  csv_from_fixed
+                 ocr_image
                );
 
 $DEBUG = 0;
@@ -850,6 +851,41 @@
   '';
 }
 
+=item ocr_image IMAGE_SCALAR
+
+Runs OCR on the provided image data and returns a list of text lines.
+
+=cut
+
+sub ocr_image {
+  my $logo_data = shift;
+
+  #XXX use conf dir location from Makefile
+  my $dir = $FS::UID::conf_dir. "/cache.". $FS::UID::datasrc;
+  my $fh = new File::Temp(
+    TEMPLATE => 'bizcard.XXXXXXXX',
+    SUFFIX   => '.png', #XXX assuming, but should handle jpg, gif, etc. too
+    DIR      => $dir,
+    UNLINK   => 0,
+  ) or die "can't open temp file: $!\n";
+
+  my $filename = $fh->filename;
+
+  print $fh $logo_data;
+  close $fh;
+
+  run( [qw(ocroscript recognize), $filename], '>'=>"$filename.hocr" )
+    or die "ocroscript recognize failed\n";
+
+  run( [qw(ocroscript hocr-to-text), "$filename.hocr"], '>pipe'=>\*OUT )
+    or die "ocroscript hocr-to-text failed\n";
+
+  my @lines = split(/\n/, <OUT> );
+
+  foreach (@lines) { s/\.c0m\s*$/.com/; }
+
+  @lines;
+}
 
 =back
 



More information about the freeside-commits mailing list