line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
26858
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
2
|
1
|
|
|
1
|
|
6
|
use warnings;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
38
|
|
3
|
|
|
|
|
|
|
package C3000::RepUtils;
|
4
|
1
|
|
|
1
|
|
5
|
use constant DEBUG => 0;
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
73
|
|
5
|
1
|
|
|
1
|
|
2678
|
use C3000;
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use File::Basename;
|
7
|
|
|
|
|
|
|
use Config::Tiny;
|
8
|
|
|
|
|
|
|
use Win32;
|
9
|
|
|
|
|
|
|
use File::Spec::Functions;
|
10
|
|
|
|
|
|
|
use Win32::ExcelSimple;
|
11
|
|
|
|
|
|
|
use DateTime;
|
12
|
|
|
|
|
|
|
use DateTime::Format::Natural;
|
13
|
|
|
|
|
|
|
use DateTime::Format::Oracle;
|
14
|
|
|
|
|
|
|
use Exporter;
|
15
|
|
|
|
|
|
|
our @ISA = qw( Exporter );
|
16
|
|
|
|
|
|
|
our @EXPORT = qw( init read_conf make_rep_name );
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = 0.11;
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# ABSTRACT: turns baubles into trinkets
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub init{
|
25
|
|
|
|
|
|
|
my $c3000_h = C3000->new();
|
26
|
|
|
|
|
|
|
my $config_h = read_conf();
|
27
|
|
|
|
|
|
|
my @excel_hs = map { Win32::ExcelSimple->new($_) } split /\s+/, $config_h->{template_name};
|
28
|
|
|
|
|
|
|
my $dt_parser_now = DateTime::Format::Natural->new(
|
29
|
|
|
|
|
|
|
lang => 'en',
|
30
|
|
|
|
|
|
|
format => 'yyyy/mm/dd',
|
31
|
|
|
|
|
|
|
time_zone => 'Asia/Taipei',
|
32
|
|
|
|
|
|
|
);
|
33
|
|
|
|
|
|
|
my $dt_from;
|
34
|
|
|
|
|
|
|
my $dt_to;
|
35
|
|
|
|
|
|
|
my $dt_start;
|
36
|
|
|
|
|
|
|
if (defined $config_h->{from}){
|
37
|
|
|
|
|
|
|
$dt_from = $dt_parser_now->parse_datetime($config_h->{from});
|
38
|
|
|
|
|
|
|
}
|
39
|
|
|
|
|
|
|
else{
|
40
|
|
|
|
|
|
|
$dt_from = $dt_parser_now->parse_datetime();
|
41
|
|
|
|
|
|
|
}
|
42
|
|
|
|
|
|
|
if (defined $config_h->{to}){
|
43
|
|
|
|
|
|
|
$dt_to = $dt_parser_now->parse_datetime($config_h->{to});
|
44
|
|
|
|
|
|
|
}
|
45
|
|
|
|
|
|
|
else{
|
46
|
|
|
|
|
|
|
$dt_to = $dt_parser_now->parse_datetime();
|
47
|
|
|
|
|
|
|
}
|
48
|
|
|
|
|
|
|
if (defined $config_h->{time_start}){
|
49
|
|
|
|
|
|
|
$dt_start = $dt_parser_now->parse_datetime($config_h->{time_start});
|
50
|
|
|
|
|
|
|
}
|
51
|
|
|
|
|
|
|
else{
|
52
|
|
|
|
|
|
|
$dt_start = $dt_parser_now->parse_datetime();
|
53
|
|
|
|
|
|
|
}
|
54
|
|
|
|
|
|
|
my $dt_parser = DateTime::Format::Natural->new(
|
55
|
|
|
|
|
|
|
datetime => $dt_start,
|
56
|
|
|
|
|
|
|
lang => 'en',
|
57
|
|
|
|
|
|
|
format => 'yyyy/mm/dd',
|
58
|
|
|
|
|
|
|
time_zone => 'Asia/Taipei',
|
59
|
|
|
|
|
|
|
);
|
60
|
|
|
|
|
|
|
return ($c3000_h, $config_h, $dt_parser, $dt_from, $dt_to, @excel_hs);
|
61
|
|
|
|
|
|
|
}
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub read_conf{
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Config::Tiny->new();
|
66
|
|
|
|
|
|
|
my $path = dirname($0);
|
67
|
|
|
|
|
|
|
my $file_name = basename($0);
|
68
|
|
|
|
|
|
|
$file_name =~ s/\..+$/\.ini/;
|
69
|
|
|
|
|
|
|
$file_name = 'RepAuto.ini' if $file_name !~ /\.ini$/;
|
70
|
|
|
|
|
|
|
$path = Win32::GetFullPathName($path);
|
71
|
|
|
|
|
|
|
my $abs_ini = catfile($path, $file_name);
|
72
|
|
|
|
|
|
|
my $Config = Config::Tiny->read($abs_ini) or die "can't open config file! $!";
|
73
|
|
|
|
|
|
|
return $Config->{_};
|
74
|
|
|
|
|
|
|
}
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub make_rep_name{
|
79
|
|
|
|
|
|
|
my($string, $rep_path, $templ_name, $from_dt, $to_dt) = @_;
|
80
|
|
|
|
|
|
|
$ENV{'NLS_DATE_FORMAT'} = 'YYYYMMDDHH24MI';
|
81
|
|
|
|
|
|
|
my $create_time_str = DateTime::Format::Oracle->format_datetime(DateTime->now());
|
82
|
|
|
|
|
|
|
print $create_time_str . "is create time \n" if DEBUG == 1;
|
83
|
|
|
|
|
|
|
my $from_time_str = DateTime::Format::Oracle->format_datetime($from_dt);
|
84
|
|
|
|
|
|
|
print $create_time_str . "is from time \n" if DEBUG == 1;
|
85
|
|
|
|
|
|
|
my $to_time_str = DateTime::Format::Oracle->format_datetime($to_dt);
|
86
|
|
|
|
|
|
|
print $create_time_str . "is to time \n" if DEBUG == 1;
|
87
|
|
|
|
|
|
|
$string =~ s/%c/$create_time_str/g;
|
88
|
|
|
|
|
|
|
$string =~ s/%templ_name/$templ_name/g;
|
89
|
|
|
|
|
|
|
$string =~ s/%f/$from_time_str/g;
|
90
|
|
|
|
|
|
|
$string =~ s/%t/$to_time_str/g;
|
91
|
|
|
|
|
|
|
$string .= '.xls';
|
92
|
|
|
|
|
|
|
return catfile($rep_path, $string);
|
93
|
|
|
|
|
|
|
}
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub RepAuto_callback{
|
96
|
|
|
|
|
|
|
my ($cell_h, $hl, $parser_from, $parser_to, $parser_now) = @_;
|
97
|
|
|
|
|
|
|
return if !defined $_[0]->{Value};
|
98
|
|
|
|
|
|
|
return if $_[0]->{Value} !~ /^~~~/;
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my @a = split /__/, substr( $_[0]->{Value}, 3 ) ; #grab useful string
|
101
|
|
|
|
|
|
|
$_[0]->{Value} = convert_xls_date( $parser_from, $parser_to, $parser_now, $a[0]);
|
102
|
|
|
|
|
|
|
if ( scalar @a == 3 ) {
|
103
|
|
|
|
|
|
|
$a[2] =
|
104
|
|
|
|
|
|
|
convert_xls_date( $parser_from, $parser_to, $parser_now,
|
105
|
|
|
|
|
|
|
$a[2] );
|
106
|
|
|
|
|
|
|
$_[0]->{Value} =
|
107
|
|
|
|
|
|
|
$hl->get_single_LP( 'ADAS_VAL_RAW', @a );
|
108
|
|
|
|
|
|
|
}
|
109
|
|
|
|
|
|
|
if ( scalar @a == 4 ) {
|
110
|
|
|
|
|
|
|
if ( $a[3] =~ /^\[/ ) {
|
111
|
|
|
|
|
|
|
$a[2] =
|
112
|
|
|
|
|
|
|
convert_xls_date( $parser_from, $parser_to,
|
113
|
|
|
|
|
|
|
$parser_now, $a[2] );
|
114
|
|
|
|
|
|
|
$_[0]->{Value} =
|
115
|
|
|
|
|
|
|
$hl->get_single_LP( 'ADAS_VAL_RAW', @a );
|
116
|
|
|
|
|
|
|
}
|
117
|
|
|
|
|
|
|
else {
|
118
|
|
|
|
|
|
|
$a[2] =
|
119
|
|
|
|
|
|
|
convert_xls_date( $parser_from, $parser_to,
|
120
|
|
|
|
|
|
|
$parser_now, $a[2] );
|
121
|
|
|
|
|
|
|
$a[3] =
|
122
|
|
|
|
|
|
|
convert_xls_date( $parser_from, $parser_to,
|
123
|
|
|
|
|
|
|
$parser_now, $a[3] );
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
$_[0]->{Value} =
|
126
|
|
|
|
|
|
|
$hl->accu_LP( 'ADAS_VAL_NORM', @a );
|
127
|
|
|
|
|
|
|
}
|
128
|
|
|
|
|
|
|
}
|
129
|
|
|
|
|
|
|
if ( scalar @a == 5 ) {
|
130
|
|
|
|
|
|
|
$a[2] =
|
131
|
|
|
|
|
|
|
convert_xls_date( $parser_from, $parser_to, $parser_now,
|
132
|
|
|
|
|
|
|
$a[2] );
|
133
|
|
|
|
|
|
|
$a[3] =
|
134
|
|
|
|
|
|
|
convert_xls_date( $parser_from, $parser_to, $parser_now,
|
135
|
|
|
|
|
|
|
$a[3] );
|
136
|
|
|
|
|
|
|
$_[0]->{Value} =
|
137
|
|
|
|
|
|
|
$hl->accu_LP( 'ADAS_VAL_NORM', @a );
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
}
|
141
|
|
|
|
|
|
|
}
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub convert_xls_date {
|
144
|
|
|
|
|
|
|
my ( $parser_from, $parser_to, $parser_now, $string ) = @_;
|
145
|
|
|
|
|
|
|
if ( $string =~ /^[Ff][Rr][Oo][Mm]\s+(.+)$/ ) {
|
146
|
|
|
|
|
|
|
return $parser_from ($1);
|
147
|
|
|
|
|
|
|
}
|
148
|
|
|
|
|
|
|
elsif ( $string =~ /^[Tt][Oo]\s+(.+)$/ ) {
|
149
|
|
|
|
|
|
|
return $parser_to ($1);
|
150
|
|
|
|
|
|
|
}
|
151
|
|
|
|
|
|
|
else {
|
152
|
|
|
|
|
|
|
return $parser_now ($1);
|
153
|
|
|
|
|
|
|
}
|
154
|
|
|
|
|
|
|
}
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1;
|
159
|
|
|
|
|
|
|
|