dolibarr/htdocs/compta/bank/categ.php

167 lines
5.3 KiB
PHP
Raw Normal View History

2013-05-08 09:28:05 +02:00
<?php
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
2018-10-27 14:43:12 +02:00
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
2015-04-18 23:11:17 +02:00
* Copyright (C) 2013 Charles-Fr BENKE <charles.fr@benke.fr>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
2013-05-08 09:28:05 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2013-05-08 09:28:05 +02:00
*/
/**
* \file htdocs/compta/bank/categ.php
* \ingroup compta
* \brief Page ajout de categories bancaires
*/
2018-07-26 11:57:25 +02:00
require '../../main.inc.php';
2013-05-08 09:28:05 +02:00
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
2013-05-08 09:28:05 +02:00
2018-05-27 09:40:17 +02:00
// Load translation files required by the page
$langs->loadLangs(array('banks', 'categories'));
2013-05-08 09:28:05 +02:00
$action = GETPOST('action', 'aZ09');
$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
2021-02-23 21:09:01 +01:00
if (!$user->rights->banque->configurer) {
accessforbidden();
}
2013-05-08 09:28:05 +02:00
$bankcateg = new BankCateg($db);
$categid = GETPOST('categid');
$label = GETPOST("label");
2013-05-08 09:28:05 +02:00
2020-10-16 13:30:20 +02:00
2013-05-08 09:28:05 +02:00
/*
2020-10-16 13:30:20 +02:00
* Actions
*/
2020-10-16 13:30:20 +02:00
2021-02-23 21:09:01 +01:00
if (GETPOST('add')) {
if ($label) {
$bankcateg = new BankCateg($db);
$bankcateg->label = GETPOST('label');
$bankcateg->create($user);
2013-05-08 09:28:05 +02:00
}
}
if ($categid) {
$bankcateg = new BankCateg($db);
if ($bankcateg->fetch($categid) > 0) {
//Update category
if (GETPOST('update') && $label) {
$bankcateg->label = $label;
$bankcateg->update($user);
2013-05-08 09:28:05 +02:00
}
//Delete category
if ($action == 'delete') {
$bankcateg->delete($user);
2013-05-08 09:28:05 +02:00
}
}
}
/*
* View
2013-05-08 09:28:05 +02:00
*/
$title = $langs->trans('RubriquesTransactions');
$help_url = 'EN:Module_Banks_and_Cash|FR:Module_Banques_et_Caisses|ES:M&oacute;dulo_Bancos_y_Cajas';
llxHeader('', $title, $help_url);
2013-05-08 09:28:05 +02:00
2020-04-09 16:36:39 +02:00
print load_fiche_titre($langs->trans("RubriquesTransactions"), '', 'object_category');
2013-05-08 09:28:05 +02:00
2013-06-05 16:24:32 +02:00
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
2021-02-23 21:09:01 +01:00
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
/*print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="page" value="'.$page.'">';
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
*/
print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">';
2013-05-08 09:28:05 +02:00
print '<tr class="liste_titre">';
2020-10-16 13:30:20 +02:00
print '<td>'.$langs->trans("Ref").'</td><td>'.$langs->trans("Label").'</td>';
print '<td></td>';
print '<td></td>';
2013-05-08 09:28:05 +02:00
print "</tr>\n";
// Line to add category
2021-02-23 21:09:01 +01:00
if ($action != 'edit') {
print '<tr class="oddeven">';
2020-10-16 13:30:20 +02:00
print '<td>&nbsp;</td><td><input name="label" type="text" class="maxwidth100"></td>';
print '<td></td>';
2022-06-09 11:47:29 +02:00
print '<td class="center"><input type="submit" name="add" class="button button-add small" value="'.$langs->trans("Add").'"></td>';
print '</tr>';
}
$sql = "SELECT rowid, label";
$sql .= " FROM ".MAIN_DB_PREFIX."bank_categ";
$sql .= " WHERE entity = ".$conf->entity;
2020-10-16 13:30:20 +02:00
$sql .= " ORDER BY rowid";
$result = $db->query($sql);
2021-02-23 21:09:01 +01:00
if ($result) {
$num = $db->num_rows($result);
2021-03-01 20:37:16 +01:00
$i = 0;
$total = 0;
2021-02-23 21:09:01 +01:00
while ($i < $num) {
$objp = $db->fetch_object($result);
2018-04-22 19:27:37 +02:00
print '<tr class="oddeven">';
2020-10-16 13:30:20 +02:00
print '<td>'.$objp->rowid.'</td>';
2021-02-23 21:09:01 +01:00
if (GETPOST('action', 'aZ09') == 'edit' && GETPOST("categid") == $objp->rowid) {
2020-10-16 13:30:20 +02:00
print '<td colspan="3">';
print '<input type="hidden" name="categid" value="'.$objp->rowid.'">';
print '<input name="label" type="text" size=45 value="'.$objp->label.'">';
print '<input type="submit" name="update" class="button" value="'.$langs->trans("Edit").'">';
print "</td>";
2020-05-21 15:05:19 +02:00
} else {
2020-10-16 13:30:20 +02:00
print "<td>".$objp->label."</td>";
print '<td>';
//print '<a href="'.DOL_URL_ROOT.'/compta/bank/budget.php?bid='.$objp->rowid.'">'.$langs->trans("List").'</a>';
print '</td>';
2020-05-17 13:34:16 +02:00
print '<td class="center">';
print '<a class="editfielda reposition marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
2019-10-06 15:34:22 +02:00
print '</td>';
}
print "</tr>";
$i++;
}
$db->free($result);
2013-05-08 09:28:05 +02:00
}
print '</table>';
print '</div>';
print '</form>';
2013-05-08 09:28:05 +02:00
2018-07-29 19:16:28 +02:00
// End of page
2013-05-08 09:28:05 +02:00
llxFooter();
2018-07-29 19:16:28 +02:00
$db->close();