* Copyright (C) 2004 Laurent Destailleur * * 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. * * $Id$ * $Source$ * */ /** * Gestion d'une proposition commerciale * @package propale */ require("./pre.inc.php"); $user->getrights('propale'); if (!$user->rights->propale->lire) accessforbidden(); /* * Modules optionnels */ require("../project.class.php"); require("./propal_model_pdf.class.php"); require("../propal.class.php"); require("../actioncomm.class.php"); require("../lib/CMailFile.class.php"); /* * Sécurité accés client */ if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } /******************************************************************************/ /* Actions */ /******************************************************************************/ if ($HTTP_POST_VARS["action"] == 'confirm_delete' && $HTTP_POST_VARS["confirm"] == yes) { if ($user->rights->propale->supprimer ) { $propal = new Propal($db, 0, $propalid); $propal->delete(); $propalid = 0; $brouillon = 1; } Header("Location: propal.php"); } if ($HTTP_POST_VARS["action"] == 'add') { $propal = new Propal($db, $_GET["socidp"]); $propal->datep = mktime(12, 1 , 1, $HTTP_POST_VARS["remonth"], $HTTP_POST_VARS["reday"], $HTTP_POST_VARS["reyear"]); $propal->duree_validite = $HTTP_POST_VARS["duree_validite"]; $propal->contactid = $HTTP_POST_VARS["contactidp"]; $propal->projetidp = $HTTP_POST_VARS["projetidp"]; $propal->modelpdf = $HTTP_POST_VARS["modelpdf"]; $propal->author = $user->id; $propal->note = $HTTP_POST_VARS["note"]; $propal->ref = $HTTP_POST_VARS["ref"]; for ($i = 1 ; $i <= PROPALE_NEW_FORM_NB_PRODUCT ; $i++) { $xid = "idprod".$i; $xqty = "qty".$i; $xremise = "remise".$i; $propal->add_product($HTTP_POST_VARS[$xid],$HTTP_POST_VARS[$xqty],$HTTP_POST_VARS[$xremise]); } $id = $propal->create(); /* * Generation */ if ($id) { propale_pdf_create($db, $id, $HTTP_POST_VARS["modelpdf"]); $propalid = $id; } } if ($action == 'pdf') { $propal = new Propal($db); $propal->fetch($propalid); propale_pdf_create($db, $propalid, $propal->modelpdf); } if ($HTTP_POST_VARS["action"] == 'setstatut' && $user->rights->propale->cloturer) { /* * Cloture de la propale */ $propal = new Propal($db); $propal->fetch($_GET["propalid"]); $propal->cloture($user, $HTTP_POST_VARS["statut"], $HTTP_POST_VARS["note"]); } if ($_GET["action"] == 'commande') { /* * Cloture de la propale */ $propal = new Propal($db); $propal->fetch($propalid); $propal->create_commande($user); } if ($action == 'modif' && $user->rights->propale->creer) { /* * Repasse la propale en mode brouillon */ $propal = new Propal($db); $propal->fetch($propalid); $propal->reopen($user->id); } if ($HTTP_POST_VARS["addligne"] == 'Ajouter' && $user->rights->propale->creer) { /* * Ajout d'une ligne produit dans la propale */ if ($HTTP_POST_VARS["idprod"]) { $propal = new Propal($db); $propal->fetch($propalid); $propal->insert_product($HTTP_POST_VARS["idprod"], $HTTP_POST_VARS["qty"], $HTTP_POST_VARS["remise"]); propale_pdf_create($db, $_GET["propalid"], $propal->modelpdf); } } if ($HTTP_POST_VARS["addproduct"] == 'Ajouter' && $user->rights->propale->creer) { /* * Ajout d'une ligne produit dans la propale */ if (strlen($HTTP_POST_VARS["np_desc"]) && strlen($HTTP_POST_VARS["np_price"])) { $propal = new Propal($db); $propal->fetch($propalid); $propal->insert_product_generic($HTTP_POST_VARS["np_desc"], $HTTP_POST_VARS["np_price"], $HTTP_POST_VARS["np_qty"], $HTTP_POST_VARS["np_tva_tx"], $HTTP_POST_VARS["np_remise"]); } } if ($HTTP_POST_VARS["action"] == 'setremise' && $user->rights->propale->creer) { $propal = new Propal($db); $propal->fetch($propalid); $propal->set_remise($user, $HTTP_POST_VARS["remise"]); propale_pdf_create($db, $_GET["propalid"], $propal->modelpdf); } if ($HTTP_POST_VARS["action"] == 'setpdfmodel' && $user->rights->propale->creer) { $propal = new Propal($db, 0, $propalid); $propal->set_pdf_model($user, $HTTP_POST_VARS["modelpdf"]); propale_pdf_create($db, $propalid, $HTTP_POST_VARS["modelpdf"]); } if ($action == 'del_ligne' && $user->rights->propale->creer) { /* * Supprime une ligne produit dans la propale */ $propal = new Propal($db); $propal->fetch($propalid); $propal->delete_product($ligne); propale_pdf_create($db, $_GET["propalid"], $propal->modelpdf); } if ($_GET["valid"] == 1 && $user->rights->propale->valider) { $propal = new Propal($db); $propal->fetch($_GET["propalid"]); $propal->update_price($_GET["propalid"]); propale_pdf_create($db, $_GET["propalid"], $propal->modelpdf); $propal->valid($user); } llxHeader(); /******************************************************************************/ /* Fin des Actions */ /******************************************************************************/ /* * * Mode fiche * * */ if ($_GET["propalid"]) { $html = new Form($db); $propal = new Propal($db); $propal->fetch($_GET["propalid"]); /* * */ print ""; print ""; print "
Proposition commerciale : $propal->ref
"; /* * Confirmation de la suppression de la propale * */ if ($action == 'delete') { $html->form_confirm("$PHP_SELF?propalid=$propal->id","Supprimer la proposition","Etes-vous sûr de vouloir supprimer cette proposition ?","confirm_delete"); } /* * */ $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 ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c, ".MAIN_DB_PREFIX."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 = $propal->id"; if ($socidp) { $sql .= " AND s.idp = $socidp"; } $result = $db->query($sql); if ( $result ) { $obj = $db->fetch_object( 0 ); if ($db->num_rows()) { $color1 = "#e0e0e0"; print ""; print ''; print ''; print ''; print ''; print ""; print '"; if ($obj->fk_projet) { $projet = new Project($db); $projet->fetch($obj->fk_projet); print ''; } /* * */ print ''; print ''; /* * */ print ''; print ''; /* * */ print ''; print ''; /* * */ print "
Société'.$obj->nom.'Statut'.$obj->lst.'
Date'.strftime("%A %d %B %Y",$obj->dp); if ($propal->fin_validite) { print " (".strftime("%d %B %Y",$propal->fin_validite).")"; } print 'Auteur'; $author = new User($db, $obj->fk_user_author); $author->fetch(''); print $author->fullname.'
Destinataire$obj->firstname $obj->name <$obj->email>Note :
'. nl2br($propal->note)."
Projet'; print ''; print $projet->title.'
Remise'.$propal->remise_percent.' % '.price($propal->remise).' euros
Montant HT'.price($obj->price + $obj->remise).' eurosTVA'.price($propal->total_tva).' euros
Total HT'.price($obj->price).' eurosTotal TTC'.price($propal->total_ttc).' euros
"; if ($_GET["action"] == 'statut') { print "
id\" method=\"post\">"; print '
'; print ''; print "
Clôturer comme : '; print "'; print '
Commentaires :
"; } /* * * */ /* * Produits */ print_titre("Produits"); print '
'; print ''; print ""; print ""; print ''; if ($propal->statut == 0) { print ""; } print "\n"; $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.price, pt.qty, p.rowid as prodid, pt.tva_tx, pt.remise_percent, pt.subprice"; $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt, ".MAIN_DB_PREFIX."product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = $propal->id"; $sql .= " ORDER BY pt.rowid ASC"; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); $i = 0; $var=True; while ($i < $num) { $objp = $db->fetch_object( $i); $var=!$var; print ""; print "\n"; print ''; print ''; print "\n"; print ''; print ''; if ($obj->statut == 0 && $user->rights->propale->creer) { print ''; } else { print ''; } print ""; $i++; } } $sql = "SELECT pt.rowid, pt.description, pt.price, pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice"; $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt WHERE pt.fk_propal = $propal->id AND pt.fk_product = 0"; if ($db->query($sql)) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $objp = $db->fetch_object( $i); $var=!$var; print "\n"; print ''; print ''; print "\n"; print ''; print ""; if ($obj->statut == 0 && $user->rights->propale->creer) { print ''; } else { print ''; } print ""; $i++; } } if ($obj->statut == 0 && $user->rights->propale->creer) { $sql = "SELECT p.rowid,p.label,p.ref,p.price FROM ".MAIN_DB_PREFIX."product as p WHERE p.envente=1 ORDER BY p.nbvente DESC LIMIT 20"; // RyXéo on a ORDER BY p.ref et pas de limit if ( $db->query($sql) ) { $opt = ""; if ($result) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $objp = $db->fetch_object( $i); $opt .= "\n"; $i++; } } $db->free(); } else { print $db->error(); } /* * Produits génériques * */ $var=!$var; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; /* * Produits * */ $var=!$var; print ""; print ''; print ''; print ''; print ''; print "\n"; } print "
RéfProduitTvaQté.RemiseP.U. 
[$objp->ref]'.$objp->product.''.$objp->tva_tx.' %".$objp->qty."'.$objp->remise_percent.' %'.price($objp->subprice).''; print img_delete(); print '-
 '.$objp->description.''.$objp->tva_tx.' %".$objp->qty."'.$objp->remise_percent.' %".price($objp->subprice)."'; print img_delete(); print '-
 '; print $html->select_tva("np_tva_tx") . ' %
  % 
"; print '
'; if ($propal->brouillon == 1) { print '
'; print ''; print '
Remise'; print '%'; print ''; print '
'; } /* * Actions */ if ($obj->statut < 2) { print '

'; if ($obj->statut == 0) { if ($user->rights->propale->supprimer) { print ""; } else { print ""; } } else { if ($obj->statut == 1 && $user->rights->propale->cloturer) { print ""; } else { print ""; } } print ''; /* * */ if ($obj->statut < 2 && $user->rights->propale->creer) { print '"; } else { print ''; } /* * */ if ($obj->statut == 1) { $file = PROPALE_OUTPUTDIR. "/$obj->ref/$obj->ref.pdf"; if (file_exists($file)) { if ($user->rights->propale->envoyer) { print ""; } else { print ''; } } else { print ''; } } else { print ""; } /* * */ if ($obj->statut == 0) { if ($user->rights->propale->valider) { print ""; } else { print ''; } } elseif ($obj->statut == 1) { if ($user->rights->propale->creer) { print ""; } else { print ''; } } else { print ''; } print "
id&action=delete\">Supprimer-id&action=statut\">Cloturer--id&action=pdf\">Générer-"; print "id&action=presend\">Envoyer la proposition-! Proposition non génerée !-id&valid=1\">Valider-id&action=modif\">Modifier--
"; } /* * Envoi de la propale par mail * */ if ($action == 'send') { $file = PROPALE_OUTPUTDIR . "/$obj->ref/$obj->ref.pdf"; if (file_exists($file)) { $subject = "Notre proposition commerciale $obj->ref"; $filepath[0] = $file ; $filename[0] = "$obj->ref.pdf"; $mimetype[0] = "application/pdf"; $filepath[1] = $_FILES['addedfile']['tmp_name']; $filename[1] = $_FILES['addedfile']['name']; $mimetype[1] = $_FILES['addedfile']['type']; $replyto = "$replytoname <$replytomail>"; $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$sendtocc); if (! $mailfile->sendfile() ) { print "!! erreur d'envoi"; } } /* * Enregistre l'action * */ $actioncomm = new ActionComm($db); $actioncomm->priority = 2; $actioncomm->type = 3; $actioncomm->date = $db->idate(time()); $actioncomm->percent = 100; $actioncomm->contact = $propal->contactid; $actioncomm->user = $user; $actioncomm->societe = $propal->socidp; $actioncomm->propalrowid = $propal->id; $actioncomm->note = "Envoyée à $sendto"; $actioncomm->add($user); } /* * */ if ($propal->brouillon == 1) { print '

'; print ''; } print '
'; print_titre('Documents'); print ''; $file = PROPALE_OUTPUTDIR . "/$obj->ref/$obj->ref.pdf"; if (file_exists($file)) { print ""; print ''; print ''; print ''; } if ($propal->brouillon == 1) { print "'; } print "
PDF'.$propal->ref.'.pdf'.filesize($file). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'
Modèle"; $html = new Form($db); $modelpdf = new Propal_Model_pdf($db); $html->select_array("modelpdf",$modelpdf->liste_array(),$propal->modelpdf); print ''; print '
\n"; /* * */ $nb_commande = sizeof($propal->commande_liste_array()); if ($nb_commande > 0) { $coms = $propal->commande_liste_array(); print '
'; print "\n"; for ($i = 0 ; $i < $nb_commande ; $i++) { print '\n"; print "\n"; } print "
Commande Num.
'.$coms[$i]."
"; } // print 'Générer"; /* * */ print "
"; /* * */ $sql = "SELECT ".$db->pdate("a.datea"). " as da, note, fk_user_author" ; $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a WHERE a.fk_soc = $obj->idp AND a.propalrowid = $propal->id "; if ( $db->query($sql) ) { $num = $db->num_rows(); $i = 0; $total = 0; if ($num > 0) { print_titre("Propale envoyée"); 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 ($propal->brouillon == 1) { print ''; } /* * * */ if ($action == 'presend') { $replytoname = $user->fullname; $replytomail = $user->email; $from_name = $user->fullname ; //$conf->propal->fromtoname; $from_mail = $user->email; //conf->propal->fromtomail; $message = "Veuillez trouver ci-joint notre proposition commerciale $obj->ref\n\nCordialement\n\n"; print "
id&action=send\">\n"; print "\n"; print "\n"; print ''; print_titre("Envoyer la propale par mail"); print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print "
Destinatairefirstname)) . " " . ucfirst(strtolower($obj->name)) . " <$obj->email>\">
Copie à
Expediteur$from_name$from_mail
Reply-to$replytoname$replytomail
Joindre un fichier en plus de la propale
(conditions générales de ventes ...)
Message
"; 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.datep"; } if ($sortorder == "") { $sortorder="DESC"; } $limit = $conf->liste_limit; $offset = $limit * $_GET["page"] ; $pageprev = $_GET["page"] - 1; $pagenext = $_GET["page"] + 1; $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.price, p.ref,".$db->pdate("p.datep")." as dp,".$db->pdate("p.fin_validite")." as dfv, c.label as statut, c.id as statutid"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c WHERE p.fk_soc = s.idp AND p.fk_statut = c.id"; if ($socidp) { $sql .= " AND s.idp = $socidp"; } if ($_GET["viewstatut"] <> '') { $sql .= " AND c.id = ".$_GET["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"; } if (strlen($HTTP_POST_VARS["sf_ref"]) > 0) { $sql .= " AND p.ref like '%".$HTTP_POST_VARS["sf_ref"] . "%'"; } $sql .= " ORDER BY $sortfield $sortorder"; $sql .= $db->plimit($limit + 1,$offset); if ( $db->query($sql) ) { $num = $db->num_rows(); print_barre_liste("Propositions commerciales", $_GET["page"], $PHP_SELF,"&socidp=$socidp",$sortfield,$sortorder,'',$num); $i = 0; print ''; print ''; print_liste_field_titre_new ("Réf",$PHP_SELF,"p.ref","","&socidp=$socidp",'width="15%"',$sortfield); print_liste_field_titre_new ("Société",$PHP_SELF,"s.nom","","&socidp=$socidp",'width="30%"',$sortfield); print_liste_field_titre_new ("Date",$PHP_SELF,"p.datep","","&socidp=$socidp", 'width="25%" align="right" colspan="2"',$sortfield); print_liste_field_titre_new ("Prix",$PHP_SELF,"p.price","","&socidp=$socidp", ' width="20%" align="right"',$sortfield); print_liste_field_titre_new ("Statut",$PHP_SELF,"p.fk_statut","","&socidp=$socidp",'width="10%" align="center"',$sortfield); print "\n"; $var=True; while ($i < min($num,$limit)) { $objp = $db->fetch_object( $i); $now = time(); $var=!$var; print ""; print '\n"; print "\n"; if ( $now > $objp->dfv && $objp->dfv > 0 ) { print ""; } else { print ""; } print "\n"; print "\n"; print "\n"; print "\n"; $total = $total + $objp->price; $subtotal = $subtotal + $objp->price; $i++; } print "
'; print img_file(); print " propalid\">$objp->refidp\">$objp->nom".strftime("%d %b %Y",$objp->dfv)." "; $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
"; $db->free(); } else { print $db->error(); } } $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>