multicurrency update online and change some behaviors
This commit is contained in:
parent
193d231d4c
commit
26a40e30e3
@ -46,7 +46,8 @@ $confirm = GETPOST('confirm', 'alpha');
|
||||
$toselect = GETPOST('toselect', 'array');
|
||||
$id_rate_selected = GETPOST('id_rate', 'int');
|
||||
$sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
|
||||
$search_date_sync = GETPOST('search_date_sync', 'alpha');
|
||||
$search_date_sync = dol_mktime(0, 0, 0, GETPOST('search_date_syncmonth', 'int'), GETPOST('search_date_syncday', 'int'), GETPOST('search_date_syncyear', 'int'));
|
||||
$search_date_sync_end = dol_mktime(0, 0, 0, GETPOST('search_date_sync_endmonth', 'int'), GETPOST('search_date_sync_endday', 'int'), GETPOST('search_date_sync_endyear', 'int'));
|
||||
$search_rate = GETPOST('search_rate', 'alpha');
|
||||
$search_code = GETPOST('search_code', 'alpha');
|
||||
$multicurrency_code = GETPOST('multicurrency_code', 'alpha');
|
||||
@ -58,12 +59,13 @@ $sortfield = GETPOST("sortfield", 'alpha');
|
||||
$sortorder = GETPOST("sortorder", 'alpha');
|
||||
$page = (GETPOST("page", 'int') ?GETPOST("page", 'int') : 0);
|
||||
|
||||
|
||||
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
|
||||
$offset = $limit * $page;
|
||||
$pageprev = $page - 1;
|
||||
$pagenext = $page + 1;
|
||||
if (!$sortfield) $sortfield = "cr.date_sync";
|
||||
if (!$sortorder) $sortorder = "DESC";
|
||||
if (!$sortorder) $sortorder = "ASC";
|
||||
|
||||
|
||||
// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
|
||||
@ -200,6 +202,7 @@ if (empty($reshook))
|
||||
{
|
||||
$sall = "";
|
||||
$search_date_sync = "";
|
||||
$search_date_sync_end="";
|
||||
$search_rate = "";
|
||||
$search_code = "";
|
||||
$search_array_options = array();
|
||||
@ -233,7 +236,7 @@ print dol_get_fiche_head($head, 'ratelist', $langs->trans("ModuleSetup"), -1, "m
|
||||
|
||||
// ACTION
|
||||
|
||||
if ($action != "updateRate") {
|
||||
if (!in_array( $action, array("updateRate", "deleteRate"))) {
|
||||
print '<table class="noborder centpercent">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("FormCreateRate").'</td>'."\n";
|
||||
@ -243,15 +246,15 @@ if ($action != "updateRate") {
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" name="formulaire">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
|
||||
print '<table><tr>';
|
||||
print '<table class="noborder centpercent"><tr>';
|
||||
|
||||
print ' <td>'.$langs->trans('Date').'</td>';
|
||||
print ' <td>';
|
||||
print $form->selectDate($dateinput, 'dateinput');
|
||||
print $form->selectDate($dateinput, 'dateinput', 0, 0, 1);
|
||||
print '</td>';
|
||||
|
||||
print '<td> '.$langs->trans('Currency').'</td>';
|
||||
print '<td>'.$form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code', 'alpha') : $multicurrency_code), 'multicurrency_code', 0, " code != '".$conf->currency."'", true).'</td>';
|
||||
print '<td>'.$form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code', 'alpha') : $multicurrency_code), 'multicurrency_code', 1, " code != '".$conf->currency."'", true).'</td>';
|
||||
|
||||
print ' <td>'.$langs->trans('Rate').'</td>';
|
||||
print ' <td><input type="number" min="0" step="any" class="maxwidth75" name="rateinput" value="'.dol_escape_htmltag($rateinput).'"></td>';
|
||||
@ -267,54 +270,7 @@ if ($action != "updateRate") {
|
||||
print '<br>';
|
||||
}
|
||||
|
||||
if ($action == "updateRate") {
|
||||
$current_rate = new CurrencyRate($db);
|
||||
$current_rate->fetch(intval($id_rate_selected));
|
||||
|
||||
if ($current_rate) {
|
||||
$curr = new MultiCurrency($db);
|
||||
$resultcurrentCurrency = $curr->fetch($current_rate->fk_multicurrency);
|
||||
|
||||
if ($resultcurrentCurrency) {
|
||||
$currency_code = $curr->code;
|
||||
} else {
|
||||
$currency_code = '';
|
||||
}
|
||||
|
||||
print '<table class="noborder centpercent">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("FormUpdateRate").'</td>'."\n";
|
||||
print '</tr></table>';
|
||||
|
||||
$form = new Form($db);
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" name="formtoupdaterate">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
|
||||
print '<table><tr>';
|
||||
print ' <td>'.$langs->trans('Date').'</td>';
|
||||
print '<td>';
|
||||
print $form->selectDate($current_rate->date_sync, 'dateinput');
|
||||
print '</td>';
|
||||
|
||||
print '<td> '.$langs->trans('Currency').'</td>';
|
||||
print '<td>'.$form->selectMultiCurrency($currency_code, 'multicurrency_code', 0, " code != '".$conf->currency."'", true).'</td>';
|
||||
|
||||
print '<td>'.$langs->trans('Rate').'</td>';
|
||||
print '<td><input class="minwidth200" name="rateinput" value="'.dol_escape_htmltag($current_rate->rate).'" type="text"></td>';
|
||||
|
||||
print '<td>';
|
||||
print '<input type="hidden" name="action" value="update">';
|
||||
print '<input type="hidden" name="id_rate" value="'.$current_rate->id.'">';
|
||||
print '<input type="submit" class="butAction" name="btnupdateCurrencyRate" value="'.$langs->trans('UpdateRate').'">';
|
||||
print '<a href="'.$_SERVER["PHP_SELF"].'" class="butAction">'.$langs->trans('CancelUpdate').'</a>';
|
||||
|
||||
print '</td>';
|
||||
print '</tr></table>';
|
||||
print '</form>';
|
||||
} else {
|
||||
dol_syslog("currency_rate:list:update", LOG_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$sql = 'SELECT cr.rowid, cr.date_sync, cr.rate, cr.entity, m.code, m.name ';
|
||||
@ -325,7 +281,11 @@ $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_date_sync && $search_date_sync_end ){
|
||||
$sql .= " AND (cr.date_sync BETWEEN '".$db->idate($search_date_sync)."' AND '".$db->idate($search_date_sync_end)."')";
|
||||
} elseif ($search_date_sync && !$search_date_sync_end) {
|
||||
$sql .= natural_search('cr.date_sync', $db->idate($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 <> '".$db->escape($conf->currency)."'";
|
||||
@ -374,9 +334,10 @@ if ($resql)
|
||||
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
|
||||
if ($sall) $param .= "&sall=".urlencode($sall);
|
||||
|
||||
if ($search_date_sync) $param = "&search_date_sync=".urlencode($search_date_sync);
|
||||
if ($search_date_sync) $param = "&search_date_sync=".$search_date_sync;
|
||||
if ($search_date_sync_end) $param="&search_date_sync_end=".$search_date_sync_end;
|
||||
if ($search_rate) $param = "&search_rate=".urlencode($search_rate);
|
||||
if ($search_code != '') $param .= "&search_code=".urlencode($search_code);
|
||||
if ($search_code != '') $param.="&search_code=".urlencode($search_code);
|
||||
|
||||
// Add $param from extra fields
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
|
||||
@ -426,7 +387,7 @@ if ($resql)
|
||||
if ($massactionbutton) $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
|
||||
|
||||
print '<div class="div-table-responsive">';
|
||||
print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
|
||||
print '<table class="tagtable centpercent liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
|
||||
|
||||
// Lines with input filters
|
||||
print '<tr class="liste_titre_filter">';
|
||||
@ -435,14 +396,15 @@ if ($resql)
|
||||
if (!empty($arrayfields['cr.date_sync']['checked']))
|
||||
{
|
||||
print '<td class="liste_titre" align="left">';
|
||||
print '<input class="flat" type="text" name="search_date_sync" size="8" value="'.dol_escape_htmltag($search_date_sync).'">';
|
||||
print $form->selectDate($search_date_sync, 'search_date_sync', 0, 0, 1);
|
||||
print $form->selectDate($search_date_sync_end, 'search_date_sync_end', 0, 0, 1);
|
||||
print '</td>';
|
||||
}
|
||||
// code
|
||||
if (!empty($arrayfields['m.code']['checked']))
|
||||
{
|
||||
print '<td class="liste_titre" align="left">';
|
||||
print '<input class="flat" type="text" name="search_code" size="12" value="'.dol_escape_htmltag($search_code).'">';
|
||||
print $form->selectMultiCurrency($multicurrency_code, 'search_code', 1, " code != '".$conf->currency."'", true);
|
||||
print '</td>';
|
||||
}
|
||||
// rate
|
||||
@ -486,52 +448,69 @@ if ($resql)
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
// date_sync
|
||||
if (!empty($arrayfields['cr.date_sync']['checked']))
|
||||
{
|
||||
print '<td class="tdoverflowmax200">';
|
||||
print $obj->date_sync;
|
||||
print "</td>\n";
|
||||
if (!$i) $totalarray['nbfield']++;
|
||||
// USER REQUEST UPDATE FOR THIS LINE
|
||||
if ($action == "updateRate" && $obj->rowid == $id_rate_selected) {
|
||||
// var_dump($obj);
|
||||
print ' <td><input class="minwidth200" name="dateinput" value="'. date('Y-m-d', dol_stringtotime($obj->date_sync)) .'" type="date"></td>';
|
||||
print '<td>' . $form->selectMultiCurrency($obj->code, 'multicurrency_code', 1, " code != '".$conf->currency."'", true) . '</td>';
|
||||
print ' <td><input type="number" min ="0" step="any" class="minwidth200" name="rateinput" value="' . dol_escape_htmltag($obj->rate) . '"></td>';
|
||||
|
||||
print '<td class="center nowrap ">';
|
||||
print '<input type="hidden" name="page" value="'.dol_escape_htmltag($page).'">';
|
||||
print '<input type="hidden" name="id_rate" value="'.dol_escape_htmltag($obj->rowid).'">';
|
||||
print '<button type="submit" class="button" name="action" value="update">'.$langs->trans("Modify").'</button>';
|
||||
print '<button type="submit" class="button" name="action" value="cancel">'.$langs->trans("Cancel").'</button>';
|
||||
print '</td>';
|
||||
}
|
||||
else {
|
||||
// date_sync
|
||||
if (!empty($arrayfields['cr.date_sync']['checked']))
|
||||
{
|
||||
print '<td class="tdoverflowmax200">';
|
||||
print $obj->date_sync;
|
||||
print "</td>\n";
|
||||
if (!$i) $totalarray['nbfield']++;
|
||||
}
|
||||
|
||||
// code
|
||||
if (! empty($arrayfields['m.code']['checked']))
|
||||
{
|
||||
print '<td class="tdoverflowmax200">';
|
||||
print $obj->code." ".$obj->name;
|
||||
print "</td>\n";
|
||||
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
}
|
||||
|
||||
// rate
|
||||
if (! empty($arrayfields['cr.rate']['checked']))
|
||||
{
|
||||
print '<td class="tdoverflowmax200">';
|
||||
print $obj->rate;
|
||||
print "</td>\n";
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
}
|
||||
|
||||
|
||||
// Fields from hook
|
||||
$parameters = ['arrayfields' => $arrayfields, 'obj' => $obj];
|
||||
$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
|
||||
print $hookmanager->resPrint;
|
||||
|
||||
// Action
|
||||
print '<td class="nowrap " >';
|
||||
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
|
||||
{
|
||||
$selected = 0;
|
||||
if (in_array($obj->rowid, $arrayofselected)) $selected = 1;
|
||||
print '<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?action=updateRate&id_rate='.$obj->rowid.'">'.img_picto('edit', 'edit').'</a>';
|
||||
print '<a class="marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?action=deleteRate&id_rate='.$obj->rowid.'">'.img_picto('delete', 'delete').'</a>';
|
||||
print '<input id="cb'.$obj->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
|
||||
}
|
||||
print '</td>';
|
||||
if (!$i) $totalarray['nbfield']++;
|
||||
}
|
||||
|
||||
// code
|
||||
if (!empty($arrayfields['m.code']['checked']))
|
||||
{
|
||||
print '<td class="tdoverflowmax200">';
|
||||
print $obj->code." ".$obj->name;
|
||||
print "</td>\n";
|
||||
|
||||
if (!$i) $totalarray['nbfield']++;
|
||||
}
|
||||
|
||||
// rate
|
||||
if (!empty($arrayfields['cr.rate']['checked']))
|
||||
{
|
||||
print '<td class="tdoverflowmax200">';
|
||||
print $obj->rate;
|
||||
print "</td>\n";
|
||||
if (!$i) $totalarray['nbfield']++;
|
||||
}
|
||||
|
||||
// Fields from hook
|
||||
$parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj);
|
||||
$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
|
||||
print $hookmanager->resPrint;
|
||||
|
||||
// Action
|
||||
print '<td class="nowrap" align="center">';
|
||||
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
|
||||
{
|
||||
$selected = 0;
|
||||
if (in_array($obj->rowid, $arrayofselected)) $selected = 1;
|
||||
print '<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?action=updateRate&id_rate='.$obj->rowid.'">'.img_picto('edit', 'edit').'</a>';
|
||||
print '<a class="marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?action=deleteRate&id_rate='.$obj->rowid.'">'.img_picto('delete', 'delete').'</a>';
|
||||
print '<input id="cb'.$obj->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
|
||||
}
|
||||
print '</td>';
|
||||
if (!$i) $totalarray['nbfield']++;
|
||||
|
||||
print "</tr>\n";
|
||||
$i++;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user