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

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



Revision: 4288
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4288&view=rev
Author:   einhverfr
Date:     2012-02-07 03:33:23 +0000 (Tue, 07 Feb 2012)
Log Message:
-----------
Merging from branches/1.3

Modified Paths:
--------------
    trunk/Changelog
    trunk/LedgerSMB/Form.pm
    trunk/LedgerSMB/Scripts/admin.pm
    trunk/LedgerSMB/Scripts/customer.pm
    trunk/LedgerSMB/Scripts/employee.pm
    trunk/LedgerSMB/Scripts/journal.pm
    trunk/LedgerSMB/Scripts/menu.pm
    trunk/LedgerSMB/Scripts/payment.pm
    trunk/LedgerSMB/Scripts/recon.pm
    trunk/LedgerSMB/Scripts/setup.pm
    trunk/LedgerSMB/Scripts/taxform.pm
    trunk/LedgerSMB/Scripts/vendor.pm
    trunk/UI/form-dynatable.csv
    trunk/UI/payments/payments_detail.html
    trunk/bin/am.pl
    trunk/bin/gl.pl
    trunk/bin/is.pl
    trunk/sql/modules/Payment.sql
    trunk/tools/prepare-company-database.sh

Property Changed:
----------------
    trunk/
    trunk/LedgerSMB/Scripts/admin.pm
    trunk/LedgerSMB/Scripts/customer.pm
    trunk/LedgerSMB/Scripts/employee.pm
    trunk/LedgerSMB/Scripts/file.pm
    trunk/LedgerSMB/Scripts/journal.pm
    trunk/LedgerSMB/Scripts/login.pm
    trunk/LedgerSMB/Scripts/menu.pm
    trunk/LedgerSMB/Scripts/payment.pm
    trunk/LedgerSMB/Scripts/recon.pm
    trunk/LedgerSMB/Scripts/setup.pm
    trunk/LedgerSMB/Scripts/taxform.pm
    trunk/LedgerSMB/Scripts/vendor.pm
    trunk/sql/upgrade/1.2-1.3-manual.sql


Property changes on: trunk
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3:3711-4271
   + /branches/1.3:3711-4287

Modified: trunk/Changelog
===================================================================
--- trunk/Changelog	2012-02-07 01:45:43 UTC (rev 4287)
+++ trunk/Changelog	2012-02-07 03:33:23 UTC (rev 4288)
@@ -16,6 +16,13 @@
   do recs from bank perspective (Chris T)
 * Added "bank register mode" for account transaction lists (Chris T)
 * Fixed join projection issue in draft search routine (Chris T)
