Skip to content

Commit

Permalink
FIX Navigation between bank receipts
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Aug 27, 2023
1 parent 0e056bc commit 19f85c6
Showing 1 changed file with 82 additions and 55 deletions.
137 changes: 82 additions & 55 deletions htdocs/compta/bank/releve.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('bankaccountstatement', 'globalcard'));

if ($user->rights->banque->consolidate && $action == 'dvnext' && !empty($dvid)) {
if ($user->hasRight('banque', 'consolidate') && $action == 'dvnext' && !empty($dvid)) {
$al = new AccountLine($db);
$al->datev_next($dvid);
}

if ($user->rights->banque->consolidate && $action == 'dvprev' && !empty($dvid)) {
if ($user->hasRight('banque', 'consolidate') && $action == 'dvprev' && !empty($dvid)) {
$al = new AccountLine($db);
$al->datev_previous($dvid);
}
Expand Down Expand Up @@ -104,11 +104,9 @@
$id = $object->id; // Force the search field on id of account
}


// Initialize technical object to manage context to save list fields
$contextpage = 'banktransactionlist'.(empty($object->ref) ? '' : '-'.$object->id);


// Security check
$fieldid = (!empty($ref) ? $ref : $id);
$fieldname = (!empty($ref) ? 'ref' : 'rowid');
Expand All @@ -118,60 +116,63 @@

$result = restrictedArea($user, 'banque', $fieldid, 'bank_account', '', '', $fieldname);

$error = 0;

// Define number of receipt to show (current, previous or next one ?)
$found = false;
if ($rel == 'prev') {
// Recherche valeur pour num = numero releve precedent
$sql = "SELECT DISTINCT(b.num_releve) as num";
$sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
$sql .= " WHERE b.num_releve < '".$db->escape($numref)."'";
$sql .= " AND b.fk_account = ".((int) $object->id);
$sql .= " AND d.entity IN (".getEntity($object->element).")";
$sql .= " ORDER BY b.num_releve DESC";

dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql) {
$numrows = $db->num_rows($resql);
if ($numrows > 0) {
$obj = $db->fetch_object($resql);
$foundprevious = '';
$foundnext = '';
// Search previous receipt number
$sql = "SELECT b.num_releve as num";
$sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
$sql .= " WHERE b.num_releve < '".$db->escape($numref)."'";
$sql .= " AND b.fk_account = ".((int) $object->id);
$sql .= " ORDER BY b.num_releve DESC";
$sql .= $db->plimit(1);

dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql) {
$numrows = $db->num_rows($resql);
if ($numrows > 0) {
$obj = $db->fetch_object($resql);
if ($rel == 'prev') {
$numref = $obj->num;
$found = true;
}
$foundprevious = $obj->num;
}
} elseif ($rel == 'next') {
// Recherche valeur pour num = numero releve precedent
$sql = "SELECT DISTINCT(b.num_releve) as num";
$sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
$sql .= " WHERE b.num_releve > '".$db->escape($numref)."'";
$sql .= " AND b.fk_account = ".((int) $object->id);
$sql .= " AND d.entity IN (".getEntity($object->element).")";
$sql .= " ORDER BY b.num_releve ASC";

dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql) {
$numrows = $db->num_rows($resql);
if ($numrows > 0) {
$obj = $db->fetch_object($resql);
} else {
dol_print_error($db);
}
// Search next receipt
$sql = "SELECT b.num_releve as num";
$sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
$sql .= " WHERE b.num_releve > '".$db->escape($numref)."'";
$sql .= " AND b.fk_account = ".((int) $object->id);
$sql .= " ORDER BY b.num_releve ASC";
$sql .= $db->plimit(1);

dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql) {
$numrows = $db->num_rows($resql);
if ($numrows > 0) {
$obj = $db->fetch_object($resql);
if ($rel == 'next') {
$numref = $obj->num;
$found = true;
}
$foundnext = $obj->num;
}
} else {
// On veut le releve num
$found = true;
dol_print_error($db);
}


$sql = "SELECT b.rowid, b.dateo as do, b.datev as dv,";
$sql .= " b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,";
$sql .= " b.fk_bordereau,";
$sql .= " bc.ref,";
$sql .= " ba.rowid as bankid, ba.ref as bankref, ba.label as banklabel";
$sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
$sql .= ", ".MAIN_DB_PREFIX."bank as b";
$sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba,";
$sql .= " ".MAIN_DB_PREFIX."bank as b";
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bordereau_cheque as bc ON bc.rowid=b.fk_bordereau';
$sql .= " WHERE b.num_releve = '".$db->escape($numref)."'";
if (empty($numref)) {
Expand All @@ -190,22 +191,42 @@
*/

if ($action == 'confirm_editbankreceipt' && !empty($oldbankreceipt) && !empty($newbankreceipt)) {
// TODO Add a test to check newbankreceipt does not exists yet
$sqlupdate = "UPDATE ".MAIN_DB_PREFIX."bank SET num_releve = '".$db->escape($newbankreceipt)."'";
$sqlupdate .= " WHERE num_releve = '".$db->escape($oldbankreceipt)."' AND fk_account = ".((int) $id);
$sqlupdate .= " AND entity IN (".getEntity($object->element).")";
$result = $db->query($sqlupdate);
if ($result < 0) {
// Test to check newbankreceipt does not exists yet
$sqltest = "SELECT b.rowid FROM ".MAIN_DB_PREFIX."bank as b, ".MAIN_DB_PREFIX."bank_account as ba";
$sqltest .= " WHERE b.fk_account = ba.rowid AND ba.entity = ".((int) $conf->entity);
$sqltest .= " AND num_releve = '".$db->escape($newbankreceipt)."'";
$sqltest .= $db->plimit(1); // Need the first one only

$resql = $db->query($sqltest);
if ($resql) {
$obj = $db->fetch_object($resql);
if ($obj && $obj->rowid) {
setEventMessages('ErrorThisBankReceiptIsAlreadyUsed', null, 'errors');
$error++;
}
} else {
dol_print_error($db);
}

// Update bank receipt name
if (!$error) {
$sqlupdate = "UPDATE ".MAIN_DB_PREFIX."bank SET num_releve = '".$db->escape($newbankreceipt)."'";
$sqlupdate .= " WHERE num_releve = '".$db->escape($oldbankreceipt)."' AND fk_account = ".((int) $id);

$resql = $db->query($sqlupdate);
if (!$resql) {
dol_print_error($db);
}
}

$action = 'view';
}


/*
* View
*/

$form = new Form($db);
$societestatic = new Societe($db);
$chargestatic = new ChargeSociales($db);
Expand Down Expand Up @@ -293,7 +314,7 @@
}

// If not cash account and can be reconciliate
if ($user->rights->banque->consolidate) {
if ($user->hasRight('banque', 'consolidate')) {
$buttonreconcile = '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?action=reconcile&sortfield=b.datev,b.dateo,b.rowid&sortorder=asc,asc,asc&search_conciliated=0&search_account='.$id.$param.'">'.$titletoconciliatemanual.'</a>';
} else {
$buttonreconcile = '<a class="butActionRefused classfortooltip" title="'.$langs->trans("NotEnoughPermissions").'" href="#">'.$titletoconciliatemanual.'</a>';
Expand All @@ -302,7 +323,7 @@

if ($allowautomaticconciliation) {
// If not cash account and can be reconciliate
if ($user->rights->banque->consolidate) {
if ($user->hasRight('banque', 'consolidate')) {
$newparam = $param;
$newparam = preg_replace('/search_conciliated=\d+/i', '', $newparam);
$buttonreconcile .= ' <a class="butAction" style="margin-bottom: 5px !important; margin-top: 5px !important" href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?action=reconcile&sortfield=b.datev,b.dateo,b.rowid&sortorder=asc,asc,asc&search_conciliated=0'.$newparam.'">'.$titletoconciliateauto.'</a>';
Expand Down Expand Up @@ -350,8 +371,8 @@
} else {
print '<input type="hidden" name="oldbankreceipt" value="'.$objp->numr.'">';
print '<input type="text" name="newbankreceipt" value="'.$objp->numr.'">';
print '<input type="submit" class="button small" name="actionnewbankreceipt" value="'.$langs->trans("Rename").'">';
print '<input type="submit" class="button button-cancel small" name="cancel" value="'.$langs->trans("Cancel").'">';
print '<input type="submit" class="button smallpaddingimp" name="actionnewbankreceipt" value="'.$langs->trans("Rename").'">';
print '<input type="submit" class="button button-cancel smallpaddingimp" name="cancel" value="'.$langs->trans("Cancel").'">';
}
print '</td>';

Expand Down Expand Up @@ -410,9 +431,13 @@

$morehtmlright = '';
$morehtmlright .= '<div class="pagination"><ul>';
$morehtmlright .= '<li class="pagination"><a class="paginationnext" href="'.$_SERVER["PHP_SELF"].'?rel=prev&amp;num='.$numref.'&amp;ve='.$ve.'&amp;account='.$object->id.'"><i class="fa fa-chevron-left" title="'.dol_escape_htmltag($langs->trans("Previous")).'"></i></a></li>';
if ($foundprevious) {
$morehtmlright .= '<li class="pagination"><a class="paginationnext" href="'.$_SERVER["PHP_SELF"].'?num='.urlencode($foundprevious).'&amp;ve='.urlencode($ve).'&amp;account='.((int) $object->id).'"><i class="fa fa-chevron-left" title="'.dol_escape_htmltag($langs->trans("Previous")).'"></i></a></li>';
}
$morehtmlright .= '<li class="pagination"><span class="active">'.$langs->trans("AccountStatement")." ".$numref.'</span></li>';
$morehtmlright .= '<li class="pagination"><a class="paginationnext" href="'.$_SERVER["PHP_SELF"].'?rel=next&amp;num='.$numref.'&amp;ve='.$ve.'&amp;account='.$object->id.'"><i class="fa fa-chevron-right" title="'.dol_escape_htmltag($langs->trans("Next")).'"></i></a></li>';
if ($foundnext) {
$morehtmlright .= '<li class="pagination"><a class="paginationnext" href="'.$_SERVER["PHP_SELF"].'?num='.urlencode($foundnext).'&amp;ve='.urlencode($ve).'&amp;account='.((int) $object->id).'"><i class="fa fa-chevron-right" title="'.dol_escape_htmltag($langs->trans("Next")).'"></i></a></li>';
}
$morehtmlright .= '</ul></div>';

$title = $langs->trans("AccountStatement").' '.$numref.' - '.$langs->trans("BankAccount").' '.$object->getNomUrl(1, 'receipts');
Expand Down Expand Up @@ -448,6 +473,8 @@
$db->free($resql);
}

$totalc = $totald = 0;

// Recherche les ecritures pour le releve
$sql = $sqlrequestforbankline;

Expand Down Expand Up @@ -671,7 +698,7 @@
}

// Line Total
print "\n".'<tr class="liste_total"><td class="right" colspan="4">'.$langs->trans("Total")." :</td><td class=\"right\">".price($totald)."</td><td class=\"right\">".price($totalc)."</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
print "\n".'<tr class="liste_total"><td class="right" colspan="4">'.$langs->trans("Total").' :</td><td class="right">'.price($totald).'</td><td class="right">'.price($totalc)."</td><td>&nbsp;</td><td>&nbsp;</td></tr>";

// Line Balance
print "\n<tr>";
Expand Down

0 comments on commit 19f85c6

Please sign in to comment.