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

SF.net SVN: ledger-smb:[4688] addons/1.3



Revision: 4688
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4688&view=rev
Author:   einhverfr
Date:     2012-04-30 06:30:39 +0000 (Mon, 30 Apr 2012)
Log Message:
-----------
Addon backporting reporting framework to 1.3

Added Paths:
-----------
    addons/1.3/report_framework/
    addons/1.3/report_framework/trunk/
    addons/1.3/report_framework/trunk/LedgerSMB/
    addons/1.3/report_framework/trunk/LedgerSMB/App_State.pm
    addons/1.3/report_framework/trunk/LedgerSMB/DBObject/
    addons/1.3/report_framework/trunk/LedgerSMB/DBObject/Report.pm
    addons/1.3/report_framework/trunk/LedgerSMB/DBObject_Moose.pm
    addons/1.3/report_framework/trunk/UI/
    addons/1.3/report_framework/trunk/UI/Reports/
    addons/1.3/report_framework/trunk/UI/Reports/display_report.csv
    addons/1.3/report_framework/trunk/UI/Reports/display_report.html

Added: addons/1.3/report_framework/trunk/LedgerSMB/App_State.pm
===================================================================
--- addons/1.3/report_framework/trunk/LedgerSMB/App_State.pm	                        (rev 0)
+++ addons/1.3/report_framework/trunk/LedgerSMB/App_State.pm	2012-04-30 06:30:39 UTC (rev 4688)
@@ -0,0 +1,113 @@
+=head1 NAME
+
+LedgerSMB::App_State
+
+=cut
+package LedgerSMB::App_State;
+use strict;
+use warnings;
+use LedgerSMB::Sysconfig;
+use LedgerSMB::User;
+use LedgerSMB::Locale;
+
+=head1 SYNPOSIS
+
+This is a generic container class for non-web-application related state
+information.  It provides a central place to track such things as localization,
+user, and other application state objects.
+
+=head1 OBJECTS FOR STORAGE
+
+The following are objects that are expected to be stored in this namespace:
+
+=over
+
+=cut
+
+our $Locale;
+
+=item Locale
+
+Stores a LedgerSMB::Locale object for the specific user.
+
+=cut
+
+our $User;
+
+=item User
+
+Stores a LedgerSMB::User object for the currently logged in user.
+
+=cut
+
+our $SODA;
+
+=item SODA
+
+Stores the SODA database access handle.
+
+=cut
+
+our $Company_Settings;
+
+=item Company_Settings
+
+Hashref for storing connection-specific settings for the application.
+
+=item DBH
+
+Database handle for current connection
+
+=cut
+
+our $DBH;
+
+=back
+
+=head1 METHODS 
+
+=over
+
+=item zero()
+
+zeroes out all majro parts.
+
+=cut
+
+sub zero() {
+    $SODA = undef;
+    $User = undef;
+    $Locale = undef;
+    $DBH = undef;
+}
+
+=item cleanup
+
+Deletes all objects attached here.
+
+=cut
+
+sub cleanup {
+
+    if ($DBH){
+        $DBH->commit;
+        $DBH->disconnect;
+    }
+    $Locale           = LedgerSMB::Locale->get_handle(
+                            $LedgerSMB::Sysconfig::language
+                        );
+    $User             = {};
+    $Company_Settings = {};
+    $DBH = undef;
+}
+
+1;
+
+=back
+
+=head1 COPYRIGHT
+
+Copyright (C) 2009 LedgerSMB Core Team.  This file is licensed under the GNU 
+General Public License version 2, or at your option any later version.  Please
+see the included License.txt for details.
+

