Fix: Works on new version

This commit is contained in:
Laurent Destailleur 2010-07-09 23:13:44 +00:00
parent a70595d969
commit 6031ffcdda
4 changed files with 50 additions and 32 deletions

View File

@ -45,14 +45,14 @@ require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
define (GEN_NUMBER_FACTURE, 5); define (GEN_NUMBER_FACTURE, 5);
$sql = "SELECT min(rowid) FROM ".MAIN_DB_PREFIX."user"; $ret=$user->fetch('','admin');
$resql = $db->query($sql); if (! $ret > 0)
if ($resql)
{ {
$row = $db->fetch_row($resql); print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
$user = new User($db); exit;
$user->fetch($row[0]);
} }
$user->getrights();
$socids = array(); $socids = array();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client=1"; $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client=1";
@ -112,12 +112,12 @@ while ($i < GEN_NUMBER_FACTURE && $result >= 0)
{ {
$prodid = rand(1, $num_prods); $prodid = rand(1, $num_prods);
$product=new Product($db); $product=new Product($db);
$product->fetch($prodids[$prodid]); $result=$product->fetch($prodids[$prodid]);
$result=$facture->addline($facid,$product->description,$product->price, rand(1,5), 0, 0, $product->localtax2_tx, $prodids[$prodid], 0, '', '', 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type); $result=$facture->addline($facture->id,$product->description,$product->price, rand(1,5), 0, 0, $product->localtax2_tx, $prodids[$prodid], 0, '', '', 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
$xnbp++; $xnbp++;
} }
print " OK"; print " OK with ref ".$facture->ref."\n";;
} }
else else
{ {
@ -129,7 +129,6 @@ while ($i < GEN_NUMBER_FACTURE && $result >= 0)
dol_print_error($db,$facture->error); dol_print_error($db,$facture->error);
} }
print "\n";
} }

View File

@ -47,7 +47,16 @@ include_once(DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php");
* Parameters * Parameters
*/ */
define (GEN_NUMBER_PRODUIT, 5); define (GEN_NUMBER_PRODUIT, 100000);
$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();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product"; $productsid = array(); $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product"; $productsid = array();
@ -71,15 +80,14 @@ for ($s = 0 ; $s < GEN_NUMBER_PRODUIT ; $s++)
$produit = new Product($db); $produit = new Product($db);
$produit->type = rand(0,1); $produit->type = rand(0,1);
$produit->status = 1; $produit->status = 1;
$produit->ref = 'P'.time().$s; $produit->ref = ($produit->type?'S':'P').time().$s;
$produit->libelle = 'Label '.time().$s; $produit->libelle = 'Label '.time().$s;
$produit->description = 'Description '.time().$s; $produit->description = 'Description '.time().$s;
$produit->price = rand(1,1000); $produit->price = rand(1,1000);
$produit->tva_tx = "19.6"; $produit->tva_tx = "19.6";
$ret=$produit->create($user); $ret=$produit->create($user);
if ($ret < 0) print "Error $ret - ".$produit->error; if ($ret < 0) print "Error $ret - ".$produit->error."\n";
else print " OK"; else print " OK with ref ".$produit->ref."\n";
print "\n";
} }

View File

