#use Date::Manip;
use File::Temp; #qw( tempfile );
use Business::CreditCard 0.28;
-use Locale::Country;
use FS::UID qw( getotaker dbh driver_name );
use FS::Record qw( qsearchs qsearch dbdef regexp_sql );
-use FS::Misc qw( generate_email send_email generate_ps do_print );
+use FS::Misc qw( generate_email send_email generate_ps do_print money_pretty );
use FS::Msgcat qw(gettext);
use FS::CurrentUser;
use FS::TicketSystem;
}else{
$amount = sprintf("%.2f", $self->balance - $self->in_transit_payments);
}
- return '' unless $amount > 0;
+ if ($amount <= 0) {
+ warn(sprintf("Customer balance %.2f - in transit amount %.2f is <= 0.\n",
+ $self->balance,
+ $self->in_transit_payments
+ ));
+ return;
+ }
my $invnum = delete $options{invnum};
my $payby = $options{payby} || $self->payby; #still dubious
foreach my $cust_pay_batch ( qsearch('cust_pay_batch', {
'batchnum' => $pay_batch->batchnum,
'custnum' => $self->custnum,
+ 'status' => '',
} ) ) {
$in_transit_payments += $cust_pay_batch->amount;
}
$contact->get('first') . ' '. $contact->get('last');
}
-#XXX this doesn't work in 3.x+
-#=item country_full
-#
-#Returns this customer's full country name
-#
-#=cut
-#
-#sub country_full {
-# my $self = shift;
-# code2country($self->country);
-#}
-
sub bill_country_full {
my $self = shift;
- code2country($self->bill_location->country);
+ $self->bill_location->country_full;
}
sub ship_country_full {
my $self = shift;
- code2country($self->ship_location->country);
+ $self->ship_location->country_full;
}
=item county_state_county [ PREFIX ]
'amount' => sprintf('%.2f', $_->setup + $_->recur ),
'charged' => sprintf('%.2f', $_->setup + $_->recur ),
'date' => $cust_bill->_date,
- 'date_pretty' => time2str('%m/%d/%Y', $cust_bill->_date ),
+ 'date_pretty' => $self->time2str_local('short', $cust_bill->_date ),
}
foreach $cust_bill->cust_bill_pkg;
'amount' => sprintf('%.2f', $_->charged ),
'charged' => sprintf('%.2f', $_->charged ),
'date' => $_->_date,
- 'date_pretty' => time2str('%m/%d/%Y', $_->_date ),
+ 'date_pretty' => $self->time2str_local('short', $_->_date ),
}
foreach $self->cust_bill;
'amount' => sprintf('%.2f', 0 - $_->paid ),
'paid' => sprintf('%.2f', $_->paid ),
'date' => $_->_date,
- 'date_pretty' => time2str('%m/%d/%Y', $_->_date ),
+ 'date_pretty' => $self->time2str_local('short', $_->_date ),
}
foreach $self->cust_pay;
'amount' => sprintf('%.2f', 0 -$_->amount ),
'credit' => sprintf('%.2f', $_->amount ),
'date' => $_->_date,
- 'date_pretty' => time2str('%m/%d/%Y', $_->_date ),
+ 'date_pretty' => $self->time2str_local('short', $_->_date ),
}
foreach $self->cust_credit;
'amount' => $_->refund,
'refund' => $_->refund,
'date' => $_->_date,
- 'date_pretty' => time2str('%m/%d/%Y', $_->_date ),
+ 'date_pretty' => $self->time2str_local('short', $_->_date ),
}
foreach $self->cust_refund;
}
$$item{'balance'} = sprintf("%.2f",$balance);
foreach my $key ( qw(amount balance) ) {
- $$item{$key.'_pretty'} = $$item{$key};
- $$item{$key.'_pretty'} =~ s/^(-?)/$1$money_char/;
+ $$item{$key.'_pretty'} = money_pretty($$item{$key});
}
push(@out,$item);
}
'description' => 'Previous balance',
'amount' => sprintf("%.2f",$previous),
'balance' => sprintf("%.2f",$previous),
+ 'date' => $$opt{'start_date'},
+ 'date_pretty' => $self->time2str_local('short', $$opt{'start_date'} ),
};
#false laziness with above
foreach my $key ( qw(amount balance) ) {
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";