Debug v17

This commit is contained in:
Laurent Destailleur 2022-12-31 15:52:03 +01:00
parent 26ef1cb270
commit f8451ffc56
5 changed files with 24 additions and 24 deletions

View File

@ -134,7 +134,8 @@ if ($action == 'add_currency') {
dolibarr_set_const($db, 'MULTICURRENCY_APP_SOURCE', GETPOST('MULTICURRENCY_APP_SOURCE', 'alpha')); dolibarr_set_const($db, 'MULTICURRENCY_APP_SOURCE', GETPOST('MULTICURRENCY_APP_SOURCE', 'alpha'));
//dolibarr_set_const($db, 'MULTICURRENCY_ALTERNATE_SOURCE', GETPOST('MULTICURRENCY_ALTERNATE_SOURCE', 'alpha')); //dolibarr_set_const($db, 'MULTICURRENCY_ALTERNATE_SOURCE', GETPOST('MULTICURRENCY_ALTERNATE_SOURCE', 'alpha'));
} else { } else {
$result = MultiCurrency::syncRates($conf->global->MULTICURRENCY_APP_ID); $multiurrency = new MultiCurrency($db);
$result = $multiurrency->syncRates(getDolGlobalString('MULTICURRENCY_APP_ID'));
if ($result > 0) { if ($result > 0) {
setEventMessages($langs->trans("CurrencyRateSyncSucceed"), null, "mesgs"); setEventMessages($langs->trans("CurrencyRateSyncSucceed"), null, "mesgs");
} }

View File

@ -600,30 +600,27 @@ class Job extends CommonObject
} }
/** /**
* Get last job for user * Get the last occupied position for a user
* *
* @param int $fk_user id of user we need to get last job * @param int $fk_user Id of user we need to get last job
* @return mixed|string|null * @return Position|string Last occupied position
*/ */
public function getLastJobForUser($fk_user) public function getLastJobForUser($fk_user)
{ {
global $db; $Tab = $this->getForUser($fk_user);
$j = new Job($db);
$Tab = $j->getForUser($fk_user);
if (empty($Tab)) return ''; if (empty($Tab)) return '';
$job = array_shift($Tab); $lastpos = array_shift($Tab);
return $job; return $lastpos;
} }
/** /**
* Get jobs for user * Get array of occupied positions for a user
* *
* @param int $userid id of user we need to get job list * @param int $userid Id of user we need to get job list
* @return array of jobs * @return Position[] Array of occupied positions
*/ */
public function getForUser($userid) public function getForUser($userid)
{ {

View File

@ -1036,6 +1036,8 @@ class Position extends CommonObject
} }
/** /**
* getForUser
*
* @param int $userid id of user we need to get position list * @param int $userid id of user we need to get position list
* @return array|int of positions of user with for each of them the job fetched into that array * @return array|int of positions of user with for each of them the job fetched into that array
*/ */
@ -1049,7 +1051,7 @@ class Position extends CommonObject
} }
/** /**
* Create a document onto disk according to template module. * Create a document onto disk according to template module.
* *
* @param string $modele Force template to use ('' to not force) * @param string $modele Force template to use ('' to not force)
* @param Translate $outputlangs objet lang a utiliser pour traduction * @param Translate $outputlangs objet lang a utiliser pour traduction

View File

@ -428,7 +428,7 @@ class MultiCurrency extends CommonObject
* *
* @param string $code currency code * @param string $code currency code
* @param double $rate new rate * @param double $rate new rate
* @return int -1 if KO, 1 if OK, 2 if label found and OK * @return int -1 if KO, 1 if OK, 2 if label found and OK
*/ */
public function addRateFromDolibarr($code, $rate) public function addRateFromDolibarr($code, $rate)
{ {
@ -609,14 +609,14 @@ class MultiCurrency extends CommonObject
* @param stdClass $TRate Object containing all currencies rates * @param stdClass $TRate Object containing all currencies rates
* @return int -1 if KO, 0 if nothing, 1 if OK * @return int -1 if KO, 0 if nothing, 1 if OK
*/ */
public static function recalculRates(&$TRate) public function recalculRates(&$TRate)
{ {
global $conf; global $conf;
if ($conf->currency != $conf->global->MULTICURRENCY_APP_SOURCE) { if ($conf->currency != getDolGlobalString('MULTICURRENCY_APP_SOURCE')) {
$alternate_source = 'USD'.$conf->currency; $alternate_source = 'USD'.$conf->currency;
if (!empty($TRate->{$alternate_source})) { if (!empty($TRate->$alternate_source)) {
$coef = $TRate->USDUSD / $TRate->{$alternate_source}; $coef = $TRate->USDUSD / $TRate->$alternate_source;
foreach ($TRate as $attr => &$rate) { foreach ($TRate as $attr => &$rate) {
$rate *= $coef; $rate *= $coef;
} }
@ -637,7 +637,7 @@ class MultiCurrency extends CommonObject
* @param int $addifnotfound Add if not found * @param int $addifnotfound Add if not found
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
public static function syncRates($key, $addifnotfound = 0) public function syncRates($key, $addifnotfound = 0)
{ {
global $conf, $db, $langs; global $conf, $db, $langs;
@ -656,16 +656,16 @@ class MultiCurrency extends CommonObject
if ($response->success) { if ($response->success) {
$TRate = $response->quotes; $TRate = $response->quotes;
$timestamp = $response->timestamp; //$timestamp = $response->timestamp;
if (self::recalculRates($TRate) >= 0) { if ($this->recalculRates($TRate) >= 0) {
foreach ($TRate as $currency_code => $rate) { foreach ($TRate as $currency_code => $rate) {
$code = substr($currency_code, 3, 3); $code = substr($currency_code, 3, 3);
$obj = new MultiCurrency($db); $obj = new MultiCurrency($db);
if ($obj->fetch(null, $code) > 0) { if ($obj->fetch(null, $code) > 0) {
$obj->updateRate($rate); $obj->updateRate($rate);
} elseif ($addifnotfound) { } elseif ($addifnotfound) {
self::addRateFromDolibarr($code, $rate); $this->addRateFromDolibarr($code, $rate);
} }
} }
} }

View File

@ -271,7 +271,7 @@ if (!in_array($action, array("updateRate", "deleteRate"))) {
print ' <td>'.$langs->trans('Date').'</td>'; print ' <td>'.$langs->trans('Date').'</td>';
print ' <td>'; print ' <td>';
print $form->selectDate($dateinput, 'dateinput', 0, 0, 1); print $form->selectDate($dateinput, 'dateinput', 0, 0, 1, '', 1, 1);
print '</td>'; print '</td>';
print '<td> '.$langs->trans('Currency').'</td>'; print '<td> '.$langs->trans('Currency').'</td>';