Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 9c79e857

Von Moritz Bunkus vor fast 10 Jahren hinzugefügt

  • ID 9c79e857f11b18b05c34189c26901fad86bc22ba
  • Vorgänger 61d88e69
  • Nachfolger 5534d9cb

Finanzcontrolling: Testcase für Aufträge mit wiederkehrenden Rechnungen

Unterschiede anzeigen:

t/controllers/financial_controlling/sales_order_with_periodic_invoices_config.t
1
package DateTime;
2

  
3
use SL::Helper::DateTime;
4

  
5
no warnings 'redefine';
6

  
7
sub now_local {
8
  return shift->new(time_zone => $::locale->get_local_time_zone, year => 2014, month => 3, day => 15, hour => 12, minute => 23, second => 34);
9
}
10

  
11
sub today_local {
12
  return shift->now_local->truncate(to => 'day');
13
}
14

  
15
package main;
16

  
17
use Test::More; # tests => 49;
18

  
19
use lib 't';
20
use strict;
21
use utf8;
22

  
23
use Carp;
24
use Support::TestSetup;
25

  
26
use_ok 'SL::BackgroundJob::CreatePeriodicInvoices';
27
use_ok 'SL::Controller::FinancialControllingReport';
28
use_ok 'SL::DB::Chart';
29
use_ok 'SL::DB::Customer';
30
use_ok 'SL::DB::Default';
31
use_ok 'SL::DB::Invoice';
32
use_ok 'SL::DB::Order';
33
use_ok 'SL::DB::Part';
34
use_ok 'SL::DB::TaxZone';
35

  
36
Support::TestSetup::login();
37

  
38
our ($ar_chart, $buchungsgruppe, $ctrl, $currency_id, $customer, $employee, $order, $part, $tax_zone, $unit, @invoices);
39

  
40
sub init_common_state {
41
  $ar_chart       = SL::DB::Manager::Chart->find_by(accno => '1400')                        || croak "No AR chart";
42
  $buchungsgruppe = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%') || croak "No accounting group";
43
  $currency_id    = SL::DB::Default->get->currency_id;
44
  $employee       = SL::DB::Manager::Employee->current                                      || croak "No employee";
45
  $tax_zone       = SL::DB::Manager::TaxZone->find_by( description => 'Inland')             || croak "No taxzone";
46
  $unit           = SL::DB::Manager::Unit->find_by(name => 'psch')                          || croak "No unit";
47
}
48

  
49
sub create_sales_order {
50
  my %params = @_;
51

  
52
  $params{$_} ||= {} for qw(customer part tax order orderitem);
53

  
54
  # Clean up: remove invoices, orders, parts and customers
55
  "SL::DB::Manager::${_}"->delete_all(all => 1) for qw(InvoiceItem Invoice OrderItem Order Customer Part);
56

  
57
  $customer     = SL::DB::Customer->new(
58
    name        => 'Test Customer',
59
    currency_id => $currency_id,
60
    taxzone_id  => $tax_zone->id,
61
    %{ $params{customer} }
62
  )->save;
63

  
64
  $part = SL::DB::Part->new(
65
    partnumber         => 'T4254',
66
    description        => 'Fourty-two fifty-four',
67
    lastcost           => 222.22,
68
    sellprice          => 333.33,
69
    buchungsgruppen_id => $buchungsgruppe->id,
70
    unit               => $unit->name,
71
    %{ $params{part} }
72
  )->save;
73
  $part->load;
74

  
75
  $order                     = SL::DB::Order->new(
76
    customer_id              => $customer->id,
77
    currency_id              => $currency_id,
78
    taxzone_id               => $tax_zone->id,
79
    transaction_description  => '<%period_start_date%>',
80
    transdate                => DateTime->from_kivitendo('01.03.2014'),
81
    orderitems               => [
82
      { parts_id             => $part->id,
83
        description          => $part->description,
84
        lastcost             => $part->lastcost,
85
        sellprice            => $part->sellprice,
86
        qty                  => 1,
87
        unit                 => $unit->name,
88
        %{ $params{orderitem} },
89
      },
90
    ],
91
    periodic_invoices_config => $params{periodic_invoices_config} ? {
92
      active                 => 1,
93
      ar_chart_id            => $ar_chart->id,
94
      %{ $params{periodic_invoices_config} },
95
    } : undef,
96
    %{ $params{order} },
97
  );
98

  
99
  $order->calculate_prices_and_taxes;
100

  
101
  ok($order->save(cascade => 1));
102

  
103
  $::form = Form->new('');
104
  $ctrl   = SL::Controller::FinancialControllingReport->new;
105

  
106
  $ctrl->orders($ctrl->models->get);
107
  $ctrl->calculate_data;
108
}
109

  
110
my @columns = qw(net_amount         other_amount
111
                 delivered_amount   billed_amount   paid_amount   billable_amount
112
                 delivered_amount_p billed_amount_p paid_amount_p billable_amount_p);
