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

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



Revision: 1982
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1982&view=rev
Author:   einhverfr
Date:     2007-12-19 09:25:47 -0800 (Wed, 19 Dec 2007)

Log Message:
-----------
More batch enhancements

Modified Paths:
--------------
    trunk/COMPATABILITY
    trunk/LedgerSMB/Batch.pm
    trunk/LedgerSMB/DBObject/Payment.pm
    trunk/UI/form-dynatable.html
    trunk/sql/modules/Payment.sql
    trunk/sql/modules/Voucher.sql

Modified: trunk/COMPATABILITY
===================================================================
--- trunk/COMPATABILITY	2007-12-18 02:26:20 UTC (rev 1981)
+++ trunk/COMPATABILITY	2007-12-19 17:25:47 UTC (rev 1982)
@@ -6,6 +6,11 @@
 These versions produce an error concerning wrong data types but the error shows 
 that the data types are indeed correct.
 
+PostgreSQL 8.3 will be supported on a best effort basis.  You will need the 
+tsearch2 compatibility libraries.  Additionally, due to the changes in implicit 
+casts, bugs may exist which cause database operations to abort.  We do accept 
+bug reports and will address them, however.
+
 -------------------------------
 
 W3M does not handle the <BUTTON> element properly and does not work.

Modified: trunk/LedgerSMB/Batch.pm
===================================================================
--- trunk/LedgerSMB/Batch.pm	2007-12-18 02:26:20 UTC (rev 1981)
+++ trunk/LedgerSMB/Batch.pm	2007-12-19 17:25:47 UTC (rev 1982)
@@ -28,4 +28,16 @@
     return @{$self->{search_results}};
 }
 
+sub post {
+    my ($self) = @_;
+    ($self->{post_return_ref}) = $self->exec_method(funcname => 'batch_post');
+    return $self->{post_return_ref};
+}
+
+sub delete {
+    my ($self) = @_;
+    ($self->{delete_ref}) = $self->exec_method(funcname => 'batch_delete');
+    return $self->{delete_ref};
+}
+
 1;

Modified: trunk/LedgerSMB/DBObject/Payment.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Payment.pm	2007-12-18 02:26:20 UTC (rev 1981)
+++ trunk/LedgerSMB/DBObject/Payment.pm	2007-12-19 17:25:47 UTC (rev 1982)
@@ -366,14 +366,19 @@
 	if ($source_src) {
 		$source_inc = $source_src;
 	} else {
-		$source_inc = $0;
+		$source_inc = 0;
 	}
     }
