From 75f3b9e631e17c592d7e09aa6e6aef4a4e8a2f42 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 22 Aug 2010 13:40:44 +0000 Subject: [PATCH] New: Nav works on bank line --- htdocs/compta/bank/account.php | 1305 ++++++++++---------- htdocs/compta/bank/class/account.class.php | 34 +- htdocs/compta/bank/ligne.php | 163 ++- htdocs/compta/paiement_charge.php | 5 +- htdocs/core/class/commonobject.class.php | 14 +- htdocs/core/class/html.form.class.php | 22 +- 6 files changed, 771 insertions(+), 772 deletions(-) diff --git a/htdocs/compta/bank/account.php b/htdocs/compta/bank/account.php index b438f4ef59e..75d679f8d7c 100644 --- a/htdocs/compta/bank/account.php +++ b/htdocs/compta/bank/account.php @@ -41,7 +41,7 @@ $langs->load("bills"); // Security check if (isset($_GET["account"]) || isset($_GET["ref"])) { - $id = isset($_GET["account"])?$_GET["account"]:(isset($_GET["ref"])?$_GET["ref"]:''); + $id = isset($_GET["account"])?$_GET["account"]:(isset($_GET["ref"])?$_GET["ref"]:''); } $fieldid = isset($_GET["ref"])?'ref':'rowid'; if ($user->societe_id) $socid=$user->societe_id; @@ -55,8 +55,8 @@ $page=isset($_GET["page"])?$_GET["page"]:0; $negpage=isset($_GET["negpage"])?$_GET["negpage"]:0; if ($negpage) { - $page=$_GET["nbpage"] - $negpage; - if ($page > $_GET["nbpage"]) $page = $_GET["nbpage"]; + $page=$_GET["nbpage"] - $negpage; + if ($page > $_GET["nbpage"]) $page = $_GET["nbpage"]; } $mesg=''; @@ -70,49 +70,49 @@ $dateop=-1; if ($_POST["action"] == 'add' && $account && ! isset($_POST["cancel"]) && $user->rights->banque->modifier) { - if (price2num($_POST["credit"]) > 0) - { - $amount = price2num($_POST["credit"]); - } - else - { - $amount = - price2num($_POST["debit"]); - } + if (price2num($_POST["credit"]) > 0) + { + $amount = price2num($_POST["credit"]); + } + else + { + $amount = - price2num($_POST["debit"]); + } - $dateop = dol_mktime(12,0,0,$_POST["opmonth"],$_POST["opday"],$_POST["opyear"]); - $operation=$_POST["operation"]; - $num_chq=$_POST["num_chq"]; - $label=$_POST["label"]; - $cat1=$_POST["cat1"]; + $dateop = dol_mktime(12,0,0,$_POST["opmonth"],$_POST["opday"],$_POST["opyear"]); + $operation=$_POST["operation"]; + $num_chq=$_POST["num_chq"]; + $label=$_POST["label"]; + $cat1=$_POST["cat1"]; - if (! $dateop) $mesg=$langs->trans("ErrorFieldRequired",$langs->trans("Date")); - if (! $operation) $mesg=$langs->trans("ErrorFieldRequired",$langs->trans("Type")); - if (! $amount) $mesg=$langs->trans("ErrorFieldRequired",$langs->trans("Amount")); + if (! $dateop) $mesg=$langs->trans("ErrorFieldRequired",$langs->trans("Date")); + if (! $operation) $mesg=$langs->trans("ErrorFieldRequired",$langs->trans("Type")); + if (! $amount) $mesg=$langs->trans("ErrorFieldRequired",$langs->trans("Amount")); - if (! $mesg) - { - $acct=new Account($db,$account); - $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, $cat1, $user); - if ($insertid > 0) - { - Header("Location: account.php?account=" . $account); - exit; - } - else - { - dol_print_error($db,$acct->error); - } - } - else - { - $_GET["action"]='addline'; - } + if (! $mesg) + { + $acct=new Account($db,$account); + $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, $cat1, $user); + if ($insertid > 0) + { + Header("Location: account.php?account=" . $account); + exit; + } + else + { + dol_print_error($db,$acct->error); + } + } + else + { + $_GET["action"]='addline'; + } } if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"]=='yes' && $user->rights->banque->modifier) { - $accline=new AccountLine($db); - $accline->fetch($_GET["rowid"]); - $result=$accline->delete(); + $accline=new AccountLine($db); + $accline->fetch($_GET["rowid"]); + $result=$accline->delete(); } @@ -133,624 +133,621 @@ $html = new Form($db); if ($account || $_GET["ref"]) { - if ($vline) - { - $viewline = $vline; - } - else - { - $viewline = 20; - } - $acct = new Account($db); - if ($account) - { - $result=$acct->fetch($account); - } - if ($_GET["ref"]) - { - $result=$acct->fetch(0,$_GET["ref"]); - $account=$acct->id; - } - - // Chargement des categories bancaires dans $options - $nbcategories=0; - - $sql = "SELECT rowid, label"; - $sql.= " FROM ".MAIN_DB_PREFIX."bank_categ"; - $sql.= " WHERE entity = ".$conf->entity; - $sql.= " ORDER BY label"; - - $result = $db->query($sql); - if ($result) - { - $var=True; - $num = $db->num_rows($result); - $i = 0; - $options = ""; - while ($i < $num) - { - $obj = $db->fetch_object($result); - $options .= "\n"; - $nbcategories++; - $i++; - } - $db->free($result); - } - - - // Definition de sql_rech et param - $param=''; - $sql_rech=''; - $mode_search = 0; - if ($_REQUEST["req_nb"]) - { - $sql_rech.= " AND b.num_chq like '%".addslashes($_REQUEST["req_nb"])."%'"; - $param.='&req_nb='.urlencode($_REQUEST["req_nb"]); - $mode_search = 1; - } - if ($_REQUEST["req_desc"]) - { - $sql_rech.= " AND b.label like '%".addslashes($_REQUEST["req_desc"])."%'"; - $param.='&req_desc='.urlencode($_REQUEST["req_desc"]); - $mode_search = 1; - } - if ($_REQUEST["req_debit"]) - { - $sql_rech.=" AND b.amount = -".price2num($_REQUEST["req_debit"]); - $param.='&req_debit='.urlencode($_REQUEST["req_debit"]); - $mode_search = 1; - } - if ($_REQUEST["req_credit"]) - { - $sql_rech.=" AND b.amount = ".price2num($_REQUEST["req_credit"]); - $param.='&req_credit='.urlencode($_REQUEST["req_credit"]); - $mode_search = 1; - } - if ($_REQUEST["thirdparty"]) - { - $sql_rech.=" AND (COALESCE(s.nom,'') LIKE '%".addslashes($_REQUEST["thirdparty"])."%')"; - $param.='&thirdparty='.urlencode($_REQUEST["thirdparty"]); - $mode_search = 1; - } - - $sql = "SELECT count(*) as nb"; - $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba"; - $sql.= ", ".MAIN_DB_PREFIX."bank as b"; - if ($mode_search) - { - $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.= " AND b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; - $sql.= $sql_rech; - - dol_syslog("account.php count transactions - sql=".$sql); - $result=$db->query($sql); - if ($result) - { - $obj = $db->fetch_object($result); - $nbline = $obj->nb; - $total_lines = $nbline; - - if ($nbline > $viewline ) - { - $limit = $nbline - $viewline ; - } - else - { - $limit = $viewline; - } - - $db->free($result); - } - else { - dol_print_error($db); - } - - if ($page > 0) - { - $limitsql = $nbline - ($page * $viewline); - if ($limitsql < $viewline) - { - $limitsql = $viewline; - } - $nbline = $limitsql; - } - else - { - $page = 0; - $limitsql = $nbline; - } - - // Onglets - $head=bank_prepare_head($acct); - dol_fiche_head($head,'journal',$langs->trans("FinancialAccount"),0,'account'); - - print ''; - - // Ref - print ''; - print ''; - - // Label - print ''; - print ''; - - print '
'.$langs->trans("Ref").''; - print $html->showrefnav($acct,'ref','',1,'ref'); - print '
'.$langs->trans("Label").''.$acct->label.'
'; - - print '
'; - - if ($mesg) print '
'.$mesg.'
'; - - - /** - * Search form - */ - $param.='&account='.$acct->id; - - - // Define transaction list navigation string - $navig=''; - $navig.='
'; - $nbpage=floor($total_lines/$viewline)+($total_lines % $viewline > 0?1:0); // Nombre de page total - if ($limitsql > $viewline) - { - $navig.=''.img_previous().''; - } - $navig.= ' Page '; - $navig.=''; - $navig.=''; - $navig.=''; - $navig.=''; - $navig.=''; - $navig.=''; - $navig.=''; - $navig.=''; - $navig.='/'.$nbpage.' '; - if ($total_lines > $limitsql ) - { - $navig.= ''.img_next().''; - } - $navig.='
'; - - - // Confirmation delete - if ($_GET["action"]=='delete') - { - $text=$langs->trans('ConfirmDeleteTransaction'); - $ret=$html->form_confirm($_SERVER['PHP_SELF'].'?account='.$acct->id.'&rowid='.$_GET["rowid"],$langs->trans('DeleteTransaction'),$text,'confirm_delete'); - if ($ret == 'html') print '
'; - } - - - print ''; - - // Show title - if (! $_GET["action"]=='addline' && ! $_GET["action"]=='delete') - { - print ''; - } - - - // Form to add a transaction with no invoice - if ($user->rights->banque->modifier && $_GET["action"]=='addline') - { - print ''; - print ''; - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ""; - - print "\n"; - } - - /* - * Affiche tableau des transactions bancaires - * - */ - - // Ligne de titre tableau des ecritures - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - print "\n"; - - /* Another solution - * create temporary table solde type=heap select amount from llx_bank limit 100 ; - * select sum(amount) from solde ; - */ - - $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"; - if ($mode_search) - { - $sql.= ", s.rowid as socid, s.nom as thirdparty"; - } - if ($mode_search && $conf->adherent->enabled) - { - - } - if ($mode_search && $conf->tax->enabled) - { - - } - $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba"; - $sql.= ", ".MAIN_DB_PREFIX."bank as b"; - if ($mode_search) - { - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu1.url_id = s.rowid"; - } - if ($mode_search && $conf->tax->enabled) - { - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu2 ON bu2.fk_bank = b.rowid AND bu2.type='payment_vat'"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."tva as t ON bu2.url_id = t.rowid"; - } - if ($mode_search && $conf->adherent->enabled) - { - // \TODO Mettre jointure sur adherent pour recherche sur un adherent - //$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.= " AND b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; - $sql.= $sql_rech; - $sql.= $db->order("b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day - $sql.= $db->plimit($limitsql, 0); - - dol_syslog("account.php get transactions - sql=".$sql); - $result = $db->query($sql); - if ($result) - { - $now=dol_now('tzserver'); - $nows=dol_date('Ymd',$now); - - //$html->load_cache_types_paiements(); - //$html->cache_types_paiements - - $var=true; - - $num = $db->num_rows($result); - $i = 0; $total = 0; $sep = 0; - - while ($i < $num) - { - $objp = $db->fetch_object($result); - $total = price2num($total + $objp->amount,'MT'); - if ($i >= ($nbline - $viewline)) - { - $var=!$var; - - // Is it a transaction in future ? - $dos=dol_date('Ymd',$db->jdate($objp->do)); - //print "dos=".$dos." nows=".$nows; - if ($dos > $nows && !$sep) // Yes, we show a subtotal - { - $sep = 1 ; - print ''; - print ""; - print ""; - print ''; - } - - print ""; - - print "\n"; - - print "\n"; - - // Payment type - print "\n"; - print '\n"; - - // Description - print ''; - - - // Add third party column - print ''; - - // Amount - if ($objp->amount < 0) - { - print "\n"; - } - else - { - print "\n"; - } - - // Balance - if ($action != 'search') - { - if ($total >= 0) - { - print ''; - } - else - { - print ''; - } - } - else - { - print ''; - } - - // Receipt conciliate or edit link - if ($objp->rappro && $acct->type != 2) // Si non compte cash - { - print ""; - } - else - { - print ''; - } - - print ""; - - } - - $i++; - } - - // Show total - if ($page == 0 && ! $mode_search) - { - print ''; - print ''; - print ''; - print ''; - } - $db->free($result); - } - else - { - dol_print_error($db); - } - - - print "
'.$navig.'
'.$langs->trans("AddBankRecordLong").'
'.$langs->trans("Date").' '.$langs->trans("Type").''.$langs->trans("Numero").''.$langs->trans("Description").''.$langs->trans("Debit").''.$langs->trans("Credit").' 
'; - $html->select_date($dateop,'op',0,0,0,'transaction'); - print ''; - $html->select_types_paiements((isset($_POST["operation"])?$_POST["operation"]:''),'operation','1,2',2,1); - print ''; - print ''; - print ''; - if ($nbcategories) - { - print '
'.$langs->trans("Category").': '; - } - print '
'; - print '
'; - print ''; - print '
 
