From e099ca093ae00d36d035cecf655a6686bf3fed4f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 28 Jul 2023 18:49:03 +0200 Subject: [PATCH] Debug v18 --- htdocs/admin/tools/listevents.php | 65 ++++++++++++++----- htdocs/core/menus/standard/eldy.lib.php | 4 +- htdocs/langs/en_US/stocks.lang | 2 + .../product/stock/class/productlot.class.php | 55 ++++++++++++++-- htdocs/product/stock/massstockmove.php | 11 +++- htdocs/product/stock/productlot_card.php | 11 ++-- 6 files changed, 115 insertions(+), 33 deletions(-) diff --git a/htdocs/admin/tools/listevents.php b/htdocs/admin/tools/listevents.php index 045ecda2cc7..a284a4a97f3 100644 --- a/htdocs/admin/tools/listevents.php +++ b/htdocs/admin/tools/listevents.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2004-2023 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2015 Bahfir Abbes * Copyright (C) 2018 Frédéric France @@ -336,6 +336,14 @@ if ($result) { // Fields title search print ''; + // Action column + if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; + $searchpicto = $form->showFilterAndCheckAddButtons(0); + print $searchpicto; + print ''; + } + print ''; print $form->selectDate($date_start === '' ? -1 : $date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzuserrel'); print $form->selectDate($date_end === '' ? -1 : $date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzuserrel'); @@ -370,15 +378,22 @@ if ($result) { print ''; } - print ''; - $searchpicto = $form->showFilterAndCheckAddButtons(0); - print $searchpicto; - print ''; + // Action column + if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; + $searchpicto = $form->showFilterAndCheckAddButtons(0); + print $searchpicto; + print ''; + } print "\n"; print ''; + // Action column + if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print_liste_field_titre(''); + } print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "e.dateevent", "", $param, '', $sortfield, $sortorder); print_liste_field_titre("Code", $_SERVER["PHP_SELF"], "e.type", "", $param, '', $sortfield, $sortorder); print_liste_field_titre("IP", $_SERVER["PHP_SELF"], "e.ip", "", $param, '', $sortfield, $sortorder); @@ -390,7 +405,10 @@ if ($result) { if (!empty($arrayfields['e.prefix_session']['checked'])) { print_liste_field_titre("SuffixSessionName", $_SERVER["PHP_SELF"], "e.prefix_session", "", $param, '', $sortfield, $sortorder); } - print_liste_field_titre(''); + // Action column + if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print_liste_field_titre(''); + } print "\n"; while ($i < min($num, $limit)) { @@ -398,20 +416,29 @@ if ($result) { print ''; + // Action column + if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; + $htmltext = ''.$langs->trans("UserAgent").': '.($obj->user_agent ? dol_string_nohtmltag($obj->user_agent) : $langs->trans("Unknown")); + $htmltext .= '
'.$langs->trans("SuffixSessionName").' (DOLSESSID_...): '.($obj->prefix_session ? dol_string_nohtmltag($obj->prefix_session) : $langs->trans("Unknown")); + print $form->textwithpicto('', $htmltext); + print ''; + } + // Date print ''.dol_print_date($db->jdate($obj->dateevent), '%Y-%m-%d %H:%M:%S', 'tzuserrel').''; // Code - print ''.$obj->type.''; + print ''.dol_escape_htmltag($obj->type).''; // IP - print ''; + print ''; print dol_print_ip($obj->ip); print ''; // Login - print ''; - if ($obj->fk_user) { + print ''; + if ($obj->fk_user > 0) { $userstatic->id = $obj->fk_user; $userstatic->login = $obj->login; $userstatic->admin = $obj->admin; @@ -446,23 +473,25 @@ if ($result) { if (!empty($arrayfields['e.user_agent']['checked'])) { // User agent print ''; - print $obj->user_agent; + print dol_escape_htmltag($obj->user_agent); print ''; } if (!empty($arrayfields['e.prefix_session']['checked'])) { // User agent print ''; - print $obj->prefix_session; + print dol_escape_htmltag($obj->prefix_session); print ''; } - // More informations - print ''; - $htmltext = ''.$langs->trans("UserAgent").': '.($obj->user_agent ? dol_string_nohtmltag($obj->user_agent) : $langs->trans("Unknown")); - $htmltext .= '
'.$langs->trans("SuffixSessionName").' (DOLSESSID_...): '.($obj->prefix_session ? dol_string_nohtmltag($obj->prefix_session) : $langs->trans("Unknown")); - print $form->textwithpicto('', $htmltext); - print ''; + // Action column + if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; + $htmltext = ''.$langs->trans("UserAgent").': '.($obj->user_agent ? dol_string_nohtmltag($obj->user_agent) : $langs->trans("Unknown")); + $htmltext .= '
'.$langs->trans("SuffixSessionName").' (DOLSESSID_...): '.($obj->prefix_session ? dol_string_nohtmltag($obj->prefix_session) : $langs->trans("Unknown")); + print $form->textwithpicto('', $htmltext); + print ''; + } print "\n"; $i++; diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 8fe0c9caee3..5e586cecd99 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -1155,12 +1155,12 @@ function get_left_menu_home($mainmenu, &$newmenu, $usemenuhider = 1, $leftmenu = $newmenu->add('/admin/system/database.php?mainmenu=home&leftmenu=admintools', $langs->trans('InfoDatabase'), 1); $newmenu->add("/admin/system/perf.php?mainmenu=home&leftmenu=admintools", $langs->trans("InfoPerf"), 1); $newmenu->add("/admin/system/security.php?mainmenu=home&leftmenu=admintools", $langs->trans("InfoSecurity"), 1); + $newmenu->add("/admin/tools/listevents.php?mainmenu=home&leftmenu=admintools", $langs->trans("Audit"), 1); + $newmenu->add("/admin/tools/listsessions.php?mainmenu=home&leftmenu=admintools", $langs->trans("Sessions"), 1); $newmenu->add("/admin/tools/dolibarr_export.php?mainmenu=home&leftmenu=admintools", $langs->trans("Backup"), 1); $newmenu->add("/admin/tools/dolibarr_import.php?mainmenu=home&leftmenu=admintools", $langs->trans("Restore"), 1); $newmenu->add("/admin/tools/update.php?mainmenu=home&leftmenu=admintools", $langs->trans("MenuUpgrade"), 1); $newmenu->add("/admin/tools/purge.php?mainmenu=home&leftmenu=admintools", $langs->trans("Purge"), 1); - $newmenu->add("/admin/tools/listevents.php?mainmenu=home&leftmenu=admintools", $langs->trans("Audit"), 1); - $newmenu->add("/admin/tools/listsessions.php?mainmenu=home&leftmenu=admintools", $langs->trans("Sessions"), 1); $newmenu->add('/admin/system/about.php?mainmenu=home&leftmenu=admintools', $langs->trans('ExternalResources'), 1); if (isModEnabled('product') || isModEnabled('service')) { diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index d0696e53c1a..26a12755f6e 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -321,3 +321,5 @@ BatchNotFound=Lot / serial not found for this product StockMovementWillBeRecorded=Stock movement will be recorded StockMovementNotYetRecorded=Stock movement will not be affected by this step WarningThisWIllAlsoDeleteStock=Warning, this will also destroy all quantities in stock in the warehouse +DeleteBatch=Delete lot/serial +ConfirmDeleteBatch=Are you sure you want to delete lot/serial ? \ No newline at end of file diff --git a/htdocs/product/stock/class/productlot.class.php b/htdocs/product/stock/class/productlot.class.php index 14172ae808b..44253d6f25d 100644 --- a/htdocs/product/stock/class/productlot.class.php +++ b/htdocs/product/stock/class/productlot.class.php @@ -102,8 +102,8 @@ class Productlot extends CommonObject */ public $fields = array( 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'noteditable'=>1, 'notnull'=> 1, 'index'=>1, 'position'=>1, 'comment'=>'Id', 'css'=>'left'), - 'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'enabled'=>1, 'visible'=>1, 'position'=>5, 'notnull'=>1, 'index'=>1, 'searchall'=>1), - 'batch' => array('type'=>'varchar(30)', 'label'=>'Batch', 'enabled'=>1, 'visible'=>1, 'notnull'=>0, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'comment'=>'Batch', 'searchall'=>1), + 'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'enabled'=>1, 'visible'=>1, 'position'=>5, 'notnull'=>1, 'index'=>1, 'searchall'=>1, 'picto' => 'product', 'css'=>'maxwidth500 widthcentpercentminusxx', 'csslist'=>'maxwidth150'), + 'batch' => array('type'=>'varchar(30)', 'label'=>'Batch', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'comment'=>'Batch', 'searchall'=>1, 'picto'=>'lot'), 'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20), 'sellby' => array('type'=>'date', 'label'=>'SellByDate', 'enabled'=>'empty($conf->global->PRODUCT_DISABLE_SELLBY)?1:0', 'visible'=>5, 'position'=>60), 'eol_date' => array('type'=>'date', 'label'=>'EndOfLife', 'enabled'=>'empty($conf->global->PRODUCT_ENABLE_TRACEABILITY)?0:1', 'visible'=>5, 'position'=>70), @@ -113,7 +113,7 @@ class Productlot extends CommonObject //'qc_frequency' => array('type'=>'varchar(6)', 'label'=>'QCFrequency', 'enabled'=>'empty($conf->global->PRODUCT_ENABLE_QUALITYCONTROL)?1:0', 'visible'=>5, 'position'=>110), 'eatby' => array('type'=>'date', 'label'=>'EatByDate', 'enabled'=>'empty($conf->global->PRODUCT_DISABLE_EATBY)?1:0', 'visible'=>5, 'position'=>62), 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'visible' => 0, 'position' => 215), - 'last_main_doc' => array('type' => 'varchar(255)', 'label' => 'LastMainDoc', 'enabled' => 1, 'visible' => -1, 'position' => 310), + 'last_main_doc' => array('type' => 'varchar(255)', 'label' => 'LastMainDoc', 'enabled' => 1, 'visible' => -2, 'position' => 310), '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'), @@ -181,7 +181,8 @@ class Productlot extends CommonObject */ public function create(User $user, $notrigger = false) { - global $conf; + global $conf, $langs; + dol_syslog(__METHOD__, LOG_DEBUG); $error = 0; @@ -208,6 +209,11 @@ class Productlot extends CommonObject } // Check parameters + if ($this->batch === '') { + $this->errors[] = $langs->trans("ErrorBadValueForBatch"); + dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR); + return -1; + } // Put here code to add control on parameters values // Insert request @@ -490,6 +496,47 @@ class Productlot extends CommonObject $this->db->begin(); + // Check there is no stock for this lot + $sql = "SELECT pb.rowid FROM ".$this->db->prefix()."product_batch as pb, ".$this->db->prefix()."product_stock as ps"; + $sql .= " WHERE pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($this->batch)."'"; + $sql .= " AND ps.fk_product = ".((int) $this->fk_product); + $sql .= $this->db->plimit(1); + + $resql = $this->db->query($sql); + if ($resql) { + $obj = $this->db->fetch_object($resql); + if ($obj) { + $error++; + $this->errors[] = 'Error Lot is used in stock (ID = '.$obj->rowid.'). Deletion not possible.'; + dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR); + } + } else { + $error++; + $this->errors[] = 'Error '.$this->db->lasterror(); + dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR); + } + + // Check there is no movement for this lot + $sql = "SELECT sm.rowid FROM ".$this->db->prefix()."stock_mouvement as sm"; + $sql .= " WHERE sm.batch = '".$this->db->escape($this->batch)."'"; + $sql .= " AND sm.fk_product = ".((int) $this->fk_product); + $sql .= $this->db->plimit(1); + + $resql = $this->db->query($sql); + if ($resql) { + $obj = $this->db->fetch_object($resql); + if ($obj) { + $error++; + $this->errors[] = 'Error Lot was used in a stock movement (ID '.$obj->rowid.'). Deletion not possible.'; + dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR); + } + } else { + $error++; + $this->errors[] = 'Error '.$this->db->lasterror(); + dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR); + } + + // TODO //if (!$error) { //if (!$notrigger) { // Uncomment this and change PRODUCTLOT to your own tag if you diff --git a/htdocs/product/stock/massstockmove.php b/htdocs/product/stock/massstockmove.php index df0eb013397..1ebd9ca2e5f 100644 --- a/htdocs/product/stock/massstockmove.php +++ b/htdocs/product/stock/massstockmove.php @@ -480,16 +480,21 @@ $titletoadd = $langs->trans("Select"); $buttonrecord = $langs->trans("RecordMovements"); $titletoaddnoent = $langs->transnoentitiesnoconv("Select"); $buttonrecordnoent = $langs->transnoentitiesnoconv("RecordMovements"); -print ''.$langs->trans("SelectProductInAndOutWareHouse", $titletoaddnoent, $buttonrecordnoent).'
'; +print ''.$langs->trans("SelectProductInAndOutWareHouse", $titletoaddnoent, $buttonrecordnoent).''; print '
'; +//print '
'; // Form to upload a file print '
'; print ''; print ''; +if (!empty($conf->dol_optimize_smallscreen)) { + print '
'; +} print ''; -print $langs->trans("or").' '; +print $langs->trans("or"); +print ' '; $importcsv = new ImportCsv($db, 'massstocklist'); print $form->textwithpicto($langs->trans('SelectAStockMovementFileToImport'), $langs->transnoentitiesnoconv("InfoTemplateImport", $importcsv->separator)); print ''; @@ -501,7 +506,7 @@ if ($maxmin > 0) { } print '     '; $out = (empty($conf->global->MAIN_UPLOAD_DOC) ? ' disabled' : ''); -print ''; +print ''; $out = ''; if (!empty($conf->global->MAIN_UPLOAD_DOC)) { $max = $conf->global->MAIN_UPLOAD_DOC; // In Kb diff --git a/htdocs/product/stock/productlot_card.php b/htdocs/product/stock/productlot_card.php index 372af1496cc..58ef6dbb126 100644 --- a/htdocs/product/stock/productlot_card.php +++ b/htdocs/product/stock/productlot_card.php @@ -118,7 +118,7 @@ $upload_dir = $conf->productbatch->multidir_output[$conf->entity]; $permissiontoread = $usercanread; $permissiontoadd = $usercancreate; -//$permissiontodelete = $usercandelete; +$permissiontodelete = $usercandelete; // Security check if (empty($conf->productbatch->enabled)) { @@ -375,8 +375,8 @@ $formfile = new FormFile($db); $title = $langs->trans("ProductLot"); $help_url = ''; -llxHeader('', $title, $help_url); +llxHeader('', $title, $help_url); // Part to create @@ -519,9 +519,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print dol_get_fiche_end(); // Link to other lists - print ''.$langs->trans("ShowCurrentStockOfLot").'
'; + print ''.img_object('', 'stock', 'class="pictofixedwidth"').$langs->trans("ShowCurrentStockOfLot").'
'; print '
'; - print ''.$langs->trans("ShowLogOfMovementIfLot").'
'; + print ''.img_object('', 'movement', 'class="pictofixedwidth"').$langs->trans("ShowLogOfMovementIfLot").'
'; print '
'; @@ -540,9 +540,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea { print ''."\n"; } - - print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $user->rights->stock->supprimer); */ + print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete); } print ''."\n";