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

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



Revision: 4840
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4840&view=rev
Author:   einhverfr
Date:     2012-06-05 12:47:58 +0000 (Tue, 05 Jun 2012)
Log Message:
-----------
New transaction/outstanding reports almost working

Modified Paths:
--------------
    trunk/LedgerSMB/AA.pm
    trunk/LedgerSMB/Scripts/journal.pm
    trunk/UI/lib/report_base.html
    trunk/bin/aa.pl
    trunk/sql/Pg-database.sql

Added Paths:
-----------
    trunk/LedgerSMB/DBObject/Report/Contact/Purchase.pm
    trunk/UI/Reports/filters/search_purchases.html

Modified: trunk/LedgerSMB/AA.pm
===================================================================
--- trunk/LedgerSMB/AA.pm	2012-06-05 07:33:11 UTC (rev 4839)
+++ trunk/LedgerSMB/AA.pm	2012-06-05 12:47:58 UTC (rev 4840)
@@ -852,406 +852,6 @@
 
 =cut
 
-# This is going to get a little awkward because it involves delving into the 
-# acc_trans table in order to avoid catching unapproved payment vouchers.
-sub transactions {
-    my ( $self, $myconfig, $form ) = @_;
-
-    # connect to database
-    my $dbh = $form->{dbh};
-    my $null;
-    my $var;
-    my $paid    = "a.paid";
-    my $ml      = 1;
-    my $ARAP    = 'AR';
-    my $table   = 'ar';
-    my $buysell = 'buy';
-    my $acc_trans_join;
-    my $acc_trans_flds;
-    my $approved = ($form->{approved}) ? 'TRUE' : 'FALSE';
-
-    #print STDERR localtime()." AA.pm transactions \$approved=$approved\n";
-
-    if ( $form->{vc} eq 'vendor' ) {
-        $ml      = -1;
-        $ARAP    = 'AP';
-        $table   = 'ap';
-        $buysell = 'sell';
-    }
-    $form->{db_dateformat} = $myconfig->{dateformat};
-
-    ( $form->{transdatefrom}, $form->{transdateto} ) =
-      $form->from_to( $form->{year}, $form->{month}, $form->{interval} )
-      if (($form->{year} && $form->{month}) && 
-          (!$form->{transdatefrom} && !$form->{transdateto}));
-
-    my @paidargs = ();
-    if ( $form->{outstanding} ) {
-        if ( $form->{transdateto} ) {
-            $paid .= qq|
-			       AND ac.transdate <= ?|;
-       #     push @paidargs, $form->{transdateto};
-        }
-    }
-
-    if ( !$form->{summary} and !$form->{outstanding} ) {
-        $acc_trans_flds = qq|
-			, c.accno, ac.source,
-			ac.memo AS description,
-			ac.amount AS linetotal,
-			i.description AS linedescription|;
-        $group_by_fields = qq|, c.accno, ac.source, ac.memo,
-                              ac.amount, i.description |;
-
-        $acc_trans_join = qq| 
-			     JOIN acc_trans ac ON (a.id = ac.trans_id)
-			     JOIN chart c ON (c.id = ac.chart_id 
-                                              AND charttype = 'A')
-			LEFT JOIN invoice i ON (i.id = ac.invoice_id)|;
-    }
-    #print STDERR localtime()." AA.pm transactions summary=$form->{summary} outstanding=$form->{outstanding} group_by_fields=$group_by_fields\n";
-    my $query;
-    if ($form->{outstanding}){
-        # $form->{ARAP} is safe since it is set in calling scripts and not passed from the UA
-        my $p = $LedgerSMB::Sysconfig::decimal_places;
-        if ($form->{transdateto} eq ''){
-            delete $form->{transdateto};
-        }
-        if ($form->{summary}){
-            $query = qq|
-		   SELECT count(a.id) as invnumber, min(a.transdate) as transdate,
-		          min(a.duedate) as duedate, 
-		          sum(a.netamount) as netamount, 
-		          sum(a.amount::numeric(20,$p)) as amount, 
-		          sum(a.amount::numeric(20,$p)) 
-                             - (sum(acs.amount::numeric(20,$p)) 
-                                * CASE WHEN '$table' = 'ar' THEN -1 ELSE 1 END)
-                          AS paid,
-		          vce.name, vc.meta_number,
-		          a.entity_credit_account
-		     FROM $table a
-		     JOIN entity_credit_account vc ON (a.entity_credit_account = vc.id)
-		     JOIN acc_trans acs ON (acs.trans_id = a.id)
-		     JOIN entity vce ON (vc.entity_id = vce.id)
-		     JOIN chart c ON (acs.chart_id = c.id 
-                                     AND charttype = 'A')
-		LEFT JOIN exchangerate ex ON (ex.curr = a.curr
-		          AND ex.transdate = a.transdate)
-		$acc_trans_join
-		    WHERE c.link = '$form->{ARAP}' AND 
-		          (|.$dbh->quote($form->{transdateto}) . qq| IS NULL OR 
-		           |.$dbh->quote($form->{transdateto}) . qq| >= acs.transdate)
-			AND a.approved IS TRUE AND acs.approved IS TRUE
-			AND a.force_closed IS NOT TRUE
-		 GROUP BY 
-		          vc.meta_number, a.entity_credit_account, vce.name 
-		   HAVING abs(sum(acs.amount::numeric(20,2))) > 0.000 |;
-        } else {
-            #HV typo error a.ponumber $acc_trans_fields -> a.ponumber $acc_trans_flds
-            $query = qq|
-		   SELECT a.id, a.invnumber, a.ordnumber, a.transdate,
-		          a.duedate, a.netamount, a.amount::numeric(20,$p), 
-		          a.amount::numeric(20,$p)
-                             - (sum(acs.amount::numeric(20,$p)) 
-                                * CASE WHEN '$table' = 'ar' THEN -1 ELSE 1 END)
-                          AS paid,
-		          a.invoice, a.datepaid, a.terms, a.notes,
-		          a.shipvia, a.shippingpoint, 
-		          vce.name, vc.meta_number,
-		          a.entity_credit_account, a.till, 
-		          ex.$buysell AS exchangerate, 
-		          a.ponumber $acc_trans_flds
-		     FROM $table a
-		     JOIN entity_credit_account vc ON (a.entity_credit_account = vc.id)
-		     JOIN acc_trans acs ON (acs.trans_id = a.id)
-		     JOIN entity vce ON (vc.entity_id = vce.id)
-		     JOIN chart c ON (acs.chart_id = c.id
-                                      AND charttype='A')
-		LEFT JOIN exchangerate ex ON (ex.curr = a.curr
-		          AND ex.transdate = a.transdate)
-		$acc_trans_join
-		    WHERE c.link = '$ARAP' AND 
-		          (|.$dbh->quote($form->{transdateto}) . qq| IS NULL OR 
-		           |.$dbh->quote($form->{transdateto}) . qq| >= acs.transdate)
-			AND a.approved IS TRUE AND acs.approved IS TRUE
-			AND a.force_closed IS NOT TRUE
-		 GROUP BY a.id, a.invnumber, a.ordnumber, a.transdate, a.duedate, a.netamount,
-		          a.amount, a.terms, a.notes, a.shipvia, a.shippingpoint, vce.name,
-		          vc.meta_number, a.entity_credit_account, a.till, ex.$buysell, vce.name,
-		          a.ponumber, a.invoice, a.datepaid $acc_trans_flds
-		   HAVING abs(sum(acs.amount::numeric(20,$p))) > 0 |;
-       } 
-    } else {
-        # XXX MUST BE PORTED TO NEW BUSINESS UNIT FRAMEWORK
-        $query = qq|
-		   SELECT a.id, a.invnumber, a.ordnumber, a.transdate,
-		          a.duedate, a.netamount, a.amount, 
-                          (a.amount - pd.due) AS paid,
-		          a.invoice, a.datepaid, a.terms, a.notes,
-		          a.shipvia, a.shippingpoint, ee.name AS employee, 
-		          vce.name, vc.meta_number,
-		          vc.entity_id, a.till, me.name AS manager, a.curr,
-		          ex.$buysell AS exchangerate, 
-		          a.ponumber
-                          $acc_trans_flds
-		     FROM $table a
-		     JOIN entity_credit_account vc ON (a.entity_credit_account = vc.id)
-                     JOIN acc_trans ac ON (a.id = ac.trans_id)
-                     JOIN chart c ON (c.id = ac.chart_id)
-                     JOIN (SELECT acc_trans.trans_id,
-                                sum(CASE WHEN '$table' = 'ap' THEN amount
-                                         WHEN '$table' = 'ar'
-                                         THEN amount * -1
-                                    END) AS due
-                           FROM acc_trans
-                           JOIN account coa ON (coa.id = acc_trans.chart_id)
-                           JOIN account_link al ON (al.account_id = coa.id)
-                          WHERE ((al.description = 'AP' AND '$table' = 'ap')
-                                OR (al.description = 'AR' AND '$table' = 'ar'))
-                          AND (approved IS TRUE)
-                       GROUP BY acc_trans.trans_id) pd ON (a.id = pd.trans_id)
-		LEFT JOIN entity_employee e ON (a.person_id = e.entity_id)
-		LEFT JOIN entity_employee m ON (e.manager_id = m.entity_id)
-		LEFT JOIN entity ee ON (e.entity_id = ee.id)
-                LEFT JOIN entity me ON (m.entity_id = me.id)
-		     JOIN entity vce ON (vc.entity_id = vce.id)
-		LEFT JOIN exchangerate ex ON (ex.curr = a.curr
-		          AND ex.transdate = a.transdate)
-                LEFT JOIN invoice i ON (i.trans_id = a.id) |;
-        $group_by = qq| 
-                GROUP BY  a.id, a.invnumber, a.ordnumber, a.transdate,
-                          a.duedate, a.netamount, a.amount,
-                          a.invoice, a.datepaid, a.terms, a.notes,
-                          a.shipvia, a.shippingpoint, ee.name , 
-                          vce.name, vc.meta_number, a.amount, pd.due,
-                          vc.entity_id, a.till, me.name, a.curr,
-                          ex.$buysell, a.ponumber $group_by_fields|;
-    }
-
-    my %ordinal = (
-        id            => 1,
-        invnumber     => 2,
-        ordnumber     => 3,
-        transdate     => 4,
-        duedate       => 5,
-        datepaid      => 10,
-        shipvia       => 13,
-        shippingpoint => 14,
-        employee      => 15,
-        name          => 16,
-        manager       => 20,
-        curr          => 21,
-        department    => 23,
-        ponumber      => 24,
-        accno         => 25,
-        source        => 26,
-        project       => 27,
-        description   => 28
-    );
-
-    my @a = qw( transdate invnumber name );
-    push @a, "employee" if $form->{l_employee};
-    push @a, "manager"  if $form->{l_manager};
-    my $sortorder = $form->sort_order( ..hidden.., \%ordinal );
-
-    my $where = "";
-    if (!$form->{outstanding}){
-        $where = "1 = 1";
-    }
-    if ($form->{"meta_number"}){
-        $where .= " AND vc.meta_number = " . $dbh->quote($form->{meta_number});
-    }
-    if ( $form->{"$form->{vc}_id"} ) {
-        $form->{entity_id} = $form->{$form->{vc}."_id"};
-        $where .= qq| AND a.entity_id = $form->{entity_id}|;
-    }
-    else {
-        if ( $form->{ $form->{vc} } ) {
-            $var = $dbh->quote( $form->like( lc $form->{ $form->{vc} } ) );
-            $where .= " AND lower(vce.name) LIKE $var";
-        }
-    }
-
-    for (qw(department_id entity_credit_account)) {
-        if ( $form->{$_} ) {
-            ( $null, $var ) = split /--/, $form->{$_};
-            $var = $dbh->quote($var);
-            $where .= " AND a.$_ = $var";
-        }
-    }
-
-    for (qw(invnumber ordnumber)) {
-        if ( $form->{$_} ) {
-            $var = $dbh->quote( $form->like( lc $form->{$_} ) );
-            $where .= " AND lower(a.$_) LIKE $var";
-            $form->{open} = $form->{closed} = 0;
-        }
-    }
-    if ( $form->{partsid} ) {
-        my $partsid = $dbh->quote( $form->{partsid} );
-        $where .= " AND a.id IN (select trans_id FROM invoice
-			WHERE parts_id = $partsid)";
-    }
-
-    for (qw(ponumber shipvia notes)) {
-        if ( $form->{$_} ) {
-            $var = $dbh->quote( $form->like( lc $form->{$_} ) );
-            $where .= " AND lower(a.$_) LIKE $var";
-        }
-    }
-
-    if ( $form->{description} ) {
-        if ($acc_trans_flds) {
-            $var = $dbh->quote( $form->like( lc $form->{description} ) );
-            $where .= " AND lower(ac.memo) LIKE $var
-			OR lower(i.description) LIKE $var";
-        }
-        else {
-            $where .= " AND a.id = 0";
-        }
-    }
-
-    if ( $form->{source} ) {
-        if ($acc_trans_flds) {
-            $var = $dbh->quote( $form->like( lc $form->{source} ) );
-            $where .= " AND lower(ac.source) LIKE $var";
-        }
-        else {
-            $where .= " AND a.id = 0";
-        }
-    }
-
-    my $transdatefrom = $dbh->quote( $form->{transdatefrom} );
-    $where .= " AND a.transdate >= $transdatefrom"
-      if $form->{transdatefrom};
-
-    my $transdateto = $dbh->quote( $form->{transdateto} );
-    $where .= " AND a.transdate <= $transdateto" if $form->{transdateto};
-
-    if ( $form->{open} || $form->{closed} ) {
-        unless ( $form->{open} && $form->{closed} ) {
-            $where .= " AND pd.due <> 0" if ( $form->{open} );
-            $where .= " AND pd.due = 0"  if ( $form->{closed} );
-        }
-    }
-
-    if ( $form->{till} ne "" ) {
-	$form->{till} = $dbh->quote($form->{till});
-        $where .= " AND a.invoice = '1'
-					AND a.till = $form->{till}";
-
-        if ( $myconfig->{role} eq 'user' ) {
-            my $login = $dbh->quote( $form->{login} );
-            $where .= " AND e.entity_id = (select entity_id from users where username = $login";
-        }
-    }
-
-    if ( $form->{$ARAP} ) {
-        my ($accno) = split /--/, $form->{$ARAP};
-        $accno = $dbh->quote($accno);
-        $where .= qq|
-			AND a.id IN (SELECT ac.trans_id
-			               FROM acc_trans ac
-			               JOIN chart c ON (c.id = ac.chart_id AND charttype = 'A')
-			              WHERE a.id = ac.trans_id
-			                    AND c.accno = $accno)|;
-    }
-
-    if ( $form->{description} ) {
-        $var = $dbh->quote( $form->like( lc $form->{description} ) );
-        $where .= qq|
-			AND (a.id IN (SELECT DISTINCT trans_id
-			                FROM acc_trans
-			               WHERE lower(memo) LIKE $var)
-			                     OR a.id IN 
-			                     (SELECT DISTINCT trans_id
-			                                 FROM invoice
-			                                WHERE lower(description)
-			                                      LIKE $var))|;
-    }
-    
-    if ($form->{invoice_type}) {
-        
-        if ( $form->{invoice_type} == 2 ) {
-        
-            $where .= qq|
-                AND a.on_hold = 'f'        
-            |;
-        }
-    
-        if ($form->{invoice_type} == 3) {
-        
-            $where .= qq|
-                AND a.on_hold = 't'
-            |;
-        }
-    }
-    
-    # the third state, all invoices, sets no explicit toggles. It just selects them all, as normal. 
-    # $approved is safe as it is set to either "TRUE" or "FALSE"
-    if ($form->{outstanding}){
-        if ($where ne ""){
-            $query =~ s/GROUP BY / $where \n GROUP BY /;
-        }
-	if ($form->{summary}){
-		$sortorder = "vc.meta_number";
-	}
-        $query .= "\n ORDER BY $sortorder";
-    } else {
-        $query .= "WHERE ($approved OR a.approved) AND $where
-                   $group_by
-			ORDER BY $sortorder";
-    }
-    #print STDERR localtime()." AA.pm transactions query=$query\n";
-    my $sth = $dbh->prepare($query);
-    $sth->execute(@paidargs) || $form->dberror($query);
-
-    while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
-	$form->db_parse_numeric(sth => $sth, hashref => $ref);
-        $ref->{exchangerate} = 1 unless $ref->{exchangerate};
-
-        if ( $ref->{linetotal} <= 0 ) {
-            $ref->{debit}  = $ref->{linetotal} * -1;
-            $ref->{credit} = 0;
-        }
-        else {
-            $ref->{debit}  = 0;
-            $ref->{credit} = $ref->{linetotal};
-        }
-
-        if ( $ref->{invoice} ) {
-            $ref->{description} ||= $ref->{linedescription};
-        }
-
-        #print STDERR localtime()." AA.pm transactions row=".Data::Dumper::Dumper($ref)."\n";
-        push @{ $form->{transactions} }, $ref;
-    }
-
-    $sth->finish;
-    $dbh->commit;
-}
-
-# this is used in IS, IR to retrieve the name
-
-=item get_name(\%myconfig, $form)
-
-Retrieves the last account used.  Also retrieves tax accounts,
-departments, and a few other things.
-
-Form variables used:
-vc: customer or vendor
-${vc}_id:  id of vendor/customemr
-transdate:  Transaction date desired
-
-Sets the following form variables
-currency
-exchangerate
-forex
-taxaccounts
-
-
-=cut
-
 sub get_name {
 
     my ( $self, $myconfig, $form ) = @_;

Added: trunk/LedgerSMB/DBObject/Report/Contact/Purchase.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Report/Contact/Purchase.pm	                        (rev 0)
+++ trunk/LedgerSMB/DBObject/Report/Contact/Purchase.pm	2012-06-05 12:47:58 UTC (rev 4840)
@@ -0,0 +1,339 @@
+=head1 NAME
+
+LedgerSMB::DBObject::Report::Contact::Purchase - Search AR/AP Transactions and
+generate Reports
+
+=head1 SYNPOSIS
+
+  my $report = LedgerSMB::DBObject::Report::Contact::Purchase->new(%$request);
+  $report->run;
+  $report->render($request, $format);
+
+=head1 DESCRIPTION
+
+This report provides the capacity to generate reports equivalent to the AR and
+AP transaction and outstanding reports in 1.3 and earlier.  General uses include
+reviewing outstanding transactions, transactions that were outstanding at a
+certain point, and locating specific transactions.
+
+=head1 INHERITS
+
+=over
+
+=item LedgerSMB::DBObject::Report;
+
+=back
+
+=cut
+
+package LedgerSMB::DBObject::Report::Contact::Purchase;
+use Moose;
+extends 'LedgerSMB::DBObject::Report';
+use LedgerSMB::App_State;
+use LedgerSMB::PGDate;
+
+my $locale = $LedgerSMB::App_State::Locale;
+
+=head1 PROPERTIES
+
+=over
+
+=item columns
+
+Read-only accessor, returns a list of columns.
+
+=over
+
+=back
+
+=cut
+
+sub columns {
+    return [
+         {col_id => 'running_number',
+            type => 'text',
+            name => '' },
+
+         {col_id => 'id',
+            type => 'text',
+            name => $locale->text('ID') },
+
+         {col_id => 'invnumber',
+            type => 'href',
+       href_base => '',
+            name => $locale->text('Invoice Number') },
+
+         {col_id => 'ordnumber',
+            type => 'text',
+            name => $locale->text('Order Number') },
+
+         {col_id => 'ponumber',
+            type => 'text',
+            name => $locale->text('PO Number') },
+
+         {col_id => 'curr',
+            type => 'text',
+            name => $locale->text('Currency') },
+        
+         {col_id => 'amount',
+            type => 'text',
+            name => $locale->text('Amount') },
+
+         {col_id => 'tax',
+            type => 'text',
+            name => $locale->text('Tax') },
+
+         {col_id => 'paid',
+            type => 'text',
+            name => $locale->text('Paid') },
+
+         {col_id => 'due',
+            type => 'text',
+            name => $locale->text('Due') },
+
+         {col_id => 'date_paid',
+            type => 'text',
+            name => $locale->text('Date Paid') },
+
+         {col_id => 'due_date',
+            type => 'text',
+            name => $locale->text('Due Date') },
+
+         {col_id => 'notes',
+            type => 'text',
+            name => $locale->text('Notes') },
+
+         {col_id => 'shipping_point',
+            type => 'text',
+            name => $locale->text('Shipping Point') },
+
+         {col_id => 'ship_via',
+            type => 'text',
+            name => $locale->text('Ship Via') },
+    ];
+}
+
+=item name
+
+=cut
+
+sub name { 
+   my ($self) = @_;
+   if ($self->entity_class == 1){
+       return $locale->text('AP Transactions'); 
+   } elsif ($self->entity_class == 2){
+       return $locale->text('AR Transactions');
+   }
+}
+
+=item header_lines
+
+=cut
+
+sub header_lines {
+     return [
+            {name => 'name_part',
+             text => $locale->text('Name')},
+            {name => 'meta_number',
+             text => $locale->text('Account Number')}
+       ]; 
+}
+
+=back
+
+=head1 CRITERIA PROPERTIES
+
+=over
+
+=item entity_class
+
+Must be 1 for vendor or 2 for customer.  No other values will return any values.
+
+=cut
+
+has entity_class => (is => 'ro', isa => 'Int');
+
+=item accno
+
+Account Number for search.  If set can be either in the form of the actual 
+account number itself or in the form of accno--description (returned by the
+current ajaxselect implementation).
+
+=cut
+
+has accno => (is => 'rw', isa => 'Maybe[Str]');
+
+=item name_part
+
+Full text search on contact name.
+
+=cut
+
+has name_part => (is => 'ro', isa => 'Maybe[Str]');
+
+=item meta_number
+
+Matches the beginning of the meta_number for the entity credit account.
+
+=cut
+
+has meta_number => (is => 'ro', isa => 'Maybe[Str]');
+
+=item invnumber
+
+Invoice number.  Matches the beginning of the string.
+
+=cut
+
+has invnumber => (is => 'ro', isa => 'Maybe[Str]');
+
+=item ordnumber
+
+Order number.  Matches the beginning of the string.
+
+=cut
+
+has ordnumber => (is => 'ro', isa => 'Maybe[Str]');
+
+=item ponumber
+
+Purchas order number.  Matches the beginning of the string.
+
+=cut
+
+has ponumber => (is => 'ro', isa => 'Maybe[Str]');
+
+=item source
+
+Matches any source field in line item details.  This can be used to see which
+invoices were paid by a specific payment.
+
+=cut
+
+has source => (is => 'ro', isa => 'Maybe[Str]');
+
+=item description
+
+Full text search on transaction description
+
+=cut
+
+has description => (is => 'ro', isa => 'Maybe[Str]');
+
+=item notes
+
+Full text search on notes of invoice
+
+=cut
+
+has notes => (is => 'ro', isa => 'Maybe[Str]');
+
+=item ship_via
+
+Full text search on ship_via field.
+
+=cut
+
+has ship_via => (is => 'ro', isa => 'Maybe[Str]');
+
+=item from_date
+
+Invoices posted starting on this date
+
+=cut
+
+has from_date => (is => 'ro', isa => 'Maybe[LedgerSMB::PGDate]');
+
+=item to_date
+
+Invoices posted no later than this date
+
+=cut
+
+has to_date => (is => 'ro', isa => 'Maybe[LedgerSMB::PGDate]');
+
+=item as_of
+
+Shows invoice balances as of this date.
+
+=cut
+
+has as_of => (is => 'ro', isa => 'Maybe[LedgerSMB::PGDate]');
+
+=item summarize
+
+Tells whether to summarize the report (i.e. produce a summary report rather than
+a detail report).
+
+=cut
+
+has summarize => (is => 'ro', isa => 'Bool');
+
+=back
+
+=head1 METHODS
+
+=over 
+
+=item prepare_criteria
+
+Converts inputs to PgDate where needed
+
+=cut
+
+sub prepare_criteria {
+    my ($self, $request) = @_;
+    $request->{as_of} = LedgerSMB::PGDate->from_input(
+               $request->{as_of}
+    );
+    $self->prepare_input($request);
+}
+
+=item run_report
+
+Runs the report, populates rows.
+
+=cut
+
+sub run_report {
+    my ($self) = @_;
+    my @rows;
+    if ($self->summarize){
+       @rows = $self->exec_method({
+               funcname => 'ar_ap__transaction_search_summary'}
+       );
+    } else {
+       @rows = $self->exec_method({funcname => 'ar_ap__transaction_search'});
+       for my $r (@rows){
+            my $href;
+            if ($r->invoice){
+                if ($self->entity_class == 1) {
+                    $href = 'ir.pl';
+                } else {
+                    $href = 'is.pl';
+                }
+            } else {
+                if ($self->entity_class == 1) {
+                    $href = 'ap.pl';
+                } else {
+                    $href = 'ar.pl';
+                }
+            } 
+            $r->{invnumber_href_suffix} = "$href?action=edit&id=$r->{id}";
+       }
+    }
+    $self->rows(..hidden..);
+}
+
+=back
+
+=head1 COPYRIGHT
+
+COPYRIGHT (C) 2012 The LedgerSMB Core Team.  This file may be re-used following
+the terms of the GNU General Public License version 2 or at your option any
+later version.  Please see included LICENSE.TXT for details.
+
+=cut
+
+__PACKAGE__->meta->make_immutable;
+return 1;

Modified: trunk/LedgerSMB/Scripts/journal.pm
===================================================================
--- trunk/LedgerSMB/Scripts/journal.pm	2012-06-05 07:33:11 UTC (rev 4839)
+++ trunk/LedgerSMB/Scripts/journal.pm	2012-06-05 12:47:58 UTC (rev 4840)
@@ -100,6 +100,26 @@
     $report->render($request);
 }
 
