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

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



Revision: 2852
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2852&view=rev
Author:   einhverfr
Date:     2010-02-07 03:02:42 +0000 (Sun, 07 Feb 2010)

Log Message:
-----------
One can now set taxes for customers/vendors
Adding .gitignore

Modified Paths:
--------------
    trunk/INSTALL
    trunk/LedgerSMB/DBObject/Admin.pm
    trunk/LedgerSMB/DBObject/Company.pm
    trunk/LedgerSMB/DBObject.pm
    trunk/LedgerSMB/Initiate.pm
    trunk/LedgerSMB/Log.pm
    trunk/LedgerSMB/Mailer.pm
    trunk/LedgerSMB/ScriptLib/Company.pm
    trunk/LedgerSMB/Sysconfig.pm
    trunk/LedgerSMB.pm
    trunk/UI/Admin/edit_user.html
    trunk/UI/Contact/contact.html
    trunk/bin/initiate.pl
    trunk/initiate.pl
    trunk/lsmb-request.pl
    trunk/scripts/admin.pl
    trunk/sql/modules/Account.sql
    trunk/sql/modules/Company.sql
    trunk/sql/modules/Person.sql

Added Paths:
-----------
    trunk/.gitignore

Added: trunk/.gitignore
===================================================================
--- trunk/.gitignore	                        (rev 0)
+++ trunk/.gitignore	2010-02-07 03:02:42 UTC (rev 2852)
@@ -0,0 +1,12 @@
+# .gitignore for LedgerSMB
+#
+# Vim swap files
+*.swp
+#
+# Perl Module::Build, Module::Install, ExtUtils::MakeMaker
+META.yml
+Makefile
+inc/
+#
+# LedgerSMB runtime files
+ledgersmb.conf

Modified: trunk/INSTALL
===================================================================
--- trunk/INSTALL	2010-01-27 18:51:31 UTC (rev 2851)
+++ trunk/INSTALL	2010-02-07 03:02:42 UTC (rev 2852)
@@ -223,7 +223,9 @@
 Identify the system package containing the files tsearch2.sql, tablefunc.sql,
 and pg_trgm.sql. Install that package, and locate the files on the filesystem.
 
-You only need to install these function libraries once per postgresql cluster.
+If you install these on template1 then you only need to install these function
+libraries once per postgresql cluster. They will be included in any new
+database created from template1.
 
 For the remainder of this INSTALL procedure, you will need to become user
 postgres, or have the ability to log in to psql as your current user, or issue

Modified: trunk/LedgerSMB/DBObject/Admin.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Admin.pm	2010-01-27 18:51:31 UTC (rev 2851)
+++ trunk/LedgerSMB/DBObject/Admin.pm	2010-02-07 03:02:42 UTC (rev 2852)
@@ -39,6 +39,7 @@
             'first_name',
             'last_name',
             'employeenumber',
+            'country_id',
         ]    
     );
     

Modified: trunk/LedgerSMB/DBObject/Company.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Company.pm	2010-01-27 18:51:31 UTC (rev 2851)
+++ trunk/LedgerSMB/DBObject/Company.pm	2010-02-07 03:02:42 UTC (rev 2852)
@@ -73,10 +73,19 @@
     my $self = shift @_;
     $self->set_entity_class();
     $self->{threshold} = $self->parse_amount(amount => $self->{threshold});
+    $self->{tax_ids} = $self->_db_array_scalars(@{$self->{tax_ids}});
     my ($ref) = $self->exec_method(funcname => 'entity_credit_save');
     $self->{credit_id} = (values %$ref)[0];
     my $dbh=$self->{dbh};
-    $dbh->do("update entity_credit_account set country_taxform_id=$self->{taxform1_id} where id=$self->{credit_id}") if($self->{taxform1_id});
+    if ($self->{taxform1_id}) {
+       my $sth = $dbh->prepare(
+           "update entity_credit_account 
+                set country_taxform_id=? 
+              where id=?"
+       );
+       $sth->execute($self->{taxform1_id}, $self->{credit_id});
+    }
+    $self->exec_method(funcname => 'eca__set_taxes');
     $dbh->commit();
     $self->{threshold} = $self->format_amount(amount => $self->{threshold});
     $self->{dbh}->commit;
