diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index 9823479242f..fe3d40c3f32 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -34,9 +34,6 @@ if (isModEnabled('workstation')) { require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php'; } -//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; -//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; - /** * Class for BOM @@ -1471,8 +1468,12 @@ class BOM extends CommonObject } } else { // Convert qty of line into hours - $unitforline = measuringUnitString($line->fk_unit, '', '', 1); - $qtyhourforline = convertDurationtoHour((float) $line->qty, $unitforline); + require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php'; + $measuringUnits = new CUnits($this->db); + $measuringUnits->fetch($line->fk_unit); + + // The unit is a unit for time, so the $measuringUnits->scale is not a power of 10, but directly the factor to change unit into seconds + $qtyhourforline = $line->qty * (int) $measuringUnits->scale / 3600; if (isModEnabled('workstation') && !empty($line->fk_default_workstation)) { $workstation = new Workstation($this->db); diff --git a/htdocs/core/class/cunits.class.php b/htdocs/core/class/cunits.class.php index b55457159d5..34f5eb68660 100644 --- a/htdocs/core/class/cunits.class.php +++ b/htdocs/core/class/cunits.class.php @@ -1,6 +1,7 @@ - * Copyright (C) 2024 MDW +/* Copyright (C) 2007-2011 Laurent Destailleur + * Copyright (C) 2024 MDW + * Copyright (C) 2024 Frédéric France * * 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 @@ -36,8 +37,8 @@ class CUnits extends CommonDict */ public $records = array(); - //var $element='ctypent'; //!< Id that identify managed objects - //var $table_element='ctypent'; //!< Name of table without prefix where object is stored + // public $element = 'cunits'; //!< Id that identify managed objects + // public $table_element = 'c_units'; //!< Name of table without prefix where object is stored /** * @var string label @@ -50,16 +51,19 @@ class CUnits extends CommonDict * @var string */ public $sortorder; + /** * @var string */ public $short_label; + /** * @var string */ public $unit_type; + /** - * @var string + * @var ?int */ public $scale; @@ -107,7 +111,7 @@ class CUnits extends CommonDict $this->active = (int) $this->active; } if (isset($this->scale)) { - $this->scale = trim($this->scale); + $this->scale = (int) $this->scale; } // Check parameters @@ -127,7 +131,7 @@ class CUnits extends CommonDict $sql .= " ".(!isset($this->label) ? 'NULL' : "'".$this->db->escape($this->label)."'").","; $sql .= " ".(!isset($this->short_label) ? 'NULL' : "'".$this->db->escape($this->short_label)."'").","; $sql .= " ".(!isset($this->unit_type) ? 'NULL' : "'".$this->db->escape($this->unit_type)."'").","; - $sql .= " ".(!isset($this->scale) ? 'NULL' : "'".$this->db->escape($this->scale)."'"); + $sql .= " ".(!isset($this->scale) ? 'NULL' : (int) $this->scale); $sql .= ")"; $this->db->begin(); @@ -176,7 +180,6 @@ class CUnits extends CommonDict $sql .= " t.short_label,"; $sql .= " t.scale,"; $sql .= " t.unit_type,"; - $sql .= " t.scale,"; $sql .= " t.active"; $sql .= " FROM ".$this->db->prefix()."c_units as t"; $sql_where = array(); @@ -201,14 +204,13 @@ class CUnits extends CommonDict if ($this->db->num_rows($resql)) { $obj = $this->db->fetch_object($resql); - $this->id = $obj->rowid; + $this->id = (int) $obj->rowid; $this->code = $obj->code; $this->label = $obj->label; $this->short_label = $obj->short_label; - $this->scale = $obj->scale; + $this->scale = $obj->scale ? (int) $obj->scale : null; $this->unit_type = $obj->unit_type; - $this->scale = $obj->scale; - $this->active = $obj->active; + $this->active = (int) $obj->active; } $this->db->free($resql); @@ -294,14 +296,14 @@ class CUnits extends CommonDict while ($obj = $this->db->fetch_object($resql)) { $record = new self($this->db); - $record->id = $obj->rowid; + $record->id = (int) $obj->rowid; $record->code = $obj->code; $record->sortorder = $obj->sortorder; $record->label = $obj->label; $record->short_label = $obj->short_label; $record->unit_type = $obj->unit_type; - $record->scale = $obj->scale; - $record->active = $obj->active; + $record->scale = $obj->scale ? (int) $obj->scale : null; + $record->active = (int) $obj->active; $this->records[$record->id] = $record; } @@ -346,7 +348,7 @@ class CUnits extends CommonDict $this->libelle = trim($this->unit_type); } if (isset($this->scale)) { - $this->scale = trim($this->scale); + $this->scale = (int) $this->scale; } if (isset($this->active)) { $this->active = (int) $this->active;