diff --git a/dev/initdata/generate-commande.php b/dev/initdata/generate-commande.php index 7be61d05284..98305ee38dd 100644 --- a/dev/initdata/generate-commande.php +++ b/dev/initdata/generate-commande.php @@ -50,6 +50,15 @@ include_once(DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php"); define (GEN_NUMBER_COMMANDE, 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."societe"; $societesid = array(); $resql=$db->query($sql); if ($resql) { @@ -80,14 +89,14 @@ else { print "err"; } $prodids = array(); $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product WHERE tosell=1"; $resql = $db->query($sql); -if ($resql) +if ($resql) { $num_prods = $db->num_rows($resql); $i = 0; while ($i < $num_prods) { $i++; - + $row = $db->fetch_row($resql); $prodids[$i] = $row[0]; } @@ -152,47 +161,56 @@ require(DOL_DOCUMENT_ROOT."/commande/class/commande.class.php"); print "Build ".GEN_NUMBER_COMMANDE." orders\n"; for ($s = 0 ; $s < GEN_NUMBER_COMMANDE ; $s++) { - print "Order ".$s; + print "Process order ".$s."\n"; $com = new Commande($db); - + $com->socid = 4; $com->date_commande = $dates[rand(1, sizeof($dates)-1)]; - $com->note = $_POST["note"]; + $com->note = 'A comment'; $com->source = 1; $com->fk_project = 0; $com->remise_percent = 0; - - $nbp = rand(2, 5); - $xnbp = 0; - while ($xnbp < $nbp) - { - // \TODO Utiliser addline plutot que add_product - $prodid = rand(1, $num_prods); - $result=$com->add_product($prodids[$prodid],rand(1,11),rand(1,6),rand(0,20)); - if ($result < 0) - { - dol_print_error($db,$propal->error); - } - $xnbp++; - } - + + $db->begin(); + $result=$com->create($user); if ($result >= 0) { $result=$com->valid($user); - if ($result) print " OK"; + if ($result > 0) + { + $nbp = rand(2, 5); + $xnbp = 0; + while ($xnbp < $nbp) + { + $prodid = rand(1, $num_prods); + $product=new Product($db); + $result=$product->fetch($prodids[$prodid]); + $result=$com->addline($com->id, $product->description, $product->price, 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); + } + $xnbp++; + } + + $db->commit(); + print " OK with ref ".$com->ref."\n"; + } else { - dol_print_error($db,$com->error); + print " KO\n"; + $db->rollback(); + dol_print_error($db,$com->error); } } else { - dol_print_error($db,$com->error); + print " KO\n"; + $db->rollback(); + dol_print_error($db,$com->error); } - - print "\n"; } ?> diff --git a/dev/initdata/generate-facture.php b/dev/initdata/generate-facture.php index 518658f3107..354f724fc62 100644 --- a/dev/initdata/generate-facture.php +++ b/dev/initdata/generate-facture.php @@ -113,7 +113,7 @@ while ($i < GEN_NUMBER_FACTURE && $result >= 0) $prodid = rand(1, $num_prods); $product=new Product($db); $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); + $result=$facture->addline($facture->id,$product->description,$product->price, rand(1,5), 0, 0, 0, $prodids[$prodid], 0, '', '', 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type); $xnbp++; } diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 0548cb8f9d4..637999fce2b 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -130,6 +130,7 @@ class Commande extends CommonObject // Chargement de la classe de numerotation $classname = $conf->global->COMMANDE_ADDON; + $result=include_once($dir.'/'.$file); if ($result) { @@ -630,6 +631,8 @@ class Commande extends CommonObject { if ($this->id) { + $this->ref="(PROV".$this->id.")"; + // Add linked object if ($this->origin && $this->origin_id) { @@ -641,7 +644,7 @@ class Commande extends CommonObject if ($this->origin == 'propal' && $this->origin_id) { // On recupere les differents contact interne et externe - $prop = New Propal($this->db, $this->socid, $this->origin_id); + $prop = new Propal($this->db, $this->socid, $this->origin_id); // On recupere le commercial suivi propale $this->userid = $prop->getIdcontact('internal', 'SALESREPFOLL'); @@ -788,12 +791,12 @@ class Commande extends CommonObject * @param date_end End date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) * @param type Type of line (0=product, 1=service) * @param rang Position of line - * @return int >0 si ok, <0 si ko + * @return int >0 if OK, <0 if KO * @see add_product - * @remarks Les parametres sont deja cense etre juste et avec valeurs finales a l'appel - * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete defini - * par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,produit) - * et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue) + * Les parametres sont deja cense etre juste et avec valeurs finales a l'appel + * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete defini + * par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,produit) + * et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue) */ function addline($commandeid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $info_bits=0, $fk_remise_except=0, $price_base_type='HT', $pu_ttc=0, $date_start='', $date_end='', $type=0, $rang=-1, $special_code=0) { diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php index 14d54805744..e7e71efc78a 100644 --- a/htdocs/install/repair.php +++ b/htdocs/install/repair.php @@ -140,7 +140,7 @@ if ($ok) //print '