Fix: Can add ban record but was not possible to delete
This commit is contained in:
parent
628e8bea83
commit
8e313ef32d
@ -2358,7 +2358,7 @@ function dol_print_error_email($prefixcode)
|
||||
* @param string $field Field to use for new sorting
|
||||
* @param string $begin ("" by defaut)
|
||||
* @param string $moreparam Add more parameters on sort url links ("" by default)
|
||||
* @param string $td Options of attribute td ("" by defaut)
|
||||
* @param string $td Options of attribute td ("" by defaut, example: 'align="center"')
|
||||
* @param string $sortfield Current field used to sort
|
||||
* @param string $sortorder Current sort order
|
||||
* @return void
|
||||
|
||||
@ -154,3 +154,5 @@ DefaultRIB=Default BAN
|
||||
AllRIB=All BAN
|
||||
LabelRIB=BAN Label
|
||||
NoBANRecord=No BAN record
|
||||
DeleteARib=Delete BAN record
|
||||
ConfirmDeleteRib=Are you sure you want to delete this BAN record ?
|
||||
|
||||
@ -154,3 +154,5 @@ DefaultRIB=RIB par défaut
|
||||
AllRIB=Tous les RIB
|
||||
LabelRIB=Nom du RIB
|
||||
NoBANRecord=Aucun RIB enregistré
|
||||
DeleteARib=Supprimé RIB enregistré
|
||||
ConfirmDeleteRib=Etes vous sur de vouloir supprimé ce RIB ?
|
||||
|
||||
@ -77,13 +77,23 @@ class CompanyBankAccount extends Account
|
||||
{
|
||||
$now=dol_now();
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_rib (fk_soc, datec) values ($this->socid, '".$this->db->idate($now)."')";
|
||||
// Correct default_rib to be sure to have always one default
|
||||
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_rib where fk_soc = ".$this->socid." AND default_rib = 1";
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$numrows=$this->db->num_rows($result);
|
||||
if ($this->default_rib && $numrows > 0) $this->default_rib = 0;
|
||||
if (empty($this->default_rib) && $numrows == 0) $this->default_rib = 1;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_rib (fk_soc, datec)";
|
||||
$sql.= " VALUES (".$this->socid.", '".$this->db->idate($now)."')";
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($this->db->affected_rows($resql))
|
||||
{
|
||||
$this->default_rib = 1;
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_rib");
|
||||
return 1;
|
||||
}
|
||||
@ -120,7 +130,7 @@ class CompanyBankAccount extends Account
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
if (!$this->id) {
|
||||
if (! $this->id) {
|
||||
$this->create();
|
||||
}
|
||||
|
||||
@ -204,6 +214,30 @@ class CompanyBankAccount extends Account
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a rib from database
|
||||
*
|
||||
* @param User $user User deleting
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function delete($user)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_rib";
|
||||
$sql.= " WHERE rowid = ".$this->id;
|
||||
|
||||
dol_syslog(get_class($this)."::delete sql=".$sql);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
dol_print_error($this->db);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return RIB
|
||||
*
|
||||
|
||||
@ -31,11 +31,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
|
||||
|
||||
$langs->load("companies");
|
||||
$langs->load("commercial");
|
||||
$langs->load("banks");
|
||||
$langs->load("bills");
|
||||
|
||||
// Security check
|
||||
$socid = isset($_GET["socid"])?$_GET["socid"]:'';
|
||||
$socid = GETPOST("socid");
|
||||
if ($user->societe_id) $socid=$user->societe_id;
|
||||
$result = restrictedArea($user, 'societe','','');
|
||||
|
||||
@ -43,17 +44,21 @@ $soc = new Societe($db);
|
||||
$soc->id = $_GET["socid"];
|
||||
$soc->fetch($_GET["socid"]);
|
||||
|
||||
$id=GETPOST("id","int");
|
||||
$ribid=GETPOST("ribid","int");
|
||||
$action=GETPOST("action");
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
if ($_POST["action"] == 'update' && ! $_POST["cancel"])
|
||||
if ($action == 'update' && ! $_POST["cancel"])
|
||||
{
|
||||
// Modification
|
||||
$account = new CompanyBankAccount($db);
|
||||
|
||||
$account->fetch($_POST["id"]);
|
||||
$account->fetch($id);
|
||||
|
||||
$account->socid = $soc->id;
|
||||
|
||||
@ -85,7 +90,7 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"])
|
||||
}
|
||||
}
|
||||
|
||||
if ($_POST["action"] == 'add' && ! $_POST["cancel"])
|
||||
if ($action == 'add' && ! $_POST["cancel"])
|
||||
{
|
||||
// Ajout
|
||||
$account = new CompanyBankAccount($db);
|
||||
@ -106,7 +111,7 @@ if ($_POST["action"] == 'add' && ! $_POST["cancel"])
|
||||
$account->proprio = $_POST["proprio"];
|
||||
$account->owner_address = $_POST["owner_address"];
|
||||
|
||||
$result = $account->update($user);
|
||||
$result = $account->update($user); // TODO Use create and include update into create method
|
||||
if (! $result)
|
||||
{
|
||||
$message=$account->error;
|
||||
@ -120,10 +125,10 @@ if ($_POST["action"] == 'add' && ! $_POST["cancel"])
|
||||
}
|
||||
}
|
||||
|
||||
if ($_GET['action'] == 'setasdefault')
|
||||
if ($action == 'setasdefault')
|
||||
{
|
||||
$account = new CompanyBankAccount($db);
|
||||
$res = $account->setAsDefault($_GET['ribid']);
|
||||
$res = $account->setAsDefault(GETPOST('ribid','int'));
|
||||
if ($res) {
|
||||
$url=DOL_URL_ROOT.'/societe/rib.php?socid='.$soc->id;
|
||||
header('Location: '.$url);
|
||||
@ -133,10 +138,35 @@ if ($_GET['action'] == 'setasdefault')
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == 'confirm_delete' && $_GET['confirm'] == 'yes')
|
||||
{
|
||||
$account = new CompanyBankAccount($db);
|
||||
if ($account->fetch($ribid?$ribid:$id))
|
||||
{
|
||||
$result = $account->delete($user);
|
||||
if ($result > 0)
|
||||
{
|
||||
$url = $_SERVER['PHP_SELF']."?socid=".$soc->id;
|
||||
header('Location: '.$url);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = $account->error;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = $account->error;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
$form = new Form($db);
|
||||
|
||||
llxHeader();
|
||||
|
||||
$head=societe_prepare_head2($soc);
|
||||
@ -144,10 +174,10 @@ $head=societe_prepare_head2($soc);
|
||||
dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company');
|
||||
|
||||
$account = new CompanyBankAccount($db);
|
||||
if (!$_GET['id'])
|
||||
if (! $id)
|
||||
$account->fetch(0,$soc->id);
|
||||
else
|
||||
$account->fetch($_GET['id']);
|
||||
$account->fetch($id);
|
||||
if (empty($account->socid)) $account->socid=$soc->id;
|
||||
|
||||
|
||||
@ -158,10 +188,17 @@ if (empty($account->socid)) $account->socid=$soc->id;
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
if ($_GET["socid"] && $_GET["action"] != 'edit' && $_GET["action"] != "create")
|
||||
if ($socid && $action != 'edit' && $action != "create")
|
||||
{
|
||||
// Confirm delete third party
|
||||
if ($action == 'delete')
|
||||
{
|
||||
print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$soc->id."&ribid=".($ribid?$ribid:$id), $langs->trans("DeleteARib"), $langs->trans("ConfirmDeleteRib", $account->getRibLabel()), "confirm_delete", '', 0, 1);
|
||||
}
|
||||
|
||||
print_titre($langs->trans("DefaultRIB"));
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
print '<tr><td>'.$langs->trans("LabelRIB").'</td>';
|
||||
print '<td colspan="4">'.$account->label.'</td></tr>';
|
||||
@ -236,11 +273,12 @@ if ($_GET["socid"] && $_GET["action"] != 'edit' && $_GET["action"] != "create")
|
||||
print_liste_field_titre($langs->trans("LabelRIB"));
|
||||
print_liste_field_titre($langs->trans("Bank"));
|
||||
print_liste_field_titre($langs->trans("RIB"));
|
||||
print_liste_field_titre($langs->trans("DefaultRIB"));
|
||||
print_liste_field_titre($langs->trans("DefaultRIB"), '', '', '', '', 'align="center"');
|
||||
print '<td width="40"></td>';
|
||||
print '</tr>';
|
||||
|
||||
foreach ($rib_list as $rib) {
|
||||
foreach ($rib_list as $rib)
|
||||
{
|
||||
print "<tr $bc[$var]>";
|
||||
print '<td>'.$rib->label.'</td>';
|
||||
print '<td>'.$rib->bank.'</td>';
|
||||
@ -248,16 +286,26 @@ if ($_GET["socid"] && $_GET["action"] != 'edit' && $_GET["action"] != "create")
|
||||
print '<td align="center" width="70">';
|
||||
if (!$rib->default_rib) {
|
||||
print '<a href="'.DOL_URL_ROOT.'/societe/rib.php?socid='.$soc->id.'&ribid='.$rib->id.'&action=setasdefault">';
|
||||
print img_picto($langs->trans("Disabled"),'switch_off');
|
||||
print img_picto($langs->trans("Disabled"),'off');
|
||||
print '</a>';
|
||||
} else {
|
||||
print img_picto($langs->trans("Enabled"),'switch_on');
|
||||
print img_picto($langs->trans("Enabled"),'on');
|
||||
}
|
||||
print '</td>';
|
||||
print '<td align="right">';
|
||||
print '<a href="'.DOL_URL_ROOT.'/societe/rib.php?socid='.$soc->id.'&id='.$rib->id.'&action=edit">';
|
||||
print img_picto($langs->trans("Modify"),'edit');
|
||||
print '</a>';
|
||||
if ($user->rights->societe->creer)
|
||||
{
|
||||
print '<a href="'.DOL_URL_ROOT.'/societe/rib.php?socid='.$soc->id.'&id='.$rib->id.'&action=edit">';
|
||||
print img_picto($langs->trans("Modify"),'edit');
|
||||
print '</a>';
|
||||
|
||||
print ' ';
|
||||
|
||||
print '<a href="'.DOL_URL_ROOT.'/societe/rib.php?socid='.$soc->id.'&id='.$rib->id.'&action=delete">';
|
||||
print img_picto($langs->trans("Delete"),'delete');
|
||||
print '</a>';
|
||||
}
|
||||
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
$var = !$var;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user