From 5657bd7793ffbfb43c22b1fdc3b6435e880d9045 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Tue, 28 Jan 2014 15:26:20 +0100
Subject: [PATCH] New: Can create contract from an order.

---
 ChangeLog                 |  1 +
 htdocs/comm/propal.php    |  6 +++---
 htdocs/commande/fiche.php | 11 +++++++++++
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5d09b5daf8b..5e64a55d663 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@ English Dolibarr ChangeLog
 
 ***** ChangeLog for 3.6 compared to 3.5.* *****
 For users:
+- New: Can create contract from an order.
 - New: Add list of orders products in tab "consumption" on thirdparties.
 - New: Add graph stats for suppliers orders in tab "stats" on products.
 - New: Add option MAIN_HIDE_INACTIVETAB_ON_PRINT to hide inactive tabs when you
diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index 41dba04b395..e61750f7bfd 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -2168,7 +2168,7 @@ else
 				}
 	
 				// Create an order
-				if (! empty($conf->commande->enabled) && $object->statut == 2 && $user->societe_id == 0)
+				if (! empty($conf->commande->enabled) && $object->statut == 2)
 				{
 					if ($user->rights->commande->creer)
 					{
@@ -2177,7 +2177,7 @@ else
 				}
 	
 				// Create contract
-				if ($conf->contrat->enabled && $object->statut == 2 && $user->societe_id == 0)
+				if ($conf->contrat->enabled && $object->statut == 2)
 				{
 					$langs->load("contracts");
 	
@@ -2188,7 +2188,7 @@ else
 				}
 	
 				// Create an invoice and classify billed
-				if ($object->statut == 2 && $user->societe_id == 0)
+				if ($object->statut == 2)
 				{
 					if (! empty($conf->facture->enabled) && $user->rights->facture->creer)
 					{
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index a0653214355..90036a05de6 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -2477,6 +2477,17 @@ else
 					print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans('ReOpen').'</a></div>';
 				}
 
+				// Create contract
+				if ($conf->contrat->enabled && ($object->statut == 1 || $object->statut == 2))
+				{
+					$langs->load("contracts");
+	
+					if ($user->rights->contrat->creer)
+					{
+						print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/contrat/fiche.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans('AddContract').'</a></div>';
+					}
+				}
+	
 				// Create bill and Classify billed
 				// Note: Even if module invoice is not enabled, we should be able to use button "Classified billed" 
 				if ($object->statut > 0  && ! $object->billed)
-- 
GitLab