From 499a66225253a9da3c38ea534bb75861c7010e62 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Wed, 3 Jul 2002 12:46:00 +0000 Subject: [PATCH] . --- htdocs/comm/addpropal.php3 | 3 +- htdocs/compta/facture.php3 | 45 +++--- htdocs/compta/resultat/index.php3 | 2 +- htdocs/compta/tex-facture.pl | 251 ++++++++++++++++++++++++++++++ htdocs/fourn/facture/index.php3 | 4 +- htdocs/main.inc.php3 | 2 +- htdocs/user/index.php3 | 2 + mysql/data/data_dev.sql | 24 +-- mysql/tables/llx_product.sql | 4 +- 9 files changed, 296 insertions(+), 41 deletions(-) create mode 100644 htdocs/compta/tex-facture.pl diff --git a/htdocs/comm/addpropal.php3 b/htdocs/comm/addpropal.php3 index b467e94ac01..54369c68372 100644 --- a/htdocs/comm/addpropal.php3 +++ b/htdocs/comm/addpropal.php3 @@ -88,7 +88,7 @@ if ($action == 'add') { llxHeader(); -print_titre("Nouvelle proposition commerciale pour $objsoc->nom"); +print_titre("Nouvelle proposition commerciale"); /* @@ -132,6 +132,7 @@ if ($action == 'create') { $smonth = 1; $syear = date("Y", time()); print ''; + print ''; print "
Société'.$objsoc->nom.'
Date"; $cday = date("d", time()); print ""; - print ""; - print ''; - print "\n"; - print ""; print ""; - print "\n"; + print "\n"; print "\n"; diff --git a/htdocs/compta/tex-facture.pl b/htdocs/compta/tex-facture.pl new file mode 100644 index 00000000000..88979e61d6e --- /dev/null +++ b/htdocs/compta/tex-facture.pl @@ -0,0 +1,251 @@ +#!/usr/bin/perl + +# Copyright (C) 2000-2002 Rodolphe Quiedeville +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# 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/ + +# $Id$ +# $Source$ + +use strict; +use DBI; +use Lolix::Conf; +use Getopt::Long; + Getopt::Long::Configure("bundling"); + + +my $gljroot = $ENV{"GLJROOT"}; + +my($debug, $verbose, $bgcolor, $idfacture, $do_fax, $do_pdf, $do_ps, $html) = (0,0); + +exit unless GetOptions("facture=i" =>\$idfacture, + "gljroot=s" =>\$gljroot, + "fax" =>\$do_fax, + "html" =>\$html, + "ps" =>\$do_ps, + "pdf" =>\$do_pdf, + "v+" =>\$verbose); + +unless ($gljroot) { print "Missing ENV var: GLJROOT is not defined\n"; exit 0; } +unless (defined $ENV{"DBI_DSN"}) { print "Missing ENV var: DBI_DSN is not defined\n"; exit 0; } + +# +# +# + +my $templatesdir = $gljroot . "/scripts/templates/facture"; +my $outputdir = $gljroot . "/www-sys/doc/facture/"; + +my $mdir = "$gljroot/www-sys/doc"; +unless (-d $mdir) { + mkdir($mdir,0777) || die "cannot mkdir " . $mdir . ": $!"; +} +$mdir = "$outputdir"; +unless (-d $mdir) { + mkdir($mdir,0777) || die "cannot mkdir " . $mdir . ": $!"; +} + +my (%CONF) = Lolix::Conf::GetAllConf($gljroot . "/conf/config", 0); +my @countries = Lolix::Conf::GetCountries($gljroot . "/conf/config", 0); + +# +# Fetch datas +# +my ($numpropale, $numfacture, $societe, $remiseht, $date, $destinataire, $ville, $address); +my ($totalht, $francsht,$remise,$tva,$total,$francsttc,$description); + +print "Fetch data\n" if $verbose; +print "
" if ($verbose && $html); + +my $dbh = DBI->connect() || die $DBI::errstr ; # We use env var DBI_DSN to connect to DB + +my $sql = "SELECT f.rowid, f.facnumber, s.nom, f.amount, f.remise, f.tva, f.total, f.datef, s.c_nom, s.c_prenom, p.ref as propalref, s.ville, s.cp, s.address"; +$sql .= " FROM llx_facture as f, societe as s, llx_propal as p, llx_fa_pr as pf "; +$sql .= " WHERE s.idp = f.fk_soc AND pf.fk_facture = f.rowid AND pf.fk_propal = p.rowid AND f.rowid = $idfacture"; + +my $sth = $dbh->prepare("$sql") || die $dbh->errstr ; + +if ( $sth->execute ) { + + while (my $hsr = $sth->fetchrow_hashref ) { + $numfacture = $hsr->{"facnumber"}; + $societe = $hsr->{"nom"}; + $remiseht = $hsr->{"remise"}; + $date = $hsr->{"datef"}; + $destinataire = $hsr->{"datep"}; + $address = $hsr->{"address"}; + $ville = $hsr->{"cp"} . " " . $hsr->{"ville"}; + + $totalht = sprintf("%.2f", $hsr->{"amount"}); + $remise = sprintf("%.2f", $hsr->{"remise"}); + $tva = sprintf("%.2f", $hsr->{"tva"}); + $total = sprintf("%.2f", $hsr->{"total"}); + $francsttc = sprintf("%.2f", ($hsr->{"total"} * 6.55957)); + + $numpropale = $hsr->{"propalref"}; + + } + $sth->finish; +} else { + print "db error\n"; +} +# +# +# +$outputdir .= $numfacture; + +print "outputdir is $outputdir\n" if $verbose ; +print "
" if ($verbose && $html); + +unless (-d $outputdir) { + print "make $outputdir\n" if $verbose ; + print "
" if ($verbose && $html); + + unless ( mkdir($outputdir,0777) ) { + print "failed : $!\n" if $verbose ; + } +} + + +# +# +# +my $headerfilename = "$templatesdir/header.tex"; +my $footerfilename = "$templatesdir/footer.tex"; +my $bodyfilename = "$templatesdir/body.tex"; + + +open (FC, ">$outputdir/$numfacture.tex") || die "can't write in $outputdir/$numfacture.tex: $!"; + +########################################################################################## +# +# Header +# +########################################################################################## +open (FH, "<$headerfilename") || die "can't open $headerfilename: $!"; +while () { + s|\#SOCIETE\#|$societe|g; + s|\#ADDRESS\#|$address|g; + + s|\#VILLE\#|$ville|g; + s|\#DESTINATAIRE\#|$destinataire|g; + + + s|\#NUMFACTURE\#|$numfacture|g; + s|\#DATE\#|$date|g; + + print FC $_; +} +close (FH); +########################################################################################## +# +# BODY +# +########################################################################################## + + +my ($qty, $ref, $pu, $pricep, $label); +# +$sql = "SELECT p.price, pr.ref, pr.label, pr.description"; +$sql .= " FROM llx_propaldet as p, llx_product as pr, llx_fa_pr as fp"; +$sql .= " WHERE p.fk_propal = fp.fk_propal AND p.fk_product = pr.rowid AND fp.fk_facture = $idfacture"; + + +$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 (FB, "<$bodyfilename") || die "can't open $bodyfilename: $!"; + while () { + s|\#LABEL\#|$hsr->{"description"}|g; + s|\#QTY\#|$qty|g; + s|\#REF\#|$ref|g; + s|\#PU\#|$pu|g; + s|\#PRICE\#|$pricep|g; + print FC $_; + } + close (FB); + } + + $sth->finish; +} else { + print "** ERROR\n"; + print "
" if ( $html); +} + +########################################################################################## +# +# Footer +# +########################################################################################## +open (FF, "<$footerfilename") || die "can't open $footerfilename: $!"; +while () { + s|\#SOCIETE\#|$societe|g; + + s|\#DATE\#|$date|g; + s|\#TOTALHT\#|$totalht|g; + + s|\#NUMPROPALE\#|$numpropale|g; + + s|\#FRANCSHT\#|$francsht|g; + + s|\#REMISEHT\#|$remise|g; + s|\#TVA\#|$tva|g; + s|\#TOTALTTC\#|$total|g; + + s|\#FRANCS\#|$francsttc|g; + + print FC $_; +} +close (FF); +########################################################################################## +# +# +# +########################################################################################## + +close (FC); + +$dbh->disconnect if $dbh; +# +# +# +print "**\n** Generate dvi file\n**\n"; +print "
" if ($verbose && $html); +system("cd $outputdir/ ; latex $numfacture.tex "); +# +#exit; + +print "

Generate pdf file
\n"; +print "
" if ($verbose && $html); +system("cd $outputdir/ ; pdflatex $numfacture.tex > /dev/null"); + + +# +print "\n**\n** Generate ps file\n**\n"; + print "
" if ($verbose && $html); +system("cd $outputdir/ ; dvips $numfacture.dvi -o $numfacture.ps > /dev/null"); + +# +# export DBI_DSN="dbi:mysql:dbname=lolixfr:host=espy" ; ../scripts/facture-tex.pl +# diff --git a/htdocs/fourn/facture/index.php3 b/htdocs/fourn/facture/index.php3 index ee63ffc90e5..94b3d72b4bb 100644 --- a/htdocs/fourn/facture/index.php3 +++ b/htdocs/fourn/facture/index.php3 @@ -103,7 +103,7 @@ if ($socid > 0) { */ print_barre_liste("Liste des factures", $page, $PHP_SELF); - $sql = "SELECT s.idp, s.nom, ".$db->pdate("s.datec")." as datec, ".$db->pdate("s.datea")." as datea, s.prefix_comm, fac.amount, fac.paye, fac.libelle, ".$db->pdate("fac.datef")." as datef, fac.rowid as facid"; + $sql = "SELECT s.idp as socid, s.nom, ".$db->pdate("s.datec")." as datec, ".$db->pdate("s.datea")." as datea, s.prefix_comm, fac.amount, fac.paye, fac.libelle, ".$db->pdate("fac.datef")." as datef, fac.rowid as facid"; $sql .= " FROM societe as s, llx_facture_fourn as fac "; $sql .= " WHERE fac.fk_soc = s.idp"; @@ -135,7 +135,7 @@ if ($socid > 0) { print "

"; print "\n"; - print "\n"; + print "\n"; print ''; print "\n"; diff --git a/htdocs/main.inc.php3 b/htdocs/main.inc.php3 index 24751bfdc1e..ef75533eb2f 100644 --- a/htdocs/main.inc.php3 +++ b/htdocs/main.inc.php3 @@ -87,7 +87,7 @@ function top_menu($head) { print 'Calendrier'; }; print ' '; - print ''; + print ''; print ''; print ''; diff --git a/htdocs/user/index.php3 b/htdocs/user/index.php3 index 826b6cdd546..5401b2298f3 100644 --- a/htdocs/user/index.php3 +++ b/htdocs/user/index.php3 @@ -29,6 +29,8 @@ $db = new Db(); * */ +print_titre("Liste des utilisateurs"); + $sql = "SELECT u.rowid, u.name, u.firstname, u.code, u.login, u.module_comm, u.module_compta FROM llx_user as u"; $sql .= " ORDER BY u.name"; diff --git a/mysql/data/data_dev.sql b/mysql/data/data_dev.sql index c0231c99297..9bfe100795b 100644 --- a/mysql/data/data_dev.sql +++ b/mysql/data/data_dev.sql @@ -129,23 +129,23 @@ values (41,4,'Alix','Victor','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net' -- delete from llx_product; -insert into llx_product (ref, label, description, price, duration) -values ('CRRJ452M','Câble Réseaux RJ45 2m','Câble Réseaux RJ45 2m',10,'1 mois'); +insert into llx_product (ref, label, description, price) +values ('CRRJ452M','Câble Réseaux RJ45 2m','Câble Réseaux RJ45 2m',10); -insert into llx_product (ref, label, description, price, duration) -values ('3COMSW8','Switch Cisco 8 ports 100Mbits','Switch Cisco 8 ports 100Mbits',1000,'1 mois'); +insert into llx_product (ref, label, description, price) +values ('3COMSW8','Switch Cisco 8 ports 100Mbits','Switch Cisco 8 ports 100Mbits',1000); -insert into llx_product (ref, label, description, price, duration) -values ('ALPH','Station Alpha Serie 3w','Configuration Alpha',9750,'1 mois'); +insert into llx_product (ref, label, description, price) +values ('ALPH','Station Alpha Serie 3w','Configuration Alpha',9750); -insert into llx_product (ref, label, description, price, duration) -values ('HUB8-10','Hub 8 ports 10Mbits','Hub 8 ports',750,'1 mois'); +insert into llx_product (ref, label, description, price) +values ('HUB8-10','Hub 8 ports 10Mbits','Hub 8 ports',750); -insert into llx_product (ref, label, description, price, duration) -values ('PB-16','Pan. Brass. 16','Panneau de brassage extensible, incluant 1 barre de 16 prises',650,'1 mois'); +insert into llx_product (ref, label, description, price) +values ('PB-16','Pan. Brass. 16','Panneau de brassage extensible, incluant 1 barre de 16 prises',650); -insert into llx_product (ref, label, description, price, duration) -values ('PB-32','Pan. Brass. 32','Panneau de brassage extensible, incluant 2 barres de 16 prises',1200,'1 mois'); +insert into llx_product (ref, label, description, price) +values ('PB-32','Pan. Brass. 32','Panneau de brassage extensible, incluant 2 barres de 16 prises',1200); -- -- diff --git a/mysql/tables/llx_product.sql b/mysql/tables/llx_product.sql index 0d1925b72da..d938d9dcef1 100644 --- a/mysql/tables/llx_product.sql +++ b/mysql/tables/llx_product.sql @@ -21,10 +21,12 @@ create table llx_product ( rowid integer AUTO_INCREMENT PRIMARY KEY, + datec datetime, + tms timestamp, ref varchar(15), label varchar(255), description text, price smallint, - duration varchar(32) + fk_user_author integer );
Facture : '.$obj->facnumber.'
socidp\">Autres factures de $obj->socnom
"; /* * Facture */ print ""; - print ""; + print ""; - print "\n"; - print ""; - print ""; - print ""; + print "\n"; + print ""; - print ""; - print ""; - print ""; + print ''; + print ''; + print ''; - print ""; + print ''; + print ""; print "
Sociétésocidp\">$obj->socnom
Sociétésocidp\">$obj->socnom
date".strftime("%A %d %B %Y",$obj->df)."
Auteur$obj->author
Statut$obj->statut
Paye".$yn[$obj->paye]."
Date".strftime("%A %d %B %Y",$obj->df)."
Auteur$obj->author
Montant".price($obj->amount)."euros HT
TVA".tva($obj->amount)."euros
Total".price($obj->total)."euros TTC
Montant'.price($obj->amount).'euros HT
TVA'.tva($obj->amount).'euros
Total'.price($obj->total).'euros TTC
Statut'.$obj->statut.'Paye".$yn[$obj->paye]."
"; print "
"; @@ -251,7 +248,7 @@ if ($action == 'create') { $num = $db->num_rows(); $i = 0; $total = 0; print "

Paiements"; - echo ''; + echo '
'; print ""; print ""; print ""; @@ -270,14 +267,16 @@ if ($action == 'create') { $total = $total + $objp->amount; $i++; } - print "\n"; - print "\n"; - $resteapayer = $obj->total - $total; - - print ""; - print "\n"; + if ($obj->paye == 0) { + print "\n"; + print "\n"; + + $resteapayer = $obj->total - $total; + print ""; + print "\n"; + } print "
DateType
Total :".price($total)."$_MONNAIE
Facturé :".price($obj->total)."$_MONNAIE
Reste a payer :".price($resteapayer)."$_MONNAIE
Total :".price($total)."$_MONNAIE
Facturé :".price($obj->total)."$_MONNAIE
Reste a payer :".price($resteapayer)."$_MONNAIE
"; $db->free(); } else { diff --git a/htdocs/compta/resultat/index.php3 b/htdocs/compta/resultat/index.php3 index 77c0bfa7951..b354ac06283 100644 --- a/htdocs/compta/resultat/index.php3 +++ b/htdocs/compta/resultat/index.php3 @@ -107,7 +107,7 @@ if ($result) { $var=!$var; print "

 Factures facid\">$objp->facnumber $objp->nomFactures $objp->nom".price($objp->amount)."
facid\">$obj->libellefacid\">$obj->nomsocid\">$obj->nom'.price($obj->amount).'$obj->prefix_comm