1 package FS::part_export::print_template;
5 use base qw( FS::part_export );
7 use FS::Record qw(qsearchs);
15 FS::part_export::print_template
19 Print a document of a template.
23 See the L<Text::Template> documentation and the billing documentation for details on the template substitution language.
25 Currently does not support printing during replace.
31 tie my %options, 'Tie::IxHash',
32 'phase' => { label => 'Print during',
34 options => [qw(insert delete suspend unsuspend)] },
35 'template_text' => { label => 'Template text',
40 #unfortunately, FS::part_svc->svc_tables fails at this point, not sure why
41 'svc' => [ qw( svc_acct svc_domain svc_cert svc_forward svc_mailinglist svc_www
42 svc_broadband svc_cable svc_dsl svc_conferencing svc_video svc_dish
43 svc_hardware svc_phone svc_pbx svc_circuit svc_port svc_alarm svc_external )
45 'desc' => 'Print document during service change, for all services',
46 'options' => \%options,
49 Will use the print command configured by the lpr setting.
50 See the <a href="http://search.cpan.org/dist/Text-Template/lib/Text/Template.pm">Text::Template</a> documentation and the billing documentation for details on the template substitution language.
51 Fields from the customer and service records are available for substitution, as well as the following fields:
54 <li>$payby - a friendler represenation of the field</li>
55 <li>$payinfo - the masked payment information</li>
56 <li>$expdate - the time at which the payment method expires (a UNIX timestamp)</li>
57 <li>$returnaddress - the invoice return address for this customer's agent</li>
58 <li>$logo_file - the image stored in the logo.eps setting
65 Each of these simply invoke this module's L<print_template> method,
66 passing the appropriate phase.
72 Hook that is called when service is initially provisioned.
73 To avoid confusion, don't use for anything else.
79 return $self->print_template('insert',@_);
84 Hook that is called when service is unprovisioned.
85 To avoid confusion, don't use for anything else.
91 return $self->print_template('delete',@_);
94 =head2 _export_replace
96 Hook that is called when provisioned service is edited.
97 To avoid confusion, don't use for anything else.
99 Currently not supported for this export.
103 sub _export_replace {
107 =head2 _export_suspend
109 Hook that is called when service is suspended.
110 To avoid confusion, don't use for anything else.
114 sub _export_suspend {
116 return $self->print_template('suspend',@_);
119 =head2 _export_unsuspend
121 Hook that is called when service is unsuspended.
122 To avoid confusion, don't use for anything else.
126 sub _export_unsuspend {
128 return $self->print_template('unsuspend',@_);
133 =head2 print_template
135 Accepts $phase and $svc_x.
136 If phase matches the configured option, starts a L</process_print_template>
142 my ($self, $phase, $svc_x) = @_;
143 if ($self->option('phase') eq $phase) {
144 my $queue = new FS::queue {
145 'svcnum' => $svc_x->svcnum,
146 'job' => 'FS::part_export::print_template::process_print_template',
148 my $error = $queue->insert(
149 'svcnum' => $svc_x->svcnum,
150 'table' => $svc_x->table,
151 'template_text' => $self->option('template_text'),
153 return "can't start print job: $error" if $error;
158 =head2 process_print_template
160 For use as an FS::queue job. Requires opts svcnum, table and template_text.
161 Constructs page from template and sends to printer.
165 sub process_print_template {
168 my $svc_x = qsearchs($opt{'table'}, { 'svcnum' => $opt{'svcnum'} } )
169 or die "invalid " . $opt{'table'} . " svcnum " . $opt{'svcnum'};
170 my $cust_main = $svc_x->cust_svc->cust_pkg->cust_main
171 or die "could not find customer for service";
173 my $ps = $cust_main->print_ps(undef,
174 'template_text' => $opt{'template_text'},
176 map { $_ => $svc_x->$_ } $svc_x->fields,
179 my $error = FS::Misc::do_print(
181 'agentnum' => $cust_main->agentnum,
183 die $error if $error;
193 jonathan@freeside.biz