@@ -145,6 +154,9 @@
     @{$self->{entity_classes}} = 
 		$self->exec_method(funcname => 'entity__list_classes');
 
+    @{$self->{all_taxes}} = 
+                $self->exec_method(funcname => 'account__get_taxes');
+
     @{$self->{ar_ap_acc_list}} = 
          $self->exec_method(funcname => 'chart_get_ar_ap');
 
@@ -244,13 +256,20 @@
 
     @{$self->{credit_list}} = 
          $self->exec_method(funcname => 'entity__list_credit');
-
+    $self->{eca_tax} = [];
     for (@{$self->{credit_list}}){
 	if (($_->{credit_id} eq $self->{credit_id}) 
                    or ($_->{meta_number} eq $self->{meta_number})
                    or ($_->{id} eq $self->{credit_id})){
-		$self->merge($_);
-                last;
+            $self->merge($_);
+            if ($_->{entity_class} == 1 || $_->{entity_class} == 2){
+                my @taxes = $self->exec_method(funcname => 'eca__get_taxes');
+                
+                for my $tax (@taxes){
+                    push @{$self->{eca_tax}}, $tax->{chart_id};
+                }
+            }
+            last;
         }
     }
     $self->{name} = $self->{legal_name};

Modified: trunk/LedgerSMB/DBObject.pm
===================================================================
--- trunk/LedgerSMB/DBObject.pm	2010-01-27 18:51:31 UTC (rev 2851)
+++ trunk/LedgerSMB/DBObject.pm	2010-02-07 03:02:42 UTC (rev 2852)
@@ -47,9 +47,12 @@
 package LedgerSMB::DBObject;
 use Scalar::Util;
 use base qw(LedgerSMB);
+use LedgerSMB::Log;
 use strict;
 use warnings;
 
+my $logger = Log::Log4perl->get_logger('LedgerSMB::DBObject');
+
 sub __validate__ {}
 
 sub new {
@@ -99,6 +102,7 @@
     my $self   = shift @_;
     my %args     = @_;
     my $funcname = $args{funcname};
+    $logger->debug("exec_method: \$funcname = $funcname");
     my @in_args;
     @in_args = @{ $args{args}} if $args{args};
     
@@ -131,17 +135,18 @@
     $ref->{pronargs} = 0 unless defined $ref->{pronargs};
     # If the user provided args..
     if (!defined  $args{args}) {
-    
         @proc_args = $self->_parse_array($pargs);
         if (@proc_args) {
             for my $arg (@proc_args) {
                 if ( $arg =~ s/^in_// ) {
+                    $logger->debug("exec_method pushing $arg = $self->{$arg}");
                      push @call_args, $self->{$arg};
                 }
             }
         }
         for (@in_args) { push @call_args, $_ } ;
         $self->{call_args} = ..hidden..;
+        $logger->debug("exec_method: \$self = " . Data::Dumper::Dumper($self));
         return $self->call_procedure( procname => $funcname, args => ..hidden.., order_by => $self->{_order_method}->{"$funcname"} );
     }
     else {

Modified: trunk/LedgerSMB/Initiate.pm
===================================================================
--- trunk/LedgerSMB/Initiate.pm	2010-01-27 18:51:31 UTC (rev 2851)
+++ trunk/LedgerSMB/Initiate.pm	2010-02-07 03:02:42 UTC (rev 2852)
@@ -8,7 +8,10 @@
 use LedgerSMB::Locale;
 use Data::Dumper;
 use DBI;
+use LedgerSMB::Log;
 
+my $logger = Log::Log4perl->get_logger('LedgerSMB::Initiate');
+
 =over
 
 =item LedgerSMB::User->new($login);
@@ -162,6 +165,7 @@
 
 sub validateform
 {
+    $logger->debug("Begin LedgerSMB::Initiate::validateform");
 
     ($self,$form,$locale)..hidden..;
 
@@ -220,12 +224,13 @@
             );
         }
     }