@ -47,14 +47,14 @@ require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
define (GEN_NUMBER_PROPAL, 5); define (GEN_NUMBER_PROPAL, 5);
$sql = "SELECT min(rowid) FROM ".MAIN_DB_PREFIX."user"; $ret=$user->fetch('','admin');
$resql = $db->query($sql); if (! $ret > 0)
if ($resql)
{ {
$row = $db->fetch_row($resql); print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
$user = new User($db); exit;
$user->fetch($row[0]);
} }
$user->getrights();
$socids = array(); $socids = array();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client=1"; $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client=1";
@ -123,11 +123,11 @@ while ($i < GEN_NUMBER_PROPAL && $result >= 0)
$soc = new Societe($db); $soc = new Societe($db);
$propal = new Propal($db, $socids[$socid]);
$obj = $conf->global->PROPALE_ADDON; $obj = $conf->global->PROPALE_ADDON;
$modPropale = new $obj; $modPropale = new $obj;
$numpr = $modPropale->getNextValue($soc); $numpr = $modPropale->getNextValue($soc,$propal);
$propal = new Propal($db, $socids[$socid]);
$propal->ref = $numpr; $propal->ref = $numpr;
$propal->contactid = $contids[$socids[$socid]][0]; $propal->contactid = $contids[$socids[$socid]][0];
@ -151,15 +151,13 @@ while ($i < GEN_NUMBER_PROPAL && $result >= 0)
} }
$xnbp++; $xnbp++;
} }
print " OK"; print " OK with ref ".$propal->ref."\n";
} }
else else
{ {
dol_print_error($db,$propal->error); dol_print_error($db,$propal->error);
} }
print "\n";
} }
?> ?>

View File

@ -53,6 +53,15 @@ $prenoms = array("Joe","Marc","Steve","Laurent","Nico","Isabelle","Dorothee","Sa
define (GEN_NUMBER_SOCIETE, 10); define (GEN_NUMBER_SOCIETE, 10);
$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();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product"; $productsid = array(); $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product"; $productsid = array();
if ($db->query($sql)) { if ($db->query($sql)) {
$num = $db->num_rows(); $i = 0; $num = $db->num_rows(); $i = 0;
@ -77,30 +86,34 @@ for ($s = 0 ; $s < GEN_NUMBER_SOCIETE ; $s++)
$soc->ville = $villes[rand(0,sizeof($villes)-1)]; $soc->ville = $villes[rand(0,sizeof($villes)-1)];
$soc->client = rand(1,2); // Une societe sur 2 est prospect, l'autre client $soc->client = rand(1,2); // Une societe sur 2 est prospect, l'autre client
$soc->fournisseur = rand(0,1); // Une societe sur 2 est fournisseur $soc->fournisseur = rand(0,1); // Une societe sur 2 est fournisseur
$soc->code_client='CU'.time()."$s";
$soc->code_fournisseur='SU'.time()."$s";
$soc->tva_assuj=1; $soc->tva_assuj=1;
$soc->pays_id=1; $soc->pays_id=1;
$soc->pays_code='FR'; $soc->pays_code='FR';
// Un client sur 10 a une remise de 5% // Un client sur 3 a une remise de 5%
$user_remise=rand(1,10); if ($user_remise==10) $soc->remise_client=5; $user_remise=rand(1,3); if ($user_remise==3) $soc->remise_client=5;
print "> client=".$soc->client.", fournisseur=".$soc->fournisseur.", remise=".$soc->remise_client."\n"; print "> client=".$soc->client.", fournisseur=".$soc->fournisseur.", remise=".$soc->remise_client."\n";
$soc->note='Fictional company created by the script generate-societe.php'; $soc->note='Company created by the script generate-societe.php';
$socid = $soc->create(); $socid = $soc->create();
if ($socid >= 0) if ($socid >= 0)
{ {
$rand = rand(1,4); $rand = rand(1,4);
print "> Generates $rand contact\n"; print "> Generates $rand contact(s)\n";
for ($c = 0 ; $c < $rand ; $c++) for ($c = 0 ; $c < $rand ; $c++)
{ {
$contact = new Contact($db); $contact = new Contact($db);
$contact->socid = $soc->id; $contact->socid = $soc->id;
$contact->name = "NomFamille".$c; $contact->name = "Lastname".$c;
$contact->firstname = $prenoms[rand(0,sizeof($prenoms)-1)]; $contact->firstname = $prenoms[rand(0,sizeof($prenoms)-1)];
if ( $contact->create($user) ) if ( $contact->create($user) )
{ {
} }
} }
print "Company ".$s." created nom=".$soc->nom."\n";
} }
else else
{ {