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