Added: addons/1.3/report_framework/trunk/LedgerSMB/DBObject/Report.pm
===================================================================
--- addons/1.3/report_framework/trunk/LedgerSMB/DBObject/Report.pm	                        (rev 0)
+++ addons/1.3/report_framework/trunk/LedgerSMB/DBObject/Report.pm	2012-04-30 06:30:39 UTC (rev 4688)
@@ -0,0 +1,176 @@
+=head1 NAME
+
+LedgerSMB::DBObject::Report - Base Reporting Functionality for LedgerSMB
+
+=head1 SYNPOSIS
+
+This Perl module provides base utility functions for reporting in LedgerSMB.
+This is intended to be an abstract class, never having direct instances, but
+instead inherited out to other modules.
+
+=head1 DESCRIPTION
+
+LedgerSMB::DBObject::Report provides basic utility functions for reporting in
+LedgerSMB.  It is an abstract class.  Individual report types MUST inherit this
+out.
+
+Subclasses MUST define the following subroutines:
+
+=over
+
+=item get_columns
+
+This MUST return a list of hashrefs for the columns per the dynatable block.
+
+=back
+
+Additionally, subclasses MAY define any of the following:
+
+=over
+
+=item template
+
+Returns the name of the template to be used.  Otherwise a generic
+UI/reports/display_report template will be used.
+
+=back
+
+=head1 INHERITS
+
+=over
+
+=item LedgerSMB::DBObject_Moose
+
+=back
+
+=cut
+
+package LedgerSMB::DBObject::Report;
+use Moose;
+extends 'LedgerSMB::DBObject_Moose';
+use LedgerSMB::Template;
+use LedgerSMB::App_State;
+
+=head1 PROPERTIES
+
+=over
+
+=item cols
+
+This is an array of hashrefs.  Properties for each hashref:
+
+=over
+
+=item col_id
+
+ID of column, alphanumeric, used in names of elements, classes, etc.  Required
+for smooth operation.
+
+=item name
+
+Localized name of column for labelling purposes
+
+=item type
+
+Display type of info.  May be text, href, input_text, checkbox, or radio.  For a
+report, it will typically be text or href.
+
+=item href_base
+
+Base for href.  Only meaningful if type is href
+
+=item class
+
+CSS class (additional) for the column.
+
+=back
+
+=cut
+
+has 'cols' => (is => 'rw', isa => 'ArrayRef[HashRef[Any]]');
+
+=item rows
+
+This is an arrayref of rows.  Each row has fields with keys equal to the col_id
+fields of the columns above.
+
+=cut
+
+has 'rows' => (is => 'rw', isa => 'ArrayRef[HashRef[Any]]');
+
+=item format
+
+This is the format, and must be one used by LedgerSMB::Template.  Options
+expected for 1.4 out of the box include csv, pdf, ps, xls, and ods.  Other
+formats could be supported in the future.  If undefined, defaults html.
+
+=cut
+
+has 'format' => (is => 'rw', isa => 'Maybe[Str]');
+
+=back
+
+=head1 METHODS
+
+=over
+
+=item render
+
+This takes no arguments and simply renders the report as is.
+
+=cut
+
+sub render {
+    my ($self, $request) = @_;
+    my $template;
+    if ($template = eval {$self->{template}}){
+       # what needs to be done here?  Maybe log it? 
+    } else {
+        $template = 'Reports/display_report';
+    }
+    if (!defined $self->format){
+        $self->format('html');
+    }
+    $template = LedgerSMB::Template->new(
+        user => $LedgerSMB::App_State::User,
+        locale => $LedgerSMB::App_State::Locale,
+        path => 'UI',
+        template => $template,
+        format => uc($request->{format} || 'HTML'),
+    );
+    $template->render({report => $self, 
+                      request => $request,
+                         name => $self->name,
+                       hlines => $self->header_lines,
+                      columns => $self->show_cols($request), 
+                         rows => $self->rows});
+}
+
+=item show_cols 
+
+Returns a list of columns based on selected ones from the report
+
+=cut
+
+sub show_cols {
+    my ($self, $request) = @_;
+    my @retval;
+    for my $ref (@{$self->columns}){
+        if ($request->{"col_$ref->{col_id}"}){
+            push @retval, $ref;
+        }
+    }
+    return ..hidden..;
+}
+
+=back
+
+=head1 COPYRIGHT
+
+COPYRIGHT (C) 2012 The LedgerSMB Core Team.  This file may be re-used under the
+terms of the LedgerSMB General Public License version 2 or at your option any
+later version.  Please see enclosed LICENSE file for details.
+
+=cut
+
+return 1;