'.$langs->trans("Date").''.$langs->trans("Value").''.$langs->trans("Type").''.$langs->trans("Numero").''.$langs->trans("Description").''.$langs->trans("ThirdParty").''.$langs->trans("Debit").''.$langs->trans("Credit").''.$langs->trans("BankBalance").''; - if ($acct->type != 2 && $acct->rappro) print $langs->trans("AccountStatementShort"); - else print ' '; - print '
  
'; - print $langs->trans("CurrentBalance"); - print '".price($total - $objp->amount)." 
".dol_print_date($db->jdate($objp->do),"day")."".dol_print_date($db->jdate($objp->dv),"day").""; - $label=($langs->trans("PaymentTypeShort".$objp->fk_type)!="PaymentTypeShort".$objp->fk_type)?$langs->trans("PaymentTypeShort".$objp->fk_type):$objp->fk_type; - if ($objp->fk_type == 'SOLD') $label=' '; - print $label; - print "'.($objp->num_chq?$objp->num_chq:"")."'; - // Show generic description - if (preg_match('/^\((.*)\)$/i',$objp->label,$reg)) - { - // Generic description because between (). We show it after translating. - print $langs->trans($reg[1]); - } - else - { - print dol_trunc($objp->label,60); - } - // Add links after description - $links = $acct->get_url($objp->rowid); - foreach($links as $key=>$val) - { - if ($links[$key]['type']=='payment') { - $paymentstatic->id=$links[$key]['url_id']; - print ' '.$paymentstatic->getNomUrl(2); - } - else if ($links[$key]['type']=='payment_supplier') { - $paymentsupplierstatic->id=$links[$key]['url_id']; - $paymentsupplierstatic->ref=$links[$key]['url_id']; - print ' '.$paymentsupplierstatic->getNomUrl(2); - } - else if ($links[$key]['type']=='company') { - } - else if ($links[$key]['type']=='sc') { // This is waiting for card to link to payment_sc - $chargestatic->id=$links[$key]['url_id']; - $chargestatic->ref=$links[$key]['url_id']; - $chargestatic->lib=$langs->trans("SocialContribution"); - print ' '.$chargestatic->getNomUrl(2); - } - else if ($links[$key]['type']=='payment_sc') - { - //print ' - '; - print ''; - print ' '.img_object($langs->trans('ShowPayment'),'payment').' '; - //print $langs->trans("SocialContributionPayment"); - print ''; - - } - else if ($links[$key]['type']=='payment_vat') - { - $paymentvatstatic->id=$links[$key]['url_id']; - $paymentvatstatic->ref=$links[$key]['url_id']; - print ' '.$paymentvatstatic->getNomUrl(2); - } - else if ($links[$key]['type']=='banktransfert') { - // Do not show this link (avoid confusion). Can already be accessed from transaction detail - } - else if ($links[$key]['type']=='member') { - } - else { - //print ' - '; - print ''; - if (preg_match('/^\((.*)\)$/i',$links[$key]['label'],$reg)) - { - // Label generique car entre parentheses. On l'affiche en le traduisant - if ($reg[1]=='paiement') $reg[1]='Payment'; - print ' '.$langs->trans($reg[1]); - } - else - { - print ' '.$links[$key]['label']; - } - print ''; - } - } - print ''; - foreach($links as $key=>$val) - { - if ($links[$key]['type']=='company') { - $societestatic->id=$links[$key]['url_id']; - $societestatic->nom=$links[$key]['label']; - print $societestatic->getNomUrl(1,'',16); - } - /*else if ($links[$key]['type']=='sc') { - $chargestatic->id=$links[$key]['url_id']; - if (preg_match('/^\((.*)\)$/i',$links[$key]['label'],$reg)) - { - if ($reg[1]=='socialcontribution') $reg[1]='SocialContribution'; - $chargestatic->lib=$langs->trans($reg[1]); - } - else - { - $chargestatic->lib=$links[$key]['label']; - } - print $chargestatic->getNomUrl(1,'',16); - }*/ - else if ($links[$key]['type']=='member') { - $memberstatic->id=$links[$key]['url_id']; - $memberstatic->ref=$links[$key]['label']; - print $memberstatic->getNomUrl(1,16,'card'); - } - } - print '".price($objp->amount * -1)."   ".price($objp->amount)." '.price($total).' '.price($total).'-"; - print ''; - print img_view(); - print ''; - print "  "; - print "num_releve&account=$acct->id\">$objp->num_releve"; - print "'; - if ($user->rights->banque->modifier || $user->rights->banque->consolidate) - { - print ''; - print img_edit(); - print ''; - } - else - { - print ''; - print img_view(); - print ''; - } - print ' '; - if ($user->rights->banque->modifier) - { - print ''; - print img_delete(); - print ''; - } - print '
'; - if ($sep) print ' '; - else print $langs->trans("CurrentBalance"); - print ''.price($total).' 
"; - - print "\n\n"; - - /* - * Boutons actions - */ - if ($_GET["action"] != 'addline' && $_GET["action"] != 'delete') - { - print '
'; - - if ($acct->type != 2 && $acct->rappro) // Si non compte cash et rapprochable - { - if ($user->rights->banque->consolidate) - { - print ''.$langs->trans("Conciliate").''; - } - else - { - print "trans("NotEnoughPermissions")."\" href=\"#\">".$langs->trans("Conciliate").""; - } - } - - if ($user->rights->banque->modifier) - { - print ''.$langs->trans("AddBankRecord").''; - } - else - { - print "trans("NotEnoughPermissions")."\" href=\"#\">".$langs->trans("AddBankRecord").""; - } - - print '
'; - } - - print '
'; + if ($vline) + { + $viewline = $vline; + } + else + { + $viewline = 20; + } + $acct = new Account($db); + if ($account) + { + $result=$acct->fetch($account); + } + if ($_GET["ref"]) + { + $result=$acct->fetch(0,$_GET["ref"]); + $account=$acct->id; + } + + // Chargement des categories bancaires dans $options + $nbcategories=0; + + $sql = "SELECT rowid, label"; + $sql.= " FROM ".MAIN_DB_PREFIX."bank_categ"; + $sql.= " WHERE entity = ".$conf->entity; + $sql.= " ORDER BY label"; + + $result = $db->query($sql); + if ($result) + { + $var=True; + $num = $db->num_rows($result); + $i = 0; + $options = ""; + while ($i < $num) + { + $obj = $db->fetch_object($result); + $options .= "\n"; + $nbcategories++; + $i++; + } + $db->free($result); + } + + + // Definition de sql_rech et param + $param=''; + $sql_rech=''; + $mode_search = 0; + if ($_REQUEST["req_nb"]) + { + $sql_rech.= " AND b.num_chq like '%".addslashes($_REQUEST["req_nb"])."%'"; + $param.='&req_nb='.urlencode($_REQUEST["req_nb"]); + $mode_search = 1; + } + if ($_REQUEST["req_desc"]) + { + $sql_rech.= " AND b.label like '%".addslashes($_REQUEST["req_desc"])."%'"; + $param.='&req_desc='.urlencode($_REQUEST["req_desc"]); + $mode_search = 1; + } + if ($_REQUEST["req_debit"]) + { + $sql_rech.=" AND b.amount = -".price2num($_REQUEST["req_debit"]); + $param.='&req_debit='.urlencode($_REQUEST["req_debit"]); + $mode_search = 1; + } + if ($_REQUEST["req_credit"]) + { + $sql_rech.=" AND b.amount = ".price2num($_REQUEST["req_credit"]); + $param.='&req_credit='.urlencode($_REQUEST["req_credit"]); + $mode_search = 1; + } + if ($_REQUEST["thirdparty"]) + { + $sql_rech.=" AND (COALESCE(s.nom,'') LIKE '%".addslashes($_REQUEST["thirdparty"])."%')"; + $param.='&thirdparty='.urlencode($_REQUEST["thirdparty"]); + $mode_search = 1; + } + + $sql = "SELECT count(*) as nb"; + $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba"; + $sql.= ", ".MAIN_DB_PREFIX."bank as b"; + if ($mode_search) + { + $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.= " AND b.fk_account = ba.rowid"; + $sql.= " AND ba.entity = ".$conf->entity; + $sql.= $sql_rech; + + dol_syslog("account.php count transactions - sql=".$sql); + $result=$db->query($sql); + if ($result) + { + $obj = $db->fetch_object($result); + $nbline = $obj->nb; + $total_lines = $nbline; + + if ($nbline > $viewline ) + { + $limit = $nbline - $viewline ; + } + else + { + $limit = $viewline; + } + + $db->free($result); + } + else { + dol_print_error($db); + } + + if ($page > 0) + { + $limitsql = $nbline - ($page * $viewline); + if ($limitsql < $viewline) + { + $limitsql = $viewline; + } + $nbline = $limitsql; + } + else + { + $page = 0; + $limitsql = $nbline; + } + + // Onglets + $head=bank_prepare_head($acct); + dol_fiche_head($head,'journal',$langs->trans("FinancialAccount"),0,'account'); + + print ''; + + // Ref + print ''; + print ''; + + // Label + print ''; + print ''; + + print '
'.$langs->trans("Ref").''; + print $html->showrefnav($acct,'ref','',1,'ref'); + print '
'.$langs->trans("Label").''.$acct->label.'
'; + + print '
'; + + if ($mesg) print '
'.$mesg.'
'; + + + /** + * Search form + */ + $param.='&account='.$acct->id; + + + // Define transaction list navigation string + $navig=''; + $navig.='
'; + $nbpage=floor($total_lines/$viewline)+($total_lines % $viewline > 0?1:0); // Nombre de page total + if ($limitsql > $viewline) + { + $navig.=''.img_previous().''; + } + $navig.= ' Page '; + $navig.=''; + $navig.=''; + $navig.=''; + $navig.=''; + $navig.=''; + $navig.=''; + $navig.=''; + $navig.=''; + $navig.='/'.$nbpage.' '; + if ($total_lines > $limitsql ) + { + $navig.= ''.img_next().''; + } + $navig.='
'; + + + // Confirmation delete + if ($_GET["action"]=='delete') + { + $text=$langs->trans('ConfirmDeleteTransaction'); + $ret=$html->form_confirm($_SERVER['PHP_SELF'].'?account='.$acct->id.'&rowid='.$_GET["rowid"],$langs->trans('DeleteTransaction'),$text,'confirm_delete'); + if ($ret == 'html') print '
'; + } + + + print ''; + + // Show title + if (! $_GET["action"]=='addline' && ! $_GET["action"]=='delete') + { + print ''; + } + + + // Form to add a transaction with no invoice + if ($user->rights->banque->modifier && $_GET["action"]=='addline') + { + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ""; + + print "\n"; + } + + /* + * Affiche tableau des transactions bancaires + * + */ + + // Ligne de titre tableau des ecritures + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + print "\n"; + + /* Another solution + * create temporary table solde type=heap select amount from llx_bank limit 100 ; + * select sum(amount) from solde ; + */ + + $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"; + if ($mode_search) + { + $sql.= ", s.rowid as socid, s.nom as thirdparty"; + } + if ($mode_search && $conf->adherent->enabled) + { + + } + if ($mode_search && $conf->tax->enabled) + { + + } + $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba"; + $sql.= ", ".MAIN_DB_PREFIX."bank as b"; + if ($mode_search) + { + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu1.url_id = s.rowid"; + } + if ($mode_search && $conf->tax->enabled) + { + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu2 ON bu2.fk_bank = b.rowid AND bu2.type='payment_vat'"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."tva as t ON bu2.url_id = t.rowid"; + } + if ($mode_search && $conf->adherent->enabled) + { + // \TODO Mettre jointure sur adherent pour recherche sur un adherent + //$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.= " AND b.fk_account = ba.rowid"; + $sql.= " AND ba.entity = ".$conf->entity; + $sql.= $sql_rech; + $sql.= $db->order("b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day + $sql.= $db->plimit($limitsql, 0); + + dol_syslog("account.php get transactions - sql=".$sql); + $result = $db->query($sql); + if ($result) + { + $now=dol_now('tzserver'); + $nows=dol_date('Ymd',$now); + + //$html->load_cache_types_paiements(); + //$html->cache_types_paiements + + $var=true; + + $num = $db->num_rows($result); + $i = 0; $total = 0; $sep = 0; + + while ($i < $num) + { + $objp = $db->fetch_object($result); + $total = price2num($total + $objp->amount,'MT'); + if ($i >= ($nbline - $viewline)) + { + $var=!$var; + + // Is it a transaction in future ? + $dos=dol_date('Ymd',$db->jdate($objp->do)); + //print "dos=".$dos." nows=".$nows; + if ($dos > $nows && !$sep) // Yes, we show a subtotal + { + $sep = 1 ; + print ''; + print ""; + print ""; + print ''; + } + + print ""; + + print "\n"; + + print "\n"; + + // Payment type + print "\n"; + print '\n"; + + // Description + print ''; + + + // Add third party column + print ''; + + // Amount + if ($objp->amount < 0) + { + print "\n"; + } + else + { + print "\n"; + } + + // Balance + if ($action != 'search') + { + if ($total >= 0) + { + print ''; + } + else + { + print ''; + } + } + else + { + print ''; + } + + // Receipt conciliate or edit link + if ($objp->rappro && $acct->type != 2) // Si non compte cash + { + print ""; + } + else + { + print ''; + } + + print ""; + + } + + $i++; + } + + // Show total + if ($page == 0 && ! $mode_search) + { + print ''; + print ''; + print ''; + print ''; + } + $db->free($result); + } + else + { + dol_print_error($db); + } + + + print "
'.$navig.'
'.$langs->trans("AddBankRecordLong").'
'.$langs->trans("Date").' '.$langs->trans("Type").''.$langs->trans("Numero").''.$langs->trans("Description").''.$langs->trans("Debit").''.$langs->trans("Credit").' 
'; + $html->select_date($dateop,'op',0,0,0,'transaction'); + print ''; + $html->select_types_paiements((isset($_POST["operation"])?$_POST["operation"]:''),'operation','1,2',2,1); + print ''; + print ''; + print ''; + if ($nbcategories) + { + print '
'.$langs->trans("Category").': '; + } + print '
'; + print '
'; + print ''; + print '
 
