From 00d2d28d687cc3e85edd62b2a1646b53bc410947 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 26 Feb 2021 12:34:41 +0100 Subject: [PATCH] NEW: Can create a lot from list Make code like modulebuilder --- .../product/stock/class/productlot.class.php | 3 +- htdocs/product/stock/productlot_card.php | 263 +++++++++++------- htdocs/product/stock/productlot_list.php | 9 +- 3 files changed, 174 insertions(+), 101 deletions(-) diff --git a/htdocs/product/stock/class/productlot.class.php b/htdocs/product/stock/class/productlot.class.php index 90df912e69d..96650c034f3 100644 --- a/htdocs/product/stock/class/productlot.class.php +++ b/htdocs/product/stock/class/productlot.class.php @@ -95,7 +95,8 @@ class Productlot extends CommonObject 'datec' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>500), 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501), 'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>510, 'foreignkey'=>'llx_user.rowid'), - 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511) + 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511), + 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>0, 'position'=>1000), ); /** diff --git a/htdocs/product/stock/productlot_card.php b/htdocs/product/stock/productlot_card.php index 64902b02e86..0fd29543c6c 100644 --- a/htdocs/product/stock/productlot_card.php +++ b/htdocs/product/stock/productlot_card.php @@ -36,8 +36,35 @@ $langs->loadLangs(array('stocks', 'other', 'productbatch')); // Get parameters $id = GETPOST('id', 'int'); -$action = GETPOST('action', 'alpha'); +$action = GETPOST('action', 'aZ09'); +$confirm = GETPOST('confirm', 'alpha'); +$cancel = GETPOST('cancel', 'aZ09'); +$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'myobjectcard'; // To manage different context of search $backtopage = GETPOST('backtopage', 'alpha'); + +// Initialize technical objects +$object = new ProductLot($db); +$extrafields = new ExtraFields($db); +$hookmanager->initHooks(array('productlotcard', 'globalcard')); // Note that conf->hooks_modules contains array + +// Fetch optionals attributes and labels +$extrafields->fetch_name_optionals_label($object->table_element); + +$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); + +// Initialize array of search criterias +$search_all = GETPOST("search_all", 'alpha'); +$search = array(); +foreach ($object->fields as $key => $val) { + if (GETPOST('search_'.$key, 'alpha')) { + $search[$key] = GETPOST('search_'.$key, 'alpha'); + } +} + +if (empty($action) && empty($id) && empty($ref)) { + $action = 'view'; +} + $batch = GETPOST('batch', 'alpha'); $productid = GETPOST('productid', 'int'); $ref = GETPOST('ref', 'alpha'); // ref is productid_batch @@ -51,22 +78,6 @@ $search_import_key = GETPOST('search_import_key', 'int'); if (empty($action) && empty($id) && empty($ref)) $action = 'list'; - -// Protection if external user -if ($user->socid > 0) -{ - //accessforbidden(); -} -//$result = restrictedArea($user, 'mymodule', $id); - - -$object = new ProductLot($db); -$extrafields = new ExtraFields($db); -$formfile = new FormFile($db); - -// fetch optionals attributes and labels -$extrafields->fetch_name_optionals_label($object->table_element); - // Load object //include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals if ($id || $ref) @@ -81,6 +92,15 @@ if ($id || $ref) $object->ref = $object->batch; // For document management ( it use $object->ref) } +// Protection if external user +if ($user->socid > 0) +{ + //accessforbidden(); +} +//$result = restrictedArea($user, 'mymodule', $id); + + + // Initialize technical object to manage hooks of modules. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('productlotcard', 'globalcard')); @@ -93,16 +113,26 @@ $usercanread = $user->rights->produit->lire; $usercancreate = $user->rights->produit->creer; $usercandelete = $user->rights->produit->supprimer; +$upload_dir = $conf->productbatch->multidir_output[$conf->entity]; + +$permissiontoadd = $usercancreate; + + /* * Actions */ $parameters = array(); $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 ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} + +if (empty($reshook)) { + $error = 0; + + $backurlforlist = dol_buildpath('/product/stock/productlot_list.php', 1); -if (empty($reshook)) -{ if ($action == 'seteatby' && $user->rights->stock->creer) { $newvalue = dol_mktime(12, 0, 0, $_POST['eatbymonth'], $_POST['eatbyday'], $_POST['eatbyyear']); @@ -117,6 +147,11 @@ if (empty($reshook)) if ($result < 0) dol_print_error($db, $object->error); } + $triggermodname = 'PRODUCT_LOT_MODIFY'; // Name of trigger action code to execute when we modify record + + // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen + include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; + /* if ($action == 'update_extras') { $object->oldcopy = dol_clone($object); @@ -152,8 +187,6 @@ if (empty($reshook)) $error = 0; - /* object_prop_getpost_prop */ - $object->entity = GETPOST('entity', 'int'); $object->fk_product = GETPOST('fk_product', 'int'); $object->batch = GETPOST('batch', 'alpha'); @@ -241,11 +274,15 @@ if (empty($reshook)) else setEventMessages($object->error, null, 'errors'); } } - - // Actions to build doc - $upload_dir = $conf->productbatch->multidir_output[$conf->entity]; - $permissiontoadd = $usercancreate; +*/ + // Action to build doc include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; + + // Actions to send emails + $triggersendname = 'PRODUCT_LOT_SENTBYMAIL'; + $autocopy = 'MAIN_MAIL_AUTOCOPY_PRODUCT_LOT_TO'; + $trackid = 'productlot'.$object->id; + include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; } @@ -255,69 +292,98 @@ if (empty($reshook)) * View */ -llxHeader('', 'ProductLot', ''); - $form = new Form($db); +$formfile = new FormFile($db); + +$title = $langs->trans("ProductLot"); +$help_url = ''; +llxHeader('', $title, $help_url); + // Part to create -if ($action == 'create') -{ - print load_fiche_titre($langs->trans("Batch")); +if ($action == 'create') { + print load_fiche_titre($langs->trans("Batch"), '', 'object_'.$object->picto); print '
'; + print ''; print ''; - print ''; + if ($backtopage) { + print ''; + } + if ($backtopageforcancel) { + print ''; + } - print dol_get_fiche_head(); + print dol_get_fiche_head(array(), ''); - print ''."\n"; - // print ''; - // - print ''; - print ''; - print ''; - print ''; - print ''; + // Set some default values + //if (! GETPOSTISSET('fieldname')) $_POST['fieldname'] = 'myvalue'; + + print '
'.$langs->trans("Label").'
'.$langs->trans("Fieldfk_product").'
'.$langs->trans("Fieldbatch").'
'.$langs->trans("Fieldfk_user_creat").'
'.$langs->trans("Fieldfk_user_modif").'
'.$langs->trans("Fieldimport_key").'
'."\n"; + + // Common attributes + include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php'; + + // Other attributes + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php'; print '
'."\n"; print dol_get_fiche_end(); - print '
 
