use FS::UID qw( dbh driver_name );
use FS::Record qw( qsearchs qsearch dbdef regexp_sql );
use FS::Cursor;
-use FS::Misc qw( generate_email send_email generate_ps do_print money_pretty );
+use FS::Misc qw( generate_ps do_print money_pretty );
use FS::Msgcat qw(gettext);
use FS::CurrentUser;
use FS::TicketSystem;
warn " setting cust_payby\n"
if $DEBUG > 1;
- if ( my $cust_payby_params = delete $options{'cust_payby_params'} ) {
+ if ( $options{cust_payby} ) {
+
+ foreach my $cust_payby ( @{ $options{cust_payby} } ) {
+ $cust_payby->custnum($self->custnum);
+ my $error = $cust_payby->insert;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+
+ } elsif ( my $cust_payby_params = delete $options{'cust_payby_params'} ) {
my $error = $self->process_o2m(
'table' => 'cust_payby',
(@tickets);
}
+=item appointments [ STATUS ]
+
+Returns an array of hashes representing the customer's RT tickets which
+are appointments.
+
+=cut
+
+sub appointments {
+ my $self = shift;
+ my $status = ( @_ && $_[0] ) ? shift : '';
+
+ return () unless $conf->config('ticket_system');
+
+ my $queueid = $conf->config('ticket_system-appointment-queueid');
+
+ @{ FS::TicketSystem->customer_tickets( $self->custnum,
+ 99,
+ undef,
+ $status,
+ $queueid,
+ )
+ };
+}
+
# Return services representing svc_accts in customer support packages
sub support_services {
my $self = shift;
=over 4
-=item notify CUSTOMER_OBJECT TEMPLATE_NAME OPTIONS
-
-Deprecated. Use event notification and message templates
-(L<FS::msg_template>) instead.
+#=item notify CUSTOMER_OBJECT TEMPLATE_NAME OPTIONS
-Sends a templated email notification to the customer (see L<Text::Template>).
+#Deprecated. Use event notification and message templates
+#(L<FS::msg_template>) instead.
-OPTIONS is a hash and may include
+#Sends a templated email notification to the customer (see L<Text::Template>).
-I<from> - the email sender (default is invoice_from)
+#OPTIONS is a hash and may include
-I<to> - comma-separated scalar or arrayref of recipients
- (default is invoicing_list)
+#I<from> - the email sender (default is invoice_from)
-I<subject> - The subject line of the sent email notification
- (default is "Notice from company_name")
+#I<to> - comma-separated scalar or arrayref of recipients
+# (default is invoicing_list)
-I<extra_fields> - a hashref of name/value pairs which will be substituted
- into the template
+#I<subject> - The subject line of the sent email notification
+# (default is "Notice from company_name")
-The following variables are vavailable in the template.
+#I<extra_fields> - a hashref of name/value pairs which will be substituted
+# into the template
-I<$first> - the customer first name
-I<$last> - the customer last name
-I<$company> - the customer company
-I<$payby> - a description of the method of payment for the customer
- # would be nice to use FS::payby::shortname
-I<$payinfo> - the account information used to collect for this customer
-I<$expdate> - the expiration of the customer payment in seconds from epoch
+#The following variables are vavailable in the template.
-=cut
-
-sub notify {
- my ($self, $template, %options) = @_;
+#I<$first> - the customer first name
+#I<$last> - the customer last name
+#I<$company> - the customer company
+#I<$payby> - a description of the method of payment for the customer
+# # would be nice to use FS::payby::shortname
+#I<$payinfo> - the account information used to collect for this customer
+#I<$expdate> - the expiration of the customer payment in seconds from epoch
- return unless $conf->exists($template);
-
- my $from = $conf->invoice_from_full($self->agentnum)
- if $conf->exists('invoice_from', $self->agentnum);
- $from = $options{from} if exists($options{from});
-
- my $to = join(',', $self->invoicing_list_emailonly);
- $to = $options{to} if exists($options{to});
-
- my $subject = "Notice from " . $conf->config('company_name', $self->agentnum)
- if $conf->exists('company_name', $self->agentnum);
- $subject = $options{subject} if exists($options{subject});
-
- my $notify_template = new Text::Template (TYPE => 'ARRAY',
- SOURCE => [ map "$_\n",
- $conf->config($template)]
- )
- or die "can't create new Text::Template object: Text::Template::ERROR";
- $notify_template->compile()
- or die "can't compile template: Text::Template::ERROR";
-
- $FS::notify_template::_template::company_name =
- $conf->config('company_name', $self->agentnum);
- $FS::notify_template::_template::company_address =
- join("\n", $conf->config('company_address', $self->agentnum) ). "\n";
-
- my $paydate = $self->paydate || '2037-12-31';
- $FS::notify_template::_template::first = $self->first;
- $FS::notify_template::_template::last = $self->last;
- $FS::notify_template::_template::company = $self->company;
- $FS::notify_template::_template::payinfo = $self->mask_payinfo;
- my $payby = $self->payby;
- my ($payyear,$paymonth,$payday) = split (/-/,$paydate);
- my $expire_time = timelocal(0,0,0,$payday,--$paymonth,$payyear);
-
- #credit cards expire at the end of the month/year of their exp date
- if ($payby eq 'CARD' || $payby eq 'DCRD') {
- $FS::notify_template::_template::payby = 'credit card';
- ($paymonth < 11) ? $paymonth++ : ($paymonth=0, $payyear++);
- $expire_time = timelocal(0,0,0,$payday,$paymonth,$payyear);
- $expire_time--;
- }elsif ($payby eq 'COMP') {
- $FS::notify_template::_template::payby = 'complimentary account';
- }else{
- $FS::notify_template::_template::payby = 'current method';
- }
- $FS::notify_template::_template::expdate = $expire_time;
-
- for (keys %{$options{extra_fields}}){
- no strict "refs";
- ${"FS::notify_template::_template::$_"} = $options{extra_fields}->{$_};
- }
+#=cut
- send_email(from => $from,
- to => $to,
- subject => $subject,
- body => $notify_template->fill_in( PACKAGE =>
- 'FS::notify_template::_template' ),
- );
+#sub notify {
+# my ($self, $template, %options) = @_;
+
+# return unless $conf->exists($template);
+
+# my $from = $conf->invoice_from_full($self->agentnum)
+# if $conf->exists('invoice_from', $self->agentnum);
+# $from = $options{from} if exists($options{from});
+
+# my $to = join(',', $self->invoicing_list_emailonly);
+# $to = $options{to} if exists($options{to});
+#
+# my $subject = "Notice from " . $conf->config('company_name', $self->agentnum)
+# if $conf->exists('company_name', $self->agentnum);
+# $subject = $options{subject} if exists($options{subject});
+
+# my $notify_template = new Text::Template (TYPE => 'ARRAY',
+# SOURCE => [ map "$_\n",
+# $conf->config($template)]
+# )
+# or die "can't create new Text::Template object: Text::Template::ERROR";
+# $notify_template->compile()
+# or die "can't compile template: Text::Template::ERROR";
+
+# $FS::notify_template::_template::company_name =
+# $conf->config('company_name', $self->agentnum);
+# $FS::notify_template::_template::company_address =
+# join("\n", $conf->config('company_address', $self->agentnum) ). "\n";
+
+# my $paydate = $self->paydate || '2037-12-31';
+# $FS::notify_template::_template::first = $self->first;
+# $FS::notify_template::_template::last = $self->last;
+# $FS::notify_template::_template::company = $self->company;
+# $FS::notify_template::_template::payinfo = $self->mask_payinfo;
+# my $payby = $self->payby;
+# my ($payyear,$paymonth,$payday) = split (/-/,$paydate);
+# my $expire_time = timelocal(0,0,0,$payday,--$paymonth,$payyear);
+
+# #credit cards expire at the end of the month/year of their exp date
+# if ($payby eq 'CARD' || $payby eq 'DCRD') {
+# $FS::notify_template::_template::payby = 'credit card';
+# ($paymonth < 11) ? $paymonth++ : ($paymonth=0, $payyear++);
+# $expire_time = timelocal(0,0,0,$payday,$paymonth,$payyear);
+# $expire_time--;
+# }elsif ($payby eq 'COMP') {
+# $FS::notify_template::_template::payby = 'complimentary account';
+# }else{
+# $FS::notify_template::_template::payby = 'current method';
+# }
+# $FS::notify_template::_template::expdate = $expire_time;
+
+# for (keys %{$options{extra_fields}}){
+# no strict "refs";
+# ${"FS::notify_template::_template::$_"} = $options{extra_fields}->{$_};
+# }
+
+# send_email(from => $from,
+# to => $to,
+# subject => $subject,
+# body => $notify_template->fill_in( PACKAGE =>
+# 'FS::notify_template::_template' ),
+# );
-}
+#}
=item generate_letter CUSTOMER_OBJECT TEMPLATE_NAME OPTIONS
into the template. These values may override values mentioned below
and those from the customer record.
+I<template_text> - if present, ignores TEMPLATE_NAME and uses the provided text
+
The following variables are available in the template instead of or in addition
to the fields of the customer record.
sub generate_letter {
my ($self, $template, %options) = @_;
- return unless $conf->exists($template);
+ warn "Template $template does not exist" && return
+ unless $conf->exists($template) || $options{'template_text'};
+
+ my $template_source = $options{'template_text'}
+ ? [ $options{'template_text'} ]
+ : [ map "$_\n", $conf->config($template) ];
my $letter_template = new Text::Template
( TYPE => 'ARRAY',
- SOURCE => [ map "$_\n", $conf->config($template)],
+ SOURCE => $template_source,
DELIMITERS => [ '[@--', '--@]' ],
)
or die "can't create new Text::Template object: Text::Template::ERROR";
my $self = qsearchs('cust_main', { 'custnum' => $opt{custnum} } )
or die "invalid customer number: " . $opt{custnum};
- my $error = $self->print( { 'template' => $opt{template} } );
+#do not backport this change to 3.x
+# my $error = $self->print( { 'template' => $opt{template} } );
+ my $error = $self->print( $opt{'template'} );
die $error if $error;
}