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

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



Revision: 6727
          http://sourceforge.net/p/ledger-smb/code/6727
Author:   einhverfr
Date:     2014-02-04 04:23:08 +0000 (Tue, 04 Feb 2014)
Log Message:
-----------
Initial changes for batch locking.  Unlocking logic will need to be redone in 1.3 due to differences in how the reporting works, but this is the patch for merge.

Modified Paths:
--------------
    trunk/Changelog
    trunk/LedgerSMB/AA.pm
    trunk/LedgerSMB/GL.pm
    trunk/sql/Pg-database.sql
    trunk/sql/modules/Fixes.sql
    trunk/sql/modules/Payment.sql
    trunk/sql/modules/Voucher.sql

Modified: trunk/Changelog
===================================================================
--- trunk/Changelog	2014-02-03 04:21:02 UTC (rev 6726)
+++ trunk/Changelog	2014-02-04 04:23:08 UTC (rev 6727)
@@ -109,6 +109,7 @@
 
 Changelog for 1.3.38
 * Fixed AR/AP transactions resetting currency/exchange rate (Chris T)
+* Fixed adding vouchers not checking for locked/approved batches (Chris T 1025)
 
 Changelog for 1.3.37
 * 1.3-1.2 downgrade now drops extensions (Chris T, 943)

Modified: trunk/LedgerSMB/AA.pm
===================================================================
--- trunk/LedgerSMB/AA.pm	2014-02-03 04:21:02 UTC (rev 6726)
+++ trunk/LedgerSMB/AA.pm	2014-02-04 04:23:08 UTC (rev 6727)
@@ -423,6 +423,15 @@
            } else {
                $batch_class = 'ap';
            }
+           my $vqh = $dbh->prepare(
+              'SELECT * FROM batch 
+               WHERE id = ? FOR UPDATE'
+           );
+           $vqh->execute($form->{batch_id});
+           my $bref = $vqh->fetchrow_hashref('NAME_lc');
+           # Change the below to die with localization in 1.4
+           $form->error('Approved Batch') if $bref->{approved_by};
+           $form->error('Locked Batch') if $bref->{locked_by};
            $query = qq| 
 		INSERT INTO voucher (batch_id, trans_id, batch_class)
 		VALUES (?, ?, (select id from batch_class where class = ?))|;

Modified: trunk/LedgerSMB/GL.pm
===================================================================
--- trunk/LedgerSMB/GL.pm	2014-02-03 04:21:02 UTC (rev 6726)
+++ trunk/LedgerSMB/GL.pm	2014-02-04 04:23:08 UTC (rev 6727)
@@ -146,6 +146,15 @@
            if (not defined $form->{batch_id}){
                $form->error($locale->text('Batch ID Missing'));
            }