-
+    $logger->debug("End LedgerSMB::Initiate::validateform");
 }
 
 
 sub save_database
 {
+    $logger->debug("Begin LedgerSMB::Initiate::save_database");
 
 	my($self,$form)..hidden..;
 	# check all files exist and valids (contrib files , pgdabase.sql and modules and chart accounts etc)
@@ -260,14 +265,20 @@
 
 		#Stage -  Wind up completed the task
 	process_roles($form);
+
+    $logger->debug("End LedgerSMB::Initiate::save_database");
 }
 
+
+
 sub process_roles {
+    $logger->debug("Begin LedgerSMB::Initiate::process_roles");
 	my ($form) = @_;
 	print STDERR "loading roles............\n";
 	LedgerSMB::Initiate->getdbh($form);
 	open (PSQL, '|-', 'psql') || $form->error($locale->text("Couldn't open psql"));
 	my $company = $form->{company};
+    $logger->debug("LedgerSMB::Initiate::process_roles: company = $company");
 
 	open (ROLEFILE, '<', 'sql/modules/Roles.sql') || $form->error($locale->text("Couldn't open Roles.sql"));
 
@@ -290,7 +301,9 @@
 			" TO " .
 			$form->{newdbh}->quote_identifier($form->{admin_username});
 	}
-	print PSQL $query;
+	print PSQL "$query";
+
+    $logger->debug("End LedgerSMB::Initiate::process_roles");
 }
 
 sub run_all_sql_scripts

Modified: trunk/LedgerSMB/Log.pm
===================================================================
--- trunk/LedgerSMB/Log.pm	2010-01-27 18:51:31 UTC (rev 2851)
+++ trunk/LedgerSMB/Log.pm	2010-02-07 03:02:42 UTC (rev 2852)
@@ -52,7 +52,13 @@
 use Data::Dumper;
 use LedgerSMB::Sysconfig;
 use Carp ();
+use Log::Log4perl;
 
+Log::Log4perl::init(\$LedgerSMB::Sysconfig::log4perl_config);
+
+my $logger = Log::Log4perl->get_logger('');
+$logger->debug('LedgerSMB::Log Log4perl config: ', $LedgerSMB::Sysconfig::log4perl_config);
+
 our $VERSION = '1.0.0';
 
 our $log_line;

Modified: trunk/LedgerSMB/Mailer.pm
===================================================================
--- trunk/LedgerSMB/Mailer.pm	2010-01-27 18:51:31 UTC (rev 2851)
+++ trunk/LedgerSMB/Mailer.pm	2010-02-07 03:02:42 UTC (rev 2852)
@@ -113,7 +113,7 @@
 	$domain =~ s/(.*?\@|>)//g;
 	my $boundary = time;
 	$boundary = "LSMB-$boundary";
-	my $msg_id = "..hidden..";
+	my $msg_id = "<..hidden..>";
 
 	$self->{contenttype} = "text/plain" unless $self->{contenttype};
 

Modified: trunk/LedgerSMB/ScriptLib/Company.pm
===================================================================
--- trunk/LedgerSMB/ScriptLib/Company.pm	2010-01-27 18:51:31 UTC (rev 2851)
+++ trunk/LedgerSMB/ScriptLib/Company.pm	2010-02-07 03:02:42 UTC (rev 2852)
@@ -369,6 +369,14 @@
     my ($request) = @_;
 
     my $company = new_company($request);
+    my @taxes;
+    $company->{tax_ids} = [];
+    for my $key(keys %$company){
+        if ($key =~ /^taxact_(\d+)$/){
+           my $tax = $1;
+           push @{$company->{tax_ids}}, $tax;
+        }  
+    }
     $company->save_credit();
     $company->get();
     _render_main_screen($company);

Modified: trunk/LedgerSMB/Sysconfig.pm
===================================================================
--- trunk/LedgerSMB/Sysconfig.pm	2010-01-27 18:51:31 UTC (rev 2851)
+++ trunk/LedgerSMB/Sysconfig.pm	2010-02-07 03:02:42 UTC (rev 2852)
@@ -85,6 +85,13 @@
 # available printers
 %printer;
 
