";
@@ -803,37 +816,20 @@ else
* Boutons Actions
*************************************************************/
- if ($user->societe_id == 0 && $contrat->statut < 3)
+ if ($user->societe_id == 0)
{
print '';
- if ($contrat->statut == 0 && $user->rights->contrat->supprimer)
+ if ($contrat->statut == 0 && $num)
+ {
+ print '
'.$langs->trans("Valid").'';
+ }
+
+ if ($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 "
";
}
diff --git a/htdocs/contrat/index.php b/htdocs/contrat/index.php
index 59e7322e9f8..c7215342e27 100644
--- a/htdocs/contrat/index.php
+++ b/htdocs/contrat/index.php
@@ -29,6 +29,7 @@
*/
require("./pre.inc.php");
+require_once (DOL_DOCUMENT_ROOT."/contrat/contrat.class.php");
$langs->load("products");
$langs->load("companies");
@@ -67,10 +68,8 @@ print '';
print '| '.$langs->trans("Legend").' |
';
print '';
print ' Statut initial ';
-print ' A commander ';
-print ' Commandé chez le fournisseur ';
-print ' Activé chez le fournisseur ';
-print ' Activé chez le client ';
+print ' '.$langs->trans("ContractStatusRunning").' ';
+print ' '.$langs->trans("Closed").' ';
print ' |
';
print '
';
@@ -92,10 +91,64 @@ if ($conf->contrat->enabled) {
print '';
+
+// Last contracts
+$max=5;
+$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 ($socid > 0) $sql .= " AND s.idp = $socid";
+$sql.= " GROUP BY c.rowid, c.datec, c.statut, s.nom, s.idp";
+$sql.= " ORDER BY c.date_contrat DESC";
+$sql.= " LIMIT $max";
+
+$result=$db->query($sql);
+if ($result)
+{
+ $num = $db->num_rows($result);
+ $i = 0;
+
+ print '";
+
+}
+else
+{
+ dolibarr_print_error($db);
+}
+
+print ' ';
+
+
// Not activated services
$sql = "SELECT cd.rowid as cid, cd.statut, cd.label, cd.description as note, cd.fk_contrat, c.fk_soc, s.nom";
$sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s";
-$sql.= " WHERE cd.statut IN (0,3)";
+$sql.= " WHERE c.statut=1 AND cd.statut = 0";
$sql.= " AND cd.fk_contrat = c.rowid AND c.fk_soc = s.idp";
$sql.= " ORDER BY cd.tms DESC";
diff --git a/htdocs/contrat/ligne.php b/htdocs/contrat/ligne.php
index 0e18f618d70..d1118b48c40 100644
--- a/htdocs/contrat/ligne.php
+++ b/htdocs/contrat/ligne.php
@@ -18,14 +18,13 @@
*
* $Id$
* $Source$
- *
*/
/**
- \file htdocs/contrat/ligne.php
- \ingroup contrat
- \brief Fiche contrat
- \version $Revision$
+ \file htdocs/contrat/ligne.php
+ \ingroup contrat
+ \brief Fiche contrat
+ \version $Revision$
*/
require("./pre.inc.php");
@@ -37,7 +36,7 @@ $langs->load("companies");
$user->getrights('contrat');
if (!$user->rights->contrat->lire)
- accessforbidden();
+accessforbidden();
require("../project.class.php");
require("../propal.class.php");
@@ -46,16 +45,16 @@ 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"] == 'confirm_active' && $_POST["confirm"] == 'yes' && $user->rights->contrat->activer)
{
$contrat = new Contrat($db);
@@ -68,8 +67,29 @@ if ($_POST["action"] == 'confirm_active' && $_POST["confirm"] == 'yes' && $user-
Header("Location: fiche.php?id=".$contrat->id);
exit;
}
+ else {
+ $mesg=$contrat->error;
+ }
}
+if ($_POST["action"] == 'confirm_close' && $_POST["confirm"] == 'yes' && $user->rights->contrat->activer)
+{
+ $contrat = new Contrat($db);
+ $contrat->fetch($_GET["id"]);
+
+ $result = $contrat->close_line($user, $_GET["ligne"], $_GET["dateend"]);
+
+ if ($result > 0)
+ {
+ Header("Location: fiche.php?id=".$contrat->id);
+ exit;
+ }
+ else {
+ $mesg=$contrat->error;
+ }
+}
+
+
llxHeader('',$langs->trans("Contract"),"Contrat");
@@ -80,288 +100,340 @@ $html = new Form($db);
/* 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)
- {
- $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");
- $h++;
+ $h = 0;
+ $head[$h][0] = DOL_URL_ROOT.'/contrat/fiche.php?id='.$contrat->id;
+ $head[$h][1] = $langs->trans("ContractCard");
+ $h++;
- $head[$h][0] = DOL_URL_ROOT.'/contrat/ligne.php?id='.$contrat->id."&ligne=".$_GET["ligne"];
- $head[$h][1] = $langs->trans($langs->trans("EditServiceLine"));
- $hselected = $h;
-
- dolibarr_fiche_head($head, $hselected, $langs->trans("Contract").': '.$contrat->id);
+ $head[$h][0] = DOL_URL_ROOT.'/contrat/ligne.php?id='.$contrat->id."&ligne=".$_GET["ligne"];
+ $head[$h][1] = $langs->trans($langs->trans("EditServiceLine"));
+ $hselected = $h;
+
+ dolibarr_fiche_head($head, $hselected, $langs->trans("Contract").': '.$contrat->id);
- /*
- * Contrat
- */
+ /*
+ * Contrat
+ */
- print '';
+ print '';
- // Reference du contrat
- print '| '.$langs->trans("Ref").' | ';
- print $contrat->ref;
- print " | ";
+ // Reference du contrat
+ print '| '.$langs->trans("Ref").' | ';
+ print $contrat->ref;
+ print " | ";
- // Customer
- print "| ".$langs->trans("Customer")." | ";
- print '';
- print ''.$contrat->societe->nom.' | ';
-
- // Status
- print '| '.$langs->trans("Status").' | ';
- print $contrat->statuts[$contrat->statut];
- print " | ";
-
- // Date
- print '| '.$langs->trans("Date").' | ';
- print ''.strftime("%A %d %B %Y",$contrat->date_contrat)." | \n";
+ // Customer
+ print "| ".$langs->trans("Customer")." | ";
+ print '';
+ print ''.$contrat->societe->nom.' | ';
- if ($conf->projet->enabled)
- {
- print '| '.$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 " | ";
- }
+ // Status
+ print '| '.$langs->trans("Status").' | ';
+ print $contrat->statuts[$contrat->statut];
+ print " | ";
- print '| '.$langs->trans("SalesRepresentativeFollowUp").' | '.$commercial_suivi->fullname.' | ';
- print ''.$langs->trans("SalesRepresentativeSignature").' | '.$commercial_signature->fullname.' | ';
- print " ";
-
-
- /*
- * Confirmation de la validation
- *
- */
- if ($_GET["action"] == 'active' && $user->rights->contrat->activer)
- {
- print ' ';
- $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");
- }
+ // Date
+ print '| '.$langs->trans("Date").' | ';
+ print ''.strftime("%A %d %B %Y",$contrat->date_contrat)." | \n";
-
- /*
- * Lignes de contrats
- *
- */
- print '
';
+ if ($conf->projet->enabled)
+ {
+ print '| '.$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 " | ";
+ }
- $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($result);
- $i = 0; $total = 0;
-
- if ($num)
- {
- print '';
- print '| '.$langs->trans("Service").' | ';
- print ''.$langs->trans("VAT").' | ';
- print ''.$langs->trans("PriceUHT").' | ';
- print ''.$langs->trans("Qty").' | ';
- print ''.$langs->trans("Discount").' | ';
- print ' | ';
- print ' | ';
- print ''.$langs->trans("Status").' | ';
- print " \n";
- }
- $var=true;
- while ($i < $num)
- {
- $objp = $db->fetch_object($result);
+ print '| '.$langs->trans("SalesRepresentativeFollowUp").' | '.$commercial_suivi->fullname.' | ';
+ print ''.$langs->trans("SalesRepresentativeSignature").' | '.$commercial_signature->fullname.' | ';
+ print " ";
- $var=!$var;
- print "\n";
- // Libellé
- if ($objp->fk_product > 0)
- {
- print ''.img_object($langs->trans("ShowService"),"service").' '.$objp->label.'';
+ /*
+ * Confirmation de la validation activation
+ */
+ if ($_GET["action"] == 'active' && $user->rights->contrat->activer)
+ {
+ print ' ';
+ $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");
+ }
- if ($objp->description)
- {
- print ' '.stripslashes(nl2br($objp->description));
- }
+ /*
+ * Confirmation de la validation fermeture
+ */
+ if ($_GET["action"] == 'close' && $user->rights->contrat->activer)
+ {
+ print ' ';
+ $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("CloseService"),$langs->trans("ConfirmCloseService",strftime("%A %d %B %Y", $dateactstart)),"confirm_close");
+ }
- print ' | ';
- }
- else
- {
- print ' | '.stripslashes(nl2br($objp->description))." | \n";
- }
- print ''.$objp->tva_tx.'% | ';
- print ''.price($objp->subprice)." | \n";
+ /*
+ * Lignes de contrats
+ */
+ print '
';
- print '| '.$objp->qty.' | ';
+ $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";
- if ($objp->remise_percent > 0)
- {
- print ''.$objp->remise_percent."% | \n";
- }
- else
- {
- print ' | ';
- }
+ $result = $db->query($sql);
+ if ($result)
+ {
+ $num = $db->num_rows($result);
+ $i = 0; $total = 0;
- print ' | | ';
+ if ($num)
+ {
+ print '';
+ print '| '.$langs->trans("Service").' | ';
+ print ''.$langs->trans("VAT").' | ';
+ print ''.$langs->trans("PriceUHT").' | ';
+ print ''.$langs->trans("Qty").' | ';
+ print ''.$langs->trans("Discount").' | ';
+ print ' | ';
+ print ' | ';
+ print ''.$langs->trans("Status").' | ';
+ print " \n";
+ }
+ $var=true;
+ while ($i < $num)
+ {
+ $objp = $db->fetch_object($result);
- if ($objp->fk_product > 0) {
- print ' | ';
- } else {
- print ' | ';
- }
+ $var=!$var;
+ print "\n";
- print " \n";
+ // Libell
+ if ($objp->fk_product > 0)
+ {
+ print ''.img_object($langs->trans("ShowService"),"service").' '.$objp->label.'';
- if ($objp->date_debut) $dateactstart=$objp->date_debut;
- if ($objp->date_fin) $dateactend=$objp->date_fin;
-
- // Dates mise en service
- print ' | ';
- print '';
- // Si pas encore activé
- if (! $objp->date_debut_reelle) {
- print $langs->trans("DateStartPlanned").': ';
- if ($objp->date_debut) print dolibarr_print_date($objp->date_debut);
- else print $langs->trans("Unknown");
- }
- // Si activé
- if ($objp->date_debut_reelle) {
- print $langs->trans("DateStartReal").': ';
- if ($objp->date_debut_reelle) print dolibarr_print_date($objp->date_debut_reelle);
- else print $langs->trans("ContractStatusNotRunning");
+ if ($objp->description)
+ {
+ print ' '.stripslashes(nl2br($objp->description));
}
- 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 ' | ';
+ }
+ else
+ {
+ print ' | '.stripslashes(nl2br($objp->description))." | \n";
+ }
+ print ''.$objp->tva_tx.'% | ';
+
+ print ''.price($objp->subprice)." | \n";
+
+ print ''.$objp->qty.' | ';
+
+ if ($objp->remise_percent > 0)
+ {
+ print ''.$objp->remise_percent."% | \n";
+ }
+ else
+ {
print ' | ';
- print ' ';
-
+ }
- $i++;
- }
- $db->free($result);
- }
- else
- {
- dolibarr_print_error($db);
- }
-
- print ' ';
- print '';
+ print ' | | ';
- if ( $user->rights->contrat->activer && $contrat->statut == 0 && $objp->statut <> 4)
- {
- /**
- * Activer la ligne de contrat
- */
- $form = new Form($db);
-
- print '';
- }
- }
+ $i++;
+ }
+ $db->free($result);
+ }
+ else
+ {
+ dolibarr_print_error($db);
+ }
+
+ print ' ';
+ print '';
+
+ if ($user->rights->contrat->activer && $contrat->statut == 1 && $objp->statut <> 4)
+ {
+ /**
+ * Activer la ligne de contrat
+ */
+ $form = new Form($db);
+
+ print '';
+ }
+
+ if ($user->rights->contrat->activer && $contrat->statut == 1 && $objp->statut == 4)
+ {
+ /**
+ * Désactiver la ligne de contrat
+ */
+ $form = new Form($db);
+
+ print '
|