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

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



Revision: 5791
          http://sourceforge.net/p/ledger-smb/code/5791
Author:   einhverfr
Date:     2013-05-15 08:34:43 +0000 (Wed, 15 May 2013)
Log Message:
-----------
Moved business type listing to new framework.  Fixes bug 814

Modified Paths:
--------------
    trunk/LedgerSMB/AM.pm
    trunk/LedgerSMB/Scripts/reports.pm
    trunk/bin/am.pl
    trunk/sql/Pg-database.sql
    trunk/sql/modules/menu_rebuild.sql

Added Paths:
-----------
    trunk/LedgerSMB/Report/Listings/
    trunk/LedgerSMB/Report/Listings/Business_Type.pm

Modified: trunk/LedgerSMB/AM.pm
===================================================================
--- trunk/LedgerSMB/AM.pm	2013-05-14 15:22:40 UTC (rev 5790)
+++ trunk/LedgerSMB/AM.pm	2013-05-15 08:34:43 UTC (rev 5791)
@@ -369,43 +369,6 @@
 
 }
 
-=item AM->business($myconfig, $form);
-
-Populates the list referred to as $form->{ALL} with hashes containing details
-about all known types of business.  Each hash contains the id, description, and
-discount for businesses of this type.  The discount is represented in numeric
-form, such that a 10% discount is stored and retrieved as 0.1.  The hashes are
-sorted by the business description.
-
-$myconfig is unused.
-
-=cut
-
-sub business {
-
-    my ( $self, $myconfig, $form ) = @_;
-
-    # connect to database
-    my $dbh = $form->{dbh};
-
-    $form->sort_order();
-    my $query = qq|
-		  SELECT id, description, discount
-		    FROM business
-		ORDER BY description $form->{direction}|;
-
-    $sth = $dbh->prepare($query);
-    $sth->execute || $form->dberror($query);
-
-    while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
-        push @{ $form->{ALL} }, $ref;
-    }
-
-    $sth->finish;
-    $dbh->commit;
-
-}
-
 =item AM->get_business($myconfig, $form);
 
 Places the description and discount for the business with an id of $form->{id}

Added: trunk/LedgerSMB/Report/Listings/Business_Type.pm
===================================================================
--- trunk/LedgerSMB/Report/Listings/Business_Type.pm	                        (rev 0)
+++ trunk/LedgerSMB/Report/Listings/Business_Type.pm	2013-05-15 08:34:43 UTC (rev 5791)
@@ -0,0 +1,103 @@
+=head1 NAME
+
+LedgerSMB::Report::Listings::Business_Type - List the Business Types in 
+LedgerSMB
+
+=head1 SYNPOPSIS
+
+  my $report = LedgerSMB::Report::Listings::Business_Type->new(%$request);
+  $report->render($request);
+
+=head1 DESCRIPTION
+
+This provides a simple list of business types, ordered alphabetically.
+
+=head1 CRITERIA PROPERTIES
+
+None
+
+=cut
+
+package LedgerSMB::Report::Listings::Business_Type;
+use Moose;
+extends 'LedgerSMB::Report';
+
+=head1 STATIC METHODS
+
+=over
+
+=item columns
+
+=over
+
+=item description
+
+=item discount
+
+=back
+
+=cut
+
+sub columns {
+    return [{
+      col_id => 'description',
+        type => 'href',
+     p_width => '10',
+        name => LedgerSMB::Report::text('Description'),
+   href_base => 'am.pl?action=edit_business&id=',
+    },
+    {
+      col_id => 'discount',
+        type => 'text',
+     p_width => '1',
+        name => LedgerSMB::Report::text('Discount (%)'),
+    }];
+};
+
+=item header_lines
+
+None added
+
+=cut
+
+sub header_lines {
+    return []
+};
+
+=item name
+
+=cut
+
+sub name {
+    return LedgerSMB::Report::text('List of Business Types');
+}
+
+=back
+
+=head1 METHODS 
+
+=head2 run_report()
+
+Runs the report and returns the results for rendering.
+
+=cut
+
+sub run_report {
+    my ($self) = @_;
+    my @rows = $self->exec_method({funcname => 'business_type__list'});
+    for my $ref(@rows){
+        $ref->{id} = $ref->{id};
+        $ref->{discount} *= 100;
+    }
+    $self->rows(..hidden..);
+}
+
+=head1 COPYRIGHT
+
+COPYRIGHT (C) 2013 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;

