*** empty log message ***

This commit is contained in:
Rodolphe Quiedeville 2002-05-04 15:15:42 +00:00
parent 562a82a811
commit 19fbbc7401

View File

@ -19,7 +19,9 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# or see http://www.gnu.org/
#
# Génération des fiche d'intervention
#
use strict;
use POSIX;
use DBI;
@ -32,10 +34,10 @@ Sys::Syslog::openlog($0, 'pid', 'daemon');
my($debug, $verbose, $bgcolor, $idpropal, $do_fax, $do_pdf, $do_ps,
my($debug, $verbose, $bgcolor, $idfiche, $do_fax, $do_pdf, $do_ps,
$templatesdir, $outputdir) = (0,0);
exit unless GetOptions("propal=i" =>\$idpropal,
exit unless GetOptions("fichinter=i" =>\$idfiche,
"fax" =>\$do_fax,
"templates=s" =>\$templatesdir,
"output=s" =>\$outputdir,
@ -43,8 +45,8 @@ exit unless GetOptions("propal=i" =>\$idpropal,
"pdf" =>\$do_pdf,
"v+" =>\$verbose);
Sys::Syslog::syslog('info', 'Start propale '.$idpropal);
Sys::Syslog::syslog('info', '['.$idpropal.'] Start');
Sys::Syslog::syslog('info', 'Start Fiche Inter '.$idfiche);
Sys::Syslog::syslog('info', '['.$idfiche.'] Start');
my $DEBUG = 1;
my $mdir = "$outputdir";
@ -56,15 +58,14 @@ print "Output in : $outputdir\n" if $verbose > 1;
#
# Fetch datas
#
Sys::Syslog::syslog('info', '['.$idpropal.'] Fetch data');
my ($numpropale, $societe, $date, $ville, $destinataire, $price, $remise, $tva, $total);
Sys::Syslog::syslog('info', '['.$idfiche.'] Fetch data');
my ($numfiche, $societe, $date, $ville, $destinataire, $address);
my $dbh = DBI->connect("","","") || die $DBI::errstr ;
my $sql = "SELECT p.rowid, p.ref, s.nom, s.cp, s.ville, unix_timestamp(p.datep) as dp, c.name, c.firstname";
$sql .= " ,p.price, p.remise, p.tva, p.total";
$sql .= " FROM llx_propal as p, societe as s , socpeople as c";
$sql .= " WHERE s.idp = p.fk_soc AND p.fk_soc_contact = c.idp AND p.rowid = $idpropal";
my $sql = "SELECT f.rowid, f.ref, s.nom, s.address, s.cp, s.ville, unix_timestamp(f.datei) as di";
$sql .= " FROM llx_fichinter as f, societe as s";
$sql .= " WHERE s.idp = f.fk_soc AND f.rowid = $idfiche";
my $sth = $dbh->prepare("$sql") || die $dbh->errstr ;
if ( $sth->execute ) {
@ -78,174 +79,108 @@ if ( $sth->execute ) {
}
while (my $hsr = $sth->fetchrow_hashref ) {
$numpropale = $hsr->{"ref"};
$numfiche = $hsr->{"ref"};
$societe = $hsr->{"nom"};
$destinataire = $hsr->{"firstname"} . " " . $hsr->{"name"};
$date = $hsr->{"dp"};
$date = $hsr->{"di"};
$address = $hsr->{"address"};
$ville = $hsr->{"cp"} . " " . $hsr->{"ville"};
$price = $hsr->{"price"};
$remise = $hsr->{"remise"};
$tva = $hsr->{"tva"};
$total = $hsr->{"total"};
}
$sth->finish;
} else {
die $dbh->errstr;
}
$outputdir .= "/".$numpropale;
Sys::Syslog::syslog('info', '['.$idpropal.'] Outputdir : ' . $outputdir);
$outputdir .= "/".$numfiche;
Sys::Syslog::syslog('info', '['.$idfiche.'] Outputdir : ' . $outputdir);
unless (-d $outputdir) {
print "Make dir : $outputdir\n" if $verbose > 1;
mkdir($outputdir,0777) || die "cannot mkdir " . $outputdir . ": $!";
}
print "Output in : $outputdir\n" if $verbose > 1;
my $adresse1 = "";
my $adresse2 = "";
#
# Decoupage de l'adresse en 2 lignes
#
#
#
my $headerfilename = "$templatesdir/header.tex";
my $footerfilename = "$templatesdir/footer.tex";
my $bodyfilename = "$templatesdir/body.tex";
unless (open (FC, ">$outputdir/$numpropale.tex") ) {
print "can't write in $outputdir/$numpropale.tex: $!";
Sys::Syslog::syslog('info', '['.$idpropal.'] ' . $outputdir/$numpropale.'.tex opened');
Sys::Syslog::syslog('info', '['.$idpropal.'] ' . $!);
my ($adresse2, $adresse1) = ("",$address);
$_ = $address;
if (/^(.*)\n(.*)/) {
$adresse1 = "$1";
$adresse2 = "$2";
print "|$adresse1|\n";
print "|$adresse2|\n";
}
print "|$address|\n";
#
# Header
#
open (FH, "<$headerfilename") || die "can't open $headerfilename: $!";
while (<FH>) {
s|\#SOCIETE\#|$societe|g;
s|\#DESTINATAIRE\#|$destinataire|g;
s|\#ADRESSE1\#|$adresse1|g;
s|\#ADRESSE2\#|$adresse2|g;
s|\#VILLE\#|$ville|g;
#
my $bodyfilename = "$templatesdir/fichinter.tex";
s|\#NUMPROPALE\#|$numpropale|g;
s|\#DATE\#|$date|g;
print FC $_;
unless (open (FC, ">$outputdir/$numfiche.tex") ) {
print "can't write in $outputdir/$numfiche.tex: $!";
Sys::Syslog::syslog('info', '['.$idfiche.'] ' . $!);
} else {
Sys::Syslog::syslog('info', '['.$idfiche.'] ' . $outputdir.'/'.$numfiche.'.tex opened');
}
close (FH);
$date = strftime("%A %d %B %Y", localtime($date));
#
# Body
#
my $totalht = 0;
my ($qty, $ref, $pu, $pricep, $label);
#
my $sql = "SELECT p.price, pr.ref, pr.label, pr.description";
$sql .= " FROM llx_propaldet as p, llx_product as pr WHERE p.fk_propal = $idpropal AND p.fk_product = pr.rowid";
$sth = $dbh->prepare("$sql") || die $dbh->errstr ;
if ( $sth->execute ) {
while (my $hsr = $sth->fetchrow_hashref ) {
$label = $hsr->{"label"};
$ref = $hsr->{"ref"};
$societe = $hsr->{"nom"};
$qty = 1 ;
$pu = sprintf("%.2f", $hsr->{"price"});
$pricep = sprintf("%.2f", $hsr->{"price"});
open (FH, "<$bodyfilename") || die "can't open $bodyfilename: $!";
while (<FH>) {
s|\#LABEL\#|$hsr->{"description"}|g;
s|\#QTY\#|$qty|g;
s|\#REF\#|$ref|g;
s|\#PU\#|$pu|g;
s|\#PRICE\#|$pricep|g;
print FC $_;
}
close (FH);
}
$sth->finish;
}
#
#
#
$totalht = $price - $remise ;
my $francsht = $totalht * 6.55957;
my $francsttc = $total * 6.55957;
#
# Footer
#
$price = sprintf("%.2f", $price);
$remise = sprintf("%.2f", $remise);
$totalht = sprintf("%.2f", $totalht);
$tva = sprintf("%.2f", $tva);
$total = sprintf("%.2f", $total);
$francsttc = sprintf("%.2f", $francsttc);
$francsht = sprintf("%.2f", $francsht);
$date = strftime("%d/%m/%Y", localtime($date));
#
open (FF, "<$footerfilename") || die "can't open $footerfilename: $!";
while (<FF>) {
open (FH, "<$bodyfilename") || die "can't open $bodyfilename: $!";
while (<FH>) {
s|\#SOCIETE\#|$societe|g;
s|\#ADRESSE1\#|$adresse1|g;
s|\#ADRESSE2\#|$adresse2|g;
s|\#VILLE\#|$ville|g;
s|\#DATE\#|$date|g;
s|\#TOTALHT\#|$totalht|g;
s|\#FRANCSHT\#|$francsht|g;
s|\#REMISEHT\#|$remise|g;
s|\#TVA\#|$tva|g;
s|\#TOTALTTC\#|$total|g;
s|\#FRANCSTTC\#|$francsttc|g;
s|\#NUMFICHE\#|$numfiche|g;
print FC $_;
}
close (FF);
close (FH);
#
#
#
close (FC);
$dbh->disconnect if $dbh;
#
system("cd $outputdir/ ; recode -d iso8859-1..ltex < $numfiche.tex > recode-$numfiche.tex");
#
#
print "Generate dvi file<br>\n";
system("cd $outputdir/ ; latex $numpropale.tex ");
system("cd $outputdir/ ; latex recode-$numfiche.tex ");
#
#
#
if ($do_pdf) {
print "<p>Generate pdf file<br>\n";
system("cd $outputdir/ ; pdflatex $numpropale.tex > /dev/null");
system("cd $outputdir/ ; pdflatex recode-$numfiche.tex > /dev/null");
system("cd $outputdir/ ; mv recode-$numfiche.pdf $numfiche.pdf > /dev/null");
}
#
#
#
if ($do_ps) {
print "Generate ps file\n";
system("cd $outputdir/ ; dvips $numpropale.dvi -o $numpropale.ps > /dev/null");
system("cd $outputdir/ ; dvips recode-$numfiche.dvi -o $numfiche.ps > /dev/null");
}
#
# $outputdir/$numpropale.tex
# $outputdir/$numfiche.tex
#
if ($do_fax) {
print "Generate fax file\n";
system("gs -q -sDEVICE=tiffg3 -dNOPAUSE -sOutputFile=$outputdir/$numpropale.%03d $outputdir/$numpropale.ps </dev/null");
system("gs -q -sDEVICE=tiffg3 -dNOPAUSE -sOutputFile=$outputdir/$numfiche.%03d $outputdir/$numfiche.ps </dev/null");
}
Sys::Syslog::syslog('info', 'End propale '.$idpropal);
Sys::Syslog::syslog('info', 'End propale '.$idfiche);
Sys::Syslog::closelog();
#
#
#
#
# export DBI_DSN="dbi:mysql:dbname=lolixfr:host=espy" ; ../scripts/propal-tex.pl
#