'.$langs->trans("Date").''.$langs->trans("Value").''.$langs->trans("Type").''.$langs->trans("Numero").''.$langs->trans("Description").''.$langs->trans("ThirdParty").''.$langs->trans("Debit").''.$langs->trans("Credit").''.$langs->trans("BankBalance").''; + if ($acct->type != 2 && $acct->rappro) print $langs->trans("AccountStatementShort"); + else print ' '; + print '
  
'; + print $langs->trans("CurrentBalance"); + print '".price($total - $objp->amount)." 
".dol_print_date($db->jdate($objp->do),"day")."".dol_print_date($db->jdate($objp->dv),"day").""; + $label=($langs->trans("PaymentTypeShort".$objp->fk_type)!="PaymentTypeShort".$objp->fk_type)?$langs->trans("PaymentTypeShort".$objp->fk_type):$objp->fk_type; + if ($objp->fk_type == 'SOLD') $label=' '; + print $label; + print "'.($objp->num_chq?$objp->num_chq:"")."'; + // Show generic description + if (preg_match('/^\((.*)\)$/i',$objp->label,$reg)) + { + // Generic description because between (). We show it after translating. + print $langs->trans($reg[1]); + } + else + { + print dol_trunc($objp->label,60); + } + // Add links after description + $links = $acct->get_url($objp->rowid); + foreach($links as $key=>$val) + { + if ($links[$key]['type']=='payment') { + $paymentstatic->id=$links[$key]['url_id']; + print ' '.$paymentstatic->getNomUrl(2); + } + else if ($links[$key]['type']=='payment_supplier') { + $paymentsupplierstatic->id=$links[$key]['url_id']; + $paymentsupplierstatic->ref=$links[$key]['url_id']; + print ' '.$paymentsupplierstatic->getNomUrl(2); + } + else if ($links[$key]['type']=='company') { + } + else if ($links[$key]['type']=='payment_sc') + { + //print ' - '; + print ''; + print ' '.img_object($langs->trans('ShowPayment'),'payment').' '; + //print $langs->trans("SocialContributionPayment"); + print ''; + + } + else if ($links[$key]['type']=='payment_vat') + { + $paymentvatstatic->id=$links[$key]['url_id']; + $paymentvatstatic->ref=$links[$key]['url_id']; + print ' '.$paymentvatstatic->getNomUrl(2); + } + else if ($links[$key]['type']=='banktransfert') { + // Do not show this link (avoid confusion). Can already be accessed from transaction detail + } + else if ($links[$key]['type']=='member') { + } + else if ($links[$key]['type']=='sc') { + } + else { + //print ' - '; + print ''; + if (preg_match('/^\((.*)\)$/i',$links[$key]['label'],$reg)) + { + // Label generique car entre parentheses. On l'affiche en le traduisant + if ($reg[1]=='paiement') $reg[1]='Payment'; + print ' '.$langs->trans($reg[1]); + } + else + { + print ' '.$links[$key]['label']; + } + print ''; + } + } + print ''; + foreach($links as $key=>$val) + { + if ($links[$key]['type']=='company') { + $societestatic->id=$links[$key]['url_id']; + $societestatic->nom=$links[$key]['label']; + print $societestatic->getNomUrl(1,'',16); + } + else if ($links[$key]['type']=='sc') { // sc=old value + $chargestatic->id=$links[$key]['url_id']; + if (preg_match('/^\((.*)\)$/i',$links[$key]['label'],$reg)) + { + if ($reg[1]=='socialcontribution') $reg[1]='SocialContribution'; + $chargestatic->lib=$langs->trans($reg[1]); + } + else + { + $chargestatic->lib=$links[$key]['label']; + } + $chargestatic->ref=$chargestatic->lib; + print $chargestatic->getNomUrl(1,16); + } + else if ($links[$key]['type']=='member') { + $memberstatic->id=$links[$key]['url_id']; + $memberstatic->ref=$links[$key]['label']; + print $memberstatic->getNomUrl(1,16,'card'); + } + } + print '".price($objp->amount * -1)."   ".price($objp->amount)." '.price($total).' '.price($total).'-"; + print ''; + print img_view(); + print ''; + print "  "; + print "num_releve&account=$acct->id\">$objp->num_releve"; + print "'; + if ($user->rights->banque->modifier || $user->rights->banque->consolidate) + { + print ''; + print img_edit(); + print ''; + } + else + { + print ''; + print img_view(); + print ''; + } + print ' '; + if ($user->rights->banque->modifier) + { + print ''; + print img_delete(); + print ''; + } + print '
'; + if ($sep) print ' '; + else print $langs->trans("CurrentBalance"); + print ''.price($total).' 
"; + + print "\n\n"; + + /* + * Boutons actions + */ + if ($_GET["action"] != 'addline' && $_GET["action"] != 'delete') + { + print '
'; + + if ($acct->type != 2 && $acct->rappro) // Si non compte cash et rapprochable + { + if ($user->rights->banque->consolidate) + { + print ''.$langs->trans("Conciliate").''; + } + else + { + print "trans("NotEnoughPermissions")."\" href=\"#\">".$langs->trans("Conciliate").""; + } + } + + if ($user->rights->banque->modifier) + { + print ''.$langs->trans("AddBankRecord").''; + } + else + { + print "trans("NotEnoughPermissions")."\" href=\"#\">".$langs->trans("AddBankRecord").""; + } + + print '
'; + } + + print '
'; } else { - print $langs->trans("ErrorBankAccountNotFound"); + print $langs->trans("ErrorBankAccountNotFound"); } $db->close(); diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 549ff685c8d..4b55c7db997 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -903,10 +903,12 @@ class Account extends CommonObject * \class AccountLine * \brief Classe permettant la gestion des lignes de transactions bancaires */ -class AccountLine +class AccountLine extends CommonObject { var $error; var $db; + var $element='bank'; + var $table_element='bank'; var $id; var $ref; @@ -940,15 +942,19 @@ class AccountLine } /** - * \brief Charge en memoire depuis la base, une ecriture sur le compte - * \param id Id de la ligne ecriture a recuperer - * \return int <0 if KO, >0 if OK + * \brief Charge en memoire depuis la base, une ecriture sur le compte + * \param id Id de la ligne ecriture a recuperer + * \param ref Ref of object + * \return int <0 if KO, >0 if OK */ - function fetch($rowid) + function fetch($rowid,$ref='') { global $conf; - $sql = "SELECT b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,"; + // Check parameters + if (empty($rowid) && empty($ref)) return -1; + + $sql = "SELECT b.rowid, b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,"; $sql.= " b.fk_user_author, b.fk_user_rappro,"; $sql.= " b.fk_type, b.num_releve, b.num_chq, b.rappro, b.note,"; $sql.= " ba.label as bank_account_label"; @@ -956,19 +962,19 @@ class AccountLine $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; $sql.= " AND ba.entity = ".$conf->entity; - $sql.= " AND b.rowid = ".$rowid; + if ($ref) $sql.= " AND b.rowid='".$ref."'"; + else $sql.= " AND b.rowid=".$rowid; dol_syslog("AccountLine::fetch sql=".$sql); $result = $this->db->query($sql); if ($result) { - if ($this->db->num_rows($result)) - { - $obj = $this->db->fetch_object($result); - - $this->id = $rowid; - $this->rowid = $rowid; - $this->ref = $rowid; + $obj = $this->db->fetch_object($result); + if ($obj) + { + $this->id = $obj->rowid; + $this->rowid = $obj->rowid; + $this->ref = $obj->rowid; $this->datec = $obj->datec; $this->datev = $obj->datev; diff --git a/htdocs/compta/bank/ligne.php b/htdocs/compta/bank/ligne.php index a61594342f2..14937f6dce9 100644 --- a/htdocs/compta/bank/ligne.php +++ b/htdocs/compta/bank/ligne.php @@ -38,6 +38,7 @@ $langs->load("categories"); if ($conf->adherent->enabled) $langs->load("members"); $rowid=isset($_GET["rowid"])?$_GET["rowid"]:$_POST["rowid"]; +$ref=isset($_GET["ref"])?$_GET["ref"]:$_POST["ref"]; $orig_account=isset($_GET["orig_account"])?$_GET["orig_account"]:$_POST["orig_account"]; $html = new Form($db); @@ -228,40 +229,32 @@ if ($result) $objp = $db->fetch_object($result); $total = $total + $objp->amount; - $acct=new Account($db,$objp->fk_account); + $acct=new Account($db); $acct->fetch($objp->fk_account); $account = $acct->id; + $bankline = new AccountLine($db); + $bankline->fetch($rowid,$ref); + $links=$acct->get_url($rowid); + $bankline->load_previous_next_ref('','rowid'); // Ref print ''.$langs->trans("Ref").""; - print ''.$objp->rowid.''; + print ''; + print $html->showrefnav($bankline,'rowid','',1,'rowid','rowid'); + print ''; print ''; - // Author - print ''.$langs->trans("Author").""; - if ($objp->fk_user_author) - { - $author=new User($db); - $author->fetch($objp->fk_user_author); - print ''; - print img_object($langs->trans("ShowUser"),'user').' '.$author->getFullName($langs).''; - } - else - { - print ' '; - } - print ""; - - $i++; + $i++; print '
'; print ''; print ""; print ""; - // Account + + // Account print "".$langs->trans("Account").""; print ''; print ''.img_object($langs->trans("ShowAccount"),'account').' '.$acct->label.''; @@ -269,7 +262,72 @@ if ($result) print ''; print ''; - // Date ope + // Show links of bank transactions + if (sizeof($links)) + { + print "".$langs->trans("Links").""; + print ''; + foreach($links as $key=>$val) + { + if ($key) print '
'; + if ($links[$key]['type']=='payment') { + print ''; + print img_object($langs->trans('ShowPayment'),'payment').' '; + print $langs->trans("Payment"); + print ''; + } + else if ($links[$key]['type']=='payment_supplier') { + print ''; + print img_object($langs->trans('ShowPayment'),'payment').' '; + print $langs->trans("Payment"); + print ''; + } + else if ($links[$key]['type']=='company') { + print ''; + print img_object($langs->trans('ShowCustomer'),'company').' '; + print $links[$key]['label']; + print ''; + } + else if ($links[$key]['type']=='sc') { + print ''; + print img_object($langs->trans('ShowSocialContribution'),'bill').' '; + print $langs->trans("SocialContribution").($links[$key]['label']?' - '.$links[$key]['label']:''); + print ''; + } + else if ($links[$key]['type']=='payment_sc') { + print ''; + print img_object($langs->trans('ShowPayment'),'payment').' '; + print $langs->trans("SocialContributionPayment"); + print ''; + } + else if ($links[$key]['type']=='payment_vat') { + print ''; + print img_object($langs->trans('ShowVAT'),'payment').' '; + print $langs->trans("VATPayment"); + print ''; + } + else if ($links[$key]['type']=='member') { + print ''; + print img_object($langs->trans('ShowMember'),'user').' '; + print $links[$key]['label']; + print ''; + } + else if ($links[$key]['type']=='banktransfert') { + print ''; + print img_object($langs->trans('ShowTransaction'),'payment').' '; + print $langs->trans("TransactionOnTheOtherAccount"); + print ''; + } + else { + print ''; + print $links[$key]['label']; + print ''; + } + } + print ''; + } + + // Date ope print ''.$langs->trans("DateOperation").''; if (! $objp->rappro && ($user->rights->banque->modifier || $user->rights->banque->consolidate)) { @@ -340,71 +398,6 @@ if ($result) } print ''; - // Affiche liens - if (sizeof($links)) - { - print "".$langs->trans("Links").""; - print ''; - foreach($links as $key=>$val) - { - if ($key) print '
'; - if ($links[$key]['type']=='payment') { - print ''; - print img_object($langs->trans('ShowPayment'),'payment').' '; - print $langs->trans("Payment"); - print ''; - } - else if ($links[$key]['type']=='payment_supplier') { - print ''; - print img_object($langs->trans('ShowPayment'),'payment').' '; - print $langs->trans("Payment"); - print ''; - } - else if ($links[$key]['type']=='company') { - print ''; - print img_object($langs->trans('ShowCustomer'),'company').' '; - print $links[$key]['label']; - print ''; - } - else if ($links[$key]['type']=='sc') { - print ''; - print img_object($langs->trans('ShowBill'),'bill').' '; - print $langs->trans("SocialContribution"); - print ''; - } - else if ($links[$key]['type']=='payment_sc') { - print ''; - print img_object($langs->trans('ShowPayment'),'payment').' '; - print $langs->trans("SocialContributionPayment"); - print ''; - } - else if ($links[$key]['type']=='payment_vat') { - print ''; - print img_object($langs->trans('ShowVAT'),'payment').' '; - print $langs->trans("VATPayment"); - print ''; - } - else if ($links[$key]['type']=='member') { - print ''; - print img_object($langs->trans('ShowMember'),'user').' '; - print $links[$key]['label']; - print ''; - } - else if ($links[$key]['type']=='banktransfert') { - print ''; - print img_object($langs->trans('ShowTransaction'),'payment').' '; - print $langs->trans("TransactionOnTheOtherAccount"); - print ''; - } - else { - print ''; - print $links[$key]['label']; - print ''; - } - } - print ' '; - } - // Amount print "".$langs->trans("Amount").""; if (! $objp->rappro && $user->rights->banque->modifier) diff --git a/htdocs/compta/paiement_charge.php b/htdocs/compta/paiement_charge.php index 12041ed190d..0e028582fe6 100755 --- a/htdocs/compta/paiement_charge.php +++ b/htdocs/compta/paiement_charge.php @@ -97,6 +97,9 @@ if ($_POST["action"] == 'add_paiement') $paiement->note = $_POST["note"]; $paymentid = $paiement->create($user); + $socialcontrib = new ChargeSociales($db); + $socialcontrib->fetch($paiement->chid); + if ($paymentid > 0) { // On determine le montant total du paiement @@ -123,7 +126,7 @@ if ($_POST["action"] == 'add_paiement') // Mise a jour liens (pour chaque charge concernee par le paiement) foreach ($paiement->amounts as $key => $value) { - //$acc->add_url_line($bank_line_id, $chid, DOL_URL_ROOT.'/compta/charges.php?id=', '(socialcontribution)','payment_sc'); + $acc->add_url_line($bank_line_id, $chid, DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_libelle.(($socialcontrib->lib && $socialcontrib->lib!=$socialcontrib->type_libelle)?' ('.$socialcontrib->lib.')':''),'sc'); $acc->add_url_line($bank_line_id, $paymentid, DOL_URL_ROOT.'/compta/payment_sc/fiche.php?id=', '(paiement)','payment_sc'); } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 1dd253c52a1..a4c693b1d9c 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -728,7 +728,7 @@ class CommonObject } /** - * + * * Enter description here ... * @param unknown_type $rowid */ @@ -744,7 +744,7 @@ class CommonObject } /** - * + * * Enter description here ... * @param unknown_type $rowid */ @@ -761,7 +761,7 @@ class CommonObject // Update position of line $this->updateLineDown($rowid, $rang, $max); } - + /** * Update position of line (rang) */ @@ -774,7 +774,7 @@ class CommonObject dol_print_error($this->db); } } - + /** * Update position of line up (rang) */ @@ -800,7 +800,7 @@ class CommonObject } } } - + /** * Update position of line down (rang) */ @@ -826,7 +826,7 @@ class CommonObject } } } - + /** * Get position of line (rang) * @result int Value of rang in table of lines @@ -842,7 +842,7 @@ class CommonObject return $row[0]; } } - + /** * Get rowid of the line relative to its position * @result int Rowid of the line diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 8111b10846d..b66cc474027 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2975,17 +2975,17 @@ class Form } /** - * \brief Return a HTML area with the reference of object and a naviagation bar for a business object - * \param object Object to show - * \param paramid Name of parameter to use to name the id into the URL link - * \param morehtml More html content to output just before the nav bar - * \param shownav Show Condition (navigation is shown if value is 1) - * \param fieldid Nom du champ en base a utiliser pour select next et previous - * \param fieldref Nom du champ objet ref (object->ref) a utiliser pour select next et previous - * \param morehtmlref Code html supplementaire a afficher apres ref - * \param moreparam More param to add in nav link url. - * \return string Portion HTML avec ref + boutons nav - * \remarks To add a particular filter on select, you must set $object->next_prev_filter to SQL criteria. + * Return a HTML area with the reference of object and a naviagation bar for a business object + * To add a particular filter on select, you must set $object->next_prev_filter to SQL criteria. + * @param object Object to show + * @param paramid Name of parameter to use to name the id into the URL link + * @param morehtml More html content to output just before the nav bar + * @param shownav Show Condition (navigation is shown if value is 1) + * @param fieldid Nom du champ en base a utiliser pour select next et previous + * @param fieldref Nom du champ objet ref (object->ref) a utiliser pour select next et previous + * @param morehtmlref Code html supplementaire a afficher apres ref + * @param moreparam More param to add in nav link url. + * @return string Portion HTML avec ref + boutons nav */ function showrefnav($object,$paramid,$morehtml='',$shownav=1,$fieldid='rowid',$fieldref='ref',$morehtmlref='',$moreparam='') {