6a98845bce0f5e5553f5c96e962cff6777a8a1e9
[kivitendo-erp.git] / SL / DB / TaxzoneChart.pm
1 # This file has been auto-generated only because it didn't exist.
2 # Feel free to modify it at will; it will not be overwritten automatically.
3
4 package SL::DB::TaxzoneChart;
5
6 use strict;
7
8 use SL::DB::MetaSetup::TaxzoneChart;
9 use SL::DB::Manager::TaxzoneChart;
10 use SL::DB::MetaSetup::Buchungsgruppe;
11
12 __PACKAGE__->meta->initialize;
13
14 # Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
15 #__PACKAGE__->meta->make_manager_class;
16
17 sub get_all_accounts_by_buchungsgruppen_id {
18   my ($self, $buchungsgruppen_id) = @_;
19
20   my $all_taxzonecharts = SL::DB::Manager::TaxzoneChart->get_all(where   => [ buchungsgruppen_id => $buchungsgruppen_id ],
21                                                                  sort_by => 'taxzone_id');
22
23   my %list = ();
24
25   # inventory_accno and description of the Buchungsgruppe:
26   $list{inventory_accno}             = SL::DB::Manager::Buchungsgruppe->find_by(id => $buchungsgruppen_id)->inventory_account->accno;
27   $list{inventory_accno_description} = SL::DB::Manager::Buchungsgruppe->find_by(id => $buchungsgruppen_id)->inventory_account->description;
28
29   foreach my $taxzonechart (@{ $all_taxzonecharts }) {
30     $list{ $taxzonechart->taxzone_id }{taxzone_chart_id}          = $taxzonechart->id;
31     $list{ $taxzonechart->taxzone_id }{income_accno}              = $taxzonechart->get_income_accno;
32     $list{ $taxzonechart->taxzone_id }{expense_accno}             = $taxzonechart->get_expense_accno;
33     $list{ $taxzonechart->taxzone_id }{income_accno_id}           = $taxzonechart->income_accno_id;
34     $list{ $taxzonechart->taxzone_id }{expense_accno_id}          = $taxzonechart->expense_accno_id;
35     $list{ $taxzonechart->taxzone_id }{income_accno_description}  = $taxzonechart->get_income_accno_description;
36     $list{ $taxzonechart->taxzone_id }{expense_accno_description} = $taxzonechart->get_expense_accno_description;
37   }
38   return \%list;
39 }
40
41 sub get_all_accounts_by_taxzone_id {
42   my ($self, $taxzone_id) = @_;
43
44   my $all_taxzonecharts = SL::DB::Manager::TaxzoneChart->get_all(where => [ taxzone_id => $taxzone_id ]);
45
46   my %list = ();
47
48   foreach my $tzchart (@{ $all_taxzonecharts }) {
49     $list{ $tzchart->buchungsgruppen_id }{taxzone_chart_id}          = $tzchart->id;
50     $list{ $tzchart->buchungsgruppen_id }{income_accno}              = $tzchart->get_income_accno;
51     $list{ $tzchart->buchungsgruppen_id }{expense_accno}             = $tzchart->get_expense_accno;
52     $list{ $tzchart->buchungsgruppen_id }{income_accno_id}           = $tzchart->income_accno_id;
53     $list{ $tzchart->buchungsgruppen_id }{expense_accno_id}          = $tzchart->expense_accno_id;
54     $list{ $tzchart->buchungsgruppen_id }{income_accno_description}  = $tzchart->get_income_accno_description;
55     $list{ $tzchart->buchungsgruppen_id }{expense_accno_description} = $tzchart->get_expense_accno_description;
56   }
57
58   return \%list;
59 }
60
61 sub get_income_accno {
62   my $self = shift;
63   require SL::DB::Manager::Chart;
64   return SL::DB::Manager::Chart->find_by(id => $self->income_accno_id)->accno();
65 }
66
67 sub get_expense_accno {
68   my $self = shift;
69   require SL::DB::Manager::Chart;
70   return SL::DB::Manager::Chart->find_by(id => $self->expense_accno_id)->accno();
71 }
72
73 sub get_income_accno_description {
74   my $self = shift;
75   require SL::DB::Manager::Chart;
76   return SL::DB::Manager::Chart->find_by(id => $self->income_accno_id)->description();
77 }
78
79 sub get_expense_accno_description {
80   my $self = shift;
81   require SL::DB::Manager::Chart;
82   return SL::DB::Manager::Chart->find_by(id => $self->expense_accno_id)->description();
83 }
84
85 1;