Modified: trunk/LedgerSMB/Scripts/reports.pm
===================================================================
--- trunk/LedgerSMB/Scripts/reports.pm	2013-05-14 15:22:40 UTC (rev 5790)
+++ trunk/LedgerSMB/Scripts/reports.pm	2013-05-15 08:34:43 UTC (rev 5791)
@@ -17,6 +17,7 @@
 use LedgerSMB::Template;
 use LedgerSMB::Business_Unit;
 use LedgerSMB::Business_Unit_Class;
+use LedgerSMB::Report::Listings::Business_Type;
 use strict;
 
 =pod
@@ -95,6 +96,18 @@
     $template->render($request);
 }   
 
+=item list_business_types 
+
+Lists the business types.  No inputs expected or used.
+
+=cut
+
+sub list_business_types {
+    my ($request) = @_;
+    my $report = LedgerSMB::Report::Listings::Business_Type->new(%$request);
+    $report->render($request);
+}
+
 =back
 
 =head1 Copyright (C) 2007 The LedgerSMB Core Team

Modified: trunk/bin/am.pl
===================================================================
--- trunk/bin/am.pl	2013-05-14 15:22:40 UTC (rev 5790)
+++ trunk/bin/am.pl	2013-05-15 08:34:43 UTC (rev 5791)
@@ -457,79 +457,6 @@
     });
 }
 
-sub list_business {
-
-    AM->business( \%myconfig, \%$form );
-
-    my $href =
-"$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
-
-    $form->sort_order();
-
-    $form->{callback} =
-"$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
-
-    my $callback = $form->escape( $form->{callback} );
-
-    $form->{title} = $locale->text('Type of Business');
-
-    my @column_index = qw(description discount);
-
-    my %column_header;
-    $column_header{description} = { text => $locale->text('Description'),
-        href => $href };
-    $column_header{discount} = $locale->text('Discount %');
-
-    my @rows;
-    $i = 0;
-    foreach my $ref ( @{ $form->{ALL} } ) {
-    
-        my %column_data;
-        $i++;
-        $i %= 2;
-        $column_data{i} = $i;
-
-        $column_data{discount} =
-          $form->format_amount( \%myconfig, $ref->{discount} * 100, 2, " " );
-        $column_data{description} = { text => $ref->{description}, href =>
-            qq|$form->{script}?action=edit_business&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback|};
-
-	push @rows, \%column_data;
-    }
-
-    $form->{type} = "business";
-
-    my @hiddens = qw(type callback path login sessionid);
-
-## SC: Temporary removal
-##    if ( $form->{lynx} ) {
-##        require "bin/menu.pl";
-##        &menubar;
-##    }
-
-    my @buttons;
-    push @buttons, {
-        name => 'action',
-        value => 'add_business',
-        text => $locale->text('Add Business'),
-        type => 'submit',
-        class => 'submit',
-    };
-
-    my $template = LedgerSMB::Template->new_UI(
-        user => \%myconfig, 
-        locale => $locale,
-        template => 'am-list-departments');
-    $template->render({
-        form => $form,
-        buttons => ..hidden..,
-        columns => ..hidden..,
-        heading => \%column_header,
-        rows => ..hidden..,
-        hiddens => ..hidden..,
-    });
-}
-
 sub business_header {
     my $hiddens = shift;
 

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2013-05-14 15:22:40 UTC (rev 5790)
+++ trunk/sql/Pg-database.sql	2013-05-15 08:34:43 UTC (rev 5791)
@@ -3153,12 +3153,12 @@
 144	action	list_classes	370
 147	menu	1	372
 148	module	am.pl	373
-149	module	am.pl	374
+149	module	reports.pl	374
 112	action	start_report	278
 112	module	reports.pl	279
 112	report_name	income_statement	280
 148	action	add_business	375
-149	action	list_business	376
+149	action	list_business_types	376
 150	menu	1	377
 151	module	am.pl	378
 152	module	am.pl	379

Modified: trunk/sql/modules/menu_rebuild.sql
===================================================================
--- trunk/sql/modules/menu_rebuild.sql	2013-05-14 15:22:40 UTC (rev 5790)
+++ trunk/sql/modules/menu_rebuild.sql	2013-05-15 08:34:43 UTC (rev 5791)
@@ -464,12 +464,12 @@
 144	action	list_classes	370
 147	menu	1	372
 148	module	am.pl	373
-149	module	am.pl	374
+149	module	reports.pl	374
 112	action	start_report	278
 112	module	reports.pl	279
 112	report_name	income_statement	280
 148	action	add_business	375
-149	action	list_business	376
+149	action	list_business_types	376
 150	menu	1	377
 151	module	am.pl	378
 152	module	am.pl	379

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