Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision e35b5c40

Von Jan Büren vor fast 9 Jahren hinzugefügt

  • ID e35b5c40b7898c91bcbf517914c3db92d75ac814
  • Vorgänger 6bec8556
  • Nachfolger cd5739ff

Selftests konsequent auf fromdate -> todate umgestellt

Ferner Kosmetik von hässlichen SQL Formatierungen

Unterschiede anzeigen:

SL/BackgroundJob/SelfTest/Transactions.pm
1
package SL::BackgroundJob::SelfTest::Transactions;
1
ackage SL::BackgroundJob::SelfTest::Transactions;
2 2

  
3 3
use utf8;
4 4
use strict;
......
43 43
  my ($self) = @_;
44 44

  
45 45
  # TODO FIXME calc dates better, unless this is wanted
46
  $self->fromdate(DateTime->new(day => 1, month => 1, year => DateTime->today->year));
46
#  my $year =
47
  #$self->fromdate(DateTime->new(day => 1, month => 1, year => DateTime->today->year));
48
  #$self->todate($self->fromdate->clone->add(years => 1)->add(days => -1));
49
  $self->fromdate(DateTime->new(day => 1, month => 1, year => 2015));
47 50
  $self->todate($self->fromdate->clone->add(years => 1)->add(days => -1));
48

  
51
  $main::lxdebug->message(0, 'hier und dort:' . $self->fromdate . ' mit ' . $self->todate);
49 52
  $self->dbh($::form->get_standard_dbh);
50 53
}
51 54

  
......
161 164
  $query = qq| select sum(netamount) from ar where transdate >= ? and transdate <= ? AND invoice; |;
162 165
  my ($netamount_laut_ar) =  selectfirst_array_query($::form, $self->dbh, $query, $self->fromdate, $self->todate);
163 166

  
164
  my $correct = $netamount_laut_invoice - $netamount_laut_ar == 0;
167
  # should be enough to get a diff below 1. We have currently the following issues:
168
  # verkaufsbericht berücksichtigt keinen rabatt
169
  # fxsellprice ist mit mwst-inklusive
170
  my $correct = abs($netamount_laut_invoice - $netamount_laut_ar) < 1;
165 171

  
166 172
  $self->tester->ok($correct, "Summe laut Verkaufsbericht sollte gleich Summe aus Verkauf -> Berichte -> Rechnungen sein");
