generate-produit.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/bin/php
  2. <?php
  3. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  4. * Copyright (C) 2004-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-produit.php
  23. * \brief Script de generation de donnees aleatoires pour les produits
  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-produit.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. /*
  41. * Parameters
  42. */
  43. define (GEN_NUMBER_PRODUIT, 100000);
  44. $ret=$user->fetch('','admin');
  45. if (! $ret > 0)
  46. {
  47. print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
  48. exit;
  49. }
  50. $user->getrights();
  51. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product"; $productsid = array();
  52. $resql=$db->query($sql);
  53. if ($resql) {
  54. $num = $db->num_rows($resql); $i = 0;
  55. while ($i < $num) { $row = $db->fetch_row($resql); $productsid[$i] = $row[0]; $i++; }
  56. }
  57. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; $societesid = array();
  58. $resql=$db->query($sql);
  59. if ($resql) {
  60. $num = $db->num_rows($resql); $i = 0;
  61. while ($i < $num) { $row = $db->fetch_row($resql); $societesid[$i] = $row[0]; $i++; }
  62. } else { print "err"; }
  63. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande"; $commandesid = array();
  64. $resql=$db->query($sql);
  65. if ($resql) {
  66. $num = $db->num_rows($resql); $i = 0;
  67. while ($i < $num) { $row = $db->fetch_row($resql); $commandesid[$i] = $row[0]; $i++; }
  68. } else { print "err"; }
  69. print "Generates ".GEN_NUMBER_PRODUIT." products\n";
  70. for ($s = 0 ; $s < GEN_NUMBER_PRODUIT ; $s++)
  71. {
  72. print "Product ".$s;
  73. $produit = new Product($db);
  74. $produit->type = rand(0,1);
  75. $produit->status = 1;
  76. $produit->ref = ($produit->type?'S':'P').time().$s;
  77. $produit->libelle = 'Label '.time().$s;
  78. $produit->description = 'Description '.time().$s;
  79. $produit->price = rand(1,1000);
  80. $produit->tva_tx = "19.6";
  81. $ret=$produit->create($user);
  82. if ($ret < 0) print "Error $ret - ".$produit->error."\n";
  83. else print " OK with ref ".$produit->ref."\n";
  84. }
  85. ?>