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

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



Revision: 2170
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2170&view=rev
Author:   einhverfr
Date:     2008-06-23 14:57:46 -0700 (Mon, 23 Jun 2008)

Log Message:
-----------
Correcting missing files and commits

Modified Paths:
--------------
    trunk/scripts/vouchers.pl
    trunk/sql/modules/Drafts.sql

Added Paths:
-----------
    trunk/scripts/drafts.pl

Added: trunk/scripts/drafts.pl
===================================================================
--- trunk/scripts/drafts.pl	                        (rev 0)
+++ trunk/scripts/drafts.pl	2008-06-23 21:57:46 UTC (rev 2170)
@@ -0,0 +1,130 @@
+
+package LedgerSMB::Scripts::vouchers;
+our $VERSION = '0.1';
+
+use LedgerSMB::DBObject::Draft;
+use LedgerSMB::Template;
+use strict;
+
+sub search {
+    my ($request) = @_;
+    my $template = LedgerSMB::Template->new(
+        user =>$request->{_user}, 
+        locale => $request->{_locale},
+        path => 'UI',
+        template => 'batch/search_transactions',
+        format => 'HTML'
+    );
+    $template->render($request);
+}
+
+sub list_drafts {
+    my ($request) = @_;
+    my $draft= LedgerSMB::Draft->new(base => $request);
+    my @search_results = $draft->search;
+    $draft->{script} = "drafts.pl";
+
+    my @columns = 
+        qw(select id transdate reference description, amount);
+
+    my $base_href = "drafts.pl";
+    my $search_href = "$base_href?action=list_transactions";
+    my $draft_href= "$base_href?action=get_transaction";
+
+    for my $key (
+       qw(class_id approved created_by description amount_gt amount_lt)
+    ){
+       $search_href .= "&$key=$draft->{key}";
+    }
+
+    my %column_heading = (
+        'select'          => $draft->{_locale}->text('Select'),
+        transaction_total => {
+             text => $draft->{_locale}->text('AR/AP/GL Total'),
+             href => "$search_href&order_by=transaction_total"
+        },
+        payment_total     => { 
+             text => $draft->{_locale}->text('Paid/Received Total'),
+             href => "$search_href&order_by=payment_total"
+        },
+        description       => {
+             text => $draft->{_locale}->text('Description'),
+             href => "$search_href&order_by=description"
+        },
+        control_code      => {
+             text => $draft->{_locale}->text('Batch Number'),
+             href => "$search_href&order_by=control_code"
+        },
+        id                => {
+             text => $draft->{_locale}->text('ID'),
+             href => "$search_href&order_by=control_code"
+        },
+    );
+    my $count = 0;
+    my @rows;
+    for my $result (@search_results){
+        ++$count;
+        $draft->{"row_$count"} = $result->{id};
+        push @rows, {
+            'select'          => {
+                                 input => {
+                                           type  => 'checkbox',
+                                           value => 1,
+                                           name  => "draft_$result->{id}"
+                                 }
+            },
+            transaction_total => $draft->format_amount(
+                                     amount => $result->{transaction_total}
+				),
+            payment_total     => $draft->format_amount (
+                                     amount => $result->{payment_total}
+                                ),
+            description => $result->{description},
+            control_code => {
+                             text  => $result->{control_code},
+                             href  => "$draft_href&draft_id=$result->{id}",
+
+            },
+            id => $result->{id},
+        };
+    }
+    $draft->{rowcount} = $count;
+    my $template = LedgerSMB::Template->new(
+        user     => $request->{_user},
+        locale   => $request->{_locale},
+        path     => 'UI',
+        template => 'form-dynatable',
+        format   => ($draft->{format}) ? $draft->{format} : 'HTML', 
+    );
+
+    my $hiddens = $draft->take_top_level();
+    $draft->{rowcount} = "$count";
+    delete $draft->{search_results};
+
+    $template->render({ 
+	form    => $draft,
+	columns => ..hidden..,
+	heading => \%column_heading,
+        rows    => ..hidden..,
+        hiddens => $hiddens,
+        buttons => [{
+                    name  => 'action',
+                    type  => 'submit',
+                    text  => $request->{_locale}->text('Post'),
+                    value => 'draft_approve',
+                    class => 'submit',
+		},{
+                    name  => 'action',
+                    type  => 'submit',
+                    text  => $request->{_locale}->text('Delete'),
+                    value => 'draft_delete',
+                    class => 'submit',
+               }]
+    });
+}
+
+
+
+sub delete_drafts {
+    my ($request) = @_;
+}

Modified: trunk/scripts/vouchers.pl
===================================================================
--- trunk/scripts/vouchers.pl	2008-06-23 17:08:04 UTC (rev 2169)
+++ trunk/scripts/vouchers.pl	2008-06-23 21:57:46 UTC (rev 2170)
@@ -38,10 +38,6 @@
     add_vouchers($batch);
 }
 
-sub search_transactions {
-}
-
-
 sub add_vouchers {
     #  This function is not safe for caching as long as the scripts are in bin.
     #  This is because these scripts import all functions into the *current*

Modified: trunk/sql/modules/Drafts.sql
===================================================================
--- trunk/sql/modules/Drafts.sql	2008-06-23 17:08:04 UTC (rev 2169)
+++ trunk/sql/modules/Drafts.sql	2008-06-23 21:57:46 UTC (rev 2170)
@@ -1,6 +1,7 @@
 CREATE TYPE draft_search_result AS (
 	id int,
 	transdate date,
+	reference text,
 	description text,
 	amount numeric
 );
@@ -12,7 +13,8 @@
 DECLARE out_row RECORD;
 BEGIN
 	FOR out_row IN
-		SELECT trans.id, trans.transdate, trans.description, 
+		SELECT trans.id, trans.transdate, trans.reference, 
+			trans.description, 
 			sum(case when in_type = 'ap' AND chart.link = 'AP'
 				 THEN line.amount
 				 WHEN in_type = 'ar' AND chart.link = 'AR'
@@ -22,13 +24,16 @@
 			 	 ELSE 0
 			    END) as amount
 		FROM (
-			SELECT id, transdate, description, approved from ap
+			SELECT id, transdate, invnumber as reference, 
+				description, approved from ap
 			WHERE in_type = 'ap'
 			UNION
-			SELECT id, transdate, description, approved from ar
+			SELECT id, transdate, invnumber as reference,
+				description, approved from ar
 			WHERE in_type = 'ar'
 			UNION
-			SELECT id, transdate, description, approved from gl
+			SELECT id, transdate, reference, description, 
+				approved from gl
 			WHERE in_type = 'gl'
 			) trans
 		JOIN acc_trans line ON (trans.id = line.trans_id)
@@ -63,7 +68,19 @@
 	ELSE
 		raise exception 'Invalid table % in draft_approve for transaction %', t_table, in_id;
 	END IF;
-	RETURN FOUND;
+
+	IF NOT FOUND THEN
+		RETURN FALSE;
+	END IF;
+
+	UPDATE transactions 
+	SET approved_by = 
+			(select entity_id FROM users 
+			WHERE username = SESSION_USER), 
+		approved_at = now() 
+	WHERE id = in_id;
+
+	RETURN TRUE;
 END;
 $$ LANGUAGE PLPGSQL SECURITY DEFINER;
 


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