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

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



Revision: 1989
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1989&view=rev
Author:   einhverfr
Date:     2007-12-20 18:37:23 -0800 (Thu, 20 Dec 2007)

Log Message:
-----------
Adding ability to delete vouchers from batch

Modified Paths:
--------------
    trunk/LedgerSMB/Batch.pm
    trunk/scripts/vouchers.pl
    trunk/sql/modules/Voucher.sql
    trunk/sql/modules/chart.sql

Modified: trunk/LedgerSMB/Batch.pm
===================================================================
--- trunk/LedgerSMB/Batch.pm	2007-12-21 01:56:50 UTC (rev 1988)
+++ trunk/LedgerSMB/Batch.pm	2007-12-21 02:37:23 UTC (rev 1989)
@@ -11,6 +11,12 @@
     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(

Modified: trunk/scripts/vouchers.pl
===================================================================
--- trunk/scripts/vouchers.pl	2007-12-21 01:56:50 UTC (rev 1988)
+++ trunk/scripts/vouchers.pl	2007-12-21 02:37:23 UTC (rev 1989)
@@ -239,6 +239,7 @@
 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 @@
 
     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 @@
     };
 
     my $classcount;
-
+    my $count = 1;
     for my $row (@vouchers) {
        $classcount = ($classcount + 1) % 2;
        $classcount ||= 0;
@@ -287,10 +289,21 @@
            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 @@
         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 @@
     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);

Modified: trunk/sql/modules/Voucher.sql
===================================================================
--- trunk/sql/modules/Voucher.sql	2007-12-21 01:56:50 UTC (rev 1988)
+++ trunk/sql/modules/Voucher.sql	2007-12-21 02:37:23 UTC (rev 1989)
@@ -330,3 +330,41 @@
 	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;

Modified: trunk/sql/modules/chart.sql
===================================================================
--- trunk/sql/modules/chart.sql	2007-12-21 01:56:50 UTC (rev 1988)
+++ trunk/sql/modules/chart.sql	2007-12-21 02:37:23 UTC (rev 1989)
@@ -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
 $$


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