* Copyright (C) 2004 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * * 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$ * */ /** \file htdocs/comm/propal.php \ingroup propale \brief Page liste des propales */ require("./pre.inc.php"); $langs->load("companies"); $langs->load("propal"); $langs->load("bills"); $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 ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') { if ($user->rights->propale->supprimer) { $propal = new Propal($db, 0, $_GET["propalid"]); $propal->delete($user); $propalid = 0; $brouillon = 1; } Header("Location: propal.php"); } if ($_POST["action"] == 'add') { $propal = new Propal($db, $_GET["socidp"]); $propal->datep = mktime(12, 1 , 1, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); $propal->duree_validite = $_POST["duree_validite"]; $propal->contactid = $_POST["contactidp"]; $propal->projetidp = $_POST["projetidp"]; $propal->modelpdf = $_POST["modelpdf"]; $propal->author = $user->id; $propal->note = $_POST["note"]; $propal->ref = $_POST["ref"]; for ($i = 1 ; $i <= PROPALE_NEW_FORM_NB_PRODUCT ; $i++) { $xid = "idprod".$i; $xqty = "qty".$i; $xremise = "remise".$i; $propal->add_product($_POST[$xid],$_POST[$xqty],$_POST[$xremise]); } $id = $propal->create(); /* * Generation */ if ($id) { propale_pdf_create($db, $id, $_POST["modelpdf"]); Header ("Location: propal.php?propalid=$id"); } } if ($_GET["action"] == 'pdf') { $propal = new Propal($db); $propal->fetch($_GET["propalid"]); propale_pdf_create($db, $_GET["propalid"], $propal->modelpdf); } if ($_POST["action"] == 'setstatut' && $user->rights->propale->cloturer) { /* * Cloture de la propale */ $propal = new Propal($db); $propal->fetch($_GET["propalid"]); $propal->cloture($user, $_POST["statut"], $_POST["note"]); } if ($_GET["action"] == 'commande') { /* * Cloture de la propale */ $propal = new Propal($db); $propal->fetch($propalid); $propal->create_commande($user); } if ($_GET["action"] == 'modif' && $user->rights->propale->creer) { /* * Repasse la propale en mode brouillon */ $propal = new Propal($db); $propal->fetch($_GET["propalid"]); $propal->reopen($user->id); } if ($_POST["addligne"] == $langs->trans("Add") && $user->rights->propale->creer) { /* * Ajout d'une ligne produit dans la propale */ if ($_POST["idprod"]) { $propal = new Propal($db); $propal->fetch($_GET["propalid"]); $propal->insert_product($_POST["idprod"], $_POST["qty"], $_POST["remise"]); propale_pdf_create($db, $_GET["propalid"], $propal->modelpdf); } } if ($_POST["addproduct"] == $langs->trans("Add") && $user->rights->propale->creer) { /* * Ajout d'une ligne produit dans la propale */ if (strlen($_POST["np_desc"]) && strlen($_POST["np_price"])) { $propal = new Propal($db); $propal->fetch($_GET["propalid"]); $propal->insert_product_generic($_POST["np_desc"], $_POST["np_price"], $_POST["np_qty"], $_POST["np_tva_tx"], $_POST["np_remise"]); } } if ($_POST["action"] == 'setremise' && $user->rights->propale->creer) { $propal = new Propal($db); $propal->fetch($_GET["propalid"]); $propal->set_remise($user, $_POST["remise"]); propale_pdf_create($db, $_GET["propalid"], $propal->modelpdf); } if ($_POST["action"] == 'setpdfmodel' && $user->rights->propale->creer) { $propal = new Propal($db, 0, $_GET["propalid"]); $propal->set_pdf_model($user, $_POST["modelpdf"]); propale_pdf_create($db, $_GET["propalid"], $_POST["modelpdf"]); } if ($_GET["action"] == 'del_ligne' && $user->rights->propale->creer) { /* * Supprime une ligne produit dans la propale */ $propal = new Propal($db); $propal->fetch($_GET["propalid"]); $propal->delete_product($_GET["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(); /* * Affichage fiche propal en mode visu * */ if ($_GET["propalid"]) { $html = new Form($db); $propal = new Propal($db); $propal->fetch($_GET["propalid"]); $societe = new Societe($db); $societe->fetch($propal->soc_id); $h=0; $head[$h][0] = DOL_URL_ROOT.'/comm/propal.php?propalid='.$propal->id; $head[$h][1] = $langs->trans("Card"); $hselected=$h; $h++; $head[$h][0] = DOL_URL_ROOT.'/comm/propal/note.php?propalid='.$propal->id; $head[$h][1] = $langs->trans("Note"); $h++; $head[$h][0] = DOL_URL_ROOT.'/comm/propal/info.php?propalid='.$propal->id; $head[$h][1] = $langs->trans("Info"); $h++; dolibarr_fiche_head($head, $hselected, $langs->trans("Prop").": $propal->ref"); /* * Confirmation de la suppression de la propale * */ if ($_GET["action"] == 'delete') { $html->form_confirm("propal.php?propalid=$propal->id",$langs->trans("DeleteProp"),$langs->trans("ConfirmDeleteProp"),"confirm_delete"); print '
'; } /* * */ $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($result); if ($db->num_rows()) { $color1 = "#e0e0e0"; if ($propal->brouillon == 1 && $user->rights->propale->creer) { /* la form est ouverte avant la table pour respect des normes */ print '
'; print ''; } print ""; $rowspan=4; print ''; print ''; print ''; print ''; $langs->load("mails"); print ""; if ($conf->projet->enabled && $propal->projet_id) $rowspan++; print '"; if ($conf->projet->enabled && $propal->projet_id) { $langs->load("projects"); $projet = new Project($db); $projet->fetch($propal->projet_id); print ''; } /* * */ if ($propal->brouillon == 1 && $user->rights->propale->creer) { print ''; print ''; print ''; } else { print ''; print ''; } print ''; /* * */ print ''; print ''; /* * */ print ''; print ''; /* * */ print "
'.$langs->trans("Company").''; if ($societe->client == 1) { $url ='fiche.php?socid='.$societe->id; } else { $url = DOL_URL_ROOT.'/comm/prospect/fiche.php?socid='.$societe->id; } print ''.$societe->nom.''.$langs->trans("Status").''.$obj->lst.'
'.$langs->trans("Date").''.strftime("%A %d %B %Y",$propal->date); if ($propal->fin_validite) { print " (".strftime("%d %B %Y",$propal->fin_validite).")"; } print ''.$langs->trans("Author").''; $author = new User($db, $obj->fk_user_author); $author->fetch(''); print $author->fullname.'
".$langs->trans("MailTo")."$obj->firstname $obj->name".($obj->email?" <$obj->email>":"")."'.$langs->trans("Note").' :
'. nl2br($propal->note)."
'.$langs->trans("Projects").''; print ''; print $projet->title.'
Remise ?%
Remise'.$propal->remise_percent.' % '.price($propal->remise).' euros
'.$langs->trans("AmountHT").''.price($obj->price + $obj->remise).' euros'.$langs->trans("VAT").''.price($propal->total_tva).' euros
'.$langs->trans("TotalHT").''.price($obj->price).' euros'.$langs->trans("TotalTTC").''.price($propal->total_ttc).' euros

"; if ($propal->brouillon == 1 && $user->rights->propale->creer) { print "
"; } if ($_GET["action"] == 'statut') { print "
id\" method=\"post\">"; print '
'; print ''; print "
Clôturer comme : '; print "'; print '
'.$langs->trans("Comments").' :
"; } /* * Produits */ print_titre($langs->trans("ProductsAndServices")); print '
'; print ''; print ""; print ''; print ''; 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($result); $var=!$var; print ""; print "\n"; print ''; print ''; print "\n"; print ''; print ''; if ($propal->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"; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $objp = $db->fetch_object($result); $var=!$var; print "\n"; print ''; print ''; print "\n"; print ''; print ""; if ($propal->statut == 0 && $user->rights->propale->creer) { print ''; } else { print ''; } print ""; $i++; } } if ($propal->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"; $result = $db->query($sql); if ($result) { $opt = ""; $num = $db->num_rows(); $i = 0; while ($i < $num) { $objp = $db->fetch_object($result); $opt .= "\n"; $i++; } $db->free(); } else { dolibarr_print_error($db); } /* * Ligne d'ajout de produits/services personalisé */ $var=!$var; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print ""; /* * Ligne d'ajout de produits/services prédéfinis */ $var=!$var; print ""; print ''; print ''; print ''; print ''; print "\n"; } print "
'.$langs->trans("Ref").''.$langs->trans("ProductOrService").''.$langs->trans("VAT").''.$langs->trans("Qty").'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",$conf->defaulttx) . "remise_client."\" name=\"np_remise\"> %trans("Add")."\" name=\"addproduct\">
  % 
"; print '

'; } print ''; /* * Barre d'actions */ if ($propal->statut < 2) { print '

'; // Valid if ($propal->statut == 0) { if ($user->rights->propale->valider) { print "id&valid=1\">".$langs->trans("Valid").""; } } // Save if ($propal->statut == 1) { if ($user->rights->propale->creer) { print "id&action=modif\">".$langs->trans("Edit").""; } } // Build PDF if ($propal->statut < 2 && $user->rights->propale->creer) { print ''.$langs->trans("BuildPDF").''; } // Send if ($propal->statut == 1) { if ($user->rights->propale->envoyer) { $file = $conf->propal->dir_output . "/$obj->ref/$obj->ref.pdf"; if (file_exists($file)) { print "id&action=presend\">".$langs->trans("Send").""; } } } // Delete if ($propal->statut == 0) { if ($user->rights->propale->supprimer) { print "id&action=delete\">".$langs->trans("Delete").""; } } // Close if ($propal->statut != 0) { if ($propal->statut == 1 && $user->rights->propale->cloturer) { print "id&action=statut\">".$langs->trans("Close").""; } } print "
"; } /* * Envoi de la propale par mail * */ if ($_GET["action"] == 'send') { $file = $conf->propal->dir_output . "/$propal->ref/$propal->ref.pdf"; if (file_exists($file)) { $subject = "Notre proposition commerciale $propal->ref"; $filepath[0] = $file ; $filename[0] = "$propal->ref.pdf"; $mimetype[0] = "application/pdf"; $filepath[1] = $_FILES['addedfile']['tmp_name']; $filename[1] = $_FILES['addedfile']['name']; $mimetype[1] = $_FILES['addedfile']['type']; $from = $_POST["fromname"] . " <".$_POST["frommail"] .">"; $replyto = $_POST["replytoname"]. " <".$_POST["replytomail"].">"; $mailfile = new CMailFile($subject,$_POST["sendto"],$from,$_POST["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 à ".$_POST["sendto"]; $actioncomm->add($user); } /* * */ if ($propal->brouillon == 1) { print '
'; print ''; } print '
'; print_titre(''.$langs->trans("Document").''); /* * */ print ''; $file = $conf->propal->dir_output . "/$propal->ref/$propal->ref.pdf"; $relativepath = "$propal->ref/$propal->ref.pdf"; $var=true; if (file_exists($file)) { print ""; print ''; print ''; print ''; } if ($propal->brouillon == 1 && $user->rights->propale->creer) { print "'; } print "
".$langs->trans("Propal")." 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"; /* * Si le module commandes est activé ... */ if($conf->commande->enabled) { $nb_commande = sizeof($propal->commande_liste_array()); if ($nb_commande > 0) { $coms = $propal->commande_liste_array(); print '
'; if ($nb_commande == 1) { print "\n"; } else { print "\n"; for ($i = 0 ; $i < $nb_commande ; $i++) { print '\n"; print "\n"; } } print "
Commande rattachée : "; print ''; print img_file(); print ' '.$coms[0].""; print "
Commandes rattachées
'.$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(); print "\n"; $authoract = new User($db); $authoract->id = $objp->fk_user_author; $authoract->fetch(''); print "\n"; print ""; $i++; } print "
".$langs->trans("Date")."".$langs->trans("Author")."
".strftime("%d %B %Y %H:%M:%S",$objp->da)."$authoract->code
$objp->note
"; } $db->free(); } else { dolibarr_print_error($db); } /* * */ print "
"; if ($propal->brouillon == 1) { print '
'; } /* * * */ if ($_GET["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 $propal->ref\n\nCordialement\n\n"; print "
id&action=send\">\n"; print ''; print ''; print ''; print_titre("Envoyer la propale par mail"); // Créé l'objet formulaire mail include_once("../html.formmail.class.php"); $formmail = new FormMail($db); $formmail->fromname = $user->fullname; $formmail->frommail = $user->email; $formmail->withfrom=1; $formmail->withto=ucfirst(strtolower($obj->firstname)) . " " . ucfirst(strtolower($obj->name)) . " <$obj->email>"; $formmail->withcc=1; $formmail->withtopic=1; $formmail->withfile=1; $formmail->withbody=1; // Tableau des substitutions $formmail->substit["__PROPREF__"]=$propal->ref; // Tableau des paramètres complémentaires $formmail->param["action"]="send"; $formmail->param["models"]="propal_send"; $formmail->param["propalid"]=$propal->id; $formmail->param["returnurl"]=DOL_URL_ROOT."/comm/propal.php?propalid=$propal->id"; $formmail->show_form(); } } else { dolibarr_print_error($db); } } else { /**************************************************************************** * * * * * Mode Liste des propales * * * * * ****************************************************************************/ $sortorder=$_GET["sortorder"]; $sortfield=$_GET["sortfield"]; $page=$_GET["page"]; $viewstatut=$_GET["viewstatut"]; if ($sortfield == "") { $sortfield="p.datep"; } if ($sortorder == "") { $sortorder="DESC"; } $limit = $conf->liste_limit; $offset = $limit * $page ; $pageprev = $page - 1; $pagenext = $page + 1; $sql = "SELECT s.nom, s.idp, s.client, 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"; $sql .= " WHERE p.fk_soc = s.idp AND p.fk_statut = c.id"; if ($_GET["socidp"]) { $sql .= " AND s.idp = ".$_GET["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($_POST["sf_ref"]) > 0) { $sql .= " AND p.ref like '%".$_POST["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", $page,"propal.php","&socidp=$socidp",$sortfield,$sortorder,'',$num); $i = 0; print ''; print ''; print_liste_field_titre($langs->trans("Ref"),"propal.php","p.ref","","&socidp=$socidp&viewstatut=$viewstatut",'width="15%"',$sortfield); print_liste_field_titre($langs->trans("Company"),"propal.php","s.nom","","&socidp=$socidp&viewstatut=$viewstatut",'width="30%"',$sortfield); print_liste_field_titre($langs->trans("Date"),"propal.php","p.datep","","&socidp=$socidp&viewstatut=$viewstatut", 'width="25%" align="right" colspan="2"',$sortfield); print_liste_field_titre($langs->trans("Price"),"propal.php","p.price","","&socidp=$socidp&viewstatut=$viewstatut", ' width="20%" align="right"',$sortfield); print_liste_field_titre($langs->trans("Status"),"propal.php","p.fk_statut","","&socidp=$socidp&viewstatut=$viewstatut",'width="10%" align="center"',$sortfield); print "\n"; $var=true; while ($i < min($num,$limit)) { $objp = $db->fetch_object(); $now = time(); $var=!$var; print ""; print '\n"; if ($objp->client == 1) { $url = DOL_URL_ROOT.'/comm/fiche.php?socid='.$objp->idp; } else { $url = DOL_URL_ROOT.'/comm/prospect/fiche.php?socid='.$objp->idp; } print ''; 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->ref'.$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 { dolibarr_print_error($db); } } $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>