* Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2010 Juanjo Menent * Copyright (C) 2015 Jean-François Ferry * * 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 * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/compta/bank/rappro.php * \ingroup banque * \brief Page to reconciliate bank transactions */ require('../../main.inc.php'); require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; $langs->load("banks"); $langs->load("categories"); $langs->load("bills"); if (! $user->rights->banque->consolidate) accessforbidden(); $action=GETPOST('action', 'alpha'); $id=GETPOST('account', 'int'); /* * Actions */ // Conciliation if ($action == 'rappro' && $user->rights->banque->consolidate) { $error=0; // Definition, nettoyage parametres $num_releve=trim($_POST["num_releve"]); if ($num_releve) { $bankline=new AccountLine($db); if (isset($_POST['rowid']) && is_array($_POST['rowid'])) { foreach($_POST['rowid'] as $row) { if($row > 0) { $result=$bankline->fetch($row); $bankline->num_releve=$num_releve; //$_POST["num_releve"]; $result=$bankline->update_conciliation($user,$_POST["cat"]); if ($result < 0) { setEventMessage($bankline->error, 'errors'); $error++; break; } } } } } else { $error++; $langs->load("errors"); setEventMessage($langs->trans("ErrorPleaseTypeBankTransactionReportName"), 'errors'); } if (! $error) { header('Location: '.DOL_URL_ROOT.'/compta/bank/rappro.php?account='.$id); // To avoid to submit twice and allow back exit; } } /* * Action suppression ecriture */ if ($action == 'del') { $bankline=new AccountLine($db); if ($bankline->fetch($_GET["rowid"]) > 0) { $result = $bankline->delete($user); if ($result < 0) { dol_print_error($db, $bankline->error); } } else { setEventMessage($langs->trans('ErrorRecordNotFound'), 'errors'); } } // Load bank groups $sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_categ ORDER BY label"; $resql = $db->query($sql); $options=""; if ($resql) { $var=True; $num = $db->num_rows($resql); if ($num > 0) $options .= ''; $i = 0; while ($i < $num) { $obj = $db->fetch_object($resql); $options .= ''."\n"; $i++; } $db->free($resql); //print $options; } else dol_print_error($db); /* * View */ $form=new Form($db); llxHeader(); $societestatic=new Societe($db); $chargestatic=new ChargeSociales($db); $memberstatic=new Adherent($db); $paymentstatic=new Paiement($db); $paymentsupplierstatic=new PaiementFourn($db); $paymentvatstatic=new TVA($db); $acct = new Account($db); $acct->fetch($id); $now=dol_now(); $sql = "SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type as type"; $sql.= ", b.fk_bordereau"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= " WHERE rappro=0 AND fk_account=".$acct->id; $sql.= " ORDER BY dateo ASC"; $sql.= " LIMIT 1000"; // Limit to avoid page overload /// ajax adjust value date print ' '; $resql = $db->query($sql); if ($resql) { $var=True; $num = $db->num_rows($resql); print_fiche_titre($langs->trans("Reconciliation").': '.$acct->label.'', '', 'title_bank.png'); print '
'; // Show last bank receipts $nbmax=5; $liste=""; $sql = "SELECT DISTINCT num_releve FROM ".MAIN_DB_PREFIX."bank"; $sql.= " WHERE fk_account=".$acct->id." AND num_releve IS NOT NULL"; $sql.= $db->order("num_releve","DESC"); $sql.= $db->plimit($nbmax+1); print $langs->trans("LastAccountStatements").' : '; $resqlr=$db->query($sql); if ($resqlr) { $numr=$db->num_rows($resqlr); $i=0; while (($i < $numr) && ($i < $nbmax)) { $objr = $db->fetch_object($resqlr); $last_releve = $objr->num_releve; $i++; $liste=''.$objr->num_releve.'   '.$liste; } if ($numr >= $nbmax) $liste="...   ".$liste; print $liste; if ($numr > 0) print '

'; else print ''.$langs->trans("None").'