+=item search_purchases
+
+Runs a search of AR or AP transactions and displays results.
+
+=cut
+
+sub search_purchases {
+    my ($request) = @_;
+    use LedgerSMB::DBObject::Report::Contact::Purchase;
+    $request->{business_units} = [];
+    for my $count (1 .. $request->{bc_count}){
+         push @{$request->{business_units}}, $request->{"business_unit_$count"}
+               if $request->{"business_unit_$count"};
+    }
+    LedgerSMB::DBObject::Report::Contact::Purchase->prepare_criteria($request);
+    my $report = LedgerSMB::DBObject::Report::Contact::Purchase->new(%$request);
+    $report->run_report;
+    $report->render($request);
+}
+
 =back
 
 =head1 Copyright (C) 2007 The LedgerSMB Core Team

Added: trunk/UI/Reports/filters/search_purchases.html
===================================================================
--- trunk/UI/Reports/filters/search_purchases.html	                        (rev 0)
+++ trunk/UI/Reports/filters/search_purchases.html	2012-06-05 12:47:58 UTC (rev 4840)
@@ -0,0 +1,433 @@
+<?lsmb INCLUDE 'ui-header.html' 
+       	include_script = ["UI/ajax/scriptaculous/lib/prototype.js","UI/ajax/scriptaculous/src/scriptaculous.js?load=builder,effects,dragdrop,controls","UI/ajax/helpers.js"]
+?>
+<?lsmb PROCESS 'elements.html';
+       PROCESS 'report_base.html';
+
+IF entity_class == 1; 
+    report_type = 'AR'; 
+    name_label = text('Vendor');
+    eca_label = text('Vendor Number'); #'
+END;
+IF entity_class == 2; 
+    report_type = 'AP'; 
+    name_label = text('Customer');
+    eca_label = text('Customer Number'); #'
+END;
+
+ ?>
+<body>
+
+<form method="get" action="journal.pl">
+<?lsmb PROCESS input element_data = {
+    name = 'entity_class'
+    type = 'hidden'
+   value = entity_class
+} ?>
+<table width="100%">
+  <tr>
+    <th class="listtop"><?lsmb text('Search Transactions', ) ?></th>
+
+  </tr>
+  <tr height="5"></tr>
+  <tr>
+    <td>
+      <table>
+         <tr>
+          <th align="right"><?lsmb text('Account') ?></th>
+          <td colspan="3">
+              <?lsmb PROCESS ajaxselect element_data = {
+                     name = "accno"
+                     initial_value = accno
+                     text_attr = 'accno'
+                     value_attr = 'id'
+                     ajax_target = 'journal.pl'
+                     params = { link_desc = report_type }
+              } ?> </td>
+	  </tr>
+	<tr>
+         <th align="right"><?lsmb name_label ?></th>
+         <td colspan="3">
+              <?lsmb PROCESS input element_data = {
+                     name = 'name_part'
+                     type = 'text'
+                    value = name_part
+                     size = 32
+                    class = 'name'
+               } ?>
+         </td>
+        </tr>
+	<tr>
+         <th align="right"><?lsmb eca_label ?></th>
+         <td colspan="3">
+              <?lsmb PROCESS input element_data = {
+                     name = 'meta_number'
+                     type = 'text'
+                    value = meta_number
+                     size = 32
+                    class = 'control-code'
+               } ?>
+         </td>
+        </tr>
+        <?lsmb PROCESS business_classes ?>
+	<tr>
+         <th align="right"><?lsmb text('Invoice Number') ?></th>
+         <td colspan="3">
+              <?lsmb PROCESS input element_data = {
+                     name = 'invnumber'
+                     type = 'text'
+                    value = invnumber
+                     size = 32
+                    class = 'control-code'
+               } ?>
+         </td>
+        </tr>
+	<tr>
+         <th align="right"><?lsmb text('Order Number') ?></th>
+         <td colspan="3">
+              <?lsmb PROCESS input element_data = {
+                     name = 'meta_number'
+                     type = 'text'
+                    value = ordnumber
+                     size = 32
+                    class = 'control-code'
+               } ?>
+         </td>
+        </tr>
+	<tr>
+         <th align="right"><?lsmb text('PO Number') ?></th>
+         <td colspan="3">
+              <?lsmb PROCESS input element_data = {
+                     name = 'ponumber'
+                     type = 'text'
+                    value = ponumber
+                     size = 32
+                    class = 'control-code'
+               } ?>
+         </td>
+        </tr>
+	<tr>
+         <th align="right"><?lsmb text('Source') ?></th>
+         <td colspan="3">
+              <?lsmb PROCESS input element_data = {
+                     name = 'source'
+                     type = 'text'
+                    value = source
+                     size = 32
+                    class = 'control-code'
+               } ?>
+         </td>
+        </tr>
+	<tr>
+         <th align="right"><?lsmb text('Description') ?></th>
+         <td colspan="3">
+              <?lsmb PROCESS input element_data = {
+                     name = 'description'
+                     type = 'text'
+                    value = description
+                     size = 40
+                    class = 'description'
+               } ?>
+         </td>
+        </tr>
+	<tr>
+         <th align="right"><?lsmb text('Notes') ?></th>
+         <td colspan="3">
+              <?lsmb PROCESS input element_data = {
+                     name = 'notes'
+                     type = 'text'
+                    value = notes
+                     size = 40
+                    class = 'notes'
+               } ?>
+         </td>
+        </tr>
+	<tr>
+         <th align="right"><?lsmb text('Ship via') ?></th>
+         <td colspan="3">
+              <?lsmb PROCESS input element_data = {
+                     name = 'ship_via'
+                     type = 'text'
+                    value = ship_via
+                     size = 40
+                    class = 'description'
+               } ?>
+         </td>
+        </tr>
+        <?lsmb PROCESS date_row ?>
+	<tr>
+         <th align="right"><?lsmb text('Payments As Of') ?></th>
+         <td colspan="3">
+              <?lsmb PROCESS input element_data = {
+                     name = 'as_of'
+                     type = 'text'
+                    value = as_of
+                     size = 11
+                    class = 'date'
+               } ?>
+         </td>
+        </tr>
+	<tr>
+         <th align="right"><?lsmb text('Report Type') ?></th>
+         <td colspan='3'>
+              <?lsmb PROCESS input element_data = {
+                     name = 'summarize'
+                     type = 'radio'
+                    label = text('Summary')
+                    value = '1'
+                  checked = 'checked'
+               } ?>&nbsp;&nbsp;&nbsp;
+              <?lsmb PROCESS input element_data = {
+                     name = 'summarize'
+                     type = 'radio'
+                    label = text('Detail')
+                    value = '0'
+               } ?>
+         </td>
+        </tr>
+         <th><?lsmb text('Include In Report') ?></th>
+            <td colspan='7'>
+              <table class='criteria'>
+                 <tr>
+                    <td>
+                        <?lsmb PROCESS input element_data = {
+                            name = 'on_hold'
+                            type = 'radio'
+                           label = text('All Invoices') #'
+                           value = ''
+                         checked = 'checked'
+                        } ?>
+                    </td>
+                    <td>
+                       <?lsmb PROCESS input element_data = {
+                          name = 'on_hold'
+                          type = 'radio'
+                         label = text('Active')
+                         value = '0'
+                       } ?>
+                    </td>
+                    <td>
+                       <?lsmb PROCESS input element_data = {
+                          name = 'on_hold'
+                          type = 'radio'
+                         label = text('On Hold') #'
+                         value = '1'
+                       } ?>
+                    </td>
+                  </tr>
+                  <tr>
+                    <td>
+                       <?lsmb PROCESS input element_data = {
+                          name = 'inc_open'
+                          type = 'checkbox'
+                       checked = 'checked'
+                         label = text('Open')
+                         value = 1
+                       } ?>
+                    </td>
+                    <td> 
+                       <?lsmb PROCESS input element_data = {
+                          name = 'inc_closed'
+                          type = 'checkbox'
+                         label = text('Closed')
+                         value = 1
+                       } ?>
+                    </td>
+                  </tr>
+                  <tr>
+                    <td colspan="3"><hr /></td>
+                  </tr>
+                  <tr>
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'col_running_number'
+                            type = 'checkbox' 
+                           value = 1
+                           label = text('Running Number') #'
+                      } ?>
+                    </td> 
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'col_id'
+                            type = 'checkbox' 
+                           value = 1
+                           label = text('ID')
+                      } ?>
+                    </td> 
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'col_invnumber'
+                            type = 'checkbox' 
+                           value = 1
+                           label = text('Invoice Number') #'
+                         checked = 'checked'
+                      } ?>
+                    </td> 
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'col_ordnumber'
+                            type = 'checkbox' 
+                           value = 1
+                           label = text('Order Number') #'
+                      } ?>
+                    </td> 
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'col_ponumber'
+                            type = 'checkbox' 
+                           value = 1
+                           label = text('PO Number') #'
+                      } ?>
+                    </td> 
+                  </tr>
+                  <tr>
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'col_transdate'
+                            type = 'checkbox' 
+                           value = 1
+                         checked = 'checked'
+                           label = text('Invoice Date') #'
+                      } ?>
+                    </td> 
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'col_business_units'
+                            type = 'checkbox' 
+                           value = 1
+                           label = text('Reporting Units') #'
+                      } ?>
+                    </td> 
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'col_name'
+                            type = 'checkbox' 
+                           value = 1
+                           label = name_label
+                         checked = 'checked'
+                      } ?>
+                    </td> 
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'col_amount'
+                            type = 'checkbox' 
+                           value = 1
+                         checked = 'checked'
+                           label = text('Amount')
+                      } ?>
+                    </td> 
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'col_tax'
+                            type = 'checkbox' 
+                           value = 1
+                           label = text('Tax')
+                      } ?>
+                    </td> 
+                  </tr>
+                  <tr>
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'col_total'
+                            type = 'checkbox' 
+                           value = 1
+                         checked = 'checked'
+                           label = text('Total')
+                      } ?>
+                    </td> 
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'col_currency'
+                            type = 'checkbox' 
+                           value = 1
+                           label = text('Currency') 
+                      } ?>
+                    </td> 
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'col_date_paid'
+                            type = 'checkbox' 
+                           value = 1
+                           label = text('Date Paid') #'
+                      } ?>
+                    </td> 
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'col_paid'
+                            type = 'checkbox' 
+                           value = 1
+                           label = text('Paid')
+                         checked = 'checked'
+                      } ?>
+                    </td> 
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'col_duedate'
+                            type = 'checkbox' 
+                           value = 1
+                           label = text('Due Date') #'
+                      } ?>
+                    </td> 
+                  </tr>
+                  <tr>
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'col_due'
+                            type = 'checkbox' 
+                           value = 1
+                         checked = 'checked'
+                           label = text('Amount Due') #'
+                      } ?>
+                    </td> 
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'col_notes'
+                            type = 'checkbox' 
+                           value = 1
+                           label = text('Notes') 
+                      } ?>
+                    </td> 
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'col_shipping_point'
+                            type = 'checkbox' 
+                           value = 1
+                           label = text('Shipping Point') #'
+                      } ?>
+                    </td> 
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'col_ship_via'
+                            type = 'checkbox' 
+                           value = 1
+                           label = text('Ship Via') #'
+                      } ?>
+                    </td> 
+                  </tr>
+                  <tr>
+                    <td>
+                      <?lsmb PROCESS input element_data = {
+                            name = 'inc_subtotals'
+                            type = 'checkbox' 
+                           value = 1
+                           label = text('Subtotals')
+                      } ?>
+                    </td> 
+                  </tr>
+               </table>
+            </td>
+          </tr>
+</table>
+</td>
+</tr>
+</table>
+<hr />
+<?lsmb PROCESS button element_data = {
+   text = text('Continue')
+   name = 'action'
+   type = 'submit'
+  class = 'submit'
+  value = 'search_purchases'
+} ?>
+</body> 
+</html>