+# Log4perl configuration
+$log4perl_config = q(
+    log4perl.rootlogger = DEBUG, Screen
+    log4perl.appender.Screen = Log::Log4perl::Appender::Screen
+    log4perl.appender.Screen.layout = SimpleLayout
+);
+
 my %config;
 read_config( 'ledgersmb.conf' => %config ) or die;
 

Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm	2010-01-27 18:51:31 UTC (rev 2851)
+++ trunk/LedgerSMB.pm	2010-02-07 03:02:42 UTC (rev 2852)
@@ -142,6 +142,7 @@
 use LedgerSMB::Locale;
 use LedgerSMB::User;
 use LedgerSMB::Setting;
+use LedgerSMB::Log;
 use strict;
 
 $CGI::Simple::POST_MAX = -1;
@@ -149,22 +150,29 @@
 package LedgerSMB;
 our $VERSION = '1.2.99';
 
+my $logger = Log::Log4perl->get_logger('LedgerSMB');
+
 sub new {
     my $type   = shift @_;
     my $argstr = shift @_;
     my %cookie;
     my $self = {};
 
+    $logger->debug("Begin LedgerSMB.pm");
 
     $self->{version} = $VERSION;
     $self->{dbversion} = "1.2.0";
     bless $self, $type;
+    $logger->debug("LedgerSMB::new: \$argstr = $argstr");
     my $query = ($argstr) ? new CGI::Simple($argstr) : new CGI::Simple;
-    my $params = $query->Vars;
+    # my $params = $query->Vars; returns a tied hash with keys that
+    # are not parameters of the CGI query.
+    my %params = $query->Vars;
+    $logger->debug("LedgerSMB::new: params = ", Data::Dumper::Dumper(\%params));
     $self->{VERSION} = $VERSION;
     $self->{_request} = $query;
 
-    $self->merge($params);
+    $self->merge(\%params);
     $self->{have_latex} = $LedgerSMB::Sysconfig::latex;
 
     # Adding this so that empty values are stored in the db as NULL's.  If
@@ -209,6 +217,8 @@
     if (!$self->{script}) {
         $self->{script} = 'login.pl';
     }
+    $logger->debug("LedgerSMB.pm: \$self->{script} = $self->{script}");
+    $logger->debug("LedgerSMB.pm: \$self->{action} = $self->{action}");
 #    if ($self->{action} eq 'migrate_user'){
 #        return $self;
 #    }
@@ -222,6 +232,7 @@
          $ccookie =~ s/.*:([^:]*)$/$1/;
          $self->{company} = $ccookie;
     }
+    $logger->debug("LedgerSMB.pm: \$self->{company} = $self->{company}");
 
     $self->_db_init;
 
@@ -230,10 +241,11 @@
        #check for valid session unless this is an inital authentication
        #request -- CT
        if (!LedgerSMB::Auth::session_check( $cookie{${LedgerSMB::Sysconfig::cookie_name}}, $self) ) {
-            print STDERR "Session did not check";
+            $logger->error("Session did not check");
             $self->_get_password("Session Expired");
             exit;
        }
+       $logger->debug("LedgerSMB::new: session_check completed OK");
     }
     $self->get_user_info;
     my %date_setting = (
@@ -253,6 +265,8 @@
 
     $self->{stylesheet} = $self->{_user}->{stylesheet};
 
+    $logger->debug("End LedgerSMB.pm");
+
     return $self;
 
 }
@@ -725,6 +739,8 @@
     my $self     = shift @_;
     my %args     = @_;
     my $creds = LedgerSMB::Auth::get_credentials();
+
+    $logger->debug("LedgerSMB::_db_init: start");
   
     $self->{login} = $creds->{login};
     if (!$self->{company}){ 
@@ -811,7 +827,7 @@
 #private, for db connection errors
 sub _on_connection_error {
     for (@_){
-        print STDERR "$_\n";
+        $logger->error("$_");
     }
 }
 
@@ -829,8 +845,8 @@
 	'P0001' => $self->{_locale}->text('Error from Function:') . "\n" .
                     $self->{dbh}->errstr,
    };
