Add function "convertDurationtoHour"

This commit is contained in:
atm-lena 2022-07-12 10:03:31 +02:00
parent 8a36e2e9d8
commit c068eebc43
2 changed files with 23 additions and 7 deletions

View File

@ -24,6 +24,7 @@
// Put here all includes required by your class file
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
@ -1128,13 +1129,7 @@ class BOM extends CommonObject
} else {
//Convert qty to hour
if($line->duration_unit == 's') $qty = $line->qty / 3600;
if($line->duration_unit == 'i') $qty = $line->qty / 60;
if($line->duration_unit == 'h') $qty = $line->qty;
if($line->duration_unit == 'd') $qty = $line->qty * 24;
if($line->duration_unit == 'w') $qty = $line->qty * 24 * 7;
if($line->duration_unit == 'm') $qty = $line->qty * 730.484;
if($line->duration_unit == 'y') $qty = $line->qty * 365 * 24;
$qty = convertDurationtoHour($line->qty, $line->duration_unit);
if($conf->workstation->enabled){
if($tmpproduct->fk_default_workstation) {

View File

@ -318,6 +318,27 @@ function convertSecondToTime($iSecond, $format = 'all', $lengthOfDay = 86400, $l
}
/** Convert duration to hour
*
* @param int $duration_value Duration value
* @param int $duration_unit Duration unit
* @return int $result
*/
function convertDurationtoHour($duration_value, $duration_unit)
{
$result = 0;
if($duration_unit == 's') $result = $duration_value / 3600;
if($duration_unit == 'i') $result = $duration_value / 60;
if($duration_unit == 'h') $result = $duration_value;
if($duration_unit == 'd') $result = $duration_value * 24;
if($duration_unit == 'w') $result = $duration_value * 24 * 7;
if($duration_unit == 'm') $result = $duration_value * 730.484;
if($duration_unit == 'y') $result = $duration_value * 365 * 24;
return $result;
}
/**
* Generate a SQL string to make a filter into a range (for second of date until last second of date).
* This method allows to maje SQL request that will deal correctly the timezone of server.