From d41edfc8121b9dc40f485184d708543d239f52fd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 8 Feb 2021 19:52:29 +0100 Subject: [PATCH] Fix responsive. Clean code --- htdocs/compta/paiement_vat.php | 29 ++- htdocs/compta/tva/class/tva.class.php | 13 +- htdocs/compta/tva/payments.php | 287 +------------------------- 3 files changed, 27 insertions(+), 302 deletions(-) diff --git a/htdocs/compta/paiement_vat.php b/htdocs/compta/paiement_vat.php index 45317ed64c0..7db2aa674af 100644 --- a/htdocs/compta/paiement_vat.php +++ b/htdocs/compta/paiement_vat.php @@ -29,7 +29,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/paymentvat.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Load translation files required by the page -$langs->load("bills"); +$langs->loadLangs(array("banks", "bills")); $chid = GETPOST("id", 'int'); $action = GETPOST('action', 'alpha'); @@ -58,9 +58,9 @@ if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'y exit; } - $datepaye = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + $datepaye = dol_mktime(12, 0, 0, GETPOST("remonth", 'int'), GETPOST("reday", 'int'), GETPOST("reyear", 'int')); - if (!$_POST["paiementtype"] > 0) + if (!(GETPOST("paiementtype", 'int') > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")), null, 'errors'); $error++; @@ -72,9 +72,9 @@ if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'y $error++; $action = 'create'; } - if (!empty($conf->banque->enabled) && !($_POST["accountid"] > 0)) + if (!empty($conf->banque->enabled) && !(GETPOST("accountid", 'int') > 0)) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToCredit")), null, 'errors'); + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToDebit")), null, 'errors'); $error++; $action = 'create'; } @@ -89,7 +89,7 @@ if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'y if (substr($key, 0, 7) == 'amount_') { $other_chid = substr($key, 7); - $amounts[$other_chid] = price2num($_POST[$key]); + $amounts[$other_chid] = price2num(GETPOST($key)); } } @@ -111,8 +111,8 @@ if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'y $paiement->amounts = $amounts; // Tableau de montant $paiement->paiementtype = GETPOST("paiementtype", 'alphanohtml'); $paiement->num_payment = GETPOST("num_payment", 'alphanohtml'); - $paiement->note = GETPOST("note", 'none'); - $paiement->note_private = GETPOST("note", 'none'); + $paiement->note = GETPOST("note", 'restricthtml'); + $paiement->note_private = GETPOST("note", 'restricthtml'); if (!$error) { @@ -187,11 +187,6 @@ if ($action == 'create') print load_fiche_titre($langs->trans("DoPayment")); print "
\n"; - if ($mesg) - { - print "
$mesg
"; - } - print '
'; print ''; print ''; @@ -223,21 +218,21 @@ if ($action == 'create') print ''.$langs->trans("RemainderToPay").''.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'';*/ print ''.$langs->trans("Date").''; - $datepaye = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); - $datepayment = empty($conf->global->MAIN_AUTOFILL_DATE) ? (empty($_POST["remonth"]) ?-1 : $datepaye) : 0; + $datepaye = dol_mktime(12, 0, 0, GETPOST("remonth", 'int'), GETPOST("reday", 'int'), GETPOST("reyear", 'int')); + $datepayment = empty($conf->global->MAIN_AUTOFILL_DATE) ? (GETPOST("remonth", 'int') ? $datepaye : -1) : 0; print $form->selectDate($datepayment, '', '', '', '', "add_payment", 1, 1); print ""; print ''; print ''.$langs->trans("PaymentMode").''; - $form->select_types_paiements(isset($_POST["paiementtype"]) ? $_POST["paiementtype"] : $tva->paiementtype, "paiementtype"); + $form->select_types_paiements(GETPOSTISSET("paiementtype") ? GETPOST("paiementtype", "int") : $tva->paiementtype, "paiementtype"); print "\n"; print ''; print ''; print ''.$langs->trans('AccountToDebit').''; print ''; - $form->select_comptes(isset($_POST["accountid"]) ? $_POST["accountid"] : $tva->accountid, "accountid", 0, '', 1); // Show opend bank account list + $form->select_comptes(GETPOST("accountid") ? GETPOST("accountid", "int") : $tva->accountid, "accountid", 0, '', 1); // Show opend bank account list print ''; // Number diff --git a/htdocs/compta/tva/class/tva.class.php b/htdocs/compta/tva/class/tva.class.php index 46711553fbb..8a817e6575f 100644 --- a/htdocs/compta/tva/class/tva.class.php +++ b/htdocs/compta/tva/class/tva.class.php @@ -712,10 +712,11 @@ class Tva extends CommonObject * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto * @param string $option link option * @param int $notooltip 1=Disable tooltip - * @param string $morecss More CSS + * @param string $morecss More CSS + * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking * @return string Chaine with URL */ - public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '') + public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) { global $langs, $conf; @@ -731,6 +732,14 @@ class Tva extends CommonObject $url = DOL_URL_ROOT.'/compta/tva/card.php?id='.$this->id; + if ($option != 'nolink') + { + // Add param to save lastsearch_values or not + $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; + } + $linkclose = ''; if (empty($notooltip)) { diff --git a/htdocs/compta/tva/payments.php b/htdocs/compta/tva/payments.php index 860db35e8cb..0cdf7e7086b 100644 --- a/htdocs/compta/tva/payments.php +++ b/htdocs/compta/tva/payments.php @@ -70,13 +70,11 @@ $sal_static = new PaymentSalary($db); llxHeader('', $langs->trans("VATExpensesArea")); -$title = $langs->trans("VATArea"); -if ($mode == 'tvaonly') $title = $langs->trans("VATPayments"); +$title = $langs->trans("VATPayments"); $param = ''; if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage; if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit; -if ($mode == 'tvaonly') $param = '&mode=tvaonly'; if ($sortfield) $param .= '&sortfield='.$sortfield; if ($sortorder) $param .= '&sortorder='.$sortorder; @@ -90,31 +88,13 @@ print ''; print ''; print ''; -if ($mode != 'tvaonly') -{ - $center = ($year ? ''.img_previous($langs->trans("Previous"), 'class="valignbottom"')." ".$langs->trans("Year").' '.$year.' '.img_next($langs->trans("Next"), 'class="valignbottom"')."" : ""); - print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $totalnboflines, 'title_accountancy', 0, '', '', $limit, 1); -} -else { - print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $totalnboflines, 'title_accountancy', 0, '', '', $limit); -} +print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $totalnboflines, 'title_accountancy', 0, '', '', $limit); if ($year) $param .= '&year='.$year; -if ($mode != 'tvaonly') -{ - print $langs->trans("DescTaxAndDividendsArea").'
'; - print "
"; -} - if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire) { - // Social contributions only - if ($mode != 'tvaonly') - { - print load_fiche_titre($langs->trans("VATPayments").($year ? ' ('.$langs->trans("Year").' '.$year.')' : ''), '', ''); - } - + print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print ''; print ''; print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "ptva.rowid", "", $param, '', $sortfield, $sortorder); @@ -227,266 +207,7 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire) dol_print_error($db); } print '
'; -} - -// VAT -if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire) -{ - if (!$mode || $mode != 'tvaonly') - { - print "
"; - - $tva = new Tva($db); - - print load_fiche_titre($langs->trans("VATPayments").($year ? ' ('.$langs->trans("Year").' '.$year.')' : ''), '', ''); - - $sql = "SELECT pv.rowid, pv.amount, pv.label, pv.datev as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."tva as pv"; - $sql .= " WHERE pv.entity = ".$conf->entity; - if ($year > 0) - { - // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance, - // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire - $sql .= " AND pv.datev between '".$db->idate(dol_get_first_day($year, 1, false))."' AND '".$db->idate(dol_get_last_day($year, 12, false))."'"; - } - if (preg_match('/^pv\./', $sortfield)) $sql .= $db->order($sortfield, $sortorder); - - $result = $db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - $i = 0; - $total = 0; - print ''; - print ''; - print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "pv.datev", "", $param, 'width="140px"', $sortfield, $sortorder); - print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "pv.label", "", $param, '', $sortfield, $sortorder); - print_liste_field_titre("ExpectedToPay", $_SERVER["PHP_SELF"], "pv.amount", "", $param, 'class="right"', $sortfield, $sortorder); - print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "pv.rowid", "", $param, '', $sortfield, $sortorder); - print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "pv.datev", "", $param, 'align="center"', $sortfield, $sortorder); - print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "pv.amount", "", $param, 'class="right"', $sortfield, $sortorder); - print "\n"; - - while ($i < $num) - { - $obj = $db->fetch_object($result); - - $total = $total + $obj->amount; - - print ''; - print ''."\n"; - - print "\n"; - - print '"; - - // Ref payment - $tva_static->id = $obj->rowid; - $tva_static->ref = $obj->rowid; - print '\n"; - - print '\n"; - print '"; - print "\n"; - - $i++; - } - print ''; - print ''; - print ''; - print ''; - print '"; - print ""; - - print "
'.dol_print_date($db->jdate($obj->dm), 'day').'".$obj->label."'.price($obj->amount)."'.$tva_static->getNomUrl(1)."'.dol_print_date($db->jdate($obj->dm), 'day')."'.price($obj->amount)."
'.$langs->trans("Total").''.price($total).'  '.price($total)."
"; - $db->free($result); - } - else { - dol_print_error($db); - } - } -} - -// Localtax -if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") -{ - $j = 1; - $numlt = 3; -} -elseif ($mysoc->localtax1_assuj == "1") -{ - $j = 1; - $numlt = 2; -} -elseif ($mysoc->localtax2_assuj == "1") -{ - $j = 2; - $numlt = 3; -} -else { - $j = 0; - $numlt = 0; -} - -while ($j < $numlt) -{ - if (!$mode || $mode != 'tvaonly') - { - print "
"; - - $tva = new Tva($db); - - print load_fiche_titre($langs->transcountry(($j == 1 ? "LT1Payments" : "LT2Payments"), $mysoc->country_code).($year ? ' ('.$langs->trans("Year").' '.$year.')' : ''), '', ''); - - - $sql = "SELECT pv.rowid, pv.amount, pv.label, pv.datev as dm, pv.datep as dp"; - $sql .= " FROM ".MAIN_DB_PREFIX."localtax as pv"; - $sql .= " WHERE pv.entity = ".$conf->entity." AND localtaxtype = ".$j; - if ($year > 0) - { - // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance, - // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire - $sql .= " AND pv.datev between '".$db->idate(dol_get_first_day($year, 1, false))."' AND '".$db->idate(dol_get_last_day($year, 12, false))."'"; - } - if (preg_match('/^pv/', $sortfield)) $sql .= $db->order($sortfield, $sortorder); - - $result = $db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - $i = 0; - $total = 0; - print ''; - print ''; - print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "pv.datev", "", $param, 'width="120"', $sortfield, $sortorder); - print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "pv.label", "", $param, '', $sortfield, $sortorder); - print_liste_field_titre("ExpectedToPay", $_SERVER["PHP_SELF"], "pv.amount", "", $param, 'class="right"', $sortfield, $sortorder); - print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "pv.rowid", "", $param, '', $sortfield, $sortorder); - print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "pv.datep", "", $param, 'align="center"', $sortfield, $sortorder); - print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "pv.amount", "", $param, 'class="right"', $sortfield, $sortorder); - print "\n"; - - while ($i < $num) - { - $obj = $db->fetch_object($result); - - $total = $total + $obj->amount; - - print ''; - print ''."\n"; - - print "\n"; - - print '"; - - // Ref payment - $tva_static->id = $obj->rowid; - $tva_static->ref = $obj->rowid; - print '\n"; - - print '\n"; - print '"; - print "\n"; - - $i++; - } - print ''; - print '"; - print ''; - print ''; - print '"; - print ""; - - print "
'.dol_print_date($db->jdate($obj->dm), 'day').'".$obj->label."'.price($obj->amount)."'.$tva_static->getNomUrl(1)."'.dol_print_date($db->jdate($obj->dp), 'day')."'.price($obj->amount)."
'.$langs->trans("Total").''.price($total)."  '.price($total)."
"; - $db->free($result); - } - else { - dol_print_error($db); - } - } - $j++; -} - - -// Payment Salary -if (!empty($conf->salaries->enabled) && !empty($user->rights->salaries->read)) -{ - if (!$mode || $mode != 'tvaonly') - { - $sal = new PaymentSalary($db); - - print "
"; - - print load_fiche_titre($langs->trans("SalariesPayments").($year ? ' ('.$langs->trans("Year").' '.$year.')' : ''), '', ''); - - $sql = "SELECT s.rowid, s.amount, s.label, s.datep as datep, s.datev as datev, s.datesp, s.dateep, s.salary, u.salary as current_salary"; - $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as s, ".MAIN_DB_PREFIX."user as u"; - $sql .= " WHERE s.entity IN (".getEntity('user').")"; - $sql .= " AND u.rowid = s.fk_user"; - if ($year > 0) - { - $sql .= " AND (s.datesp between '".$db->idate(dol_get_first_day($year, 1, false))."' AND '".$db->idate(dol_get_last_day($year, 12, false))."'"; - $sql .= " OR s.dateep between '".$db->idate(dol_get_first_day($year, 1, false))."' AND '".$db->idate(dol_get_last_day($year, 12, false))."')"; - } - if (preg_match('/^s\./', $sortfield)) $sql .= $db->order($sortfield, $sortorder); - - $result = $db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - $i = 0; - $total = 0; - print ''; - print ''; - print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "s.dateep", "", $param, 'width="140px"', $sortfield, $sortorder); - print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "s.label", "", $param, '', $sortfield, $sortorder); - print_liste_field_titre("ExpectedToPay", $_SERVER["PHP_SELF"], "s.amount", "", $param, 'class="right"', $sortfield, $sortorder); - print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "s.rowid", "", $param, '', $sortfield, $sortorder); - print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "s.datep", "", $param, 'align="center"', $sortfield, $sortorder); - print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "s.amount", "", $param, 'class="right"', $sortfield, $sortorder); - print "\n"; - - while ($i < $num) - { - $obj = $db->fetch_object($result); - - $total = $total + $obj->amount; - - print ''; - - print ''."\n"; - - print "\n"; - - print '"; - - // Ref payment - $sal_static->id = $obj->rowid; - $sal_static->ref = $obj->rowid; - print '\n"; - - print '\n"; - print '"; - print "\n"; - - $i++; - } - print ''; - print ''; // A total here has no sense - print ''; - print ''; - print '"; - print ""; - - print "
'.dol_print_date($db->jdate($obj->dateep), 'day').'".$obj->label."'.($obj->salary ?price($obj->salary) : '')."'.$sal_static->getNomUrl(1)."'.dol_print_date($db->jdate($obj->datep), 'day')."'.price($obj->amount)."
'.$langs->trans("Total").'  '.price($total)."
"; - $db->free($result); - - print "
"; - } - else { - dol_print_error($db); - } - } + print '
'; } print '
';