Replace function rand with mt_rand (prepare php 8)

This commit is contained in:
Laurent Destailleur
2016-03-05 15:01:25 +01:00
parent d8045e33bb
commit d1777a6783
15 changed files with 36 additions and 36 deletions

View File

@@ -90,7 +90,7 @@ $result=0;
while ($i < GEN_NUMBER_FACTURE && $result >= 0)
{
$i++;
$socid = rand(1, $num_socs);
$socid = mt_rand(1, $num_socs);
print "Invoice ".$i." for socid ".$socid;
@@ -105,14 +105,14 @@ while ($i < GEN_NUMBER_FACTURE && $result >= 0)
$result=$facture->validate($user);
if ($result)
{
$nbp = rand(2, 5);
$nbp = mt_rand(2, 5);
$xnbp = 0;
while ($xnbp < $nbp)
{
$prodid = rand(1, $num_prods);
$prodid = mt_rand(1, $num_prods);
$product=new Product($db);
$result=$product->fetch($prodids[$prodid]);
$result=$facture->addline($product->description, $product->price, rand(1,5), 0, 0, 0, $prodids[$prodid], 0, '', '', 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
$result=$facture->addline($product->description, $product->price, mt_rand(1,5), 0, 0, 0, $prodids[$prodid], 0, '', '', 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
if ($result < 0)
{
dol_print_error($db,$propal->error);

View File

@@ -165,7 +165,7 @@ for ($s = 0 ; $s < GEN_NUMBER_COMMANDE ; $s++)
$com = new Commande($db);
$com->socid = 4;
$com->date_commande = $dates[rand(1, count($dates)-1)];
$com->date_commande = $dates[mt_rand(1, count($dates)-1)];
$com->note = 'A comment';
$com->source = 1;
$com->fk_project = 0;
@@ -179,14 +179,14 @@ for ($s = 0 ; $s < GEN_NUMBER_COMMANDE ; $s++)
$result=$com->valid($user);
if ($result > 0)
{
$nbp = rand(2, 5);
$nbp = mt_rand(2, 5);
$xnbp = 0;
while ($xnbp < $nbp)
{
$prodid = rand(1, $num_prods);
$prodid = mt_rand(1, $num_prods);
$product=new Product($db);
$result=$product->fetch($prodids[$prodid]);
$result=$com->addline($product->description, $product->price, rand(1,5), 0, 0, 0, $prodids[$prodid], 0, 0, 0, $product->price_base_type, $product->price_ttc, '', '', $product->type);
$result=$com->addline($product->description, $product->price, mt_rand(1,5), 0, 0, 0, $prodids[$prodid], 0, 0, 0, $product->price_base_type, $product->price_ttc, '', '', $product->type);
if ($result < 0)
{
dol_print_error($db,$propal->error);

View File

@@ -85,12 +85,12 @@ for ($s = 0 ; $s < GEN_NUMBER_PRODUIT ; $s++)
{
print "Product ".$s;
$produit = new Product($db);
$produit->type = rand(0,1);
$produit->type = mt_rand(0,1);
$produit->status = 1;
$produit->ref = ($produit->type?'S':'P').time().$s;
$produit->label = 'Label '.time().$s;
$produit->description = 'Description '.time().$s;
$produit->price = rand(1,1000);
$produit->price = mt_rand(1,1000);
$produit->tva_tx = "19.6";
$ret=$produit->create($user);
if ($ret < 0) print "Error $ret - ".$produit->error."\n";

View File

@@ -117,7 +117,7 @@ $result=0;
while ($i < GEN_NUMBER_PROPAL && $result >= 0)
{
$i++;
$socid = rand(1, $num_socs);
$socid = mt_rand(1, $num_socs);
print "Proposal ".$i." for socid ".$socid;
$soc = new Societe($db);
@@ -140,14 +140,14 @@ while ($i < GEN_NUMBER_PROPAL && $result >= 0)
$result=$propal->create($user);
if ($result >= 0)
{
$nbp = rand(2, 5);
$nbp = mt_rand(2, 5);
$xnbp = 0;
while ($xnbp < $nbp)
{
$prodid = rand(1, $num_prods);
$prodid = mt_rand(1, $num_prods);
$product=new Product($db);
$result=$product->fetch($prodids[$prodid]);
$result=$propal->addline($product->description, $product->price, rand(1,5), 0, 0, 0, $prodids[$prodid], 0);
$result=$propal->addline($product->description, $product->price, mt_rand(1,5), 0, 0, 0, $prodids[$prodid], 0);
if ($result < 0)
{
dol_print_error($db,$propal->error);

View File

@@ -90,30 +90,30 @@ for ($s = 0 ; $s < GEN_NUMBER_SOCIETE ; $s++)
print "Company $s\n";
$soc = new Societe($db);
$soc->name = "Company num ".time()."$s";
$soc->town = $listoftown[rand(0, count($listoftown)-1)];
$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->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
$soc->code_client='CU'.time()."$s";
$soc->code_fournisseur='SU'.time()."$s";
$soc->tva_assuj=1;
$soc->country_id=1;
$soc->country_code='FR';
// Un client sur 3 a une remise de 5%
$user_remise=rand(1,3); if ($user_remise==3) $soc->remise_percent=5;
$user_remise=mt_rand(1,3); if ($user_remise==3) $soc->remise_percent=5;
print "> client=".$soc->client.", fournisseur=".$soc->fournisseur.", remise=".$soc->remise_percent."\n";
$soc->note_private = 'Company created by the script generate-societe.php';
$socid = $soc->create();
if ($socid >= 0)
{
$rand = rand(1,4);
$rand = mt_rand(1,4);
print "> Generates $rand contact(s)\n";
for ($c = 0 ; $c < $rand ; $c++)
{
$contact = new Contact($db);
$contact->socid = $soc->id;
$contact->lastname = "Lastname".$c;
$contact->firstname = $listoflastname[rand(0, count($listoflastname)-1)];
$contact->firstname = $listoflastname[mt_rand(0, count($listoflastname)-1)];
if ( $contact->create($user) )
{