-   print STDERR "Logging SQL State ".$self->{dbh}->state.", error ".
-           $self->{dbh}->err . ", string " .$self->{dbh}->errstr . "\n";
+   $logger->error("Logging SQL State ".$self->{dbh}->state.", error ".
+           $self->{dbh}->err . ", string " .$self->{dbh}->errstr);
    if (defined $state_error->{$self->{dbh}->state}){
        $self->error($state_error->{$self->{dbh}->state});
        exit;
@@ -886,6 +902,7 @@
         else {
             $dst_arg = $arg;
         }
+        $logger->debug("LedgerSMB.pm: merge setting $dst_arg to $src->{$arg}");
         $self->{$dst_arg} = $src->{$arg};
     }
 }

Modified: trunk/UI/Admin/edit_user.html
===================================================================
--- trunk/UI/Admin/edit_user.html	2010-01-27 18:51:31 UTC (rev 2851)
+++ trunk/UI/Admin/edit_user.html	2010-02-07 03:02:42 UTC (rev 2852)
@@ -57,6 +57,23 @@
                     <input type="textarea" name="employeenumber" value="<?lsmb user.employee.employeenumber?>"/>
                 </td>
             </tr>
+            <tr>
+                <td><?lsmb text('Country') ?></td>
+                <td>
+                    <?lsmb IF edit_location.country; 
+                        country_id = edit_location.country_id;
+                        ELSE; 
+                        country_id = default_country;
+                        END; -?>
+                    <?lsmb PROCESS select element_data = {
+                        name = "country_id"
+                        options = countries
+                        default_values = [country_id]
+                        value_attr = "id"
+                        text_attr = "name"
+                    } ?>
+                </td>
+            </tr>
         </table>
         <button type="submit" value="save_user"><?lsmb text('Save User') ?>
         </button>

Modified: trunk/UI/Contact/contact.html
===================================================================
--- trunk/UI/Contact/contact.html	2010-01-27 18:51:31 UTC (rev 2851)
+++ trunk/UI/Contact/contact.html	2010-02-07 03:02:42 UTC (rev 2852)
@@ -482,6 +482,25 @@
         </tr>
 
         </table>
