4 use FS::Record qw(dbdef);
11 sub parse_beginning_ending {
14 $cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/;
15 my $beginning = str2time($1) || 0;
17 #need an option to turn off the + 86399 ???
18 $cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/;
19 my $ending = ( $1 ? str2time($1) : 4294880896 ) + 86399;
21 ( $beginning, $ending );
25 # cust_main report methods
30 Returns an array of customer information headers according to the
31 B<cust-fields> configuration setting.
35 use vars qw( @cust_fields );
38 my @fields = qw( last first company );
39 push @fields, map "ship_$_", @fields
40 if dbdef->table('cust_main')->column('ship_last');
41 map "cust_main.$_", @fields;
46 warn "FS::svc_Common::cust_header called"
49 my $conf = new FS::Conf;
55 'Company' => 'company',
56 '(bill) Customer' => 'name',
57 '(service) Customer' => 'ship_name',
58 '(bill) Name' => 'contact',
59 '(service) Name' => 'ship_contact',
60 '(bill) Company' => 'company',
61 '(service) Company' => 'ship_company',
65 if ( $conf->exists('cust-fields')
66 && $conf->config('cust-fields') =~ /^([\w \|\#\(\)]+):/
69 warn " found cust-fields configuration value"
73 @cust_header = split(/ \| /, $cust_fields);
74 @cust_fields = map { $header2method{$_} } @cust_header;
76 warn " no cust-fields configuration value found; using default 'Customer'"
78 @cust_header = ( 'Customer' );
79 @cust_fields = ( 'cust_name' );
88 Given a svc_ object that contains fields from cust_main (say, from a
89 JOINed search. See httemplate/search/svc_* for examples), returns an array
90 of customer information according to the <B>cust-fields</B> configuration
91 setting, or "(unlinked)" if this service is not linked to a customer.
97 warn "FS::svc_Common::cust_fields called for $svc_x ".
98 "(cust_fields: @cust_fields)"
101 cust_header() unless @cust_fields;
103 my $seen_unlinked = 0;
105 if ( $svc_x->custnum ) {
110 warn " ($svc_x unlinked)"
112 $seen_unlinked++ ? '' : '(unlinked)';
118 # begin JSRPC code...
121 package FS::UI::Web::JSRPC;
124 use vars qw(@ISA $DEBUG);
125 use Storable qw(nfreeze);
127 use JavaScript::RPC::Server::CGI;
129 use FS::Record qw(qsearchs);
132 @ISA = qw( JavaScript::RPC::Server::CGI );
150 warn "FS::UI::Web::start_job: ". join(', ', @_) if $DEBUG;
154 my( $field, $value ) = splice(@_, 0, 2);
155 unless ( exists( $param{$field} ) ) {
156 $param{$field} = $value;
157 } elsif ( ! ref($param{$field}) ) {
158 $param{$field} = [ $param{$field}, $value ];
160 push @{$param{$field}}, $value;
163 warn "FS::UI::Web::start_job\n".
165 if ( ref($param{$_}) ) {
166 " $_ => [ ". join(', ', @{$param{$_}}). " ]\n";
168 " $_ => $param{$_}\n";
173 #first get the CGI params shipped off to a job ASAP so an id can be returned
176 my $job = new FS::queue { 'job' => $self->{'job'} };
178 #too slow to insert all the cgi params as individual args..,?
179 #my $error = $queue->insert('_JOB', $cgi->Vars);
181 #warn 'froze string of size '. length(nfreeze(\%param)). " for job args\n"
184 my $error = $job->insert( '_JOB', encode_base64(nfreeze(\%param)) );
195 my( $self, $jobnum ) = @_; #$url ???
197 sleep 5; #could use something better...
200 if ( $jobnum =~ /^(\d+)$/ ) {
201 $job = qsearchs('queue', { 'jobnum' => $jobnum } );
203 die "FS::UI::Web::job_status: illegal jobnum $jobnum\n";
207 if ( $job && $job->status ne 'failed' ) {
208 @return = ( 'progress', $job->statustext );
209 } elsif ( !$job ) { #handle job gone case : job sucessful
210 # so close popup, redirect parent window...
211 @return = ( 'complete' );
213 @return = ( 'error', $job ? $job->statustext : $jobnum );