* Actions */ // Ajout entrepot if ($action == 'add' && $user->rights->stock->creer) { $object = new Entrepot($db); $object->ref = $_POST["ref"]; $object->libelle = $_POST["libelle"]; $object->description = $_POST["desc"]; $object->statut = $_POST["statut"]; $object->lieu = $_POST["lieu"]; $object->address = $_POST["address"]; $object->zip = $_POST["zipcode"]; $object->town = $_POST["town"]; $object->country_id = $_POST["country_id"]; if ($object->libelle) { $id = $object->create($user); if ($id > 0) { header("Location: fiche.php?id=" . $id); exit; } $action = 'create'; $mesg = '<div class="error">' . $object->error . '</div>'; } else { $mesg = '<div class="error">' . $langs->trans("ErrorWarehouseRefRequired") . '</div>'; $action = "create"; // Force retour sur page creation } } // Delete warehouse if ($action == 'confirm_delete' && $_REQUEST["confirm"] == 'yes' && $user->rights->stock->supprimer) { $object = new Entrepot($db);
/** * Create a user into database * * @param User $user Objet user doing creation * @param int $notrigger 1=do not execute triggers, 0 otherwise * @return int <0 if KO, id of created user if OK */ function create($user, $notrigger = 0) { global $conf, $langs; global $mysoc; // Clean parameters $this->login = trim($this->login); if (!isset($this->entity)) { $this->entity = $conf->entity; } // If not defined, we use default value dol_syslog(get_class($this) . "::create login="******", user="******"errors"); $this->error = $langs->trans("ErrorBadEMail", $this->email); return -1; } if (empty($this->login)) { $langs->load("errors"); $this->error = $langs->trans("ErrorFieldRequired", $this->login); return -1; } $this->datec = dol_now(); $error = 0; $this->db->begin(); $sql = "SELECT login FROM " . MAIN_DB_PREFIX . "user"; $sql .= " WHERE login ='******'"; $sql .= " AND entity IN (0," . $this->db->escape($conf->entity) . ")"; dol_syslog(get_class($this) . "::create", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); $this->db->free($resql); if ($num) { $this->error = 'ErrorLoginAlreadyExists'; dol_syslog(get_class($this) . "::create " . $this->error, LOG_WARNING); $this->db->rollback(); return -6; } else { $sql = "INSERT INTO " . MAIN_DB_PREFIX . "user (datec,login,ldap_sid,entity)"; $sql .= " VALUES('" . $this->db->idate($this->datec) . "','" . $this->db->escape($this->login) . "','" . $this->db->escape($this->ldap_sid) . "'," . $this->db->escape($this->entity) . ")"; $result = $this->db->query($sql); dol_syslog(get_class($this) . "::create", LOG_DEBUG); if ($result) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "user"); // Set default rights if ($this->set_default_rights() < 0) { $this->error = 'ErrorFailedToSetDefaultRightOfUser'; $this->db->rollback(); return -5; } // Update minor fields $result = $this->update($user, 1, 1); if ($result < 0) { $this->db->rollback(); return -4; } if (!empty($conf->global->STOCK_USERSTOCK_AUTOCREATE)) { require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php'; $langs->load("stocks"); $entrepot = new Entrepot($this->db); $entrepot->libelle = $langs->trans("PersonalStock", $this->getFullName($langs)); $entrepot->description = $langs->trans("ThisWarehouseIsPersonalStock", $this->getFullName($langs)); $entrepot->statut = 1; $entrepot->country_id = $mysoc->country_id; $entrepot->create($user); } if (!$notrigger) { // Call trigger $result = $this->call_trigger('USER_CREATE', $user); if ($result < 0) { $error++; } // End call triggers } if (!$error) { $this->db->commit(); return $this->id; } else { //$this->error=$interface->error; dol_syslog(get_class($this) . "::create " . $this->error, LOG_ERR); $this->db->rollback(); return -3; } } else { $this->error = $this->db->lasterror(); $this->db->rollback(); return -2; } } } else { $this->error = $this->db->lasterror(); $this->db->rollback(); return -1; } }
/** * testMouvementCreate * * @return int */ public function testMouvementCreate() { global $conf, $user, $langs, $db; $conf = $this->savconf; $user = $this->savuser; $langs = $this->savlangs; $db = $this->savdb; // We create a product for tests $product1 = new Product($db); $product1->initAsSpecimen(); $product1->ref .= ' 1'; $product1->label .= ' 1'; $product1id = $product1->create($user); $product2 = new Product($db); $product2->initAsSpecimen(); $product2->ref .= ' 2'; $product2->label .= ' 2'; $product2id = $product2->create($user); // We create a product for tests $warehouse1 = new Entrepot($db); $warehouse1->initAsSpecimen(); $warehouse1->libelle .= ' 1'; $warehouse1->description .= ' 1'; $warehouse1id = $warehouse1->create($user); $warehouse2 = new Entrepot($db); $warehouse2->initAsSpecimen(); $warehouse2->libelle .= ' 2'; $warehouse2->description .= ' 2'; $warehouse2id = $warehouse2->create($user); $localobject = new MouvementStock($this->savdb); // Do a list of movement into warehouse 1 // Create an input movement (type = 3) of price 9.9 -> shoul dupdate PMP to 9.9 $result = $localobject->_create($user, $product1id, $warehouse1id, 10, 3, 9.9, 'Movement for unit test 1', 'Inventory Code Test'); print __METHOD__ . " result=" . $result . "\n"; $this->assertLessThan($result, 0); // Create an input movement (type = 3) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 $result = $localobject->_create($user, $product1id, $warehouse1id, 10, 3, 9.699999999999999, 'Movement for unit test 2', 'Inventory Code Test'); print __METHOD__ . " result=" . $result . "\n"; $this->assertLessThan($result, 0); // Create an output movement (type = 2) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 $result = $localobject->_create($user, $product1id, $warehouse1id, -5, 2, 999, 'Movement for unit test 3', 'Inventory Code Test'); print __METHOD__ . " result=" . $result . "\n"; $this->assertLessThan($result, 0); // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 $result = $localobject->_create($user, $product1id, $warehouse1id, 1, 0, 0, 'Input from transfer', 'Transfert X'); print __METHOD__ . " result=" . $result . "\n"; $this->assertLessThan($result, 0); // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 $result = $localobject->_create($user, $product1id, $warehouse1id, -2, 1, 0, 'Output from transfer', 'Transfert Y'); print __METHOD__ . " result=" . $result . "\n"; $this->assertLessThan($result, 0); // Do same but into warehouse 2 // Create an input movement (type = 3) of price 9.9 -> shoul dupdate PMP to 9.9 $result = $localobject->_create($user, $product1id, $warehouse2id, 10, 3, 9.9, 'Movement for unit test 1 wh 2', 'Inventory Code Test 2'); print __METHOD__ . " result=" . $result . "\n"; $this->assertLessThan($result, 0); // Create an input movement (type = 3) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 $result = $localobject->_create($user, $product1id, $warehouse2id, 10, 3, 9.699999999999999, 'Movement for unit test 2 wh 2', 'Inventory Code Test 2'); print __METHOD__ . " result=" . $result . "\n"; $this->assertLessThan($result, 0); // Create an output movement (type = 2) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 $result = $localobject->_create($user, $product1id, $warehouse2id, -5, 2, 999, 'Movement for unit test 3 wh 2', 'Inventory Code Test 2'); print __METHOD__ . " result=" . $result . "\n"; $this->assertLessThan($result, 0); // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 $result = $localobject->_create($user, $product1id, $warehouse2id, 1, 0, 0, 'Input from transfer wh 2', 'Transfert X 2'); print __METHOD__ . " result=" . $result . "\n"; $this->assertLessThan($result, 0); // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 $result = $localobject->_create($user, $product1id, $warehouse2id, -2, 1, 0, 'Output from transfer wh 2', 'Transfert Y 2'); print __METHOD__ . " result=" . $result . "\n"; $this->assertLessThan($result, 0); return $localobject; }
/** * testEntrepotCreate * * @return void */ public function testEntrepotCreate() { global $conf, $user, $langs, $db; $conf = $this->savconf; $user = $this->savuser; $langs = $this->savlangs; $db = $this->savdb; $localobject = new Entrepot($this->savdb); $localobject->initAsSpecimen(); $result = $localobject->create($user); print __METHOD__ . " result=" . $result . "\n"; $this->assertLessThanOrEqual($result, 0); return $result; }
if ($_POST["action"] == 'add' && $user->rights->stock->creer) { $entrepot = new Entrepot($db); $entrepot->ref = $_POST["ref"]; $entrepot->libelle = $_POST["libelle"]; $entrepot->description = $_POST["desc"]; $entrepot->statut = $_POST["statut"]; $entrepot->lieu = $_POST["lieu"]; $entrepot->address = $_POST["address"]; $entrepot->cp = $_POST["cp"]; $entrepot->ville = $_POST["ville"]; $entrepot->pays_id = $_POST["pays_id"]; if ($entrepot->libelle) { $id = $entrepot->create($user); if ($id > 0) { header("Location: fiche.php?id=".$id); exit; } $_GET["action"] = 'create'; $mesg="<div class='error'>".$entrepot->error."</div>"; } else { $mesg="<div class='error'>".$langs->trans("ErrorWarehouseRefRequired")."</div>"; $_GET["action"]="create"; // Force retour sur page cr�ation } }
/** * Create a user into database * @param user Objet user qui demande la creation * @param notrigger 1 ne declenche pas les triggers, 0 sinon * @return int <0 si KO, id compte cree si OK */ function create($user,$notrigger=0) { global $conf,$langs; // Clean parameters $this->login = trim($this->login); if (! isset($this->entity)) $this->entity=$conf->entity; // If not defined, we use default value dol_syslog("User::Create login="******", user="******"errors"); $this->error = $langs->trans("ErrorBadEMail",$this->email); return -1; } $now=dol_now(); $error=0; $this->db->begin(); $sql = "SELECT login FROM ".MAIN_DB_PREFIX."user"; $sql.= " WHERE login ='******'"; $sql.= " AND entity IN (0,".$conf->entity.")"; dol_syslog("User::Create sql=".$sql, LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); $this->db->free($resql); if ($num) { $this->error = 'ErrorLoginAlreadyExists'; dol_syslog("User::Create ".$this->error, LOG_WARNING); $this->db->rollback(); return -6; } else { $sql = "INSERT INTO ".MAIN_DB_PREFIX."user (datec,login,ldap_sid,entity)"; $sql.= " VALUES('".$this->db->idate($now)."','".$this->db->escape($this->login)."','".$this->ldap_sid."',".$this->entity.")"; $result=$this->db->query($sql); dol_syslog("User::Create sql=".$sql, LOG_DEBUG); if ($result) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."user"); // Set default rights if ($this->set_default_rights() < 0) { $this->error=$this->db->error(); $this->db->rollback(); return -5; } // Update minor fields $result = $this->update($user,1,1); if ($result < 0) { $this->db->rollback(); return -4; } if (! empty($conf->global->STOCK_USERSTOCK_AUTOCREATE)) { require_once(DOL_DOCUMENT_ROOT."/product/stock/class/entrepot.class.php"); $langs->load("stocks"); $entrepot = new Entrepot($this->db); $entrepot->libelle = $langs->trans("PersonalStock",$this->nom); $entrepot->description = $langs->trans("ThisWarehouseIsPersonalStock",$this->prenom,$this->nom); $entrepot->statut = 1; $entrepot->create($user); } if (! $notrigger) { // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); $interface = new Interfaces($this->db); $result = $interface->run_triggers('USER_CREATE',$this,$user,$langs,$conf); if ($result < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers } if (! $error) { $this->db->commit(); return $this->id; } else { $this->error=$interface->error; dol_syslog("User::Create ".$this->error, LOG_ERR); $this->db->rollback(); return -3; } } else { $this->error=$this->db->lasterror(); dol_syslog("User::Create ".$this->error, LOG_ERR); $this->db->rollback(); return -2; } } } else { $this->error=$this->db->lasterror(); dol_syslog("User::Create ".$this->error, LOG_ERR); $this->db->rollback(); return -1; } }