+        <div class="input_container" id="tax-credit-div">
+        <div class="listtop"><?lsmb text('Taxes') ?></div>
+        <?lsmb FOR tx = all_taxes ?> 
+        <div class="inputrow" id="taxrow-<?lsmb tx.chart_id ?>">
+        <span class="lable" id="txlabel-<?lsmb tx.chart_id ?>">
+            <?lsmb tx.accno ?>--<?lsmb tx.description ?></span>
+        <span class="input" id="txinput-<?lsmb tx.id ?>">
+            <?lsmb checked = "";  
+                   IF eca_tax.grep(tx.chart_id);
+                       checked = "CHECKED";
+                   END;
+                   INCLUDE input element_data = {
+                           type = "checkbox"
+                           checked = checked
+                           name = "taxact_$tx.id"
+                           value = $tx.id
+                   } ?><span></div>
+        <?lsmb END # FOR tx ?>
+         </div>
 		<?lsmb IF credit_id;
 		INCLUDE button element_data = {
 			text = text('Save Changes'),

Modified: trunk/bin/initiate.pl
===================================================================
--- trunk/bin/initiate.pl	2010-01-27 18:51:31 UTC (rev 2851)
+++ trunk/bin/initiate.pl	2010-02-07 03:02:42 UTC (rev 2852)
@@ -4,7 +4,13 @@
 use LedgerSMB::User;
 use LedgerSMB::Initiate;
 use LedgerSMB::Auth;
+use LedgerSMB::Log;
+use Data::Dumper;
 
+my $logger = Log::Log4perl->get_logger('initiate');
+
+$logger->debug('start bin/initiate.pl');
+
 #use LedgerSMB::Session;
 
 $root="";
@@ -42,7 +48,7 @@
 if ( $form->{action} ) {
 
     &check_password unless $form->{action} eq 'logout';
-   
+
     &{ $form->{action} };
 
 }

Modified: trunk/initiate.pl
===================================================================
--- trunk/initiate.pl	2010-01-27 18:51:31 UTC (rev 2851)
+++ trunk/initiate.pl	2010-02-07 03:02:42 UTC (rev 2852)
@@ -53,6 +53,10 @@
 
 $| = 1;
 
+use LedgerSMB::Log;
+
+my $logger = Log::Log4perl->get_logger('initiate');
+
 if ( $ENV{CONTENT_LENGTH} > $LedgerSMB::Sysconfig::max_post_size ) {
     print "Status: 413\n Request entity too large\n\n";
     die "Error: Request entity too large\n";
@@ -62,14 +66,20 @@
     read( STDIN, $_, $ENV{CONTENT_LENGTH} );
 }
 
+$logger->debug("initiate.pl: \$_ = $_\n");
+
 if ( $ENV{QUERY_STRING} ) {
     $_ = $ENV{QUERY_STRING};
 }
 
+$logger->debug("initiate.pl: \$_ = $_\n");
+
 if ( $ARGV[0] ) {
     $_ = $ARGV[0];
 }
 
+$logger->debug("initiate.pl: \$_ = $_\n");
+
 %form = split /[&=]/;
 
 # fix for apache 2.0 bug
@@ -80,6 +90,8 @@
 $pos = rindex $0, '/';
 $script = substr( $0, $pos + 1 );
 
+$logger->debug("initiate.pl: \$script = $script\n");
+
 #this needs to be a db based function
 #if (-e "${LedgerSMB::Sysconfig::userspath}/nologin" && $script ne 'admin.pl') {
 #	print "Content-Type: text/html\n\n<html><body><strong>";

Modified: trunk/lsmb-request.pl
===================================================================
--- trunk/lsmb-request.pl	2010-01-27 18:51:31 UTC (rev 2851)
+++ trunk/lsmb-request.pl	2010-02-07 03:02:42 UTC (rev 2852)
@@ -30,12 +30,22 @@
 use LedgerSMB;
 use LedgerSMB::Locale;
 use Data::Dumper;
+use LedgerSMB::Log;
 use strict;
 
+my $logger = Log::Log4perl->get_logger('');
+
+$logger->debug("Begin lsmb-request.pl");
+
 # for custom preprocessing logic
 eval { require "custom.pl"; };
 
+$logger->debug("lsmb-request.pl: getting request");
+
 my $request = new LedgerSMB;
+
+$logger->debug("lsmb-request.pl: Got request");
+
 $request->{action} = '__default' if (!$request->{action});
 
 $ENV{SCRIPT_NAME} =~ m/([^\/\\]*.pl)\?*.*$/;
@@ -47,8 +57,12 @@
 	$request->error($locale->text('No workflow script specified'));
 }
 
+$logger->debug("calling $script");
+
 &call_script( $script, $request );
 