167 173
  if (!$correct) {
......
265 271

  
266 272
  my $query = qq|
267 273
       select invnumber,paid,amount,transdate,c.customernumber,c.name from ar left join customer c on (ar.customer_id = c.id)
268
     where abs(paid) > abs(amount)
274
       where abs(paid) > abs(amount)
269 275
       AND transdate >= ? and transdate <= ?
270
         order by invnumber;|;
276
       order by invnumber;|;
271 277

  
272 278
  my $overpaids_ar =  selectall_hashref_query($::form, $self->dbh, $query, $self->fromdate, $self->todate);
273 279

  
......
284 290

  
285 291
  my $query = qq|
286 292
      select invnumber,paid,amount,transdate,vc.vendornumber,vc.name from ap left join vendor vc on (ap.vendor_id = vc.id)
287
    where abs(paid) > abs(amount)
293
      where abs(paid) > abs(amount)
288 294
      AND transdate >= ? and transdate <= ?
289
        order by invnumber;|;
295
      order by invnumber;|;
290 296

  
291 297
  my $overpaids_ap =  selectall_hashref_query($::form, $self->dbh, $query, $self->fromdate, $self->todate);
292 298

  
......
302 308
  my ($self) = @_;
303 309

  
304 310
  my $query = qq|
305
    SELECT ar.invnumber,sum(amount - COALESCE((SELECT sum(amount)*-1 FROM acc_trans LEFT JOIN chart ON (acc_trans.chart_id=chart.id) WHERE link ilike '%paid%' AND acc_trans.trans_id=ar.id ),0)) as "open"
311
    SELECT ar.invnumber,sum(amount - COALESCE((SELECT sum(amount)*-1
312
                            FROM acc_trans LEFT JOIN chart ON (acc_trans.chart_id=chart.id)
313
                            WHERE link ilike '%paid%' AND acc_trans.trans_id=ar.id ),0)) as "open"
306 314
    FROM ar, customer
307 315
    WHERE paid != amount
308 316
      AND ar.storno
309 317
      AND (ar.customer_id = customer.id)
310 318
      AND ar.transdate >= ? and ar.transdate <= ?
311
    GROUP BY ar.invnumber;|;
319
    GROUP BY ar.invnumber|;
312 320
  my $paid_stornos = selectall_hashref_query($::form, $self->dbh, $query, $self->fromdate, $self->todate);
313 321

  
314 322
  $self->tester->ok(0 == @$paid_stornos, "Keine bezahlten Stornos");
......
325 333
    FROM ar
326 334
    LEFT JOIN customer c on (c.id = ar.customer_id)
327 335
    WHERE storno_id is null AND storno is true AND ar.id not in (SELECT storno_id FROM ar WHERE storno_id is not null AND storno is true)
336
    AND ar.transdate >= ? and ar.transdate <= ?
328 337
    UNION
329 338
    SELECT (SELECT cast ('ap' as text)) as invoice,ap.id,invnumber,storno,amount,transdate,type,vendornumber as cv_number
330 339
    FROM ap
331 340
    LEFT JOIN vendor v on (v.id = ap.vendor_id)
332
    WHERE storno_id is null AND storno is true AND ap.id not in (SELECT storno_id FROM ap WHERE storno_id is not null AND storno is true);
333
  |;
341
    WHERE storno_id is null AND storno is true AND ap.id not in (SELECT storno_id FROM ap WHERE storno_id is not null AND storno is true)
342
    AND ap.transdate >= ? and ap.transdate <= ?|;
334 343

  
335
  my $stornos_ohne_partner =  selectall_hashref_query($::form, $self->dbh, $query);
344
  my $stornos_ohne_partner =  selectall_hashref_query($::form, $self->dbh, $query, $self->fromdate, $self->todate,
345
                                                                                   $self->fromdate, $self->todate);
336 346

  
337 347
  $self->tester->ok(@$stornos_ohne_partner == 0, 'Es sollte keine Stornos ohne Partner geben');
338 348
  if (@$stornos_ohne_partner) {
339
    $self->tester->diag("Stornos ohne Partner:   (kann passieren wenn Stornorechnung außerhalb Zeitraum liegt)");
340
    $self->tester->diag("gilt aber trotzdem als paid zu dem Zeitpunkt, oder?");
349
    $self->tester->diag("Stornos ohne Partner, oder Storno über Jahreswechsel hinaus");
341 350
  }
342 351
  my $stornoheader = 0;
343 352
  for my $storno (@{ $stornos_ohne_partner }) {
......
356 365
  # geht nur auf wenn acc_trans Zahlungseingänge auch im Untersuchungszeitraum lagen
357 366
  # Stornos werden rausgefiltert
358 367
  my $query = qq|
359
SELECT
360
invnumber,customernumber,name,ar.transdate,ar.datepaid,
361
amount,
362
amount-paid as "open via ar",
363
paid as "paid via ar",
364
coalesce((SELECT sum(amount)*-1 FROM acc_trans LEFT JOIN chart ON (acc_trans.chart_id=chart.id) WHERE link ilike '%paid%' AND acc_trans.trans_id=ar.id AND acc_trans.transdate <= ?),0) as "paid via acc_trans"
365
FROM ar left join customer c on (c.id = ar.customer_id)
366
WHERE
367
 (ar.storno IS FALSE)
368
 AND (transdate <= ? )
369
;|;
370

  
371
  my $invoices = selectall_hashref_query($::form, $self->dbh, $query, $self->todate, $self->todate);
368
    SELECT
369
    invnumber,customernumber,name,ar.transdate,ar.datepaid,
370
    amount,
371
    amount-paid as "open via ar",
372
    paid as "paid via ar",
373
    coalesce((SELECT sum(amount)*-1 FROM acc_trans LEFT JOIN chart ON (acc_trans.chart_id=chart.id)
374
      WHERE link ilike '%paid%' AND acc_trans.trans_id=ar.id AND acc_trans.transdate <= ?),0) as "paid via acc_trans"
375
    FROM ar left join customer c on (c.id = ar.customer_id)
376
    WHERE
377
     ar.storno IS FALSE
378
     AND transdate >= ? AND transdate <= ?|;
379

  
380
  my $invoices = selectall_hashref_query($::form, $self->dbh, $query, $self->todate, $self->fromdate, $self->todate);
372 381

  
373 382
  my $count_overpayments = scalar grep {
374 383
       $_->{"paid via ar"} != $_->{"paid via acc_trans"}
......
437 446
  my $query = qq|
438 447
          select sum(ac.amount) as amount, ar.invnumber,ar.netamount
439 448
          from acc_trans ac left join ar on (ac.trans_id = ar.id)
440
          where ac.chart_link like 'AR_amount%' group by invnumber,netamount having sum(ac.amount) <> ar.netamount|;
449
          WHERE ac.chart_link like 'AR_amount%'
450
          AND ac.transdate >= ? AND ac.transdate <= ?
451
          group by invnumber,netamount having sum(ac.amount) <> ar.netamount|;
441 452

  
442
  my $ar_amount_not_ac_amount = selectall_hashref_query($::form, $self->dbh, $query);
453
  my $ar_amount_not_ac_amount = selectall_hashref_query($::form, $self->dbh, $query, $self->fromdate, $self->todate);
443 454

  
444 455
  if ( scalar @{ $ar_amount_not_ac_amount } > 0 ) {
445 456
    $self->tester->ok(0, "Folgende Ausgangsrechnungen haben einen falschen Netto-Wert im Nebenbuch:");
......
460 471
  my $query = qq|
461 472
          select sum(ac.amount) as amount, ap.invnumber,ap.netamount
462 473
          from acc_trans ac left join ap on (ac.trans_id = ap.id)
463
          where ac.chart_link like 'AR_amount%' group by invnumber,netamount having sum(ac.amount) <> ap.netamount*-1|;
474
          WHERE ac.chart_link like 'AR_amount%'
475
          AND ac.transdate >= ? AND ac.transdate <= ?
476
          group by invnumber,netamount having sum(ac.amount) <> ap.netamount*-1|;
464 477

  
465
  my $ap_amount_not_ac_amount = selectall_hashref_query($::form, $self->dbh, $query);
478
  my $ap_amount_not_ac_amount = selectall_hashref_query($::form, $self->dbh, $query, $self->fromdate, $self->todate);
466 479

  
467 480
  if ( scalar @{ $ap_amount_not_ac_amount } > 0 ) {
468 481
    $self->tester->ok(0, "Folgende Eingangsrechnungen haben einen falschen Netto-Wert im Nebenbuch:");
......
487 500
  my $query = qq| select trans_id, chart.accno,transdate from acc_trans left join chart on (chart.id = acc_trans.chart_id)
488 501
                    WHERE taxkey <> 0 AND trans_id NOT IN
489 502
                    (select trans_id from acc_trans where chart_link ilike '%tax%' and trans_id IN
490
                    (SELECT trans_id from acc_trans where taxkey <> 0))|;
503
                    (SELECT trans_id from acc_trans where taxkey <> 0))
504
                    AND transdate >= ? AND transdate <= ?|;
491 505

  
492
  my $missing_tax_bookings = selectall_hashref_query($::form, $self->dbh, $query);
506
  my $missing_tax_bookings = selectall_hashref_query($::form, $self->dbh, $query, $self->fromdate, $self->todate);
493 507

  
494 508
  if ( scalar @{ $missing_tax_bookings } > 0 ) {
495 509
    $self->tester->ok(0, "Folgende Konten weisen Buchungen ohne Steuer auf:");

Auch abrufbar als: Unified diff