/** * \brief Cree la commande au statut brouillon * \param user Utilisateur qui cree * \return int <0 si ko, id de la commande creee si ok */ function create_commande($user) { dol_syslog("Fournisseur::Create_Commande"); $comm = new CommandeFournisseur($this->db); $comm->socid = $this->id; if ($comm->create($user) > 0) { $this->single_open_commande = $comm->id; return $comm->id; } else { $this->error=$comm->error; dol_syslog("Fournisseur::Create_Commande Failed ".$this->error, LOG_ERR); return -1; } }
$msg .= $order->error; setEventMessages($msg, null, 'errors'); } else { $id = $result; } } else { $order->socid = $suppliersid[$i]; $order->fetch_thirdparty(); //trick to know which orders have been generated this way $order->source = 42; foreach ($supplier['lines'] as $line) { $order->lines[] = $line; } $order->cond_reglement_id = $order->thirdparty->cond_reglement_supplier_id; $order->mode_reglement_id = $order->thirdparty->mode_reglement_supplier_id; $id = $order->create($user); if ($id < 0) { $fail++; $msg = $langs->trans('OrderFail') . " : "; $msg .= $order->error; setEventMessages($msg, null, 'errors'); } $i++; } } if (!$fail && $id) { $db->commit(); setEventMessages($langs->trans('OrderCreated'), null, 'mesgs'); header('Location: replenishorders.php'); exit; } else {
/** * testCommandeFournisseurCreate * * @return void */ public function testCommandeFournisseurCreate() { global $conf, $user, $langs, $db; $conf = $this->savconf; $user = $this->savuser; $langs = $this->savlangs; $db = $this->savdb; // Set supplier and product to use $socid = 1; $societe = new Societe($db); $societe->fetch($socid); $product = new ProductFournisseur($db); $product->fetch(0, 'PIDRESS'); if ($product->id <= 0) { print "\n" . __METHOD__ . " A product with ref PIDRESS must exists into database"; die; } $quantity = 10; $ref_fourn = 'SUPPLIER_REF_PHPUNIT'; $tva_tx = 19.6; // Create supplier price $result = $product->add_fournisseur($user, $societe->id, $ref_fourn, $quantity); // This insert record with no value for price. Values are update later with update_buyprice $this->assertGreaterThanOrEqual(1, $result); $result = $product->update_buyprice($quantity, 10, $user, 'HT', $societe, '', $ref_fourn, $tva_tx, 0, 0); $this->assertGreaterThanOrEqual(0, $result); // Create supplier order with a too low quantity $localobject = new CommandeFournisseur($db); $localobject->initAsSpecimen(); $localobject->lines = array(); // Overwrite lines of order $line = new CommandeFournisseurLigne($db); $line->desc = $langs->trans("Description") . " specimen line too low"; $line->qty = 1; // So lower than $quantity $line->fk_product = $product->id; $line->ref_fourn = $ref_fourn; $localobject->lines[] = $line; $result = $localobject->create($user); print __METHOD__ . " result=" . $result . "\n"; $this->assertEquals(-1, $result); // must be -1 because quantity is lower than minimum of supplier price $sql = "DELETE FROM " . MAIN_DB_PREFIX . "commande_fournisseur where ref=''"; $db->query($sql); // Create supplier order $localobject2 = new CommandeFournisseur($db); $localobject2->initAsSpecimen(); // This create 5 lines of first product found for socid 1 $localobject2->lines = array(); // Overwrite lines of order $line = new CommandeFournisseurLigne($db); $line->desc = $langs->trans("Description") . " specimen line ok"; $line->qty = 10; // So enough quantity $line->fk_product = $product->id; $line->ref_fourn = $ref_fourn; $localobject2->lines[] = $line; $result = $localobject2->create($user); print __METHOD__ . " result=" . $result . "\n"; $this->assertGreaterThanOrEqual(0, $result); return $result; }
/** */ public function testCommandeFournisseurCreate() { global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new CommandeFournisseur($this->savdb); $localobject->initAsSpecimen(); $result=$localobject->create($user); print __METHOD__." result=".$result."\n"; $this->assertLessThan($result, 0); return $result; }
private function addCommandeFourn(&$PDOdb, $ofLigne, $resultatSQL) { global $db, $user; dol_include_once("fourn/class/fournisseur.commande.class.php"); // On cherche s'il existe une commande pour ce fournisseur $sql = "SELECT rowid"; $sql .= " FROM " . MAIN_DB_PREFIX . "commande_fournisseur"; $sql .= " WHERE fk_soc = " . $resultatSQL->fk_soc; $sql .= " AND fk_statut = 0"; //uniquement brouillon $sql .= " ORDER BY rowid DESC"; $sql .= " LIMIT 1"; $resql = $db->query($sql); $res = $db->fetch_object($resql); if ($res) { // Il existe une commande, on la charge $com = new CommandeFournisseur($db); $com->fetch($res->rowid); } else { // Il n'existe aucune commande pour ce fournisseur donc on en crée une nouvelle $com = new CommandeFournisseur($db); $com->socid = $resultatSQL->fk_soc; $com->create($user); } // On cherche si ce produit existe déjà dans la commande, si oui, : "updateline" foreach ($com->lines as $line) { if ($line->fk_product == $resultatSQL->fk_product) { $com->updateline($line->id, $line->desc, $line->subprice, $line->qty + $ofLigne->qty, $line->remise_percent, $line->tva_tx); $done = true; break; } } if (!$done) { // Si le produit n'existe pas déjà dans la commande, on l'ajoute à cette commande $com->addline($desc, $resultatSQL->price / $resultatSQL->quantity, $ofLigne->qty, $txtva, 0, 0, $resultatSQL->fk_product, $resultatSQL->rowid); } //Création association element_element entre la commande fournisseur et l'OF $this->addElementElement($PDOdb, $com, $ofLigne); }