+$logger->debug("End lsmb-request.pl");
+
 sub call_script {
         
     my $script = shift @_;

Modified: trunk/scripts/admin.pl
===================================================================
--- trunk/scripts/admin.pl	2010-01-27 18:51:31 UTC (rev 2851)
+++ trunk/scripts/admin.pl	2010-02-07 03:02:42 UTC (rev 2852)
@@ -9,7 +9,10 @@
 use LedgerSMB::DBObject::Location;
 use Data::Dumper;
 use LedgerSMB::Setting;
+use LedgerSMB::Log;
 
+my $logger = Log::Log4perl->get_logger('LedgerSMB::Scripts::admin');
+
 sub __edit_page {
     
     
@@ -85,6 +88,7 @@
     
     my $groups = $admin->get_roles();
     
+    $logger->debug("scripts/admin.pl new_user: \$user = " . Data::Dumper::Dumper($user));
     
         my $template = LedgerSMB::Template->new( 
             user => $user, 

Modified: trunk/sql/modules/Account.sql
===================================================================
--- trunk/sql/modules/Account.sql	2010-01-27 18:51:31 UTC (rev 2851)
+++ trunk/sql/modules/Account.sql	2010-02-07 03:02:42 UTC (rev 2852)
@@ -5,6 +5,14 @@
 $$
      select * from account where accno = $1;
 $$ language sql;
+CREATE OR REPLACE FUNCTION account__get_taxes()
+RETURNS setof account AS
+$$
+SELECT * FROM account 
+ WHERE id IN (select account_id from account_link 
+               where description ilike '%tax%')
+ORDER BY accno;
+$$ language sql;
 
 CREATE OR REPLACE FUNCTION account_get (in_id int) RETURNS chart AS
 $$

Modified: trunk/sql/modules/Company.sql
===================================================================
--- trunk/sql/modules/Company.sql	2010-01-27 18:51:31 UTC (rev 2851)
+++ trunk/sql/modules/Company.sql	2010-02-07 03:02:42 UTC (rev 2852)
@@ -89,8 +89,51 @@
 		RETURN NEXT out_row;
 	END LOOP;
 END;
-$$ language plpgsql;	
+$$ language plpgsql;
 
+CREATE OR REPLACE FUNCTION eca__get_taxes(in_credit_id int)
+returns setof customertax AS
+$$
+select * from customertax where customer_id = $1
+union
+select * from vendortax where vendor_id = $1;
+$$ language sql;
+
+CREATE OR REPLACE FUNCTION eca__set_taxes(in_credit_id int, in_tax_ids int[])
+RETURNS bool AS
+$$
+DECLARE 
+    eca entity_credit_account;
+    iter int;
+BEGIN
+     SELECT * FROM entity_credit_account into eca WHERE id = in_credit_id;
+
+     IF eca.entity_class = 1 then
+        FOR iter in array_lower(in_tax_ids, 1) .. array_upper(in_tax_ids, 1)
+        LOOP
+             INSERT INTO customertax (customer_id, chart_id)
+             values (in_credit_id, in_tax_ids[iter]);
+        END LOOP;
+     ELSIF eca.entity_class = 2 then
+        FOR iter in array_lower(in_tax_ids, 1) .. array_upper(in_tax_ids, 1)
+        LOOP
+             INSERT INTO vendortax (vendor_id, chart_id)
+             values (in_credit_id, in_tax_ids[iter]);
+        END LOOP;
+        
+     ELSE 
+        RAISE EXCEPTION 'Wrong entity class or credit account not found!';
+     END IF;
+     RETURN TRUE;
+end;
+$$ language plpgsql;
+
+comment on function eca__set_taxes(in_credit_id int, in_tax_ids int[]) is
+$$
+The entity credit account must exist before calling this function, and must
+have a type of either 1 or 2.
+$$;
+
 CREATE OR REPLACE FUNCTION entity__save_notes(in_entity_id int, in_note text, in_subject text)
 RETURNS INT AS
 $$

Modified: trunk/sql/modules/Person.sql
===================================================================
--- trunk/sql/modules/Person.sql	2010-01-27 18:51:31 UTC (rev 2851)
+++ trunk/sql/modules/Person.sql	2010-02-07 03:02:42 UTC (rev 2852)
@@ -5,7 +5,8 @@
 
 CREATE OR REPLACE FUNCTION person__save
 (in_entity_id integer, in_salutation_id int, 
-in_first_name text, in_middle_name text, in_last_name text    
+in_first_name text, in_middle_name text, in_last_name text,
+in_country_id integer
 )
 RETURNS INT AS $$
 
@@ -21,8 +22,8 @@
     e_id := in_entity_id; 
     
     IF NOT FOUND THEN
-        INSERT INTO entity (name, entity_class) 
-	values (in_first_name || ' ' || in_last_name, 3);
+        INSERT INTO entity (name, entity_class, country_id) 
+	values (in_first_name || ' ' || in_last_name, 3, in_country_id);
 	e_id := currval('entity_id_seq');
        
     END IF;


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