Nouvelle mthode de gestion des contrats
This commit is contained in:
parent
99489469e2
commit
f48d62244f
@ -85,10 +85,10 @@ class Contrat
|
||||
$date_end = mktime(date("H",$date_start), date("i",$date_start), 0, $month, $day, $year);
|
||||
}
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET enservice = 1";
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET statut = 1";
|
||||
$sql .= " , mise_en_service = ".$this->db->idate($date_start).", fk_user_mise_en_service = ".$user->id;
|
||||
$sql .= " , fin_validite = ". $this->db->idate($date_end);
|
||||
$sql .= " WHERE rowid = ".$this->id . " AND enservice = 0";
|
||||
$sql .= " WHERE rowid = ".$this->id . " AND statut = 0";
|
||||
|
||||
$result = $this->db->query($sql) ;
|
||||
if (!$result)
|
||||
@ -96,6 +96,35 @@ class Contrat
|
||||
dolibarr_print_error($this->db);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
function active_line($user, $line_id, $date)
|
||||
{
|
||||
// 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) ";
|
||||
|
||||
$result = $this->db->query($sql) ;
|
||||
|
||||
if ($result)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
print $sql;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* \brief Cloture un contrat
|
||||
@ -104,9 +133,9 @@ class Contrat
|
||||
*/
|
||||
function cloture($user)
|
||||
{
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET enservice = 2";
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET statut = 2";
|
||||
$sql .= " , date_cloture = now(), fk_user_cloture = ".$user->id;
|
||||
$sql .= " WHERE rowid = ".$this->id . " AND enservice = 1";
|
||||
$sql .= " WHERE rowid = ".$this->id . " AND statut = 1";
|
||||
|
||||
$result = $this->db->query($sql) ;
|
||||
}
|
||||
@ -118,9 +147,9 @@ class Contrat
|
||||
*/
|
||||
function annule($user)
|
||||
{
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET enservice = 0";
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET statut = 0";
|
||||
$sql .= " , date_cloture = now(), fk_user_cloture = ".$user->id;
|
||||
$sql .= " WHERE rowid = ".$this->id . " AND enservice = 1";
|
||||
$sql .= " WHERE rowid = ".$this->id . " AND statut = 1";
|
||||
|
||||
$result = $this->db->query($sql) ;
|
||||
}
|
||||
@ -131,10 +160,10 @@ class Contrat
|
||||
*/
|
||||
function fetch ($id)
|
||||
{
|
||||
$sql = "SELECT rowid, enservice, fk_soc, fk_product, ".$this->db->pdate("mise_en_service")." as datemise";
|
||||
$sql .= ", fk_user_mise_en_service, ".$this->db->pdate("date_cloture")." as datecloture";
|
||||
$sql .= ", ".$this->db->pdate("fin_validite")." as datefin";
|
||||
$sql .= ", fk_user_cloture, fk_facture, fk_facturedet";
|
||||
$sql = "SELECT rowid, statut, fk_soc, ".$this->db->pdate("mise_en_service")." as datemise";
|
||||
$sql .= ", fk_user_mise_en_service, ".$this->db->pdate("date_contrat")." as datecontrat";
|
||||
$sql .= " , fk_user_author";
|
||||
$sql .= ", fk_commercial_signature, fk_commercial_suivi ";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."contrat WHERE rowid = $id";
|
||||
|
||||
$result = $this->db->query($sql) ;
|
||||
@ -144,18 +173,21 @@ class Contrat
|
||||
$result = $this->db->fetch_array();
|
||||
|
||||
$this->id = $result["rowid"];
|
||||
$this->enservice = $result["enservice"];
|
||||
$this->statut = $result["statut"];
|
||||
$this->factureid = $result["fk_facture"];
|
||||
$this->facturedetid = $result["fk_facturedet"];
|
||||
$this->mise_en_service = $result["datemise"];
|
||||
$this->date_fin_validite = $result["datefin"];
|
||||
$this->date_cloture = $result["datecloture"];
|
||||
$this->date_contrat = $result["datecontrat"];
|
||||
|
||||
$this->user_author_id = $result["fk_user_author"];
|
||||
|
||||
$this->commercial_signature_id = $result["fk_commercial_signature"];
|
||||
$this->commercial_suivi_id = $result["fk_commercial_suivi"];
|
||||
|
||||
$this->user_service->id = $result["fk_user_mise_en_service"];
|
||||
$this->user_cloture->id = $result["fk_user_cloture"];
|
||||
|
||||
$this->product->fetch($result["fk_product"]);
|
||||
|
||||
$this->societe->fetch($result["fk_soc"]);
|
||||
|
||||
$this->db->free();
|
||||
@ -168,6 +200,33 @@ class Contrat
|
||||
return $result;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
function create($user)
|
||||
{
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."contrat (datec,fk_soc, fk_user_author, fk_commercial_signature, fk_commercial_suivi, date_contrat)";
|
||||
$sql .= " VALUES (now(),".$this->soc_id.",".$user->id.",".$this->commercial_id.",".$this->commercial_id;
|
||||
$sql .= ",".$this->db->idate($this->date_contrat) .")";
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
$this->id = $this->db->last_insert_id();
|
||||
$result = 0 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = 1;
|
||||
dolibarr_syslog("Contrat::create_from_facture - 10");
|
||||
dolibarr_print_error($this->db,"Contrat::create_from_facture - 10");
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* \brief Crée autant de contrats que de lignes de facture, pour une facture donnée
|
||||
*
|
||||
@ -220,6 +279,88 @@ class Contrat
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajoute une ligne de commande
|
||||
*
|
||||
*/
|
||||
function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0)
|
||||
{
|
||||
$qty = ereg_replace(",",".",$qty);
|
||||
$pu = ereg_replace(",",".",$pu);
|
||||
|
||||
if (strlen(trim($desc)))
|
||||
{
|
||||
if (strlen(trim($qty))==0)
|
||||
{
|
||||
$qty=1;
|
||||
}
|
||||
|
||||
if ($fk_product > 0)
|
||||
{
|
||||
$prod = new Product($this->db, $fk_product);
|
||||
if ($prod->fetch($fk_product) > 0)
|
||||
{
|
||||
$label = $prod->libelle;
|
||||
$pu = $prod->price;
|
||||
$txtva = $prod->tva_tx;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$remise = 0;
|
||||
$price = round(ereg_replace(",",".",$pu), 2);
|
||||
$subprice = $price;
|
||||
if (trim(strlen($remise_percent)) > 0)
|
||||
{
|
||||
$remise = round(($pu * $remise_percent / 100), 2);
|
||||
$price = $pu - $remise;
|
||||
}
|
||||
|
||||
/*
|
||||
* Insertion dans la base
|
||||
*/
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."contratdet ";
|
||||
$sql .= "(fk_contrat,label,description,fk_product, price_ht,qty,tva_tx, remise_percent, subprice, remise)";
|
||||
$sql .= " VALUES ($this->id, '" . addslashes($label) . "','" . addslashes($desc) . "',$fk_product,".ereg_replace(",",".",$price).", '$qty', $txtva, $remise_percent,'".ereg_replace(",",".",$subprice)."','".ereg_replace(",",".", $remise)."') ;";
|
||||
|
||||
/*
|
||||
* Retour
|
||||
*/
|
||||
|
||||
if ( $this->db->query( $sql) )
|
||||
{
|
||||
//$this->update_price();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime une ligne du contrat
|
||||
*
|
||||
*/
|
||||
function delete_line($idligne)
|
||||
{
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."contratdet WHERE rowid =".$idligne;
|
||||
|
||||
if ($this->db->query($sql) )
|
||||
{
|
||||
//$this->update_price();
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Retourne le libellé du statut du contrat
|
||||
|
||||
@ -20,274 +20,716 @@
|
||||
* $Source$
|
||||
*
|
||||
*/
|
||||
|
||||
/*!
|
||||
\file htdocs/contrat/fiche.php
|
||||
\ingroup contrat
|
||||
\brief Fiche d'un contrat
|
||||
|
||||
/*! \file htdocs/commande/fiche.php
|
||||
\ingroup commande
|
||||
\brief Fiche commande
|
||||
\version $Revision$
|
||||
*/
|
||||
|
||||
require("./pre.inc.php");
|
||||
require("./contrat.class.php");
|
||||
require("../facture.class.php");
|
||||
|
||||
$langs->load("products");
|
||||
$langs->load("companies");
|
||||
$langs->load("bills");
|
||||
$langs->load("contracts");
|
||||
$langs->load("orders");
|
||||
$langs->load("companies");
|
||||
|
||||
llxHeader();
|
||||
$user->getrights('contrat');
|
||||
|
||||
$id = $_GET["id"];
|
||||
$mesg = '';
|
||||
if (!$user->rights->contrat->lire)
|
||||
accessforbidden();
|
||||
|
||||
require("../project.class.php");
|
||||
require("../propal.class.php");
|
||||
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 = '';
|
||||
$id = $user->societe_id;
|
||||
$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 = '';
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
if ($_POST["action"] == 'classin')
|
||||
{
|
||||
$commande = new Commande($db);
|
||||
$commande->fetch($_GET["id"]);
|
||||
$commande->classin($_POST["projetid"]);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
if ($_POST["action"] == 'miseenservice')
|
||||
if ($_POST["action"] == 'addligne' && $user->rights->contrat->creer)
|
||||
{
|
||||
$contrat = new Contrat($db);
|
||||
$contrat->id = $id;
|
||||
$contrat->fetch($id);
|
||||
$contrat->mise_en_service($user,
|
||||
mktime($_POST["date_starthour"],
|
||||
$_POST["date_startmin"],
|
||||
0,
|
||||
$_POST["date_startmonth"],
|
||||
$_POST["date_startday"],
|
||||
$_POST["date_startyear"]),
|
||||
0,
|
||||
mktime($_POST["date_endhour"],
|
||||
$_POST["date_endmin"],
|
||||
0,
|
||||
$_POST["date_endmonth"],
|
||||
$_POST["date_endday"],
|
||||
$_POST["date_endyear"])
|
||||
);
|
||||
$result = 0;
|
||||
$contrat = new Contrat($db);
|
||||
$contrat->fetch($_GET["id"]);
|
||||
|
||||
if ($_POST["p_idprod"] > 0)
|
||||
{
|
||||
$result = $contrat->addline($_POST["desc"],
|
||||
$_POST["pu"],
|
||||
$_POST["pqty"],
|
||||
$_POST["tva_tx"],
|
||||
$_POST["p_idprod"],
|
||||
$_POST["premise"]);
|
||||
}
|
||||
|
||||
if ($result == 0)
|
||||
{
|
||||
Header("Location: fiche.php?id=".$contrat->id);
|
||||
}
|
||||
}
|
||||
|
||||
if ($_GET["action"] == 'cloture')
|
||||
if ($_POST["action"] == 'updateligne' && $user->rights->contrat->creer)
|
||||
{
|
||||
$contrat = new Contrat($db);
|
||||
$contrat->id = $id;
|
||||
$contrat->cloture($user);
|
||||
$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"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
print "Erreur";
|
||||
}
|
||||
}
|
||||
|
||||
if ($_GET["action"] == 'annule')
|
||||
if ($_GET["action"] == 'deleteline' && $user->rights->contrat->creer)
|
||||
{
|
||||
$contrat = new Contrat($db);
|
||||
$contrat->id = $id;
|
||||
$contrat->annule($user);
|
||||
$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->valider)
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == yes)
|
||||
{
|
||||
if ($user->rights->commande->supprimer )
|
||||
{
|
||||
$commande = new Commande($db);
|
||||
$commande->id = $_GET["id"];
|
||||
$commande->delete();
|
||||
Header("Location: index.php");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
if ($action == 'pdf')
|
||||
{
|
||||
/*
|
||||
* Generation de la commande
|
||||
* définit dans /includes/modules/commande/modules_commande.php
|
||||
*/
|
||||
commande_pdf_create($db, $_GET["id"]);
|
||||
}
|
||||
|
||||
llxHeader('',$langs->trans("OrderCard"),"Commande");
|
||||
|
||||
|
||||
|
||||
$html = new Form($db);
|
||||
|
||||
|
||||
/*
|
||||
* Fiche contract en mode visu/édition
|
||||
/*********************************************************************
|
||||
*
|
||||
*/
|
||||
if ($id)
|
||||
* Mode creation
|
||||
*
|
||||
*
|
||||
*
|
||||
************************************************************************/
|
||||
if ($_GET["action"] == 'create')
|
||||
{
|
||||
$contrat = new Contrat($db);
|
||||
$result = $contrat->fetch($id);
|
||||
dolibarr_fiche_head($head, $a, "Création d'un nouveau contrat");
|
||||
|
||||
if ( $result )
|
||||
$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"];
|
||||
|
||||
|
||||
if ( $db->query($sql) )
|
||||
{
|
||||
$date_start='';
|
||||
$date_end='';
|
||||
$num = $db->num_rows();
|
||||
if ($num)
|
||||
{
|
||||
$obj = $db->fetch_object();
|
||||
|
||||
print $mesg;
|
||||
$soc = new Societe($db);
|
||||
$soc->fetch($obj->idp);
|
||||
|
||||
print '<form action="fiche.php" method="post">';
|
||||
print '<input type="hidden" name="action" value="add">';
|
||||
print '<input type="hidden" name="soc_id" value="'.$soc->id.'">' ."\n";
|
||||
print '<input type="hidden" name="remise_percent" value="0">';
|
||||
|
||||
/*
|
||||
* Affichage onglets
|
||||
*/
|
||||
$h = 0;
|
||||
print '<table class="border" cellspacing="0" cellpadding="3" width="100%">';
|
||||
|
||||
print '<tr><td>'.$langs->trans("Customer").' :</td><td>'.$obj->nom.'</td></tr>';
|
||||
|
||||
$hselected=$h;
|
||||
$head[$h][0] = DOL_URL_ROOT.'/contrat/fiche.php?id='.$id;
|
||||
$head[$h][1] = $langs->trans("CardContract").' : '.$contrat->id;
|
||||
$h++;
|
||||
print '<tr><td width="20%">'.$langs->trans("Commercial").'</td><td>';
|
||||
print '<select name="commercial">';
|
||||
|
||||
dolibarr_fiche_head($head, $hselected);
|
||||
$sql = "SELECT rowid, name, firstname FROM ".MAIN_DB_PREFIX."user ORDER BY name ";
|
||||
if ( $db->query( $sql) )
|
||||
{
|
||||
$num = $db->num_rows();
|
||||
if ( $num > 0 )
|
||||
{
|
||||
$i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
$row = $db->fetch_row($i);
|
||||
print '<option value="'.$row[0].'">'.$row[1] . " " . $row[2];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$db->free();
|
||||
|
||||
}
|
||||
print '</select></td></tr>';
|
||||
|
||||
print "<tr><td>Date :</td><td>";
|
||||
|
||||
print_date_select(time());
|
||||
|
||||
print "</td></tr>";
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
print "<tr>";
|
||||
print '<td width="20%">'.$langs->trans("Service").'</td><td colspan="3">'.($contrat->product->ref).' - '.($contrat->product->label_url).'</td>';
|
||||
print '</tr>';
|
||||
if ($contrat->factureid)
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">'.$contrat->societe->nom_url.'</td></tr>';
|
||||
print "<tr><td>Projet :</td><td>";
|
||||
$proj = new Project($db);
|
||||
$html->select_array("projetid",$proj->liste_array($soc->id),0,1);
|
||||
print "</td></tr>";
|
||||
|
||||
$facture=new Facture($db);
|
||||
$facture->fetch($contrat->factureid);
|
||||
print '<tr><td>'.$langs->trans("Bill").'</td><td><a href="../compta/facture.php?facid='.$contrat->factureid.'">'.$facture->ref.'</td>';
|
||||
print '<td>'.$langs->trans("BillStatus").'</td><td>'.$facture->get_libStatut().'</td></tr>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">'.$contrat->societe->nom_url.'</td></tr>';
|
||||
}
|
||||
/*
|
||||
*
|
||||
*
|
||||
* Liste des elements
|
||||
*
|
||||
*
|
||||
print '<tr><td colspan="3">'.$langs->trans("Services").'/'.$langs->trans("Products").'</td></tr>';
|
||||
print '<tr><td colspan="3">';
|
||||
|
||||
// Affiche statut contrat
|
||||
$now=mktime();
|
||||
if ($contrat->enservice == 1)
|
||||
{
|
||||
if (! $contrat->date_fin_validite || $contrat->date_fin_validite >= $now) {
|
||||
$class = 'normal';
|
||||
$statut=$langs->trans("ContractStatusRunning");
|
||||
}
|
||||
else {
|
||||
$class = 'error';
|
||||
$statut= $langs->trans("ContractStatusRunning").', '.img_warning().' '.$langs->trans("ContractStatusExpired");
|
||||
}
|
||||
}
|
||||
elseif($contrat->enservice == 2)
|
||||
{
|
||||
$class = 'normal';
|
||||
$statut= $langs->trans("ContractStatusClosed");
|
||||
}
|
||||
else
|
||||
{
|
||||
$class = 'warning';
|
||||
$statut= '<b>'.$langs->trans("ContractNotRunning").'</b>';
|
||||
}
|
||||
print "<tr><td>".$langs->trans("ContractStatus")."</td><td colspan=\"3\" class=\"$class\">$statut</td></tr>\n";
|
||||
$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 = "<option value=\"0\" selected></option>";
|
||||
if ($result)
|
||||
{
|
||||
$num = $db->num_rows(); $i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $db->fetch_object();
|
||||
$opt .= "<option value=\"$objp->rowid\">[$objp->ref] $objp->label : $objp->price</option>\n";
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$db->free();
|
||||
}
|
||||
else
|
||||
{
|
||||
print $db->error();
|
||||
}
|
||||
|
||||
print '<table class="noborder" cellspacing="0">';
|
||||
print '<tr><td>20 Produits les plus vendus</td><td>Quan.</td><td>Remise</td></tr>';
|
||||
for ($i = 1 ; $i < 5 ; $i++)
|
||||
{
|
||||
print '<tr><td><select name="idprod'.$i.'">'.$opt.'</select></td>';
|
||||
print '<td><input type="text" size="3" name="qty'.$i.'" value="1"></td>';
|
||||
print '<td><input type="text" size="4" name="remise_percent'.$i.'" value="0"> %</td></tr>';
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
print '</td></tr>';
|
||||
*/
|
||||
print '<tr><td>Commentaires</td><td valign="top">';
|
||||
print '<textarea name="note" wrap="soft" cols="60" rows="4"></textarea></td></tr>';
|
||||
|
||||
if ($_GET["request"] == 'miseenservice')
|
||||
{
|
||||
// Si contrat lié à une ligne de facture, on recherche date debut et fin de la ligne
|
||||
if ($contrat->facturedetid) {
|
||||
$facturedet = new FactureLigne($db);
|
||||
$facturedet->fetch($contrat->facturedetid);
|
||||
$date_start=$facturedet->date_start;
|
||||
$date_end=$facturedet->date_end;
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
print '<tr><td colspan="3" align="center"><input type="submit" value="Créer"></td></tr>';
|
||||
print "</form>\n";
|
||||
print "</table>\n";
|
||||
|
||||
// Si date_start et date_end ne sont pas connues de la ligne de facture, on les
|
||||
// definit à une valeur par défaut en fonction de la durée définie pour le service.
|
||||
if (! $date_start) { $date_start=mktime(); }
|
||||
if (! $date_end) {
|
||||
if ($contrat->product->duration)
|
||||
{
|
||||
// Si duree du service connue
|
||||
$duree_value = substr($contrat->product->duration,0,strlen($contrat->product->duration)-1);
|
||||
$duree_unit = substr($contrat->product->duration,-1);
|
||||
if ($propalid)
|
||||
{
|
||||
/*
|
||||
* Produits
|
||||
*/
|
||||
print_titre("Produits");
|
||||
|
||||
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="3">';
|
||||
print '<tr class="liste_titre"><td>'.$langs->trans("Ref").'</td><td>Produit</td>';
|
||||
print '<td align="right">'.$langs->trans("Price").'</td><td align="center">Remise</td><td align="center">Qté.</td></tr>';
|
||||
|
||||
$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 "<tr $bc[$var]><td>[$objp->ref]</td>\n";
|
||||
print '<td>'.$objp->product.'</td>';
|
||||
print "<td align=\"right\">".price($objp->price)."</TD>";
|
||||
print '<td align="center">'.$objp->remise_percent.' %</td>';
|
||||
print "<td align=\"center\">".$objp->qty."</td></tr>\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 "<tr $bc[$var]><td> </td>\n";
|
||||
print '<td>'.$objp->product.'</td>';
|
||||
print '<td align="right">'.price($objp->price).'</td>';
|
||||
print '<td align="center">'.$objp->remise_percent.' %</td>';
|
||||
print "<td align=\"center\">".$objp->qty."</td></tr>\n";
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print $sql;
|
||||
}
|
||||
|
||||
$month = date("m",$date_start);
|
||||
$day = date("d",$date_start);
|
||||
$year = date("Y",$date_start);
|
||||
|
||||
switch($duree_unit)
|
||||
{
|
||||
case "d":
|
||||
$day = $day + $duree_value;
|
||||
break;
|
||||
case "w":
|
||||
$day = $day + ($duree_value * 7);
|
||||
break;
|
||||
case "m":
|
||||
$month = $month + $duree_value;
|
||||
break;
|
||||
case "y":
|
||||
$year = $year + $duree_value;
|
||||
break;
|
||||
}
|
||||
$date_end = mktime(date("H",$date_start), date("i",$date_start), 0, $month, $day, $year);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
print '<form action="fiche.php?id='.$id.'" method="post">';
|
||||
print '<input type="hidden" name="action" value="miseenservice">';
|
||||
|
||||
print '<tr><td>Durée standard pour ce service</td><td colspan="3">';
|
||||
print $contrat->product->duration;
|
||||
print '<input type="hidden" name="duration" value="'.$contrat->product->duration.'">';
|
||||
print '</td></tr>';
|
||||
|
||||
// Date de début de mise en service
|
||||
print '<tr><td>Date de mise en service</td><td colspan="3">';
|
||||
print $html->select_date($date_start,'date_start',1,1);
|
||||
print " ";
|
||||
print '</td></tr>';
|
||||
|
||||
// Date de fin prévue de mise en service
|
||||
print '<tr><td>Date de fin prévue</td><td colspan="3">';
|
||||
print $html->select_date($date_end,'date_end',1,1);
|
||||
print " ";
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td colspan="4" align="center">';
|
||||
print '<input type="submit" value="'.$langs->trans("Save").'">';
|
||||
print '</td></tr>';
|
||||
print '</form>';
|
||||
}
|
||||
|
||||
if ($contrat->enservice > 0)
|
||||
{
|
||||
print "<tr><td valign=\"top\">Mis en service</td><td>".dolibarr_print_date($contrat->mise_en_service,"%d %B %Y à %H:%M");
|
||||
print "</td>";
|
||||
$contrat->user_service->fetch();
|
||||
print '<td>'.$langs->trans("By").'</td><td>'.$contrat->user_service->fullname.'</td></tr>';
|
||||
|
||||
print '<tr><td valign="top">Fin de validité</td><td colspan="3">'.dolibarr_print_date($contrat->date_fin_validite,"%d %B %Y à %H:%M");
|
||||
}
|
||||
|
||||
if ($contrat->enservice == 2)
|
||||
{
|
||||
print '<tr><td valign="top">'.$langs->trans("Closed").'</td><td>'.dolibarr_print_date($contrat->date_cloture,"%d %B %Y à %H:%M").'</td>';
|
||||
$contrat->user_cloture->fetch();
|
||||
print '<td>'.$langs->trans("By").'</td><td>'.$contrat->user_cloture->fullname.'</td></tr>';
|
||||
}
|
||||
|
||||
|
||||
print "</table>";
|
||||
print '<br>';
|
||||
print '</div>';
|
||||
print '</table>';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print $db->error() . "<br>$sql";;
|
||||
}
|
||||
}
|
||||
else
|
||||
/* *************************************************************************** */
|
||||
/* */
|
||||
/* Mode vue et edition */
|
||||
/* */
|
||||
/* *************************************************************************** */
|
||||
{
|
||||
$id = $_GET["id"];
|
||||
if ($id > 0)
|
||||
{
|
||||
$contrat = New Contrat($db);
|
||||
if ( $contrat->fetch($id) > 0)
|
||||
{
|
||||
|
||||
$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("Contract");
|
||||
$hselected = $h;
|
||||
$h++;
|
||||
|
||||
|
||||
|
||||
dolibarr_fiche_head($head, $hselected, $contrat->societe->nom);
|
||||
|
||||
/*
|
||||
* 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 '<form action="fiche.php?id='.$id.'" method="post">';
|
||||
print '<input type="hidden" name="action" value="setremise">';
|
||||
}
|
||||
|
||||
print '<table class="border" cellspacing="0" cellpadding="2" width="100%">';
|
||||
print "<tr><td>".$langs->trans("Customer")."</td>";
|
||||
print '<td colspan="2">';
|
||||
print '<b><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$contrat->societe->id.'">'.$contrat->societe->nom.'</a></b></td>';
|
||||
|
||||
print '<td width="50%" colspan="2">';
|
||||
print $contrat->statuts[$contrat->statut];
|
||||
print "</td></tr>";
|
||||
|
||||
print '<tr><td>'.$langs->trans("Date").'</td>';
|
||||
print "<td colspan=\"2\">".strftime("%A %d %B %Y",$contrat->date_contrat)."</td>\n";
|
||||
|
||||
print '<td>Projet</td><td>';
|
||||
if ($contrat->projet_id > 0)
|
||||
{
|
||||
$projet = New Project($db);
|
||||
$projet->fetch($contrat->projet_id);
|
||||
print '<a href="'.DOL_URL_ROOT.'/projet/fiche.php?id='.$contrat->projet_id.'">'.$projet->title.'</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<a href="fiche.php?id='.$id.'&action=classer">Classer le contrat</a>';
|
||||
}
|
||||
print " </td></tr>";
|
||||
|
||||
print '<tr><td>'.$langs->trans("Commercial suivi").'</td><td colspan="2">'.$commercial_suivi->fullname.'</td>';
|
||||
print '<td>'.$langs->trans("Commercial signature").'</td><td colspan="2">'.$commercial_signature->fullname.'</td></tr>';
|
||||
print "</table>";
|
||||
|
||||
if ($contrat->brouillon == 1 && $user->rights->contrat->creer)
|
||||
{
|
||||
print '</form>';
|
||||
}
|
||||
|
||||
/*
|
||||
* Lignes de contrats
|
||||
*
|
||||
*/
|
||||
echo '<br><table border="0" width="100%" cellspacing="0" cellpadding="3">';
|
||||
|
||||
$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 '<tr class="liste_titre">';
|
||||
print '<td width="54%">'.$langs->trans("Description").'</td>';
|
||||
print '<td width="8%" align="center">Tva</td>';
|
||||
print '<td width="8%" align="center">Quantité</td>';
|
||||
print '<td width="8%" align="right">Remise</td>';
|
||||
print '<td width="12%" align="right">P.U.</td>';
|
||||
print '<td width="10%"> </td><td width="10%"> </td>';
|
||||
print "</tr>\n";
|
||||
}
|
||||
$var=True;
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $db->fetch_object();
|
||||
print "<tr $bc[$var]>\n";
|
||||
if ($objp->fk_product > 0)
|
||||
{
|
||||
print '<td>';
|
||||
print '<a href="'.DOL_URL_ROOT.'/contrat/ligne.php?id='.$contrat->id.'&ligne='.$objp->rowid.'">';;
|
||||
print '<img src="./statut'.$objp->statut.'.png" border="0" alt="statut"></a> ';
|
||||
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.stripslashes(nl2br($objp->label)).'</a>';
|
||||
|
||||
if ($objp->description)
|
||||
{
|
||||
|
||||
print '<br />'.stripslashes(nl2br($objp->description));
|
||||
}
|
||||
|
||||
print '</td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<td>".stripslashes(nl2br($objp->description))."</TD>\n";
|
||||
}
|
||||
print '<td align="center">'.$objp->tva_tx.' %</TD>';
|
||||
print '<td align="center">'.$objp->qty.'</TD>';
|
||||
if ($objp->remise_percent > 0)
|
||||
{
|
||||
print '<td align="right">'.$objp->remise_percent." %</td>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<td> </td>';
|
||||
}
|
||||
print '<td align="right">'.price($objp->subprice)."</td>\n";
|
||||
if ($contrat->statut == 0 && $user->rights->contrat->creer)
|
||||
{
|
||||
print '<td align="right"><a href="fiche.php?id='.$id.'&action=editline&rowid='.$objp->rowid.'">';
|
||||
print img_edit();
|
||||
print '</a></td>';
|
||||
print '<td align="right"><a href="fiche.php?id='.$id.'&action=deleteline&lineid='.$objp->rowid.'">';
|
||||
print img_delete();
|
||||
print '</a></td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<td> </td><td> </td>';
|
||||
}
|
||||
print "</tr>\n";
|
||||
|
||||
if ($_GET["action"] == 'editline' && $_GET["rowid"] == $objp->rowid)
|
||||
{
|
||||
print "<form action=\"fiche.php?id=$id\" method=\"post\">";
|
||||
print '<input type="hidden" name="action" value="updateligne">';
|
||||
print '<input type="hidden" name="elrowid" value="'.$_GET["rowid"].'">';
|
||||
print "<tr $bc[$var]>";
|
||||
print '<td colspan="2"><textarea name="eldesc" cols="60" rows="2">'.stripslashes($objp->description).'</textarea></TD>';
|
||||
print '<td align="center"><input size="4" type="text" name="elqty" value="'.$objp->qty.'"></TD>';
|
||||
print '<td align="right"><input size="3" type="text" name="elremise_percent" value="'.$objp->remise_percent.'"> %</td>';
|
||||
print '<td align="right"><input size="8" type="text" name="elprice" value="'.price($objp->subprice).'"></td>';
|
||||
print '<td align="right" colspan="2"><input type="submit" value="'.$langs->trans("Save").'"></td>';
|
||||
print '</tr>' . "\n";
|
||||
print "</form>\n";
|
||||
}
|
||||
$i++;
|
||||
$var=!$var;
|
||||
}
|
||||
$db->free();
|
||||
}
|
||||
else
|
||||
{
|
||||
print $db->error();
|
||||
}
|
||||
|
||||
/*
|
||||
* Ajouter une ligne produit/service
|
||||
*
|
||||
*/
|
||||
if ($user->rights->contrat->creer)
|
||||
{
|
||||
$sql = "SELECT p.rowid,p.label,p.ref,p.price FROM ".MAIN_DB_PREFIX."product as p ";
|
||||
$sql .= " WHERE p.envente = 1";
|
||||
$sql .= " ORDER BY p.nbvente DESC LIMIT 20";
|
||||
|
||||
if ( $db->query($sql) )
|
||||
{
|
||||
$opt = "<option value=\"0\" SELECTED></option>";
|
||||
|
||||
$num = $db->num_rows();
|
||||
$i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $db->fetch_object();
|
||||
$opt .= "<option value=\"$objp->rowid\">[$objp->ref] $objp->label : $objp->price</option>\n";
|
||||
$i++;
|
||||
}
|
||||
|
||||
$db->free();
|
||||
}
|
||||
else
|
||||
{
|
||||
print $db->error();
|
||||
}
|
||||
|
||||
print '<form action="fiche.php?id='.$id.'" method="post">';
|
||||
print '<input type="hidden" name="action" value="addligne">';
|
||||
|
||||
print "<tr class=\"liste_titre\">";
|
||||
print '<td width="54%">'.$langs->trans("Description").'</td>';
|
||||
print '<td width="8%" align="center">Tva</td>';
|
||||
print '<td width="8%" align="center">Quantité</td>';
|
||||
print '<td width="8%" align="right">Remise</td>';
|
||||
print '<td width="12%" align="right">P.U.</TD>';
|
||||
print '<td> </td><td> </td>'."</tr>\n";
|
||||
|
||||
|
||||
/*
|
||||
print "<tr $bc[$var]>".'<td><textarea name="desc" cols="60" rows="1"></textarea></td>';
|
||||
print '<td align="center">';
|
||||
print $html->select_tva("tva_tx");
|
||||
print '</td>';
|
||||
print '<td align="center"><input type="text" name="qty" value="1" size="2"></td>';
|
||||
print '<td align="right"><input type="text" name="remise_percent" size="4" value="0"> %</td>';
|
||||
print '<td align="right"><input type="text" name="pu" size="8"></td>';
|
||||
|
||||
print '<td align="center" colspan="3"><input type="submit" value="'.$langs->trans("Add").'"></td></tr>';
|
||||
*/
|
||||
|
||||
$var=!$var;
|
||||
print "<tr $bc[$var]>";
|
||||
print '<td colspan="2"><select name="p_idprod">'.$opt.'</select></td>';
|
||||
print '<td align="center"><input type="text" size="2" name="pqty" value="1"></td>';
|
||||
print '<td align="right"><input type="text" size="4" name="premise" value="0"> %</td>';
|
||||
print '<td> </td>';
|
||||
print '<td align="center" colspan="3"><input type="submit" value="'.$langs->trans("Add").'"></td></tr>';
|
||||
print "</tr>\n";
|
||||
print "<tr $bc[$var]>".'<td colspan="7"><textarea name="desc" cols="60" rows="1"></textarea></td></tr>';
|
||||
|
||||
print "</form>";
|
||||
}
|
||||
print "</table><br>";
|
||||
/*
|
||||
* Fin Ajout ligne
|
||||
*
|
||||
*/
|
||||
|
||||
print '</div>';
|
||||
|
||||
if ($user->societe_id == 0 && $contrat->statut < 3)
|
||||
{
|
||||
print '<div class="tabsAction">';
|
||||
|
||||
if ($contrat->statut == 0 && $user->rights->contrat->supprimer)
|
||||
{
|
||||
print '<a class="tabAction" href="fiche.php?id='.$id.'&action=delete">Supprimer</a>';
|
||||
}
|
||||
|
||||
if ($contrat->statut > 0 && $contrat->statut < 3 && $user->rights->expedition->creer)
|
||||
{
|
||||
print '<a class="tabAction" href="'.DOL_URL_ROOT.'/expedition/contrat.php?id='.$_GET["id"].'">Expédier</a>';
|
||||
}
|
||||
|
||||
|
||||
if ($contrat->statut == 0)
|
||||
{
|
||||
if ($user->rights->contrat->valider)
|
||||
{
|
||||
print '<a class="tabAction" href="fiche.php?id='.$id.'&action=valid">Valider</a>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($contrat->statut == 1)
|
||||
{
|
||||
$nb_expedition = $contrat->nb_expedition();
|
||||
if ($user->rights->contrat->valider && $nb_expedition == 0)
|
||||
{
|
||||
print '<a class="tabAction" href="fiche.php?id='.$id.'&action=annuler">Annuler la contrat</a>';
|
||||
}
|
||||
}
|
||||
|
||||
print "</div>";
|
||||
}
|
||||
print "<p>\n";
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
*/
|
||||
if ($_GET["action"] == 'classer')
|
||||
{
|
||||
print '<p><form method="post" action="fiche.php?id='.$contrat->id.'">';
|
||||
print '<input type="hidden" name="action" value="classin">';
|
||||
print '<table cellspacing="0" class="border" cellpadding="3">';
|
||||
print '<tr><td>Projet</td><td>';
|
||||
|
||||
$proj = new Project($db);
|
||||
$html->select_array("projetid",$proj->liste_array($contrat->soc_id));
|
||||
|
||||
print "</td></tr>";
|
||||
print '<tr><td colspan="2" align="center"><input type="submit" value="Envoyer"></td></tr></table></form>';
|
||||
}
|
||||
/*
|
||||
*
|
||||
*
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Contrat non trouvée */
|
||||
print "Contrat inexistante ou accés refusé";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error(0,"Contract id not provided");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* Barre d'action */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
print '<div class="tabsAction">';
|
||||
|
||||
if (! $contrat->enservice)
|
||||
{
|
||||
if ($request != 'miseenservice') {
|
||||
print '<a class="tabAction" href="fiche.php?request=miseenservice&id='.$id.'">Mettre en service...</a>';
|
||||
} else {
|
||||
print '<a class="tabAction" href="fiche.php?id='.$id.'">Ne pas mettre en service</a>';
|
||||
}
|
||||
}
|
||||
elseif ($contrat->enservice == 1)
|
||||
{
|
||||
print '<a class="tabAction" href="fiche.php?action=annule&id='.$id.'">Mettre hors service</a>';
|
||||
print '<a class="tabAction" href="fiche.php?action=cloture&id='.$id.'">'.$langs->trans("Close").'</a>';
|
||||
}
|
||||
print '</div>';
|
||||
|
||||
$db->close();
|
||||
|
||||
|
||||
@ -53,103 +53,46 @@ if ($user->societe_id > 0)
|
||||
$socid = $user->societe_id;
|
||||
}
|
||||
|
||||
|
||||
if ($page == -1) { $page = 0 ; }
|
||||
|
||||
$limit = $conf->liste_limit;
|
||||
$offset = $limit * $page ;
|
||||
|
||||
if ($sortfield == "")
|
||||
{
|
||||
$sortfield="c.tms";
|
||||
}
|
||||
|
||||
if ($sortorder == "")
|
||||
{
|
||||
$sortorder="DESC";
|
||||
}
|
||||
print_barre_liste("Contrats", $page, "index.php", "&sref=$sref&snom=$snom", $sortfield, $sortorder,'',$num);
|
||||
|
||||
|
||||
$sql = "SELECT c.rowid as cid, c.enservice, ".$db->pdate("c.fin_validite")." as fin_validite, c.fin_validite-sysdate() as delairestant, p.label, p.rowid as pid, s.nom, s.idp as sidp";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."product as p";
|
||||
$sql .= " WHERE c.fk_soc = s.idp AND c.fk_product = p.rowid";
|
||||
if ($socid > 0)
|
||||
{
|
||||
$sql .= " AND s.idp = $socid";
|
||||
}
|
||||
$sql .= " ORDER BY $sortfield $sortorder, delairestant";
|
||||
$sql .= $db->plimit($limit + 1 ,$offset);
|
||||
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
|
||||
print '<tr><td width="30%" valign="top">Légende<br />';
|
||||
print '<img src="./statut0.png" border="0" alt="statut"> Statut initial<br />';
|
||||
print '<img src="./statut1.png" border="0" alt="statut"> A commander<br />';
|
||||
print '<img src="./statut2.png" border="0" alt="statut"> Commandé chez le fournisseur<br />';
|
||||
print '<img src="./statut3.png" border="0" alt="statut"> Activé chez le fournisseur<br />';
|
||||
print '<img src="./statut4.png" border="0" alt="statut"> Activé chez le client<br />';
|
||||
|
||||
print '</td><td width="70%" valign="top">';
|
||||
|
||||
$sql = "SELECT cd.rowid as cid, cd.statut, cd.label, cd.fk_contrat ";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."contratdet as cd";
|
||||
$sql .= " WHERE cd.statut IN (0,3)";
|
||||
$sql .= " ORDER BY cd.tms DESC";
|
||||
|
||||
if ( $db->query($sql) )
|
||||
{
|
||||
$num = $db->num_rows();
|
||||
$i = 0;
|
||||
|
||||
|
||||
print_barre_liste("Liste des contrats", $page, "index.php", "&sref=$sref&snom=$snom", $sortfield, $sortorder,'',$num);
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
print_liste_field_titre($langs->trans("Ref"),"index.php", "c.rowid","","","",$sortfield);
|
||||
print_liste_field_titre($langs->trans("Label"),"index.php", "p.label","","","",$sortfield);
|
||||
print_liste_field_titre($langs->trans("Company"),"index.php", "s.nom","","","",$sortfield);
|
||||
print_liste_field_titre($langs->trans("Status"),"index.php", "c.enservice","","",'align="center"',$sortfield);
|
||||
print_liste_field_titre("Date Fin","index.php", "c.fin_validite","","",'align="center"',$sortfield);
|
||||
print '<td>'.$langs->trans("Action").'</td>';
|
||||
print '<tr class="liste_titre"><td>Service</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
$now=mktime();
|
||||
$var=True;
|
||||
while ($i < min($num,$limit))
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $db->fetch_object();
|
||||
$var=!$var;
|
||||
print "<tr $bc[$var]>";
|
||||
print "<td><a href=\"fiche.php?id=$obj->cid\">";
|
||||
print img_file();
|
||||
print "</a> <a href=\"fiche.php?id=$obj->cid\">$obj->cid</a></td>\n";
|
||||
print "<td><a href=\"../product/fiche.php?id=$obj->pid\">$obj->label</a></td>\n";
|
||||
print "<td><a href=\"../comm/fiche.php?socid=$obj->sidp\">$obj->nom</a></td>\n";
|
||||
|
||||
// Affiche statut contrat
|
||||
if ($obj->enservice == 1)
|
||||
{
|
||||
if (! $obj->fin_validite || $obj->fin_validite >= $now) {
|
||||
$class = 'normal';
|
||||
$statut= $langs->trans("ContractStatusRunning");
|
||||
}
|
||||
else {
|
||||
$class = 'error';
|
||||
$statut= $langs->trans("ContractStatusRunning").', '.img_warning().' '.$langs->trans("ContractStatusExpired");
|
||||
}
|
||||
}
|
||||
elseif($obj->enservice == 2)
|
||||
{
|
||||
$class = "normal";
|
||||
$statut= $langs->trans("Closed");
|
||||
}
|
||||
else
|
||||
{
|
||||
$class = "warning";
|
||||
$statut= $langs->trans("ContractStatusToRun");
|
||||
}
|
||||
print "<td align=\"center\" class=\"$class\">";
|
||||
print "$statut";
|
||||
print "</td>";
|
||||
|
||||
print "<td align=\"center\">";
|
||||
if ($obj->enservice > 0) {
|
||||
print dolibarr_print_date($obj->fin_validite);
|
||||
}
|
||||
else {
|
||||
print " ";
|
||||
}
|
||||
print "</td>\n";
|
||||
|
||||
print '<td>';
|
||||
// \todo Créer action "Renouveler"
|
||||
print '</td>';
|
||||
print "<td>";
|
||||
print '<img src="./statut'.$obj->statut.'.png" border="0" alt="statut"></a> ';
|
||||
print "</a> <a href=\"fiche.php?id=$obj->fk_contrat\">$obj->label</a></td>\n";
|
||||
|
||||
|
||||
|
||||
print "</tr>\n";
|
||||
$i++;
|
||||
@ -164,6 +107,7 @@ else
|
||||
dolibarr_print_error($db);
|
||||
}
|
||||
|
||||
print '</td></tr></table>';
|
||||
|
||||
$db->close();
|
||||
|
||||
|
||||
329
htdocs/contrat/ligne.php
Normal file
329
htdocs/contrat/ligne.php
Normal file
@ -0,0 +1,329 @@
|
||||
<?php
|
||||
/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* 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/commande/fiche.php
|
||||
\ingroup commande
|
||||
\brief Fiche commande
|
||||
\version $Revision$
|
||||
*/
|
||||
|
||||
require("./pre.inc.php");
|
||||
|
||||
$langs->load("contracts");
|
||||
$langs->load("orders");
|
||||
$langs->load("companies");
|
||||
|
||||
$user->getrights('contrat');
|
||||
|
||||
if (!$user->rights->contrat->lire)
|
||||
accessforbidden();
|
||||
|
||||
require("../project.class.php");
|
||||
require("../propal.class.php");
|
||||
require_once (DOL_DOCUMENT_ROOT."/contrat/contrat.class.php");
|
||||
|
||||
/*
|
||||
* Sécurité accés client
|
||||
*/
|
||||
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 = '';
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
if ($_POST["action"] == 'confirm_active' && $_POST["confirm"] == 'yes' && $user->rights->contrat->activer)
|
||||
{
|
||||
$contrat = new Contrat($db);
|
||||
$contrat->fetch($_GET["id"]);
|
||||
|
||||
$result = $contrat->active_line($user, $_GET["ligne"], $_GET["date"]);
|
||||
|
||||
if ($result == 0)
|
||||
{
|
||||
Header("Location: fiche.php?id=".$contrat->id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
llxHeader('',$langs->trans("Contract"),"Contrat");
|
||||
|
||||
$html = new Form($db);
|
||||
|
||||
/* *************************************************************************** */
|
||||
/* */
|
||||
/* Mode vue et edition */
|
||||
/* */
|
||||
/* *************************************************************************** */
|
||||
|
||||
$id = $_GET["id"];
|
||||
if ($id > 0)
|
||||
{
|
||||
$contrat = New Contrat($db);
|
||||
if ( $contrat->fetch($id) > 0)
|
||||
{
|
||||
|
||||
$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("Contract");
|
||||
$h++;
|
||||
|
||||
$head[$h][0] = DOL_URL_ROOT.'/contrat/ligne.php?id='.$contrat->id;
|
||||
$head[$h][1] = $langs->trans("Edition de la ligne");
|
||||
$hselected = $h;
|
||||
|
||||
dolibarr_fiche_head($head, $hselected, $contrat->societe->nom);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Contrat
|
||||
*/
|
||||
|
||||
|
||||
print '<table class="border" cellspacing="0" cellpadding="2" width="100%">';
|
||||
print "<tr><td>".$langs->trans("Customer")."</td>";
|
||||
print '<td colspan="2">';
|
||||
print '<b><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$contrat->societe->id.'">'.$contrat->societe->nom.'</a></b></td>';
|
||||
|
||||
print '<td width="50%" colspan="2">';
|
||||
print $contrat->statuts[$contrat->statut];
|
||||
print "</td></tr>";
|
||||
|
||||
print '<tr><td>'.$langs->trans("Date").'</td>';
|
||||
print "<td colspan=\"2\">".strftime("%A %d %B %Y",$contrat->date_contrat)."</td>\n";
|
||||
|
||||
print '<td>Projet</td><td>';
|
||||
if ($contrat->projet_id > 0)
|
||||
{
|
||||
$projet = New Project($db);
|
||||
$projet->fetch($contrat->projet_id);
|
||||
print '<a href="'.DOL_URL_ROOT.'/projet/fiche.php?id='.$contrat->projet_id.'">'.$projet->title.'</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<a href="fiche.php?id='.$id.'&action=classer">Classer le contrat</a>';
|
||||
}
|
||||
print " </td></tr>";
|
||||
|
||||
print '<tr><td>'.$langs->trans("Commercial suivi").'</td><td colspan="2">'.$commercial_suivi->fullname.'</td>';
|
||||
print '<td>'.$langs->trans("Commercial signature").'</td><td colspan="2">'.$commercial_signature->fullname.'</td></tr>';
|
||||
print "</table>";
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Confirmation de la validation
|
||||
*
|
||||
*/
|
||||
if ($_GET["action"] == 'active' && $user->rights->contrat->activer)
|
||||
{
|
||||
print '<br />';
|
||||
$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");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Lignes de contrats
|
||||
*
|
||||
*/
|
||||
echo '<br><table border="0" width="100%" cellspacing="0" cellpadding="3">';
|
||||
|
||||
$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";
|
||||
|
||||
$result = $db->query($sql);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$num = $db->num_rows();
|
||||
$i = 0; $total = 0;
|
||||
|
||||
if ($num)
|
||||
{
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td width="54%">'.$langs->trans("Description").'</td>';
|
||||
print '<td width="8%" align="center">Tva</td>';
|
||||
print '<td width="8%" align="center">Quantité</td>';
|
||||
print '<td width="8%" align="right">Remise</td>';
|
||||
print '<td width="12%" align="right">P.U.</td>';
|
||||
print '<td width="10%"> </td><td width="10%"> </td>';
|
||||
print "</tr>\n";
|
||||
}
|
||||
$var=True;
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $db->fetch_object();
|
||||
print "<tr $bc[$var]>\n";
|
||||
if ($objp->fk_product > 0)
|
||||
{
|
||||
print '<td>';
|
||||
print '<img src="./statut'.$objp->statut.'.png" border="0" alt="statut"> ';
|
||||
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.stripslashes(nl2br($objp->label)).'</a>';
|
||||
|
||||
if ($objp->description)
|
||||
{
|
||||
print '<br />'.stripslashes(nl2br($objp->description));
|
||||
}
|
||||
|
||||
print '</td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<td>".stripslashes(nl2br($objp->description))."</TD>\n";
|
||||
}
|
||||
print '<td align="center">'.$objp->tva_tx.' %</TD>';
|
||||
print '<td align="center">'.$objp->qty.'</TD>';
|
||||
if ($objp->remise_percent > 0)
|
||||
{
|
||||
print '<td align="right">'.$objp->remise_percent." %</td>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<td> </td>';
|
||||
}
|
||||
print '<td align="right">'.price($objp->subprice)."</td>\n";
|
||||
|
||||
print '<td> </td><td> </td>';
|
||||
|
||||
print "</tr>\n";
|
||||
|
||||
|
||||
$i++;
|
||||
$var=!$var;
|
||||
}
|
||||
$db->free();
|
||||
}
|
||||
else
|
||||
{
|
||||
print $db->error();
|
||||
}
|
||||
|
||||
|
||||
print '</div>';
|
||||
|
||||
|
||||
print "<p>\n";
|
||||
|
||||
|
||||
|
||||
if ( $user->rights->contrat->activer && $contrat->statut == 0 && $objp->statut <> 4)
|
||||
{
|
||||
/**
|
||||
* Activer la ligne de contrat
|
||||
*/
|
||||
$form = new Form($db);
|
||||
|
||||
print '<table class="noborder" cellpadding="2" cellspacing="0" width="100%"><tr><td>';
|
||||
|
||||
print '<form action="ligne.php?id='.$contrat->id.'&ligne='.$_GET["ligne"].'&action=active" method="post">';
|
||||
print '<table class="noborder" cellpadding="2" cellspacing="0">';
|
||||
print '<tr class="liste_titre"><td colspan="2">Activer le service</td><td>';
|
||||
print '<tr><td>Date d\'activation</td><td>';
|
||||
|
||||
if ($_POST["remonth"])
|
||||
{
|
||||
$dateact = mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$dateact = time();
|
||||
}
|
||||
|
||||
print $form->select_date($dateact);
|
||||
print '</td>';
|
||||
|
||||
print '<tr><td>Intervenant</td><td>'.$user->fullname.'</td></tr>';
|
||||
|
||||
print '<tr><td>Commentaire</td><td><input size="30" type="text" name="commentaire"></td></tr>';
|
||||
|
||||
print '<tr><td colspan="2" align="center"><input type="submit" name="Activer"></td></tr>';
|
||||
print '</table>';
|
||||
|
||||
print '</form></td><td>';
|
||||
|
||||
print ' </td></tr></table>';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Contrat non trouvée */
|
||||
print "Contrat inexistante ou accés refusé";
|
||||
}
|
||||
}
|
||||
|
||||
$db->close();
|
||||
|
||||
llxFooter("<em>Dernière modification $Date$ révision $Revision$</em>");
|
||||
?>
|
||||
@ -21,9 +21,6 @@
|
||||
*/
|
||||
require("../main.inc.php");
|
||||
|
||||
$types[0] = "produit";
|
||||
$types[1] = "service";
|
||||
|
||||
function llxHeader($head = "", $urlp = "")
|
||||
{
|
||||
global $user, $conf;
|
||||
@ -37,6 +34,7 @@ function llxHeader($head = "", $urlp = "")
|
||||
$menu = new Menu();
|
||||
|
||||
$menu->add(DOL_URL_ROOT."/contrat/index.php", "Contrats");
|
||||
$menu->add_submenu(DOL_URL_ROOT."/contrat/liste.php", "Liste");
|
||||
$menu->add_submenu(DOL_URL_ROOT."/contrat/enservice.php", "En service");
|
||||
|
||||
left_menu($menu->liste);
|
||||
|
||||
BIN
htdocs/contrat/statut0.png
Normal file
BIN
htdocs/contrat/statut0.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 198 B |
BIN
htdocs/contrat/statut1.png
Normal file
BIN
htdocs/contrat/statut1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 197 B |
BIN
htdocs/contrat/statut2.png
Normal file
BIN
htdocs/contrat/statut2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 191 B |
BIN
htdocs/contrat/statut3.png
Normal file
BIN
htdocs/contrat/statut3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 227 B |
BIN
htdocs/contrat/statut4.png
Normal file
BIN
htdocs/contrat/statut4.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 193 B |
Loading…
Reference in New Issue
Block a user