Added: addons/1.3/report_framework/trunk/LedgerSMB/DBObject_Moose.pm
===================================================================
--- addons/1.3/report_framework/trunk/LedgerSMB/DBObject_Moose.pm	                        (rev 0)
+++ addons/1.3/report_framework/trunk/LedgerSMB/DBObject_Moose.pm	2012-04-30 06:30:39 UTC (rev 4688)
@@ -0,0 +1,129 @@
+
+
+=head1 NAME
+
+LedgerSMB::DBObject - LedgerSMB class for building objects from db relations
+
+=head1 SYOPSIS
+
+This module creates object instances based on LedgerSMB's in-database ORM.  
+
+=head1 METHODS
+
+=over
+
+=item new ($class, base => $LedgerSMB::hash)
+
+This is the base constructor for all child classes.  It must be used with base
+argument because this is necessary for database connectivity and the like.
+
+Of course the base object can be any object that inherits LedgerSMB, so you can
+use any subclass of that.  The per-session dbh is passed between the objects 
+this way as is any information that is needed.
+
+=item exec_method 
+
+($self, procname => $function_name, [args => ..hidden.., schema => $schema,
+continue_on_error=>$continue_on_error])
+
+Provides the basic mapping of parameters to the SQL stored procedure function 
+arguments.
+
+If ..hidden.. is not defined, args are mapped from the object's properties, 
+stripping them of their in_ prefix.  If schema is provided, that is used 
+instead of PostgreSQL's search path.  If continue_on_error is provided and true,
+the operation will not raise an exception in the event of a database error, and 
+it will be up to the application to handle any exceptions.
+
+=item _db_array_scalars(@elements) creates a db array from scalars.
+
+=item _db_array_literal(@elements) creates a multiple dimension db array from 
+	preparsed db arrays or other data which does not need to be escaped.
+
+=cut
+
+package LedgerSMB::DBObject_Moose;
+use LedgerSMB::DBObject;
+use Moose;
+use Scalar::Util;
+use Log::Log4perl;
+use LedgerSMB::DBObject;
+
+my $logger = Log::Log4perl->get_logger('LedgerSMB::DBObject');
+
+sub __validate__ {}
+
+has 'dbh' => (is => 'ro', isa => 'DBI::db', required => '1');
+has '_roles' => (is => 'ro', isa => 'ArrayRef[Str]', required => '1');
+has '_user' => (is => 'ro', isa => 'LedgerSMB::User', required => '1');
+has '_locale' => (is => 'ro', isa => 'LedgerSMB::Locale', required => '1');
+has '_request' => (is => 'ro', isa => 'CGI::Simple', required => '1');
+
+sub prepare_dbhash {
+    my $self = shift;
+    my $target = shift;
+    for my $att (qw(dbh _roles _user _locale _request)){
+        if (!$target->{$att}){
+           $target->{$att} = $self->{$att};
+        }
+    }
+}
+
+# _to_dbobject 
+#Private method used to convert to db object for purposes of 
+#
+sub _to_dbobject {
+     my $self   = shift @_;
+    return LedgerSMB::DBObject->new({base => $self});
+}
+
+=item set_ordering
+
+Sets the ordering used by default for specific functions called by exec_method
+
+=cut
+
+sub exec_method {
+    my $self   = shift @_;
+    my $dbo = $self->_to_dbobject;
+    return $dbo->exec_method(@_);
+}
+
+=item run_custom_queries
+
+Backward-compatible with 1.2 custom query system for moving forward.
+
+=cut
+
+sub run_custom_queries {
+    my $self   = shift @_;
+    my $dbo = $self->_to_dbobject;
+    return $dbo->run_custom_queries(@_);
+}
+
+sub call_procedure {
+    my $self   = shift @_; 
+    my $dbo = $self->_to_dbobject;
+    return $dbo->call_procedure(@_);
+}
+
+# Keeping this here due to common requirements
+sub is_allowed_role {
+    my $self   = shift @_;
+    my $dbo = $self->_to_dbobject;
+    return $dbo->is_allowed_role(@_);
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
+=back
+
+=head1 Copyright (C) 2007, The LedgerSMB core team.
+
+This file is licensed under the Gnu General Public License version 2, or at your
+option any later version.  A copy of the license should have been included with
+your software.
+
+=cut

Added: addons/1.3/report_framework/trunk/UI/Reports/display_report.csv
===================================================================
--- addons/1.3/report_framework/trunk/UI/Reports/display_report.csv	                        (rev 0)
+++ addons/1.3/report_framework/trunk/UI/Reports/display_report.csv	2012-04-30 06:30:39 UTC (rev 4688)
@@ -0,0 +1,4 @@
+<?lsmb PROCESS 'dynatable.csv';
+
+PROCESS dynatable tbody = {rows = rows };
+?>

Added: addons/1.3/report_framework/trunk/UI/Reports/display_report.html
===================================================================
--- addons/1.3/report_framework/trunk/UI/Reports/display_report.html	                        (rev 0)
+++ addons/1.3/report_framework/trunk/UI/Reports/display_report.html	2012-04-30 06:30:39 UTC (rev 4688)
@@ -0,0 +1,46 @@
+<?lsmb
+
+PROCESS "ui-header.html"
+   stylesheet = USER.stylesheet;
+
+PROCESS "elements.html";
+
+PROCESS "dynatable.html";
+
+LINK = 'http://' _ ENVARS.SERVER_NAME _ ENVARS.SCRIPT_NAME 
+           _ '?' _ ENVARS.QUERY_STRING _ '&company=' _ form.company;
+
+?>
+<body>
+<div class="report_header"><label><?lsmb text('Report Name') ?>:</label>
+<span class="report_header"><?lsmb name ?></span>
+</div>
+<body>
+<div class="report_header"><label><?lsmb text('Company') ?>:</label>
+<span class="report_header"><?lsmb request.company ?></span>
+</div>
+<?lsmb FOREACH LINE IN hlines ?>
+<div class="report_header"><label><?lsmb LINE.text ?>:</label>
+<span class="report_header"><?lsmb request.${LINE.name} ?></span>
+</div>
+<?lsmb END ?>
+<?lsmb PROCESS dynatable tbody = {rows => rows } 
+               attributes = {class = 'report' } ?>
+
+<a href="<?lsmb LINK ?>">[<?lsmb text('permalink') ?>]</a>&nbsp;
+<?lsmb IF FORMATS.grep('PDF').size()
+?>
+<a href="<?lsmb LINK _ '&format=PDF' ?>">[<?lsmb text('PDF') ?>]</a>&nbsp;
+<?lsmb END;
+IF FORMATS.grep('TXT').size();
+?>
+<a href="<?lsmb LINK _ '&format=CSV' ?>">[<?lsmb text('CSV') ?>]</a>&nbsp;
+<?lsmb END;
+IF FORMATS.grep('XLS').size() ?>
+<a href="<?lsmb LINK _ '&format=XLS' ?>">[<?lsmb text('XLS') ?>]</a>&nbsp;
+<?lsmb END;
+IF FORMATS.grep('ODS').size() ?>
+<a href="<?lsmb LINK _ '&format=ODS' ?>">[<?lsmb text('ODS') ?>]</a>&nbsp;
+<?lsmb END; ?>
+</body>
+<?lsmb PROCESS end_html ?>

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