+    my $source_length = length($source_inc);
+   
     @{$self->{contact_invoices}} = $self->exec_method(
 		funcname => 'payment_get_all_contact_invoices');
     for my $inv (@{$self->{contact_invoices}}){
         if (defined $self->{source_start}){
 		my $source = $self->{source_start};
+		if (length($source_inc) < $source_length){
+                    $source_inc = sprintf('%0*s', $source_length, $source_inc);
+                }
 		$source =~ s/$source_src(\D*)$/$source_inc$1/;
 		++ $source_inc;
 		$inv->{source} = $source;

Modified: trunk/UI/form-dynatable.html
===================================================================
--- trunk/UI/form-dynatable.html	2007-12-18 02:26:20 UTC (rev 1981)
+++ trunk/UI/form-dynatable.html	2007-12-19 17:25:47 UTC (rev 1982)
@@ -15,6 +15,7 @@
 <?lsmb PROCESS elements.html ?> 
 
 <body>
+<form method="post" action="<?lsmb form.script ?>">
 
 <table width="100%">
   <tr>
@@ -83,7 +84,6 @@
 
 <br />
 
-<form method="post" action="<?lsmb form.script ?>">
 <?lsmb FOREACH hidden IN hiddens.keys;
 	PROCESS input element_data={
 		type => 'hidden',

Modified: trunk/sql/modules/Payment.sql
===================================================================
--- trunk/sql/modules/Payment.sql	2007-12-18 02:26:20 UTC (rev 1981)
+++ trunk/sql/modules/Payment.sql	2007-12-19 17:25:47 UTC (rev 1982)
@@ -312,6 +312,8 @@
 	t_voucher_id int;
 	t_trans_id int;
 	t_amount numeric;
+        t_ar_ap_id int;
+	t_cash_id int;
 BEGIN
 	IF in_batch_id IS NULL THEN
 		-- t_voucher_id := NULL;
@@ -322,21 +324,21 @@
 
 		t_voucher_id := currval('voucher_id_seq');
 	END IF;
+
+	select id into t_ar_ap_id from chart where accno = in_ar_ap_accno;
+	select id into t_cash_id from chart where accno = in_cash_accno;
+
 	FOR out_count IN 
-		array_lower(in_transactions, 1) .. 
-		array_upper(in_transactions, 1)
+			array_lower(in_transactions, 1) ..
+			array_upper(in_transactions, 1)
 	LOOP
 		INSERT INTO acc_trans 
 			(trans_id, chart_id, amount, approved, voucher_id,
 			transdate)
 		VALUES
 			(in_transactions[out_count][1], 
-				case when in_account_class = 1 THEN 
-					(SELECT id FROM chart 
-					WHERE accno = in_cash_accno)
-				WHEN in_account_class = 2 THEN 
-					(SELECT id FROM chart 
-					WHERE accno = in_ar_ap_accno)
+				case when in_account_class = 1 THEN t_cash_id
+				WHEN in_account_class = 2 THEN t_ar_ap_id
 				ELSE -1 END,
 
 				in_transactions[out_count][2],
@@ -346,12 +348,8 @@
 				t_voucher_id, in_payment_date),
 
 			(in_transactions[out_count][1], 
-				case when in_account_class = 1 THEN 
-					(SELECT id FROM chart 
-					WHERE accno = in_ar_ap_accno)
-				WHEN in_account_class = 2 THEN 
-					(SELECT id FROM chart 
-					WHERE accno = in_cash_accno)
+				case when in_account_class = 1 THEN t_ar_ap_id
+				WHEN in_account_class = 2 THEN t_cash_id
 				ELSE -1 END,
 
 				in_transactions[out_count][2]* -1,

Modified: trunk/sql/modules/Voucher.sql
===================================================================
--- trunk/sql/modules/Voucher.sql	2007-12-18 02:26:20 UTC (rev 1981)
+++ trunk/sql/modules/Voucher.sql	2007-12-19 17:25:47 UTC (rev 1982)
@@ -11,7 +11,7 @@
 $$ language plpgsql;
 
 
-CREATE OR REPLACE FUNCTION batch_post (in_batch text, in_login varchar, in_entered date,
+CREATE OR REPLACE FUNCTION batch_update (in_batch text, in_login varchar, in_entered date,
 	in_batch_number text, in_description text, in_id integer) 
 RETURNS integer AS
 $$
@@ -53,32 +53,43 @@
 BEGIN
     	FOR voucher_item IN
 		SELECT v.id, a.invnumber, e.name, v.batch_id, v.trans_id, 
-			a.amount - a.paid, a.transdate, 'Payable'
+			a.amount, a.transdate, 'Payable'
 		FROM voucher v
 		JOIN ap a ON (v.trans_id = a.id)
 		JOIN entity e ON (a.entity_id = e.id)
 		WHERE v.batch_id = in_batch_id 
 			AND v.batch_class = (select id from batch_class 
-					WHERE class = 'payable')
+					WHERE class = 'ap')
 		UNION
 		SELECT v.id, a.invnumber, e.name, v.batch_id, v.trans_id, 
-			a.amount - a.paid, a.transdate, 'Receivable'
+			a.amount, a.transdate, 'Receivable'
 		FROM voucher v
 		JOIN ar a ON (v.trans_id = a.id)
 		JOIN entity e ON (a.entity_id = e.id)
 		WHERE v.batch_id = in_batch_id 
 			AND v.batch_class = (select id from batch_class 
-					WHERE class = 'receivable')
+					WHERE class = 'ar')
 		UNION
+		-- TODO:  Add the class labels to the class table.
 		SELECT v.id, a.source, a.memo, v.batch_id, v.trans_id, 
-			a.amount, a.transdate, bc.class
+			CASE WHEN bc.class LIKE 'payment%' THEN a.amount * -1
+			     ELSE amount  END, a.transdate, 
+			CASE WHEN bc.class = 'payment' THEN 'Payment'
+			     WHEN bc.class = 'receipt' THEN 'Receipt'
+			     WHEN bc.class = 'payment_reversal' 
+			     THEN 'Payment Reversal'
+			     WHEN bc.class = 'receipt_reversal' 
+			     THEN 'Receipt Reversal'
+			     ELSE 'UNKNOWN'
+			END
 		FROM voucher v
 		JOIN acc_trans a ON (v.trans_id = a.trans_id)
                 JOIN batch_class bc ON (bc.id = v.batch_class)
+		JOIN chart c ON (a.chart_id = c.id)
 		WHERE v.batch_id = in_batch_id 
 			AND a.voucher_id = v.id
-			AND bc.class like 'payment%'
-			OR bc.class like 'receipt%'
+			AND (bc.class like 'payment%' AND c.link = 'AP')
+			OR (bc.class like 'receipt%' AND c.link = 'AR')
 		UNION
 		SELECT v.id, g.reference, g.description, v.batch_id, v.trans_id,
 			sum(a.amount), g.transdate, 'gl'
@@ -200,15 +211,15 @@
 		AND batch_class = 5);
 
 	UPDATE acc_trans SET approved = true 
-	WHERE id IN (select trans_id FROM voucher 
+	WHERE trans_id IN (select trans_id FROM voucher 
 		WHERE batch_id = in_batch_id
 		AND batch_class IN (3, 4, 7, 8));
 
 	UPDATE batch 
 	SET approved_on = now(),
 		approved_by = (select entity_id FROM users 
-			WHERE login = SESSION_USER)
-	WHERE batch_id = in_batch_id;
+			WHERE username = SESSION_USER)
+	WHERE id = in_batch_id;
 
 	RETURN now()::date;
 END;
@@ -263,18 +274,18 @@
 		(select sum(amount) * -1 from acc_trans 
 		join chart ON (acc_trans.chart_id = chart.id)
 		where link = 'AR' AND trans_id = ar.id
-			AND voucher_id NOT IN 
+			AND (voucher_id IS NULL OR voucher_id NOT IN 
 				(select id from voucher 
-				WHERE batch_id = in_batch_id)) 
+				WHERE batch_id = in_batch_id))) 
 	where id in (select trans_id from acc_trans where voucher_id IN 
 		(select id from voucher where batch_id = in_batch_id));
 
 	update ap set paid = amount - (select sum(amount) from acc_trans 
 		join chart ON (acc_trans.chart_id = chart.id)
 		where link = 'AP' AND trans_id = ap.id
-			AND voucher_id NOT IN 
+			AND (voucher_id IS NULL OR voucher_id NOT IN 
 				(select id from voucher 
-				WHERE batch_id = in_batch_id)) 
+				WHERE batch_id = in_batch_id))) 
 	where id in (select trans_id from acc_trans where voucher_id IN 
 		(select id from voucher where batch_id = in_batch_id));
 


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