Modified: trunk/UI/lib/report_base.html
===================================================================
--- trunk/UI/lib/report_base.html	2012-06-05 07:33:11 UTC (rev 4839)
+++ trunk/UI/lib/report_base.html	2012-06-05 12:47:58 UTC (rev 4840)
@@ -3,7 +3,7 @@
         <tr>
           <th align="right"><?lsmb text(BUC.label) ?></th>
           <?lsmb b_units.${BUC.id}.unshift({}) ?>
-          <td><?lsmb PROCESS select element_data = {
+          <td colspan=3><?lsmb PROCESS select element_data = {
                    name = 'business_unit_' _ loop.count
                 options = b_units.${BUC.id}
               text_attr = 'text'

Modified: trunk/bin/aa.pl
===================================================================
--- trunk/bin/aa.pl	2012-06-05 07:33:11 UTC (rev 4839)
+++ trunk/bin/aa.pl	2012-06-05 12:47:58 UTC (rev 4840)
@@ -1804,720 +1804,3 @@
 
 }
 
-sub transactions {
-    # it shouldn't be putting it into vendor_id or customer_id, but into 
-    # entity_id, conforming to the new entity tables.
-    my $total_due = 0;
-    if ( $form->{ $form->{vc} } ) {
-        $form->{ $form->{vc} } = $form->unescape( $form->{ $form->{vc} } );
-        ( $form->{ $form->{vc} }, $form->{"$form->{vc}_id"} ) =
-          split( /--/, $form->{ $form->{vc} } );
-    }
-    if ($form->{vc} eq 'customer'){
-        $form->{entity_class} = 2;
-    } elsif ($form->{vc} eq 'vendor'){
-        $form->{entity_class} = 1;
-    } else {
-        $form->{entity_class} = "0";
-    }
-    @column_index;
-    AA->transactions( \%myconfig, \%$form );
-
-    $href = "$form->{script}?action=transactions";
-    for (qw(direction oldsort till outstanding path login sessionid summary)) {
-        $href .= qq|&$_=$form->{$_}|;
-    }
-    $href .= "&title=" . $form->escape( $form->{title} );
-
-    $form->sort_order();
-
-    $callback = "$form->{script}?action=transactions";
-    for (qw(direction oldsort till outstanding path login sessionid summary)) {
-        $callback .= qq|&$_=$form->{$_}|;
-    }
-    $callback .= "&title=" . $form->escape( $form->{title}, 1 );
-
-    if ( $form->{ $form->{ARAP} } ) {
-        $callback .=
-          "&$form->{ARAP}=" . $form->escape( $form->{ $form->{ARAP} }, 1 );
-        $href .= "&$form->{ARAP}=" . $form->escape( $form->{ $form->{ARAP} } );
-        $form->{ $form->{ARAP} } =~ s/--/ /;
-        $option = $locale->text('Account') . " : $form->{$form->{ARAP}}";
-    }
-
-    if ( $form->{ $form->{vc} } ) {
-        $callback .=
-            "&$form->{vc}="
-          . $form->escape( $form->{ $form->{vc} }, 1 )
-          . qq|--$form->{"$form->{vc}_id"}|;
-        $href .=
-            "&$form->{vc}="
-          . $form->escape( $form->{ $form->{vc} } )
-          . qq|--$form->{"$form->{vc}_id"}|;
-        $option .= "\n<br>" if ($option);
-        $name =
-          ( $form->{vc} eq 'customer' )
-          ? $locale->text('Customer')
-          : $locale->text('Vendor');
-        $option .= "$name : $form->{$form->{vc}}";
-    }
-    if ( $form->{department} ) {
-        $callback .= "&department=" . $form->escape( $form->{department}, 1 );
-        $href .= "&department=" . $form->escape( $form->{department} );
-        ($department) = split /--/, $form->{department};
-        $option .= "\n<br>" if ($option);
-        $option .= $locale->text('Department') . " : $department";
-    }
-    if ( $form->{employee} ) {
-        $callback .= "&employee=" . $form->escape( $form->{employee}, 1 );
-        $href .= "&employee=" . $form->escape( $form->{employee} );
-        ($employee) = split /--/, $form->{employee};
-        $option .= "\n<br>" if ($option);
-        if ( $form->{ARAP} eq 'AR' ) {
-            $option .= $locale->text('Salesperson');
-        }
-        else {
-            $option .= $locale->text('Employee');
-        }
-        $option .= " : $employee";
-    }
-
-    if ( $form->{invnumber} ) {
-        $callback .= "&invnumber=" . $form->escape( $form->{invnumber}, 1 );
-        $href   .= "&invnumber=" . $form->escape( $form->{invnumber} );
-        $option .= "\n<br>" if ($option);
-        $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
-    }
-    if ( $form->{ordnumber} ) {
-        $callback .= "&ordnumber=" . $form->escape( $form->{ordnumber}, 1 );
-        $href   .= "&ordnumber=" . $form->escape( $form->{ordnumber} );
-        $option .= "\n<br>" if ($option);
-        $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
-    }
-    if ( $form->{ponumber} ) {
-        $callback .= "&ponumber=" . $form->escape( $form->{ponumber}, 1 );
-        $href   .= "&ponumber=" . $form->escape( $form->{ponumber} );
-        $option .= "\n<br>" if ($option);
-        $option .= $locale->text('PO Number') . " : $form->{ponumber}";
-    }
-    if ( $form->{source} ) {
-        $callback .= "&source=" . $form->escape( $form->{source}, 1 );
-        $href   .= "&source=" . $form->escape( $form->{source} );
-        $option .= "\n<br>" if $option;
-        $option .= $locale->text('Source') . " : $form->{source}";
-    }
-    if ( $form->{description} ) {
-        $callback .= "&description=" . $form->escape( $form->{description}, 1 );
-        $href   .= "&description=" . $form->escape( $form->{description} );
-        $option .= "\n<br>" if $option;
-        $option .= $locale->text('Description') . " : $form->{description}";
-    }
-    if ( $form->{notes} ) {
-        $callback .= "&notes=" . $form->escape( $form->{notes}, 1 );
-        $href   .= "&notes=" . $form->escape( $form->{notes} );
-        $option .= "\n<br>" if $option;
-        $option .= $locale->text('Notes') . " : $form->{notes}";
-    }
-    if ( $form->{shipvia} ) {
-        $callback .= "&shipvia=" . $form->escape( $form->{shipvia}, 1 );
-        $href   .= "&shipvia=" . $form->escape( $form->{shipvia} );
-        $option .= "\n<br>" if $option;
-        $option .= $locale->text('Ship via') . " : $form->{shipvia}";
-    }
-    if ( $form->{transdatefrom} ) {
-        $callback .= "&transdatefrom=$form->{transdatefrom}";
-        $href     .= "&transdatefrom=$form->{transdatefrom}";
-        $option   .= "\n<br>" if ($option);
-        $option .=
-            $locale->text('From') . "&nbsp;"
-          . $locale->date( \%myconfig, $form->{transdatefrom}, 1 );
-    }
-    if ( $form->{transdateto} ) {
-        $callback .= "&transdateto=$form->{transdateto}";
-        $href     .= "&transdateto=$form->{transdateto}";
-        $option   .= "\n<br>" if ($option);
-        $option .=
-          $locale->text( 'To [_1]',
-            $locale->date( \%myconfig, $form->{transdateto}, 1 ) );
-    }
-    if ( $form->{open} ) {
-        $callback .= "&open=$form->{open}";
-        $href     .= "&open=$form->{open}";
-        $option   .= "\n<br>" if ($option);
-        $option   .= $locale->text('Open');
-    }
-    if ( $form->{closed} ) {
-        $callback .= "&closed=$form->{closed}";
-        $href     .= "&closed=$form->{closed}";
-        $option   .= "\n<br>" if ($option);
-        $option   .= $locale->text('Closed');
-    }
-
-    @columns =
-      $form->sort_columns(
-        qw(transdate id invnumber ordnumber ponumber name netamount tax amount paid due curr datepaid duedate notes till employee manager shippingpoint shipvia department)
-      );
-    pop @columns if $form->{department};
-    unshift @columns, "runningnumber";
-
-    foreach $item (@columns) {
-        if ( $form->{"l_$item"} eq "Y" ) {
-            push @column_index, $item;
-
-            if ( $form->{l_curr} && $item =~ /(amount|tax|paid|due)/ ) {
-                push @column_index, "fx_$item";
-            }
-
-            # add column to href and callback
-            $callback .= "&l_$item=Y";
-            $href     .= "&l_$item=Y";
-        }
-    }
-    if ( !$form->{summary} and !$form->{outstanding}) {
-        foreach $item (qw(source debit credit accno description projectnumber))
-        {
-            push @column_index, $item;
-        }
-    } elsif ($form->{l_projectnumber} eq 'Y'){
-        push @column_index, 'projectnumber';
-    }
-
-    if ( $form->{l_subtotal} eq 'Y' ) {
-        $callback .= "&l_subtotal=Y";
-        $href     .= "&l_subtotal=Y";
-    }
-
-    $employee =
-      ( $form->{ARAP} eq 'AR' )
-      ? $locale->text('Salesperson')
-      : $locale->text('Employee');
-    $name =
-      ( $form->{vc} eq 'customer' )
-      ? $locale->text('Customer')
-      : $locale->text('Vendor');
-
-    $column_header{runningnumber} = qq|<th class=listheading>&nbsp;</th>|;
-    $column_header{id} =
-        "<th><a class=listheading href=$href&sort=id>"
-      . $locale->text('ID')
-      . "</a></th>";
-    $column_header{transdate} =
-        "<th><a class=listheading href=$href&sort=transdate>"
-      . $locale->text('Date')
-      . "</a></th>";
-    $column_header{duedate} =
-        "<th><a class=listheading href=$href&sort=duedate>"
-      . $locale->text('Due Date')
-      . "</a></th>";
-    $column_header{invnumber} =
-        "<th><a class=listheading href=$href&sort=invnumber>"
-      . $locale->text('Invoice')
-      . "</a></th>";
-    if ($form->{summary}){
-        $column_header{invnumber} =
-            "<th><a class=listheading href=$href&sort=invnumber>"
-            . $locale->text('Invoices')
-            . "</a></th>";
-
-    }
-    $column_header{ordnumber} =
-        "<th><a class=listheading href=$href&sort=ordnumber>"
-      . $locale->text('Order')
-      . "</a></th>";
-    $column_header{ponumber} =
-        "<th><a class=listheading href=$href&sort=ponumber>"
-      . $locale->text('PO Number')
-      . "</a></th>";
-    $column_header{name} =
-      "<th>".$locale->text('Account')."</th><th><a class=listheading href=$href&sort=name>$name</a></th>";
-    $column_header{netamount} =
-      "<th class=listheading>" . $locale->text('Amount') . "</th>";
-    $column_header{tax} =
-      "<th class=listheading>" . $locale->text('Tax') . "</th>";
-    $column_header{amount} =
-      "<th class=listheading>" . $locale->text('Total') . "</th>";
-    $column_header{paid} =
-      "<th class=listheading>" . $locale->text('Paid') . "</th>";
-    $column_header{datepaid} =
-        "<th><a class=listheading href=$href&sort=datepaid>"
-      . $locale->text('Date Paid')
-      . "</a></th>";
-    $column_header{due} =
-      "<th class=listheading>" . $locale->text('Amount Due') . "</th>";
-    $column_header{notes} =
-      "<th class=listheading>" . $locale->text('Notes') . "</th>";
-    $column_header{employee} =
-      "<th><a class=listheading href=$href&sort=employee>$employee</th>";
-    $column_header{manager} =
-      "<th><a class=listheading href=$href&sort=manager>"
-      . $locale->text('Manager') . "</th>";
-    $column_header{till} =
-      "<th class=listheading><a class=listheading href=$href&sort=till>"
-      . $locale->text('Till') . "</th>";
-
-    $column_header{shippingpoint} =
-        "<th><a class=listheading href=$href&sort=shippingpoint>"
-      . $locale->text('Shipping Point')
-      . "</a></th>";
-    $column_header{shipvia} =
-        "<th><a class=listheading href=$href&sort=shipvia>"
-      . $locale->text('Ship via')
-      . "</a></th>";
-
-    $column_header{curr} =
-        "<th><a class=listheading href=$href&sort=curr>"
-      . $locale->text('Curr')
-      . "</a></th>";
-    for (qw(amount tax netamount paid due)) {
-        $column_header{"fx_$_"} = "<th>&nbsp;</th>";
-    }
-
-    $column_header{department} =
-        "<th><a class=listheading href=$href&sort=department>"
-      . $locale->text('Department')
-      . "</a></th>";
-
-    $column_header{accno} =
-        "<th><a class=listheading href=$href&sort=accno>"
-      . $locale->text('Account')
-      . "</a></th>";
-    $column_header{source} =
-        "<th><a class=listheading href=$href&sort=source>"
-      . $locale->text('Source')
-      . "</a></th>";
-    $column_header{debit} =
-      "<th class=listheading>" . $locale->text('Debit') . "</th>";
-    $column_header{credit} =
-      "<th class=listheading>" . $locale->text('Credit') . "</th>";
-    $column_header{projectnumber} =
-        "<th><a class=listheading href=$href&sort=projectnumber>"
-      . $locale->text('Project')
-      . "</a></th>";
-    $column_header{description} =
-        "<th><a class=listheading href=$href&sort=linedescription>"
-      . $locale->text('Description')
-      . "</a></th>";
-
-    $form->{title} =
-      ( $form->{title} ) ? $form->{title} : $locale->text('AR Transactions');
-
-    $form->header;
-
-    print qq|
-<body>
-
-<table width=100%>
-  <tr>
-    <th class=listtop>$form->{title}</th>
-  </tr>
-  <tr height="5"></tr>
-  <tr>
-    <td>$option</td>
-  </tr>
-  <tr>
-    <td>
-      <table width=100%>
-	<tr class=listheading>
-|;
-
-    for (@column_index) { print "\n$column_header{$_}" }
-
-    print qq|
-	</tr>
-|;
-
-    # add sort and escape callback, this one we use for the add sub
-    $form->{callback} = $callback .= "&sort=$form->{sort}";
-
-    # escape callback for href
-    $callback = $form->escape($callback);
-
-    # flip direction
-    $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC";
-    $href =~ s/&direction=(\w+)&/&direction=$direction&/;
-
-    if ( @{ $form->{transactions} } ) {
-        $sameitem = $form->{transactions}->[0]->{ $form->{sort} };
-    }
-
-    # sums and tax on reports by Antonio Gallardo
-    #
-    $i = 0;
-
-    foreach $ref ( @{ $form->{transactions} } ) {
-
-        $i++;
-        #print STDERR localtime()." aa.pl sub transactions row=".Data::Dumper::Dumper($ref)."\n";
-        #print STDERR localtime()." aa.pl sub transactions invnumber=$ref->{invnumber} projectnumber=$ref->{projectnumber}\n";
-        if ($form->{l_projectnumber} eq 'Y' and ref($ref->{ac_projects}) eq 'ARRAY' and ref($ref->{inv_projects}) eq 'ARRAY'){
-            #HV $ref->{projectnumber} in this case is not filled by AA-->transactions
-            my @projects;
-            my %projects_hash;
-            foreach $acprjct(@{$ref->{ac_projects}})
-            {
-             if($acprjct)
-             {
-              if(! exists $projects_hash{$acprjct})
-              {
-               #print STDERR localtime()." aa.pl sub transactions acprjct=$acprjct\n";
-               $projects_hash{$acprjct}=1;
-               push @projects, $acprjct;
-              }
-             }
-            }
-            foreach $invprjct(@{$ref->{inv_projects}})
-            {
-             if($invprjct)
-             {
-              if(! exists $projects_hash{$invprjct})
-              {
-               #print STDERR localtime()." aa.pl sub transactions invprjct=$invprjct\n";
-               $projects_hash{$invprjct}=1;
-               push @projects, $invprjct;
-              }
-             }
-            }
-            #push @projects, @{$ref->{ac_projects}};
-            #push @projects, @{$ref->{inv_projects}};
-            $ref->{projectnumber} = join '<br />', @projects;
-            $ref->{projectnumber} =~ s/(<br \/>)+/<br \/>/;
-        }
-        if ( $form->{l_subtotal} eq 'Y' ) {
-            if ( $sameitem ne $ref->{ $form->{sort} } ) {
-                &subtotal;
-                $sameitem = $ref->{ $form->{sort} };
-            }
-        }
-
-        if ( $form->{l_curr} ) {
-            for (qw(netamount amount paid)) {
-                $ref->{"fx_$_"} = $ref->{$_} / $ref->{exchangerate};
-            }
-
-            for (qw(netamount amount paid)) {
-                $column_data{"fx_$_"} = "<td align=right>"
-                  . $form->format_amount( \%myconfig, $ref->{"fx_$_"}, 2,
-                    "&nbsp;" )
-                  . "</td>";
-            }
-
-            $column_data{fx_tax} = "<td align=right>"
-              . $form->format_amount( \%myconfig,
-                $ref->{fx_amount} - $ref->{fx_netamount},
-                2, "&nbsp;" )
-              . "</td>";
-            $column_data{fx_due} = "<td align=right>"
-              . $form->format_amount( \%myconfig,
-                $ref->{fx_amount} - $ref->{fx_paid},
-                2, "&nbsp;" )
-              . "</td>";
-
-            $subtotalfxnetamount += $ref->{fx_netamount};
-            $subtotalfxamount    += $ref->{fx_amount};
-            $subtotalfxpaid      += $ref->{fx_paid};
-
-            $totalfxnetamount += $ref->{fx_netamount};
-            $totalfxamount    += $ref->{fx_amount};
-            $totalfxpaid      += $ref->{fx_paid};
-
-        }
-
-        $column_data{runningnumber} = "<td align=right>$i</td>";
-
-        for (qw(netamount amount paid debit credit)) {
-            $column_data{$_} =
-                "<td align=right>"
-              . $form->format_amount( \%myconfig, $ref->{$_}, 2, "&nbsp;" )
-              . "</td>";
-        }
-
-        $column_data{tax} = "<td align=right>"
-          . $form->format_amount( \%myconfig,
-            $ref->{amount} - $ref->{netamount},
-            2, "&nbsp;" )
-          . "</td>";
-        $total_due += $ref->{amount} - $ref->{paid};
-        $column_data{due} = "<td align=right>"
-          . $form->format_amount( \%myconfig, $ref->{amount} - $ref->{paid},
-            2, "&nbsp;" )
-          . "</td>";
-
-        $subtotalnetamount += $ref->{netamount};
-        $subtotalamount    += $ref->{amount};
-        $subtotalpaid      += $ref->{paid};
-        $subtotaldebit     += $ref->{debit};
-        $subtotalcredit    += $ref->{credit};
-
-        $totalnetamount += $ref->{netamount};
-        $totalamount    += $ref->{amount};
-        $totalpaid      += $ref->{paid};
-        $totaldebit     += $ref->{debit};
-        $totalcredit    += $ref->{credit};
-
-        $module =
-            ( $ref->{invoice} )
-          ? ( $form->{ARAP} eq 'AR' ) ? "is.pl" : "ir.pl"
-          :   $form->{script};
-        $module = ( $ref->{till} ) ? "ps.pl" : $module;
-        if ($form->{outstanding} and $form->{summary}){
-            $column_data{invnumber} = "<td>$ref->{invnumber}</td>";
-	} else {
-            $column_data{invnumber} =
-"<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber}&nbsp;</a></td>";
-        }
-        for (qw(notes description)) { $ref->{$_} =~ s/\r?\n/<br>/g }
-        for (
-            qw(transdate datepaid duedate department ordnumber ponumber notes shippingpoint shipvia employee manager till source description projectnumber)
-          )
-        {
-            $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>";
-        }
-        for (qw(id curr)) { $column_data{$_} = "<td>$ref->{$_}</td>" }
-
-        $column_data{accno} =
-qq|<td><a href=ca.pl?path=$form->{path}&action=list_transactions&accounttype=standard&accno=$ref->{accno}&fromdate=$form->{transdatefrom}&todate=$form->{transdateto}&sort=transdate&l_subtotal=$form->{l_subtotal}&prevreport=$callback>$ref->{accno}</a></td>|;
-
-        $column_data{name} =
-qq|<td>$ref->{meta_number}</td><td><a href=$form->{vc}.pl?path=$form->{path}&action=edit&entity_id=$ref->{entity_id}&meta_number=$ref->{meta_number}&db=$form->{vc}&callback=$callback>$ref->{name}</a></td>|;
-
-        if ( $ref->{id} != $sameid or $form->{summary}) {
-            $j++;
-            $j %= 2;
-        }
-
-        print "
-        <tr class=listrow$j>
-";
-
-        for (@column_index) { print "\n$column_data{$_}" }
-
-        print qq|
-        </tr>
-|;
-
-        $sameid = $ref->{id};
-
-    }
-
-    if ( $form->{l_subtotal} eq 'Y' ) {
-        &subtotal;
-        $sameitem = $ref->{ $form->{sort} };
-    }
-
-    # print totals
-    print qq|
-        <tr class=listtotal>
-        <td>&nbsp</td>|;
-    my $total_data;
-    for (@column_index){ $total_data->{$_} = "&nbsp;"; }
-    $total_data->{due} = $form->format_amount(\%myconfig, $total_due, $LedgerSMB::Sysconfig::decimal_places);
-    $total_data->{netamount} = $form->format_amount(\%myconfig, $totalnetamount, $LedgerSMB::Sysconfig::decimal_places);
-    $total_data->{amount} = $form->format_amount(\%myconfig, $totalamount, $LedgerSMB::Sysconfig::decimal_places);
-    $total_data->{paid} = $form->format_amount(\%myconfig, $totalpaid, $LedgerSMB::Sysconfig::decimal_places);
-    $total_data->{debit} = $form->format_amount(\%myconfig, $totaldebit, $LedgerSMB::Sysconfig::decimal_places);
-    $total_data->{credit} = $form->format_amount(\%myconfig, $totalcredit, $LedgerSMB::Sysconfig::decimal_places);
-    for (@column_index){
-        print "<td>$total_data->{$_}</td>";
-    }
-    print qq|
-        </tr>
-|;
-
-    for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
-    # See setting of $column_header{name} - it has two columns
-    $column_data{name} = "<td>&nbsp;</td><td>&nbsp;</td>";
-
-    $column_data{netamount} =
-        "<th class=listtotal align=right>"
-      . $form->format_amount( \%myconfig, $totalnetamount, 2, "&nbsp;" )
-      . "</th>";
-    $column_data{tax} = "<th class=listtotal align=right>"
-      . $form->format_amount( \%myconfig, $totalamount - $totalnetamount,
-        2, "&nbsp;" )
-      . "</th>";
-    $column_data{amount} =
-      "<th class=listtotal align=right>"
-      . $form->format_amount( \%myconfig, $totalamount, 2, "&nbsp;" ) . "</th>";
-    $column_data{paid} =
-      "<th class=listtotal align=right>"
-      . $form->format_amount( \%myconfig, $totalpaid, 2, "&nbsp;" ) . "</th>";
-    $column_data{due} =
-      "<th class=listtotal align=right>"
-      . $form->format_amount( \%myconfig, $totalamount - $totalpaid, 2,
-        "&nbsp;" )
-      . "</th>";
-    $column_data{debit} =
-      "<th class=listtotal align=right>"
-      . $form->format_amount( \%myconfig, $totaldebit, 2, "&nbsp;" ) . "</th>";
-    $column_data{credit} =
-      "<th class=listtotal align=right>"
-      . $form->format_amount( \%myconfig, $totalcredit, 2, "&nbsp;" ) . "</th>";
-
-    if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
-        $column_data{fx_netamount} =
-            "<th class=listtotal align=right>"
-          . $form->format_amount( \%myconfig, $totalfxnetamount, 2, "&nbsp;" )
-          . "</th>";
-        $column_data{fx_tax} = "<th class=listtotal align=right>"
-          . $form->format_amount( \%myconfig,
-            $totalfxamount - $totalfxnetamount,
-            2, "&nbsp;" )
-          . "</th>";
-        $column_data{fx_amount} =
-            "<th class=listtotal align=right>"
-          . $form->format_amount( \%myconfig, $totalfxamount, 2, "&nbsp;" )
-          . "</th>";
-        $column_data{fx_paid} =
-            "<th class=listtotal align=right>"
-          . $form->format_amount( \%myconfig, $totalfxpaid, 2, "&nbsp;" )
-          . "</th>";
-        $column_data{fx_due} = "<th class=listtotal align=right>"
-          . $form->format_amount( \%myconfig, $totalfxamount - $totalfxpaid,
-            2, "&nbsp;" )
-          . "</th>";
-    }
-
-    #for (@column_index) { print STDERR qq|______ $_ => $column_data{$_} ______________|; print "\n$column_data{$_}" }
-
-    if ( $myconfig{acs} !~ /$form->{ARAP}--$form->{ARAP}/ ) {
-        $i = 1;
-        if ( $form->{ARAP} eq 'AR' ) {
-            $button{'AR--Add Transaction'}{code} =
-qq|<button class="submit" type="submit" name="action" value="ar_transaction">|
-              . $locale->text('AR Transaction')
-              . qq|</button> |;
-            $button{'AR--Add Transaction'}{order} = $i++;
-            $button{'AR--Sales Invoice'}{code} =
-qq|<button class="submit" type="submit" name="action" value="sales_invoice_">|
-              . $locale->text('Sales Invoice.')
-              . qq|</button> |;
-            $button{'AR--Sales Invoice'}{order} = $i++;
-        }
-        else {
-            $button{'AP--Add Transaction'}{code} =
-qq|<button class="submit" type="submit" name="action" value="ap_transaction">|
-              . $locale->text('AP Transaction')
-              . qq|</button> |;
-            $button{'AP--Add Transaction'}{order} = $i++;
-            $button{'AP--Vendor Invoice'}{code} =
-qq|<button class="submit" type="submit" name="action" value="vendor_invoice_">|
-              . $locale->text('Vendor Invoice')
-              . qq|</button> |;
-            $button{'AP--Vendor Invoice'}{order} = $i++;
-        }
-
-        foreach $item ( split /;/, $myconfig{acs} ) {
-            delete $button{$item};
-        }
-    }
-
-    print qq|
-	</tr>
-      </table>
-    </td>
-  </tr>
-  <tr>
-    <td><hr size=3 noshade></td>
-  </tr>
-</table>
-
-<br>
-<form method=post action=$form->{script}>
-|;
-
-    $form->hide_form(
-        "callback",    "path", "login", "sessionid",
-        "$form->{vc}", "$form->{vc}_id"
-    );
-
-    if ( !$form->{till} ) {
-        foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
-          
-            print $item->{code};
-        }
-    }
-
-    if ( $form->{lynx} ) {
-        require "bin/menu.pl";
-        &menubar;
-    }
-
-    print qq|
-</form>
-
-</body>
-</html>
-|;
-
-}
-
-sub subtotal {
-
-    for (@column_index) { $column_data{$_} = "<td test=$_>&nbsp;</td>" }
-
-    $column_data{tax} = "<th class=listsubtotal align=right>"
-      . $form->format_amount( \%myconfig, $subtotalamount - $subtotalnetamount,
-        2, "&nbsp;" )
-      . "</th>";
-    $column_data{amount} =
-        "<th class=listsubtotal align=right>"
-      . $form->format_amount( \%myconfig, $subtotalamount, 2, "&nbsp;" )
-      . "</th>";
-    $column_data{paid} =
-        "<th class=listsubtotal align=right>"
-      . $form->format_amount( \%myconfig, $subtotalpaid, 2, "&nbsp;" )
-      . "</th>";
-    $column_data{due} = "<th class=listsubtotal align=right>"
-      . $form->format_amount( \%myconfig, $subtotalamount - $subtotalpaid,
-        2, "&nbsp;" )
-      . "</th>";
-    $column_data{debit} =
-        "<th class=listsubtotal align=right>"
-      . $form->format_amount( \%myconfig, $subtotaldebit, 2, "&nbsp;" )
-      . "</th>";
-    $column_data{credit} =
-        "<th class=listsubtotal align=right>"
-      . $form->format_amount( \%myconfig, $subtotalcredit, 2, "&nbsp;" )
-      . "</th>";
-
-    if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
-        $column_data{fx_tax} = "<th class=listsubtotal align=right>"
-          . $form->format_amount( \%myconfig,
-            $subtotalfxamount - $subtotalfxnetamount,
-            2, "&nbsp;" )
-          . "</th>";
-        $column_data{fx_amount} =
-            "<th class=listsubtotal align=right>"
-          . $form->format_amount( \%myconfig, $subtotalfxamount, 2, "&nbsp;" )
-          . "</th>";
-        $column_data{fx_paid} =
-            "<th class=listsubtotal align=right>"
-          . $form->format_amount( \%myconfig, $subtotalfxpaid, 2, "&nbsp;" )
-          . "</th>";
-        $column_data{fx_due} = "<th class=listsubtotal align=right>"
-          . $form->format_amount( \%myconfig,
-            $subtotalfxmount - $subtotalfxpaid,
-            2, "&nbsp;" )
-          . "</th>";
-    }
-
-    $subtotalnetamount = 0;
-    $subtotalamount    = 0;
-    $subtotalpaid      = 0;
-    $subtotaldebit     = 0;
-    $subtotalcredit    = 0;
-
-    $subtotalfxnetamount = 0;
-    $subtotalfxamount    = 0;
-    $subtotalfxpaid      = 0;
-
-    print "<tr class=listsubtotal>";
-
-    for (@column_index) { print "\n$column_data{$_}" }
-
-    print "
-</tr>
-";
-
-}
-

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2012-06-05 07:33:11 UTC (rev 4839)
+++ trunk/sql/Pg-database.sql	2012-06-05 12:47:58 UTC (rev 4840)
@@ -2548,7 +2548,7 @@
 9	Taxable Sales	4	4
 10	Non-Taxable	4	5
 39	Invoice Vouchers	250	2
-16	Budgets	109	6
+16	Budgets	0	18
 17	Add  Budget	16	1
 18	Search	16	2
 22	Add Transaction	21	1

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