summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-12-21 02:37:23 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-12-21 02:37:23 +0000
commitd257ea9283277cfac10c93b247e252805119720f (patch)
treeec55763d004ec53e664efc56e4ffa682bb083284
parent948648b269291eb95e85fe8c726689b5924738a0 (diff)
Adding ability to delete vouchers from batch
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1989 4979c152-3d1c-0410-bac9-87ea11338e46
-rw-r--r--LedgerSMB/Batch.pm6
-rw-r--r--scripts/vouchers.pl42
-rw-r--r--sql/modules/Voucher.sql38
-rw-r--r--sql/modules/chart.sql13
4 files changed, 93 insertions, 6 deletions
diff --git a/LedgerSMB/Batch.pm b/LedgerSMB/Batch.pm
index a09031cd..127ee791 100644
--- a/LedgerSMB/Batch.pm
+++ b/LedgerSMB/Batch.pm
@@ -11,6 +11,12 @@ sub create {
return $ref->{id};
}
+sub delete_voucher {
+ my ($self, $voucher_id) = @_;
+ $self->call_procedure(procname => 'voucher__delete', args => [$voucher_id]);
+ $self->{dbh}->commit;
+}
+
sub get_search_criteria {
$self = shift @_;
@{$self->{batch_classes}} = $self->exec_method(
diff --git a/scripts/vouchers.pl b/scripts/vouchers.pl
index c4799bdf..1b5569d1 100644
--- a/scripts/vouchers.pl
+++ b/scripts/vouchers.pl
@@ -239,6 +239,7 @@ sub list_batches {
sub get_batch {
my ($request) = @_;
my $batch = LedgerSMB::Batch->new(base => $request);
+ $batch->{script} = 'vouchers.pl';
my $rows = [];
$batch->{id} ||= $batch->{batch_id};
@@ -247,8 +248,9 @@ sub get_batch {
my $base_href = "vouchers.pl?action=get_batch&batch_id=$batch->{batch_id}";
- my @columns = qw(id description batch_class reference amount date);
+ my @columns = qw(selected id description batch_class reference amount date);
my $heading = {
+ selected => $request->{_locale}->text('Selected'),
id => {
text => $request->{_locale}->text('ID'),
href => "$base_href&order_by=id"
@@ -276,7 +278,7 @@ sub get_batch {
};
my $classcount;
-
+ my $count = 1;
for my $row (@vouchers) {
$classcount = ($classcount + 1) % 2;
$classcount ||= 0;
@@ -287,10 +289,21 @@ sub get_batch {
amount => $batch->format_amount(amount => $row->{amount}),
date => $row->{transaction_date},
reference => $row->{reference},
- class => "listrow$classcount"
-
+ i => "$classcount",
+ selected => {
+ input => {
+ type => 'checkbox',
+ name => "voucher_$row->{id}",
+ value => "1"
+ }
+ }
};
+ $batch->{"row_$count"} = $row->{id};
+ ++$count;
}
+
+ $batch->{rowcount} = $count;
+
$batch->{title} = "Batch ID: $batch->{batch_id}";
my $template = LedgerSMB::Template->new(
user => $request->{_user},
@@ -309,15 +322,21 @@ sub get_batch {
buttons => [{
name => 'action',
type => 'submit',
- text => $request->{_locale}->text('Post'),
+ text => $request->{_locale}->text('Post Batch'),
value => 'batch_approve',
class => 'submit',
},{
name => 'action',
type => 'submit',
- text => $request->{_locale}->text('Delete'),
+ text => $request->{_locale}->text('Delete Batch'),
value => 'batch_delete',
class => 'submit',
+ },{
+ name => 'action',
+ type => 'submit',
+ text => $request->{_locale}->text('Delete Vouchers'),
+ value => 'voucher_delete',
+ class => 'submit',
}]
});
@@ -332,6 +351,17 @@ sub list_batches_batch_approve {
batch_approve(@_);
}
+sub get_batch_voucher_delete {
+ my ($request) = @_;
+ my $batch = LedgerSMB::Batch->new(base => $request);
+ for my $count (1 .. $batch->{rowcount}){
+ my $voucher_id = $batch->{"row_$count"};
+ next unless $batch->{"voucher_$voucher_id"};
+ $batch->delete_voucher($voucher_id);
+ }
+ search_batch($request);
+}
+
sub batch_approve {
my ($request) = @_;
my $batch = LedgerSMB::Batch->new(base => $request);
diff --git a/sql/modules/Voucher.sql b/sql/modules/Voucher.sql
index f095b92a..31de0bae 100644
--- a/sql/modules/Voucher.sql
+++ b/sql/modules/Voucher.sql
@@ -330,3 +330,41 @@ BEGIN
RETURN 1;
END;
$$ language plpgsql;
+
+CREATE OR REPLACE FUNCTION voucher__delete(in_voucher_id int)
+RETURNS int AS
+$$
+DECLARE
+ voucher_row RECORD;
+BEGIN
+ SELECT * INTO voucher_row FROM voucher WHERE id = in_voucher_id;
+ IF voucher_row.batch_class IN (1, 2, 5) THEN
+ DELETE from acc_trans WHERE trans_id = voucher_row.trans_id;
+ DELETE FROM ar WHERE id = voucher_row.trans_id;
+ DELETE FROM ap WHERE id = voucher_row.trans_id;
+ DELETE FROM gl WHERE id = voucher_row.trans_id;
+ DELETE FROM voucher WHERE id = voucher_row.id;
+ DELETE FROM transactions WHERE id = voucher_row.trans_id;
+ ELSE
+ update ar set paid = amount +
+ (select sum(amount) from acc_trans
+ join chart ON (acc_trans.chart_id = chart.id)
+ where link = 'AR' AND trans_id = ar.id
+ AND (voucher_id IS NULL
+ OR voucher_id <> voucher_row.id))
+ where id in (select trans_id from acc_trans
+ where voucher_id = voucher_row.id);
+
+ update ap set paid = amount - (select sum(amount) from acc_trans
+ join chart ON (acc_trans.chart_id = chart.id)
+ where link = 'AP' AND trans_id = ap.id
+ AND (voucher_id IS NULL
+ OR voucher_id <> voucher_row.id))
+ where id in (select trans_id from acc_trans
+ where voucher_id = voucher_row.id);
+
+ DELETE FROM acc_trans where voucher_id = voucher_row.id;
+ END IF;
+ RETURN 1;
+END;
+$$ LANGUAGE PLPGSQL;
diff --git a/sql/modules/chart.sql b/sql/modules/chart.sql
index 4575bc69..0a6b6e58 100644
--- a/sql/modules/chart.sql
+++ b/sql/modules/chart.sql
@@ -1,3 +1,16 @@
+CREATE OR REPLACE FUNCTION chart_list_all()
+RETURNS SETOF chart AS
+$$
+DECLARE out_row chart%ROWTYPE;
+BEGIN
+ FOR out_row IN
+ SELECT * FROM chart ORDER BY accno
+ LOOP
+ RETURN next out_row;
+ END LOOP;
+END;
+$$ LANGUAGE PLPGSQL;
+
CREATE OR REPLACE FUNCTION chart_list_cash(in_account_class int)
RETURNS SETOF chart AS
$$