'; + print '
'; + print ''; + print '  '; + print ''; // Cancel for create does not post form if we don't know the backtopage + print '
'; print '
'; + + //dol_set_focus('input[name="ref"]'); } // Part to show record -if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) -{ +if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) { $res = $object->fetch_optionals(); - //print load_fiche_titre($langs->trans("Batch")); - $head = productlot_prepare_head($object); - print dol_get_fiche_head($head, 'card', $langs->trans("Batch"), -1, 'barcode'); - + print dol_get_fiche_head($head, 'card', $langs->trans("Batch"), -1, $object->picto); + $formconfirm = ''; + + // Confirmation to delete if ($action == 'delete') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteBatch'), $langs->trans('ConfirmDeleteBatch'), 'confirm_delete', '', 0, 1); - print $formconfirm; } - + // Call Hook formConfirm + $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid); + $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if (empty($reshook)) { + $formconfirm .= $hookmanager->resPrint; + } elseif ($reshook > 0) { + $formconfirm = $hookmanager->resPrint; + } + + // Print form confirm + print $formconfirm; + + // Object card + // ------------------------------------------------------------ $linkback = ''.$langs->trans("BackToList").''; $shownav = 1; if ($user->socid && !in_array('batch', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; - dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch'); + $morehtmlref = ''; + + dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch', $morehtmlref); print '
'; print '
'; - - print ''."\n"; + print '
'."\n"; // Product print ''; print ''; } - // Other attributes - $cols = 2; + + // Other attributes. Fields from hook formObjectOptions and Extrafields. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; print '
'.$langs->trans("Product").''; @@ -345,44 +411,49 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print '
'; print '
'; + print '
'; + print dol_get_fiche_end(); - - // Buttons - print '
'."\n"; - $parameters = array(); - $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - - if (empty($reshook)) - { - /*TODO if ($user->rights->stock->lire) - { - print ''."\n"; - } - - if ($user->rights->stock->supprimer) - { - print ''."\n"; - } - */ - } - print '
'."\n"; - - + // Link to other lists print ''.$langs->trans("ShowCurrentStockOfLot").'
'; print '
'; print ''.$langs->trans("ShowLogOfMovementIfLot").'
'; - + print '
'; + + + // Buttons for actions + if ($action != 'presend' && $action != 'editline') { + print '
'."\n"; + $parameters = array(); + $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + + if (empty($reshook)) { + /*TODO if ($user->rights->stock->lire) + { + print ''."\n"; + } + + if ($user->rights->stock->supprimer) + { + print ''."\n"; + } + */ + } + + print '
'."\n"; + } + } @@ -391,30 +462,32 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea * Documents generes */ -if (empty($action)) -{ +if ($action != 'presend') { print '
'; print ''; // ancre + $includedocgeneration = 1; + // Documents - $filedir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product_batch').dol_sanitizeFileName($object->ref); - $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; - $genallowed = $usercanread; - $delallowed = $usercancreate; + if ($includedocgeneration) { + $objref = dol_sanitizeFileName($object->ref); + $relativepath = $objref.'/'.$objref.'.pdf'; + $filedir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product_batch').dol_sanitizeFileName($object->ref); + $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; + $genallowed = $usercanread; // If you can read, you can build the PDF to read content + $delallowed = $usercancreate; // If you can create/edit, you can remove a file on card + print $formfile->showdocuments('product_batch', $objref, $filedir, $urlsource, $genallowed, $delallowed, '', 0, 0, 0, 28, 0, '', 0, '', $langs->default_lang, '', $object); + } - print $formfile->showdocuments('product_batch', dol_sanitizeFileName($object->ref), $filedir, $urlsource, $genallowed, $delallowed, '', 0, 0, 0, 28, 0, '', 0, '', $object->default_lang, '', $object); - $somethingshown = $formfile->numoffiles; - - print '
'; - - // List of actions on element - print '
'; + print '
'; + + $MAXEVENT = 10; + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; $formactions = new FormActions($db); - $somethingshown = $formactions->showactions($object, 'productlot', $socid, 1); - print '
'; + $somethingshown = $formactions->showactions($object, 'productlot', $socid, 1, '', $MAXEVENT); - print '
'; + print '
'; } // End of page diff --git a/htdocs/product/stock/productlot_list.php b/htdocs/product/stock/productlot_list.php index e03de931a58..6e818be629d 100644 --- a/htdocs/product/stock/productlot_list.php +++ b/htdocs/product/stock/productlot_list.php @@ -124,9 +124,9 @@ if (is_array($extrafields->attributes[$object->table_element]['label']) && count $object->fields = dol_sort_array($object->fields, 'position'); $arrayfields = dol_sort_array($arrayfields, 'position'); -$permissiontoread = $user->rights->stock->read; -$permissiontoadd = $user->rights->stock->write; -$permissiontodelete = $user->rights->stock->delete; +$permissiontoread = $user->rights->stock->lire; +$permissiontoadd = $user->rights->stock->mouvement->creer; +//$permissiontodelete = $user->rights->stock->supprimer; @@ -321,8 +321,7 @@ print ''; //print ''; print ''; -$newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/mymodule/myobject_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd); -$newcardbutton = ''; +$newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/product/stock/productlot_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);