diff --git a/htdocs/contrat/contrat.class.php b/htdocs/contrat/contrat.class.php index 13262f08bad..50a56c979cf 100644 --- a/htdocs/contrat/contrat.class.php +++ b/htdocs/contrat/contrat.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004 Destailleur Laurent +/* Copyright (C) 2003 Rodolphe Quiedeville + * Copyright (C) 2004-2005 Destailleur Laurent * * 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 @@ -120,18 +120,22 @@ class Contrat /** - * \brief Active une ligne detail d'un contrat - * \param user Objet User qui avtice le contrat - * \param line_id Id de la ligne de detail à activer - * \param date Date d'ouverture - */ - function active_line($user, $line_id, $date) + * \brief Active une ligne detail d'un contrat + * \param user Objet User qui avtice le contrat + * \param line_id Id de la ligne de detail à activer + * \param date Date d'ouverture + * \param date Date fin prévue + * \return int < 0 si erreur, > 0 si ok + */ + function active_line($user, $line_id, $date, $dateend='') { // statut actif : 4 - $sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET statut = 4"; - $sql .= " , date_ouverture = '".$this->db->idate($date)."', fk_user_ouverture = ".$user->id; - $sql .= " WHERE rowid = ".$line_id . " AND (statut = 0 OR statut = 3) "; + $sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET statut = 4,"; + $sql.= " date_ouverture = '".$this->db->idate($date)."',"; + if ($dateend) $sql.= " date_fin_validite = '".$this->db->idate($dateend)."',"; + $sql.= " fk_user_ouverture = ".$user->id; + $sql.= " WHERE rowid = ".$line_id . " AND (statut = 0 OR statut = 3) "; $result = $this->db->query($sql) ; @@ -143,7 +147,7 @@ class Contrat $interface->run_triggers('CONTRACT_SERVICE_ACTIVATE',$this,$user,$lang,$conf); // Fin appel triggers - return 0; + return 1; } else { @@ -251,10 +255,11 @@ class Contrat } /** - * \brief Crée un contrat vierge - * \param user Utilisateur qui crée - * \param lang Environnement langue de l'utilisateur - * \param conf Environnement de configuration lors de l'opération + * \brief Crée un contrat vierge en base + * \param user Utilisateur qui crée + * \param lang Environnement langue de l'utilisateur + * \param conf Environnement de configuration lors de l'opération + * \return int < 0 si erreur, id contrat créé sinon */ function create($user,$lang='',$conf='') { @@ -271,19 +276,48 @@ class Contrat $interface->run_triggers('CONTRACT_CREATE',$this,$user,$lang,$conf); // Fin appel triggers - $result = 0 ; + $result = $this->id; } else { - $result = 1; dolibarr_syslog("Contrat::create - 10"); - dolibarr_print_error($this->db,"Contrat::create - 10"); + $result = -1; } return $result; } + /** + * \brief Supprime un contrat de la base + * \param user Utilisateur qui supprime + * \param lang Environnement langue de l'utilisateur + * \param conf Environnement de configuration lors de l'opération + * \return int < 0 si erreur, > 0 si ok + */ + function delete($user,$lang='',$conf='') + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."contrat"; + $sql.= " WHERE rowid=".$this->id; + if ($this->db->query($sql)) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $interface->run_triggers('CONTRACT_DELETE',$this,$user,$lang,$conf); + // Fin appel triggers + + $result = 1; + } + else + { + $result = -1; + } + + return $result; + } + + /** * \brief Ajoute une ligne de commande * \return int <0 si KO, =0 si OK diff --git a/htdocs/contrat/enservice.php b/htdocs/contrat/enservice.php index 5d2df9eec15..4e6d40e43fc 100644 --- a/htdocs/contrat/enservice.php +++ b/htdocs/contrat/enservice.php @@ -86,7 +86,7 @@ if ($resql) print ''; print ''; - print_liste_field_titre($langs->trans("Ref"),"enservice.php", "c.rowid","","","",$sortfield); + print_liste_field_titre($langs->trans("Contract"),"enservice.php", "c.rowid","","","",$sortfield); print_liste_field_titre($langs->trans("Status"),"enservice.php", "cd.statut","","","",$sortfield); print_liste_field_titre($langs->trans("Service"),"enservice.php", "p.label","","","",$sortfield); print_liste_field_titre($langs->trans("Company"),"enservice.php", "s.nom","","","",$sortfield); diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php index 3b2d8f2ca6f..62a521fc6a2 100644 --- a/htdocs/contrat/fiche.php +++ b/htdocs/contrat/fiche.php @@ -20,12 +20,12 @@ * $Source$ * */ - + /** \file htdocs/contrat/fiche.php - \ingroup contrat - \brief Fiche contrat - \version $Revision$ + \ingroup contrat + \brief Fiche contrat + \version $Revision$ */ require("./pre.inc.php"); @@ -37,7 +37,7 @@ $langs->load("companies"); $user->getrights('contrat'); if (!$user->rights->contrat->lire) - accessforbidden(); +accessforbidden(); require("../project.class.php"); require("../propal.class.php"); @@ -46,58 +46,52 @@ require_once (DOL_DOCUMENT_ROOT."/contrat/contrat.class.php"); /* * Sécurité accés client */ -if ($user->societe_id > 0) +if ($user->societe_id > 0) { - $action = ''; - $socidp = $user->societe_id; + $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_id = $_POST["commercial"]; - $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); - if ($result == 0) - { - Header("Location: fiche.php?id=".$contrat->id); - } - - $_GET["id"] = $contrat->id; - - $action = ''; -} -/* - * - */ -if ($_POST["action"] == 'classin') -{ - $commande = new Commande($db); - $commande->fetch($_GET["id"]); - $commande->classin($_POST["projetid"]); -} - -/* - * */ +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_id = $_POST["commercial"]; + $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,$lang,$conf); + if ($result == 0) + { + Header("Location: fiche.php?id=".$contrat->id); + } + + $_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) { @@ -125,73 +119,74 @@ if ($_POST["action"] == 'addligne' && $user->rights->contrat->creer) } } -if ($_POST["action"] == 'updateligne' && $user->rights->contrat->creer) +if ($_POST["action"] == 'updateligne' && $user->rights->contrat->creer) { - $contrat = new Contrat($db,"",$_GET["id"]); - if ($contrat->fetch($_GET["id"]) ) + $contrat = new Contrat($db,"",$_GET["id"]); + if ($contrat->fetch($_GET["id"]) ) { - $result = $contrat->update_line($_POST["elrowid"], - $_POST["eldesc"], - $_POST["elprice"], - $_POST["elqty"], - $_POST["elremise_percent"]); + $result = $contrat->update_line($_POST["elrowid"], + $_POST["eldesc"], + $_POST["elprice"], + $_POST["elqty"], + $_POST["elremise_percent"]); } - else + else { - dolibarr_print_error($db); + dolibarr_print_error($db); } } -if ($_GET["action"] == 'deleteline' && $user->rights->contrat->creer) +if ($_GET["action"] == 'deleteline' && $user->rights->contrat->creer) { - $contrat = new Contrat($db); - $contrat->fetch($_GET["id"]); - $result = $contrat->delete_line($_GET["lineid"]); + $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 ($result == 0) + { + Header("Location: fiche.php?id=".$contrat->id); } } if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == yes && $user->rights->contrat->valider) { - $contrat = new Contrat($db); - $contrat->fetch($_GET["id"]); - $soc = new Societe($db); - $soc->fetch($contrat->soc_id); - $result = $contrat->valid($user); + $contrat = new Contrat($db); + $contrat->fetch($_GET["id"]); + $soc = new Societe($db); + $soc->fetch($contrat->soc_id); + $result = $contrat->valid($user); } if ($_POST["action"] == 'confirm_cancel' && $_POST["confirm"] == yes && $user->rights->contrat->valider) { - $contrat = new Contrat($db); - $contrat->fetch($_GET["id"]); - $result = $contrat->cancel($user); + $contrat = new Contrat($db); + $contrat->fetch($_GET["id"]); + $result = $contrat->cancel($user); } if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == yes) { - if ($user->rights->commande->supprimer ) + if ($user->rights->contrat->supprimer ) { - $commande = new Commande($db); - $commande->id = $_GET["id"]; - $commande->delete(); - Header("Location: index.php"); + $contrat = new Contrat($db); + $contrat->id = $_GET["id"]; + $contrat->delete($user,$lang,$conf); + Header("Location: index.php"); + return; } } /* - * - */ +* +*/ if ($action == 'pdf') { - /* - * Generation de la commande - * définit dans /includes/modules/commande/modules_commande.php - */ - commande_pdf_create($db, $_GET["id"]); -} + /* + * Generation de la commande + * définit dans /includes/modules/commande/modules_commande.php + */ + commande_pdf_create($db, $_GET["id"]); +} llxHeader('',$langs->trans("ContractCard"),"Contrat"); @@ -204,556 +199,594 @@ $html = new Form($db); * * Mode creation * - * - ************************************************************************/ -if ($_GET["action"] == 'create') + *********************************************************************/ +if ($_GET["action"] == 'create') { - dolibarr_fiche_head($head, $a, $langs->trans("AddContract")); + dolibarr_fiche_head($head, $a, $langs->trans("AddContract")); - if ($mesg) print $mesg; + if ($mesg) print $mesg; - $new_contrat = new Contrat($db); + $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"]; - + $sql = "SELECT s.nom, s.prefix_comm, s.idp "; + $sql .= "FROM ".MAIN_DB_PREFIX."societe as s "; + $sql .= "WHERE s.idp = ".$_GET["socid"]; - if ( $db->query($sql) ) + + if ( $db->query($sql) ) { - $num = $db->num_rows(); - if ($num) - { - $obj = $db->fetch_object(); + $num = $db->num_rows(); + if ($num) + { + $obj = $db->fetch_object(); - $soc = new Societe($db); - $soc->fetch($obj->idp); - - print ''; - print ''; - print '' ."\n"; - print ''; + $soc = new Societe($db); + $soc->fetch($obj->idp); - print '
'; - - print ''; + print ''; + print ''; + print '' ."\n"; + print ''; - print ''; - if ($propalid) - { - /* - * Produits - */ - print_titre($langs->trans("Products")); - - print '
'.$langs->trans("Customer").' :'.$obj->nom.'
'.$langs->trans("Commercial").''; + print ''; - print ''; - - print '"; + print ''; - if ($conf->projet->enabled) - { - print '"; - } - - /* - * - * Liste des elements - * - * - print ''; - print ''; - */ - print ''; + print ''; - print "\n"; - print "
'.$langs->trans("Date").' :'; - $html->select_date(); - print "
'.$langs->trans("Customer").' :'.$obj->nom.'
'.$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").'
'; + print '
'.$langs->trans("Commercial").''; - $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"; + } + 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(); - $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 = $propalid 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 - { - dolibarr_print_error($db); - } + print '"; - 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."
'.$langs->trans("Date").' :'; + $html->select_date(); + print "
'; - } - } - } - else - { - dolibarr_print_error($db); + if ($conf->projet->enabled) + { + print ''.$langs->trans("Project").' :'; + $proj = new Project($db); + $html->select_array("projetid",$proj->liste_array($soc->id),0,1); + print ""; + } + + /* + * + * Liste des elements + * + * + print ''.$langs->trans("Services").'/'.$langs->trans("Products").''; + print ''; + + $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 ''; + */ + print ''.$langs->trans("Comment").''; + print ''; + + /* + * + */ + print ''; + print "\n"; + 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(); + $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 = $propalid 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 + { + 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 + else + { + dolibarr_print_error($db); + } +} +else /* *************************************************************************** */ /* */ /* Mode vue et edition */ /* */ /* *************************************************************************** */ -{ - $id = $_GET["id"]; - if ($id > 0) +{ + $id = $_GET["id"]; + if ($id > 0) { - $contrat = New Contrat($db); - if ( $contrat->fetch($id) > 0) - { + $contrat = New Contrat($db); + if ( $contrat->fetch($id) > 0) + { - if ($mesg) print $mesg; + if ($mesg) print $mesg; - $author = new User($db); - $author->id = $contrat->user_author_id; - $author->fetch(); + $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_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(); + $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++; - - - dolibarr_fiche_head($head, $hselected, $langs->trans("Contract").': '.$contrat->id); + $h = 0; + $head[$h][0] = DOL_URL_ROOT.'/contrat/fiche.php?id='.$contrat->id; + $head[$h][1] = $langs->trans("ContractCard"); + $hselected = $h; + $h++; - /* - * Confirmation de la suppression de la contrat - * - */ - if ($_GET["action"] == 'delete') - { - $html->form_confirm("fiche.php?id=$id","Supprimer la contrat","Etes-vous sûr de vouloir supprimer cette contrat ?","confirm_delete"); - } - - /* - * Confirmation de la validation - * - */ - if ($_GET["action"] == 'valid') - { - //$numfa = contrat_get_num($soc); - $html->form_confirm("fiche.php?id=$id","Valider la contrat","Etes-vous sûr de vouloir valider cette contrat ?","confirm_valid"); - } - - /* - * 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("Commercial suivi").''.$commercial_suivi->fullname.''.$langs->trans("Commercial signature").''.$commercial_signature->fullname.'
"; - - if ($contrat->brouillon == 1 && $user->rights->contrat->creer) - { - print '
'; - } - - /* - * Lignes de contrats - * - */ - echo '
'; - - $sql = "SELECT l.statut, l.label, l.fk_product, l.description, l.price_ht, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice"; - $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as l"; - $sql .= " WHERE l.fk_contrat = ".$id; - $sql .= " ORDER BY l.rowid"; - - $result = $db->query($sql); - - if ($result) - { - $num = $db->num_rows(); - $i = 0; $total = 0; - - if ($num) - { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - } - $var=True; - while ($i < $num) - { - $objp = $db->fetch_object(); - - $var=!$var; - print "\n"; - if ($objp->fk_product > 0) - { - print ''; - } - else - { - print "\n"; - } - print ''; - print ''; - if ($objp->remise_percent > 0) - { - print '\n"; - } - else - { - print ''; - } - - // Icon delete - print '\n"; - if ($contrat->statut == 0 && $objp->statut == 0 && $user->rights->contrat->creer) - { - // print ''; - print ''; - } - else - { - print ''; - } - print "\n"; - - - if ($_GET["action"] == 'editline' && $_GET["rowid"] == $objp->rowid) - { - print ""; - print ''; - print ''; - print ""; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print '' . "\n"; - print "\n"; - } - $i++; - } - $db->free(); - } - else - { - dolibarr_print_error($db); - } - - - /* - * Ajouter une ligne produit/service - * - */ - if ($user->rights->contrat->creer) - { - print ''; - print ''; - print ''; - - print ""; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''."\n"; - - /* - print "".''; - print ''; - print ''; - print ''; - print ''; - - print ''; - */ - - $var=!$var; - print ""; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - print ""; - print ''; - print ''; - print ''; - - print ""; - } - print "
'.$langs->trans("Status").''.$langs->trans("Service").''.$langs->trans("VAT").''.$langs->trans("Qty").''.$langs->trans("Discount").''.$langs->trans("PriceU").'  
'; - print '';; - print 'statut'; - 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.' %'.$objp->qty.''.$objp->remise_percent." % '.price($objp->subprice)."'; - // print img_edit(); - // print ''; - print img_delete(); - print ' 
  %
 '.$langs->trans("Service").''.$langs->trans("VAT").''.$langs->trans("Qty").''.$langs->trans("Discount").''.$langs->trans("PriceU").'  
'; - print $html->select_tva("tva_tx",$conf->defaulttx); - print ' %
 '; - $html->select_produits('','p_idprod'); - print '% 
 

"; - /* - * Fin Ajout ligne - * - */ - - print ''; - - if ($user->societe_id == 0 && $contrat->statut < 3) - { - print '
'; - - if ($contrat->statut == 0 && $user->rights->contrat->supprimer) - { - print ''.$langs->trans("Delete").''; - } - - if ($contrat->statut > 0 && $contrat->statut < 3 && $user->rights->expedition->creer) - { - print ''.$langs->trans("Send").''; - } - - if ($contrat->statut == 0) - { - if ($user->rights->contrat->valider) - { - print ''.$langs->trans("Valid").''; - } - } - - if ($contrat->statut == 1) - { - $nb_expedition = $contrat->nb_expedition(); - if ($user->rights->contrat->valider && $nb_expedition == 0) - { - print ''.$langs->trans("Cancel").''; - } - } - - print "
"; - } - print "

\n"; + dolibarr_fiche_head($head, $hselected, $langs->trans("Contract").': '.$contrat->id); - /* - * - * - */ - 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é"; - } - } + /* + * 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"),"Etes-vous sûr de vouloir valider cette contrat ?","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("Commercial suivi").''.$commercial_suivi->fullname.''.$langs->trans("Commercial signature").''.$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 "\n"; + } + $var=true; + while ($i < $num) + { + $objp = $db->fetch_object($result); + + $var=!$var; + print ''; + if ($objp->fk_product > 0) + { + print ''; + } + else + { + print "\n"; + } + print ''; + print ''; + if ($objp->remise_percent > 0) + { + print '\n"; + } + else + { + print ''; + } + + print '\n"; + + // Icon delete + if ($contrat->statut == 0 && $objp->statut == 0 && $user->rights->contrat->creer) + { + // print ''; + print ''; + } + else + { + print ''; + } + print "\n"; + + // Dates mise en service + print ''; + print ''; + print ''; + print ''; + + if ($_GET["action"] == 'editline' && $_GET["rowid"] == $objp->rowid) + { + print ""; + print ''; + print ''; + print ""; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '' . "\n"; + print "\n"; + } + $i++; + } + $db->free(); + } + else + { + dolibarr_print_error($db); + } + + + /* + * Ajouter une ligne produit/service + */ + if ($user->rights->contrat->creer) + { + print ''; + print ''; + print ''; + + print ""; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''."\n"; + + /* + print "".''; + print ''; + print ''; + print ''; + print ''; + + print ''; + */ + + $var=!$var; + print ""; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + print ""; + print ''; + print ''; + print ''; + + print ""; + } + print "
'.$langs->trans("Status").''.$langs->trans("Service").''.$langs->trans("VAT").''.$langs->trans("Qty").''.$langs->trans("Discount").''.$langs->trans("PriceU").'  
'; + print '';; + print 'statut'; + 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.' %'.$objp->qty.''.$objp->remise_percent." % '.price($objp->subprice)."'; + // print img_edit(); + // print ''; + print img_delete(); + 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"); + } + if ($objp->date_debut_reelle && $objp->date_fin_reelle) { + print $langs->trans("DateEndReal").': '; + dolibarr_print_date($objp->date_fin_reelle); + } + print '
  %
 '.$langs->trans("Service").''.$langs->trans("VAT").''.$langs->trans("Qty").''.$langs->trans("Discount").''.$langs->trans("PriceU").'  
