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

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



Revision: 3458
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3458&view=rev
Author:   einhverfr
Date:     2011-07-07 10:33:08 +0000 (Thu, 07 Jul 2011)

Log Message:
-----------
CSV parser for Fixed Asset import

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Asset_Class.pm

Added Paths:
-----------
    trunk/LedgerSMB/Assets/
    trunk/LedgerSMB/Assets/CSV.pm

Added: trunk/LedgerSMB/Assets/CSV.pm
===================================================================
--- trunk/LedgerSMB/Assets/CSV.pm	                        (rev 0)
+++ trunk/LedgerSMB/Assets/CSV.pm	2011-07-07 10:33:08 UTC (rev 3458)
@@ -0,0 +1,51 @@
+# CSV parser is basically a framework to handle any CSV files or fixed-width format files.
+# Parsers are defined in CSV/parser_type.
+
+package LedgerSMB::Reconciliation::CSV;
+
+use base qw/LedgerSMB::DBObject::Reconciliation/;
+
+opendir (DCSV, 'LedgerSMB/Reconciliation/CSV/Formats');
+for my $format (readdir(DCSV)){
+	if ($format !~ /^\./){
+		do "LedgerSMB/Reconciliation/CSV/Formats/$format";
+	}
+};
+
+sub load_file {
+    
+    my $self = shift @_;
+    my $fieldname = shift @_;
+    
+    my $contents;
+    my $handle = $self->{_request}->upload($fieldname);
+    $contents = join("\n", <$handle>);
+    return $contents;
+}
+
+sub process {
+    my $self = shift @_;
+    
+    # thoroughly implementation-dependent, so depends on helper-functions
+    my ($recon, $fldname) = @_;
+    my $contents = $self->load_file($fldname);
+    
+    my $func = "parse_" . $recon->{chart_id};
+    if ($self->can($func)){
+       @entries = $self->can($func)->($self,$contents);
+       @{$self->{entries}} = @entries;
+
+       $self->{file_upload} = 1;
+   }
+   else {
+       $self->{file_upload} = 0;
+   }
+   return $self->{entries};
+}
+
+sub is_error {
+   my $self = shift @_;    
+   return $self->{invalid_format};
+}
+
+1;

Modified: trunk/LedgerSMB/DBObject/Asset_Class.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Asset_Class.pm	2011-07-07 10:24:08 UTC (rev 3457)
+++ trunk/LedgerSMB/DBObject/Asset_Class.pm	2011-07-07 10:33:08 UTC (rev 3458)
@@ -9,11 +9,55 @@
 This library contains the base utility functions for creating, saving, and
 retrieving depreciation categories of assets.
 
+=head1 STANDARD PROPERTIES
+
+=over
+
+=item id
+
+Integer ID of record.
+
+=item lable
+
+Text description of asset class
+
+=item asset_account_id 
+
+Integer id of asset account.
+
+=item dep_account_id 
+
+Integer id of depreciation account.
+
+=item method 
+
+Integer id of depreciation method.
+
+=back
+
+=head1 METHODS
+
+=over
+
 =cut
 
 use base qw(LedgerSMB::DBObject);
 use strict;
 
+=item save
+
+Properties used:
+id:  (Optional) ID of existing class to overwrite. 
+asset_account_id: Account id to store asset values
+dep_account_id: Account id for depreciation information 
+method:  ID of depreciation method
+label:  Name of the asset class
+unit_label:  Label of the depreciation unit
+
+Typically sets ID if no match found or if ID not provided.
+
+=cut
+
 sub save {
     my ($self) = @_;
     my ($ref) = $self->exec_method(funcname => 'asset_class__save');
@@ -25,6 +69,16 @@
     return $ref if $self->{dbh}->commit;
 }
 
+=item get_metadata 
+
+sets:
+
+asset_accounts to arrayref of asset accounts
+dep_accounts to arrayref of depreciation accounts
+dep_methods to arrayrefo of depreciation methods
+
+=cut
+
 sub get_metadata {
     my ($self) = @_;
     @{$self->{asset_accounts}} = $self->exec_method(funcname => 'asset_class__get_asset_accounts');
@@ -38,6 +92,14 @@
     }
 }
 
+=item get_asset_class()
+
+Requires id to be set.
+
+Sets all other standard properties if the record is found.
+
+=cut
+
 sub get_asset_class {
     my ($self) = @_;
     my ($ref) = $self->exec_method(funcname => 'asset_class__get');
@@ -45,6 +107,12 @@
     return $ref;
 }
 
+=item list_asset_classes
+
+Sets classes to a list of all asset classes, ordered as per db.
+
+=cut
+
 sub list_asset_classes {
     my ($self) = @_;
     my @refs = $self->exec_method(funcname => 'asset_class__list');


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