generate-facture.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/usr/bin/php
  2. <?php
  3. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * ATTENTION DE PAS EXECUTER CE SCRIPT SUR UNE INSTALLATION DE PRODUCTION
  19. */
  20. /**
  21. * \file htdocs/dev/generate-facture.php
  22. * \brief Script de generation de donnees aleatoires pour les factures
  23. */
  24. // Test si mode batch
  25. $sapi_type = php_sapi_name();
  26. if (substr($sapi_type, 0, 3) == 'cgi') {
  27. 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";
  28. exit;
  29. }
  30. // Recupere root dolibarr
  31. $path=preg_replace('/generate-facture.php/i','',$_SERVER["PHP_SELF"]);
  32. require ($path."../../htdocs/master.inc.php");
  33. require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
  34. require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
  35. /*
  36. * Parameters
  37. */
  38. define (GEN_NUMBER_FACTURE, 5);
  39. $ret=$user->fetch('','admin');
  40. if (! $ret > 0)
  41. {
  42. print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
  43. exit;
  44. }
  45. $user->getrights();
  46. $socids = array();
  47. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client=1";
  48. $resql = $db->query($sql);
  49. if ($resql)
  50. {
  51. $num_socs = $db->num_rows($resql);
  52. $i = 0;
  53. while ($i < $num_socs)
  54. {
  55. $i++;
  56. $row = $db->fetch_row($resql);
  57. $socids[$i] = $row[0];
  58. }
  59. }
  60. $prodids = array();
  61. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product WHERE tosell=1";
  62. $resql = $db->query($sql);
  63. if ($resql)
  64. {
  65. $num_prods = $db->num_rows($resql);
  66. $i = 0;
  67. while ($i < $num_prods)
  68. {
  69. $i++;
  70. $row = $db->fetch_row($resql);
  71. $prodids[$i] = $row[0];
  72. }
  73. }
  74. $i=0;
  75. $result=0;
  76. while ($i < GEN_NUMBER_FACTURE && $result >= 0)
  77. {
  78. $i++;
  79. $socid = rand(1, $num_socs);
  80. print "Invoice ".$i." for socid ".$socid;
  81. $facture = new Facture($db, $socids[$socid]);
  82. $facture->date = time();
  83. $facture->cond_reglement_id = 3;
  84. $facture->mode_reglement_id = 3;
  85. $result=$facture->create($user);
  86. if ($result >= 0)
  87. {
  88. $result=$facture->validate($user);
  89. if ($result)
  90. {
  91. $nbp = rand(2, 5);
  92. $xnbp = 0;
  93. while ($xnbp < $nbp)
  94. {
  95. $prodid = rand(1, $num_prods);
  96. $product=new Product($db);
  97. $result=$product->fetch($prodids[$prodid]);
  98. $result=$facture->addline($facture->id,$product->description,$product->price, rand(1,5), 0, 0, 0, $prodids[$prodid], 0, '', '', 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
  99. $xnbp++;
  100. }
  101. print " OK with ref ".$facture->ref."\n";;
  102. }
  103. else
  104. {
  105. dol_print_error($db,$facture->error);
  106. }
  107. }
  108. else
  109. {
  110. dol_print_error($db,$facture->error);
  111. }
  112. }
  113. ?>