From 80efdcf260d5091e7776fdeb18c58fc83f56628a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 31 Oct 2020 14:24:00 +0100 Subject: [PATCH] Debug multicurrency editor --- .../class/multicurrency.class.php | 30 ++++--- htdocs/multicurrency/multicurrency_rate.php | 79 +++++++++---------- 2 files changed, 53 insertions(+), 56 deletions(-) diff --git a/htdocs/multicurrency/class/multicurrency.class.php b/htdocs/multicurrency/class/multicurrency.class.php index 190efb0da48..ec4b55f39dc 100644 --- a/htdocs/multicurrency/class/multicurrency.class.php +++ b/htdocs/multicurrency/class/multicurrency.class.php @@ -687,6 +687,7 @@ class MultiCurrency extends CommonObject } } + /** * Class CurrencyRate */ @@ -727,6 +728,7 @@ class CurrencyRate extends CommonObjectLine */ public $entity; + /** * Constructor * @@ -744,8 +746,7 @@ class CurrencyRate extends CommonObjectLine * * @param int $fk_multicurrency Id of currency * @param bool $trigger true=launch triggers after, false=disable triggers - * - * @return int <0 if KO, Id of created object if OK + * @return int <0 if KO, Id of created object if OK */ public function create($fk_multicurrency, $trigger = true) { @@ -756,7 +757,7 @@ class CurrencyRate extends CommonObjectLine $error = 0; $this->rate = price2num($this->rate); if (empty($this->entity) || $this->entity <= 0) $this->entity = $conf->entity; - $now = !empty($this->date_sync) ? $this->date_sync : date('Y-m-d H:i:s'); + $now = empty($this->date_sync) ? dol_now() : $this->date_sync; // Insert request $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'('; @@ -766,9 +767,9 @@ class CurrencyRate extends CommonObjectLine $sql .= ' entity'; $sql .= ') VALUES ('; $sql .= ' '.$this->rate.','; - $sql .= ' \''.$now.'\','; - $sql .= ' \''.$fk_multicurrency.'\','; - $sql .= ' \''.$this->entity.'\''; + $sql .= " '".$this->db->idate($now)."',"; + $sql .= " ".((int) $fk_multicurrency).","; + $sql .= " ".((int) $this->entity); $sql .= ')'; $this->db->begin(); @@ -806,9 +807,8 @@ class CurrencyRate extends CommonObjectLine /** * Load object in memory from the database * - * @param int $id Id object - * - * @return int <0 if KO, 0 if not found, >0 if OK + * @param int $id Id object + * @return int <0 if KO, 0 if not found, >0 if OK */ public function fetch($id) { @@ -827,7 +827,7 @@ class CurrencyRate extends CommonObjectLine $this->id = $obj->rowid; $this->rate = $obj->rate; - $this->date_sync = $obj->date_sync; + $this->date_sync = $this->db->jdate($obj->date_sync); $this->fk_multicurrency = $obj->fk_multicurrency; $this->entity = $obj->entity; } @@ -849,9 +849,8 @@ class CurrencyRate extends CommonObjectLine /** * Update object into database * - * @param bool $trigger true=launch triggers after, false=disable triggers - * - * @return int <0 if KO, >0 if OK + * @param bool $trigger true=launch triggers after, false=disable triggers + * @return int <0 if KO, >0 if OK */ public function update($trigger = true) { @@ -900,9 +899,8 @@ class CurrencyRate extends CommonObjectLine /** * Delete object in database * - * @param bool $trigger true=launch triggers after, false=disable triggers - * - * @return int <0 if KO, >0 if OK + * @param bool $trigger true=launch triggers after, false=disable triggers + * @return int <0 if KO, >0 if OK */ public function delete($trigger = true) { diff --git a/htdocs/multicurrency/multicurrency_rate.php b/htdocs/multicurrency/multicurrency_rate.php index 2340df84ce5..37f4693fd9a 100644 --- a/htdocs/multicurrency/multicurrency_rate.php +++ b/htdocs/multicurrency/multicurrency_rate.php @@ -50,9 +50,8 @@ $search_date_sync = GETPOST('search_date_sync', 'alpha'); $search_rate = GETPOST('search_rate', 'alpha'); $search_code = GETPOST('search_code', 'alpha'); $multicurrency_code = GETPOST('multicurrency_code', 'alpha'); -$dateinput = GETPOST('dateinput', 'alpha'); -$rateinput = GETPOST('rateinput', 'int'); -$search_tobatch = GETPOST('search_tobatch', 'int'); +$dateinput = dol_mktime(0, 0, 0, GETPOST('dateinputmonth', 'int'), GETPOST('dateinputday', 'int'), GETPOST('dateinputyear', 'int')); +$rateinput = price2num(GETPOST('rateinput', 'alpha')); $optioncss = GETPOST('optioncss', 'alpha'); $limit = GETPOST('limit', 'int')?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); @@ -86,9 +85,9 @@ $fieldstosearchall = array( // Definition of fields for lists $arrayfields=array( - 'cr.date_sync'=>array('label'=>$langs->trans("date_sync"), 'checked'=>1), - 'cr.rate'=>array('label'=>$langs->trans("rate"), 'checked'=>1), - 'm.code'=>array('label'=>$langs->trans("code"), 'checked'=>1), + 'cr.date_sync'=>array('label'=>'Date', 'checked'=>1), + 'cr.rate'=>array('label'=>'Rate', 'checked'=>1), + 'm.code'=>array('label'=>'Code', 'checked'=>1), ); @@ -112,14 +111,14 @@ if ($action == "create"){ $currencyRate_static->rate = $rateinput; $result = $currencyRate_static->create(intval($fk_currency)); - if ($result) { - setEventMessage($langs->trans('successRateCreate', $multicurrency_code)); + if ($result > 0) { + setEventMessages($langs->trans('successRateCreate', $multicurrency_code), null); } else { dol_syslog("currencyRate:createRate", LOG_WARNING); - setEventMessage($langs->trans('successRateCreate')); + setEventMessages($currencyRate_static->error, $currencyRate_static->errors, 'errors'); } } else { - setEventMessage($langs->trans('NoEmptyRate'), "errors"); + setEventMessages($langs->trans('NoEmptyRate'),null, "errors"); } } @@ -129,17 +128,17 @@ if ($action == 'update'){ if ( $result > 0){ $currency_static = new MultiCurrency($db); $fk_currency = $currency_static->getIdFromCode($db, $multicurrency_code); - $currencyRate->date_sync = $db->escape(GETPOST('dateinput', 'alpha')); + $currencyRate->date_sync = $dateinput; $currencyRate->fk_multicurrency = $fk_currency; - $currencyRate->rate = $db->escape(GETPOST('rateinput', 'int')); + $currencyRate->rate = $rateinput; $res = $currencyRate->update(); if ($res){ - setEventMessage($langs->trans('successUpdateRate')); + setEventMessages($langs->trans('successUpdateRate'), null); }else { - setEventMessage($langs->trans('errorUpdateRate'), "errors"); + setEventMessages($currencyRate->error, $currencyRate->errors, "errors"); } }else { - setEventMessage($langs->trans(''), "warnings"); + setEventMessages($langs->trans('Error'), null, "warnings"); } } @@ -151,7 +150,7 @@ if ($action == "deleteRate"){ $current_currency = new MultiCurrency($db); $current_currency->fetch($current_rate->fk_multicurrency); if ($current_currency){ - $delayedhtmlcontent .= $form->formconfirm( + $delayedhtmlcontent = $form->formconfirm( $_SERVER["PHP_SELF"].'?id_rate='.$id_rate_selected, $langs->trans('DeleteLineRate'), $langs->trans('ConfirmDeleteLineRate', $current_rate->rate, $current_currency->name, $current_rate->date_sync), @@ -174,12 +173,12 @@ if ($action == "confirm_delete"){ if ($current_rate){ $result = $current_rate->delete(); if ($result){ - setEventMessage($langs->trans('successRateDelete')); + setEventMessages($langs->trans('successRateDelete'), null); }else { - setEventMessage($langs->trans('errorRateDelete'), 'errors'); + setEventMessages($current_rate->error, $current_rate->errors, 'errors'); } }else { - setEventMessage($langs->trans('NoCurrencyRateSelected'), "warnings"); + setEventMessages($langs->trans('NoCurrencyRateSelected'), null, "warnings"); dol_syslog($langs->trans('NoCurrencyRateSelected'), LOG_WARNING); } } @@ -244,13 +243,15 @@ if ($action!= "updateRate" && $action!= "deleteRate" ) { print '
'; print ''; - print ' '; - print ' '; + print ' '; + print ' '; - print ' '; + print ''; print ''; - print ' '; + print ' '; print ' '; print '
' . $langs->trans('date') . '' . $langs->trans('Date') . ''; + print $form->selectDate($dateinput, 'dateinput'); + print '' . $langs->trans('Codemulticurrency') . ' ' . $langs->trans('Currency') . '' . $form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code', 'alpha') : $multicurrency_code), 'multicurrency_code', 0, " code != '".$conf->currency."'", true) . '' . $langs->trans('rate') . '' . $langs->trans('Rate') . ''; @@ -260,6 +261,8 @@ if ($action!= "updateRate" && $action!= "deleteRate" ) { print '
'; print '
'; + + print '
'; } if ($action == "updateRate"){ @@ -282,15 +285,17 @@ if ($action == "updateRate"){ print ''; $form = new Form($db); - print '
'; + print ''; print ''; - print ' '; - print ''; + print ' '; + print ''; - print ''; + print ''; print ''; - print ''; + print ''; print ''; print '
' . $langs->trans('date') . '' . $langs->trans('Date') . ''; + print $form->selectDate($current_rate->date_sync, 'dateinput'); + print '' . $langs->trans('Codemulticurrency') . ' ' . $langs->trans('Currency') . '' . $form->selectMultiCurrency($currency_code, 'multicurrency_code', 0, " code != '".$conf->currency."'", true) . '' . $langs->trans('rate') . '' . $langs->trans('Rate') . ''; @@ -309,28 +314,23 @@ if ($action == "updateRate"){ $sql = 'SELECT cr.rowid, cr.date_sync, cr.rate, cr.entity, m.code, m.name '; - // Add fields from hooks $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook $sql.=$hookmanager->resPrint; $sql.= ' FROM '.MAIN_DB_PREFIX.'multicurrency_rate as cr '; $sql .=" INNER JOIN ".MAIN_DB_PREFIX."multicurrency AS m ON cr.fk_multicurrency = m.rowid"; - - if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall); - -if ($search_date_sync) $sql .= natural_search('cr.date_sync', $search_date_sync); -if ($search_rate) $sql .= natural_search('cr.rate', $search_rate); +if ($search_date_sync) $sql .= natural_search('cr.date_sync', $search_date_sync); +if ($search_rate) $sql .= natural_search('cr.rate', $search_rate); if ($search_code) $sql .= natural_search('m.code', $search_code); - -$sql.= ' WHERE m.code != \''.$conf->currency. '\''; +$sql.= " WHERE m.code <> '".$db->escape($conf->currency)."'"; // Add where from hooks $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook $sql.=$hookmanager->resPrint; -$sql.= " GROUP BY cr.rowid, cr.date_sync, cr.rate, m.code, cr.entity "; +$sql.= " GROUP BY cr.rowid, cr.date_sync, cr.rate, m.code, cr.entity, m.code, m.name"; // Add fields from hooks $parameters=array(); @@ -377,12 +377,11 @@ if ($resql) // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; - if ($user->admin) $arrayofmassactions['predelete']=$langs->trans("Delete"); if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array(); $massactionbutton=$form->selectMassAction('', $arrayofmassactions); - print ''; + print ''; if ($optioncss != '') print ''; print ''; print ''; @@ -522,7 +521,7 @@ if ($resql) { $selected=0; if (in_array($obj->rowid, $arrayofselected)) $selected=1; - print 'rowid.'" class="like-link " style="margin-right:15px;important">' . img_picto('edit', 'edit') . ''; + print 'rowid.'" class="like-link " style="margin-right:15px;important">' . img_picto('edit', 'edit') . ''; print 'rowid.'" class="like-link" style="margin-right:45px;important">' . img_picto('delete', 'delete') . ''; print ''; }