Fix creation/edit rum number

This commit is contained in:
Laurent Destailleur 2017-10-11 23:43:42 +02:00
parent 918738ce46
commit 8674867db2
2 changed files with 77 additions and 60 deletions

View File

@ -105,13 +105,11 @@ class CompanyBankAccount extends Account
{ {
return 0; return 0;
} }
} }
else else
{ {
return 1; return 1;
} }
} }
} }
else else
@ -133,11 +131,7 @@ class CompanyBankAccount extends Account
global $conf; global $conf;
$error = 0; $error = 0;
if (! $this->id) return -1;
if (! $this->id)
{
$this->create();
}
if (dol_strlen($this->domiciliation) > 255) $this->domiciliation = dol_trunc($this->domiciliation, 254, 'right', 'UTF-8', 1); if (dol_strlen($this->domiciliation) > 255) $this->domiciliation = dol_trunc($this->domiciliation, 254, 'right', 'UTF-8', 1);
if (dol_strlen($this->owner_address) > 255) $this->owner_address = dol_trunc($this->owner_address, 254, 'right', 'UTF-8', 1); if (dol_strlen($this->owner_address) > 255) $this->owner_address = dol_trunc($this->owner_address, 254, 'right', 'UTF-8', 1);

View File

@ -207,6 +207,8 @@ if (empty($reshook))
$account->rum = GETPOST('rum','alpha'); $account->rum = GETPOST('rum','alpha');
$account->datec = dol_now(); $account->datec = dol_now();
$db->begin();
// This test can be done only once properties were set // This test can be done only once properties were set
if ($account->needIBAN() == 1) if ($account->needIBAN() == 1)
{ {
@ -226,25 +228,43 @@ if (empty($reshook))
if (! $error) if (! $error)
{ {
$result = $account->create($user);
if ($result < 0)
{
$error++;
setEventMessages($account->error, $account->errors, 'errors');
$action='create'; // Force chargement page création
}
if (empty($account->rum)) if (empty($account->rum))
{ {
$account->rum = $prelevement->buildRumNumber($object->code_client, $account->datec, $account->id); $account->rum = $prelevement->buildRumNumber($object->code_client, $account->datec, $account->id);
$account->date_rum = dol_now(); $account->date_rum = dol_now();
} }
$result = $account->update($user); // This will set the UMR number.
// TODO Use create and include update into create method
if (! $result)
{
setEventMessages($account->error, $account->errors, 'errors');
$_GET["action"]='create'; // Force chargement page création
} }
else
if (! $error)
{ {
$result = $account->update($user); // This will set the UMR number.
if ($result < 0)
{
$error++;
setEventMessages($account->error, $account->errors, 'errors');
$action='create';
}
}
if (! $error)
{
$db->commit();
$url=DOL_URL_ROOT.'/societe/rib.php?socid='.$object->id; $url=DOL_URL_ROOT.'/societe/rib.php?socid='.$object->id;
header('Location: '.$url); header('Location: '.$url);
exit; exit;
} }
else
{
$db->rollback();
} }
} }
} }
@ -321,11 +341,14 @@ $formfile = new FormFile($db);
llxHeader(); llxHeader();
$head=societe_prepare_head($object); $head=societe_prepare_head($object);
if (! $id) if (! $id)
{
$account->fetch(0,$object->id); $account->fetch(0,$object->id);
}
else else
{
$account->fetch($id); $account->fetch($id);
}
if (empty($account->socid)) $account->socid=$object->id; if (empty($account->socid)) $account->socid=$object->id;
if ($socid && $action == 'edit' && $user->rights->societe->creer) if ($socid && $action == 'edit' && $user->rights->societe->creer)
@ -775,7 +798,7 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer)
// RUM // RUM
print '<tr><td class="titlefield">'.$langs->trans("RUM").'</td>'; print '<tr><td class="titlefield">'.$langs->trans("RUM").'</td>';
print '<td><input size="30" type="text" name="rum" value="'.dol_escape_htmltag($account->rum).'"></td></tr>'; print '<td><input class="minwidth300" type="text" name="rum" value="'.dol_escape_htmltag($account->rum).'"></td></tr>';
print '<tr><td>'.$langs->trans("WithdrawMode").'</td><td>'; print '<tr><td>'.$langs->trans("WithdrawMode").'</td><td>';
$tblArraychoice = array("FRST" => $langs->trans("FRST"), "RECUR" => $langs->trans("RECUR")); $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RECUR" => $langs->trans("RECUR"));
@ -872,7 +895,7 @@ if ($socid && $action == 'create' && $user->rights->societe->creer)
// RUM // RUM
print '<tr><td class="titlefieldcreate">'.$langs->trans("RUM").'</td>'; print '<tr><td class="titlefieldcreate">'.$langs->trans("RUM").'</td>';
print '<td colspan="4"><input size="30" type="text" name="rum" value="'.dol_escape_htmltag($account->rum).'"><br>'.$langs->trans("RUMWillBeGenerated").'</td></tr>'; print '<td colspan="4"><input type="text" class="minwidth300" name="rum" value="'.GETPOST('rum','alpha').'"><br>'.$langs->trans("RUMWillBeGenerated").'</td></tr>';
print '<tr><td>'.$langs->trans("WithdrawMode").'</td><td>'; print '<tr><td>'.$langs->trans("WithdrawMode").'</td><td>';
$tblArraychoice = array("FRST" => $langs->trans("FRST"), "RECUR" => $langs->trans("RECUR")); $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RECUR" => $langs->trans("RECUR"));