'; + print $html->select_tva("tva_tx",$conf->defaulttx); + print ' %
 '; + $html->select_produits('','p_idprod'); + print '% 
 

"; + /* + * Fin Ajout ligne + */ + + print ''; + + /************************************************************* + * Boutons Actions + *************************************************************/ + + if ($user->societe_id == 0 && $contrat->statut < 3) + { + print '
'; + + if ($contrat->statut == 0 && $user->rights->contrat->supprimer) + { + print ''.$langs->trans("Delete").''; + } + + if ($contrat->statut > 0 && $contrat->statut < 3 && $user->rights->expedition->creer) + { + print ''.$langs->trans("Send").''; + } + + if ($contrat->statut == 0) + { + if ($user->rights->contrat->valider) + { + print ''.$langs->trans("Valid").''; + } + } + + if ($contrat->statut == 1) + { + $nb_expedition = $contrat->nb_expedition(); + if ($user->rights->contrat->valider && $nb_expedition == 0) + { + print ''.$langs->trans("Cancel").''; + } + } + + 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("Dernière modification $Date$ révision $Revision$"); +llxFooter('$Date$ - $Revision$'); ?> diff --git a/htdocs/contrat/index.php b/htdocs/contrat/index.php index 5bd0f8ed22b..f5d33e23ac6 100644 --- a/htdocs/contrat/index.php +++ b/htdocs/contrat/index.php @@ -62,12 +62,33 @@ print ''; print '
'; // Légende -print 'Légende
'; +$var=false; +print ''; +print ''; +print ''; +print '
'.$langs->trans("Legend").'
'; print 'statut Statut initial
'; print 'statut A commander
'; print 'statut Commandé chez le fournisseur
'; print 'statut Activé chez le fournisseur
'; print 'statut Activé chez le client
'; +print '
'; + +print '
'; + +/* + * Recherche Contrat + */ +if ($conf->contrat->enabled) { + $var=false; + print '
'; + print ''; + print ''; + print ''; + print "
'.$langs->trans("SearchAContract").'
'; + print $langs->trans("Ref").':

