This commit is contained in:
Laurent Destailleur 2019-09-30 19:00:19 +02:00
parent fe735d4e67
commit d9e9364ddf

View File

@ -87,81 +87,17 @@ $usercanread = (($user->rights->stock->lire));
$usercancreate = (($user->rights->stock->creer));
$usercandelete = (($user->rights->stock->supprimer));
// Ajout entrepot
if ($action == 'add' && $user->rights->stock->creer)
$parameters=array('id'=>$id, 'ref'=>$ref);
$reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook))
{
$object->ref = GETPOST("ref");
$object->fk_parent = GETPOST("fk_parent");
$object->libelle = GETPOST("libelle");
$object->description = GETPOST("desc");
$object->statut = GETPOST("statut");
$object->lieu = GETPOST("lieu");
$object->address = GETPOST("address");
$object->zip = GETPOST("zipcode");
$object->town = GETPOST("town");
$object->country_id = GETPOST("country_id");
if (! empty($object->libelle))
// Ajout entrepot
if ($action == 'add' && $user->rights->stock->creer)
{
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
if ($ret < 0) {
$error++;
$action = 'create';
}
if (! $error) {
$id = $object->create($user);
if ($id > 0) {
setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
$categories = GETPOST('categories', 'array');
$object->setCategories($categories);
if (!empty($backtopage)) {
header("Location: " . $backtopage);
exit;
} else {
header("Location: card.php?id=" . $id);
exit;
}
} else {
$action = 'create';
setEventMessages($object->error, $object->errors, 'errors');
}
}
}
else
{
setEventMessages($langs->trans("ErrorWarehouseRefRequired"), null, 'errors');
$action="create"; // Force retour sur page creation
}
}
// Delete warehouse
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->stock->supprimer)
{
$object->fetch(GETPOST('id', 'int'));
$result=$object->delete($user);
if ($result > 0)
{
setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
header("Location: ".DOL_URL_ROOT.'/product/stock/list.php?restore_lastsearch_values=1');
exit;
}
else
{
setEventMessages($object->error, $object->errors, 'errors');
$action='';
}
}
// Modification entrepot
if ($action == 'update' && $cancel <> $langs->trans("Cancel"))
{
if ($object->fetch($id))
{
$object->libelle = GETPOST("libelle");
$object->ref = GETPOST("ref");
$object->fk_parent = GETPOST("fk_parent");
$object->libelle = GETPOST("libelle");
$object->description = GETPOST("desc");
$object->statut = GETPOST("statut");
$object->lieu = GETPOST("lieu");
@ -170,57 +106,127 @@ if ($action == 'update' && $cancel <> $langs->trans("Cancel"))
$object->town = GETPOST("town");
$object->country_id = GETPOST("country_id");
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
if ($ret < 0) $error++;
if (! empty($object->libelle))
{
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
if ($ret < 0) {
$error++;
$action = 'create';
}
if (! $error) {
$ret = $object->update($id, $user);
if ($ret < 0) $error++;
}
if (! $error) {
$id = $object->create($user);
if ($id > 0) {
setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
if ($error) {
$categories = GETPOST('categories', 'array');
$object->setCategories($categories);
if (!empty($backtopage)) {
header("Location: " . $backtopage);
exit;
} else {
header("Location: card.php?id=" . $id);
exit;
}
} else {
$action = 'create';
setEventMessages($object->error, $object->errors, 'errors');
}
}
}
else
{
setEventMessages($langs->trans("ErrorWarehouseRefRequired"), null, 'errors');
$action="create"; // Force retour sur page creation
}
}
// Delete warehouse
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->stock->supprimer)
{
$object->fetch(GETPOST('id', 'int'));
$result=$object->delete($user);
if ($result > 0)
{
setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
header("Location: ".DOL_URL_ROOT.'/product/stock/list.php?restore_lastsearch_values=1');
exit;
}
else
{
setEventMessages($object->error, $object->errors, 'errors');
$action='';
}
}
// Modification entrepot
if ($action == 'update' && $cancel <> $langs->trans("Cancel"))
{
if ($object->fetch($id))
{
$object->libelle = GETPOST("libelle");
$object->fk_parent = GETPOST("fk_parent");
$object->description = GETPOST("desc");
$object->statut = GETPOST("statut");
$object->lieu = GETPOST("lieu");
$object->address = GETPOST("address");
$object->zip = GETPOST("zipcode");
$object->town = GETPOST("town");
$object->country_id = GETPOST("country_id");
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
if ($ret < 0) $error++;
if (! $error) {
$ret = $object->update($id, $user);
if ($ret < 0) $error++;
}
if ($error) {
$action = 'edit';
setEventMessages($object->error, $object->errors, 'errors');
} else {
$categories = GETPOST('categories', 'array');
$object->setCategories($categories);
$action = '';
}
}
else
{
$action = 'edit';
setEventMessages($object->error, $object->errors, 'errors');
} else {
$categories = GETPOST('categories', 'array');
$object->setCategories($categories);
$action = '';
}
}
}
else
elseif ($action == 'update_extras') {
$object->oldcopy = dol_clone($object);
// Fill array 'array_options' with data from update form
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute', 'none'));
if ($ret < 0) $error++;
if (! $error) {
$result = $object->insertExtraFields();
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
$error++;
}
}
if ($error) $action = 'edit_extras';
}
if ($cancel == $langs->trans("Cancel"))
{
$action = 'edit';
setEventMessages($object->error, $object->errors, 'errors');
$action = '';
}
// Actions to build doc
$upload_dir = $conf->stock->dir_output;
$permissioncreate = $user->rights->stock->creer;
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
}
elseif ($action == 'update_extras') {
$object->oldcopy = dol_clone($object);
// Fill array 'array_options' with data from update form
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute', 'none'));
if ($ret < 0) $error++;
if (! $error) {
$result = $object->insertExtraFields();
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
$error++;
}
}
if ($error) $action = 'edit_extras';
}
if ($cancel == $langs->trans("Cancel"))
{
$action = '';
}
// Actions to build doc
$upload_dir = $conf->stock->dir_output;
$permissioncreate = $user->rights->stock->creer;
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
/*