+           my $vqh = $dbh->prepare(
+              'SELECT * FROM batch 
+               WHERE id = ? FOR UPDATE'
+           );
+           $vqh->execute($form->{batch_id});
+           my $bref = $vqh->fetchrow_hashref('NAME_lc');
+           # Change the below to die with localization in 1.4
+           $form->error('Approved Batch') if $bref->{approved_by};
+           $form->error('Locked Batch') if $bref->{locked_by};
            my $query = qq| 
 			INSERT INTO voucher (batch_id, trans_id, batch_class) 
 			VALUES (?, ?, (select id FROM batch_class 

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2014-02-03 04:21:02 UTC (rev 6726)
+++ trunk/sql/Pg-database.sql	2014-02-04 04:23:08 UTC (rev 6727)
@@ -1403,7 +1403,7 @@
   approved_on date default null,
   approved_by int references entity_employee(entity_id),
   created_by int references entity_employee(entity_id),
-  locked_by int references session(session_id),
+  locked_by int references session(session_id) ON DELETE CASCADE,
   created_on date default now(),
   CHECK (length(control_code) > 0)
 );

Modified: trunk/sql/modules/Fixes.sql
===================================================================
--- trunk/sql/modules/Fixes.sql	2014-02-03 04:21:02 UTC (rev 6726)
+++ trunk/sql/modules/Fixes.sql	2014-02-04 04:23:08 UTC (rev 6727)
@@ -294,3 +294,9 @@
 UPDATE voucher SET batch_class = 2 WHERE batch_class = 1 AND trans_id IN
 (SELECT id FROM ar);
 COMMIT;
+
+BEGIN;
+ALTER TABLE batch DROP CONSTRAINT "batch_locked_by_fkey";
+ALTER TABLE batch ADD FOREIGN KEY (locked_by) REFERENCES session(session_id)
+ON DELETE SET NULL;
+COMMIT;

Modified: trunk/sql/modules/Payment.sql
===================================================================
--- trunk/sql/modules/Payment.sql	2014-02-03 04:21:02 UTC (rev 6726)
+++ trunk/sql/modules/Payment.sql	2014-02-04 04:23:08 UTC (rev 6727)
@@ -491,6 +491,7 @@
         t_currs text[];
         t_exchangerate numeric;
         t_cash_sign int;
+        t_batch batch;
 BEGIN
 
         SELECT * INTO t_exchangerate FROM currency_get_exchangerate(
@@ -500,6 +501,12 @@
                 -- t_voucher_id := NULL;
                 RAISE EXCEPTION 'Bulk Post Must be from Batch!';
         ELSE
+                SELECT * INTO t_batch FROM batch WHERE in_batch_id = id;
+                IF t_batch.approved_by IS NOT NULL THEN
+                    RAISE EXCEPTION 'Approved Batch';
+                ELSIF t_batch.locked_by IS NOT NULL THEN
+                    RAISE EXCEPTION 'Locked Batch';
+                END;
                 INSERT INTO voucher (batch_id, batch_class, trans_id)
                 values (in_batch_id,
                 (SELECT batch_class_id FROM batch WHERE id = in_batch_id),

Modified: trunk/sql/modules/Voucher.sql
===================================================================
--- trunk/sql/modules/Voucher.sql	2014-02-03 04:21:02 UTC (rev 6726)
+++ trunk/sql/modules/Voucher.sql	2014-02-04 04:23:08 UTC (rev 6727)
@@ -138,9 +138,39 @@
     created_on date,
     default_date date,
     transaction_total numeric,
-    payment_total numeric
+    payment_total numeric,
+    lock_success bool
 );
 
+CREATE OR REPLACE FUNCTION batch__lock(in_batch_id int) 
+RETURNS BOOL LANGUAGE PLPGSQL SECURITY DEFINER AS
+$$
+BEGIN
+UPDATE batch SET locked_by = (select max(session_id)
+                                FROM "session" where users_id = (
+                                        select id from users 
+                                         WHERE username = SESSION_USER))
+ WHERE locked_by IS NULL;
+RETURN FOUND;
+END;
+$$;
+
+CREATE OR REPLACE FUNCTION batch__unlock(in_batch_id int)
+RETURNS BOOL LANGUAGE plpgsql SECURITY DEFINER AS
+$$
+BEGIN
+
+UPDATE batch SET locked_by = NULL
+ WHERE id = $1 AND locked_by IN (select session_id 
+                                   from "session" s
+                                   join users u on (u.id = s.user_id)
+                                  where username = SESSION_USER);
+ 
+RETURN FOUND;
+
+END;
+$$;
+
 CREATE OR REPLACE FUNCTION 
 batch__search(in_class_id int, in_description text, in_created_by_eid int, 
 	in_date_from date, in_date_to date,
@@ -169,7 +199,8 @@
 				     THEN al.amount * -1
 				     ELSE 0
 				END
-			   ) AS payment_total
+			   ) AS payment_total, 
+                     batch__lock(b.id)
 		FROM batch b
 		JOIN batch_class c ON (b.batch_class_id = c.id)
 		LEFT JOIN users u ON (u.entity_id = b.created_by)

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


------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk
_______________________________________________
Ledger-smb-commits mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-commits