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

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



Revision: 2617
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2617&view=rev
Author:   einhverfr
Date:     2009-06-03 16:53:32 +0000 (Wed, 03 Jun 2009)

Log Message:
-----------
tax form adjustments

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Admin.pm
    trunk/LedgerSMB/DBObject/User.pm
    trunk/LedgerSMB/TaxForm.pm
    trunk/LedgerSMB.pm
    trunk/UI/taxform/add_taxform.html
    trunk/sql/modules/admin.sql

Modified: trunk/LedgerSMB/DBObject/Admin.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Admin.pm	2009-06-01 16:11:57 UTC (rev 2616)
+++ trunk/LedgerSMB/DBObject/Admin.pm	2009-06-03 16:53:32 UTC (rev 2617)
@@ -27,8 +27,8 @@
     $self->{entity_id} = $entity->{entity};
     
     
-    my $user_id = shift @{ $self->exec_method( funcname => "admin__save_user" ) };
-    $self->merge($user_id);
+    my ($user_id) = $self->exec_method( funcname => "admin__save_user" );
+    $self->{user_id} = $user_id->{admin__save_user};
     
     my $employee = LedgerSMB::DBObject::Employee->new( base=>$self, copy=>'list',
         merge=>[
@@ -41,6 +41,21 @@
     
     $employee->{entity_id} = $entity_id->{id};    
     $employee->save();
+    # now, check for user-specific stuff. Is this person a user or not?
+    
+    my $user = LedgerSMB::DBObject::User->new(base=>$self, copy=>'list',
+        merge=>[
+            'username',
+            'password',
+            'is_a_user',
+            'user_id',
+        ]
+    );
+    $user->get();
+    $user->save();
+    $self->{user} = $user;
+    $self->{employee} = $employee;
+    $self->debug({file => '/tmp/user11'});
 
     if ($self->{password}){
        return;
@@ -73,20 +88,6 @@
     $homephone->save();
     $email->save();
     
-    # now, check for user-specific stuff. Is this person a user or not?
-    
-    my $user = LedgerSMB::DBObject::User->new(base=>$self, copy=>'list',
-        merge=>[
-            'username',
-            'password',
-            'is_a_user'
-        ]
-    );
-    $user->get();
-    $user->save();
-    $self->{user} = $user;
-    $self->{employee} = $employee;
-    $user->debug({file => '/tmp/user11'});
 }
 
 sub save_roles {

Modified: trunk/LedgerSMB/DBObject/User.pm
===================================================================
--- trunk/LedgerSMB/DBObject/User.pm	2009-06-01 16:11:57 UTC (rev 2616)
+++ trunk/LedgerSMB/DBObject/User.pm	2009-06-03 16:53:32 UTC (rev 2617)
@@ -136,34 +136,37 @@
     
     my $self = shift @_;
     my $id = shift;
-    my @users = $self->exec_method(
+    if ($id){
+        $self->{user_id} = $id;
+    }
+    my ($user) = $self->exec_method(
         funcname=>'admin__get_user',
-        args=>[$id]
         );
-    $self->{user} = $users[0];
-    my @prefs = $self->exec_method(
-        funcname=>'admin__user_preferences',
-        args=>[$id]
+    print STDERR "Point 1\n";
+    $self->{user} = $user;
+    my ($prefs) = $self->exec_method(
+        funcname=>'user__get_preferences',
         );
-    $self->{pref} = $prefs[0];
+    print STDERR "Point 1\n";
+    $self->{prefs} = $prefs;
+    print STDERR "Point 2\n";
 #    $self->{person} = @{ $self->exec_method(
 #        funcname=>'admin__user_preferences',
 #        args=>[$self->{user}->{entity_id}]
 #        )
 #    }[0];
-    my @emp = $self->exec_method(
+    my ($emp) = $self->exec_method(
         funcname=>'employee__get',
         args=>[$self->{user}->{entity_id}]
         );
-    $self->{employee} = $emp[0];
-    my @ent = $self->exec_method( 
+    $self->{employee} = $emp;
+    my ($ent) = $self->exec_method( 
         funcname=>'entity__get_entity',
         args=>[ $self->{user}->{entity_id} ] 
         );
-    $self->{entity} = $ent[0];
+    $self->{entity} = $ent;
     my @roles = $self->exec_method(
         funcname=>'admin__get_roles_for_user',
-        args=>[$id]
     );
     # Now, location and stuff.
     my @loc = $self->exec_method(

Modified: trunk/LedgerSMB/TaxForm.pm
===================================================================
--- trunk/LedgerSMB/TaxForm.pm	2009-06-01 16:11:57 UTC (rev 2616)
+++ trunk/LedgerSMB/TaxForm.pm	2009-06-03 16:53:32 UTC (rev 2617)
@@ -32,6 +32,8 @@
                 funcname => 'location_list_country'
     );
 
+    my ($ref) = $self->call_procedure(procname => 'setting_get', args => ['default_country']);
+    $self->{default_country} = $ref->{setting_get};
 }
 
 1;

Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm	2009-06-01 16:11:57 UTC (rev 2616)
+++ trunk/LedgerSMB.pm	2009-06-03 16:53:32 UTC (rev 2617)
@@ -812,8 +812,10 @@
 	'42501' => $self->{_locale}->text('Access Denied'),
 	'22008' => $self->{_locale}->text('Invalid date/time entered'),
 	'22012' => $self->{_locale}->text('Division by 0 error'),
-	'22004' => $self->{_locale}->text('Required input not provided')
-	#'23502' => $self->{_locale}->text('Required input not provided')
+	'22004' => $self->{_locale}->text('Required input not provided'),
+	'P0001' => $self->{_locale}->text('Error from Function:') . " " .
+                    $self->{dbh}->errstr,
+	'23502' => $self->{_locale}->text('Required input not provided'),
    };
    print STDERR "Logging SQL State ".$self->{dbh}->state.", error ".
            $self->{dbh}->err . ", string " .$self->{dbh}->errstr . "\n";

Modified: trunk/UI/taxform/add_taxform.html
===================================================================
--- trunk/UI/taxform/add_taxform.html	2009-06-01 16:11:57 UTC (rev 2616)
+++ trunk/UI/taxform/add_taxform.html	2009-06-03 16:53:32 UTC (rev 2617)
@@ -17,7 +17,7 @@
 <?lsmb IF countries ?>
  <?lsmb PROCESS select element_data = {
 		name = "country_code"
-		default_values = []
+		default_values = [default_country]
 		options = countries
 		value_attr = "id"
 		text_attr = "name"

Modified: trunk/sql/modules/admin.sql
===================================================================
--- trunk/sql/modules/admin.sql	2009-06-01 16:11:57 UTC (rev 2616)
+++ trunk/sql/modules/admin.sql	2009-06-03 16:53:32 UTC (rev 2617)
@@ -15,7 +15,7 @@
     
 );
 
-CREATE OR REPLACE FUNCTION admin__add_user_to_role(in_user TEXT, in_role TEXT) returns INT AS $$
+CREATE OR REPLACE FUNCTION admin__add_user_to_role(in_username TEXT, in_role TEXT) returns INT AS $$
     
     declare
         stmt TEXT;
@@ -30,16 +30,16 @@
             RAISE EXCEPTION 'Cannot grant permissions of a non-existant role.';
         END IF;
         
-        select rolname into a_user from pg_roles where rolname = in_user;
+        select rolname into a_user from pg_roles where rolname = in_username;
         
         IF NOT FOUND THEN
             RAISE EXCEPTION 'Cannot grant permissions to a non-existant user.';
         END IF;
         
-        stmt := 'GRANT '|| quote_ident(in_role) ||' to '|| quote_ident(in_user);
+        stmt := 'GRANT '|| quote_ident(in_role) ||' to '|| quote_ident(in_username);
         
         EXECUTE stmt;
-        insert into lsmb_roles (user_id, role) values (in_user, in_role);
+        insert into lsmb_roles (user_id, role) values (in_username, in_role);
         return 1;
     END;
     
@@ -47,7 +47,7 @@
 
 REVOKE EXECUTE ON FUNCTION admin__add_user_to_role(TEXT, TEXT) FROM PUBLIC;
 
-CREATE OR REPLACE FUNCTION admin__remove_user_from_role(in_user TEXT, in_role TEXT) returns INT AS $$
+CREATE OR REPLACE FUNCTION admin__remove_user_from_role(in_username TEXT, in_role TEXT) returns INT AS $$
     
     declare
         stmt TEXT;
@@ -62,13 +62,13 @@
             RAISE EXCEPTION 'Cannot revoke permissions of a non-existant role.';
         END IF;
         
-        select rolname into a_user from pg_roles where rolname = in_user;
+        select rolname into a_user from pg_roles where rolname = in_username;
         
         IF NOT FOUND THEN
             RAISE EXCEPTION 'Cannot revoke permissions from a non-existant user.';
         END IF;
         
-        stmt := 'REVOKE '|| quote_ident(in_role) ||' FROM '|| quote_ident(in_user);
+        stmt := 'REVOKE '|| quote_ident(in_role) ||' FROM '|| quote_ident(in_username);
         
         EXECUTE stmt;
         
@@ -94,7 +94,7 @@
             RAISE EXCEPTION 'Cannot grant permissions of a non-existant role.';
         END IF;
         
-        select rolname into a_user from pg_roles where rolname = in_user;
+        select rolname into a_user from pg_roles where rolname = in_username;
         
         IF NOT FOUND THEN
             RAISE EXCEPTION 'Cannot grant permissions to a non-existant user.';
@@ -126,7 +126,7 @@
             RAISE EXCEPTION 'Cannot revoke permissions of a non-existant role.';
         END IF;
         
-        select rolname into a_user from pg_roles where rolname = in_user;
+        select rolname into a_user from pg_roles where rolname = in_username;
         
         IF NOT FOUND THEN
             RAISE EXCEPTION 'Cannot revoke permissions from a non-existant function.';
@@ -215,15 +215,15 @@
         
 --$$ language 'plpgsql';
 
-create or replace function admin__get_user(in_user INT) returns setof users as $$
+create or replace function admin__get_user(in_user_id INT) returns setof users as $$
     
     DECLARE
         a_user users;
     BEGIN
         
-        select * into a_user from users where id = in_user;
+        select * into a_user from users where id = in_user_id;
         IF NOT FOUND THEN
-            RAISE EXCEPTION 'cannot find user %', in_user;
+            RAISE EXCEPTION 'cannot find user %', in_user_id;
         END IF;
         
         return next a_user;
@@ -328,6 +328,9 @@
         select * into a_user from users lu where lu.id = in_id;
         
         IF NOT FOUND THEN 
+            if in_password IS NULL THEN
+                RAISE EXCEPTION 'Must create password when adding new users!';
+            end if;
             -- Insert cycle
             
             --- The entity is expected to already BE created. See admin.pm.
@@ -360,12 +363,13 @@
         ELSIF FOUND THEN
             
             -- update cycle
+            IF in_password IS NOT NULL THEN
             
-            execute ' alter user '|| quote_ident(in_username) || 
+                execute ' alter user '|| quote_ident(in_username) || 
                      ' with encrypted password ' 
                              || quote_literal(in_password) || 
                      $e$ valid until now()::timezone + '1 day'::interval $e$;
-            
+            end if;
                       
             return a_user.id;
         
@@ -588,16 +592,16 @@
 END;
 $$ language plpgsql;
 
-create or replace function user__get_preferences (in_user int) returns setof user_preference as $$
+create or replace function user__get_preferences (in_user_id int) returns setof user_preference as $$
     
 declare
     v_row user_preference;
 BEGIN
-    select * into v_row from user_preference where id = in_user;
+    select * into v_row from user_preference where id = in_user_id;
     
     IF NOT FOUND THEN
     
-        RAISE EXCEPTION 'Could not find user preferences for id %', in_user;
+        RAISE EXCEPTION 'Could not find user preferences for id %', in_user_id;
     ELSE
         return next v_row;
     END IF;


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