/
Upgrade_Tests.pm
1244 lines (1051 loc) · 42.1 KB
/
Upgrade_Tests.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package LedgerSMB::Upgrade_Tests;
=head1 NAME
LedgerSMB::Upgrade_Tests - Upgrade tests for LedgerSMB
=head1 SYNPOPSIS
TODO
=head1 DESCRIPTION
This module has a single function that returns upgrade tests.
=cut
use strict;
use warnings;
use Moose;
use Moose::Util::TypeConstraints;
use namespace::autoclean;
use List::Util qw( first );
use LedgerSMB::Locale qw(marktext);
=head1 FUNCTIONS
=over
=item get_tests()
Returns the test array
=cut
sub get_tests {
my ($self) = @_;
my @tests = $self->_get_tests;
return @tests;
}
=item get_by_name($name)
Returns the test object with the name.
=cut
sub get_by_name {
my ($self, $name) = @_;
return first { $_->name eq $name } $self->_get_tests;
}
=back
=head1 TEST DEFINITION
Each test is a Moose object with the following properties (optional ones marked
as such).
=over
=item name
Name of the test
=cut
has name => (is => 'ro', isa => 'Str', required => 1);
=item min_version
The first version to run this against
=cut
has min_version => (is => 'ro', isa => 'Str', required => 1);
=item max_version
The maximum version to run this against
=cut
has max_version => (is => 'ro', isa => 'Str', required => 1);
=item appname
The appname of the application the test belongs to.
Can currently be 'ledgersmb' or 'sql-leder'.
=cut
has appname => (is => 'ro', isa => 'Str', required => 1);
=item test_query
Text of the query to run
=cut
has test_query => (is => 'ro', isa => 'Str', required => 1);
=item table
Repair query table to run once per result.
=cut
has table => (is => 'ro', isa => 'Str', required => 0);
=item selectable_values
Hash specifying for each column (identified by the key) which
query to execute to retrieve the values to fill the drop-down with.
Each query needs to return 2 columns: C<text> and C<value>, where
C<value> is the value to be stored in the (fixed) record and
C<text> is the textual value to be presented in the UI.
=cut
has selectable_values => (is => 'ro', isa => 'HashRef', required => 0);
=item force_queries
Array of queries to run on Force. Typically, they will be use to remove missing
or invalid values from tables. For example, removing references to a missing
business discount from the customer and vendor tables. The data is still good
because the discount has been applied but we cannot find the actual values at
the time.
=cut
has force_queries => (is => 'ro', isa => 'ArrayRef', required => 0);
=item insert
Insert data instead of update. This to set defaults on a very limited subset
of tables. Business, for example isn't required in SQL-Ledger but mandatory for
LedgerSMB.
=cut
has insert => (is => 'ro', isa => 'Bool', required => 0, default => 0);
=item id_columns
Repair columns to use as ids
=cut
has id_columns => (is => 'ro', isa => 'ArrayRef[Str]', required => 0,
default => sub { return ['id'] });
=item columns
Repair query columns to run once per result
=cut
has columns => (is => 'ro', isa => 'ArrayRef[Str]', required => 0);
=item display_cols
columns to display on test failures
=cut
has display_cols => (is => 'ro', isa => 'ArrayRef[Str]', required => 1);
=item display_name
Human readable, localized display name
=cut
has display_name => (is => 'ro', isa => 'Str', required => 1);
=item instructions
Human readable instructions for test, localized.
=cut
has instructions => (is => 'ro', isa => 'Str', required => 1);
=item buttons
Enabled buttons
=cut
subtype 'button'
=> as 'Str'
=> where { $_ =~ /Save and Retry|Cancel|Force/ }
=> message { "Invalid button '$_'" };
has buttons => (is => 'ro', isa => 'ArrayRef[button]',
default => sub { return ['Save and Retry', 'Cancel']}, required => 0);
=item tooltips
Tooltip for each button.
Validate that buttons are enabled for each tooltip, then prepend defaults
and override with test specific labeling.
=cut
has tooltips => (is => 'ro',
isa => 'Maybe[HashRef[Str]]', required => 0,
default => undef, # Force initializer call
initializer => sub {
my ( $self, $value, $writer_sub_ref, $attribute_meta ) = @_;
$value //= {};
my %defaults = ('Save and Retry' => marktext('Save the fixes provided and attempt to continue migration'),
'Cancel' => marktext('Cancel the <b>whole migration</b>'));
for my $tooltip (keys %defaults) {
$value->{$tooltip} //= $defaults{$tooltip}
if grep( /^$tooltip/, @{$self->{buttons}});
}
$writer_sub_ref->($value);
}
);
=back
=head1 Methods
=over
=item run($dbh, $cb)
Runs the verification query against the C<$dbh>, calling the callback C<$cb>
with these arguments on failure: C<$self>, C<$dbh>, C<$sth>.
Returns a falsish value on failure or trueish on success.
=cut
sub run {
my ($self, $dbh, $cb) = @_;
my $sth = $dbh->prepare($self->test_query)
or die $dbh->errstr;
$sth->execute()
or die 'Failed to execute pre-migration check ' . $self->name . ', ' . $sth->errstr;
if ($sth->rows > 0) {
$cb->($self, $dbh, $sth);
return 0;
}
return 1;
}
=item fix($dbh, $fix_values)
Applies data fixes. Intended to be used to resolve data-issues reported to
the callback C<$cb> of the C<run> method.
C<$fix_values> is an arrayref holding hashrefs with the keys being the names
of the columns and the values the data to be applied for that column. Columns
listed in C<id_columns> must be part of the data supplied.
=cut
sub fix {
my ($self, $dbh, $fixes) = @_;
my $table = $dbh->quote_identifier($self->table);
my $query;
my @bind_columns;
if ($self->insert) {
my $columns =
join ', ',
map { $dbh->quote_identifier($_) } @{$self->columns};
my $values =
join ', ', map { '?' } @{$self->columns};
$query = qq{INSERT INTO $table ($columns) VALUES ($values)};
@bind_columns = @{$self->columns};
}
else {
my $setters =
join ', ',
map { $dbh->quote_identifier($_) . ' = ?' } @{$self->columns};
$query = qq{UPDATE $table SET $setters WHERE }
. join(' AND ',
map { "$_ = ?" }
map { $dbh->quote_identifier($_) }
@{$self->id_columns});
@bind_columns = (@{$self->columns}, @{$self->id_columns});
}
my $sth = $dbh->prepare($query)
or die "Failed to compile query ($query) to apply fixes: " . $dbh->errstr;
for my $row (@$fixes) {
my $rv = $sth->execute(map { $row->{$_} } @bind_columns);
if (not $rv) {
die "Failed to execute data fix query for $self->{name}: " . $sth->errstr;
}
if ($rv != 1) {
die "Upgrade query affected $rv rows while a single row was expected";
}
}
$sth->finish;
$dbh->commit;
}
=item force($dbh)
=cut
sub force {
my ($self, $dbh) = @_;
for my $force_query ( @{$self->{force_queries}}) {
$dbh->do($force_query)
or die q{Failed to run 'force' data cleaning query};
}
$dbh->commit;
return;
}
=item query_selectable_values($dbh)
Returns an arrayref with the keys being the names of the columns and the
values arrays of hashes. Each hash has two keys (C<text> and C<value>);
the C<value>s are the allowable values for the given column in C<$fix_values>
when calling C<fix()>.
=cut
sub query_selectable_values {
my ($self, $dbh) = @_;
return {} unless $self->selectable_values;
my %query_values;
for my $column (@{$self->columns // []}) {
my $query = $self->selectable_values->{$column};
next unless $query;
my $sth = $dbh->prepare($query)
or die 'Invalid query for drop-down data in ' . $self->name;
$sth->execute()
or die 'Failed to query for drop-down data in ' . $self->name;
$query_values{$column} = $sth->fetchall_arrayref({});
}
return \%query_values;
}
sub _get_tests {
my ($request) = @_;
my @tests;
# 1.2-1.3 tests
push @tests, __PACKAGE__->new(
test_query =>
q{select count(*) as customer_count
from customer
where (select count(*)
from chart
where 'AR' = ANY(string_to_array(link,':'))) > 0
having count(*) = 0},
display_name => marktext('AR account available when customers defined'),
instructions => marktext(
q(When customers are defined, an AR account must be defined,
however, your setup doesn't. Please go back and define one.)),
name => 'customers_require_ar',
display_cols => [],
columns => [],
table => 'customer',
appname => 'ledgersmb',
min_version => '1.2',
max_version => '1.2'
);
push @tests, __PACKAGE__->new(
test_query =>
q{select count(*) as vendor_count
from vendor
where (select count(*)
from chart
where 'AP' = ANY(string_to_array(link,':'))) > 0
having count(*) = 0},
display_name => marktext('AP account available when vendors defined'),
instructions => marktext(
q(When vendors are defined, an AP account must be defined,
however, your setup doesn't. Please go back and define one.)),
name => 'vendors_require_ap',
display_cols => [],
columns => [],
table => 'vendor',
appname => 'ledgersmb',
min_version => '1.2',
max_version => '1.2'
);
push @tests, __PACKAGE__->new(
test_query =>
'select id, customernumber, name, address1, city, state, zipcode
from customer where customernumber in
(SELECT customernumber from customer
GROUP BY customernumber
HAVING count(*) > 1)',
display_name => marktext('Unique Customernumber'),
instructions => marktext(
'Please make all customer numbers unique'),
name => 'unique_customernumber',
display_cols => ['customernumber', 'name', 'address1', 'city', 'state', 'zip'],
columns => ['customernumber'],
table => 'customer',
appname => 'ledgersmb',
min_version => '1.2',
max_version => '1.2'
);
push @tests, __PACKAGE__->new(
test_query =>
'select id, vendornumber, name, address1, city, state, zipcode
from vendor where vendornumber in
(SELECT vendornumber from vendor
GROUP BY vendornumber
HAVING count(*) > 1)',
display_name => marktext('Unique Vendornumber'),
instructions => marktext(
'Please make all vendor numbers unique'),
name => 'unique_vendornumber',
display_cols => ['vendornumber', 'name', 'address1', 'city', 'state', 'zip'],
columns => ['vendornumber'],
table => 'customer',
appname => 'ledgersmb',
min_version => '1.2',
max_version => '1.2'
);
push @tests, __PACKAGE__->new(
test_query => 'SELECT * FROM employee WHERE employeenumber IS NULL',
display_name => marktext('No Null employeenumber'),
instructions => marktext(
'Enter employee numbers where they are missing'),
name => 'null_employeenumber',
display_cols => ['login', 'name', 'employeenumber'],
columns => ['employeenumber'],
table => 'employee',
appname => 'ledgersmb',
min_version => '1.2',
max_version => '1.2'
);
push @tests, __PACKAGE__->new(
test_query => q{SELECT login, name, employeenumber FROM employee
WHERE not name ~ '[[:alnum:]_]'::text},
name => 'minimal_employee_name_requirements',
display_name => marktext('Employee name doesn\'t meet minimal requirements (e.g. non-empty, alphanumeric)'),
instructions => marktext(
'Make sure every name consists of alphanumeric characters (and underscores) only and is at least one character long'),
display_cols => ['login', 'name', 'employeenumber'],
columns => ['name'],
table => 'employee',
appname => 'ledgersmb',
min_version => '1.2',
max_version => '1.2'
);
push @tests, __PACKAGE__->new(
test_query => 'SELECT login, name, employeenumber FROM employee
WHERE employeenumber IN
(SELECT employeenumber FROM employee
GROUP BY employeenumber
HAVING count(*) > 1)',
name => 'duplicate_employee_numbers',
display_name => marktext('Duplicate employee numbers'),
instructions => marktext(
'Make employee numbers unique'),
display_cols => ['login', 'name', 'employeenumber'],
columns => ['employeenumber'],
table => 'employee',
appname => 'ledgersmb',
min_version => '1.2',
max_version => '1.2'
);
push @tests, __PACKAGE__->new(
test_query => 'select partnumber, description, sellprice
from parts where obsolete is not true
and partnumber in
(select partnumber from parts
WHERE obsolete is not true
group by partnumber having count(*) > 1)
order by partnumber',
name => 'duplicate_partnumbers',
display_name => marktext('Unique nonobsolete partnumbers'),
instructions => marktext(
'Make non-obsolete partnumbers unique'),
display_cols => ['partnumber', 'description', 'sellprice'],
columns => ['partnumber'],
table => 'parts',
appname => 'ledgersmb',
min_version => '1.2',
max_version => '1.2'
);
push @tests, __PACKAGE__->new(
test_query => 'SELECT invnumber, transdate, amount, netamount, paid
from ar where invnumber in (
select invnumber from ar
group by invnumber having count(*) > 1)',
display_name => marktext('Unique AR Invoice numbers'),
instructions => marktext(
'Make invoice numbers unique'),
name => 'unique_ar_invnumbers',
display_cols => ['invnumber', 'transdate', 'amount', 'netamount', 'paid'],
columns => ['invnumber'],
table => 'ar',
appname => 'ledgersmb',
min_version => '1.2',
max_version => '1.2',
);
# New tests in 1.4
push @tests, __PACKAGE__->new(
test_query => 'select trans_id, chart_id, transdate
from acc_trans WHERE amount IS NULL',
display_name => marktext('No NULL Amounts'),
name => 'no_null_ac_amounts',
display_cols => ['trans_id', 'chart_id', 'transdate'],
id_columns => ['trans_id'],
instructions => marktext(
'There are NULL values in the amounts column of your
source database. Please either find professional help to migrate your
database, or delete the offending rows through PgAdmin III or psql'),
appname => 'ledgersmb',
min_version => '1.2',
max_version => '1.3'
);
push @tests, __PACKAGE__->new(
test_query => 'select meta_number, class, description, name, eca.id as id
from entity_credit_account eca
join entity_class ec on eca.entity_class = ec.id
join entity e on eca.entity_id = e.id
where exists
(select meta_number from entity_credit_account eca2
where eca.meta_number = eca2.meta_number
and eca.entity_class = eca2.entity_class
group by meta_number having count(*) > 1)
order by meta_number',
display_name => marktext('No duplicate meta_numbers'),
name => 'no_meta_number_dupes',
display_cols => [ 'meta_number', 'class', 'description', 'name' ],
columns => ['meta_number'],
table => 'entity_credit_account',
instructions => marktext('Make sure all meta numbers are unique.'),
appname => 'ledgersmb',
min_version => '1.3',
max_version => '1.3'
);
push @tests, __PACKAGE__->new(
test_query => q{select distinct gifi_accno from chart
where not exists (select 1
from gifi
where gifi.accno = chart.gifi_accno)
and gifi_accno is not null
and gifi_accno !~ '^\s*$'},
display_name => marktext('GIFI accounts not in "gifi" table'),
name => 'missing_gifi_table_rows',
display_cols => [ 'gifi_accno' ],
table => 'chart',
instructions => marktext('Please use the 1.2 UI to add the GIFI accounts'),
appname => 'ledgersmb',
min_version => '1.2',
max_version => '1.2'
);
push @tests, __PACKAGE__->new(
test_query =>
q{select count(*) as customer_count
from customer
where (select count(*)
from chart
where 'AR' = ANY(string_to_array(link,':'))) > 0
having count(*) = 0},
display_name => marktext('AR account available when customers defined'),
instructions => marktext(
q(When customers are defined, an AR account must be defined,
however, your setup doesn't. Please go back and define one.)),
name => 'customers_require_ar',
display_cols => [],
columns => [],
table => 'customer',
appname => 'sql-ledger',
min_version => '2.7',
max_version => '3.0'
);
push @tests, __PACKAGE__->new(
test_query =>
q{select count(*) as vendor_count
from vendor
where (select count(*)
from chart
where 'AP' = ANY(string_to_array(link,':'))) > 0
having count(*) = 0},
display_name => marktext('AP account available when vendors defined'),
instructions => marktext(
q(When vendors are defined, an AP account must be defined,
however, your setup doesn't. Please go back and define one.)),
name => 'vendors_require_ap',
display_cols => [],
columns => [],
table => 'vendor',
appname => 'ledgersmb',
min_version => '2.7',
max_version => '3.0'
);
push @tests, __PACKAGE__->new(
test_query => q{select distinct gifi_accno as accno from chart
where not exists (select 1
from gifi
where gifi.accno = chart.gifi_accno)
and gifi_accno is not null
and charttype <> 'H'
and gifi_accno !~ '^\s*$'},
display_name => marktext('GIFI accounts not in "gifi" table'),
name => 'missing_gifi_table_rows',
display_cols => [ 'accno', 'description' ],
table => 'gifi',
columns => ['description'],
id_columns => ['accno'],
instructions => marktext('Please add the missing GIFI accounts'),
appname => 'sql-ledger',
min_version => '2.7',
max_version => '3.0'
);
push @tests, __PACKAGE__->new(
test_query => q{select distinct gifi_accno from account
where not exists (select 1
from gifi
where gifi.accno = account.gifi_accno)
and gifi_accno is not null
and gifi_accno !~ '^\s*$'},
display_name => marktext('GIFI accounts not in "gifi" table'),
name => 'missing_gifi_table_rows',
display_cols => [ 'gifi_accno' ],
table => 'account',
instructions => marktext('Please use the 1.3 UI to add the GIFI accounts'),
appname => 'ledgersmb',
min_version => '1.3',
max_version => '1.3'
);
push @tests, __PACKAGE__->new(
test_query => q{select chart_id, account
from cr_coa_to_account ccta
where chart_id in (select crcoa.chart_id
from cr_coa_to_account crcoa
where ccta.chart_id = crcoa.chart_id
group by crcoa.chart_id
having count(crcoa.chart_id) > 1)},
display_name => marktext('Accounts marked for recon -- once'),
name => 'non_duplicate_recon_accounts_marker',
display_cols => [ 'chart_id', 'account' ],
table => 'cr_coa_to_account',
instructions => marktext('Please use pgAdmin3 or psql to remove the duplicates'),
appname => 'ledgersmb',
min_version => '1.3',
max_version => '1.3'
);
push @tests, __PACKAGE__->new(
test_query => q{select chart_id, account
from cr_coa_to_account ccta
where not exists (select 1
from account
where account.id = ccta.chart_id)},
display_name => marktext('Accounts marked for recon exist'),
name => 'recon_accounts_exist',
display_cols => [ 'chart_id', 'account' ],
table => 'cr_coa_to_account',
instructions => marktext(q(Please use pgAdmin3 or psql to look up the 'chart_id' value in the 'account' table and change it to an existing value)),
appname => 'ledgersmb',
min_version => '1.3',
max_version => '1.3'
);
push @tests, __PACKAGE__->new(
test_query => q{select name, contact from customer
where arap_accno_id is null
order by name},
display_name => marktext('Empty AR account'),
name => 'no_null_ar_accounts',
display_cols => [ 'name', 'contact' ],
instructions => marktext("Please go into the SQL-Ledger UI and correct the empty AR accounts"),
appname => 'sql-ledger',
min_version => '2.7',
max_version => '3.0'
);
push @tests, __PACKAGE__->new(
test_query => q{select name, contact from vendor
where arap_accno_id is null
order by name},
display_name => marktext('Empty AP account'),
name => 'no_null_ap_accounts',
display_cols => [ 'name', 'contact' ],
instructions => marktext("Please go into the SQL-Ledger UI and correct the empty AP accounts"),
appname => 'sql-ledger',
min_version => '2.7',
max_version => '3.0'
);
push @tests,__PACKAGE__->new(
test_query => q{ select category, accno, description
from chart
where charttype = 'A'
and category not in ('A', 'L', 'Q', 'I', 'E')},
display_name => marktext('Unsupported account categories'),
name => 'unsupported_account_types',
display_cols => ['category', 'accno', 'description'],
instructions => marktext(
'Please make sure all accounts have a category of
(A)sset, (L)iability, e(Q)uity, (I)ncome or (E)xpense.'),
columns => ['category'],
table => 'chart',
appname => 'sql-ledger',
min_version => '2.7',
max_version => '3.0'
);
push @tests,__PACKAGE__->new(
test_query => q{select accno, description, link
from chart
where charttype = 'A'
and link ~ '(^|:)(AR|AP|IC)(:|\$)'
and link ~ '(AR|AP|IC)[^:]'},
display_name => marktext('Unsupported account link combinations'),
name => 'unsupported_account_links',
display_cols => ['accno', 'description', 'link'],
instructions => marktext(
'An account can either be a summary account (which have a
link of "AR", "AP" or "IC" value) or be linked to dropdowns (having any
number of "AR_*", "AP_*" and/or "IC_*" links concatenated by colons (:).'),
columns => ['link'],
table => 'chart',
appname => 'sql-ledger',
min_version => '2.7',
max_version => '3.0'
);
push @tests,__PACKAGE__->new(
test_query => q{select accno, description, link
from chart c
where charttype = 'A'
and 0 = (select count(*)
from chart cn
where cn.charttype = 'H'
and cn.accno < c.accno)},
display_name => marktext('Accounts without heading'),
name => 'no_header_accounts',
display_cols => ['accno', 'description', 'link'],
instructions => marktext(
'Please go into the SQL-Ledger UI and create/rename a
heading which sorts alphanumerically before the first account by accno'),
table => 'chart',
appname => 'sql-ledger',
min_version => '2.7',
max_version => '3.0'
);
push @tests,__PACKAGE__->new(
test_query => 'select id, customernumber, name
from customer
where customernumber is null',
display_name => marktext('Empty customernumbers'),
name => 'no_empty_customernumbers',
display_cols => ['customernumber', 'name'],
instructions => marktext(
'Please make sure there are no empty customer numbers.'),
columns => ['customernumber'],
table => 'customer',
appname => 'sql-ledger',
min_version => '2.7',
max_version => '3.0'
);
push @tests,__PACKAGE__->new(
test_query => q{select id, 'auto-business-' || id as description, 0 as discount from (
select distinct id from (
select business_id as id from customer
union select business_id from vendor
) a
where id is not null
and id <> 0
and id not in (select id from business)
order by id
) a},
display_name => marktext('Empty businesses'),
name => 'no_businesses',
display_cols => ['description', 'discount'],
instructions => marktext(
'Undefined businesses.<br>
Please make sure business used by vendors and constomers are defined.<br>
<i><b>Hover on buttons</b> to see their effects and impacts</i>'),
columns => ['description', 'discount'],
table => 'business',
appname => 'sql-ledger',
min_version => '2.7',
max_version => '3.0',
insert => 1,
# They should be constrained
buttons => ['Save and Retry', 'Cancel', 'Force'],
force_queries => ['UPDATE customer SET business_id = NULL
WHERE business_id NOT IN (
SELECT id FROM business);
UPDATE vendor SET business_id = NULL
WHERE business_id NOT IN (
SELECT id FROM business);'],
tooltips => {
'Force' => marktext('This will <b>remove</b> the business references in <u>vendor</u> and <u>customer</u> tables')
}
);
push @tests, __PACKAGE__->new(
test_query => 'SELECT id, name, business_id
FROM vendor
WHERE business_id NOT IN (SELECT id
FROM business)
AND business_id <> 0
ORDER BY name',
display_name => marktext('Vendor not in a business'),
name => 'no_business_for_vendor',
display_cols => ['name', 'business_id'],
columns => ['business_id'],
instructions => marktext(
'LedgerSMB vendors must be assigned to a valid business.<br>
Please review the selection or select the proper business from the list'),
selectable_values => { business_id => q{SELECT concat(description,' -- ',discount) AS text, id as value
FROM business
ORDER BY id}},
table => 'vendor',
appname => 'sql-ledger',
min_version => '2.7',
max_version => '3.0'
);
push @tests, __PACKAGE__->new(
test_query => 'SELECT id, name, business_id
FROM customer
WHERE business_id NOT IN (SELECT id
FROM business)
AND business_id <> 0
ORDER BY name',
display_name => marktext('Customer not in a business'),
name => 'no_business_for_customer',
display_cols => ['name', 'business_id'],
columns => ['business_id'],
instructions => marktext(
'LedgerSMB customers must be assigned to a valid business.<br>
Please review the selection or select the proper business from the list'),
selectable_values => { business_id => q{SELECT concat(description,' -- ',discount) AS text, id as value
FROM business
ORDER BY id}},
table => 'customer',
appname => 'sql-ledger',
min_version => '2.7',
max_version => '3.0'
);
push @tests,__PACKAGE__->new(
test_query => 'select id, customernumber, name
from customer
where customernumber in (select customernumber
from customer
group by customernumber
having count(*) > 1)
order by customernumber',
display_name => marktext('Double customernumbers'),
name => 'no_double_customernumbers',
display_cols => ['customernumber', 'name'],
instructions => marktext(
'Please make all customer numbers unique'),
columns => ['customernumber'],
table => 'customer',
appname => 'sql-ledger',
min_version => '2.7',
max_version => '3.0'
);
push @tests,__PACKAGE__->new(
test_query => 'select id, vendornumber, name
from vendor
where vendornumber is null',
display_name => marktext('Empty vendornumbers'),
name => 'no_empty_vendornumbers',
display_cols => ['vendornumber', 'name'],
instructions => marktext(
'Please make sure there are no empty vendor numbers.'),
columns => ['vendornumber'],
table => 'vendor',
appname => 'sql-ledger',
min_version => '2.7',
max_version => '3.0'
);
push @tests,__PACKAGE__->new(
test_query => 'select id, vendornumber, name
from vendor
where vendornumber in (select vendornumber
from vendor
group by vendornumber
having count(*) > 1)',
display_name => marktext('Double vendornumbers'),
name => 'no_double_vendornumbers',
display_cols => ['vendornumber', 'name'],
instructions => marktext(
'Please make all vendor numbers unique'),
columns => ['vendornumber'],
table => 'vendor',
appname => 'sql-ledger',
min_version => '2.7',
max_version => '3.0'
);
push @tests, __PACKAGE__->new(
test_query => 'select id, login, name, employeenumber
from employee
where employeenumber is null',
display_name => marktext('Null employee numbers'),
name => 'no_null_employeenumbers',
display_cols => ['login', 'name', 'employeenumber'],
instructions => marktext(
'Please make sure all employees have an employee number'),
columns => ['employeenumber'],
table => 'employee',
appname => 'sql-ledger',
min_version => '2.7',
max_version => '3.0'
);
push @tests, __PACKAGE__->new(
test_query => 'select id, login, name, employeenumber
from employee
where employeenumber in (select employeenumber
from employee
group by employeenumber
having count(*) > 1)',
display_name => marktext('Null employee numbers'),
name => 'no_duplicate_employeenumbers',
display_cols => ['login', 'name', 'employeenumber'],
columns => ['employeenumber'],
instructions => marktext(
'Please make all employee numbers unique'),
table => 'employee',
appname => 'sql-ledger',
min_version => '2.7',
max_version => '3.0'
);
push @tests, __PACKAGE__->new(
test_query => 'select id, invnumber, transdate, duedate, datepaid,
ordnumber, quonumber, approved
from ar
where invnumber in (select invnumber
from ar
group by invnumber
having count(*) > 1)
order by invnumber',
display_name => marktext('Non-unique invoice numbers'),
name => 'no_duplicate_ar_invoicenumbers',
display_cols => ['invnumber', 'transdate', 'duedate', 'datepaid',
'ordnumber', 'quonumber', 'approved'],
columns => ['invnumber'],
instructions => marktext(
'Please make all AR invoice numbers unique'),
table => 'ar',
appname => 'sql-ledger',
min_version => '2.7',
max_version => '3.0'
);
# There's no AP uniqueness requirement?
push @tests, __PACKAGE__->new(
test_query => q{SELECT id, concat(invnumber,'-',row_number() over(partition by invnumber order by id)) AS invnumber,
dcn, description, transdate, duedate, datepaid, ordnumber, quonumber, approved