summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2008-06-30 21:24:59 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2008-06-30 21:24:59 +0000
commit24708fad478ce6484e7a6987e17ffa58855b7d27 (patch)
treec2071fc7d37cff09e66dca5ecd6abdb114aaf8c7
parent49174fdc16c696dcc0f8d4124cb0749f91b6bb4d (diff)
Adding batch_search_mini api
Addressing issue on create batch screen of searching through all batches Adding error message in LedgerSMB::call_procedure if procname is undefined. git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@2178 4979c152-3d1c-0410-bac9-87ea11338e46
-rwxr-xr-xLedgerSMB.pm6
-rw-r--r--LedgerSMB/Batch.pm19
-rw-r--r--scripts/vouchers.pl3
-rw-r--r--sql/modules/Voucher.sql38
-rw-r--r--t/01-load.t2
5 files changed, 63 insertions, 5 deletions
diff --git a/LedgerSMB.pm b/LedgerSMB.pm
index 63f4ec27..3fe186b9 100755
--- a/LedgerSMB.pm
+++ b/LedgerSMB.pm
@@ -552,6 +552,10 @@ sub call_procedure {
my $argstr = "";
my @results;
+ if (!defined $procname){
+ $self->error('Undefined function in call_procedure.');
+ }
+
$procname = $self->{dbh}->quote_identifier($procname);
for ( 1 .. scalar @call_args ) {
$argstr .= "?, ";
@@ -566,7 +570,7 @@ sub call_procedure {
if (scalar @call_args){
$sth->execute(@call_args) || $self->error($self->{dbh}->errstr);
} else {
- $sth->execute() || $self->error($self->{dbh}->errstr);
+ $sth->execute() || $self->error($self->{dbh}->errstr . ':' . $query);
}
my @types = @{$sth->{TYPE}};
diff --git a/LedgerSMB/Batch.pm b/LedgerSMB/Batch.pm
index 142a6bb4..34d0185c 100644
--- a/LedgerSMB/Batch.pm
+++ b/LedgerSMB/Batch.pm
@@ -31,11 +31,26 @@ sub get_search_criteria {
}
sub get_search_results {
- my ($self) = @_;
- @{$self->{search_results}} = $self->exec_method(funcname => 'batch_search');
+ my ($self, $args) = @_;
+ if ($args->{mini}){
+ $search_proc = "batch_search_mini";
+ } else {
+ $search_proc = "batch_search";
+ }
+ @{$self->{search_results}} = $self->exec_method(funcname => $search_proc);
return @{$self->{search_results}};
}
+sub get_class_id {
+ my ($self, $type) = @_;
+ @results = $self->call_procedure(
+ procname => 'batch_get_class_id',
+ args => [$type]
+ );
+ my $result = pop @results;
+ return $result->{batch_get_class_id};
+}
+
sub post {
my ($self) = @_;
($self->{post_return_ref}) = $self->exec_method(funcname => 'batch_post');
diff --git a/scripts/vouchers.pl b/scripts/vouchers.pl
index 152e43e7..7084232b 100644
--- a/scripts/vouchers.pl
+++ b/scripts/vouchers.pl
@@ -22,7 +22,8 @@ sub create_batch {
];
my $batch = LedgerSMB::Batch->new({base => $request});
- $batch->get_search_results;
+ $batch->{class_id} = $batch->get_class_id($batch->{batch_type});
+ $batch->get_search_results();
my $template = LedgerSMB::Template->new(
user =>$request->{_user},
diff --git a/sql/modules/Voucher.sql b/sql/modules/Voucher.sql
index c9d6cc60..5c236ed5 100644
--- a/sql/modules/Voucher.sql
+++ b/sql/modules/Voucher.sql
@@ -213,6 +213,44 @@ BEGIN
END;
$$ LANGUAGE PLPGSQL;
+CREATE OR REPLACE FUNCTION batch_get_class_id (in_type text) returns int AS
+$$
+SELECT id FROM batch_class WHERE class = $1;
+$$ language sql;
+
+CREATE OR REPLACE FUNCTION
+batch_search_mini
+(in_class_id int, in_description text, in_created_by_eid int, 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, NULL
+ 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)
+ JOIN voucher v ON (v.batch_id = b.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
+ LOOP
+ RETURN NEXT out_value;
+ END LOOP;
+END;
+$$ LANGUAGE PLPGSQL;
+
+
CREATE OR REPLACE FUNCTION batch_post(in_batch_id INTEGER)
diff --git a/t/01-load.t b/t/01-load.t
index 6d654615..aa3ab2d5 100644
--- a/t/01-load.t
+++ b/t/01-load.t
@@ -28,7 +28,7 @@ use_ok('LedgerSMB::PE');
use_ok('LedgerSMB::PriceMatrix');
use_ok('LedgerSMB::RC');
use_ok('LedgerSMB::RP');
-use_ok('LedgerSMB::Session');
+use_ok('LedgerSMB::Auth');
use_ok('LedgerSMB::Sysconfig');
use_ok('LedgerSMB::Tax');
use_ok('LedgerSMB::Template');