X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FMisc.pm;h=e1f654c346712aa30b24666701c81ed0220c4a1e;hb=0ed195595b5c7ea404c8848d9d1881ada4214489;hp=036c32d4ed02ba7d5edec089c5ddde6fcffcd768;hpb=f13c9d8580d02851b150e21ea9beb6fc1dfbd3c8;p=freeside.git diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm index 036c32d4e..e1f654c34 100644 --- a/FS/FS/Misc.pm +++ b/FS/FS/Misc.pm @@ -22,6 +22,8 @@ use Encode; generate_ps generate_pdf do_print csv_from_fixed ocr_image + bytes_substr + money_pretty ); $DEBUG = 0; @@ -255,9 +257,9 @@ sub send_email { push @to, $options{bcc} if defined($options{bcc}); local $@; # just in case -# eval { sendmail($message, { transport => $transport, -# from => $from, -# to => \@to }) }; + eval { sendmail($message, { transport => $transport, + from => $from, + to => \@to }) }; my $error = ''; if(ref($@) and $@->isa('Email::Sender::Failure')) { @@ -827,7 +829,7 @@ sub _pslatex { } return if -e "$file.dvi" && -s "$file.dvi"; - die "pslatex $file.tex failed; see $file.log for details?\n"; + die "pslatex $file.tex failed, see $file.log for details?\n"; } @@ -961,6 +963,42 @@ sub ocr_image { @lines; } +=item bytes_substr STRING, OFFSET[, LENGTH[, REPLACEMENT] ] + +A replacement for "substr" that counts raw bytes rather than logical +characters. Unlike "bytes::substr", will suppress fragmented UTF-8 characters +rather than output them. Unlike real "substr", is not an lvalue. + +=cut + +sub bytes_substr { + my ($string, $offset, $length, $repl) = @_; + my $bytes = substr( + Encode::encode('utf8', $string), + $offset, + $length, + Encode::encode('utf8', $repl) + ); + my $chk = $DEBUG ? Encode::FB_WARN : Encode::FB_QUIET; + return Encode::decode('utf8', $bytes, $chk); +} + +=item money_pretty + +Accepts a postive or negative numerical value. +Returns amount formatted for display, +including money character. + +=cut + +sub money_pretty { + my $amount = shift; + my $money_char = $conf->{'money_char'} || '$'; + $amount = sprintf("%0.2f",$amount); + $amount =~ s/^(-?)/$1$money_char/; + return $amount; +} + =back =head1 BUGS