blib/lib/oEdtk/lib/index_Check_tracked_docs.pl untested

filter: Statementstmt 0.0% 0 / 88 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 0.0% 0 / 6 Podpod n/a totaltotal 0.0% 0 / 143 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/perl
2  
3 use strict;
4 use warnings;
5  
6 use oEdtk::Main;
7 use oEdtk::Config qw(config_read);
8 use oEdtk::DBAdmin qw(db_connect);
9  
10 use Date::Calc qw(Today Gmtime Week_of_Year);
11 my $YWWD;
12 {
13 my $time = time;
14 my ( $year, $month, $day, $hour, $min, $sec, $doy, $dow, $dst ) = Gmtime($time);
15 my ( $week, ) = Week_of_Year( $year, $month, $day );
16 $YWWD = sprintf( "%1d%02d%1d", $year % 10, $week, $dow );
17 }
18  
19 if ( @ARGV < 1 or $ARGV[0] =~ /-h/i ) {
20 die "Usage: $0 <today|week|yweek_value|idldoc|ALL> [refiddoc] [SEQLOT|SOURCE|source_name]\n"
21 . "\t week\t\t: number of week in the year \n"
22 . "\t yweek_value\t: number of week in the year as YWW\n"
23 . "\t idldoc\t\t: unique id doc lot (a UUID, or 4 - 16 digits)\n"
24 . "\t source_name\t: job name in tracking\n\n"
25 . " This checks references for tracked sources\n (ie today YWWD = $YWWD)\n\n";
26 }
27  
28 my $period = $ARGV[0] || "today";
29 my $refiddoc = $ARGV[1] || 0;
30 my $lot = $ARGV[2] || 0;
31  
32 my $cfg = config_read('EDTK_STATS');
33 my $dbh = db_connect( $cfg, 'EDTK_DBI_STATS', { AutoCommit => 1, RaiseError => 1 } );
34  
35 ################################################################################
36  
37 #use Date::Calc qw(Today Gmtime Week_of_Year);
38 my $time = time;
39 my ( $year, $month, $day, $hour, $min, $sec, $doy, $dow, $dst ) = Gmtime($time);
40 my ( $week, ) = Week_of_Year( $year, $month, $day );
41 my ( $idldocKey, $select, $sql, $groupby, $orderby, @sql_values );
42  
43 if ( $period =~ /^today$/i ) {
44 $idldocKey = sprintf( "%1d%02d%1d", $year % 10, $week, $dow );
45  
46 }
47 elsif ( $period =~ /^all$/i ) {
48  
49 }
50 elsif ( $period =~ /^(\d{3,15})$/ ) { # references in YWW or idldoc format...
51 $idldocKey = sprintf( "%d", $1 );
52  
53 }
54 elsif ( oe_is_IDLDOC($period) || $period =~ /^[0-9A-Fa-f-]{4,35}$/ ) { # idldoc UUID (S70/D1)...
55 $idldocKey = $period;
56  
57 }
58 elsif ( $period =~ /^(\d{1,2})$/ ) { # references in WW format...
59 $idldocKey = sprintf( "%1d%d", $year % 10, $1 );
60  
61 }
62 elsif ( $period =~ /^week$/i ) {
63 $idldocKey = sprintf( "%1d%02d", $year % 10, $week );
64  
65 }
66 else {
67 $idldocKey = sprintf( "%1d%02d", $year % 10, $week );
68 }
69 $idldocKey .= "%"
70 ; # strangely, for the week and \d2 cases we get the following message if we put % in the sprintf : Invalid conversion in sprintf: end of string at C:\Sources\edtk_MNT\lib\index_Check_docs_omgr.pl line 44.
71 push( @sql_values, $idldocKey );
72  
73 $select =
74 "SELECT COUNT (DISTINCT A.ED_IDLDOC||TO_CHAR(A.ED_SEQDOC,'FM0000000')) AS NB_DOCS, "
75 . " NVL(C.ED_STATUS, NVL(A.ED_STATUS, 'NONE')) AS STATUS,"
76 . " B.ED_APP, B.ED_SNGL_ID ";
77 $sql =
78 " FROM "
79 . $cfg->{'EDTK_STATS_OUTMNGR'} . " A, "
80 . $cfg->{'EDTK_STATS_TRACKING'}
81 . " B, EDTK_ACQ C "
82 . " WHERE B.ED_SNGL_ID=A.ED_IDLDOC (+) AND B.ED_JOB_EVT='J' AND B.ED_SNGL_ID LIKE ? "
83 . " AND A.ED_SEQLOT = C.ED_SEQLOT (+)";
84  
85 # . " AND ROWNUM<1000 "; # the problem is that ROWNUM holds the line detail before grouping by lot
86 # . " WHERE A.ED_IDLDOC=B.ED_SNGL_ID AND B.ED_JOB_EVT='J' AND A.ED_SEQLOT != 'ANO' AND A.ED_SEQLOT LIKE ? ";
87 $groupby = " GROUP BY B.ED_APP, B.ED_SNGL_ID, A.ED_STATUS, C.ED_STATUS ";
88 $orderby = " ORDER BY B.ED_APP, NB_DOCS, B.ED_SNGL_ID, A.ED_STATUS, C.ED_STATUS ASC";
89  
90 my $col = "";
91 if ($refiddoc) {
92 $sql .= " AND B.ED_APP = ? ";
93 push( @sql_values, $refiddoc );
94 }
95  
96 if ( $lot =~ /^SEQLOT$/i ) {
97 $select .= ", A.ED_SEQLOT ";
98 $groupby .= ", A.ED_SEQLOT ";
99 $orderby = ", A.ED_SEQLOT ";
100 $col = uc($lot);
101  
102 }
103 elsif ( $lot =~ /^SOURCE$/i ) {
104 $select .= ", B.ED_SOURCE ";
105 $groupby .= ", B.ED_SOURCE ";
106 $orderby = ", B.ED_SOURCE ";
107 $col = uc($lot);
108  
109 }
110 elsif ($lot) {
111 $select .= ", B.ED_SOURCE ";
112 $sql .= " AND B.ED_SOURCE = ? ";
113 $groupby .= ", B.ED_SOURCE ";
114 $orderby = ", B.ED_SOURCE ";
115 push( @sql_values, $lot );
116 }
117  
118 $sql = $select . $sql . $groupby . $orderby;
119  
120 #warn "\nINFO: $sql\n\n";
121  
122 my $sth = $dbh->prepare($sql);
123 $sth->execute(@sql_values);
124  
125 my $rows = $sth->fetchall_arrayref();
126 foreach my $row (@$rows) {
127 for ( my $i = 0 ; $i <= $#$row ; $i++ ) {
128 $$row[$i] = $$row[$i] || ""; # IN THE SEQLOT CASE IT MAY NOT BE FILLED IN YET
129 }
130  
131 # push (@tlist, printf ("%-16s %9s %9s %9s %8s %8s %7s %-10s %s\n", @$row));
132 }
133  
134 printf "%9s %-7s %-15s %-16s %s from EDTK_STATS_OUTMNGR\n", "NB_DOCS", "STATUS", "REFIDDOC",
135 "IDLDOC", $col;
136  
137 ################################################################################
138  
139 if ( !scalar @{$rows} ) {
140 warn "INFO: no associated data.\n";
141 exit;
142 }
143  
144 foreach my $row (@$rows) {
145 for ( my $i = 0 ; $i <= $#$row ; $i++ ) {
146 $$row[$i] = $$row[$i] || ""; # SOME VALUES MAY NOT BE FILLED IN IN SOME CASES
147 }
148 printf "%9s %7s %-15s %-16s %s \n", @$row, ""; # 1391152325098839
149 }