From c86183e18c6739a33dc68b753f5eb1805faa3cee Mon Sep 17 00:00:00 2001 From: Regis Houssin <regis@dolibarr.fr> Date: Mon, 13 Feb 2012 14:49:20 +0100 Subject: [PATCH] Fix: uniformize code and force paiement type if cash account --- htdocs/compta/bank/account.php | 150 ++++++++++++++++----------------- htdocs/core/lib/bank.lib.php | 5 +- 2 files changed, 74 insertions(+), 81 deletions(-) diff --git a/htdocs/compta/bank/account.php b/htdocs/compta/bank/account.php index ddc4569fbcc..2a39c68ae91 100644 --- a/htdocs/compta/bank/account.php +++ b/htdocs/compta/bank/account.php @@ -3,7 +3,7 @@ * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org> * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net> * Copytight (C) 2004 Christophe Combelles <ccomb@free.fr> - * Copytight (C) 2005-2011 Regis Houssin <regis@dolibarr.fr> + * Copytight (C) 2005-2012 Regis Houssin <regis@dolibarr.fr> * Copytight (C) 2010-2011 Juanjo Menent <jmenent@@2byte.es> * * This program is free software; you can redistribute it and/or modify @@ -37,22 +37,22 @@ require_once(DOL_DOCUMENT_ROOT."/fourn/class/paiementfourn.class.php"); $langs->load("bills"); +$id = (GETPOST('id','int') ? GETPOST('id','int') : GETPOST('account','int')); +$ref = GETPOST('ref','alpha'); +$action=GETPOST('action','alpha'); +$confirm=GETPOST('confirm','alpha'); + // Security check -if (isset($_GET["account"]) || isset($_GET["ref"])) -{ - $id = isset($_GET["account"])?$_GET["account"]:(isset($_GET["ref"])?$_GET["ref"]:''); -} -$fieldid = isset($_GET["ref"])?'ref':'rowid'; +$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref :'')); +$fieldtype = (! empty($ref) ? 'ref' :'rowid'); if ($user->societe_id) $socid=$user->societe_id; -$result=restrictedArea($user,'banque',$id,'bank_account','','',$fieldid); +$result=restrictedArea($user,'banque',$fieldvalue,'bank_account','','',$fieldtype); $req_nb=GETPOST("req_nb",'',3); $thirdparty=GETPOST("thirdparty",'',3); -$account=GETPOST("account"); $vline=GETPOST("vline"); -$action=GETPOST("action"); -$page=isset($_GET["page"])?$_GET["page"]:0; -$negpage=isset($_GET["negpage"])?$_GET["negpage"]:0; +$page=GETPOST('page','int'); +$negpage=GETPOST('negpage','int'); if ($negpage) { $page=$_GET["nbpage"] - $negpage; @@ -61,13 +61,14 @@ if ($negpage) $mesg=''; +$object = new Account($db); /* * Action */ $dateop=-1; -if ($action == 'add' && $account && ! isset($_POST["cancel"]) && $user->rights->banque->modifier) +if ($action == 'add' && $id && ! isset($_POST["cancel"]) && $user->rights->banque->modifier) { if (price2num($_POST["credit"]) > 0) { @@ -90,17 +91,16 @@ if ($action == 'add' && $account && ! isset($_POST["cancel"]) && $user->rights-> if (! $mesg) { - $acct=new Account($db); - $acct->fetch($account); - $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, $cat1, $user); + $object->fetch($id); + $insertid = $object->addline($dateop, $operation, $label, $amount, $num_chq, $cat1, $user); if ($insertid > 0) { - Header("Location: ".$_SERVER['PHP_SELF']."?account=" . $account."&action=addline"); + Header("Location: ".$_SERVER['PHP_SELF']."?id=".$id."&action=addline"); exit; } else { - dol_print_error($db,$acct->error); + $mesg=$object->error; } } else @@ -108,7 +108,7 @@ if ($action == 'add' && $account && ! isset($_POST["cancel"]) && $user->rights-> $action='addline'; } } -if ($action == 'confirm_delete' && $_POST["confirm"]=='yes' && $user->rights->banque->modifier) +if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->banque->modifier) { $accline=new AccountLine($db); $accline->fetch($_GET["rowid"]); @@ -131,7 +131,7 @@ $paymentvatstatic=new TVA($db); $form = new Form($db); -if ($account || $_GET["ref"]) +if ($id > 0 || ! empty($ref)) { if ($vline) { @@ -141,16 +141,8 @@ if ($account || $_GET["ref"]) { $viewline = empty($conf->global->MAIN_SIZE_LISTE_LIMIT)?20:$conf->global->MAIN_SIZE_LISTE_LIMIT; } - $acct = new Account($db); - if ($account) - { - $result=$acct->fetch($account); - } - if ($_GET["ref"]) - { - $result=$acct->fetch(0,$_GET["ref"]); - $account=$acct->id; - } + + $result=$object->fetch($id, $ref); // Chargement des categories bancaires dans $options $nbcategories=0; @@ -187,22 +179,22 @@ if ($account || $_GET["ref"]) $param.='&req_nb='.urlencode($req_nb); $mode_search = 1; } - if ($_REQUEST["req_desc"]) + if (GETPOST("req_desc")) { - $sql_rech.= " AND b.label LIKE '%".$db->escape($_REQUEST["req_desc"])."%'"; - $param.='&req_desc='.urlencode($_REQUEST["req_desc"]); + $sql_rech.= " AND b.label LIKE '%".$db->escape(GETPOST("req_desc"))."%'"; + $param.='&req_desc='.urlencode(GETPOST("req_desc")); $mode_search = 1; } - if ($_REQUEST["req_debit"]) + if (GETPOST("req_debit")) { - $sql_rech.=" AND b.amount = -".price2num($_REQUEST["req_debit"]); - $param.='&req_debit='.urlencode($_REQUEST["req_debit"]); + $sql_rech.=" AND b.amount = -".price2num(GETPOST("req_debit")); + $param.='&req_debit='.urlencode(GETPOST("req_debit")); $mode_search = 1; } - if ($_REQUEST["req_credit"]) + if (GETPOST("req_credit")) { - $sql_rech.=" AND b.amount = ".price2num($_REQUEST["req_credit"]); - $param.='&req_credit='.urlencode($_REQUEST["req_credit"]); + $sql_rech.=" AND b.amount = ".price2num(GETPOST("req_credit")); + $param.='&req_credit='.urlencode(GETPOST("req_credit")); $mode_search = 1; } if ($thirdparty) @@ -211,10 +203,10 @@ if ($account || $_GET["ref"]) $param.='&thirdparty='.urlencode($thirdparty); $mode_search = 1; } - if ($_REQUEST["paiementtype"]) + if (GETPOST("paiementtype")) { - $sql_rech.=" AND b.fk_type = '".$db->escape($_REQUEST["paiementtype"])."'"; - $param.='&paiementtype='.urlencode($_REQUEST["paiementtype"]); + $sql_rech.=" AND b.fk_type = '".$db->escape(GETPOST("paiementtype"))."'"; + $param.='&paiementtype='.urlencode(GETPOST("paiementtype")); $mode_search = 1; } @@ -226,7 +218,7 @@ if ($account || $_GET["ref"]) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = b.rowid AND bu.type='company'"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu.url_id = s.rowid"; } - $sql.= " WHERE b.fk_account = ".$acct->id; + $sql.= " WHERE b.fk_account = ".$object->id; $sql.= " AND b.fk_account = ba.rowid"; $sql.= " AND ba.entity = ".$conf->entity; $sql.= $sql_rech; @@ -263,7 +255,7 @@ if ($account || $_GET["ref"]) //print $limitsql.'-'.$page.'-'.$viewline; // Onglets - $head=bank_prepare_head($acct); + $head=bank_prepare_head($object); dol_fiche_head($head,'journal',$langs->trans("FinancialAccount"),0,'account'); print '<table class="border" width="100%">'; @@ -271,12 +263,12 @@ if ($account || $_GET["ref"]) // Ref print '<tr><td valign="top" width="25%">'.$langs->trans("Ref").'</td>'; print '<td colspan="3">'; - print $form->showrefnav($acct,'ref','',1,'ref'); + print $form->showrefnav($object,'ref','',1,'ref'); print '</td></tr>'; // Label print '<tr><td valign="top">'.$langs->trans("Label").'</td>'; - print '<td colspan="3">'.$acct->label.'</td></tr>'; + print '<td colspan="3">'.$object->label.'</td></tr>'; print '</table>'; @@ -287,7 +279,7 @@ if ($account || $_GET["ref"]) /** * Search form */ - $param.='&account='.$acct->id; + $param.='&account='.$object->id; // Define transaction list navigation string $navig=''; @@ -298,16 +290,16 @@ if ($account || $_GET["ref"]) $navig.= $langs->trans("Page")." "; // ' Page '; $navig.='<input type="text" name="negpage" size="1" class="flat" value="'.($nbpage-$page).'">'; $navig.='<input type="hidden" name="req_nb" value="'.$req_nb.'">'; - $navig.='<input type="hidden" name="req_desc" value="'.$_REQUEST["req_desc"].'">'; - $navig.='<input type="hidden" name="req_debit" value="'.$_REQUEST["req_debit"].'">'; - $navig.='<input type="hidden" name="req_credit" value="'.$_REQUEST["req_credit"].'">'; + $navig.='<input type="hidden" name="req_desc" value="'.GETPOST("req_desc").'">'; + $navig.='<input type="hidden" name="req_debit" value="'.GETPOST("req_debit").'">'; + $navig.='<input type="hidden" name="req_credit" value="'.GETPOST("req_credit").'">'; $navig.='<input type="hidden" name="thirdparty" value="'.$thirdparty.'">'; $navig.='<input type="hidden" name="nbpage" value="'.$nbpage.'">'; - $navig.='<input type="hidden" name="account" value="'.($acct->id).'">'; + $navig.='<input type="hidden" name="id" value="'.$object->id.'">'; $navig.='/'.$nbpage.' '; if ($total_lines > $limitsql ) { - $navig.= '<a href="account.php?'.$param.'&page='.($page-1).'">'.img_next().'</a>'; + $navig.= '<a href="'.$_SERVER["PHP_SELF"].'?'.$param.'&page='.($page-1).'">'.img_next().'</a>'; } $navig.='</form>'; //var_dump($navig); @@ -316,7 +308,7 @@ if ($account || $_GET["ref"]) if ($action == 'delete') { $text=$langs->trans('ConfirmDeleteTransaction'); - $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?account='.$acct->id.'&rowid='.$_GET["rowid"],$langs->trans('DeleteTransaction'),$text,'confirm_delete'); + $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&rowid='.$_GET["rowid"],$langs->trans('DeleteTransaction'),$text,'confirm_delete'); if ($ret == 'html') print '<br>'; } @@ -331,11 +323,11 @@ if ($account || $_GET["ref"]) // Form to add a transaction with no invoice if ($user->rights->banque->modifier && $action == 'addline') { - print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">'; + print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="action" value="add">'; - print '<input type="hidden" name="vline" value="' . $vline . '">'; - print '<input type="hidden" name="account" value="' . $acct->id . '">'; + print '<input type="hidden" name="vline" value="'.$vline.'">'; + print '<input type="hidden" name="id" value="'.$object->id.'">'; print '<tr>'; print '<td align="left" colspan="10"><b>'.$langs->trans("AddBankRecordLong").'</b></td>'; @@ -357,18 +349,18 @@ if ($account || $_GET["ref"]) $form->select_date($dateop,'op',0,0,0,'transaction'); print '</td>'; print '<td nowrap="nowrap">'; - $form->select_types_paiements((isset($_POST["operation"])?$_POST["operation"]:''),'operation','1,2',2,1); + $form->select_types_paiements(($object->courant == 2 ? 'LIQ' : GETPOST('operation')),'operation','1,2',2,1); print '</td><td>'; - print '<input name="num_chq" class="flat" type="text" size="4" value="'.(isset($_POST["num_chq"])?$_POST["num_chq"]:'').'"></td>'; + print '<input name="num_chq" class="flat" type="text" size="4" value="'.GETPOST("num_chq").'"></td>'; print '<td colspan="2">'; - print '<input name="label" class="flat" type="text" size="24" value="'.(isset($_POST["label"])?$_POST["label"]:'').'">'; + print '<input name="label" class="flat" type="text" size="24" value="'.GETPOST("label").'">'; if ($nbcategories) { print '<br>'.$langs->trans("Category").': <select class="flat" name="cat1">'.$options.'</select>'; } print '</td>'; - print '<td align=right><input name="debit" class="flat" type="text" size="4" value="'.(isset($_POST["debit"])?$_POST["debit"]:'').'"></td>'; - print '<td align=right><input name="credit" class="flat" type="text" size="4" value="'.(isset($_POST["credit"])?$_POST["credit"]:'').'"></td>'; + print '<td align=right><input name="debit" class="flat" type="text" size="4" value="'.GETPOST("debit").'"></td>'; + print '<td align=right><input name="credit" class="flat" type="text" size="4" value="'.GETPOST("credit").'"></td>'; print '<td colspan="2" align="center">'; print '<input type="submit" name="save" class="button" value="'.$langs->trans("Add").'"><br>'; print '<input type="submit" name="cancel" class="button" value="'.$langs->trans("Cancel").'">'; @@ -394,14 +386,14 @@ if ($account || $_GET["ref"]) print '<td align="right">'.$langs->trans("Credit").'</td>'; print '<td align="right" width="80">'.$langs->trans("BankBalance").'</td>'; print '<td align="center" width="60">'; - if ($acct->type != 2 && $acct->rappro) print $langs->trans("AccountStatementShort"); + if ($object->type != 2 && $object->rappro) print $langs->trans("AccountStatementShort"); else print ' '; print '</td></tr>'; print '<form action="'.$_SERVER["PHP_SELF"].'?'.$param.'" name="search" method="POST">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="action" value="search">'; - print '<input type="hidden" name="account" value="' . $acct->id . '">'; + print '<input type="hidden" name="id" value="'.$object->id.'">'; print '<tr class="liste_titre">'; print '<td> </td>'; @@ -412,10 +404,10 @@ if ($account || $_GET["ref"]) print $form->select_types_paiements($_REQUEST['paiementtype'],'paiementtype',$filtertype,2,1,1,8); print '</td>'; print '<td><input type="text" class="flat" name="req_nb" value="'.$req_nb.'" size="2"></td>'; - print '<td><input type="text" class="flat" name="req_desc" value="'.$_REQUEST["req_desc"].'" size="24"></td>'; + print '<td><input type="text" class="flat" name="req_desc" value="'.GETPOST("req_desc").'" size="24"></td>'; print '<td><input type="text" class="flat" name="thirdparty" value="'.$thirdparty.'" size="14"></td>'; - print '<td align="right"><input type="text" class="flat" name="req_debit" value="'.$_REQUEST["req_debit"].'" size="4"></td>'; - print '<td align="right"><input type="text" class="flat" name="req_credit" value="'.$_REQUEST["req_credit"].'" size="4"></td>'; + print '<td align="right"><input type="text" class="flat" name="req_debit" value="'.GETPOST("req_debit").'" size="4"></td>'; + print '<td align="right"><input type="text" class="flat" name="req_credit" value="'.GETPOST("req_credit").'" size="4"></td>'; print '<td align="center"> </td>'; print '<td align="center" width="40"><input type="image" class="liste_titre" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'"></td>'; print "</tr>\n"; @@ -461,7 +453,7 @@ if ($account || $_GET["ref"]) //$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu3 ON bu3.fk_bank = b.rowid AND bu3.type='company'"; //$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu3.url_id = s.rowid"; } - $sql.= " WHERE b.fk_account=".$acct->id; + $sql.= " WHERE b.fk_account=".$object->id; $sql.= " AND b.fk_account = ba.rowid"; $sql.= " AND ba.entity = ".$conf->entity; $sql.= $sql_rech; @@ -537,7 +529,7 @@ if ($account || $_GET["ref"]) print dol_trunc($objp->label,60); } // Add links after description - $links = $acct->get_url($objp->rowid); + $links = $object->get_url($objp->rowid); foreach($links as $key=>$val) { if ($links[$key]['type']=='payment') @@ -664,14 +656,14 @@ if ($account || $_GET["ref"]) } // Transaction reconciliated or edit link - if ($objp->rappro && $acct->canBeConciliated() > 0) // If line not conciliated and account can be conciliated + if ($objp->rappro && $object->canBeConciliated() > 0) // If line not conciliated and account can be conciliated { print '<td align="center" nowrap>'; - print '<a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&account='.$acct->id.'&page='.$page.'">'; + print '<a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&account='.$object->id.'&page='.$page.'">'; print img_edit(); print '</a>'; print " "; - print '<a href="releve.php?num='.$objp->num_releve.'&account='.$acct->id.'">'.$objp->num_releve.'</a>'; + print '<a href="releve.php?num='.$objp->num_releve.'&account='.$object->id.'">'.$objp->num_releve.'</a>'; print "</td>"; } else @@ -679,17 +671,17 @@ if ($account || $_GET["ref"]) print '<td align="center">'; if ($user->rights->banque->modifier || $user->rights->banque->consolidate) { - print '<a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&account='.$acct->id.'&page='.$page.'">'; + print '<a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&account='.$object->id.'&page='.$page.'">'; print img_edit(); print '</a>'; } else { - print '<a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&account='.$acct->id.'&page='.$page.'">'; + print '<a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&account='.$object->id.'&page='.$page.'">'; print img_view(); print '</a>'; } - if ($acct->canBeConciliated() > 0 && empty($objp->rappro)) + if ($object->canBeConciliated() > 0 && empty($objp->rappro)) { if ($db->jdate($objp->dv) < ($now - $conf->bank->rappro->warning_delay)) { @@ -699,7 +691,7 @@ if ($account || $_GET["ref"]) print ' '; if ($user->rights->banque->modifier) { - print '<a href="'.DOL_URL_ROOT.'/compta/bank/account.php?action=delete&rowid='.$objp->rowid.'&account='.$acct->id.'&page='.$page.'">'; + print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&rowid='.$objp->rowid.'&id='.$object->id.'&page='.$page.'">'; print img_delete(); print '</a>'; } @@ -742,11 +734,11 @@ if ($account || $_GET["ref"]) { print '<div class="tabsAction">'; - if ($acct->type != 2 && $acct->rappro) // If not cash account and can be reconciliate + if ($object->type != 2 && $object->rappro) // If not cash account and can be reconciliate { if ($user->rights->banque->consolidate) { - print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/bank/rappro.php?account='.$acct->id.'">'.$langs->trans("Conciliate").'</a>'; + print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/bank/rappro.php?account='.$object->id.'">'.$langs->trans("Conciliate").'</a>'; } else { @@ -758,7 +750,7 @@ if ($account || $_GET["ref"]) { if ($user->rights->banque->modifier) { - print '<a class="butAction" href="account.php?action=addline&account='.$acct->id.'&page='.$page.'">'.$langs->trans("AddBankRecord").'</a>'; + print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=addline&id='.$object->id.'&page='.$page.'">'.$langs->trans("AddBankRecord").'</a>'; } else { @@ -776,7 +768,7 @@ else print $langs->trans("ErrorBankAccountNotFound"); } -$db->close(); - llxFooter(); + +$db->close(); ?> \ No newline at end of file diff --git a/htdocs/core/lib/bank.lib.php b/htdocs/core/lib/bank.lib.php index 0e524b73be5..741a2903769 100644 --- a/htdocs/core/lib/bank.lib.php +++ b/htdocs/core/lib/bank.lib.php @@ -1,5 +1,6 @@ <?php -/* Copyright (C) 2006-2007 Laurent Destailleur <eldy@users.sourceforge.net> +/* Copyright (C) 2006-2007 Laurent Destailleur <eldy@users.sourceforge.net> + * Copyright (C) 2012 Regis Houssin <regis@dolibarr.fr> * * 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 @@ -47,7 +48,7 @@ function bank_prepare_head($object) $h++; } - $head[$h][0] = DOL_URL_ROOT."/compta/bank/account.php?account=".$object->id; + $head[$h][0] = DOL_URL_ROOT."/compta/bank/account.php?id=".$object->id; $head[$h][1] = $langs->trans("Transactions"); $head[$h][2] = 'journal'; $h++; -- GitLab