From cafd5064aba0368046f2a4564e3cd58a8303eadb Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Thu, 25 May 2006 19:27:53 +0000
Subject: [PATCH] =?UTF-8?q?Am=E9lioration=20du=20script=20de=20g=E9n=E9rat?=
 =?UTF-8?q?ion=20de=20soci=E9t=E9s=20pour=20g=E9n=E9rer=20des=20clients=20?=
 =?UTF-8?q?mais=20aussi=20des=20prospects?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 dev/generate-societe.php | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/dev/generate-societe.php b/dev/generate-societe.php
index f38f2e95cd1..a26a4400627 100644
--- a/dev/generate-societe.php
+++ b/dev/generate-societe.php
@@ -26,6 +26,11 @@
 		\version    $Revision$
 */
 
+if (! file_exists("../htdocs/master.inc.php"))
+{
+	print "Error: This script must be run from its directory.\n"; 
+	exit -1;	
+}
 require ("../htdocs/master.inc.php");
 include_once(DOL_DOCUMENT_ROOT."/societe.class.php");
 include_once(DOL_DOCUMENT_ROOT."/contact.class.php");
@@ -65,17 +70,21 @@ for ($s = 0 ; $s < GEN_NUMBER_SOCIETE ; $s++)
     $soc->nom = "Soci�t� al�atoire num ".time()."$s";
     $villes = array("Auray","Baden","Vannes","Pirouville","Haguenau","Souffelweiersheim","Illkirch-Graffenstaden","Lauterbourg","Picauville","Sainte-M�re Eglise","Le Bono");
     $soc->ville = $villes[rand(0,sizeof($villes)-1)];
-    $soc->client = 1;
+	// Une societe sur 2 est prospect, l'autre client
+    $soc->client = rand(1,2);
+    // Un client sur 10 a une remise de 5%
+    $user_remise=rand(1,10); if ($user_remise==10) $soc->remise_client=5;
+	print "(client=".$soc->client.", remise=".$soc->remise_client.")\n";
     $socid = $soc->create();
 
-    if ($socid)
+    if ($socid >= 0)
     {
         $rand = rand(1,4);
-        print "-- g�n�re $rand contact<br>";
+        print "-- G�n�re $rand contact\n";
         for ($c = 0 ; $c < $rand ; $c++)
         {
             $contact = new Contact($db);
-            $contact->socid = $socid;
+            $contact->socid = $soc->id;
             $contact->nom = "Nom al�a ".time()."-$c";
             if ( $contact->create($user) )
             {
@@ -83,6 +92,10 @@ for ($s = 0 ; $s < GEN_NUMBER_SOCIETE ; $s++)
             }
         }
     }
+    else
+    {
+    	print "Error: ".$soc->error."\n";
+    }
 }
 
 
-- 
GitLab