diff --git a/htdocs/comm/addpropal.php3 b/htdocs/comm/addpropal.php3
index bb4efa4f920..d543ffdbaa8 100644
--- a/htdocs/comm/addpropal.php3
+++ b/htdocs/comm/addpropal.php3
@@ -49,7 +49,7 @@ print "";
print "";
if ($action == 'add') {
- $propal = new Propal($socidp);
+ $propal = new Propal($db, $socidp);
$propal->remise = $remise;
$propal->datep = $db->idate(mktime(12, 1 , 1, $pmonth, $pday, $pyear));
@@ -67,24 +67,27 @@ if ($action == 'add') {
$propal->add_product($idprod3);
$propal->add_product($idprod4);
- $sqlok = $propal->create($db);
+ $id = $propal->create();
/*
*
* Generation
*
*/
- if ($sqlok) {
+ if ($id) {
print "
Génération du PDF";
- $command = "export DBI_DSN=\"".$GLOBALS["DBI"]."\" ";
- $command .= " ; ../../scripts/propal-tex.pl --propal=$propalid --pdf --gljroot=" . $GLOBALS["GLJ_ROOT"] ;
+ //$DBI = "dbi:mysql:dbname=lolixdev:host=espy:user=rodo";
- //$command .= " ; ../../scripts/fax-tex.pl --propal=$propalid --gljroot=" . $GLOBALS["GLJ_ROOT"] ;
+ $gljroot = "/home/www/dolibarr/dolibarr/htdocs";
+
+ $command = "export DBI_DSN=\"dbi:mysql:dbname=".$conf->db->name.":host=localhost\" ";
+ $command .= " ; ./propal-tex.pl --propal=".$id ." --pdf --output=".$conf->propal->outputdir;
+ $command .= " --templates=".$conf->propal->templatesdir;
$output = system($command);
print "
command : $command
";
-
+ print $output;
} else {
print $db->error();
}
@@ -158,8 +161,8 @@ if ($action == 'create') {
print "";
print "";
- $author = $GLOBALS["REMOTE_USER"];
- print "
| Auteur | $author |
";
+
+ print '| Auteur | '.$user->fullname.' |
';
print "| Num | |
\n";
/*
*
diff --git a/htdocs/comm/facture.php3 b/htdocs/comm/facture.php3
index 48616d11d66..24ad3b65897 100644
--- a/htdocs/comm/facture.php3
+++ b/htdocs/comm/facture.php3
@@ -21,7 +21,7 @@
*/
require("./pre.inc.php3");
-require("../lib/functions.inc.php3");
+
llxHeader();
$db = new Db();
$author = $GLOBALS["REMOTE_USER"];
diff --git a/htdocs/comm/index.php3 b/htdocs/comm/index.php3
index b3dec4b7267..7dc6a469d63 100644
--- a/htdocs/comm/index.php3
+++ b/htdocs/comm/index.php3
@@ -112,37 +112,19 @@ print "";
*
*
*/
-if ($mode == 'search')
-{
- if ($mode-search == 'soc')
- {
- $sql = "SELECT s.idp FROM societe as s, c_stcomm as st ";
- $sql .= " WHERE s.fk_stcomm = st.id AND s.datea IS NOT NULL";
-
- if ($socname)
- {
- $sql .= " AND lower(s.nom) like '%".strtolower($socname)."%'";
- $sortfield = "lower(s.nom)";
- $sortorder = "ASC";
- }
+if ($mode == 'search') {
+ if ($mode-search == 'soc') {
+ $sql = "SELECT s.idp FROM societe as s ";
+ $sql .= " WHERE lower(s.nom) like '%".strtolower($socname)."%'";
+ }
-
- $result = $db->query($sql);
- if ($result)
- {
- if ( $db->num_rows() == 1)
- {
- $obj = $db->fetch_object(0);
- $socid = $obj->idp;
- }
- $db->free();
- }
+ if ( $db->query($sql) ) {
+ if ( $db->num_rows() == 1) {
+ $obj = $db->fetch_object(0);
+ $socid = $obj->idp;
}
- else
- {
-
- }
-
+ $db->free();
+ }
}
diff --git a/htdocs/comm/propal-tex.pl b/htdocs/comm/propal-tex.pl
new file mode 100755
index 00000000000..3f8946f1e79
--- /dev/null
+++ b/htdocs/comm/propal-tex.pl
@@ -0,0 +1,251 @@
+#!/usr/bin/perl
+
+# Copyright (C) 2000-2002 Rodolphe Quiedeville
+#
+# $Id$
+# $Source$
+#
+# 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/
+
+use strict;
+use POSIX;
+use DBI;
+use Sys::Syslog qw(:DEFAULT setlogsock);
+use Getopt::Long;
+ Getopt::Long::Configure("bundling");
+
+Sys::Syslog::setlogsock('unix');
+Sys::Syslog::openlog($0, 'pid', 'daemon');
+
+
+
+my($debug, $verbose, $bgcolor, $idpropal, $do_fax, $do_pdf, $do_ps,
+ $templatesdir, $outputdir) = (0,0);
+
+exit unless GetOptions("propal=i" =>\$idpropal,
+ "fax" =>\$do_fax,
+ "templates=s" =>\$templatesdir,
+ "output=s" =>\$outputdir,
+ "ps" =>\$do_ps,
+ "pdf" =>\$do_pdf,
+ "v+" =>\$verbose);
+
+Sys::Syslog::syslog('info', 'Start propale '.$idpropal);
+Sys::Syslog::syslog('info', '['.$idpropal.'] Start');
+my $DEBUG = 1;
+
+my $mdir = "$outputdir";
+unless (-d $mdir) {
+ mkdir($mdir,0777) || die "cannot mkdir " . $mdir . ": $!";
+}
+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);
+
+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 $sth = $dbh->prepare("$sql") || die $dbh->errstr ;
+if ( $sth->execute ) {
+
+ if (! $sth->rows ) {
+ $sth->finish;
+ $dbh->disconnect if $dbh;
+ print "\n" . $dbh->errstr;
+ print "\n$sql\n";
+ exit ;
+ }
+
+ while (my $hsr = $sth->fetchrow_hashref ) {
+ $numpropale = $hsr->{"ref"};
+ $societe = $hsr->{"nom"};
+ $destinataire = $hsr->{"firstname"} . " " . $hsr->{"name"};
+ $date = $hsr->{"dp"};
+ $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);
+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 = "";
+
+#
+#
+#
+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.'] ' . $!);
+}
+#
+# Header
+#
+open (FH, "<$headerfilename") || die "can't open $headerfilename: $!";
+while () {
+ s|\#SOCIETE\#|$societe|g;
+ s|\#DESTINATAIRE\#|$destinataire|g;
+ s|\#ADRESSE1\#|$adresse1|g;
+ s|\#ADRESSE2\#|$adresse2|g;
+ s|\#VILLE\#|$ville|g;
+
+ s|\#NUMPROPALE\#|$numpropale|g;
+ s|\#DATE\#|$date|g;
+
+ print FC $_;
+}
+close (FH);
+#
+# 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 () {
+ 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 () {
+ 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);
+
+$dbh->disconnect if $dbh;
+#
+#
+#
+print "Generate dvi file
\n";
+system("cd $outputdir/ ; latex $numpropale.tex ");
+#
+#
+#
+if ($do_pdf) {
+ print "Generate pdf file
\n";
+ system("cd $outputdir/ ; pdflatex $numpropale.tex > /dev/null");
+}
+#
+#
+#
+if ($do_ps) {
+ print "Generate ps file\n";
+ system("cd $outputdir/ ; dvips $numpropale.dvi -o $numpropale.ps > /dev/null");
+}
+#
+# $outputdir/$numpropale.tex
+#
+if ($do_fax) {
+ print "Generate fax file\n";
+ system("gs -q -sDEVICE=tiffg3 -dNOPAUSE -sOutputFile=$outputdir/$numpropale.%03d $outputdir/$numpropale.ps db = $DB ;
$this->socidp = $soc_idp;
$this->products = array();
}
@@ -50,7 +52,7 @@ class Propal {
*
*
*/
- Function create($db) {
+ Function create() {
/*
* Total des produits a ajouter
*/
@@ -61,9 +63,9 @@ class Propal {
}
$sql = substr($sql, 0, strlen($sql)-1) . ");";
- if ( $db->query($sql) ) {
- $cprice = $db->result(0, 0);
- $db->free();
+ if ( $this->db->query($sql) ) {
+ $cprice = $this->db->result(0, 0);
+ $this->db->free();
}
/*
* Calcul TVA, Remise
@@ -78,25 +80,28 @@ class Propal {
$sql .= " VALUES ($this->socidp, $this->contactid, $cprice, $this->remise, $tva, $total, $this->datep, now(), '$this->ref', $this->author, '$this->note')";
$sqlok = 0;
- if ( $db->query($sql) ) {
+ if ( $this->db->query($sql) ) {
+
+ $this->id = $this->db->last_insert_id();
+
$sql = "SELECT rowid FROM llx_propal WHERE ref='$this->ref';";
- if ( $db->query($sql) ) {
+ if ( $this->db->query($sql) ) {
/*
* Insertion du detail des produits dans la base
*/
- if ( $db->num_rows() ) {
- $propalid = $db->result( 0, 0);
- $db->free();
+ if ( $this->db->num_rows() ) {
+ $propalid = $this->db->result( 0, 0);
+ $this->db->free();
for ($i = 0 ; $i < sizeof($this->products) ; $i++) {
- $prod = new Product($db, $this->products[$i]);
+ $prod = new Product($this->db, $this->products[$i]);
$prod->fetch();
$sql = "INSERT INTO llx_propaldet (fk_propal, fk_product, price) VALUES ";
$sql .= " ($propalid,". $this->products[$i].", $prod->price) ; ";
- if (! $db->query($sql) ) {
- print $sql . '
' . $db->error() .'
';
+ if (! $this->db->query($sql) ) {
+ print $sql . '
' . $this->db->error() .'
';
}
}
/*
@@ -104,23 +109,22 @@ class Propal {
*/
if ($this->projetidp) {
$sql = "UPDATE llx_propal SET fk_projet=$this->projetidp WHERE ref='$this->ref';";
- $db->query($sql);
+ $this->db->query($sql);
}
}
} else {
- print $db->error() . '
'.$sql;
+ print $this->db->error() . '
'.$sql;
}
} else {
- print $db->error() . '
'.$sql;
+ print $this->db->error() . '
'.$sql;
}
- return 1;
+ return $this->id;
}
/*
*
*
*
*/
-
Function fetch($db, $rowid) {
$sql = "SELECT ref,price,".$db->pdate(datep)."as dp FROM llx_propal WHERE rowid=$rowid;";
@@ -140,6 +144,45 @@ class Propal {
print $db->error();
}
}
+ /*
+ *
+ *
+ *
+ */
+ Function valid($userid) {
+ $sql = "UPDATE llx_propal SET fk_statut = 1, date_valid=now(), fk_user_valid=$userid";
+ $sql .= " WHERE rowid = $this->id;";
+
+ if ($this->db->query($sql) ) {
+ return 1;
+ } else {
+ print $this->db->error() . ' in ' . $sql;
+ }
+ }
+ /*
+ *
+ *
+ *
+ */
+ Function cloture($userid, $statut, $note) {
+ $sql = "UPDATE llx_propal SET fk_statut = $statut, note = '$note', date_cloture=now(), fk_user_cloture=$userid";
+
+ $sql .= " WHERE rowid = $this->id;";
+
+ if ($this->db->query($sql) ) {
+ return 1;
+ } else {
+ print $this->db->error() . ' in ' . $sql;
+ }
+ }
+
+
+
+
+
+
+
+
}
?>
diff --git a/htdocs/comm/propal.php3 b/htdocs/comm/propal.php3
index 21d89836ca6..b5ea62b6851 100644
--- a/htdocs/comm/propal.php3
+++ b/htdocs/comm/propal.php3
@@ -26,17 +26,17 @@ require("../lib/CMailFile.class.php3");
* Modules optionnels
*/
require("projet/project.class.php3");
+require("./propal.class.php3");
/*
*
*/
-$author = $GLOBALS["REMOTE_USER"];
-
llxHeader();
+
print "";
print "| Propositions commerciales | ";
if ($socidp) {
-print "Nouvelle Propal | ";
+print "[Nouvelle Propal] | ";
}
print "Liste | ";
print "CA Prévisionnel | ";
@@ -65,8 +65,13 @@ $pageprev = $page - 1;
$pagenext = $page + 1;
if ($action == 'setstatut') {
- $sql = "UPDATE llx_propal SET fk_statut = $statut, note = '$note' WHERE rowid = $propalid";
- $result = $db->query($sql);
+ /*
+ * Cloture de la propale
+ */
+ $propal = new Propal($db);
+ $propal->id = $propalid;
+ $propal->cloture($user->id, $statut, $note);
+
} elseif ( $action == 'delete' ) {
$sql = "DELETE FROM llx_propal WHERE rowid = $propalid;";
if ( $db->query($sql) ) {
@@ -88,17 +93,15 @@ if ($action == 'setstatut') {
if ($propalid) {
if ($valid == 1) {
- $sql = "SELECT p.fk_soc, p.fk_projet,p.price, p.ref,".$db->pdate("p.datep")." as dp, p.author";
+ $sql = "SELECT p.fk_soc, p.fk_projet,p.price, p.ref,".$db->pdate("p.datep")." as dp";
$sql .= " FROM llx_propal as p WHERE p.rowid = $propalid";
if ( $db->query($sql) ) {
$obj = $db->fetch_object( 0 );
- $sql = "UPDATE llx_propal SET fk_statut = 1 WHERE rowid = $propalid;";
- if (! $db->query($sql) ) {
- print $db->error();
- }
-
+ $propal = new Propal($db);
+ $propal->id = $propalid;
+ $propal->valid($user->id);
} else {
print $db->error();
}
@@ -106,16 +109,10 @@ if ($propalid) {
/*
*
*/
- $sql = "SELECT s.nom, s.idp, p.price, p.fk_projet,p.remise, p.tva, p.total, p.ref,".$db->pdate("p.datep")." as dp, c.id as statut, c.label as lst, p.author, p.note, x.firstname, x.name, x.fax, x.phone, x.email";
+ $sql = "SELECT s.nom, s.idp, p.price, p.fk_projet,p.remise, p.tva, p.total, p.ref,".$db->pdate("p.datep")." as dp, c.id as statut, c.label as lst, p.note, x.firstname, x.name, x.fax, x.phone, x.email, p.fk_user_author, p.fk_user_valid, p.fk_user_cloture, p.datec, p.date_valid, p.date_cloture";
$sql .= " FROM societe as s, llx_propal as p, c_propalst as c, socpeople as x";
$sql .= " WHERE p.fk_soc = s.idp AND p.fk_statut = c.id AND x.idp = p.fk_soc_contact AND p.rowid = $propalid";
-
- /* $sql = "SELECT s.nom, s.idp, p.price, p.remise, p.tva, p.total, p.ref,".$db->pdate("p.datep")." as dp, c.id as statut, c.label as lst, p.author, p.note, x.firstname, x.name, x.fax, x.phone, x.email";
- * $sql .= " FROM societe as s, llx_propal as p, c_propalst as c";
- * $sql .= " WHERE p.fk_soc = s.idp AND p.fk_statut = c.id AND p.rowid = $propalid";
- */
-
$result = $db->query($sql);
if ( $result ) {
@@ -154,7 +151,10 @@ if ($propalid) {
/*
*
*/
- print "
| Auteur | $obj->author | ";
+ print '
| Auteur | ';
+ $author = new User($db, $obj->fk_user_author);
+ $author->fetch('');
+ print $author->fullname.' | ';
$totalht = $obj->price - $obj->remise ;
@@ -195,7 +195,7 @@ if ($propalid) {
print "