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

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



Revision: 1795
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1795&view=rev
Author:   einhverfr
Date:     2007-10-18 23:05:41 -0700 (Thu, 18 Oct 2007)

Log Message:
-----------
Some voucher fixes

Modified Paths:
--------------
    trunk/LedgerSMB/Batch.pm
    trunk/LedgerSMB/DBObject.pm
    trunk/LedgerSMB/GL.pm
    trunk/LedgerSMB/Session/DB.pm
    trunk/LedgerSMB.pm
    trunk/UI/create_batch.html
    trunk/common.pl
    trunk/scripts/vouchers.pl
    trunk/sql/modules/Voucher.sql

Modified: trunk/LedgerSMB/Batch.pm
===================================================================
--- trunk/LedgerSMB/Batch.pm	2007-10-19 03:32:46 UTC (rev 1794)
+++ trunk/LedgerSMB/Batch.pm	2007-10-19 06:05:41 UTC (rev 1795)
@@ -3,4 +3,11 @@
 package LedgerSMB::Batch;
 use base qw(LedgerSMB::DBObject);
 
+sub create {
+    $self = shift @_;
+    my ($ref) = $self->exec_method(funcname => 'batch_create');
+    $self->{id} = $ref->{id}
+    return $ref->{id};
+}
+
 1;

Modified: trunk/LedgerSMB/DBObject.pm
===================================================================
--- trunk/LedgerSMB/DBObject.pm	2007-10-19 03:32:46 UTC (rev 1794)
+++ trunk/LedgerSMB/DBObject.pm	2007-10-19 06:05:41 UTC (rev 1795)
@@ -107,7 +107,7 @@
      
     my $query = "SELECT proname, pronargs, proargnames FROM pg_proc WHERE proname = ?";
     my $sth   = $self->{dbh}->prepare($query);
-    $sth->execute($funcname);
+    $sth->execute($funcname) || $self->error($DBI::errstr . "in exec_method");
     my $ref;
 
     $ref = $sth->fetchrow_hashref('NAME_lc');

Modified: trunk/LedgerSMB/GL.pm
===================================================================
--- trunk/LedgerSMB/GL.pm	2007-10-19 03:32:46 UTC (rev 1794)
+++ trunk/LedgerSMB/GL.pm	2007-10-19 06:05:41 UTC (rev 1795)
@@ -101,12 +101,11 @@
         $uid .= "$$";
 
         $query = qq|
-		INSERT INTO gl (reference, employee_id)
-		     VALUES ('$uid', (SELECT id FROM employee
-		                       WHERE login = ?))|;
+		INSERT INTO gl (reference)
+		     VALUES ('$uid')|;
 
         $sth = $dbh->prepare($query);
-        $sth->execute( $form->{login} ) || $form->dberror($query);
+        $sth->execute() || $form->dberror($query);
 
         $query = qq|
 			SELECT id 

Modified: trunk/LedgerSMB/Session/DB.pm
===================================================================
--- trunk/LedgerSMB/Session/DB.pm	2007-10-19 03:32:46 UTC (rev 1794)
+++ trunk/LedgerSMB/Session/DB.pm	2007-10-19 06:05:41 UTC (rev 1795)
@@ -182,7 +182,7 @@
     }
     $deleteExisting->execute( $login)
       || $lsmb->dberror(
-        __FILE__ . ':' . __LINE__ . ': Delete from session: ' );
+        __FILE__ . ':' . __LINE__ . ': Delete from session: ' . $DBI::errstr);
 
 #doing the random stuff in the db so that LedgerSMB won't
 #require a good random generator - maybe this should be reviewed, 

Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm	2007-10-19 03:32:46 UTC (rev 1794)
+++ trunk/LedgerSMB.pm	2007-10-19 06:05:41 UTC (rev 1795)
@@ -688,7 +688,7 @@
     $sth->execute;
     my ($dbversion) = $sth->fetchrow_array;
     if ($dbversion ne $self->{dbversion}){
-        $self->error("Database is not the expected version.");
+        $self->error("Database is not the expected version.  Was $dbversion, expected $self->{dbversion}");
     }
 
 
@@ -710,6 +710,12 @@
     }
 }
 
