* Copyright (C) 2003 Xavier DUTOIT * Copyright (C) 2004-2017 Laurent Destailleur * Copyright (C) 2004 Christophe Combelles * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2015-2017 Alexandre Spangaro * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2016 Marcos García * Copyright (C) 2018 Frédéric France * * 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/ligne.php * \ingroup bank * \brief Page to edit a bank transaction record */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; // Load translation files required by the page $langs->loadLangs(array('banks', 'categories', 'compta', 'bills', 'other')); if (! empty($conf->adherent->enabled)) $langs->load("members"); if (! empty($conf->don->enabled)) $langs->load("donations"); if (! empty($conf->loan->enabled)) $langs->load("loan"); if (! empty($conf->salaries->enabled)) $langs->load("salaries"); $id = (GETPOST('id','int') ? GETPOST('id','int') : GETPOST('account','int')); $ref = GETPOST('ref','alpha'); $action=GETPOST('action','alpha'); $confirm=GETPOST('confirm','alpha'); $rowid=GETPOST("rowid",'int'); $orig_account=GETPOST("orig_account"); $backtopage=GETPOST('backtopage','alpha'); $cancel=GETPOST('cancel','alpha'); // Security check $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref :'')); $fieldtype = (! empty($ref) ? 'ref' :'rowid'); if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'banque',$fieldvalue,'bank_account','','',$fieldtype); if (! $user->rights->banque->lire && ! $user->rights->banque->consolidate) accessforbidden(); /* * Actions */ if ($cancel) { if ($backtopage) { header("Location: ".$backtopage); exit; } } if ($user->rights->banque->consolidate && $action == 'donext') { $al = new AccountLine($db); $al->dateo_next($_GET["rowid"]); }elseif ($user->rights->banque->consolidate && $action == 'doprev') { $al = new AccountLine($db); $al->dateo_previous($_GET["rowid"]); }elseif ($user->rights->banque->consolidate && $action == 'dvnext') { $al = new AccountLine($db); $al->datev_next($_GET["rowid"]); }elseif ($user->rights->banque->consolidate && $action == 'dvprev') { $al = new AccountLine($db); $al->datev_previous($_GET["rowid"]); } if ($action == 'confirm_delete_categ' && $confirm == "yes" && $user->rights->banque->modifier) { $cat1=GETPOST("cat1",'int'); if (!empty($rowid) && !empty($cat1)) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid = ".$rowid." AND fk_categ = ".$cat1; if (! $db->query($sql)) { dol_print_error($db); } } else { setEventMessages($langs->trans("MissingIds"), null, 'errors'); } } if ($user->rights->banque->modifier && $action == "update") { $error=0; $acline = new AccountLine($db); $acline->fetch($rowid); $acsource = new Account($db); $acsource->fetch($id); $actarget = new Account($db); if (GETPOST('accountid','int') > 0 && ! $acline->rappro && ! $acline->getVentilExportCompta()) // We ask to change bank account { $actarget->fetch(GETPOST('accountid','int')); } else { $actarget->fetch($id); } if ($actarget->courant == Account::TYPE_CASH && GETPOST('value','alpha') != 'LIQ') { setEventMessages($langs->trans("ErrorCashAccountAcceptsOnlyCashMoney"), null, 'errors'); $error++; } if (! $error) { $db->begin(); $amount = price2num($_POST['amount']); $dateop = dol_mktime(12,0,0,$_POST["dateomonth"],$_POST["dateoday"],$_POST["dateoyear"]); $dateval= dol_mktime(12,0,0,$_POST["datevmonth"],$_POST["datevday"],$_POST["datevyear"]); $sql = "UPDATE ".MAIN_DB_PREFIX."bank"; $sql.= " SET "; // Always opened if (isset($_POST['value'])) $sql.=" fk_type='".$db->escape($_POST['value'])."',"; if (isset($_POST['num_chq'])) $sql.=" num_chq='".$db->escape($_POST["num_chq"])."',"; if (isset($_POST['banque'])) $sql.=" banque='".$db->escape($_POST["banque"])."',"; if (isset($_POST['emetteur'])) $sql.=" emetteur='".$db->escape($_POST["emetteur"])."',"; // Blocked when conciliated if (! $acline->rappro) { if (isset($_POST['label'])) $sql.=" label='".$db->escape($_POST["label"])."',"; if (isset($_POST['amount'])) $sql.=" amount='".$amount."',"; if (isset($_POST['dateomonth'])) $sql.=" dateo = '".$db->idate($dateop)."',"; if (isset($_POST['datevmonth'])) $sql.=" datev = '".$db->idate($dateval)."',"; } $sql.= " fk_account = ".$actarget->id; $sql.= " WHERE rowid = ".$acline->id; $result = $db->query($sql); if (! $result) { $error++; } if (! $error) { $arrayofcategs=GETPOST('custcats', 'array'); $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid = ".$rowid; if (! $db->query($sql)) { $error++; dol_print_error($db); } if (count($arrayofcategs)) { foreach($arrayofcategs as $val) { $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (lineid, fk_categ) VALUES (".$rowid.", ".$val.")"; if (! $db->query($sql)) { $error++; dol_print_error($db); } } // $arrayselected will be loaded after in page output } } if (! $error) { setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); $db->commit(); } else { $db->rollback(); dol_print_error($db); } } } // Reconcile if ($user->rights->banque->consolidate && ($action == 'num_releve' || $action == 'setreconcile')) { $num_rel=trim($_POST["num_rel"]); $rappro=$_POST['reconciled']?1:0; // Check parameters if ($rappro && empty($num_rel)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountStatement")), null, 'errors'); $error++; } if (! $error) { $db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."bank"; $sql.= " SET num_releve=".($num_rel?"'".$num_rel."'":"null"); if (empty($num_rel)) $sql.= ", rappro = 0"; else $sql.=", rappro = ".$rappro; $sql.= " WHERE rowid = ".$rowid; dol_syslog("ligne.php", LOG_DEBUG); $result = $db->query($sql); if ($result) { setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); $db->commit(); } else { $db->rollback(); dol_print_error($db); } } } /* * View */ $form = new Form($db); llxHeader('', $langs->trans("BankTransaction")); $c = new Categorie($db); $cats = $c->containing($rowid, Categorie::TYPE_BANK_LINE); foreach ($cats as $cat) { $arrayselected[] = $cat->id; } $tabs = array( array( DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$rowid, $langs->trans('Card') ), array( DOL_URL_ROOT.'/compta/bank/info.php?rowid='.$rowid, $langs->trans('Info') ) ); $sql = "SELECT b.rowid,b.dateo as do,b.datev as dv, b.amount, b.label, b.rappro,"; $sql.= " b.num_releve, b.fk_user_author, b.num_chq, b.fk_type, b.fk_account, b.fk_bordereau as receiptid,"; $sql.= " b.emetteur,b.banque"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= " WHERE rowid=".$rowid; $sql.= " ORDER BY dateo ASC"; $result = $db->query($sql); if ($result) { $i = 0; $total = 0; if ($db->num_rows($result)) { $objp = $db->fetch_object($result); $total = $total + $objp->amount; $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'); // Confirmations if ($action == 'delete_categ') { print $form->formconfirm($_SERVER['PHP_SELF']."?rowid=".$rowid."&cat1=".GETPOST("fk_categ")."&orig_account=".$orig_account, $langs->trans("RemoveFromRubrique"), $langs->trans("RemoveFromRubriqueConfirm"), "confirm_delete_categ", '', 'yes', 1); } print '
'; print ''; print ''; print ''; print ''; dol_fiche_head($tabs, 0, $langs->trans('LineRecord'), -1, 'account', 0); $linkback = ''.$langs->trans("BackToList").''; dol_banner_tab($bankline, 'rowid', $linkback); print '
'; print '
'; print ''; $i++; // Bank account print ''; print ''; print ''; // Show links of bank transactions if (count($links)) { print ''; print ''; } //$user->rights->banque->modifier=false; //$user->rights->banque->consolidate=true; // Type of payment / Number print ""; if ($user->rights->banque->modifier || $user->rights->banque->consolidate) { print ''; } else { print ''; } print ""; // Transmitter print ""; if ($user->rights->banque->modifier || $user->rights->banque->consolidate) { print ''; } else { print ''; } print ""; // Bank of cheque print ""; if ($user->rights->banque->modifier || $user->rights->banque->consolidate) { print ''; } else { print ''; } print ""; // Date ope print ''; if ($user->rights->banque->modifier || $user->rights->banque->consolidate) { print ''; } else { print ''; } print ''; // Value date print ""; if ($user->rights->banque->modifier || $user->rights->banque->consolidate) { print ''; } else { print ''; } print ""; // Description print ""; if ($user->rights->banque->modifier || $user->rights->banque->consolidate) { print ''; } else { print ''; } print ''; // Amount print ""; if ($user->rights->banque->modifier) { print ''; } else { print ''; } print ""; // Categories if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) { $langs->load('categories'); // Bank line print '"; } print "
'.$langs->trans("Account").''; if (! $objp->rappro && ! $bankline->getVentilExportCompta()) { print $form->select_comptes($acct->id, 'accountid', 0, '', 0); } else { print $acct->getNomUrl(1,'transactions','reflabel'); } print '
'.$langs->trans("Links").''; foreach($links as $key=>$val) { if ($key) print '
'; if ($links[$key]['type']=='payment') { require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; $paymenttmp=new Paiement($db); $paymenttmp->fetch($links[$key]['url_id']); $paymenttmp->ref = $langs->trans("Payment").' '.$paymenttmp->ref; /*print ''; print img_object($langs->trans('ShowPayment'),'payment').' '; print $langs->trans("Payment"); print '';*/ print $paymenttmp->getNomUrl(1); } elseif ($links[$key]['type']=='payment_supplier') { require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; $paymenttmp=new PaiementFourn($db); $paymenttmp->fetch($links[$key]['url_id']); $paymenttmp->ref = $langs->trans("Payment").' '.$paymenttmp->ref; /*print ''; print img_object($langs->trans('ShowPayment'),'payment').' '; print $langs->trans("Payment"); print '';*/ print $paymenttmp->getNomUrl(1); } elseif ($links[$key]['type']=='company') { $societe=new Societe($db); $societe->fetch($links[$key]['url_id']); print $societe->getNomUrl(1); } elseif ($links[$key]['type']=='sc') { print ''; print img_object($langs->trans('ShowSocialContribution'),'bill').' '; print $langs->trans("SocialContribution").($links[$key]['label']?' - '.$links[$key]['label']:''); print ''; } elseif ($links[$key]['type']=='payment_sc') { print ''; print img_object($langs->trans('ShowPayment'),'payment').' '; print $langs->trans("SocialContributionPayment"); print ''; } elseif ($links[$key]['type']=='payment_vat') { print ''; print img_object($langs->trans('ShowVAT'),'payment').' '; print $langs->trans("VATPayment"); print ''; } elseif ($links[$key]['type']=='payment_salary') { print ''; print img_object($langs->trans('ShowPaymentSalary'),'payment').' '; print $langs->trans("SalaryPayment"); print ''; } elseif ($links[$key]['type']=='payment_loan') { print ''; print img_object($langs->trans('ShowLoanPayment'),'payment').' '; print $langs->trans("PaymentLoan"); print ''; } elseif ($links[$key]['type']=='loan') { print ''; print img_object($langs->trans('ShowLoan'),'bill').' '; print $langs->trans("Loan"); print ''; } elseif ($links[$key]['type']=='member') { print ''; print img_object($langs->trans('ShowMember'),'user').' '; print $links[$key]['label']; print ''; } elseif ($links[$key]['type']=='payment_donation') { print ''; print img_object($langs->trans('ShowDonation'),'payment').' '; print $langs->trans("DonationPayment"); print ''; } elseif ($links[$key]['type']=='banktransfert') { print ''; print img_object($langs->trans('ShowTransaction'),'payment').' '; print $langs->trans("TransactionOnTheOtherAccount"); print ''; } elseif ($links[$key]['type']=='user') { print ''; print img_object($langs->trans('ShowUser'),'user').' '; print $langs->trans("User"); print ''; } elseif ($links[$key]['type']=='payment_various') { print ''; print img_object($langs->trans('ShowVariousPayment'),'payment').' '; print $langs->trans("VariousPayment"); print ''; } else { print ''; print img_object('','generic').' '; print $links[$key]['label']; print ''; } } print '
".$langs->trans("Type")." / ".$langs->trans("Numero"); print ' ('.$langs->trans("ChequeOrTransferNumber").')'; print "'; $form->select_types_paiements($objp->fk_type,"value",'',2); print ''; if ($objp->receiptid) { include_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php'; $receipt=new RemiseCheque($db); $receipt->fetch($objp->receiptid); print '     '.$langs->trans("CheckReceipt").': '.$receipt->getNomUrl(2); } print ''.$objp->fk_type.' '.$objp->num_chq.'
".$langs->trans("CheckTransmitter"); print ' ('.$langs->trans("ChequeMaker").')'; print "'; print ''; print ''.$objp->emetteur.'
".$langs->trans("Bank"); print ' ('.$langs->trans("ChequeBank").')'; print "'; print ''; print ''.$objp->banque.'
'.$langs->trans("DateOperation").''; print $form->selectDate($db->jdate($objp->do), 'dateo', '', '', '', 'update', 1, 0, $objp->rappro); if (! $objp->rappro) { print '   '; print ''; print img_edit_remove() . " "; print ''; print img_edit_add() .""; } print ''; print dol_print_date($db->jdate($objp->do),"day"); print '
".$langs->trans("DateValue")."'; print $form->selectDate($db->jdate($objp->dv), 'datev', '', '', '', 'update', 1, 0, $objp->rappro); if (! $objp->rappro) { print '   '; print ''; print img_edit_remove() . " "; print ''; print img_edit_add() .""; } print ''; print dol_print_date($db->jdate($objp->dv),"day"); print '
".$langs->trans("Label")."'; print 'rappro?' disabled':'').' value="'; if (preg_match('/^\((.*)\)$/i',$objp->label,$reg)) { // Label generique car entre parentheses. On l'affiche en le traduisant print $langs->trans($reg[1]); } else { print $objp->label; } print '">'; print ''; if (preg_match('/^\((.*)\)$/i',$objp->label,$reg)) { // Label generique car entre parentheses. On l'affiche en le traduisant print $langs->trans($reg[1]); } else { print $objp->label; } print '
".$langs->trans("Amount")."'; print 'rappro?' disabled':'').' value="'.price($objp->amount).'"> '.$langs->trans("Currency".$acct->currency_code); print ''; print price($objp->amount); print '
' . $form->editfieldkey('RubriquesTransactions', 'custcats', '', $object, 0) . ''; $cate_arbo = $form->select_all_categories(Categorie::TYPE_BANK_LINE, null, 'parent', null, null, 1); print $form->multiselectarray('custcats', $cate_arbo, $arrayselected, null, null, null, null, "90%"); print "
"; print '
'; dol_fiche_end(); print '

'; print "
"; // Releve rappro if ($acct->canBeConciliated() > 0) // Si compte rapprochable { print load_fiche_titre($langs->trans("Reconciliation"), '', 'title_bank.png'); print '
'."\n"; print '
'; print ''; print ''; print ''; print ''; print '
'; print ''; print '"; if ($user->rights->banque->consolidate) { print ''; } else { print ''; } print ''; print ""; if ($user->rights->banque->consolidate) { print ''; } else { print ''; } print ''; print '
'.$langs->trans("Conciliation")."'; if ($objp->rappro) { print $langs->trans("AccountStatement").' rappro?' disabled':'').'>'; print ''; } else { print $langs->trans("AccountStatement").' rappro?' disabled':'').'>'; } if ($objp->num_releve) print '   ('.$langs->trans("AccountStatement").' '.$objp->num_releve.')'; print ''.$objp->num_releve.' 
".$langs->trans("BankLineConciliated")."'; print 'rappro?' checked="checked"':'')).'">'; print ''.yn($objp->rappro).'
'; print '
'; print '
'; print ''; if ($backtopage) { print '   '; print ''; } print '
'; print '
'; } } $db->free($result); } else dol_print_error($db); // End of page llxFooter(); $db->close();