Skip to content

Commit

Permalink
Merging fixed assets in except for menu
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.code.sf.net/p/ledger-smb/code/trunk@3455 4979c152-3d1c-0410-bac9-87ea11338e46
  • Loading branch information
einhverfr committed Jul 6, 2011
1 parent a7f83a2 commit 762b72c
Show file tree
Hide file tree
Showing 10 changed files with 2,589 additions and 0 deletions.
133 changes: 133 additions & 0 deletions LedgerSMB/DBObject/Asset.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package LedgerSMB::DBObject::Asset;

=head1 NAME
LedgerSMB::DBObject::Asset.pm, LedgerSMB Base Class for Fixed Assets
=head1 SYNOPSIS
This library contains the base utility functions for creating, saving, and
retrieving fixed assets for depreciation
=cut

use base qw(LedgerSMB::DBObject);
use strict;

sub save {
my ($self) = @_;
my ($ref) = $self->exec_method(funcname => 'asset__save');
$self->merge($ref);
$self->{dbh}->commit || $self->error(
$self->{_locale}->text("Unable to save [_1] object",
$self->{_locale}->text('Asset'))
);
return $ref if $self->{dbh}->commit;
}

sub import_file {

my $self = shift @_;

my $handle = $self->{_request}->upload('import_file');
my $contents = join("\n", <$handle>);

$self->{import_entries} = [];
for my $line (split /(\r\n|\r|\n)/, $contents){
next if ($line !~ /,/);
my @fields;
$line =~ s/[^"]"",/"/g;
while ($line ne '') {
if ($line =~ /^"/){
$line =~ s/"(.*?)"(,|$)//;
my $field = $1;
$field =~ s/\s*$//;
push @fields, $field;
} else {
$line =~ s/([^,]*),?//;
my $field = $1;
$field =~ s/\s*$//;
push @fields, $field;
}
}
push @{$self->{import_entries}}, \@fields;
}
unshift @{$self->{import_entries}}; # get rid of header line
return @{$self->{import_entries}};
}


sub get {
my ($self) = @_;
my ($ref) = $self->exec_method(funcname => 'asset__get');
$self->merge($ref);
return $ref;
}

sub search {
my ($self) = @_;
my @results = $self->exec_method(funcname => 'asset_item__search');
$self->{search_results} = \@results;
return @results;
}

sub save_note {
my ($self) = @_;
my ($ref) = $self->exec_method(funcname => 'asset_item__add_note');
$self->{dbh}->commit;
}

sub get_metadata {
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->{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(
funcname => 'asset_report__get_expense_accts'
);
my @dep_methods = $self->exec_method(
funcname => 'asset_class__get_dep_methods'
);
for my $dep(@dep_methods){
$self->{dep_method}->{$dep->{id}} = $dep;
}
for my $acc (@{$self->{asset_accounts}}){
$acc->{text} = $acc->{accno} . '--' . $acc->{description};
}
for my $acc (@{$self->{dep_accounts}}){
$acc->{text} = $acc->{accno} . '--' . $acc->{description};
}
for my $acc (@{$self->{exp_accounts}}){
$acc->{text} = $acc->{accno} . '--' . $acc->{description};
}
}

sub get_next_tag {
my ($self) = @_;
my ($ref) = $self->call_procedure(
procname => 'setting_increment',
args => ['asset_tag']
);
$self->{tag} = $ref->{setting_increment};
$self->{dbh}->commit;
}

sub import_asset {
my ($self) = @_;
my ($ref) = $self->exec_method(funcname => 'asset_report__import');
return $ref;
}

sub get_invoice_id {
my ($self) = @_;
my ($ref) = $self->exec_method(funcname => 'get_vendor_invoice_id');
if (!$ref) {
$self->error($self->{_locale}->text('Invoice not found'));
} else {
$self->{invoice_id} = $ref->{get_vendor_invoice_id};
}
}

1;
55 changes: 55 additions & 0 deletions LedgerSMB/DBObject/Asset_Class.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package LedgerSMB::DBObject::Asset_Class;

=head1 NAME
LedgerSMB::DBObject::Asset_Class.pm, LedgerSMB Base Class for Asset Classes
=head1 SYNOPSIS
This library contains the base utility functions for creating, saving, and
retrieving depreciation categories of assets.
=cut

use base qw(LedgerSMB::DBObject);
use strict;

sub save {
my ($self) = @_;
my ($ref) = $self->exec_method(funcname => 'asset_class__save');
$self->merge($ref);
$self->{dbh}->commit || $self->error(
$self->{_locale}->text("Unable to save [_1] object",
$self->{_locale}->text('Asset Class'))
);
return $ref if $self->{dbh}->commit;
}

sub get_metadata {
my ($self) = @_;
@{$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->{dep_methods}} = $self->exec_method(funcname => 'asset_class__get_dep_methods');
for my $acc (@{$self->{asset_accounts}}){
$acc->{text} = $acc->{accno} . '--' . $acc->{description};
}
for my $acc (@{$self->{dep_accounts}}){
$acc->{text} = $acc->{accno} . '--' . $acc->{description};
}
}

sub get_asset_class {
my ($self) = @_;
my ($ref) = $self->exec_method(funcname => 'asset_class__get');
$self->merge($ref);
return $ref;
}

sub list_asset_classes {
my ($self) = @_;
my @refs = $self->exec_method(funcname => 'asset_class__list');
$self->{classes} = \@refs;
return @refs;
}

1;
117 changes: 117 additions & 0 deletions LedgerSMB/DBObject/Asset_Report.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@

package LedgerSMB::DBObject::Asset_Report;

=head1 NAME
LedgerSMB::DBObject::Asset_Report.pm, LedgerSMB Base Class for Asset Reports
=head1 SYNOPSIS
This library contains the base utility functions for creating, saving, and
retrieving depreciation categories of asset depreciation and disposal reports.
=cut

use base qw(LedgerSMB::DBObject);
use strict;

sub save {
my ($self) = @_;
if ($self->{depreciation}){
my ($ref) = $self->exec_method(funcname => 'asset_report__save');
$self->{report_id} = $ref->{id};
$self->{asset_ids} = $self->_db_array_scalars(@{$self->{asset_ids}});
my ($dep) = $self->exec_method(funcname => 'asset_class__get_dep_method');
$self->exec_method(funcname => $dep->{sproc});
} else {
my ($ref) = $self->exec_method(funcname => 'asset_report__begin_disposal');
for my $i (0 .. $self->{rowcount}){
if ($self->{"asset_$i"} == 1){
my $id = $self->{"id_$i"};
$self->call_procedure(procname => 'asset_report__dispose',
args => [$ref->{id},
$id,
$self->{"amount_$id"},
$self->{"dm_$id"},
$self->{"percent_$id"}]);
}
}
}
$self->{dbh}->commit;
}

sub get {
my ($self) = @_;
my ($ref) = $self->exec_method(funcname => 'asset_report__get');
$self->merge($ref);
$self->{report_lines} = [];
if ($self->{report_class} == 1){
@{$self->{report_lines}} = $self->exec_method(
funcname => 'asset_report__get_lines'
);
} elsif ($self->{report_class} == 2) {
@{$self->{report_lines}} = $self->exec_method(
funcname => 'asset_report__get_disposal'
);
} elsif ($self->{report_class} == 4) {
@{$self->{report_lines}} = $self->exec_method(
funcname => 'asset_report_partial_disposal_details'
);
}
return;
}

sub get_nbv {
my ($self) = @_;
return $self->exec_method(funcname => 'asset_nbv_report');
}


sub generate {
my ($self) = @_;
@{$self->{assets}} = $self->exec_method(
funcname => 'asset_report__generate'
);
for my $asset (@{$self->{assets}}){
if ($self->{depreciation}){
$asset->{checked} = "CHECKED";
}
}
}

sub approve {
my ($self) = @_;
$self->exec_method(funcname => 'asset_report__approve');
$self->{dbh}->commit;
}

sub search {
my ($self) = @_;
return $self->exec_method(funcname => 'asset_report__search');
}

sub get_metadata {
my ($self) = @_;
@{$self->{asset_classes}} = $self->exec_method(
funcname => 'asset_class__list'
);
@{$self->{exp_accounts}} = $self->exec_method(
funcname => 'asset_report__get_expense_accts'
);
@{$self->{gain_accounts}} = $self->exec_method(
funcname => 'asset_report__get_gain_accts'
);
@{$self->{disp_methods}} = $self->exec_method(
funcname => 'asset_report__get_disposal_methods'
);
@{$self->{loss_accounts}} = $self->exec_method(
funcname => 'asset_report__get_loss_accts'
);
for my $atype (qw(exp_accounts gain_accounts loss_accounts)){
for my $acct (@{$self->{$atype}}){
$acct->{text} = $acct->{accno}. '--'. $acct->{description};
}
}
}

1;
7 changes: 7 additions & 0 deletions asset.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/perl

use FindBin;
BEGIN {
lib->import($FindBin::Bin) unless $ENV{mod_perl}
}
require "lsmb-request.pl";
Loading

0 comments on commit 762b72c

Please sign in to comment.