From 8caa6131dfe8d0c27631b9455f5794a6101dc474 Mon Sep 17 00:00:00 2001 From: VESSILLER Date: Tue, 30 May 2023 08:37:17 +0200 Subject: [PATCH 001/579] NEW make sell or eat by mandatory in product lot --- htdocs/fourn/commande/dispatch.php | 11 +- htdocs/langs/en_US/productbatch.lang | 3 + htdocs/product/ajax/product_lot.php | 69 ++++ htdocs/product/card.php | 30 +- htdocs/product/class/product.class.php | 60 ++- .../product/stock/class/productlot.class.php | 347 ++++++++++++------ htdocs/product/stock/productlot_card.php | 60 ++- .../product/stock/tpl/stockcorrection.tpl.php | 49 ++- htdocs/reception/class/reception.class.php | 13 + 9 files changed, 515 insertions(+), 127 deletions(-) create mode 100644 htdocs/product/ajax/product_lot.php diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index e262c64e89e..065b01889e7 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -43,6 +43,7 @@ require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; if (isModEnabled('project')) { require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; } +require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php'; // Load translation files required by the page $langs->loadLangs(array("bills", "orders", "sendings", "companies", "deliveries", "products", "stocks", "receptions")); @@ -327,6 +328,8 @@ if ($action == 'dispatch' && $permissiontoreceive) { // We ask to move a qty if (GETPOST($qty) > 0) { + $productId = (int) GETPOST($prod, 'int'); + if (!(GETPOST($ent, 'int') > 0)) { dol_syslog('No dispatch for line '.$key.' as no warehouse was chosen.'); $text = $langs->transnoentities('Warehouse').', '.$langs->transnoentities('Line').' '.($numline).'-'.($reg[1] + 1); @@ -334,7 +337,9 @@ if ($action == 'dispatch' && $permissiontoreceive) { $error++; } - if (!(GETPOST($lot, 'alpha') || $dDLUO || $dDLC)) { + // check sell-by / eat-by date is mandatory + $errorMsgArr = Productlot::checkSellOrEatByMandatoryFromProductIdAndDates($productId, $dDLC, $dDLUO); + if (!(GETPOST($lot, 'alpha')) || !empty($errorMsgArr)) { dol_syslog('No dispatch for line '.$key.' as serial/eat-by/sellby date are not set'); $text = $langs->transnoentities('atleast1batchfield').', '.$langs->transnoentities('Line').' '.($numline).'-'.($reg[1] + 1); setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors'); @@ -342,7 +347,7 @@ if ($action == 'dispatch' && $permissiontoreceive) { } if (!$error) { - $result = $object->dispatchProduct($user, GETPOST($prod, 'int'), GETPOST($qty), GETPOST($ent, 'int'), GETPOST($pu), GETPOST('comment'), $dDLUO, $dDLC, GETPOST($lot, 'alpha'), GETPOST($fk_commandefourndet, 'int'), $notrigger); + $result = $object->dispatchProduct($user, $productId, GETPOST($qty), GETPOST($ent, 'int'), GETPOST($pu), GETPOST('comment'), $dDLUO, $dDLC, GETPOST($lot, 'alpha'), GETPOST($fk_commandefourndet, 'int'), $notrigger); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; @@ -359,7 +364,7 @@ if ($action == 'dispatch' && $permissiontoreceive) { $sql .= ", price = ".price2num(GETPOST($pu), 'MU', 2)." * quantity"; $sql .= ", remise_percent = ".price2num((empty($dto) ? 0 : $dto), 3, 2)."'"; $sql .= " WHERE fk_soc = ".((int) $object->socid); - $sql .= " AND fk_product=".((int) GETPOST($prod, 'int')); + $sql .= " AND fk_product=".($productId); $resql = $db->query($sql); } diff --git a/htdocs/langs/en_US/productbatch.lang b/htdocs/langs/en_US/productbatch.lang index c51d94b8acd..01e869c1fcf 100644 --- a/htdocs/langs/en_US/productbatch.lang +++ b/htdocs/langs/en_US/productbatch.lang @@ -6,6 +6,9 @@ ProductStatusNotOnBatch=No (lot/serial not used) ProductStatusOnBatchShort=Lot ProductStatusOnSerialShort=Serial ProductStatusNotOnBatchShort=No +BatchSellOrEatByMandatoryList=Make %s or %s mandatory +BatchSellOrEatByMandatoryNone=None +BatchSellOrEatByMandatoryAll=%s and %s Batch=Lot/Serial atleast1batchfield=Eat-by date or Sell-by date or Lot/Serial number batch_number=Lot/Serial number diff --git a/htdocs/product/ajax/product_lot.php b/htdocs/product/ajax/product_lot.php new file mode 100644 index 00000000000..bca04d6698e --- /dev/null +++ b/htdocs/product/ajax/product_lot.php @@ -0,0 +1,69 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/takepos/ajax/ajax.php + * \brief Ajax search component for TakePos. It search products of a category. + */ + +if (!defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); +} +if (!defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); +} +if (!defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); +} +if (!defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (!defined('NOBROWSERNOTIF')) { + define('NOBROWSERNOTIF', '1'); +} + +// Load Dolibarr environment +require '../../main.inc.php'; // Load $user and permissions +require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php'; + +$action = GETPOST('action', 'aZ09'); +$productId = GETPOST('product_id', 'int'); +$batch = GETPOST('batch', 'alphanohtml'); + +/* + * View + */ + +top_httphead('application/json'); + +$rows = array(); + +if ($action == 'search' && $batch != '') { + $productLot = new Productlot($db); + $result = $productLot->fetch('', $productId, $batch); + + if ($result > 0 && $productLot->id > 0) { + $rows[] = array( + 'rowid' => $productLot->id, + 'sellby' => ($productLot->sellby ? dol_print_date($productLot->sellby, 'day') : ''), + 'eatby' => ($productLot->eatby ? dol_print_date($productLot->eatby, 'day') : ''), + ); + } +} + +echo json_encode($rows); +exit(); diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 99071758252..92c607240b4 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -537,6 +537,7 @@ if (empty($reshook)) { $object->status = GETPOST('statut'); $object->status_buy = GETPOST('statut_buy'); $object->status_batch = GETPOST('status_batch'); + $object->sell_or_eat_by_mandatory = GETPOST('sell_or_eat_by_mandatory', 'int'); $object->batch_mask = GETPOST('batch_mask'); $object->barcode_type = GETPOST('fk_barcode_type'); @@ -731,6 +732,7 @@ if (empty($reshook)) { $object->status = GETPOST('statut', 'int'); $object->status_buy = GETPOST('statut_buy', 'int'); $object->status_batch = GETPOST('status_batch', 'aZ09'); + $object->sell_or_eat_by_mandatory = GETPOST('sell_or_eat_by_mandatory', 'int'); $object->batch_mask = GETPOST('batch_mask', 'alpha'); $object->fk_default_warehouse = GETPOST('fk_default_warehouse'); $object->fk_default_workstation = GETPOST('fk_default_workstation'); @@ -1217,7 +1219,10 @@ $formcompany = new FormCompany($db); if (isModEnabled('accounting')) { $formaccounting = new FormAccounting($db); } - +$sellOrEatByMandatoryList = null; +if (isModEnabled('productbatch')) { + $sellOrEatByMandatoryList = Product::getSellOrEatByMandatoryList(); +} $title = $langs->trans('ProductServiceCard'); @@ -1417,6 +1422,13 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print ''; } } + + // SellBy / EatBy mandatory list + if (!empty($sellOrEatByMandatoryList)) { + print ''.$langs->trans('BatchSellOrEatByMandatoryList', $langs->trans('SellByDate'), $langs->trans('EatByDate')).''; + print $form->selectarray('sell_or_eat_by_mandatory', $sellOrEatByMandatoryList, GETPOST('sell_or_eat_by_mandatory', 'int')); + print ''; + } } $showbarcode = isModEnabled('barcode'); @@ -1981,6 +1993,18 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print ''; } } + + // SellBy / EatBy mandatory list + if (!empty($sellOrEatByMandatoryList)) { + if (GETPOSTISSET('sell_or_eat_by_mandatory')) { + $sellOrEatByMandatorySelectedId = GETPOST('sell_or_eat_by_mandatory', 'int'); + } else { + $sellOrEatByMandatorySelectedId = $object->sell_or_eat_by_mandatory; + } + print ''.$langs->trans('BatchSellOrEatByMandatoryList', $langs->trans('SellByDate'), $langs->trans('EatByDate')).''; + print $form->selectarray('sell_or_eat_by_mandatory', $sellOrEatByMandatoryList, $sellOrEatByMandatorySelectedId); + print ''; + } } // Barcode @@ -2419,6 +2443,10 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print ''; } } + + print ''.$langs->trans('BatchSellOrEatByMandatoryList', $langs->trans('SellByDate'), $langs->trans('EatByDate')).''; + print $object->getSellOrEatByMandatoryLabel(); + print ''; } if (empty($conf->global->PRODUCT_DISABLE_ACCOUNTING)) { diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index b703340be37..35c2d971214 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -45,6 +45,14 @@ require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; */ class Product extends CommonObject { + /** + * Const sell or eat by mandatory id + */ + const SELL_OR_EAT_BY_MANDATORY_ID_NONE = 0; + const SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY = 1; + const SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY = 2; + const SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT = 3; + /** * @var string ID to identify managed object */ @@ -324,6 +332,13 @@ class Product extends CommonObject */ public $status_batch = 0; + /** + * Make sell-by or eat-by date mandatory + * + * @var int + */ + public $sell_or_eat_by_mandatory = 0; + /** * If allowed, we can edit batch or serial number mask for each product * @@ -783,6 +798,7 @@ class Product extends CommonObject $sql .= ", canvas"; $sql .= ", finished"; $sql .= ", tobatch"; + $sql .= ", sell_or_eat_by_mandatory"; $sql .= ", batch_mask"; $sql .= ", fk_unit"; $sql .= ", mandatory_period"; @@ -812,6 +828,7 @@ class Product extends CommonObject $sql .= ", '".$this->db->escape($this->canvas)."'"; $sql .= ", ".((!isset($this->finished) || $this->finished < 0 || $this->finished == '') ? 'NULL' : (int) $this->finished); $sql .= ", ".((empty($this->status_batch) || $this->status_batch < 0) ? '0' : ((int) $this->status_batch)); + $sql .= ", ".((empty($this->sell_or_eat_by_mandatory) || $this->sell_or_eat_by_mandatory < 0) ? 0 : ((int) $this->sell_or_eat_by_mandatory)); $sql .= ", '".$this->db->escape($this->batch_mask)."'"; $sql .= ", ".($this->fk_unit > 0 ? ((int) $this->fk_unit) : 'NULL'); $sql .= ", '".$this->db->escape($this->mandatory_period)."'"; @@ -1193,6 +1210,7 @@ class Product extends CommonObject $sql .= ", tosell = ".(int) $this->status; $sql .= ", tobuy = ".(int) $this->status_buy; $sql .= ", tobatch = ".((empty($this->status_batch) || $this->status_batch < 0) ? '0' : (int) $this->status_batch); + $sql .= ", sell_or_eat_by_mandatory = ".((empty($this->sell_or_eat_by_mandatory) || $this->sell_or_eat_by_mandatory < 0) ? 0 : (int) $this->sell_or_eat_by_mandatory); $sql .= ", batch_mask = '".$this->db->escape($this->batch_mask)."'"; $sql .= ", finished = ".((!isset($this->finished) || $this->finished < 0 || $this->finished == '') ? "null" : (int) $this->finished); @@ -1526,6 +1544,42 @@ class Product extends CommonObject } } + /** + * Get sell or eat by mandatory list + * + * @return array Sell or eat by mandatory list + */ + public static function getSellOrEatByMandatoryList() + { + global $langs; + + $sellByLabel = $langs->trans('SellByDate'); + $eatByLabel = $langs->trans('EatByDate'); + return array( + self::SELL_OR_EAT_BY_MANDATORY_ID_NONE => $langs->trans('BatchSellOrEatByMandatoryNone'), + self::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY => $sellByLabel, + self::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY => $eatByLabel, + self::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT => $langs->trans('BatchSellOrEatByMandatoryAll', $sellByLabel, $eatByLabel), + ); + } + + /** + * Get sell or eat by mandatory label + * + * @return string Sell or eat by mandatory label + */ + public function getSellOrEatByMandatoryLabel() + { + $sellOrEatByMandatoryLabel = ''; + + $sellOrEatByMandatoryList = self::getSellOrEatByMandatoryList(); + if (isset($sellOrEatByMandatoryList[$this->sell_or_eat_by_mandatory])) { + $sellOrEatByMandatoryLabel = $sellOrEatByMandatoryList[$this->sell_or_eat_by_mandatory]; + } + + return $sellOrEatByMandatoryLabel; + } + /** * Update or add a translation for a product * @@ -2417,7 +2471,7 @@ class Product extends CommonObject } else { $sql .= " p.pmp,"; } - $sql .= " p.datec, p.tms, p.import_key, p.entity, p.desiredstock, p.tobatch, p.batch_mask, p.fk_unit,"; + $sql .= " p.datec, p.tms, p.import_key, p.entity, p.desiredstock, p.tobatch, p.sell_or_eat_by_mandatory, p.batch_mask, p.fk_unit,"; $sql .= " p.fk_price_expression, p.price_autogen, p.model_pdf,"; if ($separatedStock) { $sql .= " SUM(sp.reel) as stock"; @@ -2460,7 +2514,7 @@ class Product extends CommonObject } else { $sql .= " p.pmp,"; } - $sql .= " p.datec, p.tms, p.import_key, p.entity, p.desiredstock, p.tobatch, p.batch_mask, p.fk_unit,"; + $sql .= " p.datec, p.tms, p.import_key, p.entity, p.desiredstock, p.tobatch, p.sell_or_eat_by_mandatory, p.batch_mask, p.fk_unit,"; $sql .= " p.fk_price_expression, p.price_autogen, p.model_pdf"; if (!$separatedStock) { $sql .= ", p.stock"; @@ -2488,6 +2542,7 @@ class Product extends CommonObject $this->status = $obj->tosell; $this->status_buy = $obj->tobuy; $this->status_batch = $obj->tobatch; + $this->sell_or_eat_by_mandatory = $obj->sell_or_eat_by_mandatory; $this->batch_mask = $obj->batch_mask; $this->customcode = $obj->customcode; @@ -6081,6 +6136,7 @@ class Product extends CommonObject $this->status = 1; $this->status_buy = 1; $this->tobatch = 0; + $this->sell_or_eat_by_mandatory = 0; $this->note_private = 'This is a comment (private)'; $this->note_public = 'This is a comment (public)'; $this->date_creation = $now; diff --git a/htdocs/product/stock/class/productlot.class.php b/htdocs/product/stock/class/productlot.class.php index 14172ae808b..87e7d564efc 100644 --- a/htdocs/product/stock/class/productlot.class.php +++ b/htdocs/product/stock/class/productlot.class.php @@ -105,13 +105,13 @@ class Productlot extends CommonObject '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), '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), + 'sellby' => array('type'=>'date', 'label'=>'SellByDate', 'enabled'=>'empty($conf->global->PRODUCT_DISABLE_SELLBY)?1:0', 'visible'=>1, 'notnull'=>0, 'position'=>60), 'eol_date' => array('type'=>'date', 'label'=>'EndOfLife', 'enabled'=>'empty($conf->global->PRODUCT_ENABLE_TRACEABILITY)?0:1', 'visible'=>5, 'position'=>70), 'manufacturing_date' => array('type'=>'date', 'label'=>'ManufacturingDate', 'enabled'=>'empty($conf->global->PRODUCT_ENABLE_TRACEABILITY)?0:1', 'visible'=>5, 'position'=>80), 'scrapping_date' => array('type'=>'date', 'label'=>'DestructionDate', 'enabled'=>'empty($conf->global->PRODUCT_ENABLE_TRACEABILITY)?0:1', 'visible'=>5, 'position'=>90), //'commissionning_date' => array('type'=>'date', 'label'=>'FirstUseDate', 'enabled'=>'empty($conf->global->PRODUCT_ENABLE_TRACEABILITY)?0:1', 'visible'=>5, 'position'=>100), //'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), + 'eatby' => array('type'=>'date', 'label'=>'EatByDate', 'enabled'=>'empty($conf->global->PRODUCT_DISABLE_EATBY)?1:0', 'visible'=>1, 'notnull'=>0, '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), 'datec' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>500), @@ -171,6 +171,126 @@ class Productlot extends CommonObject $this->db = $db; } + /** + * Check sell or eat by date is mandatory + * + * @param string $onlyFieldName [=''] check all fields by default or only one field name ("sellby", "eatby") + * @return int <0 if KO, 0 nothing done, >0 if OK + */ + public function checkSellOrEatByMandatory($onlyFieldName = '') + { + global $conf; + + if (!empty($conf->global->PRODUCT_DISABLE_SELLBY) && !empty($conf->global->PRODUCT_DISABLE_EATBY)) { + return 0; + } + + $errorMsgArr = array(); + if ($this->fk_product > 0) { + $res = $this->fetch_product(); + $product = $this->product; + if ($res <= 0) { + $errorMsgArr[] = $product->errorsToString(); + } + + if (empty($errorMsgArr)) { + $errorMsgArr = self::checkSellOrEatByMandatoryFromProductAndDates($product, $this->sellby, $this->eatby, $onlyFieldName, true); + } + } + + if (!empty($errorMsgArr)) { + $this->errors = array_merge($this->errors, $errorMsgArr); + return -1; + } else { + return 1; + } + } + + /** + * Check sell or eat by date is mandatory from product id and sell-by and eat-by dates + * + * @param int $productId Product id + * @param int $sellBy Sell by date + * @param int $eatBy Eat by date + * @param string $onlyFieldName [=''] check all fields by default or only one field name ("sellby", "eatby") + * @return array|null Array of errors or null if nothing done + */ + public static function checkSellOrEatByMandatoryFromProductIdAndDates($productId, $sellBy, $eatBy, $onlyFieldName = '') + { + global $conf, $db; + + if (!empty($conf->global->PRODUCT_DISABLE_SELLBY) && !empty($conf->global->PRODUCT_DISABLE_EATBY)) { + return null; + } + + $errorMsgArr = array(); + if ($productId > 0) { + $product = new Product($db); + $res = $product->fetch($productId); + if ($res <= 0) { + $errorMsgArr[] = $product->errorsToString(); + } + + if (empty($errorMsgArr)) { + $errorMsgArr = self::checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName, true); + } + } + + return $errorMsgArr; + } + + /** + * Check sell or eat by date is mandatory from product and sell-by and eat-by dates + * + * @param Product $product Product object + * @param int $sellBy Sell by date + * @param int $eatBy Eat by date + * @param string $onlyFieldName [=''] check all fields by default or only one field name ("sellby", "eatby") + * @param bool $alreadyCheckConf [=false] conf hasn't been already checked by default or true not to check conf + * @return array|null Array of errors or null if nothing done + */ + public static function checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName = '', $alreadyCheckConf = false) + { + global $conf, $langs; + + if ($alreadyCheckConf === false && !empty($conf->global->PRODUCT_DISABLE_SELLBY) && !empty($conf->global->PRODUCT_DISABLE_EATBY)) { + return null; + } + + $errorMsgArr = array(); + $checkSellByMandatory = false; + $checkEatByMandatory = false; + + $sellOrEatByMandatoryId = $product->sell_or_eat_by_mandatory; + if (empty($conf->global->PRODUCT_DISABLE_SELLBY) && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY && ($onlyFieldName == '' || $onlyFieldName == 'sellby')) { + $checkSellByMandatory = true; + } elseif (empty($conf->global->PRODUCT_DISABLE_EATBY) && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY && ($onlyFieldName == '' || $onlyFieldName == 'eatby')) { + $checkEatByMandatory = true; + } elseif ($sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT) { + if (empty($conf->global->PRODUCT_DISABLE_SELLBY) && ($onlyFieldName == '' || $onlyFieldName == 'sellby')) { + $checkSellByMandatory = true; + } + if (empty($conf->global->PRODUCT_DISABLE_EATBY) && ($onlyFieldName == '' || $onlyFieldName == 'eatby')) { + $checkEatByMandatory = true; + } + } + + if ($checkSellByMandatory === true) { + if (!isset($sellBy) || dol_strlen($sellBy) == 0) { + // error : sell by is mandatory + $errorMsgArr[] = $langs->trans('ErrorFieldRequired', $langs->transnoentities('SellByDate')); + } + } + if ($checkEatByMandatory === true) { + if (!isset($eatBy) || dol_strlen($eatBy) == 0) { + // error : eat by is mandatory + $errorMsgArr[] = $langs->trans('ErrorFieldRequired', $langs->transnoentities('EatByDate')); + } + } + + return $errorMsgArr; + } + /** * Create object into database * @@ -209,78 +329,86 @@ class Productlot extends CommonObject // Check parameters // Put here code to add control on parameters values - - // Insert request - $sql = 'INSERT INTO '.$this->db->prefix().$this->table_element.'('; - $sql .= 'entity,'; - $sql .= 'fk_product,'; - $sql .= 'batch,'; - $sql .= 'eatby,'; - $sql .= 'sellby,'; - $sql .= 'eol_date,'; - $sql .= 'manufacturing_date,'; - $sql .= 'scrapping_date,'; - //$sql .= 'commissionning_date,'; - //$sql .= 'qc_frequency,'; - $sql .= 'datec,'; - $sql .= 'fk_user_creat,'; - $sql .= 'fk_user_modif,'; - $sql .= 'import_key'; - $sql .= ') VALUES ('; - $sql .= ' '.(!isset($this->entity) ? $conf->entity : $this->entity).','; - $sql .= ' '.(!isset($this->fk_product) ? 'NULL' : $this->fk_product).','; - $sql .= ' '.(!isset($this->batch) ? 'NULL' : "'".$this->db->escape($this->batch)."'").','; - $sql .= ' '.(!isset($this->eatby) || dol_strlen($this->eatby) == 0 ? 'NULL' : "'".$this->db->idate($this->eatby)."'").','; - $sql .= ' '.(!isset($this->sellby) || dol_strlen($this->sellby) == 0 ? 'NULL' : "'".$this->db->idate($this->sellby)."'").','; - $sql .= ' '.(!isset($this->eol_date) || dol_strlen($this->eol_date) == 0 ? 'NULL' : "'".$this->db->idate($this->eol_date)."'").','; - $sql .= ' '.(!isset($this->manufacturing_date) || dol_strlen($this->manufacturing_date) == 0 ? 'NULL' : "'".$this->db->idate($this->manufacturing_date)."'").','; - $sql .= ' '.(!isset($this->scrapping_date) || dol_strlen($this->scrapping_date) == 0 ? 'NULL' : "'".$this->db->idate($this->scrapping_date)."'").','; - //$sql .= ' '.(!isset($this->commissionning_date) || dol_strlen($this->commissionning_date) == 0 ? 'NULL' : "'".$this->db->idate($this->commissionning_date)."'").','; - //$sql .= ' '.(!isset($this->qc_frequency) ? 'NULL' : $this->qc_frequency).','; - $sql .= ' '."'".$this->db->idate(dol_now())."'".','; - $sql .= ' '.(!isset($this->fk_user_creat) ? 'NULL' : $this->fk_user_creat).','; - $sql .= ' '.(!isset($this->fk_user_modif) ? 'NULL' : $this->fk_user_modif).','; - $sql .= ' '.(!isset($this->import_key) ? 'NULL' : $this->import_key); - $sql .= ')'; - - $this->db->begin(); - - $resql = $this->db->query($sql); - if (!$resql) { + $res = $this->checkSellOrEatByMandatory(); + if ($res < 0) { $error++; - $this->errors[] = 'Error '.$this->db->lasterror(); - dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR); } if (!$error) { - $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); + // Insert request + $sql = 'INSERT INTO ' . $this->db->prefix() . $this->table_element . '('; + $sql .= 'entity,'; + $sql .= 'fk_product,'; + $sql .= 'batch,'; + $sql .= 'eatby,'; + $sql .= 'sellby,'; + $sql .= 'eol_date,'; + $sql .= 'manufacturing_date,'; + $sql .= 'scrapping_date,'; + //$sql .= 'commissionning_date,'; + //$sql .= 'qc_frequency,'; + $sql .= 'datec,'; + $sql .= 'fk_user_creat,'; + $sql .= 'fk_user_modif,'; + $sql .= 'import_key'; + $sql .= ') VALUES ('; + $sql .= ' ' . (!isset($this->entity) ? $conf->entity : $this->entity) . ','; + $sql .= ' ' . (!isset($this->fk_product) ? 'NULL' : $this->fk_product) . ','; + $sql .= ' ' . (!isset($this->batch) ? 'NULL' : "'" . $this->db->escape($this->batch) . "'") . ','; + $sql .= ' ' . (!isset($this->eatby) || dol_strlen($this->eatby) == 0 ? 'NULL' : "'" . $this->db->idate($this->eatby) . "'") . ','; + $sql .= ' ' . (!isset($this->sellby) || dol_strlen($this->sellby) == 0 ? 'NULL' : "'" . $this->db->idate($this->sellby) . "'") . ','; + $sql .= ' ' . (!isset($this->eol_date) || dol_strlen($this->eol_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->eol_date) . "'") . ','; + $sql .= ' ' . (!isset($this->manufacturing_date) || dol_strlen($this->manufacturing_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->manufacturing_date) . "'") . ','; + $sql .= ' ' . (!isset($this->scrapping_date) || dol_strlen($this->scrapping_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->scrapping_date) . "'") . ','; + //$sql .= ' '.(!isset($this->commissionning_date) || dol_strlen($this->commissionning_date) == 0 ? 'NULL' : "'".$this->db->idate($this->commissionning_date)."'").','; + //$sql .= ' '.(!isset($this->qc_frequency) ? 'NULL' : $this->qc_frequency).','; + $sql .= ' ' . "'" . $this->db->idate(dol_now()) . "'" . ','; + $sql .= ' ' . (!isset($this->fk_user_creat) ? 'NULL' : $this->fk_user_creat) . ','; + $sql .= ' ' . (!isset($this->fk_user_modif) ? 'NULL' : $this->fk_user_modif) . ','; + $sql .= ' ' . (!isset($this->import_key) ? 'NULL' : $this->import_key); + $sql .= ')'; + + $this->db->begin(); + + $resql = $this->db->query($sql); + if (!$resql) { + $error++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + } - // Actions on extra fields if (!$error) { - $result = $this->insertExtraFields(); - if ($result < 0) { - $error++; + $this->id = $this->db->last_insert_id($this->db->prefix() . $this->table_element); + + // Actions on extra fields + if (!$error) { + $result = $this->insertExtraFields(); + if ($result < 0) { + $error++; + } + } + + if (!$error && !$notrigger) { + // Call triggers + $result = $this->call_trigger('PRODUCTLOT_CREATE', $user); + if ($result < 0) { + $error++; + } + // End call triggers } } - if (!$error && !$notrigger) { - // Call triggers - $result = $this->call_trigger('PRODUCTLOT_CREATE', $user); - if ($result < 0) { - $error++; - } - // End call triggers + // Commit or rollback + if ($error) { + $this->db->rollback(); + } else { + $this->db->commit(); } } - // Commit or rollback if ($error) { - $this->db->rollback(); - + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); return -1 * $error; } else { - $this->db->commit(); - return $this->id; } } @@ -412,64 +540,75 @@ class Productlot extends CommonObject $this->import_key = trim($this->import_key); } + // Check parameters + // Put here code to add a control on parameters values + $res = $this->checkSellOrEatByMandatory(); + if ($res < 0) { + $error++; + } + // $this->oldcopy should have been set by the caller of update (here properties were already modified) if (empty($this->oldcopy)) { $this->oldcopy = dol_clone($this); } - // Update request - $sql = 'UPDATE '.$this->db->prefix().$this->table_element.' SET'; - $sql .= ' entity = '.(isset($this->entity) ? $this->entity : "null").','; - $sql .= ' fk_product = '.(isset($this->fk_product) ? $this->fk_product : "null").','; - $sql .= ' batch = '.(isset($this->batch) ? "'".$this->db->escape($this->batch)."'" : "null").','; - $sql .= ' eatby = '.(!isset($this->eatby) || dol_strlen($this->eatby) != 0 ? "'".$this->db->idate($this->eatby)."'" : 'null').','; - $sql .= ' sellby = '.(!isset($this->sellby) || dol_strlen($this->sellby) != 0 ? "'".$this->db->idate($this->sellby)."'" : 'null').','; - $sql .= ' eol_date = '.(!isset($this->eol_date) || dol_strlen($this->eol_date) != 0 ? "'".$this->db->idate($this->eol_date)."'" : 'null').','; - $sql .= ' manufacturing_date = '.(!isset($this->manufacturing_date) || dol_strlen($this->manufacturing_date) != 0 ? "'".$this->db->idate($this->manufacturing_date)."'" : 'null').','; - $sql .= ' scrapping_date = '.(!isset($this->scrapping_date) || dol_strlen($this->scrapping_date) != 0 ? "'".$this->db->idate($this->scrapping_date)."'" : 'null').','; - //$sql .= ' commissionning_date = '.(!isset($this->first_use_date) || dol_strlen($this->first_use_date) != 0 ? "'".$this->db->idate($this->first_use_date)."'" : 'null').','; - //$sql .= ' qc_frequency = '.(!isset($this->qc_frequency) || dol_strlen($this->qc_frequency) != 0 ? "'".$this->db->escape($this->qc_frequency)."'" : 'null').','; - $sql .= ' datec = '.(!isset($this->datec) || dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').','; - $sql .= ' tms = '.(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : "'".$this->db->idate(dol_now())."'").','; - $sql .= ' fk_user_creat = '.(isset($this->fk_user_creat) ? $this->fk_user_creat : "null").','; - $sql .= ' fk_user_modif = '.(isset($this->fk_user_modif) ? $this->fk_user_modif : "null").','; - $sql .= ' import_key = '.(isset($this->import_key) ? $this->import_key : "null"); - $sql .= ' WHERE rowid='.((int) $this->id); - - $this->db->begin(); - - $resql = $this->db->query($sql); - if (!$resql) { - $error++; - $this->errors[] = 'Error '.$this->db->lasterror(); - dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR); - } - - // Actions on extra fields if (!$error) { - $result = $this->insertExtraFields(); - if ($result < 0) { + // Update request + $sql = 'UPDATE ' . $this->db->prefix() . $this->table_element . ' SET'; + $sql .= ' entity = ' . (isset($this->entity) ? $this->entity : "null") . ','; + $sql .= ' fk_product = ' . (isset($this->fk_product) ? $this->fk_product : "null") . ','; + $sql .= ' batch = ' . (isset($this->batch) ? "'" . $this->db->escape($this->batch) . "'" : "null") . ','; + $sql .= ' eatby = ' . (!isset($this->eatby) || dol_strlen($this->eatby) != 0 ? "'" . $this->db->idate($this->eatby) . "'" : 'null') . ','; + $sql .= ' sellby = ' . (!isset($this->sellby) || dol_strlen($this->sellby) != 0 ? "'" . $this->db->idate($this->sellby) . "'" : 'null') . ','; + $sql .= ' eol_date = ' . (!isset($this->eol_date) || dol_strlen($this->eol_date) != 0 ? "'" . $this->db->idate($this->eol_date) . "'" : 'null') . ','; + $sql .= ' manufacturing_date = ' . (!isset($this->manufacturing_date) || dol_strlen($this->manufacturing_date) != 0 ? "'" . $this->db->idate($this->manufacturing_date) . "'" : 'null') . ','; + $sql .= ' scrapping_date = ' . (!isset($this->scrapping_date) || dol_strlen($this->scrapping_date) != 0 ? "'" . $this->db->idate($this->scrapping_date) . "'" : 'null') . ','; + //$sql .= ' commissionning_date = '.(!isset($this->first_use_date) || dol_strlen($this->first_use_date) != 0 ? "'".$this->db->idate($this->first_use_date)."'" : 'null').','; + //$sql .= ' qc_frequency = '.(!isset($this->qc_frequency) || dol_strlen($this->qc_frequency) != 0 ? "'".$this->db->escape($this->qc_frequency)."'" : 'null').','; + $sql .= ' datec = ' . (!isset($this->datec) || dol_strlen($this->datec) != 0 ? "'" . $this->db->idate($this->datec) . "'" : 'null') . ','; + $sql .= ' tms = ' . (dol_strlen($this->tms) != 0 ? "'" . $this->db->idate($this->tms) . "'" : "'" . $this->db->idate(dol_now()) . "'") . ','; + $sql .= ' fk_user_creat = ' . (isset($this->fk_user_creat) ? $this->fk_user_creat : "null") . ','; + $sql .= ' fk_user_modif = ' . (isset($this->fk_user_modif) ? $this->fk_user_modif : "null") . ','; + $sql .= ' import_key = ' . (isset($this->import_key) ? $this->import_key : "null"); + $sql .= ' WHERE rowid=' . ((int)$this->id); + + $this->db->begin(); + + $resql = $this->db->query($sql); + if (!$resql) { $error++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + } + + // Actions on extra fields + if (!$error) { + $result = $this->insertExtraFields(); + if ($result < 0) { + $error++; + } + } + + if (!$error && !$notrigger) { + // Call triggers + $result = $this->call_trigger('PRODUCTLOT_MODIFY', $user); + if ($result < 0) { + $error++; + } + // End call triggers + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + } else { + $this->db->commit(); } } - if (!$error && !$notrigger) { - // Call triggers - $result = $this->call_trigger('PRODUCTLOT_MODIFY', $user); - if ($result < 0) { - $error++; - } - // End call triggers - } - - // Commit or rollback if ($error) { - $this->db->rollback(); - + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); return -1 * $error; } else { - $this->db->commit(); - return 1; } } diff --git a/htdocs/product/stock/productlot_card.php b/htdocs/product/stock/productlot_card.php index 0e00476455e..aaaf512b2f0 100644 --- a/htdocs/product/stock/productlot_card.php +++ b/htdocs/product/stock/productlot_card.php @@ -150,10 +150,24 @@ if (empty($reshook)) { if ($action == 'seteatby' && $user->rights->stock->creer && ! GETPOST('cancel', 'alpha')) { $newvalue = dol_mktime(12, 0, 0, GETPOST('eatbymonth', 'int'), GETPOST('eatbyday', 'int'), GETPOST('eatbyyear', 'int')); - $result = $object->setValueFrom('eatby', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY'); - if ($result < 0) { - setEventMessages($object->error, null, 'errors'); - $action == 'editeatby'; + + // check parameters + $object->eatby = $newvalue; + $res = $object->checkSellOrEatByMandatory('eatby'); + if ($res < 0) { + $error++; + } + + if (!$error) { + $result = $object->setValueFrom('eatby', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY'); + if ($result < 0) { + $error++; + } + } + + if ($error) { + setEventMessages($object->error, $object->errors, 'errors'); + $action = 'editeatby'; } else { $action = 'view'; } @@ -161,10 +175,24 @@ if (empty($reshook)) { if ($action == 'setsellby' && $user->rights->stock->creer && ! GETPOST('cancel', 'alpha')) { $newvalue = dol_mktime(12, 0, 0, GETPOST('sellbymonth', 'int'), GETPOST('sellbyday', 'int'), GETPOST('sellbyyear', 'int')); - $result = $object->setValueFrom('sellby', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY'); - if ($result < 0) { - setEventMessages($object->error, null, 'errors'); - $action == 'editsellby'; + + // check parameters + $object->sellby = $newvalue; + $res = $object->checkSellOrEatByMandatory('sellby'); + if ($res < 0) { + $error++; + } + + if (!$error) { + $result = $object->setValueFrom('sellby', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY'); + if ($result < 0) { + $error++; + } + } + + if ($error) { + setEventMessages($object->error, $object->errors, 'errors'); + $action = 'editsellby'; } else { $action = 'view'; } @@ -377,7 +405,17 @@ $title = $langs->trans("ProductLot"); $help_url = ''; llxHeader('', $title, $help_url); - +$res = $object->fetch_product(); +if ($res > 0 && $object->product) { + if ($object->product->sell_or_eat_by_mandatory == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY) { + $object->fields['sellby']['notnull'] = 1; + } elseif ($object->product->sell_or_eat_by_mandatory == Product::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY) { + $object->fields['eatby']['notnull'] = 1; + } elseif ($object->product->sell_or_eat_by_mandatory == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT) { + $object->fields['sellby']['notnull'] = 1; + $object->fields['eatby']['notnull'] = 1; + } +} // Part to create if ($action == 'create') { @@ -468,7 +506,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Sell by if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) { print ''; - print $form->editfieldkey($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker'); + print $form->editfieldkey($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker', '', $object->fields['sellby']['notnull']); print ''; print $form->editfieldval($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker', '', null, null, '', 1, '', 'id', 'auto', array(), $action); print ''; @@ -478,7 +516,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Eat by if (empty($conf->global->PRODUCT_DISABLE_EATBY)) { print ''; - print $form->editfieldkey($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker'); + print $form->editfieldkey($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker', '', $object->fields['eatby']['notnull']); print ''; print $form->editfieldval($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker', '', null, null, '', 1, '', 'id', 'auto', array(), $action); print ''; diff --git a/htdocs/product/stock/tpl/stockcorrection.tpl.php b/htdocs/product/stock/tpl/stockcorrection.tpl.php index 793c0dcd1e4..8fdb18c5d4e 100644 --- a/htdocs/product/stock/tpl/stockcorrection.tpl.php +++ b/htdocs/product/stock/tpl/stockcorrection.tpl.php @@ -29,6 +29,10 @@ if (empty($conf) || !is_object($conf)) { element == 'product') { $productref = $object->ref; @@ -54,6 +58,19 @@ if ($pdluoid > 0) { } } +$sellByCss = ''; +$eatByCss = ''; +if ($object->sell_or_eat_by_mandatory == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY) { + $sellByCss = 'fieldrequired'; +} elseif ($object->sell_or_eat_by_mandatory == Product::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY) { + $eatByCss = 'fieldrequired'; +} elseif ($object->sell_or_eat_by_mandatory == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT) { + $sellByCss = 'fieldrequired'; + $eatByCss = 'fieldrequired'; +} + +$disableSellBy = getDolGlobalInt('PRODUCT_DISABLE_SELLBY'); +$disableEatBy = getDolGlobalInt('PRODUCT_DISABLE_EATBY'); print ''; + });'; + +if ($disableSellBy == 0 || $disableEatBy == 0) { + print ' + var disableSellBy = '.dol_escape_js($disableSellBy).'; + var disableEatBy = '.dol_escape_js($disableSellBy).'; + jQuery("#batch_number").change(function(event) { + var batch = jQuery(this).val(); + jQuery.getJSON("'.DOL_URL_ROOT.'/product/ajax/product_lot.php?action=search&token='.newToken().'&product_id='.$id.'&batch="+batch, function(data) { + if (data.length > 0) { + var productLot = data[0]; + if (disableSellBy == 0) { + jQuery("#sellby").val(productLot.sellby); + } + if (disableEatBy == 0) { + jQuery("#eatby").val(productLot.eatby); + } + } + }); + });'; +} +print '});'; +print ''; print load_fiche_titre($langs->trans("StockCorrection"), '', 'generic'); @@ -155,21 +192,21 @@ if (ismodEnabled('productbatch') && print ''; print ''; } else { - print img_picto('', 'barcode', 'class="pictofixedwidth"').''; + print img_picto('', 'barcode', 'class="pictofixedwidth"').''; } print ''; print ''; print ''; if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) { - print ''.$langs->trans("SellByDate").''; + print ''.$langs->trans("SellByDate").''; $sellbyselected = dol_mktime(0, 0, 0, GETPOST('sellbymonth'), GETPOST('sellbyday'), GETPOST('sellbyyear')); // If form was opened for a specific pdluoid, field is disabled print $form->selectDate(($pdluo->id > 0 ? $pdluo->sellby : $sellbyselected), 'sellby', '', '', 1, "", 1, 0, ($pdluoid > 0 ? 1 : 0)); print ''; } if (empty($conf->global->PRODUCT_DISABLE_EATBY)) { - print ''.$langs->trans("EatByDate").''; + print ''.$langs->trans("EatByDate").''; $eatbyselected = dol_mktime(0, 0, 0, GETPOST('eatbymonth'), GETPOST('eatbyday'), GETPOST('eatbyyear')); // If form was opened for a specific pdluoid, field is disabled print $form->selectDate(($pdluo->id > 0 ? $pdluo->eatby : $eatbyselected), 'eatby', '', '', 1, "", 1, 0, ($pdluoid > 0 ? 1 : 0)); diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index d60c286ecf6..4b414439e05 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -843,6 +843,19 @@ class Reception extends CommonObject $this->error = $langs->trans('ErrorProductDoesNotNeedBatchNumber', $product->ref); return -1; } + + // check sell-by / eat-by date is mandatory + $errorMsgArr = Productlot::checkSellOrEatByMandatoryFromProductAndDates($product, $sellby, $eatby); + if (!empty($errorMsgArr)) { + $errorMessage = '' . $product->ref . ' : '; + $errorMessage .= '
    '; + foreach ($errorMsgArr as $errorMsg) { + $errorMessage .= '
  • ' . $errorMsg . '
  • '; + } + $errorMessage .= '
'; + $this->error = $errorMessage; + return -1; + } } unset($product); From f41205c0c8a031fe255742fe6b8d71352cf20bf6 Mon Sep 17 00:00:00 2001 From: VESSILLER Date: Tue, 30 May 2023 08:56:01 +0200 Subject: [PATCH 002/579] FIX stickler-ci --- htdocs/product/stock/class/productlot.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/stock/class/productlot.class.php b/htdocs/product/stock/class/productlot.class.php index 87e7d564efc..9908d6ba473 100644 --- a/htdocs/product/stock/class/productlot.class.php +++ b/htdocs/product/stock/class/productlot.class.php @@ -570,7 +570,7 @@ class Productlot extends CommonObject $sql .= ' fk_user_creat = ' . (isset($this->fk_user_creat) ? $this->fk_user_creat : "null") . ','; $sql .= ' fk_user_modif = ' . (isset($this->fk_user_modif) ? $this->fk_user_modif : "null") . ','; $sql .= ' import_key = ' . (isset($this->import_key) ? $this->import_key : "null"); - $sql .= ' WHERE rowid=' . ((int)$this->id); + $sql .= ' WHERE rowid=' . ((int) $this->id); $this->db->begin(); From fd40dcb87458ceb69b0c60cd3d556f717717ccc8 Mon Sep 17 00:00:00 2001 From: VESSILLER Date: Tue, 30 May 2023 09:17:26 +0200 Subject: [PATCH 003/579] FIX reload stickler-ci From b2ae991501c090c5847133cbc06725e504a64b7c Mon Sep 17 00:00:00 2001 From: atm-thibaultf Date: Wed, 30 Aug 2023 17:08:57 +0200 Subject: [PATCH 004/579] NEW_hide_external_user_in_combobox --- htdocs/admin/user.php | 25 +++++++++++++++++++ .../html.formadvtargetemailing.class.php | 3 +++ htdocs/core/class/html.form.class.php | 3 +++ htdocs/core/class/html.formother.class.php | 6 +++++ htdocs/langs/en_US/admin.lang | 1 + htdocs/langs/fr_FR/admin.lang | 1 + test.php | 3 +++ 7 files changed, 42 insertions(+) create mode 100644 test.php diff --git a/htdocs/admin/user.php b/htdocs/admin/user.php index 20eb7a0c0b2..b6c0bcebbfd 100644 --- a/htdocs/admin/user.php +++ b/htdocs/admin/user.php @@ -116,6 +116,15 @@ if ($action == 'set_default') { } else { dol_print_error($db); } +} elseif ($action == 'sethideexternaluser') { + //Set hide external user into combox or select +$status = GETPOST('status', 'alpha'); + +if (dolibarr_set_const($db, "USER_HIDE_EXTERNAL_IN_COMBOBOX", $status, 'chaine', 0, '', $conf->entity) > 0) { + header("Location: ".$_SERVER["PHP_SELF"]); + exit; +} else { + dol_print_error($db); } @@ -184,6 +193,22 @@ if ($conf->use_javascript_ajax) { } print ''; +print ''; +print ''.$langs->trans("UserHideExternal").''; +print ' '; + +print ''; +if ($conf->use_javascript_ajax) { + print ajax_constantonoff('USER_HIDE_EXTERNAL_IN_COMBOBOX'); +} else { + if (empty($conf->global->USER_HIDE_EXTERNAL_IN_COMBOBOX)) { + print ''.img_picto($langs->trans("Disabled"), 'off').''; + } else { + print ''.img_picto($langs->trans("Enabled"), 'on').''; + } +} +print ''; + print ''; print ''; diff --git a/htdocs/comm/mailing/class/html.formadvtargetemailing.class.php b/htdocs/comm/mailing/class/html.formadvtargetemailing.class.php index 50169438baa..00d31aac368 100644 --- a/htdocs/comm/mailing/class/html.formadvtargetemailing.class.php +++ b/htdocs/comm/mailing/class/html.formadvtargetemailing.class.php @@ -171,6 +171,9 @@ class FormAdvTargetEmailing extends Form if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX)) { $sql_usr .= " AND u2.statut<>0 "; } + if (!empty($conf->global->USER_HIDE_EXTERNAL_IN_COMBOBOX)) { + $sql_usr .= " AND u2.employee<>0 "; + } $sql_usr .= " ORDER BY name ASC"; // print $sql_usr;exit; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 8f11af63f4a..117a56d42cd 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2050,6 +2050,9 @@ class Form if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX) || $notdisabled) { $sql .= " AND u.statut <> 0"; } + if (!empty($conf->global->USER_HIDE_EXTERNAL_IN_COMBOBOX) || $notdisabled) { + $sql .= " AND u.employee <> 0"; + } if (!empty($morefilter)) { $sql .= " " . $morefilter; } diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index cce5cf7819d..b87ecc60f71 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -512,6 +512,12 @@ class FormOther if (!empty($user->socid)) { $sql_usr .= " AND u.fk_soc = ".((int) $user->socid); } + if (!empty($conf->global->USER_HIDE_EXTERNAL_IN_COMBOBOX)) { + $sql_usr .= " AND u.employee <> 0"; + } + if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX)) { + $sql_usr .= " AND u.statut <> 0"; + } //Add hook to filter on user (for exemple on usergroup define in custom modules) if (!empty($reshook)) { diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 9c5d62fc38b..f809db92a95 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1416,6 +1416,7 @@ DisableForgetPasswordLinkOnLogonPage=Do not show the "Password Forgotten" link o UsersSetup=Users module setup UserMailRequired=Email required to create a new user UserHideInactive=Hide inactive users from all combo lists of users (Not recommended: this may means you won't be able to filter or search on old users on some pages) +UserHideExternal=Hide external users from all combo lists of users (Not recommended: this may means you won't be able to filter or search on external users on some pages) UsersDocModules=Document templates for documents generated from user record GroupsDocModules=Document templates for documents generated from a group record ##### HRM setup ##### diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 4fc55bfd30b..33a0314f83a 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -1413,6 +1413,7 @@ DisableForgetPasswordLinkOnLogonPage=Cacher le lien "Mot de passe oublié" sur l UsersSetup=Configuration du module utilisateurs UserMailRequired=Email requis pour créer un nouvel utilisateur UserHideInactive=Masquer les utilisateurs inactifs sur toutes les listes déroulantes d'utilisateurs (non recommandé: cela peut signifier que vous ne pourrez pas filtrer ou rechercher les anciens utilisateurs sur certaines pages) +UserHideExternal=Masquer les utilisateurs externes (non salariés) sur toutes les listes déroulantes d'utilisateurs (non recommandé: cela peut signifier que vous ne pourrez pas filtrer ou rechercher les utilisateurs externes sur certaines pages) UsersDocModules=Modèles de documents pour les documents générés à partir de la fiche utilisateur GroupsDocModules=Modèles de documents pour les documents générés à partir de la fiche d'un groupe ##### HRM setup ##### diff --git a/test.php b/test.php new file mode 100644 index 00000000000..bacfe6c3edc --- /dev/null +++ b/test.php @@ -0,0 +1,3 @@ + From 81038fbfe744e5298dc471d92d0bfed3fdbec7f7 Mon Sep 17 00:00:00 2001 From: atm-thibaultf Date: Wed, 30 Aug 2023 17:30:40 +0200 Subject: [PATCH 005/579] Clean branch --- htdocs/admin/user.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/htdocs/admin/user.php b/htdocs/admin/user.php index b6c0bcebbfd..16592f09dff 100644 --- a/htdocs/admin/user.php +++ b/htdocs/admin/user.php @@ -118,13 +118,13 @@ if ($action == 'set_default') { } } elseif ($action == 'sethideexternaluser') { //Set hide external user into combox or select -$status = GETPOST('status', 'alpha'); - -if (dolibarr_set_const($db, "USER_HIDE_EXTERNAL_IN_COMBOBOX", $status, 'chaine', 0, '', $conf->entity) > 0) { - header("Location: ".$_SERVER["PHP_SELF"]); - exit; -} else { - dol_print_error($db); + $status = GETPOST('status', 'alpha'); + if (dolibarr_set_const($db, "USER_HIDE_EXTERNAL_IN_COMBOBOX", $status, 'chaine', 0, '', $conf->entity) > 0) { + header("Location: " . $_SERVER["PHP_SELF"]); + exit; + } else { + dol_print_error($db); + } } From 3fc49660da156717074d7a27482e557f6cbcf560 Mon Sep 17 00:00:00 2001 From: Thibault Fiacre <57494317+atm-thibaultf@users.noreply.github.com> Date: Wed, 30 Aug 2023 17:36:27 +0200 Subject: [PATCH 006/579] Delete test.php --- test.php | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 test.php diff --git a/test.php b/test.php deleted file mode 100644 index bacfe6c3edc..00000000000 --- a/test.php +++ /dev/null @@ -1,3 +0,0 @@ - From 199e5c1a467ed500b38d5f14563857806cc67877 Mon Sep 17 00:00:00 2001 From: atm-thibaultf Date: Tue, 5 Sep 2023 14:34:21 +0200 Subject: [PATCH 007/579] NEW hide external and non employee users in combobox --- htdocs/admin/user.php | 30 +++++++++++++++++++ .../html.formadvtargetemailing.class.php | 5 +++- htdocs/core/class/html.form.class.php | 5 +++- htdocs/core/class/html.formother.class.php | 5 +++- htdocs/langs/en_US/admin.lang | 3 +- htdocs/langs/fr_FR/admin.lang | 3 +- 6 files changed, 46 insertions(+), 5 deletions(-) diff --git a/htdocs/admin/user.php b/htdocs/admin/user.php index 16592f09dff..fa116202a1c 100644 --- a/htdocs/admin/user.php +++ b/htdocs/admin/user.php @@ -125,6 +125,16 @@ if ($action == 'set_default') { } else { dol_print_error($db); } +} elseif ($action == 'sethidenonemployeeuser') { + //Set hide non employee user into combox or select + $status = GETPOST('status', 'alpha'); + + if (dolibarr_set_const($db, "USER_HIDE_NONEMPLOYEE_IN_COMBOBOX", $status, 'chaine', 0, '', $conf->entity) > 0) { + header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } else { + dol_print_error($db); + } } @@ -193,6 +203,26 @@ if ($conf->use_javascript_ajax) { } print ''; +// user hide non employee + +print ''; +print ''.$langs->trans("UserHideNonEmployee").''; +print ' '; + +print ''; +if ($conf->use_javascript_ajax) { + print ajax_constantonoff('USER_HIDE_NONEMPLOYEE_IN_COMBOBOX'); +} else { + if (empty($conf->global->USER_HIDE_NONEMPLOYEE_IN_COMBOBOX)) { + print ''.img_picto($langs->trans("Disabled"), 'off').''; + } else { + print ''.img_picto($langs->trans("Enabled"), 'on').''; + } +} +print ''; + +// user hide external + print ''; print ''.$langs->trans("UserHideExternal").''; print ' '; diff --git a/htdocs/comm/mailing/class/html.formadvtargetemailing.class.php b/htdocs/comm/mailing/class/html.formadvtargetemailing.class.php index 00d31aac368..ab50676106d 100644 --- a/htdocs/comm/mailing/class/html.formadvtargetemailing.class.php +++ b/htdocs/comm/mailing/class/html.formadvtargetemailing.class.php @@ -171,9 +171,12 @@ class FormAdvTargetEmailing extends Form if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX)) { $sql_usr .= " AND u2.statut<>0 "; } - if (!empty($conf->global->USER_HIDE_EXTERNAL_IN_COMBOBOX)) { + if (!empty($conf->global->USER_HIDE_NONEMPLOYEE_IN_COMBOBOX)) { $sql_usr .= " AND u2.employee<>0 "; } + if (!empty($conf->global->USER_HIDE_EXTERNAL_IN_COMBOBOX)) { + $sql_usr .= " AND u2.fk_soc IS NULL "; + } $sql_usr .= " ORDER BY name ASC"; // print $sql_usr;exit; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 8f17a927c2c..e7f8a24b91f 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2082,9 +2082,12 @@ class Form if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX) || $notdisabled) { $sql .= " AND u.statut <> 0"; } - if (!empty($conf->global->USER_HIDE_EXTERNAL_IN_COMBOBOX) || $notdisabled) { + if (!empty($conf->global->USER_HIDE_NONEMPLOYEE_IN_COMBOBOX) || $notdisabled) { $sql .= " AND u.employee <> 0"; } + if (!empty($conf->global->USER_HIDE_EXTERNAL_IN_COMBOBOX) || $notdisabled) { + $sql .= " AND u.fk_soc IS NULL"; + } if (!empty($morefilter)) { $sql .= " " . $morefilter; } diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 8ebb9538530..c6cfa14cf15 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -513,9 +513,12 @@ class FormOther if (!empty($user->socid)) { $sql_usr .= " AND u.fk_soc = ".((int) $user->socid); } - if (!empty($conf->global->USER_HIDE_EXTERNAL_IN_COMBOBOX)) { + if (!empty($conf->global->USER_HIDE_NONEMPLOYEE_IN_COMBOBOX)) { $sql_usr .= " AND u.employee <> 0"; } + if (!empty($conf->global->USER_HIDE_EXTERNAL_IN_COMBOBOX)) { + $sql_usr .= " AND u.fk_soc IS NULL"; + } if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX)) { $sql_usr .= " AND u.statut <> 0"; } diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 0082c1a4e86..2e169294fde 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1419,7 +1419,8 @@ DisableForgetPasswordLinkOnLogonPage=Do not show the "Password Forgotten" link o UsersSetup=Users module setup UserMailRequired=Email required to create a new user UserHideInactive=Hide inactive users from all combo lists of users (Not recommended: this may means you won't be able to filter or search on old users on some pages) -UserHideExternal=Hide external users from all combo lists of users (Not recommended: this may means you won't be able to filter or search on external users on some pages) +UserHideExternal=Hide external users (not linked to a third party) from all combo lists of users (Not recommended: this may means you won't be able to filter or search on external users on some pages) +UserHideNonEmployee=Hide non employee users from all combo lists of users (Not recommended: this may means you won't be able to filter or search on non employee users on some pages) UsersDocModules=Document templates for documents generated from user record GroupsDocModules=Document templates for documents generated from a group record ##### HRM setup ##### diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 001c48bf5de..a84774cf925 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -1419,7 +1419,8 @@ DisableForgetPasswordLinkOnLogonPage=Cacher le lien "Mot de passe oublié" sur l UsersSetup=Configuration du module utilisateurs UserMailRequired=Email requis pour créer un nouvel utilisateur UserHideInactive=Masquer les utilisateurs inactifs sur toutes les listes déroulantes d'utilisateurs (non recommandé: cela peut signifier que vous ne pourrez pas filtrer ou rechercher les anciens utilisateurs sur certaines pages) -UserHideExternal=Masquer les utilisateurs externes (non salariés) sur toutes les listes déroulantes d'utilisateurs (non recommandé: cela peut signifier que vous ne pourrez pas filtrer ou rechercher les utilisateurs externes sur certaines pages) +UserHideExternal=Masquer les utilisateurs externes (non liés à un tiers) sur toutes les listes déroulantes d'utilisateurs (non recommandé: cela peut signifier que vous ne pourrez pas filtrer ou rechercher les utilisateurs externes sur certaines pages) +UserHideNonEmployee=Masquer les utilisateurs externes (non salariés) sur toutes les listes déroulantes d'utilisateurs (non recommandé: cela peut signifier que vous ne pourrez pas filtrer ou rechercher les utilisateurs non salariés sur certaines pages) UsersDocModules=Modèles de documents pour les documents générés à partir de la fiche utilisateur GroupsDocModules=Modèles de documents pour les documents générés à partir de la fiche d'un groupe ##### HRM setup ##### From 57ef86fdde55a300db3ee59089df6ee36664d25b Mon Sep 17 00:00:00 2001 From: William Mead Date: Wed, 25 Oct 2023 15:52:20 +0200 Subject: [PATCH 008/579] NEW added address, zip & town to resource object --- htdocs/resource/class/dolresource.class.php | 42 +++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php index e60f6a7a352..e5b3ae43b88 100644 --- a/htdocs/resource/class/dolresource.class.php +++ b/htdocs/resource/class/dolresource.class.php @@ -44,6 +44,12 @@ class Dolresource extends CommonObject */ public $picto = 'resource'; + /** + * @var string address variables + */ + public $address; + public $zip; + public $town; /** * @var int ID @@ -122,6 +128,15 @@ class Dolresource extends CommonObject if (isset($this->ref)) { $this->ref = trim($this->ref); } + if (isset($this->address)) { + $this->address = trim($this->address); + } + if (isset($this->zip)) { + $this->zip = trim($this->zip); + } + if (isset($this->town)) { + $this->town = trim($this->town); + } if (isset($this->description)) { $this->description = trim($this->description); } @@ -143,6 +158,9 @@ class Dolresource extends CommonObject $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."("; $sql .= "entity,"; $sql .= "ref,"; + $sql .= "address,"; + $sql .= "zip,"; + $sql .= "town,"; $sql .= "description,"; $sql .= "fk_country,"; $sql .= "fk_code_type_resource,"; @@ -219,6 +237,9 @@ class Dolresource extends CommonObject $sql .= " t.rowid,"; $sql .= " t.entity,"; $sql .= " t.ref,"; + $sql .= " t.address,"; + $sql .= " t.zip,"; + $sql .= " t.town,"; $sql .= " t.description,"; $sql .= " t.fk_country,"; $sql .= " t.fk_code_type_resource,"; @@ -243,6 +264,9 @@ class Dolresource extends CommonObject $this->id = $obj->rowid; $this->entity = $obj->entity; $this->ref = $obj->ref; + $this->address = $obj->address; + $this->zip = $obj->zip; + $this->town = $obj->zip; $this->description = $obj->description; $this->country_id = $obj->fk_country; $this->fk_code_type_resource = $obj->fk_code_type_resource; @@ -281,6 +305,15 @@ class Dolresource extends CommonObject if (isset($this->ref)) { $this->ref = trim($this->ref); } + if (isset($this->address)) { + $this->address = trim($this->address); + } + if (isset($this->zip)) { + $this->zip = trim($this->zip); + } + if (isset($this->town)) { + $this->town = trim($this->town); + } if (isset($this->fk_code_type_resource)) { $this->fk_code_type_resource = trim($this->fk_code_type_resource); } @@ -299,6 +332,9 @@ class Dolresource extends CommonObject // Update request $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; $sql .= " ref=".(isset($this->ref) ? "'".$this->db->escape($this->ref)."'" : "null").","; + $sql .= " address=".(isset($this->address) ? "'".$this->db->escape($this->address)."'" : "null").","; + $sql .= " zip=".(isset($this->zip) ? "'".$this->db->escape($this->zip)."'" : "null").","; + $sql .= " town=".(isset($this->town) ? "'".$this->db->escape($this->town)."'" : "null").","; $sql .= " description=".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "null").","; $sql .= " fk_country=".($this->country_id > 0 ? $this->country_id : "null").","; $sql .= " fk_code_type_resource=".(isset($this->fk_code_type_resource) ? "'".$this->db->escape($this->fk_code_type_resource)."'" : "null").","; @@ -517,6 +553,9 @@ class Dolresource extends CommonObject $sql .= " t.rowid,"; $sql .= " t.entity,"; $sql .= " t.ref,"; + $sql .= " t.address,"; + $sql .= " t.zip,"; + $sql .= " t.town,"; $sql .= " t.description,"; $sql .= " t.fk_country,"; $sql .= " t.fk_code_type_resource,"; @@ -560,6 +599,9 @@ class Dolresource extends CommonObject $line = new Dolresource($this->db); $line->id = $obj->rowid; $line->ref = $obj->ref; + $line->address = $obj->address; + $line->zip = $obj->zip; + $line->town = $obj->town; $line->description = $obj->description; $line->country_id = $obj->fk_country; $line->fk_code_type_resource = $obj->fk_code_type_resource; From 19484ac5d5700b6cfb39affd81f7f18c864b2920 Mon Sep 17 00:00:00 2001 From: William Mead Date: Wed, 25 Oct 2023 17:03:24 +0200 Subject: [PATCH 009/579] Added getBannerAddress method. Fixed fetching town. --- htdocs/resource/class/dolresource.class.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php index e5b3ae43b88..4c6f99e6b26 100644 --- a/htdocs/resource/class/dolresource.class.php +++ b/htdocs/resource/class/dolresource.class.php @@ -266,7 +266,7 @@ class Dolresource extends CommonObject $this->ref = $obj->ref; $this->address = $obj->address; $this->zip = $obj->zip; - $this->town = $obj->zip; + $this->town = $obj->town; $this->description = $obj->description; $this->country_id = $obj->fk_country; $this->fk_code_type_resource = $obj->fk_code_type_resource; @@ -969,4 +969,12 @@ class Dolresource extends CommonObject return -1; } } + + /** + * @return string + */ + public function getBannerAddress() + { + return $this->getFullAddress(1,', '); + } } From 5871f1902746f2a09a56533498ca8b266ad6ef5c Mon Sep 17 00:00:00 2001 From: William Mead Date: Wed, 25 Oct 2023 17:03:52 +0200 Subject: [PATCH 010/579] Cleaned code --- htdocs/resource/card.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index 3ee118d06c7..b0830755414 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -276,12 +276,7 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0) { $linkback = ''.$langs->trans("BackToList").''; - - $morehtmlref = '
'; - $morehtmlref .= '
'; - - - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref'); print '
'; From 40d22cf012cd5c1f6a6f55897a5b4ac2a8485ef6 Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 26 Oct 2023 09:09:26 +0200 Subject: [PATCH 011/579] Added address, zip & town form fields. Moved country field. --- htdocs/resource/card.php | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index b0830755414..301a02f8576 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -222,6 +222,34 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0) { print ''.$langs->trans("ResourceFormLabel_ref").''; print ''; + // Address + print ''.$form->editfieldkey('Address', 'address', '', $object, 0).''; + print ''; + print $form->widgetForTranslation("address", $object, $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent'); + print ''; + + // Zip / Town + print ''.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'browser->layout == 'phone' ? ' colspan="3"': '').'>'; + print $formresource->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100'); + print ''; + if ($conf->browser->layout == 'phone') { + print ''; + } + print ''.$form->editfieldkey('Town', 'town', '', $object, 0).'browser->layout == 'phone' ? ' colspan="3"': '').'>'; + print $formresource->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id')); + print $form->widgetForTranslation("town", $object, $permissiontoadd, 'string', 'alphanohtml', 'maxwidth100 quatrevingtpercent'); + print ''; + + // Origin country + print ''.$langs->trans("CountryOrigin").''; + print $form->select_country($object->country_id, 'country_id'); + if ($user->admin) { + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + } + print ''; + // Type print ''.$langs->trans("ResourceType").''; print ''; @@ -236,14 +264,6 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0) { $doleditor->Create(); print ''; - // Origin country - print ''.$langs->trans("CountryOrigin").''; - print $form->select_country($object->country_id, 'country_id'); - if ($user->admin) { - print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); - } - print ''; - // Other attributes $parameters = array(); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook From f685eb66f67ef1c150df1dd3e6442b666b632809 Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 26 Oct 2023 09:09:57 +0200 Subject: [PATCH 012/579] Added select_ziptown method --- .../class/html.formresource.class.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/htdocs/resource/class/html.formresource.class.php b/htdocs/resource/class/html.formresource.class.php index 527fa93a483..ef7101a12a5 100644 --- a/htdocs/resource/class/html.formresource.class.php +++ b/htdocs/resource/class/html.formresource.class.php @@ -239,4 +239,38 @@ class FormResource print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); } } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Return a select list with zip codes and their town + * + * @param string $selected Preselected value + * @param string $htmlname HTML select name + * @param array $fields Array with key of fields to refresh after selection + * @param int $fieldsize Field size + * @param int $disableautocomplete 1 To disable ajax autocomplete features (browser autocomplete may still occurs) + * @param string $moreattrib Add more attribute on HTML input field + * @param string $morecss More css + * @return string + */ + public function select_ziptown($selected = '', $htmlname = 'zipcode', $fields = array(), $fieldsize = 0, $disableautocomplete = 0, $moreattrib = '', $morecss = '') + { + // phpcs:enable + global $conf; + + $out = ''; + + $size = ''; + if (!empty($fieldsize)) { + $size = 'size="' . $fieldsize . '"'; + } + + if ($conf->use_javascript_ajax && empty($disableautocomplete)) { + $out .= ajax_multiautocompleter($htmlname, $fields, DOL_URL_ROOT . '/core/ajax/ziptown.php') . "\n"; + $moreattrib .= ' autocomplete="off"'; + } + $out .= '' . "\n"; + + return $out; + } } From 905471fbdd7eecb1efe766eb0e181ff68bf78cba Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 26 Oct 2023 09:30:10 +0200 Subject: [PATCH 013/579] Added address, zip & town to add, update & get logic. --- htdocs/resource/card.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index 301a02f8576..326ad5a40ed 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -39,9 +39,12 @@ $id = GETPOST('id', 'int'); $action = GETPOST('action', 'aZ09'); $cancel = GETPOST('cancel', 'alpha'); $ref = GETPOST('ref', 'alpha'); +$address = GETPOST('address', 'alpha'); +$zip = GETPOST('zipcode', 'alpha'); +$town = GETPOST('town', 'alpha'); $description = GETPOST('description', 'restricthtml'); $confirm = GETPOST('confirm', 'aZ09'); -$fk_code_type_resource = GETPOST('fk_code_type_resource', 'alpha'); +$fk_code_type_resource = GETPOST('fk_code_type_resource', 'alpha'); $country_id = GETPOST('country_id', 'int'); // Protection if external user @@ -98,6 +101,9 @@ if (empty($reshook)) { $action = 'create'; } else { $object->ref = $ref; + $object->address = $address; + $object->zip = $zip; + $object->town = $town; $object->description = $description; $object->fk_code_type_resource = $fk_code_type_resource; $object->country_id = $country_id; @@ -138,6 +144,9 @@ if (empty($reshook)) { $res = $object->fetch($id); if ($res > 0) { $object->ref = $ref; + $object->address = $address; + $object->zip = $zip; + $object->town = $town; $object->description = $description; $object->fk_code_type_resource = $fk_code_type_resource; $object->country_id = $country_id; From 96d9b1c7925514b446f3986e1d57cd56c8c1e845 Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 26 Oct 2023 11:44:42 +0200 Subject: [PATCH 014/579] Added address state --- htdocs/resource/card.php | 20 ++++++++++++++++++++ htdocs/resource/class/dolresource.class.php | 18 +++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index 326ad5a40ed..cc84eb6275e 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -46,6 +46,7 @@ $description = GETPOST('description', 'restricthtml'); $confirm = GETPOST('confirm', 'aZ09'); $fk_code_type_resource = GETPOST('fk_code_type_resource', 'alpha'); $country_id = GETPOST('country_id', 'int'); +$state_id = GETPOST('state_id', 'int'); // Protection if external user if ($user->socid > 0) { @@ -107,6 +108,7 @@ if (empty($reshook)) { $object->description = $description; $object->fk_code_type_resource = $fk_code_type_resource; $object->country_id = $country_id; + $object->state_id = $state_id; // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost(null, $object); @@ -150,6 +152,7 @@ if (empty($reshook)) { $object->description = $description; $object->fk_code_type_resource = $fk_code_type_resource; $object->country_id = $country_id; + $object->state_id = $state_id; // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); @@ -259,6 +262,23 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0) { } print ''; + // State + if (empty($conf->global->SOCIETE_DISABLE_STATE)) { + if ((getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) { + print ''.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).''; + } else { + print ''.$form->editfieldkey('State', 'state_id', '', $object, 0).''; + } + + if ($object->country_id) { + print img_picto('', 'state', 'class="pictofixedwidth"'); + print $formresource->select_state($object->state_id, $object->country_code); + } else { + print $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; + } + print ''; + } + // Type print ''.$langs->trans("ResourceType").''; print ''; diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php index 4c6f99e6b26..0d80b2e08e8 100644 --- a/htdocs/resource/class/dolresource.class.php +++ b/htdocs/resource/class/dolresource.class.php @@ -63,8 +63,11 @@ class Dolresource extends CommonObject */ public $description; + /** + * @var int ID + */ public $fk_country; - + public $fk_state; // Variable for a link of resource @@ -143,6 +146,9 @@ class Dolresource extends CommonObject if (!is_numeric($this->country_id)) { $this->country_id = 0; } + if (!is_numeric($this->state_id)) { + $this->state_id = 0; + } if (isset($this->fk_code_type_resource)) { $this->fk_code_type_resource = trim($this->fk_code_type_resource); } @@ -163,6 +169,7 @@ class Dolresource extends CommonObject $sql .= "town,"; $sql .= "description,"; $sql .= "fk_country,"; + $sql .= "fk_state,"; $sql .= "fk_code_type_resource,"; $sql .= "note_public,"; $sql .= "note_private"; @@ -171,6 +178,7 @@ class Dolresource extends CommonObject $sql .= " ".(!isset($this->ref) ? 'NULL' : "'".$this->db->escape($this->ref)."'").","; $sql .= " ".(!isset($this->description) ? 'NULL' : "'".$this->db->escape($this->description)."'").","; $sql .= " ".($this->country_id > 0 ? $this->country_id : 'null').","; + $sql .= " ".($this->state_id > 0 ? $this->state_id : 'null').","; $sql .= " ".(!isset($this->fk_code_type_resource) ? 'NULL' : "'".$this->db->escape($this->fk_code_type_resource)."'").","; $sql .= " ".(!isset($this->note_public) ? 'NULL' : "'".$this->db->escape($this->note_public)."'").","; $sql .= " ".(!isset($this->note_private) ? 'NULL' : "'".$this->db->escape($this->note_private)."'"); @@ -242,6 +250,7 @@ class Dolresource extends CommonObject $sql .= " t.town,"; $sql .= " t.description,"; $sql .= " t.fk_country,"; + $sql .= " t.fk_state,"; $sql .= " t.fk_code_type_resource,"; $sql .= " t.note_public,"; $sql .= " t.note_private,"; @@ -269,6 +278,7 @@ class Dolresource extends CommonObject $this->town = $obj->town; $this->description = $obj->description; $this->country_id = $obj->fk_country; + $this->state_id = $obj->fk_state; $this->fk_code_type_resource = $obj->fk_code_type_resource; $this->note_public = $obj->note_public; $this->note_private = $obj->note_private; @@ -323,6 +333,9 @@ class Dolresource extends CommonObject if (!is_numeric($this->country_id)) { $this->country_id = 0; } + if (!is_numeric($this->state_id)) { + $this->state_id = 0; + } // $this->oldcopy should have been set by the caller of update (here properties were already modified) if (empty($this->oldcopy)) { @@ -337,6 +350,7 @@ class Dolresource extends CommonObject $sql .= " town=".(isset($this->town) ? "'".$this->db->escape($this->town)."'" : "null").","; $sql .= " description=".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "null").","; $sql .= " fk_country=".($this->country_id > 0 ? $this->country_id : "null").","; + $sql .= " fk_state=".($this->state_id > 0 ? $this->state_id : "null").","; $sql .= " fk_code_type_resource=".(isset($this->fk_code_type_resource) ? "'".$this->db->escape($this->fk_code_type_resource)."'" : "null").","; $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null'); $sql .= " WHERE rowid=".((int) $this->id); @@ -558,6 +572,7 @@ class Dolresource extends CommonObject $sql .= " t.town,"; $sql .= " t.description,"; $sql .= " t.fk_country,"; + $sql .= " t.fk_state,"; $sql .= " t.fk_code_type_resource,"; $sql .= " t.tms,"; // Add fields from extrafields @@ -604,6 +619,7 @@ class Dolresource extends CommonObject $line->town = $obj->town; $line->description = $obj->description; $line->country_id = $obj->fk_country; + $line->state_id = $obj->fk_state; $line->fk_code_type_resource = $obj->fk_code_type_resource; $line->type_label = $obj->type_label; From bef4a371d07bdcef3ea00dbbc466fb3e84b5770b Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 26 Oct 2023 11:44:58 +0200 Subject: [PATCH 015/579] Added select_state method --- .../class/html.formresource.class.php | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/htdocs/resource/class/html.formresource.class.php b/htdocs/resource/class/html.formresource.class.php index ef7101a12a5..2c391cf733e 100644 --- a/htdocs/resource/class/html.formresource.class.php +++ b/htdocs/resource/class/html.formresource.class.php @@ -273,4 +273,116 @@ class FormResource return $out; } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Returns the drop-down list of departments/provinces/cantons for all countries or for a given country. + * In the case of an all-country list, the display breaks on the country. + * The key of the list is the code (there can be several entries for a given code but in this case, the country field differs). + * Thus the links with the departments are done on a department independently of its name. + * + * @param int $selected Code state preselected (mus be state id) + * @param integer $country_codeid Country code or id: 0=list for all countries, otherwise country code or country rowid to show + * @param string $htmlname Id of department. If '', we want only the string with