* Copyright (C) 2004-2005 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$ * */ /** \file htdocs/contrat/fiche.php \ingroup contrat \brief Fiche contrat \version $Revision$ */ require("./pre.inc.php"); require("../project.class.php"); require("../propal.class.php"); require_once (DOL_DOCUMENT_ROOT."/contrat/contrat.class.php"); $langs->load("contracts"); $langs->load("orders"); $langs->load("companies"); $user->getrights('contrat'); if (! $user->rights->contrat->lire) accessforbidden(); $date_start_update=mktime(12, 0 , 0, $_POST["date_start_updatemonth"], $_POST["date_start_updateday"], $_POST["date_start_updateyear"]); $date_end_update=mktime(12, 0 , 0, $_POST["date_end_updatemonth"], $_POST["date_end_updateday"], $_POST["date_end_updateyear"]); $date_start=mktime(12, 0 , 0, $_POST["date_startmonth"], $_POST["date_startday"], $_POST["date_startyear"]); $date_end=mktime(12, 0 , 0, $_POST["date_endmonth"], $_POST["date_endday"], $_POST["date_endyear"]); /* * Sécurité accés client */ if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } /* * Actions */ if ($_POST["action"] == 'add') { $datecontrat = mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); $contrat = new Contrat($db); $contrat->soc_id = $_POST["soc_id"]; $contrat->date_contrat = $datecontrat; $contrat->commercial_suivi_id = $_POST["commercial_suivi_id"]; $contrat->commercial_signature_id = $_POST["commercial_signature_id"]; $contrat->note = $_POST["note"]; $contrat->projetid = $_POST["projetid"]; $contrat->remise_percent = $_POST["remise_percent"]; /* $contrat->add_product($_POST["idprod1"],$_POST["qty1"],$_POST["remise_percent1"]); $contrat->add_product($_POST["idprod2"],$_POST["qty2"],$_POST["remise_percent2"]); $contrat->add_product($_POST["idprod3"],$_POST["qty3"],$_POST["remise_percent3"]); $contrat->add_product($_POST["idprod4"],$_POST["qty4"],$_POST["remise_percent4"]); */ $result = $contrat->create($user,$langs,$conf); if ($result >= 0) { Header("Location: fiche.php?id=".$contrat->id); exit; } else { $mesg='
'.$contrat->error.'
'; } $_GET["id"] = $contrat->id; $action = ''; } if ($_POST["action"] == 'classin') { $contrat = new Contrat($db); $contrat->fetch($_GET["id"]); $contrat->classin($_POST["projetid"]); } if ($_POST["action"] == 'addligne' && $user->rights->contrat->creer) { $result = 0; $contrat = new Contrat($db); $result=$contrat->fetch($_GET["id"]); if (($_POST["p_idprod"] > 0 && $_POST["mode"]=='predefined') || ($_POST["mode"]=='libre')) { //print $_POST["desc"]." - ".$_POST["pu"]." - ".$_POST["pqty"]." - ".$_POST["tva_tx"]." - ".$_POST["p_idprod"]." - ".$_POST["premise"]; exit; $result = $contrat->addline( $_POST["desc"], $_POST["pu"], $_POST["pqty"], $_POST["tva_tx"], $_POST["p_idprod"], $_POST["premise"], $date_start, $date_end ); } if ($result >= 0) { Header("Location: fiche.php?id=".$contrat->id); exit; } else { $mesg='
'.$contrat->error.'
'; } } if ($_POST["action"] == 'updateligne' && $user->rights->contrat->creer) { $contrat = new Contrat($db,"",$_GET["id"]); if ($contrat->fetch($_GET["id"])) { $result = $contrat->updateline($_POST["elrowid"], $_POST["eldesc"], $_POST["elprice"], $_POST["elqty"], $_POST["elremise_percent"], $date_start_update, $date_end_update ); if ($result > 0) { $db->commit(); } else { dolibarr_print_error($db,"result=$result"); $db->rollback(); } } else { dolibarr_print_error($db); } } if ($_GET["action"] == 'deleteline' && $user->rights->contrat->creer) { $contrat = new Contrat($db); $contrat->fetch($_GET["id"]); $result = $contrat->delete_line($_GET["lineid"]); if ($result == 0) { Header("Location: fiche.php?id=".$contrat->id); } } if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes' && $user->rights->contrat->creer) { $contrat = new Contrat($db); $contrat->fetch($_GET["id"]); $soc = new Societe($db); $soc->fetch($contrat->soc_id); $result = $contrat->validate($user); } if ($_POST["action"] == 'confirm_cancel' && $_POST["confirm"] == 'yes' && $user->rights->contrat->creer) { $contrat = new Contrat($db); $contrat->fetch($_GET["id"]); $result = $contrat->cancel($user); } if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') { if ($user->rights->contrat->supprimer ) { $contrat = new Contrat($db); $contrat->id = $_GET["id"]; $contrat->delete($user,$lang,$conf); Header("Location: index.php"); return; } } llxHeader('',$langs->trans("ContractCard"),"Contrat"); $html = new Form($db); /********************************************************************* * * Mode creation * *********************************************************************/ if ($_GET["action"] == 'create') { dolibarr_fiche_head($head, $a, $langs->trans("AddContract")); if ($mesg) print $mesg; $new_contrat = new Contrat($db); $sql = "SELECT s.nom, s.prefix_comm, s.idp "; $sql .= "FROM ".MAIN_DB_PREFIX."societe as s "; $sql .= "WHERE s.idp = ".$_GET["socid"]; $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); if ($num) { $obj = $db->fetch_object($resql); $soc = new Societe($db); $soc->fetch($obj->idp); print '
'; print ''; print ''."\n"; print ''; print ''; print ''; // Commercial suivi print ''; // Commercial signature print ''; print '"; if ($conf->projet->enabled) { print '"; } /* * * Liste des elements * * print ''; print ''; */ print ''; print ''; print "\n"; print "
'.$langs->trans("Customer").':'.$obj->nom.'
'.$langs->trans("SalesRepresentativeFollowUp").''; print '
'.$langs->trans("SalesRepresentativeSignature").''; print '
'.$langs->trans("Date").' :'; $html->select_date(); print "
'.$langs->trans("Project").' :'; $proj = new Project($db); $html->select_array("projetid",$proj->liste_array($soc->id),0,1); print "
'.$langs->trans("Services").'/'.$langs->trans("Products").'
'; $sql = "SELECT p.rowid,p.label,p.ref,p.price FROM ".MAIN_DB_PREFIX."product as p "; $sql .= " WHERE envente = 1"; $sql .= " ORDER BY p.nbvente DESC LIMIT 20"; if ( $db->query($sql) ) { $opt = ""; if ($result) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $objp = $db->fetch_object(); $opt .= "\n"; $i++; } } $db->free(); } else { print $db->error(); } print ''; print ''; for ($i = 1 ; $i < 5 ; $i++) { print ''; print ''; print ''; } print '
20 Produits les plus vendusQuan.Remise
%
'; print '
'.$langs->trans("Comment").''; print '

