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

SF.net SVN: ledger-smb:[6434] trunk/LedgerSMB



Revision: 6434
          http://sourceforge.net/p/ledger-smb/code/6434
Author:   einhverfr
Date:     2014-01-10 12:30:01 +0000 (Fri, 10 Jan 2014)
Log Message:
-----------
Asset listing migrated to new framework

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Asset.pm
    trunk/LedgerSMB/Scripts/asset.pm

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

Modified: trunk/LedgerSMB/DBObject/Asset.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Asset.pm	2014-01-10 11:06:54 UTC (rev 6433)
+++ trunk/LedgerSMB/DBObject/Asset.pm	2014-01-10 12:30:01 UTC (rev 6434)
@@ -228,7 +228,7 @@
     my ($self) = @_;
     @{$self->{asset_classes}} = $self->exec_method(funcname => 'asset_class__list');
    @{$self->{locations}} = $self->exec_method(funcname => 'warehouse__list_all');
-   @{$self->{departments}} = $self->exec_method(funcname => 'department__list_all');
+   @{$self->{departments}} = $self->call_procedure(procname => 'business_unit__list_by_class', args => [1, undef, undef, undef]);
     @{$self->{asset_accounts}} = $self->exec_method(funcname => 'asset_class__get_asset_accounts');
     @{$self->{dep_accounts}} = $self->exec_method(funcname => 'asset_class__get_dep_accounts');
     @{$self->{exp_accounts}} = $self->exec_method(

Added: trunk/LedgerSMB/Report/Listings/Asset.pm
===================================================================
--- trunk/LedgerSMB/Report/Listings/Asset.pm	                        (rev 0)
+++ trunk/LedgerSMB/Report/Listings/Asset.pm	2014-01-10 12:30:01 UTC (rev 6434)
@@ -0,0 +1,158 @@
+=head1 NAME
+
+LedgerSMB::Report::Listings::Asset - Search Fixed Assets in LedgerSMB
+
+=head1 SYNPOSIS
+
+  LedgerSMB::Report::Listings::Asset->new(%$request)->render($request);
+
+=cut
+
+package LedgerSMB::Report::Listings::Asset;
+use Moose;
+extends 'LedgerSMB::Report';
+
+=head1 CRITERIA PROPERTIES
+
+=head2 asset_class int
+
+id of asset class
+
+=head2 description text
+
+Partial string search for description
+
+=head2 tag
+
+Partial string search for tag
+
+=head2 purchase_date
+
+Exact search on purchase date
+
+=head2 purchase_value
+
+Exact search on purchase value
+
+=head2 usable_life
+
+Exact search on usable life
+
+=head2 salvage_value
+
+Exact search on salvage value
+
+=cut
+
+has asset_class     => (is => 'ro', isa => 'Int', required => 0);
+has description     => (is => 'ro', isa => 'Str', required => 0);
+has tag             => (is => 'ro', isa => 'Str', required => 0);
+has purchase_date   => (is => 'ro', isa => 'LedgerSMB::Moose::Date',coerce=> 1);
+has purchase_value  => (is => 'ro', isa => 'LedgerSMB::Moose::Numeric',
+                       coerce => 1);
+has usable_life     => (is => 'ro', isa => 'Int', required => 0);
+has salvage_value   => (is => 'ro', isa => 'LedgerSMB::Moose::Numeric',
+                       coerce => 1);
+
+=head1 CONSTANT METHODS
+
+=head2 columns
+
+=over
+
+=item tag 
+
+=item description
+
+=item purchase_date
+
+=item purchase_value
+
+=item usable_life
+
+=back
+
+=cut
+
+sub columns {
+    return [
+     { col_id => 'tag',
+         name => LedgerSMB::Report::text('Tag'),
+         type => 'href',
+    href_base => 'asset.pl?action=asset_edit&id=', },
+    {  col_id => 'description',
+         name => LedgerSMB::Report::text('Description'),
+         type => 'text', },
+    {  col_id => 'purchase_date',
+         name => LedgerSMB::Report::text('Purchase Date'),
+         type => 'text', },
+    {  col_id => 'purchase_value',
+         name => LedgerSMB::Report::text('Purchase Value'),
+         type => 'text', },
+    {  col_id => 'usable_life',
+         name => LedgerSMB::Report::text('Usable Life'),
+         type => 'text', },
+   ];
+}
+
+
+=head2 header_lines
+
+=over 
+
+=item tag
+
+=item description
+
+=item purchase_date
+
+=item purchase_value
+
+=back
+
+=cut
+
+sub header_lines {
+    return  [
+     { name => 'tag',         text => LedgerSMB::Report::text('Tag') },
+     { name => 'description', text => LedgerSMB::Report::text('Description') },
+     {name => 'purchase_date',text => LedgerSMB::Report::text('Purchase Date')},
+     {name => 'purchase_value',
+        text=> text => LedgerSMB::Report::text('Purchase Value') },
+   ];
+}
+
+=head2 name
+
+Asset Listing
+
+=cut
+
+sub name { return LedgerSMB::Report::text('Asset Listing') }
+
+=head1 METHODS
+
+=head2 run_report
+
+=cut
+
+sub run_report {
+    my ($self, $request) = @_;
+    my @rows = $self->exec_method(funcname => 'asset__search');
+    for my $r(@rows){
+       $r->{row_id} = $r->{id};
+    }
+    $self->rows(\@rows);
+}
+
+=head1 COPYRIGHT
+
+Copyright (C) 2014 The LedgerSMB Core Team
+
+This file may be re-used under the terms of the GNU General Public License 
+version 2 or at your option any later version.  Please see the included 
+LICENSE.txt for details
+
+=cut
+
+__PACKAGE__->meta->make_immutable;

Modified: trunk/LedgerSMB/Scripts/asset.pm
===================================================================
--- trunk/LedgerSMB/Scripts/asset.pm	2014-01-10 11:06:54 UTC (rev 6433)
+++ trunk/LedgerSMB/Scripts/asset.pm	2014-01-10 12:30:01 UTC (rev 6434)
@@ -21,6 +21,7 @@
 use LedgerSMB::DBObject::Asset_Report;
 use LedgerSMB::Report::Assets::Net_Book_Value;
 use LedgerSMB::Report::Listings::Asset_Class;
+use LedgerSMB::Report::Listings::Asset;
 use strict;
 
 our @file_columns = qw(tag purchase_date description asset_class location vendor 
@@ -253,68 +254,7 @@
 
 sub asset_results { 
     my ($request) = @_;
-    my $locale = $request->{_locale};
-    my $asset = LedgerSMB::DBObject::Asset->new(base => $request);
-    $asset->get_metadata;
-    if (!$asset->{usable_life}){
-       delete $asset->{usable_life};
-    }
-    my @items = $asset->search();
-    my $columns = ['tag', 'description', 'class', 'purchase_date', 
-                  'purchase_value', 'usable_life', 'location', 'department'];
-    my $heading = { tag            => $locale->text('Tag'),
-                    description    => $locale->text('Description'),
-                    purchase_date  => $locale->text('Purchase Date'),
-                    purchase_value => $locale->text('Purchase Value'),
-                    class          => $locale->text('Class'),
-                    usable_life    => $locale->text('Usable Life'),
-                    location       => $locale->text('Location'),
-                    department     => $locale->text('Department'),
-    };
-    my $asset_classes = {};
-    for my $ac(@{$asset->{asset_classes}}){
-        $asset_classes->{$ac->{id}} = $ac;
-    }
-    my $departments = {};
-    for my $dept(@{$asset->{departments}}){
-        $departments->{$dept->{id}} = $dept;
-    }
-    my $locations = {};
-    for my $loc(@{$asset->{asset_classes}}){
-        $locations->{$loc->{id}} = $loc;
-    }
-    my $rows = [];
-    for my $item (@items){
-        my $ref = {};
-        for my $label (qw(id description purchase_date purchase_value 
-                   usable_life)){
-            $ref->{$label} = $item->{$label};
-        }
-        $ref->{tag} = { href => "asset.pl?action=asset_edit&id=$item->{id}",
-                        text => $item->{tag},
-                      };
-        for my $label (qw(purchase_value usable_life)){
-            $ref->{$label} = $asset->format_amount({amount => $ref->{$label}});
-        }
-        $ref->{class} = $asset_classes->{$item->{asset_class_id}}->{label};
-        $ref->{department} 
-          = $departments->{$item->{department_id}}->{description};
-        $ref->{location} = $locations->{$item->{location_id}}->{description};
-        push @$rows, $ref;
-    }
-    my $template = LedgerSMB::Template->new(
-        user =>$request->{_user}, 
-        locale => $request->{_locale},
-        path => 'UI',
-        template => 'form-dynatable',
-        format => 'HTML'
-    );
-    $template->render({
-         form    => $asset,
-         heading => $heading,
-         rows    => $rows,
-         columns => $columns,
-   });
+    LedgerSMB::Report::Listings::Asset->new(%$request)->render($request);
 }
 
 =item asset_save

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


------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Ledger-smb-commits mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-commits