113

  
114
sub run_tests {
115
  my ($msg, $num_orders, $values, %order_params) = @_;
116

  
117
  create_sales_order(%order_params);
118

  
119
  is($num_orders, scalar @{ $ctrl->orders }, "${msg}, #orders");
120
  is_deeply([ map { ($ctrl->orders->[0]->{$_} // 0) * 1 } @columns ],
121
            $values,
122
            "${msg}, values");
123
}
124

  
125
init_common_state();
126

  
127
# ----------------------------------------------------------------------
128
# An order without periodic invoices:
129
run_tests("no periodic conf", 1, [ 333.33, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]);
130

  
131
# ----------------------------------------------------------------------
132
# order_value_periodicity=y, periodicity=q
133

  
134
run_tests(
135
  "periodic conf p=q ovp=y, starting in previous year", 1,
136
  [ 333.33, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
137
  periodic_invoices_config  => {
138
    periodicity             => 'q',
139
    order_value_periodicity => 'y',
140
    start_date              => DateTime->from_kivitendo('01.05.2013'),
141
  });
142

  
143
run_tests(
144
  "periodic conf p=q ovp=y, starting and ending in previous year", 1,
145
  [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
146
  periodic_invoices_config  => {
147
    periodicity             => 'q',
148
    order_value_periodicity => 'y',
149
    terminated              => 1,
150
    start_date              => DateTime->from_kivitendo('01.05.2013'),
151
    end_date                => DateTime->from_kivitendo('01.12.2013'),
152
  });
153

  
154
run_tests(
155
  "periodic conf p=q ovp=y, starting in next year", 1,
156
  [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
157
  periodic_invoices_config  => {
158
    periodicity             => 'q',
159
    order_value_periodicity => 'y',
160
    start_date              => DateTime->from_kivitendo('01.01.2015'),
161
  });
162

  
163
run_tests(
164
  "periodic conf p=q ovp=y, starting January 1st of current year", 1,
165
  [ 333.33, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
166
  periodic_invoices_config  => {
167
    periodicity             => 'q',
168
    order_value_periodicity => 'y',
169
    start_date              => DateTime->from_kivitendo('01.01.2014'),
170
  });
171

  
172
run_tests(
173
  "periodic conf p=q ovp=y, starting July 1st of current year", 1,
174
  [ 166.665, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
175
  periodic_invoices_config  => {
176
    periodicity             => 'q',
177
    order_value_periodicity => 'y',
178
    start_date              => DateTime->from_kivitendo('01.07.2014'),
179
  });
180

  
181
run_tests(
182
  "periodic conf p=q ovp=y, starting May 1st of current year", 1,
183
  [ 249.9975, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
184
  periodic_invoices_config  => {
185
    periodicity             => 'q',
186
    order_value_periodicity => 'y',
187
    start_date              => DateTime->from_kivitendo('01.05.2014'),
188
  });
189

  
190
run_tests(
191
  "periodic conf p=q ovp=y, starting January 1st of current year, ending June 30", 1,
192
  [ 166.665, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
193
  periodic_invoices_config  => {
194
    periodicity             => 'q',
195
    order_value_periodicity => 'y',
196
    start_date              => DateTime->from_kivitendo('01.01.2014'),
197
    end_date                => DateTime->from_kivitendo('30.06.2014'),
198
    terminated              => 1,
199
  });
200

  
201
run_tests(
202
  "periodic conf p=q ovp=y, starting July 1st of current year, ending November 30", 1,
203
  [ 166.665, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
204
  periodic_invoices_config  => {
205
    periodicity             => 'q',
206
    order_value_periodicity => 'y',
207
    start_date              => DateTime->from_kivitendo('01.07.2014'),
208
    end_date                => DateTime->from_kivitendo('30.11.2014'),
209
    terminated              => 1,
210
  });
211

  
212
run_tests(
213
  "periodic conf p=q ovp=y, starting May 1st of current year, ending next year", 1,
214
  [ 249.9975, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
215
  periodic_invoices_config  => {
216
    periodicity             => 'q',
217
    order_value_periodicity => 'y',
218
    start_date              => DateTime->from_kivitendo('01.05.2014'),
219
    end_date                => DateTime->from_kivitendo('30.06.2015'),
220
    terminated              => 1,
221
  });
222

  
223
run_tests(
224
  "periodic conf p=q ovp=y, starting November 1 in previous year, ending April 30", 1,
225
  [ 83.3325, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
226
  periodic_invoices_config  => {
227
    periodicity             => 'q',
228
    order_value_periodicity => 'y',
229
    terminated              => 1,
230
    start_date              => DateTime->from_kivitendo('01.11.2013'),
231
    end_date                => DateTime->from_kivitendo('30.04.2014'),
232
  });
233

  
234

  
235
# ----------------------------------------------------------------------
236
# order_value_periodicity=y, periodicity=m
237

  
238
run_tests(
239
  "periodic conf p=m ovp=y, starting in previous year", 1,
240
  [ 333.33, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
241
  periodic_invoices_config  => {
242
    periodicity             => 'm',
243
    order_value_periodicity => 'y',
244
    start_date              => DateTime->from_kivitendo('01.05.2013'),
245
  });
246

  
247
run_tests(
248
  "periodic conf p=m ovp=y, starting and ending in previous year", 1,
249
  [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
250
  periodic_invoices_config  => {
251
    periodicity             => 'm',
252
    order_value_periodicity => 'y',
253
    terminated              => 1,
254
    start_date              => DateTime->from_kivitendo('01.05.2013'),
255
    end_date                => DateTime->from_kivitendo('01.12.2013'),
256
  });
257

  
258
run_tests(
259
  "periodic conf p=m ovp=y, starting in next year", 1,
260
  [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
261
  periodic_invoices_config  => {
262
    periodicity             => 'm',
263
    order_value_periodicity => 'y',
264
    start_date              => DateTime->from_kivitendo('01.01.2015'),
265
  });
266

  
267
run_tests(
268
  "periodic conf p=m ovp=y, starting January 1st of current year", 1,
269
  [ 333.33, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
270
  periodic_invoices_config  => {
271
    periodicity             => 'm',
272
    order_value_periodicity => 'y',
273
    start_date              => DateTime->from_kivitendo('01.01.2014'),
274
  });
275

  
276
run_tests(
277
  "periodic conf p=m ovp=y, starting July 1st of current year", 1,
278
  [ 166.665, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
279
  periodic_invoices_config  => {
280
    periodicity             => 'm',
281
    order_value_periodicity => 'y',
282
    start_date              => DateTime->from_kivitendo('01.07.2014'),
283
  });
284

  
285
run_tests(
286
  "periodic conf p=m ovp=y, starting May 1st of current year", 1,
287
  [ 222.22, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
288
  periodic_invoices_config  => {
289
    periodicity             => 'm',
290
    order_value_periodicity => 'y',
291
    start_date              => DateTime->from_kivitendo('01.05.2014'),
292
  });
293

  
294
run_tests(
295
  "periodic conf p=m ovp=y, starting January 1st of current year, ending June 30", 1,
296
  [ 166.665, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
297
  periodic_invoices_config  => {
298
    periodicity             => 'm',
299
    order_value_periodicity => 'y',
300
    start_date              => DateTime->from_kivitendo('01.01.2014'),
301
    end_date                => DateTime->from_kivitendo('30.06.2014'),
302
    terminated              => 1,
303
  });
304

  
305
run_tests(
306
  "periodic conf p=m ovp=y, starting July 1st of current year, ending November 30", 1,
307
  [ 138.8875, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
308
  periodic_invoices_config  => {
309
    periodicity             => 'm',
310
    order_value_periodicity => 'y',
311
    start_date              => DateTime->from_kivitendo('01.07.2014'),
312
    end_date                => DateTime->from_kivitendo('30.11.2014'),
313
    terminated              => 1,
314
  });
315

  
316
run_tests(
317
  "periodic conf p=m ovp=y, starting May 1st of current year, ending next year", 1,
318
  [ 222.22, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
319
  periodic_invoices_config  => {
320
    periodicity             => 'm',
321
    order_value_periodicity => 'y',
322
    start_date              => DateTime->from_kivitendo('01.05.2014'),
323
    end_date                => DateTime->from_kivitendo('30.06.2015'),
324
    terminated              => 1,
325
  });
326

  
327
run_tests(
328
  "periodic conf p=m ovp=y, starting November 1 in previous year, ending April 30", 1,
329
  [ 111.11, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
330
  periodic_invoices_config  => {
331
    periodicity             => 'm',
332
    order_value_periodicity => 'y',
333
    terminated              => 1,
334
    start_date              => DateTime->from_kivitendo('01.11.2013'),
335
    end_date                => DateTime->from_kivitendo('30.04.2014'),
336
  });
337

  
338

  
339
# ----------------------------------------------------------------------
340
# order_value_periodicity=y, periodicity=q
341

  
342
run_tests(
343
  "periodic conf p=q ovp=2, starting in previous year", 1,
344
  [ 166.665, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
345
  periodic_invoices_config  => {
346
    periodicity             => 'q',
347
    order_value_periodicity => '2',
348
    start_date              => DateTime->from_kivitendo('01.05.2013'),
349
  });
350

  
351
run_tests(
352
  "periodic conf p=q ovp=2, starting and ending in previous year", 1,
353
  [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
354
  periodic_invoices_config  => {
355
    periodicity             => 'q',
356
    order_value_periodicity => '2',
357
    terminated              => 1,
358
    start_date              => DateTime->from_kivitendo('01.05.2013'),
359
    end_date                => DateTime->from_kivitendo('01.12.2013'),
360
  });
361

  
362
run_tests(
363
  "periodic conf p=q ovp=2, starting in next year", 1,
364
  [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
365
  periodic_invoices_config  => {
366
    periodicity             => 'q',
367
    order_value_periodicity => '2',
368
    start_date              => DateTime->from_kivitendo('01.01.2015'),
369
  });
370

  
371
run_tests(
372
  "periodic conf p=q ovp=2, starting January 1st of current year", 1,
373
  [ 166.665, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
374
  periodic_invoices_config  => {
375
    periodicity             => 'q',
376
    order_value_periodicity => '2',
377
    start_date              => DateTime->from_kivitendo('01.01.2014'),
378
  });
379

  
380
run_tests(
381
  "periodic conf p=q ovp=2, starting July 1st of current year", 1,
382
  [ 83.3325, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
383
  periodic_invoices_config  => {
384
    periodicity             => 'q',
385
    order_value_periodicity => '2',
386
    start_date              => DateTime->from_kivitendo('01.07.2014'),
387
  });
388

  
389
run_tests(
390
  "periodic conf p=q ovp=2, starting May 1st of current year", 1,
391
  [ 124.99875, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
392
  periodic_invoices_config  => {
393
    periodicity             => 'q',
394
    order_value_periodicity => '2',
395
    start_date              => DateTime->from_kivitendo('01.05.2014'),
396
  });
397

  
398
run_tests(
399
  "periodic conf p=q ovp=2, starting January 1st of current year, ending June 30", 1,
400
  [ 83.3325, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
401
  periodic_invoices_config  => {
402
    periodicity             => 'q',
403
    order_value_periodicity => '2',
404
    start_date              => DateTime->from_kivitendo('01.01.2014'),
405
    end_date                => DateTime->from_kivitendo('30.06.2014'),
406
    terminated              => 1,
407
  });
408

  
409
run_tests(
410
  "periodic conf p=q ovp=2, starting July 1st of current year, ending November 30", 1,
411
  [ 83.3325, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
412
  periodic_invoices_config  => {
413
    periodicity             => 'q',
414
    order_value_periodicity => '2',
415
    start_date              => DateTime->from_kivitendo('01.07.2014'),
416
    end_date                => DateTime->from_kivitendo('30.11.2014'),
417
    terminated              => 1,
418
  });
419

  
420
run_tests(
421
  "periodic conf p=q ovp=2, starting May 1st of current year, ending next year", 1,
422
  [ 124.99875, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
423
  periodic_invoices_config  => {
424
    periodicity             => 'q',
425
    order_value_periodicity => '2',
426
    start_date              => DateTime->from_kivitendo('01.05.2014'),
427
    end_date                => DateTime->from_kivitendo('30.06.2015'),
428
    terminated              => 1,
429
  });
430

  
431
run_tests(
432
  "periodic conf p=q ovp=2, starting November 1 in previous year, ending April 30", 1,
433
  [ 41.66625, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
434
  periodic_invoices_config  => {
435
    periodicity             => 'q',
436
    order_value_periodicity => '2',
437
    terminated              => 1,
438
    start_date              => DateTime->from_kivitendo('01.11.2013'),
439
    end_date                => DateTime->from_kivitendo('30.04.2014'),
440
  });
441

  
442

  
443

  
444
# ----------------------------------------------------------------------
445
# order_value_periodicity=m, periodicity=b
446

  
447
run_tests(
448
  "periodic conf p=b ovp=m, starting in previous year", 1,
449
  [ 3999.96, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
450
  periodic_invoices_config  => {
451
    periodicity             => 'b',
452
    order_value_periodicity => 'm',
453
    start_date              => DateTime->from_kivitendo('01.05.2013'),
454
  });
455

  
456
run_tests(
457
  "periodic conf p=b ovp=m, starting and ending in previous year", 1,
458
  [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
459
  periodic_invoices_config  => {
460
    periodicity             => 'b',
461
    order_value_periodicity => 'm',
462
    terminated              => 1,
463
    start_date              => DateTime->from_kivitendo('01.05.2013'),
464
    end_date                => DateTime->from_kivitendo('01.12.2013'),
465
  });
466

  
467
run_tests(
468
  "periodic conf p=b ovp=m, starting in next year", 1,
469
  [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
470
  periodic_invoices_config  => {
471
    periodicity             => 'b',
472
    order_value_periodicity => 'm',
473
    start_date              => DateTime->from_kivitendo('01.01.2015'),
474
  });
475

  
476
run_tests(
477
  "periodic conf p=b ovp=m, starting January 1st of current year", 1,
478
  [ 3999.96, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
479
  periodic_invoices_config  => {
480
    periodicity             => 'b',
481
    order_value_periodicity => 'm',
482
    start_date              => DateTime->from_kivitendo('01.01.2014'),
483
  });
484

  
485
run_tests(
486
  "periodic conf p=b ovp=m, starting July 1st of current year", 1,
487
  [ 1999.98, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
488
  periodic_invoices_config  => {
489
    periodicity             => 'b',
490
    order_value_periodicity => 'm',
491
    start_date              => DateTime->from_kivitendo('01.07.2014'),
492
  });
493

  
494
run_tests(
495
  "periodic conf p=b ovp=m, starting May 1st of current year", 1,
496
  [ 3999.96, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
497
  periodic_invoices_config  => {
498
    periodicity             => 'b',
499
    order_value_periodicity => 'm',
500
    start_date              => DateTime->from_kivitendo('01.05.2014'),
501
  });
502

  
503
run_tests(
504
  "periodic conf p=b ovp=m, starting January 1st of current year, ending June 30", 1,
505
  [ 1999.98, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
506
  periodic_invoices_config  => {
507
    periodicity             => 'b',
508
    order_value_periodicity => 'm',
509
    start_date              => DateTime->from_kivitendo('01.01.2014'),
510
    end_date                => DateTime->from_kivitendo('30.06.2014'),
511
    terminated              => 1,
512
  });
513

  
514
run_tests(
515
  "periodic conf p=b ovp=m, starting July 1st of current year, ending November 30", 1,
516
  [ 1999.98, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
517
  periodic_invoices_config  => {
518
    periodicity             => 'b',
519
    order_value_periodicity => 'm',
520
    start_date              => DateTime->from_kivitendo('01.07.2014'),
521
    end_date                => DateTime->from_kivitendo('30.11.2014'),
522
    terminated              => 1,
523
  });
524

  
525
run_tests(
526
  "periodic conf p=b ovp=m, starting May 1st of current year, ending next year", 1,
527
  [ 3999.96, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
528
  periodic_invoices_config  => {
529
    periodicity             => 'b',
530
    order_value_periodicity => 'm',
531
    start_date              => DateTime->from_kivitendo('01.05.2014'),
532
    end_date                => DateTime->from_kivitendo('30.06.2015'),
533
    terminated              => 1,
534
  });
535

  
536
run_tests(
537
  "periodic conf p=b ovp=m, starting November 1 in previous year, ending April 30", 1,
538
  [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
539
  periodic_invoices_config  => {
540
    periodicity             => 'b',
541
    order_value_periodicity => 'm',
542
    terminated              => 1,
543
    start_date              => DateTime->from_kivitendo('01.11.2013'),
544
    end_date                => DateTime->from_kivitendo('30.04.2014'),
545
  });
546

  
547

  
548
done_testing();

Auch abrufbar als: Unified diff