'; } else { dol_print_error($db); } print '
'; print ''; print ""; print "id."\">"; print ''.$langs->trans("InputReceiptNumber").': '; print ''; print '
'; if ($options) { print $langs->trans("EventualyAddCategory").':
'; } print '
'.$langs->trans("ThenCheckLinesAndConciliate").' "'.$langs->trans("Conciliate").'"
'; print '
'; print ''; print ''."\n"; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $i = 0; while ($i < $num) { $objp = $db->fetch_object($resql); $var=!$var; print "\n"; // print ''; // print ''; // print "rowid."\">"; // Date op print ''; // Date value if (! $objp->rappro && ($user->rights->banque->modifier || $user->rights->banque->consolidate)) { print ''; } else { print ''; } // Type + Number $label=($langs->trans("PaymentType".$objp->type)!="PaymentType".$objp->type)?$langs->trans("PaymentType".$objp->type):$objp->type; // $objp->type is a code if ($label=='SOLD') $label=''; print ''; // Description print ''; if ($objp->amount < 0) { print "\n"; } else { print "\n"; } if ($objp->rappro) { // If line already reconciliated, we show receipt print ""; } else { // If not already reconciliated if ($user->rights->banque->modifier) { print '"; } else { print ""; } } // Show checkbox for conciliation if ($db->jdate($objp->do) <= $now) { print '"; } else { print ''; } print "\n"; $i++; } $db->free($resql); print "
'.$langs->trans("DateOperationShort").''.$langs->trans("DateValueShort").''.$langs->trans("Type").''.$langs->trans("Description").''.$langs->trans("Debit").''.$langs->trans("Credit").''.$langs->trans("Action").''.$langs->trans("ToConciliate").'
'.dol_print_date($db->jdate($objp->do),"day").''."\n"; print ''.dol_print_date($db->jdate($objp->dv),"day").""; print ' '; print ''; print ''; print img_edit_remove() . " "; print ''; print img_edit_add() .""; print ''; print ''; print dol_print_date($db->jdate($objp->dv),"day"); print ''.$label.($objp->num_chq?' '.$objp->num_chq:'').($objp->fk_bordereau>0?' ('.$objp->fk_bordereau.')':'').''; $reg=array(); preg_match('/\((.+)\)/i',$objp->label,$reg); // Si texte entoure de parentheses on tente recherche de traduction if ($reg[1] && $langs->trans($reg[1])!=$reg[1]) print $langs->trans($reg[1]); else print $objp->label; print ''; /* * Ajout les liens (societe, company...) */ $newline=1; $links = $acct->get_url($objp->rowid); foreach($links as $key=>$val) { if ($newline == 0) print ' - '; else if ($newline == 1) print '
'; if ($links[$key]['type']=='payment') { $paymentstatic->id=$links[$key]['url_id']; print ' '.$paymentstatic->getNomUrl(2); $newline=0; } elseif ($links[$key]['type']=='payment_supplier') { $paymentsupplierstatic->id=$links[$key]['url_id']; $paymentsupplierstatic->ref=$links[$key]['label']; print ' '.$paymentsupplierstatic->getNomUrl(1); $newline=0; } elseif ($links[$key]['type']=='company') { $societestatic->id=$links[$key]['url_id']; $societestatic->name=$links[$key]['label']; print $societestatic->getNomUrl(1,'',24); $newline=0; } else if ($links[$key]['type']=='sc') { $chargestatic->id=$links[$key]['url_id']; $chargestatic->ref=$links[$key]['url_id']; $chargestatic->lib=$langs->trans("SocialContribution"); print ' '.$chargestatic->getNomUrl(1); } else if ($links[$key]['type']=='payment_sc') { // We don't show anything because there is 1 payment for 1 social contribution and we already show link to social contribution /*print ''; print img_object($langs->trans('ShowPayment'),'payment').' '; print $langs->trans("SocialContributionPayment"); print '';*/ $newline=2; } else if ($links[$key]['type']=='payment_vat') { $paymentvatstatic->id=$links[$key]['url_id']; $paymentvatstatic->ref=$links[$key]['url_id']; $paymentvatstatic->ref=$langs->trans("VATPayment"); print ' '.$paymentvatstatic->getNomUrl(1); } else if ($links[$key]['type']=='banktransfert') { print ''; print img_object($langs->trans('ShowTransaction'),'payment').' '; print $langs->trans("TransactionOnTheOtherAccount"); print ''; } else if ($links[$key]['type']=='member') { print ''; print img_object($langs->trans('ShowMember'),'user').' '; print $links[$key]['label']; print ''; } 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 ''; $newline=0; } } print '
".price($objp->amount * -1)."  ".price($objp->amount)."num_releve&account=$acct->id\">$objp->num_releve'; print ''; print img_edit(); print '  '; $now=dol_now(); if ($db->jdate($objp->do) <= $now) { print ''; print img_delete(); print ''; } else { print " "; // On n'empeche la suppression car le raprochement ne pourra se faire qu'apr�s la date pass�e et que l'�criture apparaisse bien sur le compte. } print " '; print 'rowid])?' checked':'').'>'; // print ''; // print '   '; // print "trans("Conciliate")."\">"; // if ($options) // { // print "
"; // } print "
'; print $langs->trans("FutureTransaction"); print '

\n"; print '

'; print "
\n"; } else { dol_print_error($db); } llxFooter(); $db->close();