diff --git a/dev/initdata/generate-facture.php b/dev/initdata/generate-facture.php index 42f1bb98491..271518fda8a 100644 --- a/dev/initdata/generate-facture.php +++ b/dev/initdata/generate-facture.php @@ -45,14 +45,14 @@ require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php"); define (GEN_NUMBER_FACTURE, 5); -$sql = "SELECT min(rowid) FROM ".MAIN_DB_PREFIX."user"; -$resql = $db->query($sql); -if ($resql) +$ret=$user->fetch('','admin'); +if (! $ret > 0) { - $row = $db->fetch_row($resql); - $user = new User($db); - $user->fetch($row[0]); + print 'A user with login "admin" and all permissions must be created to use this script.'."\n"; + exit; } +$user->getrights(); + $socids = array(); $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); $product=new Product($db); - $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=$product->fetch($prodids[$prodid]); + $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++; } - print " OK"; + print " OK with ref ".$facture->ref."\n";; } else { @@ -129,7 +129,6 @@ while ($i < GEN_NUMBER_FACTURE && $result >= 0) dol_print_error($db,$facture->error); } - print "\n"; } diff --git a/dev/initdata/generate-produit.php b/dev/initdata/generate-produit.php index e977bbf3654..776e528020c 100644 --- a/dev/initdata/generate-produit.php +++ b/dev/initdata/generate-produit.php @@ -47,7 +47,16 @@ include_once(DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php"); * 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(); @@ -71,15 +80,14 @@ for ($s = 0 ; $s < GEN_NUMBER_PRODUIT ; $s++) $produit = new Product($db); $produit->type = rand(0,1); $produit->status = 1; - $produit->ref = 'P'.time().$s; + $produit->ref = ($produit->type?'S':'P').time().$s; $produit->libelle = 'Label '.time().$s; $produit->description = 'Description '.time().$s; $produit->price = rand(1,1000); $produit->tva_tx = "19.6"; $ret=$produit->create($user); - if ($ret < 0) print "Error $ret - ".$produit->error; - else print " OK"; - print "\n"; + if ($ret < 0) print "Error $ret - ".$produit->error."\n"; + else print " OK with ref ".$produit->ref."\n"; } diff --git a/dev/initdata/generate-propale.php b/dev/initdata/generate-propale.php index 2852ae87d2e..1923f9dda33 100644 --- a/dev/initdata/generate-propale.php +++ b/dev/initdata/generate-propale.php @@ -47,14 +47,14 @@ require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php"); define (GEN_NUMBER_PROPAL, 5); -$sql = "SELECT min(rowid) FROM ".MAIN_DB_PREFIX."user"; -$resql = $db->query($sql); -if ($resql) +$ret=$user->fetch('','admin'); +if (! $ret > 0) { - $row = $db->fetch_row($resql); - $user = new User($db); - $user->fetch($row[0]); + print 'A user with login "admin" and all permissions must be created to use this script.'."\n"; + exit; } +$user->getrights(); + $socids = array(); $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); + $propal = new Propal($db, $socids[$socid]); + $obj = $conf->global->PROPALE_ADDON; $modPropale = new $obj; - $numpr = $modPropale->getNextValue($soc); - - $propal = new Propal($db, $socids[$socid]); + $numpr = $modPropale->getNextValue($soc,$propal); $propal->ref = $numpr; $propal->contactid = $contids[$socids[$socid]][0]; @@ -151,15 +151,13 @@ while ($i < GEN_NUMBER_PROPAL && $result >= 0) } $xnbp++; } - print " OK"; + print " OK with ref ".$propal->ref."\n"; } else { dol_print_error($db,$propal->error); } - print "\n"; } - ?> diff --git a/dev/initdata/generate-societe.php b/dev/initdata/generate-societe.php index 945809c77e5..bd78878fd80 100644 --- a/dev/initdata/generate-societe.php +++ b/dev/initdata/generate-societe.php @@ -53,6 +53,15 @@ $prenoms = array("Joe","Marc","Steve","Laurent","Nico","Isabelle","Dorothee","Sa 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(); if ($db->query($sql)) { $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->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->code_client='CU'.time()."$s"; + $soc->code_fournisseur='SU'.time()."$s"; $soc->tva_assuj=1; $soc->pays_id=1; $soc->pays_code='FR'; - // Un client sur 10 a une remise de 5% - $user_remise=rand(1,10); if ($user_remise==10) $soc->remise_client=5; + // Un client sur 3 a une remise de 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"; - $soc->note='Fictional company created by the script generate-societe.php'; + $soc->note='Company created by the script generate-societe.php'; $socid = $soc->create(); if ($socid >= 0) { $rand = rand(1,4); - print "> Generates $rand contact\n"; + print "> Generates $rand contact(s)\n"; for ($c = 0 ; $c < $rand ; $c++) { $contact = new Contact($db); $contact->socid = $soc->id; - $contact->name = "NomFamille".$c; + $contact->name = "Lastname".$c; $contact->firstname = $prenoms[rand(0,sizeof($prenoms)-1)]; if ( $contact->create($user) ) { } } + + print "Company ".$s." created nom=".$soc->nom."\n"; } else {