\n"; if ($propalid) { /* * Produits */ print_titre($langs->trans("Products")); 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 = $propalid"; $sql .= " ORDER BY pt.rowid ASC"; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; $var=True; while ($i < $num) { $objp = $db->fetch_object($result); $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"; $sql.= " WHERE pt.fk_propal = $propalid AND pt.fk_product = 0"; $sql.= " ORDER BY pt.rowid ASC"; $result=$db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; while ($i < $num) { $objp = $db->fetch_object($result); $var=!$var; print "\n"; print ''; print ''; print ''; print "\n"; $i++; } } else { dolibarr_print_error($db); } 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."
'; } } } else { dolibarr_print_error($db); } } else /* *************************************************************************** */ /* */ /* Mode vue et edition */ /* */ /* *************************************************************************** */ { $id = $_GET["id"]; if ($id > 0) { $contrat = New Contrat($db); if ( $contrat->fetch($id) > 0) { if ($mesg) print $mesg; $author = new User($db); $author->id = $contrat->user_author_id; $author->fetch(); $commercial_signature = new User($db); $commercial_signature->id = $contrat->commercial_signature_id; $commercial_signature->fetch(); $commercial_suivi = new User($db); $commercial_suivi->id = $contrat->commercial_suivi_id; $commercial_suivi->fetch(); $h = 0; $head[$h][0] = DOL_URL_ROOT.'/contrat/fiche.php?id='.$contrat->id; $head[$h][1] = $langs->trans("ContractCard"); $hselected = $h; $h++; $head[$h][0] = DOL_URL_ROOT.'/contrat/info.php?id='.$contrat->id; $head[$h][1] = $langs->trans("Info"); $h++; dolibarr_fiche_head($head, $hselected, $langs->trans("Contract").': '.$contrat->id); /* * Confirmation de la suppression de la contrat */ if ($_GET["action"] == 'delete') { $html->form_confirm("fiche.php?id=$id",$langs->trans("DeleteAContract"),$langs->trans("ConfirmDeleteAContract"),"confirm_delete"); print '
'; } /* * Confirmation de la validation */ if ($_GET["action"] == 'valid') { //$numfa = contrat_get_num($soc); $html->form_confirm("fiche.php?id=$id",$langs->trans("ValidateAContract"),$langs->trans("ConfirmValidateContract"),"confirm_valid"); print '
'; } /* * Confirmation de l'annulation */ if ($_GET["action"] == 'annuler') { $html->form_confirm("fiche.php?id=$id",$langs->trans("Cancel"),"Etes-vous sûr de vouloir annuler cette contrat ?","confirm_cancel"); } /* * Contrat */ if ($contrat->brouillon == 1 && $user->rights->contrat->creer) { print '
'; print ''; } print ''; // Reference du contrat print '"; // Customer print ""; print ''; // Statut contrat print '"; // Date print ''; print '\n"; // Factures associées /* TODO */ // Projet if ($conf->projet->enabled) { print '"; } print ''; print ''; print "
'.$langs->trans("Ref").''; print $contrat->ref; print "
".$langs->trans("Customer")."'; print ''.$contrat->societe->nom.'
'.$langs->trans("Status").''; print $contrat->statuts[$contrat->statut]; print "
'.$langs->trans("Date").''.dolibarr_print_date($contrat->date_contrat,"%A %d %B %Y")."
'.$langs->trans("Project").''; if ($contrat->projet_id > 0) { $projet = New Project($db); $projet->fetch($contrat->projet_id); print ''.$projet->title.''; } else { print 'Classer le contrat'; } print "
'.$langs->trans("SalesRepresentativeFollowUp").''.$commercial_suivi->fullname.''.$langs->trans("SalesRepresentativeSignature").''.$commercial_signature->fullname.'
"; if ($contrat->brouillon == 1 && $user->rights->contrat->creer) { print '
'; } /* * Lignes de contrats */ echo '
'; $sql = "SELECT cd.statut, cd.label, cd.fk_product, cd.description, cd.price_ht, cd.qty, cd.rowid, cd.tva_tx, cd.remise_percent, cd.subprice,"; $sql.= " ".$db->pdate("cd.date_ouverture_prevue")." as date_debut, ".$db->pdate("cd.date_ouverture")." as date_debut_reelle,"; $sql.= " ".$db->pdate("cd.date_fin_validite")." as date_fin, ".$db->pdate("cd.date_cloture")." as date_fin_reelle"; $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd"; $sql.= " WHERE cd.fk_contrat = ".$id; $sql.= " ORDER BY cd .rowid"; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; $total = 0; if ($num) { print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; } $var=true; while ($i < $num) { $objp = $db->fetch_object($result); $var=!$var; if ($_GET["action"] != 'editline' || $_GET["rowid"] != $objp->rowid) { print ''; if ($objp->fk_product > 0) { print ''; } else { print "\n"; } // TVA print ''; // Prix print '\n"; // Quantité print ''; // Remise if ($objp->remise_percent > 0) { print '\n"; } else { print ''; } // Icon update et delete if ($contrat->statut == 0 && $objp->statut == 0 && $user->rights->contrat->creer) { print ''; print ''; } else { print ''; } // Statut print ''; print "\n"; // Dates mise en service print ''; print ''; print ''; print ''; } else { print ""; print ''; print ''; // Ligne carac print ""; print ''; print ''; print ''; print ''; print ''; // Ligne dates prévues print ""; print ''; print ''; print '' . "\n"; print "\n"; } $i++; } $db->free($result); } else { dolibarr_print_error($db); } /* * Ajouter une ligne produit/service */ if ($user->rights->contrat->creer && $contrat->statut == 0) { print ""; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $var=false; print ''; print ''; print ''; print ''; print ""; print ''; print ''; print ''; print ''; print ""; print ''; print ''; print ''; print ""; $var=!$var; print ''; print ''; print ''; print ''; print ""; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; print ''; print ""; print ''; print ''; print ""; } print "
'.$langs->trans("Service").''.$langs->trans("VAT").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("Discount").'  '.$langs->trans("Status").'
'; print ''; print img_object($langs->trans("ShowService"),"service").' '.$objp->label.''; if ($objp->description) print '
'.stripslashes(nl2br($objp->description)); print '
".stripslashes(nl2br($objp->description))."'.$objp->tva_tx.'%'.price($objp->subprice)."'.$objp->qty.''.$objp->remise_percent."% '; print img_edit(); print ''; print img_delete(); print ' '; if ($contrat->statut == 1) print '';; print 'statut'; if ($contrat->statut == 1) print ''; print '
'; // Si pas encore activé if (! $objp->date_debut_reelle) { print $langs->trans("DateStartPlanned").': '; if ($objp->date_debut) print dolibarr_print_date($objp->date_debut); else print $langs->trans("Unknown"); } // Si activé if ($objp->date_debut_reelle) { print $langs->trans("DateStartReal").': '; if ($objp->date_debut_reelle) print dolibarr_print_date($objp->date_debut_reelle); else print $langs->trans("ContractStatusNotRunning"); } print '  -  '; // Si pas encore activé if (! $objp->date_debut_reelle) { print $langs->trans("DateEndPlanned").': '; if ($objp->date_fin) { print dolibarr_print_date($objp->date_fin); } else print $langs->trans("Unknown"); } // Si activé if ($objp->date_debut_reelle && ! $objp->date_fin_reelle) { print $langs->trans("DateEndPlanned").': '; if ($objp->date_fin) { print dolibarr_print_date($objp->date_fin); if ($objp->date_fin < time()) { print " ".img_warning($langs->trans("Late")); } } else print $langs->trans("Unknown"); } // Si désactivé if ($objp->date_debut_reelle && $objp->date_fin_reelle) { print $langs->trans("DateEndReal").': '; print dolibarr_print_date($objp->date_fin_reelle); } print ' 
'; print ''; print img_object($langs->trans("ShowService"),"service").' '.$objp->label.'
'; print '
%
'; print 'Date prévue mise en service '; $html->select_date($objp->date_debut,"date_start_update",0,0,($objp->date_debut>0?0:1)); print '   Date prévue fin de service '; $html->select_date($objp->date_fin,"date_end_update",0,0,($objp->date_fin>0?0:1)); print '
'.$langs->trans("Service").''.$langs->trans("VAT").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("Discount").'   
'; $html->select_produits('','p_idprod','',0); print '%
'; print 'Date prévue mise en service '; $html->select_date('',"date_start",0,0,1); print '   Date prévue fin de service '; $html->select_date('',"date_end",0,0,1); print '
'; $html->select_tva("tva_tx",$conf->defaulttx); print '%
'; print 'Date prévue mise en service '; $html->select_date('',"date_start",0,0,1); print '   Date prévue fin de service '; $html->select_date('',"date_end",0,0,1); print '

"; /* * Fin Ajout ligne */ print ''; /************************************************************* * Boutons Actions *************************************************************/ if ($user->societe_id == 0) { print '
'; if ($contrat->statut == 0 && $num) { print ''.$langs->trans("Valid").''; } if ($user->rights->contrat->supprimer) { print ''.$langs->trans("Delete").''; } print "
"; } /* * * */ if ($_GET["action"] == 'classer') { $langs->load("project"); print '

'; print ''; print ''; print '"; print '
'.$langs->trans("Project").''; $proj = new Project($db); $html->select_array("projetid",$proj->liste_array($contrat->soc_id)); print "
'; } } else { /* Contrat non trouvée */ print "Contrat inexistant ou accés refusé"; } } } $db->close(); llxFooter('$Date$ - $Revision$'); ?>