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 >
* Copyright ( C ) 2004 - 2007 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
* the Free Software Foundation ; either version 2 of the License , or
* ( 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
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*
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
*/
/**
\file htdocs / dev / generate - commande . php
2009-07-23 02:03:01 +02:00
\brief Script de generation de donnees aleatoires pour les commandes
\version $Id $
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 ;
}
// Recupere root dolibarr
2009-10-20 16:22:24 +02:00
$path = preg_replace ( '/generate-commande.php/i' , '' , $_SERVER [ " PHP_SELF " ]);
2010-05-09 22:25:53 +02:00
require ( $path . " ../../htdocs/master.inc.php " );
2010-04-29 16:54:12 +02:00
include_once ( DOL_DOCUMENT_ROOT . " /societe/class/societe.class.php " );
2010-04-28 09:55:43 +02:00
include_once ( DOL_DOCUMENT_ROOT . " /contact/class/contact.class.php " );
2010-04-25 16:17:39 +02:00
include_once ( DOL_DOCUMENT_ROOT . " /compta/facture/class/facture.class.php " );
2010-04-28 23:29:12 +02:00
include_once ( DOL_DOCUMENT_ROOT . " /product/class/product.class.php " );
2010-04-25 10:47:08 +02:00
include_once ( DOL_DOCUMENT_ROOT . " /compta/paiement/class/paiement.class.php " );
2010-04-28 10:35:57 +02:00
include_once ( DOL_DOCUMENT_ROOT . " /contrat/class/contrat.class.php " );
2005-08-13 23:45:08 +02:00
/*
* Parametre
*/
define ( GEN_NUMBER_COMMANDE , 10 );
2007-06-12 00:51:47 +02:00
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . " societe " ; $societesid = array ();
2007-08-26 14:10:50 +02:00
$resql = $db -> query ( $sql );
if ( $resql ) {
$num = $db -> num_rows ( $resql );
$i = 0 ;
2006-09-09 15:05:45 +02:00
while ( $i < $num ) {
2007-08-26 14:10:50 +02:00
$row = $db -> fetch_row ( $resql );
$societesid [ $i ] = $row [ 0 ];
$i ++ ;
2006-09-09 15:05:45 +02:00
}
}
else { print " err " ; }
2005-08-13 23:45:08 +02:00
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . " commande " ; $commandesid = array ();
2007-08-26 14:10:50 +02:00
$resql = $db -> query ( $sql );
if ( $resql ) {
$num = $db -> num_rows ( $resql );
$i = 0 ;
2006-09-09 15:05:45 +02:00
while ( $i < $num ) {
2007-08-26 14:10:50 +02:00
$row = $db -> fetch_row ( $resql );
$commandesid [ $i ] = $row [ 0 ];
$i ++ ;
2006-09-09 15:05:45 +02:00
}
}
else { print " err " ; }
$prodids = array ();
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . " product WHERE envente=1 " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$num_prods = $db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num_prods )
{
$i ++ ;
$row = $db -> fetch_row ( $resql );
$prodids [ $i ] = $row [ 0 ];
}
}
2005-08-13 23:45:08 +02:00
$dates = array ( mktime ( 12 , 0 , 0 , 1 , 3 , 2003 ),
mktime ( 12 , 0 , 0 , 1 , 9 , 2003 ),
mktime ( 12 , 0 , 0 , 2 , 13 , 2003 ),
mktime ( 12 , 0 , 0 , 2 , 23 , 2003 ),
mktime ( 12 , 0 , 0 , 3 , 30 , 2003 ),
mktime ( 12 , 0 , 0 , 4 , 3 , 2003 ),
mktime ( 12 , 0 , 0 , 4 , 3 , 2003 ),
mktime ( 12 , 0 , 0 , 5 , 9 , 2003 ),
mktime ( 12 , 0 , 0 , 5 , 1 , 2003 ),
mktime ( 12 , 0 , 0 , 5 , 13 , 2003 ),
mktime ( 12 , 0 , 0 , 5 , 19 , 2003 ),
mktime ( 12 , 0 , 0 , 5 , 23 , 2003 ),
mktime ( 12 , 0 , 0 , 6 , 3 , 2003 ),
mktime ( 12 , 0 , 0 , 6 , 19 , 2003 ),
mktime ( 12 , 0 , 0 , 6 , 24 , 2003 ),
mktime ( 12 , 0 , 0 , 7 , 3 , 2003 ),
mktime ( 12 , 0 , 0 , 7 , 9 , 2003 ),
mktime ( 12 , 0 , 0 , 7 , 23 , 2003 ),
mktime ( 12 , 0 , 0 , 7 , 30 , 2003 ),
mktime ( 12 , 0 , 0 , 8 , 9 , 2003 ),
mktime ( 12 , 0 , 0 , 9 , 23 , 2003 ),
mktime ( 12 , 0 , 0 , 10 , 3 , 2003 ),
mktime ( 12 , 0 , 0 , 11 , 12 , 2003 ),
mktime ( 12 , 0 , 0 , 11 , 13 , 2003 ),
mktime ( 12 , 0 , 0 , 1 , 3 , 2002 ),
mktime ( 12 , 0 , 0 , 1 , 9 , 2002 ),
mktime ( 12 , 0 , 0 , 2 , 13 , 2002 ),
mktime ( 12 , 0 , 0 , 2 , 23 , 2002 ),
mktime ( 12 , 0 , 0 , 3 , 30 , 2002 ),
mktime ( 12 , 0 , 0 , 4 , 3 , 2002 ),
mktime ( 12 , 0 , 0 , 4 , 3 , 2002 ),
mktime ( 12 , 0 , 0 , 5 , 9 , 2002 ),
mktime ( 12 , 0 , 0 , 5 , 1 , 2002 ),
mktime ( 12 , 0 , 0 , 5 , 13 , 2002 ),
mktime ( 12 , 0 , 0 , 5 , 19 , 2002 ),
mktime ( 12 , 0 , 0 , 5 , 23 , 2002 ),
mktime ( 12 , 0 , 0 , 6 , 3 , 2002 ),
mktime ( 12 , 0 , 0 , 6 , 19 , 2002 ),
mktime ( 12 , 0 , 0 , 6 , 24 , 2002 ),
mktime ( 12 , 0 , 0 , 7 , 3 , 2002 ),
mktime ( 12 , 0 , 0 , 7 , 9 , 2002 ),
mktime ( 12 , 0 , 0 , 7 , 23 , 2002 ),
mktime ( 12 , 0 , 0 , 7 , 30 , 2002 ),
mktime ( 12 , 0 , 0 , 8 , 9 , 2002 ),
mktime ( 12 , 0 , 0 , 9 , 23 , 2002 ),
mktime ( 12 , 0 , 0 , 10 , 3 , 2002 ),
mktime ( 12 , 0 , 0 , 11 , 12 , 2003 ),
mktime ( 12 , 0 , 0 , 11 , 13 , 2003 ),
mktime ( 12 , 0 , 0 , 12 , 12 , 2003 ),
mktime ( 12 , 0 , 0 , 12 , 13 , 2003 ),
);
2010-04-27 10:13:42 +02:00
require ( DOL_DOCUMENT_ROOT . " /commande/class/commande.class.php " );
2005-08-13 23:45:08 +02:00
2007-08-26 14:10:50 +02:00
print " Build " . GEN_NUMBER_COMMANDE . " orders \n " ;
2005-08-13 23:45:08 +02:00
for ( $s = 0 ; $s < GEN_NUMBER_COMMANDE ; $s ++ )
{
2007-08-26 14:10:50 +02:00
print " Order " . $s ;
2006-09-09 15:05:45 +02:00
2005-08-13 23:45:08 +02:00
$com = new Commande ( $db );
2006-09-13 20:56:30 +02:00
$com -> socid = 4 ;
2005-08-13 23:45:08 +02:00
$com -> date_commande = $dates [ rand ( 1 , sizeof ( $dates ) - 1 )];
$com -> note = $_POST [ " note " ];
$com -> source = 1 ;
2010-03-11 15:31:16 +01:00
$com -> fk_project = 0 ;
2005-08-13 23:45:08 +02:00
$com -> remise_percent = 0 ;
2006-09-09 15:05:45 +02:00
$nbp = rand ( 2 , 5 );
$xnbp = 0 ;
while ( $xnbp < $nbp )
{
// \TODO Utiliser addline plutot que add_product
$prodid = rand ( 1 , $num_prods );
2007-08-26 14:10:50 +02:00
$result = $com -> add_product ( $prodids [ $prodid ], rand ( 1 , 11 ), rand ( 1 , 6 ), rand ( 0 , 20 ));
if ( $result < 0 )
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db , $propal -> error );
2007-08-26 14:10:50 +02:00
}
$xnbp ++ ;
2006-09-09 15:05:45 +02:00
}
2007-08-26 14:10:50 +02:00
$result = $com -> create ( $user );
if ( $result >= 0 )
{
$result = $com -> valid ( $user );
if ( $result ) print " OK " ;
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db , $com -> error );
2007-08-26 14:10:50 +02:00
}
}
else
{
2009-09-10 23:46:10 +02:00
dol_print_error ( $db , $com -> error );
2007-08-26 14:10:50 +02:00
}
2006-09-09 15:05:45 +02:00
print " \n " ;
2005-08-13 23:45:08 +02:00
}
?>