\n"; +} + print '
'; diff --git a/htdocs/contrat/ligne.php b/htdocs/contrat/ligne.php index 6becc881b4b..95b29895a40 100644 --- a/htdocs/contrat/ligne.php +++ b/htdocs/contrat/ligne.php @@ -22,7 +22,7 @@ */ /** - \file htdocs/contrat/fiche.php + \file htdocs/contrat/ligne.php \ingroup contrat \brief Fiche contrat \version $Revision$ @@ -51,53 +51,23 @@ if ($user->societe_id > 0) $action = ''; $socidp = $user->societe_id; } + + /* - * - */ -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_id = $_POST["commercial"]; - $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); - if ($result == 0) - { - Header("Location: fiche.php?id=".$contrat->id); - } - - $_GET["id"] = $contrat->id; - - $action = ''; -} -/* - * + * Actions */ if ($_POST["action"] == 'confirm_active' && $_POST["confirm"] == 'yes' && $user->rights->contrat->activer) { - $contrat = new Contrat($db); - $contrat->fetch($_GET["id"]); + $contrat = new Contrat($db); + $contrat->fetch($_GET["id"]); - $result = $contrat->active_line($user, $_GET["ligne"], $_GET["date"]); + $result = $contrat->active_line($user, $_GET["ligne"], $_GET["date"], $_GET["dateend"]); - if ($result == 0) + if ($result > 0) { - Header("Location: fiche.php?id=".$contrat->id); + Header("Location: fiche.php?id=".$contrat->id); + exit; } - } @@ -196,8 +166,9 @@ $html = new Form($db); if ($_GET["action"] == 'active' && $user->rights->contrat->activer) { print '
'; - $dateact = mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); - $html->form_confirm("ligne.php?id=".$contrat->id."&ligne=".$_GET["ligne"]."&date=".$dateact,"Activer le service","Etes-vous sûr de vouloir activer ce service en date du ".strftime("%A %d %B %Y", $dateact)." ?","confirm_active"); + $dateactstart = mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + $dateactend = mktime(12, 0 , 0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); + $html->form_confirm("ligne.php?id=".$contrat->id."&ligne=".$_GET["ligne"]."&date=".$dateactstart."&dateend=".$dateactend,$langs->trans("ActivateService"),$langs->trans("ConfirmActivateService",strftime("%A %d %B %Y", $dateactstart)),"confirm_active"); } @@ -207,17 +178,18 @@ $html = new Form($db); */ print '
'; - $sql = "SELECT l.statut, l.label, l.fk_product, l.description, l.price_ht, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice"; - $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as l"; - $sql .= " WHERE l.fk_contrat = ".$id; - $sql .= " AND rowid = ".$_GET["ligne"]; - $sql .= " ORDER BY l.rowid"; + $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.= " AND rowid = ".$_GET["ligne"]; + $sql.= " ORDER BY cd.rowid"; $result = $db->query($sql); - if ($result) { - $num = $db->num_rows(); + $num = $db->num_rows($result); $i = 0; $total = 0; if ($num) @@ -232,10 +204,10 @@ $html = new Form($db); print ''; print "\n"; } - $var=True; + $var=true; while ($i < $num) { - $objp = $db->fetch_object(); + $objp = $db->fetch_object($result); $var=!$var; print "\n"; @@ -270,11 +242,57 @@ $html = new Form($db); print ''; print "\n"; + + if ($objp->date_debut) $dateactstart=$objp->date_debut; + if ($objp->date_fin) $dateactend=$objp->date_fin; + + // Dates mise en service + print ''; + print ''; + print ''; + print ''; $i++; } - $db->free(); + $db->free($result); } else { @@ -297,22 +315,30 @@ $html = new Form($db); 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"); + } + if ($objp->date_debut_reelle && $objp->date_fin_reelle) { + print $langs->trans("DateEndReal").': '; + dolibarr_print_date($objp->date_fin_reelle); + } + print '
'; print ''; - print ''; print ''; + // Definie date debut et fin par defaut + if ($_POST["remonth"]) $dateactstart = mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + elseif (! $dateactstart) $dateactstart = time(); + + if ($_POST["endmonth"]) $dateactend = mktime(12, 0 , 0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); + elseif (! $dateactend) { + if ($objp->fk_product > 0) { + $product=new Product($db); + $product->fetch($objp->fk_product); + $dateactend = dolibarr_time_plus_duree (time(), $product->duration_value, $product->duration_unit); + } + } + + print ''; + + print ''; + print ''; print ''; @@ -324,7 +350,7 @@ $html = new Form($db); else { /* Contrat non trouvée */ - print "Contrat inexistante ou accés refusé"; + print "Contrat inexistant ou accés refusé"; } } diff --git a/htdocs/contrat/liste.php b/htdocs/contrat/liste.php index a0caa855318..42f970f6021 100644 --- a/htdocs/contrat/liste.php +++ b/htdocs/contrat/liste.php @@ -62,9 +62,10 @@ if ($user->societe_id > 0) -$sql = "SELECT c.rowid as cid, c.statut, ".$db->pdate("c.fin_validite")." as fin_validite, c.fin_validite-sysdate() as delairestant, s.nom, s.idp as sidp"; -$sql .= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s"; -$sql .= " WHERE c.fk_soc = s.idp "; +$sql = "SELECT count(cd.rowid) as nb, c.rowid as cid, c.datec, c.statut, s.nom, s.idp as sidp"; +$sql.= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s"; +$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat"; +$sql.= " WHERE c.fk_soc = s.idp "; if ($_POST["search_contract"]) { $sql .= " AND c.rowid = ".$_POST["search_contract"]; } @@ -72,8 +73,9 @@ if ($socid > 0) { $sql .= " AND s.idp = $socid"; } -$sql .= " ORDER BY $sortfield $sortorder, delairestant"; -$sql .= $db->plimit($limit + 1 ,$offset); +$sql.= " GROUP BY c.rowid, c.datec, c.statut, s.nom, s.idp"; +$sql.= " ORDER BY $sortfield $sortorder"; +$sql.= $db->plimit($limit + 1 ,$offset); $resql=$db->query($sql); if ($resql) @@ -87,7 +89,9 @@ if ($resql) print ''; print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "c.rowid","","","",$sortfield); + print_liste_field_titre($langs->trans("NbOfServices"), $_SERVER["PHP_SELF"], "nb","","","",$sortfield); print_liste_field_titre($langs->trans("Company"), $_SERVER["PHP_SELF"], "s.nom","","","",$sortfield); + print_liste_field_titre($langs->trans("DateCreation"), $_SERVER["PHP_SELF"], "c.datec","","","",$sortfield); print "\n"; $now=mktime(); @@ -99,7 +103,9 @@ if ($resql) print ""; print "'; + print ''; print ''; + print ''; print "\n"; $i++; @@ -117,5 +123,5 @@ else $db->close(); -llxFooter("Dernière modification $Date$ révision $Revision$"); +llxFooter('$Date$ - $Revision$'); ?>
'.$langs->trans("ActivateService").'
'.$langs->trans("DateServiceActivate").''; - - if ($_POST["remonth"]) - { - $dateact = mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); - } - else - { - $dateact = time(); - } - - print $form->select_date($dateact); - print '
'.$langs->trans("User").''.$user->fullname.'
'.$langs->trans("DateServiceActivate").''; + print $form->select_date($dateactstart); + print '
'.$langs->trans("DateEndPlanned").''; + print $form->select_date($dateactend,"end"); + print '
'.$langs->trans("Comment").'
cid\">"; print img_object($langs->trans("ShowContract"),"contract").' '.$obj->cid.''.$obj->nb.''.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.''.dolibarr_print_date($obj->datec).'