5 use FS::Record qw(dbdef);
12 sub parse_beginning_ending {
15 $cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/;
16 my $beginning = str2time($1) || 0;
18 #need an option to turn off the + 86399 ???
19 $cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/;
20 my $ending = ( $1 ? str2time($1) : 4294880896 ) + 86399;
22 ( $beginning, $ending );
26 # cust_main report methods
31 Returns an array of customer information headers according to the
32 B<cust-fields> configuration setting.
36 use vars qw( @cust_fields );
39 my @fields = qw( last first company );
40 push @fields, map "ship_$_", @fields
41 if dbdef->table('cust_main')->column('ship_last');
42 map "cust_main.$_", @fields;
47 warn "FS::svc_Common::cust_header called"
50 my $conf = new FS::Conf;
56 'Company' => 'company',
57 '(bill) Customer' => 'name',
58 '(service) Customer' => 'ship_name',
59 '(bill) Name' => 'contact',
60 '(service) Name' => 'ship_contact',
61 '(bill) Company' => 'company',
62 '(service) Company' => 'ship_company',
66 if ( $conf->exists('cust-fields')
67 && $conf->config('cust-fields') =~ /^([\w \|\#\(\)]+):/
70 warn " found cust-fields configuration value"
74 @cust_header = split(/ \| /, $cust_fields);
75 @cust_fields = map { $header2method{$_} } @cust_header;
77 warn " no cust-fields configuration value found; using default 'Customer'"
79 @cust_header = ( 'Customer' );
80 @cust_fields = ( 'name' );
89 Given a svc_ object that contains fields from cust_main (say, from a
90 JOINed search. See httemplate/search/svc_* for examples), returns an array
91 of customer information according to the <B>cust-fields</B> configuration
92 setting, or "(unlinked)" if this service is not linked to a customer.
98 warn "FS::svc_Common::cust_fields called for $svc_x ".
99 "(cust_fields: @cust_fields)"
102 cust_header() unless @cust_fields;
104 my $seen_unlinked = 0;
106 if ( $svc_x->custnum ) {
111 warn " ($svc_x unlinked)"
113 $seen_unlinked++ ? '' : '(unlinked)';
119 # begin JSRPC code...
122 package FS::UI::Web::JSRPC;
125 use vars qw(@ISA $DEBUG);
126 use Storable qw(nfreeze);
128 use JavaScript::RPC::Server::CGI;
130 use FS::Record qw(qsearchs);
133 @ISA = qw( JavaScript::RPC::Server::CGI );
151 warn "FS::UI::Web::start_job: ". join(', ', @_) if $DEBUG;
155 my( $field, $value ) = splice(@_, 0, 2);
156 unless ( exists( $param{$field} ) ) {
157 $param{$field} = $value;
158 } elsif ( ! ref($param{$field}) ) {
159 $param{$field} = [ $param{$field}, $value ];
161 push @{$param{$field}}, $value;
164 warn "FS::UI::Web::start_job\n".
166 if ( ref($param{$_}) ) {
167 " $_ => [ ". join(', ', @{$param{$_}}). " ]\n";
169 " $_ => $param{$_}\n";
174 #first get the CGI params shipped off to a job ASAP so an id can be returned
177 my $job = new FS::queue { 'job' => $self->{'job'} };
179 #too slow to insert all the cgi params as individual args..,?
180 #my $error = $queue->insert('_JOB', $cgi->Vars);
182 #warn 'froze string of size '. length(nfreeze(\%param)). " for job args\n"
185 my $error = $job->insert( '_JOB', encode_base64(nfreeze(\%param)) );
196 my( $self, $jobnum ) = @_; #$url ???
198 sleep 5; #could use something better...
201 if ( $jobnum =~ /^(\d+)$/ ) {
202 $job = qsearchs('queue', { 'jobnum' => $jobnum } );
204 die "FS::UI::Web::job_status: illegal jobnum $jobnum\n";
208 if ( $job && $job->status ne 'failed' ) {
209 @return = ( 'progress', $job->statustext );
210 } elsif ( !$job ) { #handle job gone case : job sucessful
211 # so close popup, redirect parent window...
212 @return = ( 'complete' );
214 @return = ( 'error', $job ? $job->statustext : $jobnum );