[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[3348] trunk



Revision: 3348
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3348&view=rev
Author:   ehuelsmann
Date:     2011-06-26 20:16:10 +0000 (Sun, 26 Jun 2011)

Log Message:
-----------
Implement support for e-mail billing addresses,
like we have support for billing physical addresses.

Modified Paths:
--------------
    trunk/LedgerSMB/Form.pm
    trunk/bin/aa.pl
    trunk/bin/ir.pl
    trunk/bin/is.pl
    trunk/sql/Pg-database.sql

Modified: trunk/LedgerSMB/Form.pm
===================================================================
--- trunk/LedgerSMB/Form.pm	2011-06-26 19:23:44 UTC (rev 3347)
+++ trunk/LedgerSMB/Form.pm	2011-06-26 20:16:10 UTC (rev 3348)
@@ -2288,7 +2288,7 @@
 }
 
 =item $form->create_links( { module => $module,
-    myconfig => $myconfig, vc => $vc, [, job => $job ] });
+    myconfig => $myconfig, vc => $vc, billing => $billing [, job => $job ] });
 
 Populates the hash referred to as $form->{${module}_links} details about
 accounts that have $module in their link field.  The hash is keyed upon link
@@ -2316,6 +2316,10 @@
 current date.  If $form->{id} is not set, then $form->{transdate} also takes on
 the current date.
 
+When $billing is provided and true, the email addresses are selected
+from the billing contact classes, when available, falling back to the
+normal email classes when not.
+
 After all this, it calls $form->all_vc to conclude.
 
 =cut
@@ -2441,14 +2445,32 @@
         for (qw(printed emailed queued)) { $self->{$_} =~ s/ +$//g }
 
 	# get customer e-mail accounts
-	$query = qq|SELECT * FROM eca__list_contacts(?);|;
+	$query = qq|SELECT * FROM eca__list_contacts(?)
+                      WHERE class_id BETWEEN 12 AND ?
+                      ORDER BY class_id DESC;|;
+	my %id_map = ( 12 => 'email',
+		       13 => 'cc',
+		       14 => 'bcc',
+		       15 => 'email',
+		       16 => 'cc',
+		       17 => 'bcc' );
 	$sth = $dbh->prepare($query);
-	$sth->execute( $self->{entity_id} ) || $self->dberror( $query );
+	$sth->execute( $self->{entity_id},
+	               $billing ? 17 : 14) || $self->dberror( $query );
 
 	my $ctype;
+	my $billing_email = 0;
 	while ( $ref = $sth->fetchrow_hashref('NAME_lc') ) {
-	    $ctype = lc $ref->{class};
-	    $self->{$ctype} .= "$ref->{contact} ";
+	    $ctype = $ref->{class_id};
+	    $ctype = $id_map{$ctype};
+	    $billing_email = 1
+		if $ref->{class_id} == 15;
+
+	    # If there's an explicit billing email, don't use
+	    # the standard email addresses; otherwise fall back to standard
+	    $self->{$ctype} .= "$ref->{contact} "
+		if (($ref->{class_id} < 15 && ! $billing_email)
+		    || $ref->{class_id} >= 15);
 	}
 	$sth->finish;
 

Modified: trunk/bin/aa.pl
===================================================================
--- trunk/bin/aa.pl	2011-06-26 19:23:44 UTC (rev 3347)
+++ trunk/bin/aa.pl	2011-06-26 20:16:10 UTC (rev 3348)
@@ -159,7 +159,9 @@
 
     $form->create_links( module => $form->{ARAP},
 			 myconfig => \%myconfig,
-			 vc => $form->{vc} );
+			 vc => $form->{vc},
+			 billing => $form->{vc} eq 'customer'
+			            && $form->{type} eq 'invoice');
 
     $duedate     = $form->{duedate};
     $taxincluded = $form->{taxincluded};
@@ -1398,7 +1400,8 @@
 
     $form->create_links( module => $form->{ARAP},
 			 myconfig => \%myconfig,
-			 vc => $form->{vc} );
+			 vc => $form->{vc},
+			 billing => 0);
 
     $form->{"select$form->{ARAP}"} = "<option>\n";
     for ( @{ $form->{"$form->{ARAP}_links"}{ $form->{ARAP} } } ) {

Modified: trunk/bin/ir.pl
===================================================================
--- trunk/bin/ir.pl	2011-06-26 19:23:44 UTC (rev 3347)
+++ trunk/bin/ir.pl	2011-06-26 20:16:10 UTC (rev 3348)
@@ -92,6 +92,7 @@
     $form->create_links( module => "AP",
 			 myconfig => \%myconfig,
 			 vc => "vendor",
+			 billing => 0,
 			 job => 1 );
 
     # currencies

Modified: trunk/bin/is.pl
===================================================================
--- trunk/bin/is.pl	2011-06-26 19:23:44 UTC (rev 3347)
+++ trunk/bin/is.pl	2011-06-26 20:16:10 UTC (rev 3348)
@@ -97,6 +97,7 @@
     $form->create_links( module => "AR",
 			 myconfig => \%myconfig,
 			 vc => "customer",
+			 billing => 1,
 			 job => 1 );
 
     # currencies

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2011-06-26 19:23:44 UTC (rev 3347)
+++ trunk/sql/Pg-database.sql	2011-06-26 20:16:10 UTC (rev 3348)
@@ -689,11 +689,16 @@
 INSERT INTO contact_class (id,class) values (9,'Fax');
 INSERT INTO contact_class (id,class) values (10,'Generic Jabber');
 INSERT INTO contact_class (id,class) values (11,'Home Phone');
+-- The e-mail classes are hard-coded into LedgerSMB/Form.pm by class_id
+-- i.e. 'class_id's 12 - 17
 INSERT INTO contact_class (id,class) values (12,'Email');
 INSERT INTO contact_class (id,class) values (13,'CC');
 INSERT INTO contact_class (id,class) values (14,'BCC');
+INSERT INTO contact_class (id,class) values (15,'Billing Email');
+INSERT INTO contact_class (id,class) values (16,'Billing CC');
+INSERT INTO contact_class (id,class) values (17,'Billing BCC');
 
-SELECT SETVAL('contact_class_id_seq',12);
+SELECT SETVAL('contact_class_id_seq',17);
 
 CREATE TABLE person_to_contact (
   person_id integer not null references person(id) ON DELETE CASCADE,


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.