+* Fixed prepare-database.sh for Pg 9.1 (Erik H)
+* Fixed Customer/vendor selection for dropdowns (Chris T)
+* Fixed some HASH() entries in CSV templates (Chris T)
+* Removed unnecessary shebang lines in scripts/* files (Robert C)
+* Fixed GL recurring transaction not posting (Chris T)
+* Improved error handling when extensions/contrib scripts not found (Chris T)
+* Fixed multicurrency handling in bulk payment interface (Chris T and Erik H)
 
 Changelog for 1.3.10
 * Fixes for permissions for exchangerate table (Erik H)

Modified: trunk/LedgerSMB/Form.pm
===================================================================
--- trunk/LedgerSMB/Form.pm	2012-02-07 01:45:43 UTC (rev 4287)
+++ trunk/LedgerSMB/Form.pm	2012-02-07 03:33:23 UTC (rev 4288)
@@ -1820,9 +1820,9 @@
     ($myconfig->{vclimit}) = $sth->fetchrow_array();
 
     if ($vc eq 'customer'){
+        $self->{vc_class} = 2;
+    } else {
         $self->{vc_class} = 1;
-    } else {
-        $self->{vc_class} = 2;
         $vc = 'vendor';
     }
     my $query = qq|SELECT count(*) FROM entity_credit_account ec 

Modified: trunk/LedgerSMB/Scripts/admin.pm
===================================================================
--- trunk/LedgerSMB/Scripts/admin.pm	2012-02-07 01:45:43 UTC (rev 4287)
+++ trunk/LedgerSMB/Scripts/admin.pm	2012-02-07 03:33:23 UTC (rev 4288)
@@ -1,4 +1,3 @@
-#!/usr/bin/perl
 package LedgerSMB::Scripts::admin;
 use strict;
 


Property changes on: trunk/LedgerSMB/Scripts/admin.pm
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3/LedgerSMB/Scripts/admin.pm:3901-4271
/branches/1.3/scripts/admin.pl:3711-3903
   + /branches/1.3/LedgerSMB/Scripts/admin.pm:3901-4287
/branches/1.3/scripts/admin.pl:3711-3903,4273-4287

Modified: trunk/LedgerSMB/Scripts/customer.pm
===================================================================
--- trunk/LedgerSMB/Scripts/customer.pm	2012-02-07 01:45:43 UTC (rev 4287)
+++ trunk/LedgerSMB/Scripts/customer.pm	2012-02-07 03:33:23 UTC (rev 4288)
@@ -1,4 +1,3 @@
-#!/usr/bin/perl
 
 =pod
 


Property changes on: trunk/LedgerSMB/Scripts/customer.pm
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/1.3/scripts/customer.pl:4273-4287

Modified: trunk/LedgerSMB/Scripts/employee.pm
===================================================================
--- trunk/LedgerSMB/Scripts/employee.pm	2012-02-07 01:45:43 UTC (rev 4287)
+++ trunk/LedgerSMB/Scripts/employee.pm	2012-02-07 03:33:23 UTC (rev 4288)
@@ -1,4 +1,3 @@
-#!/usr/bin/perl
 
 =pod
 


Property changes on: trunk/LedgerSMB/Scripts/employee.pm
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3/LedgerSMB/Scripts/employee.pm:3712-4271
/branches/1.3/scripts/employee.pl:3842-3843
   + /branches/1.3/LedgerSMB/Scripts/employee.pm:3712-4287
/branches/1.3/scripts/employee.pl:3842-3843,4273-4287


Property changes on: trunk/LedgerSMB/Scripts/file.pm
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3/LedgerSMB/Scripts/file.pm:3711-4271
/branches/1.3/scripts/file.pl:3711-4138
   + /branches/1.3/LedgerSMB/Scripts/file.pm:3711-4287
/branches/1.3/scripts/file.pl:3711-4138

Modified: trunk/LedgerSMB/Scripts/journal.pm
===================================================================
--- trunk/LedgerSMB/Scripts/journal.pm	2012-02-07 01:45:43 UTC (rev 4287)
+++ trunk/LedgerSMB/Scripts/journal.pm	2012-02-07 03:33:23 UTC (rev 4288)
@@ -1,6 +1,4 @@
-#!/usr/bin/perl
 
-
 =head1 NAME
 
 LedgerSMB::Scripts::journal - LedgerSMB slim ajax script for journal's


Property changes on: trunk/LedgerSMB/Scripts/journal.pm
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/1.3/scripts/journal.pl:4273-4287


Property changes on: trunk/LedgerSMB/Scripts/login.pm
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3/LedgerSMB/Scripts/login.pm:4193-4271
/branches/1.3/scripts/login.pl:3711-4192
   + /branches/1.3/LedgerSMB/Scripts/login.pm:4193-4287
/branches/1.3/scripts/login.pl:3711-4192

Modified: trunk/LedgerSMB/Scripts/menu.pm
===================================================================
--- trunk/LedgerSMB/Scripts/menu.pm	2012-02-07 01:45:43 UTC (rev 4287)
+++ trunk/LedgerSMB/Scripts/menu.pm	2012-02-07 03:33:23 UTC (rev 4288)
@@ -1,6 +1,4 @@
-#!/usr/bin/perl
 
-
 =head1 NAME
 
 LedgerSMB::Scripts::menu - LedgerSMB controller script for menus


Property changes on: trunk/LedgerSMB/Scripts/menu.pm
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3/LedgerSMB/Scripts/menu.pm:4155-4271
/branches/1.3/scripts/menu.pl:3711-4192
   + /branches/1.3/LedgerSMB/Scripts/menu.pm:4155-4287
/branches/1.3/scripts/menu.pl:3711-4192,4273-4287

Modified: trunk/LedgerSMB/Scripts/payment.pm
===================================================================
--- trunk/LedgerSMB/Scripts/payment.pm	2012-02-07 01:45:43 UTC (rev 4287)
+++ trunk/LedgerSMB/Scripts/payment.pm	2012-02-07 03:33:23 UTC (rev 4288)
@@ -555,6 +555,7 @@
 sub display_payments {
     my ($request) = @_;
     my $payment =  LedgerSMB::DBObject::Payment->new({'base' => $request});
+    $payment->{default_currency} =  $payment->get_default_currency();;
     $payment->get_payment_detail_data();
     $payment->open_form();
     $payment->{dbh}->commit;


Property changes on: trunk/LedgerSMB/Scripts/payment.pm
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3/LedgerSMB/Scripts/payment.pm:4010-4271
/branches/1.3/scripts/payment.pl:3711-4263
   + /branches/1.3/LedgerSMB/Scripts/payment.pm:4010-4287
/branches/1.3/scripts/payment.pl:3711-4263,4273-4287

Modified: trunk/LedgerSMB/Scripts/recon.pm
===================================================================
--- trunk/LedgerSMB/Scripts/recon.pm	2012-02-07 01:45:43 UTC (rev 4287)
+++ trunk/LedgerSMB/Scripts/recon.pm	2012-02-07 03:33:23 UTC (rev 4288)
@@ -1,4 +1,3 @@
-#!/usr/bin/perl
 =pod
 
 =head1 NAME


Property changes on: trunk/LedgerSMB/Scripts/recon.pm
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3/LedgerSMB/Scripts/recon.pm:3711-4271
/branches/1.3/scripts/recon.pl:4194-4271
   + /branches/1.3/LedgerSMB/Scripts/recon.pm:3711-4287
/branches/1.3/scripts/recon.pl:4194-4271,4273-4287

Modified: trunk/LedgerSMB/Scripts/setup.pm
===================================================================
--- trunk/LedgerSMB/Scripts/setup.pm	2012-02-07 01:45:43 UTC (rev 4287)
+++ trunk/LedgerSMB/Scripts/setup.pm	2012-02-07 03:33:23 UTC (rev 4288)
@@ -64,15 +64,15 @@
     if (($sv_info[0] > 9)or ($sv_info[0]  == 9 and $sv_info[1] >= 1)){
        if (! -f "$ENV{PG_CONTRIB_DIR}/tablefunc.control"){
             $request->error($request->{_locale}->text(
-                      'Cannot find Contrib scripts in [_1].',
-                      $ENV{PG_CONTRIB_DIR}
+                      'Cannot find Contrib script [_1] in [_2].',
+                      "tablefunc.control", $ENV{PG_CONTRIB_DIR}
             ));
        }
     } else {
        if (! -f "$ENV{PG_CONTRIB_DIR}/tablefunc.sql"){
             $request->error($request->{_locale}->text(
-                      'Cannot find Contrib scripts in [_1].',
-                      $ENV{PG_CONTRIB_DIR}
+                      'Cannot find Contrib script [_1] in [_2].',
+                      "tablefunc.sql", $ENV{PG_CONTRIB_DIR}
             ));
       
        }


Property changes on: trunk/LedgerSMB/Scripts/setup.pm
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3/LedgerSMB/Scripts/setup.pm:3937-4271
/branches/1.3/scripts/setup.pl:3711-4216
   + /branches/1.3/LedgerSMB/Scripts/setup.pm:3937-4287
/branches/1.3/scripts/setup.pl:3711-4216,4273-4287

Modified: trunk/LedgerSMB/Scripts/taxform.pm
===================================================================
--- trunk/LedgerSMB/Scripts/taxform.pm	2012-02-07 01:45:43 UTC (rev 4287)
+++ trunk/LedgerSMB/Scripts/taxform.pm	2012-02-07 03:33:23 UTC (rev 4288)
@@ -1,5 +1,3 @@
-#!/usr/bin/perl
-
 =head1 NAME
 
 LedgerSMB::Scripts::taxform - LedgerSMB handler for reports on tax forms.


Property changes on: trunk/LedgerSMB/Scripts/taxform.pm
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3/LedgerSMB/Scripts/taxform.pm:4193-4271
/branches/1.3/scripts/taxform.pl:3711-4192
   + /branches/1.3/LedgerSMB/Scripts/taxform.pm:4193-4287
/branches/1.3/scripts/taxform.pl:3711-4192,4273-4287

Modified: trunk/LedgerSMB/Scripts/vendor.pm
===================================================================
--- trunk/LedgerSMB/Scripts/vendor.pm	2012-02-07 01:45:43 UTC (rev 4287)
+++ trunk/LedgerSMB/Scripts/vendor.pm	2012-02-07 03:33:23 UTC (rev 4288)
@@ -1,5 +1,3 @@
-#!/usr/bin/perl
-
 =pod
 
 =head1 NAME


Property changes on: trunk/LedgerSMB/Scripts/vendor.pm
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/1.3/scripts/vendor.pl:4273-4287

Modified: trunk/UI/form-dynatable.csv
===================================================================
--- trunk/UI/form-dynatable.csv	2012-02-07 01:45:43 UTC (rev 4287)
+++ trunk/UI/form-dynatable.csv	2012-02-07 03:33:23 UTC (rev 4288)
@@ -1,5 +1,5 @@
 <?lsmb FOREACH column IN columns;
-	IF heading.$column.text;
+	IF heading.$column.exists('text');
 		heading.$column.text;
 	ELSE;
 		heading.$column;
@@ -10,7 +10,7 @@
 END ?>
 <?lsmb FOREACH row IN rows;
 	FOREACH column IN columns;
-		IF row.$column.text.defined;
+		IF row.$column.exists('text');
 			row.$column.text;
 		ELSE;
 			row.$column;

Modified: trunk/UI/payments/payments_detail.html
===================================================================
--- trunk/UI/payments/payments_detail.html	2012-02-07 01:45:43 UTC (rev 4287)
+++ trunk/UI/payments/payments_detail.html	2012-02-07 03:33:23 UTC (rev 4288)
@@ -145,17 +145,17 @@
 		END # If a.accno... ?><?lsmb
 	END # FOREACH a ?>
       </span>
-     </div>
-     <?lsmb  IF defaultcurrency != curr ?>
+     </div> 
+     <?lsmb  IF default_currency != currency ?>
       <div class="info" id="exrate_row">
          <?lsmb PROCESS input element_data= {
-		label = text('Exchange Rate')
-		type = text
+		label = text('Exchange Rate') #'
+		type = 'text'
 		class = "numeric"
-		name = 'exchange_rate'
-		value = exchange_rate
+		name = 'exchangerate'
+		value = exchangerate
 		size = 20
-	} # ' ?>
+	}  ?>
 	</div>
      <?lsmb END ?>
      <?lsmb IF business ?>

Modified: trunk/bin/am.pl
===================================================================
--- trunk/bin/am.pl	2012-02-07 01:45:43 UTC (rev 4287)
+++ trunk/bin/am.pl	2012-02-07 03:33:23 UTC (rev 4288)
@@ -2703,7 +2703,7 @@
                 $form->{reference} = $pt->{reference};
                 $form->{transdate} = $pt->{nextdate};
 
-                $j = 1;
+                $j = 0;
                 foreach $ref ( @{ $form->{GL} } ) {
                     $form->{"accno_$j"} = "$ref->{accno}--$ref->{description}";
 
@@ -2732,7 +2732,7 @@
                         $form->{reference}
                       )
                 );
-                $ok = GL->post_transaction( \%myconfig, \%$form );
+                $ok = GL->post_transaction( \%myconfig, \%$form, $locale );
                 $form->info( " ..... " . $locale->text('done') );
 
             }

Modified: trunk/bin/gl.pl
===================================================================
--- trunk/bin/gl.pl	2012-02-07 01:45:43 UTC (rev 4287)
+++ trunk/bin/gl.pl	2012-02-07 03:33:23 UTC (rev 4288)
@@ -653,7 +653,7 @@
         if ($form->{bank_register_mode}){
             @columns = $form->sort_columns(
                 qw(transdate id reference description notes source memo cleared credit
-                   debit credit accno gifi_accno)
+                   debit accno gifi_accno)
             );
         }
         $form->{l_cleared} = "Y";

Modified: trunk/bin/is.pl
===================================================================
--- trunk/bin/is.pl	2012-02-07 01:45:43 UTC (rev 4287)
+++ trunk/bin/is.pl	2012-02-07 03:33:23 UTC (rev 4288)
@@ -373,7 +373,7 @@
             $exchangerate .=
                 qq|<th align=right>|
               . $locale->text('Exchange Rate')
-              . qq|</th><td><input name="exchangerate size="10" value="$form->{exchangerate}"></td>|;
+              . qq|</th><td><input name="exchangerate" size="10" value="$form->{exchangerate}"></td>|;
         }
     }
     $exchangerate .= qq|

Modified: trunk/sql/modules/Payment.sql
===================================================================
--- trunk/sql/modules/Payment.sql	2012-02-07 01:45:43 UTC (rev 4287)
+++ trunk/sql/modules/Payment.sql	2012-02-07 03:33:23 UTC (rev 4288)
@@ -121,8 +121,7 @@
 	LOOP
 		RETURN NEXT out_entity;
 	END LOOP;
-END;
-$$ LANGUAGE PLPGSQL;
+$$;
 
 COMMENT ON FUNCTION payment_get_all_accounts(int) IS
 $$ This function takes a single argument (1 for vendor, 2 for customer as 
@@ -358,7 +357,7 @@
 		    JOIN (SELECT ap.id, invnumber, transdate, amount, entity_id, 
 				 curr, 1 as invoice_class,
 		                 entity_credit_account, on_hold, v.batch_id,
-				 approved
+				 approved, paid
 		            FROM ap
 		       LEFT JOIN (select * from voucher where batch_class = 1) v 
 			         ON (ap.id = v.trans_id)
@@ -368,7 +367,7 @@
 		          SELECT ar.id, invnumber, transdate, amount, entity_id,
 		                 curr, 2 as invoice_class,
 		                 entity_credit_account, on_hold, v.batch_id,
-				 approved
+				 approved, paid
 		            FROM ar
 		       LEFT JOIN (select * from voucher where batch_class = 2) v 
 			         ON (ar.id = v.trans_id)
@@ -397,6 +396,7 @@
 		             AND a.approved
 		         AND a.amount <> a.paid 
 			 AND NOT a.on_hold
+                         AND a.curr = in_currency
 		         AND EXISTS (select trans_id FROM acc_trans
 		                      WHERE trans_id = a.id AND
 		                            chart_id = (SELECT id from account
@@ -439,114 +439,142 @@
 username of the individual who has the lock.
 $$;
 
+DROP FUNCTION IF EXISTS payment_bulk_post
+(in_transactions numeric[], in_batch_id int, in_source text, in_total numeric,
+        in_ar_ap_accno text, in_cash_accno text,
+        in_payment_date date, in_account_class int,
+        in_exchangerate numeric, in_curr text);
 
 CREATE OR REPLACE FUNCTION payment_bulk_post
 (in_transactions numeric[], in_batch_id int, in_source text, in_total numeric,
-	in_ar_ap_accno text, in_cash_accno text, 
-	in_payment_date date, in_account_class int,
-        in_exchangerate numeric, in_curr text)
+        in_ar_ap_accno text, in_cash_accno text, 
+        in_payment_date date, in_account_class int,
+        in_exchangerate numeric, in_currency text)
 RETURNS int AS
 $$
 DECLARE 
-	out_count int;
-	t_voucher_id int;
-	t_trans_id int;
-	t_amount numeric;
+        out_count int;
+        t_voucher_id int;
+        t_trans_id int;
+        t_amount numeric;
         t_ar_ap_id int;
-	t_cash_id int;
+        t_cash_id int;
         t_currs text[];
         t_exchangerate numeric;
+        t_cash_sign int;
 BEGIN
-	IF in_batch_id IS NULL THEN
-		-- t_voucher_id := NULL;
-		RAISE EXCEPTION 'Bulk Post Must be from Batch!';
-	ELSE
-		INSERT INTO voucher (batch_id, batch_class, trans_id)
-		values (in_batch_id,
+        IF in_batch_id IS NULL THEN
+                -- t_voucher_id := NULL;
+                RAISE EXCEPTION 'Bulk Post Must be from Batch!';
+        ELSE
+                INSERT INTO voucher (batch_id, batch_class, trans_id)
+                values (in_batch_id,
                 (SELECT batch_class_id FROM batch WHERE id = in_batch_id),
                 in_transactions[1][1]);
 
-		t_voucher_id := currval('voucher_id_seq');
-	END IF;
+                t_voucher_id := currval('voucher_id_seq');
+        END IF;
 
-	SELECT string_to_array(value, ':') into t_currs 
+        SELECT string_to_array(value, ':') into t_currs 
           from defaults 
          where setting_key = 'curr';
 
-        IF (in_curr IS NULL OR in_curr = t_currs[0]) THEN
+        IF (in_currency IS NULL OR in_currency = t_currs[0]) THEN
                 t_exchangerate := 1;
         ELSE 
                 t_exchangerate := in_exchangerate;
         END IF;
+        IF t_exchangerate IS NULL THEN
+            RAISE EXCEPTION 'No exchangerate provided and not default currency';
+        END IF;
 
-	CREATE TEMPORARY TABLE bulk_payments_in (id int, amount numeric);
+        CREATE TEMPORARY TABLE bulk_payments_in
+           (id int, amount numeric, fxrate numeric, gain_loss_accno int);
 
-	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;
+        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)
-	LOOP
-		EXECUTE $E$
-			INSERT INTO bulk_payments_in(id, amount)
-			VALUES ($E$ || quote_literal(in_transactions[out_count][1])
-				|| $E$, $E$ ||
-				quote_literal(in_transactions[out_count][2])
-				|| $E$)$E$;
-	END LOOP;
-	EXECUTE $E$ 
-		INSERT INTO acc_trans 
-			(trans_id, chart_id, amount, approved, voucher_id, transdate, 
-			source)
-		SELECT id, 
-		case when $E$ || quote_literal(in_account_class) || $E$ = 1
-				quote_literal(in_transactions[out_count][2])
-				|| $E$)$E$;
-	END LOOP;
-	EXECUTE $E$ 
-		INSERT INTO acc_trans 
-			(trans_id, chart_id, amount, approved, voucher_id, transdate, 
-			source)
-		SELECT id, 
-		case when $E$ || quote_literal(in_account_class) || $E$ = 1
-			THEN $E$ || t_cash_id || $E$
-			WHEN $E$ || quote_literal(in_account_class) || $E$ = 2 
-			THEN $E$ || t_ar_ap_id || $E$
-			ELSE -1 END, 
-		amount * $E$|| quote_literal(t_exchangerate) || $E$,
-		CASE 
-			WHEN $E$|| t_voucher_id || $E$ IS NULL THEN true
-			ELSE false END,
-		$E$ || t_voucher_id || $E$, $E$|| quote_literal(in_payment_date) 
-		||$E$ , $E$ ||COALESCE(quote_literal(in_source), 'NULL') || 
-		$E$ 
-		FROM bulk_payments_in  where amount <> 0 $E$;
+        FOR out_count IN 
+                        array_lower(in_transactions, 1) ..
+                        array_upper(in_transactions, 1)
+        LOOP
+            -- Fill the bulk payments table
+            INSERT INTO bulk_payments_in(id, amount)
+            VALUES (in_transactions[out_count][1],
+                    in_transactions[out_count][2]);
+        END LOOP;
 
-	EXECUTE $E$ 
-		INSERT INTO acc_trans 
-			(trans_id, chart_id, amount, approved, voucher_id, transdate, 
-			source)
-		SELECT id, 
-		case when $E$ || quote_literal(in_account_class) || $E$ = 1 
-			THEN $E$ || t_ar_ap_id || $E$
-			WHEN $E$ || quote_literal(in_account_class) || $E$ = 2 
-			THEN $E$ || t_cash_id || $E$
-			ELSE -1 END, 
-		amount * -1 * $E$|| quote_literal(t_exchangerate) || $E$,
-		CASE 
-			WHEN $E$|| t_voucher_id || $E$ IS NULL THEN true
-			ELSE false END,
-		$E$ || t_voucher_id || $E$, $E$|| quote_literal(in_payment_date) 
-		||$E$ , $E$ ||COALESCE(quote_literal(in_source), 'null') 
-		||$E$ 
-		FROM bulk_payments_in where amount <> 0 $E$;
+        IF in_account_class = 1 THEN
+            t_cash_sign := 1;
+        ELSE
+            t_cash_sign := -1;
+        END IF;
 
-	-- ### BUG: Where's the FX gain/loss part for FX postings??
+        IF (in_currency IS NULL OR in_currency = t_currs[0]) THEN
+            UPDATE bulk_payments_in
+               SET fxrate = 1;
+        ELSE
+            UPDATE bulk_payments_in
+               SET fxrate =
+                (SELECT CASE WHEN in_account_class = 1 THEN sell
+                             ELSE buy
+                        END
+                   FROM exchangerate e
+                   JOIN (SELECT transdate, id, curr FROM ar
+                         UNION
+                         SELECT transdate, id, curr FROM ap) a
+                     ON (e.transdate = a.transdate
+                         AND e.curr = a.curr)
+                   WHERE a.id = bulk_payments_in.id);
+            UPDATE bulk_payments_in
+               SET gain_loss_accno =
+                (SELECT value::int FROM defaults
+                  WHERE setting_key = 'fxgain_accno_id')
+             WHERE ((t_exchangerate - bulk_payments_in.fxrate) * t_cash_sign) < 0;
+            UPDATE bulk_payments_in
+               SET gain_loss_accno = (SELECT value::int FROM defaults
+                  WHERE setting_key = 'fxloss_accno_id')
+             WHERE ((t_exchangerate - bulk_payments_in.fxrate) * t_cash_sign) > 0;
+            -- explicitly leave zero gain/loss accno_id entries at NULL
+            -- so we have an easy check for which 
+        END IF;
 
-	EXECUTE $E$ DROP TABLE bulk_payments_in $E$;
-	perform unlock_all();
-	return out_count;
+        -- Insert cash side
+        INSERT INTO acc_trans
+             (trans_id, chart_id, amount, approved,
+              voucher_id, transdate, source)
+           SELECT id, t_cash_id, amount * t_cash_sign * t_exchangerate,
+                  CASE WHEN t_voucher_id IS NULL THEN true
+                       ELSE false END,
+                  t_voucher_id, in_payment_date, in_source
+             FROM bulk_payments_in  where amount <> 0;
+
+        -- Insert ar/ap side
+        INSERT INTO acc_trans
+             (trans_id, chart_id, amount, approved,
+              voucher_id, transdate, source)
+           SELECT id, t_ar_ap_id,
+                  amount * -1 * t_cash_sign * fxrate,
+                  CASE WHEN t_voucher_id IS NULL THEN true
+                       ELSE false END,
+                  t_voucher_id, in_payment_date, in_source
+             FROM bulk_payments_in where amount <> 0;
+
+        -- Insert fx gain/loss effects, if applicable
+        INSERT INTO acc_trans
+             (trans_id, chart_id, amount, approved,
+              voucher_id, transdate, source)
+           SELECT id, gain_loss_accno,
+                  amount * -1 * t_cash_sign * (t_exchangerate - fxrate),
+                  CASE WHEN t_voucher_id IS NULL THEN true
+                       ELSE false END,
+                  t_voucher_id, in_payment_date, in_source
+             FROM bulk_payments_in
+            WHERE amount <> 0 AND gain_loss_accno IS NOT NULL;
+
+        DROP TABLE bulk_payments_in;
+        perform unlock_all();
+        return out_count;
 END;
 $$ language plpgsql;
 
@@ -554,7 +582,7 @@
 (in_transactions numeric[], in_batch_id int, in_source text, in_total numeric,
         in_ar_ap_accno text, in_cash_accno text, 
         in_payment_date date, in_account_class int, 
-	in_exchangerate numeric, in_curr text)
+	in_exchangerate numeric, in_currency text)
 IS
 $$ This posts the payments for large batch workflows.
 
@@ -1290,10 +1318,7 @@
             
       LOOP
            RETURN NEXT out_overpayment;
-    		WHERE available <> 0 AND in_account_class = payment_class
-        LOOP
-                RETURN NEXT out_entity;
-        END LOOP;
+      END LOOP;
  END;
 $$ LANGUAGE PLPGSQL;
 


Property changes on: trunk/sql/upgrade/1.2-1.3-manual.sql
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3/sql/upgrade/1.2-1.3-manual.sql:3712-4271
/branches/1.3/sql/upgrade/1.2-1.3.sql:3711-3851
/trunk/sql/upgrade/1.2-1.3.sql:858-3710
   + /branches/1.3/sql/upgrade/1.2-1.3-manual.sql:3712-4287
/branches/1.3/sql/upgrade/1.2-1.3.sql:3711-3851
/trunk/sql/upgrade/1.2-1.3.sql:858-3710

Modified: trunk/tools/prepare-company-database.sh
===================================================================
--- trunk/tools/prepare-company-database.sh	2012-02-07 01:45:43 UTC (rev 4287)
+++ trunk/tools/prepare-company-database.sh	2012-02-07 03:33:23 UTC (rev 4288)
@@ -169,8 +169,11 @@
   exit 1
 fi
 
-if test "$pgsql_contrib_dir" = "ignore"
+is_v9_1plus=`su -c "psql -U postgres -d postgres -c 'SELECT version();'" | grep -E 'PostgreSQL 9.[1-9]'`
+
+if test "$pgsql_contrib_dir" = "ignore" -a -z "$is_v9_1plus"
 then
+  # --pgsql-contrib argument not required due to 9.1+ CREATE EXTENSION system
   echo "missing argument --pgsql-contrib!"
   usage
   exit 1

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