[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[2582] trunk
- Subject: SF.net SVN: ledger-smb:[2582] trunk
- From: ..hidden..
- Date: Thu, 30 Apr 2009 19:28:10 +0000
Revision: 2582
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2582&view=rev
Author: aurynn_cmd
Date: 2009-04-30 19:28:10 +0000 (Thu, 30 Apr 2009)
Log Message:
-----------
Adding John Worsely's empty batch delete sproc and UI. Empty batch sproc test in test/Voucher.sql.
Modified Paths:
--------------
trunk/LedgerSMB/Batch.pm
trunk/UI/batch/filter.html
trunk/scripts/vouchers.pl
trunk/sql/modules/Voucher.sql
trunk/sql/modules/test/Voucher.sql
Modified: trunk/LedgerSMB/Batch.pm
===================================================================
--- trunk/LedgerSMB/Batch.pm 2009-04-29 01:28:28 UTC (rev 2581)
+++ trunk/LedgerSMB/Batch.pm 2009-04-30 19:28:10 UTC (rev 2582)
@@ -47,7 +47,9 @@
sub get_search_results {
my ($self, $args) = @_;
- if ($args->{mini}){
+ if ($self->{empty}){
+ $search_proc = "batch_search_empty";
+ } elsif ($args->{mini}){
$search_proc = "batch_search_mini";
} else {
$search_proc = "batch_search";
Modified: trunk/UI/batch/filter.html
===================================================================
--- trunk/UI/batch/filter.html 2009-04-29 01:28:28 UTC (rev 2581)
+++ trunk/UI/batch/filter.html 2009-04-30 19:28:10 UTC (rev 2582)
@@ -23,6 +23,12 @@
value = '1'
type = "checkbox"
} ?>
+ <?lsmb INCLUDE input element_data = {
+ label = text("Empty")
+ name = "empty"
+ value = '1'
+ type = "checkbox"
+ } ?>
</div>
<div class="input" id="entered_by_div">
<?lsmb INCLUDE select element_data = {
Modified: trunk/scripts/vouchers.pl
===================================================================
--- trunk/scripts/vouchers.pl 2009-04-29 01:28:28 UTC (rev 2581)
+++ trunk/scripts/vouchers.pl 2009-04-30 19:28:10 UTC (rev 2582)
@@ -246,26 +246,40 @@
my $hiddens = $batch->take_top_level();
$batch->{rowcount} = "$count";
delete $batch->{search_results};
-
- $template->render({
- form => $batch,
- columns => ..hidden..,
- heading => \%column_heading,
- rows => ..hidden..,
- hiddens => $hiddens,
- buttons => [{
+
+ my @buttons;
+ if ($batch->{empty})
+ {
+ @buttons = [{
name => 'action',
type => 'submit',
+ text => $request->{_locale}->text('Delete'),
+ value => 'batch_delete',
+ class => 'submit',
+ }];
+ } else {
+ @buttons = [{
+ name => 'action',
+ type => 'submit',
text => $request->{_locale}->text('Post'),
value => 'batch_approve',
class => 'submit',
- },{
+ },{
name => 'action',
type => 'submit',
text => $request->{_locale}->text('Delete'),
value => 'batch_delete',
class => 'submit',
- }]
+ }];
+ }
+
+ $template->render({
+ form => $batch,
+ columns => ..hidden..,
+ heading => \%column_heading,
+ rows => ..hidden..,
+ hiddens => $hiddens,
+ buttons => @buttons
});
}
Modified: trunk/sql/modules/Voucher.sql
===================================================================
--- trunk/sql/modules/Voucher.sql 2009-04-29 01:28:28 UTC (rev 2581)
+++ trunk/sql/modules/Voucher.sql 2009-04-30 19:28:10 UTC (rev 2582)
@@ -263,6 +263,76 @@
$$ LANGUAGE PLPGSQL;
+CREATE OR REPLACE FUNCTION
+batch_search_empty(in_class_id int, in_description text, in_created_by_eid int,
+ in_amount_gt numeric,
+ in_amount_lt numeric, in_approved bool)
+RETURNS SETOF batch_list_item AS
+$$
+DECLARE out_value batch_list_item;
+BEGIN
+ FOR out_value IN
+ SELECT b.id, c.class, b.control_code, b.description, u.username,
+ b.created_on,
+ sum(
+ CASE WHEN vc.id = 5 AND al.amount < 0 -- GL
+ THEN al.amount
+ WHEN vc.id = 1
+ THEN ap.amount
+ WHEN vc.id = 2
+ THEN ap.amount
+ ELSE 0
+ END) AS transaction_total,
+ sum(
+ CASE WHEN alc.link = 'AR' AND vc.id IN (6, 7)
+ THEN al.amount
+ WHEN alc.link = 'AP' AND vc.id IN (3, 4)
+ THEN al.amount * -1
+ ELSE 0
+ END
+ ) AS payment_total
+ 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)
+ LEFT JOIN voucher v ON (v.batch_id = b.id)
+ LEFT JOIN batch_class vc ON (v.batch_class = vc.id)
+ LEFT JOIN ar ON (vc.id = 2 AND v.trans_id = ar.id)
+ LEFT JOIN ap ON (vc.id = 1 AND v.trans_id = ap.id)
+ LEFT JOIN acc_trans al ON
+ ((vc.id = 5 AND v.trans_id = al.trans_id) OR
+ (vc.id IN (3, 4, 6, 7)
+ AND al.voucher_id = v.id))
+ LEFT JOIN chart alc ON (al.chart_id = alc.id)
+ WHERE (c.id = in_class_id OR in_class_id IS NULL) AND
+ (b.description LIKE
+ '%' || in_description || '%' OR
+ in_description IS NULL) AND
+ (in_created_by_eid = b.created_by OR
+ in_created_by_eid IS NULL) AND
+ ((in_approved = false OR in_approved IS NULL AND
+ approved_on IS NULL) OR
+ (in_approved = true AND approved_on IS NOT NULL)
+ )
+ GROUP BY b.id, c.class, b.description, u.username, b.created_on,
+ b.control_code
+ HAVING
+ (in_amount_gt IS NULL OR
+ sum(coalesce(ar.amount - ar.paid, ap.amount - ap.paid,
+ al.amount))
+ >= in_amount_gt)
+ AND
+ (in_amount_lt IS NULL OR
+ sum(coalesce(ar.amount - ar.paid, ap.amount - ap.paid,
+ al.amount))
+ <= in_amount_lt)
+ AND count(v.*) = 0
+ ORDER BY b.control_code, b.description
+
+ LOOP
+ RETURN NEXT out_value;
+ END LOOP;
+END;
+$$ LANGUAGE PLPGSQL;
CREATE OR REPLACE FUNCTION batch_post(in_batch_id INTEGER)
Modified: trunk/sql/modules/test/Voucher.sql
===================================================================
--- trunk/sql/modules/test/Voucher.sql 2009-04-29 01:28:28 UTC (rev 2581)
+++ trunk/sql/modules/test/Voucher.sql 2009-04-30 19:28:10 UTC (rev 2582)
@@ -39,6 +39,20 @@
SELECT 'partial payment support', count(*) > 1
FROM voucher where trans_id = -5 and batch_class = 3;
+-- Adding the test for empty batch sproc
+
+insert into batch (batch_class_id, control_code, description, default_date, created_by) values (1, 'EMPTYBATCHTEST', 'EMPTY BATCH TEST', '2009-01-01', -3);
+
+INSERT INTO test_result (test_name, success)
+SELECT 'Empty Batch Detected', count(*) = 1
+ FROM batch_search_empty(1, -- Batch class ID
+ 'EMPTY BATCH TEST', -- Batch description
+ -3, -- Entity ID
+ NULL::numeric, -- Amount greater than
+ NULL::numeric, -- Amount less than
+ 'f'::bool -- Approved
+);
+
SELECT * FROM test_result;
SELECT (select count(*) from test_result where success is true)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.