generate-societe.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/usr/bin/php
  2. <?php
  3. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  4. * Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * ATTENTION DE PAS EXECUTER CE SCRIPT SUR UNE INSTALLATION DE PRODUCTION
  20. */
  21. /**
  22. * \file htdocs/dev/generate-societe.php
  23. * \brief Script de generation de donnees aleatoires pour les societes
  24. */
  25. // Test si mode batch
  26. $sapi_type = php_sapi_name();
  27. if (substr($sapi_type, 0, 3) == 'cgi') {
  28. echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer mailing-send.php en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n";
  29. exit;
  30. }
  31. // Recupere root dolibarr
  32. $path=preg_replace('/generate-societe.php/i','',$_SERVER["PHP_SELF"]);
  33. require ($path."../../htdocs/master.inc.php");
  34. include_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
  35. include_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php");
  36. include_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
  37. include_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
  38. include_once(DOL_DOCUMENT_ROOT."/compta/paiement/class/paiement.class.php");
  39. include_once(DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php");
  40. $villes = array("Auray","Baden","Vannes","Pirouville","Haguenau","Souffelweiersheim","Illkirch-Graffenstaden","Lauterbourg","Picauville","Sainte-Mère Eglise","Le Bono");
  41. $prenoms = array("Joe","Marc","Steve","Laurent","Nico","Isabelle","Dorothee","Saby","Brigitte","Karine","Jose-Anne","Celine","Virginie");
  42. /*
  43. * Parametre
  44. */
  45. define (GEN_NUMBER_SOCIETE, 10);
  46. $ret=$user->fetch('','admin');
  47. if (! $ret > 0)
  48. {
  49. print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
  50. exit;
  51. }
  52. $user->getrights();
  53. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product"; $productsid = array();
  54. $resql=$db->query($sql);
  55. if ($resql) {
  56. $num = $db->num_rows($resql); $i = 0;
  57. while ($i < $num) { $row = $db->fetch_row($resql); $productsid[$i] = $row[0]; $i++; }
  58. }
  59. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; $societesid = array();
  60. $resql=$db->query($sql);
  61. if ($resql) {
  62. $num = $db->num_rows($resql); $i = 0;
  63. while ($i < $num) { $row = $db->fetch_row($resql); $societesid[$i] = $row[0]; $i++; }
  64. } else { print "err"; }
  65. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande"; $commandesid = array();
  66. $resql=$db->query($sql);
  67. if ($resql) {
  68. $num = $db->num_rows($resql); $i = 0;
  69. while ($i < $num) { $row = $db->fetch_row($resql); $commandesid[$i] = $row[0]; $i++; }
  70. } else { print "err"; }
  71. print "Generates ".GEN_NUMBER_SOCIETE." companies\n";
  72. for ($s = 0 ; $s < GEN_NUMBER_SOCIETE ; $s++)
  73. {
  74. print "Company $s\n";
  75. $soc = new Societe($db);
  76. $soc->nom = "Company num ".time()."$s";
  77. $soc->ville = $villes[rand(0,sizeof($villes)-1)];
  78. $soc->client = rand(1,2); // Une societe sur 2 est prospect, l'autre client
  79. $soc->fournisseur = rand(0,1); // Une societe sur 2 est fournisseur
  80. $soc->code_client='CU'.time()."$s";
  81. $soc->code_fournisseur='SU'.time()."$s";
  82. $soc->tva_assuj=1;
  83. $soc->pays_id=1;
  84. $soc->pays_code='FR';
  85. // Un client sur 3 a une remise de 5%
  86. $user_remise=rand(1,3); if ($user_remise==3) $soc->remise_client=5;
  87. print "> client=".$soc->client.", fournisseur=".$soc->fournisseur.", remise=".$soc->remise_client."\n";
  88. $soc->note='Company created by the script generate-societe.php';
  89. $socid = $soc->create();
  90. if ($socid >= 0)
  91. {
  92. $rand = rand(1,4);
  93. print "> Generates $rand contact(s)\n";
  94. for ($c = 0 ; $c < $rand ; $c++)
  95. {
  96. $contact = new Contact($db);
  97. $contact->socid = $soc->id;
  98. $contact->name = "Lastname".$c;
  99. $contact->firstname = $prenoms[rand(0,sizeof($prenoms)-1)];
  100. if ( $contact->create($user) )
  101. {
  102. }
  103. }
  104. print "Company ".$s." created nom=".$soc->nom."\n";
  105. }
  106. else
  107. {
  108. print "Error: ".$soc->error."\n";
  109. }
  110. }
  111. ?>