* * $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. * */ require("./pre.inc.php3"); require("../lib/CMailFile.class.php3"); /* * Modules optionnels */ require("../project.class.php3"); require("../propal.class.php3"); require("../actioncomm.class.php3"); /* * */ llxHeader(); $db = new Db(); /******************************************************************************/ /* Actions */ /******************************************************************************/ if ($action == 'add') { $propal = new Propal($db, $socidp); $propal->remise = $remise; $propal->datep = $db->idate(mktime(12, 1 , 1, $pmonth, $pday, $pyear)); $propal->contactid = $contactidp; $propal->projetidp = $projetidp; $propal->author = $user->id; $propal->note = $note; $propal->ref = $ref; $propal->add_product($idprod1,$qty1); $propal->add_product($idprod2,$qty2); $propal->add_product($idprod3,$qty3); $propal->add_product($idprod4,$qty4); $id = $propal->create(); /* * * Generation * */ if ($id) { //$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 --ps --output=".$conf->propal->outputdir; $command .= " --templates=".$conf->propal->templatesdir; $output = system($command); //print "

command : $command
"; //print $output; /* * Renvoie directement sur la fiche */ //Header("Location: propal.php3?propalid=$id"); $propalid = $id; } else { print $db->error(); } } if ($action == 'setstatut') { /* * 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) ) { $sql = "DELETE FROM llx_propaldet WHERE fk_propal = $propalid ;"; if ( $db->query($sql) ) { print "Propal supprimée"; } else { print $db->error(); print "

$sql"; } } else { print $db->error(); print "

$sql"; } $propalid = 0; $brouillon = 1; } /******************************************************************************/ /* Fin des Actions */ /******************************************************************************/ /* * * Mode fiche * * */ if ($propalid) { $propal = new Propal($db); $propal->fetch($propalid); if ($valid == 1) { $propal->valid($user->id); } /* * */ print ""; print ""; print "
Proposition commerciale : $propal->ref
"; /* * */ $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"; $result = $db->query($sql); if ( $result ) { $obj = $db->fetch_object( 0 ); if ($db->num_rows()) { $color1 = "#e0e0e0"; print ""; print ''; print ""; print ''; if ($obj->fk_projet) { $projet = new Project($db); $projet->fetch($obj->fk_projet); print ''; } print ""; /* * */ print ""; /* * */ print ""; /* * */ $totalht = $propal->price - $propal->remise ; print ""; /* * */ print ''; /* * */ print ""; print ''; print "
Société'.$obj->nom.'Note :
". nl2br($obj->note)."
Date'.strftime("%A %d %B %Y",$obj->dp).'
Projet'; print ''; print $projet->title.'
Destinataire$obj->firstname $obj->name <$obj->email>
Montant HT".price($obj->price)." euros
Remise".price($obj->remise)." euros
Total HT".price($totalht)." euros
Auteur'; $author = new User($db, $obj->fk_user_author); $author->fetch(''); print $author->fullname.'
Statut :$obj->lst
"; if ($action == 'statut') { print "

"; print ""; print "'; print '

'; print "
"; } print ""; print "
"; /* * Produits */ $sql = "SELECT p.label as product, p.ref, pt.price, pt.qty"; $sql .= " FROM llx_propaldet as pt, llx_product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = $propalid"; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); $i = 0; $total = 0; print "

Produits"; print ""; print ""; print ""; print "\n"; $var=True; while ($i < $num) { $objp = $db->fetch_object( $i); $var=!$var; print ""; print "\n"; print "\n"; print "\n"; print ""; $total = $total + $objp->price; $i++; } //print "\n"; print "
RéfProduitPrixQté.
[$objp->ref]$objp->product".price($objp->price)."".$objp->qty."
Total : ".price($total)."Euros HT
"; } /* * */ print "

"; /* * Actions */ print "

"; if ($obj->statut == 0) { print ""; } else { if ($obj->statut == 1) { print ""; } else { print ""; } } print ""; if ($obj->statut == 1) { $file = $conf->propal->outputdir. "/$obj->ref/$obj->ref.pdf"; if (file_exists($file)) { print ""; } else { print ""; } } else { print ""; } if ($obj->statut == 0) { print ""; } else { print ""; } print "
[Supprimer][Cloturer]--"; print "[Envoyer la propale par mail]! Propale non generee !-[Valider]-
"; /* * */ /* * Send * */ if ($action == 'send') { $file = $GLOBALS["GLJ_ROOT"] . "/www-sys/doc/propal/$obj->ref/$obj->ref.pdf"; if (file_exists($file)) { $subject = "Notre proposition commerciale $obj->ref"; $message = "Veuillez trouver ci-joint notre proposition commerciale $obj->ref\n\nCordialement\n\n"; $filepath = $file ; $filename = "$obj->ref.pdf"; $mimetype = "application/pdf"; $replyto = "$replytoname <$replytomail>"; $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype, $filename); if ( $mailfile->sendfile() ) { print "

envoyé à $sendto"; print "

envoyé par ".htmlentities($replyto); } else { print "!! erreur d'envoi"; } } /* * Enregistre l'action * * Ne fonctionne pas, a corriger ! */ if ( $db->query($sql) ) { $sql = "INSERT INTO actioncomm (datea,fk_action,fk_soc, propalrowid,note, fk_user_author) "; $sql .= " VALUES (now(), 3, $obj->idp, $propalid, 'Envoyée à $sendto',$user->id);"; if (! $db->query($sql) ) { print $db->error(); print "

$sql

"; } } else { print $db->error(); } } /* * */ print "
"; print "
"; print "Documents générés
"; print ""; $file = $conf->propal->outputdir. "/$obj->ref/$obj->ref.pdf"; if (file_exists($file)) { print ""; print ''; } $file = $conf->propal->outputdir . "/$obj->ref/$obj->ref.ps"; if (file_exists($file)) { print ""; print ''; print ""; } print ''; $file = $GLOBALS["GLJ_ROOT"] . "/www-sys/doc/propale/$obj->ref/FAX-$obj->ref.ps"; if (file_exists($file)) { print ""; } print "
Propale PDF'.$obj->ref.'.pdf
Propale Postscript'.$obj->ref.'.s
(liste...)
FAX d'entete
\n"; /* * */ print "
"; print "Propale envoyée
"; /* * */ $sql = "SELECT ".$db->pdate("a.datea"). " as da, note, fk_user_author" ; $sql .= " FROM actioncomm as a WHERE a.fk_soc = $obj->idp AND a.propalrowid = $propalid "; if ( $db->query($sql) ) { $num = $db->num_rows(); $i = 0; $total = 0; print ""; print "\n"; while ($i < $num) { $objp = $db->fetch_object( $i); print "\n"; $authoract = new User($db); $authoract->id = $objp->fk_user_author; $authoract->fetch(''); print "\n"; print ""; $i++; } print "
DateAuteur
".strftime("%d %B %Y %H:%M:%S",$objp->da)."$authoract->code
$objp->note
"; $db->free(); } else { print $db->error(); } /* * */ print "
"; /* * * */ if ($action == 'presend') { $sendto = "rq@lolix.org"; $replytoname = $conf->propal->replytoname; $replytomail = $conf->propal->replytomail; $from_name = $user->fullname ; //$conf->propal->fromtoname; $from_mail = $user->email; //conf->propal->fromtomail; print "
\n"; print "\n"; print "\n"; print "\n"; print "

Envoyer la propale par mail"; print ""; print ""; print ""; print ""; print ""; print ""; print "
Destinataire$obj->firstname $obj->nameemail\">
Expediteur$from_name$from_mail
Reply-to$replytoname$replytomail
"; print ""; print "

"; } } else { print "Num rows = " . $db->num_rows(); print "

$sql"; } /* * Voir le suivi des actions * * * */ if ($suivi) { $validor = new User($db, $obj->fk_user_valid); $validor->fetch(''); $cloturor = new User($db, $obj->fk_user_cloture); $cloturor->fetch(''); print 'Suivi des actions
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
 NomDate
Création'.$author->fullname.''.$obj->datec.'
Validation'.$validor->fullname.' '.$obj->date_valid.' 
Cloture'.$cloturor->fullname.' '.$obj->date_cloture.' 
'; } else { print '

Voir le suivi des actions '; } } else { print $db->error(); print "

$sql"; } /* * * * */ } else { /* * * * Mode Liste des propales * * */ if ($sortfield == "") { $sortfield="p.fk_statut, datep "; } if ($sortorder == "") { $sortorder="ASC"; } if ($page == -1) { $page = 0 ; } $limit = 26; $offset = $limit * $page ; $pageprev = $page - 1; $pagenext = $page + 1; print ""; print ""; print "
Propositions commerciales
"; $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.price - p.remise as price, p.ref,".$db->pdate("p.datep")." as dp, c.label as statut, c.id as statutid"; $sql .= " FROM societe as s, llx_propal as p, c_propalst as c WHERE p.fk_soc = s.idp AND p.fk_statut = c.id"; if ($socidp) { $sql .= " AND s.idp = $socidp"; } if ($viewstatut <> '') { $sql .= " AND c.id = $viewstatut"; } if ($month > 0) { $sql .= " AND date_format(p.datep, '%Y-%m') = '$year-$month'"; } if ($year > 0) { $sql .= " AND date_format(p.datep, '%Y') = $year"; } $sql .= " ORDER BY $sortfield ASC"; if ( $db->query($sql) ) { $num = $db->num_rows(); $i = 0; print ""; $oldstatut = -1; $subtotal = 0; while ($i < $num) { $objp = $db->fetch_object( $i); if ($objp->statut <> $oldstatut ) { $oldstatut = $objp->statut; if ($i > 0) { print "\n"; print "\n"; } $subtotal = 0; print ''; print ""; print ""; print "'; print "\n"; $var=True; } $var=!$var; print ""; print "\n"; print "\n"; $now = time(); $lim = 3600 * 24 * 15 ; if ( ($now - $objp->dp) > $lim && $objp->statutid == 1 ) { print ""; } else { print ""; } print "\n"; print "\n"; print "\n"; print "\n"; $total = $total + $objp->price; $subtotal = $subtotal + $objp->price; $i++; } print "\n"; print "\n"; print ""; print ""; print ""; print "
Total : ".price($subtotal)."Euros HT
Réf"; print_liste_field_titre ("Société",$PHP_SELF,"s.nom"); print "DatePrixStatut statutid\">"; print '
propalid\">$objp->refidp\">$objp->nom > 15 jours "; $y = strftime("%Y",$objp->dp); $m = strftime("%m",$objp->dp); print strftime("%d",$objp->dp)."\n"; print " "; print strftime("%B",$objp->dp)."\n"; print " "; print strftime("%Y",$objp->dp)."".price($objp->price)."$objp->statut
Total : ".price($subtotal)."Euros HT
$i propalesTotal : ".price($total)."Euros HT
"; $db->free(); } else { print $db->error(); } } $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>