2
0
forked from Wavyzz/dolibarr

New expense report rules and ik (index kilometers) - MAIN_USE_EXPENSE_IK - MAIN_USE_EXPENSE_RULE

This commit is contained in:
phf
2017-06-15 11:08:53 +02:00
parent 00bf4bba13
commit 1beec51928
27 changed files with 2551 additions and 238 deletions

View File

@@ -6383,3 +6383,43 @@ function dol_mimetype($file,$default='application/octet-stream',$mode=0)
return $mime;
}
/**
* Return value from dictionary
*
* @param string $tablename name of dictionary
* @param string $field the value to return
* @param int $id id of line
* @param bool $checkentity add filter on entity
* @param string $rowidfield name of the column rowid
*/
function getDictvalue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
{
global $dictvalues,$db,$langs;
if (!isset($dictvalues[$tablename]))
{
$dictvalues[$tablename] = array();
$sql = 'SELECT * FROM '.$tablename.' WHERE 1';
if ($checkentity) $sql.= ' entity IN (0,'.getEntity('').')';
$resql = $db->query($sql);
if ($resql)
{
while ($obj = $db->fetch_object($resql))
{
$dictvalues[$tablename][$obj->{$rowidfield}] = $obj;
}
}
else
{
dol_print_error($db);
}
}
if (!empty($dictvalues[$tablename][$id])) return $dictvalues[$tablename][$id]->{$field}; // Found
else // Not found
{
if ($id > 0) return $id;
return '';
}
}