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

SF.net SVN: ledger-smb:[6728] branches/1.3



Revision: 6728
          http://sourceforge.net/p/ledger-smb/code/6728
Author:   einhverfr
Date:     2014-02-04 04:26:07 +0000 (Tue, 04 Feb 2014)
Log Message:
-----------
Initial fix for 1025. Unlocking not done yet for 1.3, so locks only time out or are terminated by admin.  To be fixed in next commit.

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

Modified: branches/1.3/Changelog
===================================================================
--- branches/1.3/Changelog	2014-02-04 04:23:08 UTC (rev 6727)
+++ branches/1.3/Changelog	2014-02-04 04:26:07 UTC (rev 6728)
@@ -5,6 +5,7 @@
 Changelog for 1.3.38
 * Fixed AR/AP transactions resetting currency/exchange rate (Chris T)
 * Reports all default to detail instead of summary (Erik H)
+* 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: branches/1.3/LedgerSMB/AA.pm
===================================================================
--- branches/1.3/LedgerSMB/AA.pm	2014-02-04 04:23:08 UTC (rev 6727)
+++ branches/1.3/LedgerSMB/AA.pm	2014-02-04 04:26:07 UTC (rev 6728)
@@ -412,6 +412,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: branches/1.3/LedgerSMB/GL.pm
===================================================================
--- branches/1.3/LedgerSMB/GL.pm	2014-02-04 04:23:08 UTC (rev 6727)
+++ branches/1.3/LedgerSMB/GL.pm	2014-02-04 04:26:07 UTC (rev 6728)
@@ -176,6 +176,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: branches/1.3/sql/Pg-database.sql
===================================================================
--- branches/1.3/sql/Pg-database.sql	2014-02-04 04:23:08 UTC (rev 6727)
+++ branches/1.3/sql/Pg-database.sql	2014-02-04 04:26:07 UTC (rev 6728)
@@ -1082,7 +1082,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: branches/1.3/sql/modules/Fixes.sql
===================================================================
--- branches/1.3/sql/modules/Fixes.sql	2014-02-04 04:23:08 UTC (rev 6727)
+++ branches/1.3/sql/modules/Fixes.sql	2014-02-04 04:26:07 UTC (rev 6728)
@@ -673,3 +673,9 @@
 BEGIN;
 INSERT INTO defaults VALUES ('disable_back', '0');
 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: branches/1.3/sql/modules/Payment.sql
===================================================================
--- branches/1.3/sql/modules/Payment.sql	2014-02-04 04:23:08 UTC (rev 6727)
+++ branches/1.3/sql/modules/Payment.sql	2014-02-04 04:26:07 UTC (rev 6728)
@@ -495,6 +495,7 @@
         t_currs text[];
         t_exchangerate numeric;
         t_cash_sign int;
+        t_batch batch;
 BEGIN
 
         SELECT * INTO t_exchangerate FROM currency_get_exchangerate(
@@ -504,6 +505,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: branches/1.3/sql/modules/Voucher.sql
===================================================================
--- branches/1.3/sql/modules/Voucher.sql	2014-02-04 04:23:08 UTC (rev 6727)
+++ branches/1.3/sql/modules/Voucher.sql	2014-02-04 04:26:07 UTC (rev 6728)
@@ -134,9 +134,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,
@@ -165,7 +195,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