2015-12-11 05:08:32 +01:00
#!/usr/bin/env php
2005-08-13 23:45:08 +02:00
< ? php
2007-08-26 14:10:50 +02:00
/* Copyright ( C ) 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2013-03-09 16:19:15 +01:00
* Copyright ( C ) 2006 - 2013 Laurent Destailleur < eldy @ users . sourceforge . net >
2005-08-13 23:45:08 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2005-08-13 23:45:08 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2011-08-01 00:21:57 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2005-08-13 23:45:08 +02:00
*
2007-08-26 14:10:50 +02:00
* ATTENTION DE PAS EXECUTER CE SCRIPT SUR UNE INSTALLATION DE PRODUCTION
2005-08-13 23:45:08 +02:00
*/
/**
2015-11-09 16:48:30 +01:00
* \file dev / initdata / generate - thirdparty . php
* \brief Script example to inject random thirdparties ( for load tests )
2010-01-20 19:36:42 +01:00
*/
2005-08-13 23:45:08 +02:00
2007-08-26 14:10:50 +02:00
// Test si mode batch
$sapi_type = php_sapi_name ();
if ( substr ( $sapi_type , 0 , 3 ) == 'cgi' ) {
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 " ;
exit ;
2006-05-25 21:27:53 +02:00
}
2007-08-26 14:10:50 +02:00
// Recupere root dolibarr
2016-07-15 19:44:45 +02:00
//$path=preg_replace('/generate-societe.php/i','',$_SERVER["PHP_SELF"]);
require ( __DIR__ . '/../../htdocs/master.inc.php' );
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
include_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
include_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
include_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php' ;
include_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php' ;
2005-08-13 23:45:08 +02:00
2013-03-09 16:19:15 +01:00
$listoftown = array ( " Auray " , " Baden " , " Vannes " , " Pirouville " , " Haguenau " , " Souffelweiersheim " , " Illkirch-Graffenstaden " , " Lauterbourg " , " Picauville " , " Sainte-Mère Eglise " , " Le Bono " );
$listoflastname = array ( " Joe " , " Marc " , " Steve " , " Laurent " , " Nico " , " Isabelle " , " Dorothee " , " Saby " , " Brigitte " , " Karine " , " Jose-Anne " , " Celine " , " Virginie " );
2005-08-13 23:45:08 +02:00
2010-01-20 19:36:42 +01:00
2005-08-13 23:45:08 +02:00
/*
* Parametre
*/
2012-02-15 13:58:37 +01:00
define ( GEN_NUMBER_SOCIETE , 10 );
2005-08-13 23:45:08 +02:00
2010-07-10 01:13:44 +02:00
$ret = $user -> fetch ( '' , 'admin' );
if ( ! $ret > 0 )
{
print 'A user with login "admin" and all permissions must be created to use this script.' . " \n " ;
exit ;
}
$user -> getrights ();
2005-08-13 23:45:08 +02:00
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . " product " ; $productsid = array ();
2010-08-14 04:44:07 +02:00
$resql = $db -> query ( $sql );
if ( $resql ) {
$num = $db -> num_rows ( $resql ); $i = 0 ;
while ( $i < $num ) { $row = $db -> fetch_row ( $resql ); $productsid [ $i ] = $row [ 0 ]; $i ++ ; }
}
2005-08-13 23:45:08 +02:00
2007-06-12 00:51:47 +02:00
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . " societe " ; $societesid = array ();
2010-08-14 04:44:07 +02:00
$resql = $db -> query ( $sql );
if ( $resql ) {
$num = $db -> num_rows ( $resql ); $i = 0 ;
while ( $i < $num ) { $row = $db -> fetch_row ( $resql ); $societesid [ $i ] = $row [ 0 ]; $i ++ ; }
} else { print " err " ; }
2005-08-13 23:45:08 +02:00
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . " commande " ; $commandesid = array ();
2010-08-14 04:44:07 +02:00
$resql = $db -> query ( $sql );
if ( $resql ) {
$num = $db -> num_rows ( $resql ); $i = 0 ;
while ( $i < $num ) { $row = $db -> fetch_row ( $resql ); $commandesid [ $i ] = $row [ 0 ]; $i ++ ; }
} else { print " err " ; }
2005-08-13 23:45:08 +02:00
2009-08-04 09:25:41 +02:00
print " Generates " . GEN_NUMBER_SOCIETE . " companies \n " ;
2005-08-13 23:45:08 +02:00
for ( $s = 0 ; $s < GEN_NUMBER_SOCIETE ; $s ++ )
{
2009-08-04 09:25:41 +02:00
print " Company $s\n " ;
2005-08-13 23:45:08 +02:00
$soc = new Societe ( $db );
2015-04-01 10:10:39 +02:00
$soc -> name = " Company num " . time () . " $s " ;
2016-03-05 15:01:25 +01:00
$soc -> town = $listoftown [ mt_rand ( 0 , count ( $listoftown ) - 1 )];
$soc -> client = mt_rand ( 1 , 2 ); // Une societe sur 2 est prospect, l'autre client
$soc -> fournisseur = mt_rand ( 0 , 1 ); // Une societe sur 2 est fournisseur
2010-07-10 01:13:44 +02:00
$soc -> code_client = 'CU' . time () . " $s " ;
$soc -> code_fournisseur = 'SU' . time () . " $s " ;
2006-06-06 01:06:34 +02:00
$soc -> tva_assuj = 1 ;
2011-12-29 18:07:41 +01:00
$soc -> country_id = 1 ;
$soc -> country_code = 'FR' ;
2010-07-10 01:13:44 +02:00
// Un client sur 3 a une remise de 5%
2016-03-05 15:01:25 +01:00
$user_remise = mt_rand ( 1 , 3 ); if ( $user_remise == 3 ) $soc -> remise_percent = 5 ;
2013-06-16 21:31:21 +02:00
print " > client= " . $soc -> client . " , fournisseur= " . $soc -> fournisseur . " , remise= " . $soc -> remise_percent . " \n " ;
2015-04-01 10:10:39 +02:00
$soc -> note_private = 'Company created by the script generate-societe.php' ;
2005-08-13 23:45:08 +02:00
$socid = $soc -> create ();
2006-05-25 21:27:53 +02:00
if ( $socid >= 0 )
2005-08-13 23:45:08 +02:00
{
2016-03-05 15:01:25 +01:00
$rand = mt_rand ( 1 , 4 );
2010-07-10 01:13:44 +02:00
print " > Generates $rand contact(s) \n " ;
2005-08-13 23:45:08 +02:00
for ( $c = 0 ; $c < $rand ; $c ++ )
{
$contact = new Contact ( $db );
2006-05-25 21:27:53 +02:00
$contact -> socid = $soc -> id ;
2013-03-09 16:19:15 +01:00
$contact -> lastname = " Lastname " . $c ;
2016-03-05 15:01:25 +01:00
$contact -> firstname = $listoflastname [ mt_rand ( 0 , count ( $listoflastname ) - 1 )];
2005-08-13 23:45:08 +02:00
if ( $contact -> create ( $user ) )
{
}
}
2010-07-10 01:13:44 +02:00
2015-04-01 10:10:39 +02:00
print " Company " . $s . " created nom= " . $soc -> name . " \n " ;
2005-08-13 23:45:08 +02:00
}
2006-05-25 21:27:53 +02:00
else
{
print " Error: " . $soc -> error . " \n " ;
}
2005-08-13 23:45:08 +02:00
}