use vars qw ( @ISA @EXPORT_OK $DEBUG );
use Exporter;
use Carp;
-use FS::Record qw(dbh qsearch);
-use FS::cust_credit_refund;
-#use FS::cust_credit_bill;
-#use FS::cust_bill_pay;
-#use FS::cust_pay_refund;
use Data::Dumper;
+#do NOT depend on any FS:: modules here, causes weird (sometimes unreproducable
+#until on client machine) dependancy loops. put them in FS::Misc::Something
+#instead
@ISA = qw( Exporter );
@EXPORT_OK = qw( send_email send_fax
states_hash counties state_label
- card_types prune_applications
+ card_types
+ generate_ps do_print
);
$DEBUG = 0;
unless exists($options{'dialstring'});
if (exists($options{'docdata'}) and ref($options{'docdata'}) eq 'ARRAY') {
- my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
+ my $dir = $FS::UID::conf_dir. "/cache.". $FS::UID::datasrc;
my $fh = new File::Temp(
TEMPLATE => 'faxdoc.'. $options{'dialstring'} . '.XXXXXXXX',
DIR => $dir,
\%card_types;
}
-=item prune_applications OPTION_HASH
+=item generate_ps FILENAME
-Removes applications of credits to refunds in the event that the database
-is corrupt and either the credits or refunds are missing (see
-L<FS::cust_credit>, L<FS::cust_refund>, and L<FS::cust_credit_refund>).
-If the OPTION_HASH contains the element 'dry_run' then a report of
-affected records is returned rather than actually deleting the records.
+Returns an postscript rendition of the LaTex file, as a scalar.
+FILENAME does not contain the .tex suffix and is unlinked by this function.
=cut
-sub prune_applications {
- my $options = shift;
- my $dbh = dbh
-
- local $DEBUG = 1 if exists($options->{debug});
- my $ccr = <<EOW;
- WHERE
- 0 = (select count(*) from cust_credit
- where cust_credit_refund.crednum = cust_credit.crednum)
- or
- 0 = (select count(*) from cust_refund
- where cust_credit_refund.refundnum = cust_refund.refundnum)
-EOW
- my $ccb = <<EOW;
- WHERE
- 0 = (select count(*) from cust_credit
- where cust_credit_bill.crednum = cust_credit.crednum)
- or
- 0 = (select count(*) from cust_bill
- where cust_credit_bill.invnum = cust_bill.invnum)
-EOW
- my $cbp = <<EOW;
- WHERE
- 0 = (select count(*) from cust_bill
- where cust_bill_pay.invnum = cust_bill.invnum)
- or
- 0 = (select count(*) from cust_pay
- where cust_bill_pay.paynum = cust_pay.paynum)
-EOW
- my $cpr = <<EOW;
- WHERE
- 0 = (select count(*) from cust_pay
- where cust_pay_refund.paynum = cust_pay.paynum)
- or
- 0 = (select count(*) from cust_refund
- where cust_pay_refund.refundnum = cust_refund.refundnum)
-EOW
-
- my %strays = (
- 'cust_credit_refund' => { clause => $ccr,
- link1 => 'crednum',
- link2 => 'refundnum',
- },
-# 'cust_credit_bill' => { clause => $ccb,
-# link1 => 'crednum',
-# link2 => 'refundnum',
-# },
-# 'cust_bill_pay' => { clause => $cbp,
-# link1 => 'crednum',
-# link2 => 'refundnum',
-# },
-# 'cust_pay_refund' => { clause => $cpr,
-# link1 => 'crednum',
-# link2 => 'refundnum',
-# },
- );
+use String::ShellQuote;
- if ( exists($options->{dry_run}) ) {
- my @response = ();
- foreach my $table (keys %strays) {
- my $clause = $strays{$table}->{clause};
- my $link1 = $strays{$table}->{link1};
- my $link2 = $strays{$table}->{link2};
- my @rec = qsearch($table, {}, '', $clause);
- my $keyname = $rec[0]->primary_key if $rec[0];
- foreach (@rec) {
- push @response, "$table " .$_->$keyname . " claims attachment to ".
- "$link1 " . $_->$link1 . " and $link2 " . $_->$link2 . "\n";
- }
- }
- return (@response);
- } else {
- foreach (keys %strays) {
- my $statement = "DELETE FROM $_ " . $strays{$_}->{clause};
- warn $statement if $DEBUG;
- my $sth = $dbh->prepare($statement)
- or die $dbh->errstr;
- $sth->execute
- or die $sth->errstr;
- }
- return ();
+sub generate_ps {
+ my $file = shift;
+
+ my $dir = $FS::UID::conf_dir. "/cache.". $FS::UID::datasrc;
+ chdir($dir);
+
+ my $sfile = shell_quote $file;
+
+ system("pslatex $sfile.tex >/dev/null 2>&1") == 0
+ or die "pslatex $file.tex failed; see $file.log for details?\n";
+ system("pslatex $sfile.tex >/dev/null 2>&1") == 0
+ or die "pslatex $file.tex failed; see $file.log for details?\n";
+
+ system('dvips', '-q', '-t', 'letter', "$file.dvi", '-o', "$file.ps" ) == 0
+ or die "dvips failed";
+
+ open(POSTSCRIPT, "<$file.ps")
+ or die "can't open $file.ps: $! (error in LaTeX template?)\n";
+
+ unlink("$file.dvi", "$file.log", "$file.aux", "$file.ps", "$file.tex");
+
+ my $ps = '';
+
+ if ( $conf->exists('lpr-postscript_prefix') ) {
+ my $prefix = $conf->config('lpr-postscript_prefix');
+ $ps .= eval qq("$prefix");
+ }
+
+ while (<POSTSCRIPT>) {
+ $ps .= $_;
+ }
+
+ close POSTSCRIPT;
+
+ if ( $conf->exists('lpr-postscript_suffix') ) {
+ my $suffix = $conf->config('lpr-postscript_suffix');
+ $ps .= eval qq("$suffix");
}
+
+ return $ps;
+
+}
+
+=item print ARRAYREF
+
+Sends the lines in ARRAYREF to the printer.
+
+=cut
+
+use IPC::Run3;
+
+sub do_print {
+ my $data = shift;
+
+ my $lpr = $conf->config('lpr');
+
+ my $outerr = '';
+ run3 $lpr, $data, \$outerr, \$outerr;
+ if ( $? ) {
+ $outerr = ": $outerr" if length($outerr);
+ die "Error from $lpr (exit status ". ($?>>8). ")$outerr\n";
+ }
+
}
=back