+# Deprecated, only here for old code
+sub dberror{
+   my $self = shift @_;
+   $self->error(@_);
+}
+
 sub redo_rows {
 
     my $self  = shift @_;

Modified: trunk/UI/create_batch.html
===================================================================
--- trunk/UI/create_batch.html	2007-10-19 03:32:46 UTC (rev 1794)
+++ trunk/UI/create_batch.html	2007-10-19 06:05:41 UTC (rev 1795)
@@ -41,7 +41,7 @@
   </div>
 </div>
 <div id="buttons">
-<button value="create_batch" type="submit" class="submit">
+<button value="create_vouchers" type="submit" class="submit" name="action">
 <?lsmb text('Continue') ?></button>
 </div>
 <?lsmb FOREACH item = hidden ?>

Modified: trunk/common.pl
===================================================================
--- trunk/common.pl	2007-10-19 03:32:46 UTC (rev 1794)
+++ trunk/common.pl	2007-10-19 06:05:41 UTC (rev 1795)
@@ -57,7 +57,7 @@
     $form->{script} = $script;
 
     if ( !$myconfig ) {    # needed for login
-        %myconfig = %{ LedgerSMB::User->fetch_config( $form->{login} ) };
+        %myconfig = %{ LedgerSMB::User->fetch_config( $form ) };
     }
     if ( !$form->{dbh} and ( $script ne 'admin.pl' ) ) {
         $form->db_init( \%myconfig );

Modified: trunk/scripts/vouchers.pl
===================================================================
--- trunk/scripts/vouchers.pl	2007-10-19 03:32:46 UTC (rev 1794)
+++ trunk/scripts/vouchers.pl	2007-10-19 06:05:41 UTC (rev 1795)
@@ -16,7 +16,7 @@
 sub create_batch {
     my ($request) = @_;
     $request->{hidden} = [
-        batch_type => $request->{batch_type},
+        {name => "batch_type", value => $request->{batch_type}},
     ];
     my $template = LedgerSMB::Template->new(
         user =>$request->{_user}, 
@@ -33,15 +33,40 @@
     #  This is because these scripts import all functions into the *current*
     #  namespace.  People using fastcgi and modperl should *not* cache this 
     #  module at the moment. -- CT
-    my %vouchers_dispatch = (
+    my ($request) = shift @_;
+    use LedgerSMB::Form;
+
+    my $batch = LedgerSMB::Batch->new({base => $request});
+    $batch->create;
+
+    my $vouchers_dispatch = 
+    {
         payable    => {script => 'bin/ap.pl', function => sub {add()}},
         receivable => {script => 'bin/ar.pl', function => sub {add()}},
         payments   => {script => 'bin/cp.pl', function => sub {payments()}},
         receipts   => {script => 'bin/cp.pl', function => sub {receipts()}},
-        gl         => {script => 'bin/gl.pl'. function => sub {add()}},
-    )
-    require $vouchers_dispatch{$request->{batch_type}}{script}
-    $vouchers_dispatch{$request->{batch_type}}{function}();
+        gl         => {script => 'bin/gl.pl', function => sub {add()}},
+    };
+
+    # Note that the line below is generally considered incredibly bad form. 
+    # However, the code we are including is going to require it for now.
+    no strict;
+    our $form = new Form;
+    our $locale = $request->{_locale};
+    for (keys %$request){
+        $form->{$_} = $request->{$_};
+    }
+
+    $form->{approved} = 0;
+    $form->{transdate} = $request->{batch_date};
+    print STDERR "$request->{batch_type}\n";
+    require $vouchers_dispatch->{$request->{batch_type}}{script};
+
+    my $script = $vouchers_dispatch->{$request->{batch_type}}{script};
+    $script =~ s|.*/||;
+    $form->{script} = $script;
+
+\    $vouchers_dispatch->{$request->{batch_type}}{function}();
 }
 
 sub list_vouchers {

Modified: trunk/sql/modules/Voucher.sql
===================================================================
--- trunk/sql/modules/Voucher.sql	2007-10-19 03:32:46 UTC (rev 1794)
+++ trunk/sql/modules/Voucher.sql	2007-10-19 06:05:41 UTC (rev 1795)
@@ -193,7 +193,7 @@
 $$
 DECLARE
 	control_amount NUMERIC;
-	voucher vouchers%ROWTYPE; 
+	voucher voucher%ROWTYPE; 
 	incriment NUMERIC;
 BEGIN
 --  CHECK CONTROL NUMBERS
@@ -204,7 +204,7 @@
 				SELECT id FROM gl 
 				WHERE coalesce(approved, false) != true)
 			AND trans_id IN (
-				SELECT transaction_id FROM vouchers 
+				SELECT transaction_id FROM voucher 
 				WHERE batch_id = ANY (in_batch_id))
 			AND coalesce(approved, false) != true
 			AND amount > 0
@@ -214,7 +214,7 @@
 
 		SELECT sum(ac.amount) INTO control_amount 
 		FROM acc_trans ac
-		JOIN vouchers v ON (v.transaction_id = ac.trans_id)
+		JOIN voucher v ON (v.transaction_id = ac.trans_id)
 		WHERE v.batch_id = ANY (in_batch_id)
 			AND ac.vr_id = v.id
 			AND coalesce(approved, false) = false
@@ -224,7 +224,7 @@
 		SELECT sum(amount) INTO control_amount
 		FROM acc_trans 
 		WHERE trans_id IN
-				(SELECT transaction_id FROM vouchers 
+				(SELECT transaction_id FROM voucher 
 				WHERE batch_id = ANY (in_batch_id))
 			AND trans_id IN
 				(SELECT trans_id FROM ap 
@@ -245,20 +245,20 @@
 		UPDATE acc_trans 
 		SET approved = true 
 		WHERE trans_id IN 
-			(SELECT transaction_id FROM vouchers
+			(SELECT transaction_id FROM voucher
 			WHERE batch_id = ANY (in_batch_id));
 
 		IF in_batch = 'gl' THEN
 
 			UPDATE gl SET approved = true
 			WHERE trans_id IN
-				(SELECT transaction_id FROM vouchers
+				(SELECT transaction_id FROM voucher
 				WHERE batch_id = ANY (in_batch_id));
 
 		ELSE 
 			UPDATE ap SET approved = true
 			WHERE trans_id IN
-				(SELECT transaction_id FROM vouchers
+				(SELECT transaction_id FROM voucher
 				WHERE batch_id = ANY (in_batch_id));
 		END IF;
 	END IF;
@@ -266,3 +266,18 @@
 	RETURN TRUE;
 END;
 $$ LANGUAGE PLPGSQL;
+
+
+CREATE OR REPLACE FUNCTION batch_create(
+in_batch_number text, in_description text, in_batch_class text) RETURNS int AS
+$$
+BEGIN
+	INSERT INTO 
+		batch (batch_class_id, description, control_code, created_by)
+	VALUES ((SELECT id FROM batch_class WHERE class = in_batch_class),
+		in_description, in_batch_number, 
+			(select id FROM users WHERE username = session_user));
+
+	return currval('batch_id_seq');
+END;	
+$$ LANGUAGE PLPGSQL;


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