Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 3705b374

Von Kivitendo Admin vor fast 8 Jahren hinzugefügt

  • ID 3705b3749fa74d720841294775973ffea0d34772
  • Vorgänger bfb31beb
  • Nachfolger 2bc58307

Project verknüpfte Belege - auch project_id durchsuchen

Bisher wurde nur auf globalproject_id in ar/ap/oe/do geprüft.

Jetzt wird zusätzlich gelistet:

  • gl-Belege erweitere, wo das Project einer der acc_trans-Zeilen zugeordnet ist,
  • Rechnungen/Aufträge/Lieferscheine, wo mindestens eine der Positionen einen
    Projekteintrag hat, aber nicht unbedingt die globalproject_id gesetzt ist

Unterschiede anzeigen:

SL/Controller/Project.pm
28 28

  
29 29
use Rose::Object::MakeMethods::Generic
30 30
(
31
 scalar => [ qw(project linked_records) ],
32
 'scalar --get_set_init' => [ qw(models customers project_types project_statuses projects) ],
31
 scalar => [ qw(project) ],
32
 'scalar --get_set_init' => [ qw(models customers project_types project_statuses projects linked_records) ],
33 33
);
34 34

  
35 35
__PACKAGE__->run_before('check_auth',   except => [ qw(ajax_autocomplete) ]);
......
75 75
sub action_edit {
76 76
  my ($self) = @_;
77 77

  
78
  $self->get_linked_records;
79 78
  $self->display_form(title    => $::locale->text('Edit project #1', $self->project->projectnumber),
80 79
                      callback => $::form->{callback} || $self->url_for(action => 'edit', id => $self->project->id));
81 80
}
......
164 163
sub init_project_statuses { SL::DB::Manager::ProjectStatus->get_all_sorted }
165 164
sub init_project_types    { SL::DB::Manager::ProjectType->get_all_sorted   }
166 165

  
166
sub init_linked_records {
167
  my ($self) = @_;
168
  return [
169
    map  { @{ $_ } }
170
    grep { $_      } (
171
      SL::DB::Manager::Invoice->        get_all(where        => [ invoice => 1, or => [ globalproject_id => $self->project->id, 'invoiceitems.project_id' => $self->project->id ] ],
172
                                                with_objects => [ 'invoiceitems', 'customer' ],
173
                                                distinct     => [ 'customer' ],
174
                                                sort_by       => 'transdate ASC'),
175
      SL::DB::Manager::Invoice->        get_all(where        => [ invoice => 0, or => [ globalproject_id => $self->project->id, 'transactions.project_id' => $self->project->id ] ],
176
                                                with_objects => [ 'transactions', 'customer' ],
177
                                                distinct     => [ 'customer' ],
178
                                                sort_by       => 'transdate ASC'),
179
      SL::DB::Manager::PurchaseInvoice->get_all(where => [ invoice => 1,
180
                                                           or => [ globalproject_id => $self->project->id, 'invoiceitems.project_id' => $self->project->id ]
181
                                                         ],
182
                                                with_objects => [ 'invoiceitems', 'vendor' ],
183
                                                distinct     => [ 'customer' ],
184
                                                sort_by => 'transdate ASC'),
185
      SL::DB::Manager::PurchaseInvoice->get_all(where => [ invoice => 0,
186
                                                           or => [ globalproject_id => $self->project->id, 'transactions.project_id' => $self->project->id ]
187
                                                         ],
188
                                                with_objects => [ 'transactions', 'vendor' ],
189
                                                distinct     => [ 'customer' ],
190
                                                sort_by => 'transdate ASC'),
191
      SL::DB::Manager::GLTransaction->  get_all(where => [ 'transactions.project_id' => $self->project->id ],
192
                                                with_objects => [ 'transactions' ],
193
                                                distinct     => 1,
194
                                                sort_by => 'transdate ASC'),
195
      SL::DB::Manager::Order->          get_all(where => [ or => [ globalproject_id => $self->project->id, 'orderitems.project_id' => $self->project->id ] ],
196
                                                with_objects => [ 'orderitems', 'customer', 'vendor' ],
197
                                                distinct => [ 'customer', 'vendor' ],
198
                                                sort_by => 'transdate ASC' ),
199
      SL::DB::Manager::DeliveryOrder->  get_all(where => [ or => [ globalproject_id => $self->project->id, 'orderitems.project_id' => $self->project->id ] ],
200
                                                with_objects => [ 'orderitems', 'customer', 'vendor' ],
201
                                                distinct => [ 'customer', 'vendor' ],
202
                                                sort_by => 'transdate ASC'),
203
    )];
204
}
205

  
206

  
167 207
sub init_projects {
168 208
  if ($::form->{no_paginate}) {
169 209
    $_[0]->models->disable_plugin('paginated');
......
233 273
  $self->project(SL::DB::Project->new(id => $::form->{id})->load);
234 274
}
235 275

  
236
sub get_linked_records {
237
  my ($self) = @_;
238

  
239
  $self->linked_records([
240
    map  { @{ $_ } }
241
    grep { $_      } (
242
      SL::DB::Manager::Order->          get_all(where => [ globalproject_id => $self->project->id ], with_objects => [ 'customer', 'vendor' ], sort_by => 'transdate ASC'),
243
      SL::DB::Manager::DeliveryOrder->  get_all(where => [ globalproject_id => $self->project->id ], with_objects => [ 'customer', 'vendor' ], sort_by => 'transdate ASC'),
244
      SL::DB::Manager::Invoice->        get_all(where => [ globalproject_id => $self->project->id ], with_objects => [ 'customer'           ], sort_by => 'transdate ASC'),
245
      SL::DB::Manager::PurchaseInvoice->get_all(where => [ globalproject_id => $self->project->id ], with_objects => [             'vendor' ], sort_by => 'transdate ASC'),
246
    )]);
247
}
248 276

  
249 277
sub prepare_report {
250 278
  my ($self)      = @_;
t/controllers/project/project_linked_records.t
1
use strict;
2
use Test::More;
3

  
4
use lib 't';
5
use Support::TestSetup;
6
use Carp;
7
use Test::Exception;
8
use SL::Dev::ALL;
9
use SL::DB::Part;
10
use SL::DB::Order;
11
use SL::DB::Customer;
12
use SL::DB::Vendor;
13
use SL::DB::Chart;
14
use SL::Controller::Project;
15
use DateTime;
16

  
17
use utf8;
18

  
19
Support::TestSetup::login();
20

  
21
clear_up();
22

  
23
my $vendor   = SL::Dev::CustomerVendor::create_vendor->save;
24
my $customer = SL::Dev::CustomerVendor::create_customer->save;
25
my $project  = SL::Dev::Record::create_project(projectnumber => 'p1', description => 'Project 1')->save;
26

  
27
my $part1 = SL::Dev::Part::create_part(   partnumber => 'T4254')->save;
28
my $part2 = SL::Dev::Part::create_service(partnumber => 'Serv1')->save;
29

  
30
# sales order with globalproject_id and item project_ids
31
my $sales_order = SL::Dev::Record::create_sales_order(
32
  save             => 1,
33
  customer         => $customer,
34
  globalproject_id => $project->id,
35
  taxincluded      => 0,
36
  orderitems       => [ SL::Dev::Record::create_order_item(part => $part1, qty =>  3, sellprice => 70, project_id => $project->id),
37
                        SL::Dev::Record::create_order_item(part => $part2, qty => 10, sellprice => 50, project_id => $project->id),
38
                      ]
39
);
40

  
41
# sales order with no globalproject_id but item project_ids
42
my $sales_order2 = SL::Dev::Record::create_sales_order(
43
  save             => 1,
44
  customer         => $customer,
45
  taxincluded      => 0,
46
  orderitems       => [ SL::Dev::Record::create_order_item(part => $part1, qty =>  3, sellprice => 70, project_id => $project->id),
47
                        SL::Dev::Record::create_order_item(part => $part2, qty => 10, sellprice => 50),
48
                      ]
49
);
50

  
51
# purchase order with globalproject_id and item project_ids
52
my $purchase_order = SL::Dev::Record::create_purchase_order(
53
  save             => 1,
54
  vendor           => $vendor,
55
  globalproject_id => $project->id,
56
  taxincluded      => 0,
57
  orderitems       => [ SL::Dev::Record::create_order_item(part => $part1, qty =>  3, sellprice => 70, project_id => $project->id),
58
                        SL::Dev::Record::create_order_item(part => $part2, qty => 10, sellprice => 50, project_id => $project->id),
59
                      ]
60
);
61

  
62
# sales_invoice with globalproject_id, and all items with project_id
63
my $sales_invoice = SL::Dev::Record::create_sales_invoice(
64
  customer         => $customer,
65
  globalproject_id => $project->id,
66
  taxincluded      => 0,
67
  invoiceitems     => [ SL::Dev::Record::create_invoice_item(part => $part1, qty =>  3, sellprice => 70, project_id => $project->id),
68
                        SL::Dev::Record::create_invoice_item(part => $part2, qty => 10, sellprice => 50, project_id => $project->id),
69
                      ]
70
);
71

  
72
# sales_invoice with globalproject_id, but none of the items has a project_id
73
my $sales_invoice2 = SL::Dev::Record::create_sales_invoice(
74
  customer         => $customer,
75
  globalproject_id => $project->id,
76
  taxincluded      => 0,
77
  invoiceitems     => [ SL::Dev::Record::create_invoice_item(part => $part1, qty =>  3, sellprice => 70),
78
                        SL::Dev::Record::create_invoice_item(part => $part2, qty => 10, sellprice => 50),
79
                      ]
80
);
81

  
82
# one of the invoice items has the project id, but there is no globalproject_id
83
my $sales_invoice4 = SL::Dev::Record::create_sales_invoice(
84
  customer         => $customer,
85
  taxincluded      => 0,
86
  invoiceitems     => [ SL::Dev::Record::create_invoice_item(part => $part1, qty =>  3, sellprice => 70),
87
                        SL::Dev::Record::create_invoice_item(part => $part2, qty => 10, sellprice => 50, project_id => $project->id),
88
                      ]
89
);
90

  
91
my $today = DateTime->today;
92
my $expense_chart_porto = SL::DB::Manager::Chart->find_by(description => 'Porto');
93
my $income_chart        = SL::DB::Manager::Chart->find_by(accno => 8400);
94
my $tax_9 = SL::DB::Manager::Tax->find_by(taxkey => 9, rate => 0.19) || die "No tax";
95
my $tax_3 = SL::DB::Manager::Tax->find_by(taxkey => 3, rate => 0.19) || die "No tax";
96

  
97
# create an ar_transaction manually, with globalproject_id and acc_trans project_ids
98
my $ar_transaction = SL::DB::Invoice->new(
99
      invoice          => 0,
100
      invnumber        => 'test ar_transaction globalproject_id',
101
      amount           => 119,
102
      netamount        => 100,
103
      transdate        => $today,
104
      taxincluded      => 0,
105
      customer_id      => $customer->id,
106
      taxzone_id       => $customer->taxzone_id,
107
      currency_id      => $::instance_conf->get_currency_id,
108
      transactions     => [],
109
      notes            => 'test ar_transaction globalproject_id',
110
      globalproject_id => $project->id,
111
);
112
$ar_transaction->add_ar_amount_row(
113
    amount     => $ar_transaction->netamount,
114
    chart      => $income_chart,
115
    tax_id     => $tax_3->id,
116
    project_id => $project->id,
117
);
118
my $ar_chart = SL::DB::Manager::Chart->find_by( accno => '1400' ); # Forderungen
119
$ar_transaction->create_ar_row(chart => $ar_chart);
120
$ar_transaction->save;
121

  
122
# create an ap_transaction manually, with globalproject_id and acc_trans project_ids
123
my $ap_transaction = SL::DB::PurchaseInvoice->new(
124
      invoice          => 0,
125
      invnumber        => 'test ap_transaction globalproject_id',
126
      amount           => 119,
127
      netamount        => 100,
128
      transdate        => $today,
129
      taxincluded      => 0,
130
      vendor_id        => $vendor->id,
131
      taxzone_id       => $vendor->taxzone_id,
132
      currency_id      => $::instance_conf->get_currency_id,
133
      transactions     => [],
134
      notes            => 'test ap_transaction globalproject_id',
135
      globalproject_id => $project->id,
136
);
137
$ap_transaction->add_ap_amount_row(
138
    amount     => $ap_transaction->netamount,
139
    chart      => $expense_chart_porto,
140
    tax_id     => $tax_9->id,
141
    project_id => $project->id,
142
);
143
my $ap_chart = SL::DB::Manager::Chart->find_by( accno => '1600' ); # Verbindlichkeiten
144
$ap_transaction->create_ap_row(chart => $ap_chart);
145
$ap_transaction->save;
146

  
147
# create an ap_transaction manually, with no globalproject_id but acc_trans project_ids
148
my $ap_transaction2 = SL::DB::PurchaseInvoice->new(
149
      invoice          => 0,
150
      invnumber        => 'test ap_transaction no globalproject_id',
151
      amount           => 119,
152
      netamount        => 100,
153
      transdate        => $today,
154
      taxincluded      => 0,
155
      vendor_id        => $vendor->id,
156
      taxzone_id       => $vendor->taxzone_id,
157
      currency_id      => $::instance_conf->get_currency_id,
158
      transactions     => [],
159
      notes            => 'test ap_transaction no globalproject_id',
160
);
161
$ap_transaction2->add_ap_amount_row(
162
    amount     => $ap_transaction2->netamount,
163
    chart      => $expense_chart_porto,
164
    tax_id     => $tax_9->id,
165
    project_id => $project->id,
166
);
167
my $ap_chart = SL::DB::Manager::Chart->find_by( accno => '1600' ); # Verbindlichkeiten
168
$ap_transaction2->create_ap_row(chart => $ap_chart);
169
$ap_transaction2->save;
170

  
171
my $expense_chart = SL::DB::Manager::Chart->find_by(accno => '4660'); # Reisekosten
172
my $cash_chart    = SL::DB::Manager::Chart->find_by(accno => '1000'); # Kasse
173
my $tax_chart     = SL::DB::Manager::Chart->find_by(accno => '1576'); # Vorsteuer
174

  
175
my @acc_trans;
176
push(@acc_trans, SL::DB::AccTransaction->new(
177
                                      chart_id   => $expense_chart->id,
178
                                      chart_link => $expense_chart->link,
179
                                      amount     => -84.03,
180
                                      transdate  => $today,
181
                                      source     => '',
182
                                      taxkey     => 9,
183
                                      tax_id     => $tax_9->id,
184
                                      project_id => $project->id,
185
));
186
push(@acc_trans, SL::DB::AccTransaction->new(
187
                                      chart_id   => $tax_chart->id,
188
                                      chart_link => $tax_chart->link,
189
                                      amount     => -15.97,
190
                                      transdate  => $today,
191
                                      source     => '',
192
                                      taxkey     => 9,
193
                                      tax_id     => $tax_9->id,
194
                                      project_id => $project->id,
195
));
196
push(@acc_trans, SL::DB::AccTransaction->new(
197
                                      chart_id   => $cash_chart->id,
198
                                      chart_link => $cash_chart->link,
199
                                      amount     => 100,
200
                                      transdate  => $today,
201
                                      source     => '',
202
                                      taxkey     => 0,
203
                                      tax_id     => 0,
204
));
205

  
206
my $gl_transaction = SL::DB::GLTransaction->new(
207
  reference      => "reise",
208
  description    => "reise",
209
  transdate      => $today,
210
  gldate         => $today,
211
  employee_id    => SL::DB::Manager::Employee->current->id,
212
  taxincluded    => 1,
213
  type           => undef,
214
  ob_transaction => 0,
215
  cb_transaction => 0,
216
  storno         => 0,
217
  storno_id      => undef,
218
  transactions   => \@acc_trans,
219
)->save;
220

  
221
my $controller = SL::Controller::Project->new;
222
$::form->{id} = $project->id;
223
$controller->load_project;
224
is( scalar @{$controller->linked_records}, 10, "found all records that have a link to the project");
225

  
226
clear_up();
227

  
228
done_testing;
229

  
230
sub clear_up {
231
  foreach (qw(OrderItem Order InvoiceItem Invoice PurchaseInvoice Part GLTransaction AccTransaction PurchaseInvoice Project Vendor Customer)) {
232
    "SL::DB::Manager::${_}"->delete_all(all => 1);
233
  }
234
}
235

  
236
1

Auch abrufbar als: Unified diff