* Copyright (C) 2004 Destailleur Laurent * 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$ * */ /** \todo Ce fichier ne semble plus utilisé. A virer ? NON Il est utilisé ! */ require("./pre.inc.php"); $user->getrights('facture'); $user->getrights('propale'); if (!$user->rights->propale->lire) accessforbidden(); require("../lib/CMailFile.class.php"); /* * Modules optionnels */ require("../project.class.php"); require("../propal.class.php"); require("../actioncomm.class.php"); /* * Sécurité accés client */ if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } if ($_GET["action"] == 'setstatut') { /* * Classée la facture comme facturée */ $propal = new Propal($db); $propal->id = $_GET["propalid"]; $propal->cloture($user, $_GET["statut"], $note); } llxHeader(); if ( $action == 'delete' ) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = $propalid;"; if ( $db->query($sql) ) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."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; } /* * * Mode fiche * * */ if ($_GET["propalid"]) { $propal = new Propal($db); $propal->fetch($_GET["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 ".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; $result = $db->query($sql); if ( $result ) { $obj = $db->fetch_object($result); 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 ; print ""; /* * */ print ''; /* * */ print ""; $file = $conf->propal->dir_output. "/$obj->ref/$obj->ref.pdf"; $relativepath = "$obj->ref/$obj->ref.pdf"; if (file_exists($file)) { print ''; } print ''; /* * */ print ''; print ''; print "
'.$langs->trans("Company").''.$obj->nom.'Note :
". nl2br($obj->note)."
'.$langs->trans("Date").''.dolibarr_print_date($obj->dp).'
'.$langs->trans("Project").''; print ''; print $projet->title.'
Destinataire$obj->firstname $obj->name <$obj->email>
".$langs->trans("AmountHT")."".price($obj->price + $obj->remise)." euros
".$langs->trans("Discount")."".price($obj->remise)." euros
".$langs->trans("TotalHT")."".price($totalht)." euros
'.$langs->trans("Author").''; $author = new User($db, $obj->fk_user_author); $author->fetch(''); print $author->fullname.'
".$langs->trans("Propal")." PDF'.$obj->ref.'.pdf
'.$langs->trans("Status").' :'.$obj->lst.'
"; if ($action == 'statut') { print "

id."\" method=\"post\">"; print ""; print "'; print '

'; print "
"; } print ""; /* * */ print "
"; /* * Factures associees */ $sql = "SELECT f.facnumber, f.total,".$db->pdate("f.datef")." as df, f.rowid as facid, f.fk_user_author, f.paye"; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."fa_pr as fp WHERE fp.fk_facture = f.rowid AND fp.fk_propal = ".$propal->id; $result = $db->query($sql); if ($result) { $num_fac_asso = $db->num_rows(); $i = 0; $total = 0; print "
"; if ($num_fac_asso > 1) { print_titre("Factures associées"); } else { print_titre("Facture associée"); } print ''; print ""; print ''; print ''; print ''; print ''; print "\n"; $var=True; while ($i < $num_fac_asso) { $objp = $db->fetch_object(); $var=!$var; print ""; print "\n"; print "\n"; if ($objp->fk_user_author <> $user->id) { $fuser = new User($db, $objp->fk_user_author); $fuser->fetch(); print "\n"; } else { print "\n"; } print ''; print ""; $total = $total + $objp->total; $i++; } print "\n"; print "
'.$langs->trans("Ref").''.$langs->trans("Date").''.$langs->trans("Author").''.$langs->trans("Price").'
facid\">$objp->facnumber"; if ($objp->paye) { print " (payée)"; } print "".strftime("%d %B %Y",$objp->df)."".$fuser->fullname."".$user->fullname."'.price($objp->total).'
".$langs->trans("TotalHT").": $total ".$conf->monnaie."
"; $db->free(); } print "
"; /* * Que si le module commande est actif ! * */ 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[$i].""; print "
Commandes rattachées
'.$coms[$i]."
"; } } /* * * Actions * */ if ($obj->statut <> 4 && $user->societe_id == 0) { print '
'; if ($obj->statut == 2 && $user->rights->facture->creer) { print '"; } else { print ''; } print ''; print ''; print ''; if ($obj->statut == 2 && $num_fac_asso) { print ""; } else { print ''; } print "
'; print "id."&action=create\">Emettre une facture----[id."&action=setstatut&statut=4\">Facturée]-
"; } /* * */ } else { print "Num rows = " . $db->num_rows(); print "

$sql"; } /* * Produits */ print_titre("Produits"); print ''; print ""; print ''; print ''; $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.price, pt.qty, p.rowid as prodid, pt.remise_percent"; $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"; if ($db->query($sql)) { $num = $db->num_rows(); $i = 0; $var=True; while ($i < $num) { $objp = $db->fetch_object(); $var=!$var; print "\n"; print ''; print ""; print ''; print "\n"; $i++; } } $sql = "SELECT pt.rowid, pt.description as product, pt.price, pt.qty, pt.remise_percent"; $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt WHERE pt.fk_propal = ".$propal->id." AND pt.fk_product = 0"; $sql .= " ORDER BY pt.rowid ASC"; if ($db->query($sql)) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $objp = $db->fetch_object(); $var=!$var; print "\n"; print ''; print ''; print ''; print "\n"; $i++; } } else { print $sql; } print '
'.$langs->trans("Ref").''.$langs->trans("Product").''.$langs->trans("Price").''.$langs->trans("Discount").''.$langs->trans("Qty").'
[$objp->ref]'.$objp->product.'".price($objp->price)."'.$objp->remise_percent.' %".$objp->qty."
 '.$objp->product.''.price($objp->price).''.$objp->remise_percent.' %".$objp->qty."
'; /* * 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 '

Cacher le 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"; } if ($page == -1) { $page = 0 ; } $pageprev = $page - 1; $pagenext = $page + 1; $limit = $conf->liste_limit; $offset = $limit * $page ; $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.price, p.ref,".$db->pdate("p.datep")." as dp, 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 AND p.fk_statut in(2,4)"; 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 $sortorder, p.rowid DESC "; $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","","&year=$year&viewstatut=$viewstatut",'',$sortfield); print_liste_field_titre($langs->trans("Company"),"propal.php","s.nom","&viewstatut=$viewstatut","",'',$sortfield); print_liste_field_titre($langs->trans("Date"),"propal.php","p.datep","&viewstatut=$viewstatut","",'align="right" colspan="2"',$sortfield); print_liste_field_titre($langs->trans("Price"),"propal.php","p.price","&viewstatut=$viewstatut","",'align="right"',$sortfield); print_liste_field_titre($langs->trans("Status"),"propal.php","p.fk_statut","&viewstatut=$viewstatut","",'align="center"',$sortfield); print "\n"; while ($i < min($num, $limit)) { $objp = $db->fetch_object(); $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"; $i++; } print "
'.img_object($langs->trans("ShowPropal"),"propal")." \n"; print ''.$objp->ref."idp\">$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
"; $db->free(); } else { print $db->error(); print "
$sql"; } } $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>