* Copyright (C) 2007-2011 Laurent Destailleur * Copyright (C) 2009-2012 Regis Houssin * Copyright (C) 2011-2016 Juanjo Menent * Copyright (C) 2013 Philippe Grand * Copyright (C) 2015-2016 Alexandre Spangaro * Copyright (C) 2018-2021 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/paiement/cheque/card.php * \ingroup bank, invoice * \brief Page for cheque deposits */ require '../../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Load translation files required by the page $langs->loadLangs(array('banks', 'categories', 'bills', 'companies', 'compta')); $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); // Security check $fieldname = (!empty($ref) ? 'ref' : 'rowid'); if ($user->socid) { $socid = $user->socid; } $result = restrictedArea($user, 'cheque', $id, 'bordereau_cheque', '', 'fk_user_author', $fieldname); $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (!$sortorder) { $sortorder = "ASC"; } if (!$sortfield) { $sortfield = "b.dateo,b.rowid"; } if (empty($page) || $page == -1) { $page = 0; } $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $offset = $limit * $page; $dir = $conf->bank->dir_output.'/checkdeposits/'; $filterdate = dol_mktime(0, 0, 0, GETPOST('fdmonth'), GETPOST('fdday'), GETPOST('fdyear')); $filteraccountid = GETPOST('accountid', 'int'); $object = new RemiseCheque($db); /* * Actions */ if ($action == 'setdate' && $user->rights->banque->cheque) { $result = $object->fetch(GETPOST('id', 'int')); if ($result > 0) { $date = dol_mktime(0, 0, 0, GETPOST('datecreate_month', 'int'), GETPOST('datecreate_day', 'int'), GETPOST('datecreate_year', 'int')); $result = $object->set_date($user, $date); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } else { setEventMessages($object->error, $object->errors, 'errors'); } } if ($action == 'setrefext' && $user->rights->banque->cheque) { $result = $object->fetch(GETPOST('id', 'int')); if ($result > 0) { $ref_ext = GETPOST('ref_ext'); $result = $object->setValueFrom('ref_ext', $ref_ext, '', null, 'text', '', $user, 'CHECKDEPOSIT_MODIFY'); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } else { setEventMessages($object->error, $object->errors, 'errors'); } } if ($action == 'setref' && $user->rights->banque->cheque) { $result = $object->fetch(GETPOST('id', 'int')); if ($result > 0) { $ref = GETPOST('ref'); $result = $object->set_number($user, $ref); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } else { setEventMessages($object->error, $object->errors, 'errors'); } } if ($action == 'create' && GETPOST("accountid", "int") > 0 && $user->rights->banque->cheque) { if (is_array(GETPOST('toRemise'))) { $result = $object->create($user, GETPOST("accountid", "int"), 0, GETPOST('toRemise')); if ($result > 0) { if ($object->statut == 1) { // If statut is validated, we build doc $object->fetch($object->id); // To force to reload all properties in correct property name // Define output language $outputlangs = $langs; $newlang = ''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) { $newlang = GETPOST('lang_id', 'aZ09'); } //if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } $result = $object->generatePdf(GETPOST("model"), $outputlangs); } header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } } else { setEventMessages($langs->trans("ErrorSelectAtLeastOne"), null, 'mesgs'); $action = 'new'; } } if ($action == 'remove' && $id > 0 && GETPOST("lineid", 'int') > 0 && $user->rights->banque->cheque) { $object->id = $id; $result = $object->removeCheck(GETPOST("lineid", "int")); if ($result === 0) { header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } } if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->banque->cheque) { $object->id = $id; $result = $object->delete(); if ($result == 0) { header("Location: index.php"); exit; } else { setEventMessages($paiement->error, $paiement->errors, 'errors'); } } if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->banque->cheque) { $result = $object->fetch($id); $result = $object->validate($user); if ($result >= 0) { // Define output language $outputlangs = $langs; $newlang = ''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) { $newlang = GETPOST('lang_id', 'aZ09'); } //if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } $result = $object->generatePdf(GETPOST('model'), $outputlangs); header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } } if ($action == 'confirm_reject_check' && $confirm == 'yes' && $user->rights->banque->cheque) { $reject_date = dol_mktime(0, 0, 0, GETPOST('rejectdate_month'), GETPOST('rejectdate_day'), GETPOST('rejectdate_year')); $rejected_check = GETPOST('bankid', 'int'); $object->fetch($id); $paiement_id = $object->rejectCheck($rejected_check, $reject_date); if ($paiement_id > 0) { setEventMessages($langs->trans("CheckRejectedAndInvoicesReopened"), null, 'mesgs'); //header("Location: ".DOL_URL_ROOT.'/compta/paiement/card.php?id='.$paiement_id); //exit; $action = ''; } else { setEventMessages($object->error, $object->errors, 'errors'); $action = ''; } } if ($action == 'builddoc' && $user->rights->banque->cheque) { $result = $object->fetch($id); // Save last template used to generate document //if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); $outputlangs = $langs; $newlang = ''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) { $newlang = GETPOST('lang_id', 'aZ09'); } //if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } $result = $object->generatePdf(GETPOST("model"), $outputlangs); if ($result <= 0) { dol_print_error($db, $object->error); exit; } else { header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG) ? '' : '#builddoc')); exit; } } elseif ($action == 'remove_file' && $user->rights->banque->cheque) { // Remove file in doc form if ($object->fetch($id) > 0) { include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $langs->load("other"); $file = $dir.get_exdir($object->ref, 0, 1, 0, $object, 'cheque').GETPOST('file'); $ret = dol_delete_file($file, 0, 0, 0, $object); if ($ret) { setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs'); } else { setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors'); } } } /* * View */ if (GETPOST('removefilter')) { $filterdate = ''; $filteraccountid = 0; } $title = $langs->trans("Cheques")." - ".$langs->trans("Card"); $helpurl = ""; llxHeader("", $title, $helpurl); $form = new Form($db); $formfile = new FormFile($db); if ($action == 'new') { $head = array(); $h = 0; $head[$h][0] = $_SERVER["PHP_SELF"].'?action=new'; $head[$h][1] = $langs->trans("MenuChequeDeposits"); $hselected = $h; $h++; print load_fiche_titre($langs->trans("Cheques"), '', 'bank_account'); } else { $result = $object->fetch($id, $ref); if ($result < 0) { dol_print_error($db, $object->error); exit; } $h = 0; $head[$h][0] = $_SERVER["PHP_SELF"].'?id='.$object->id; $head[$h][1] = $langs->trans("CheckReceipt"); $hselected = $h; $h++; // $head[$h][0] = DOL_URL_ROOT.'/compta/paiement/cheque/info.php?id='.$object->id; // $head[$h][1] = $langs->trans("Info"); // $h++; print dol_get_fiche_head($head, $hselected, $langs->trans("Cheques"), -1, 'payment'); /* * Confirmation of slip's delete */ if ($action == 'delete') { print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("DeleteCheckReceipt"), $langs->trans("ConfirmDeleteCheckReceipt"), 'confirm_delete', '', '', 1); } /* * Confirmation of slip's validation */ if ($action == 'valide') { print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("ValidateCheckReceipt"), $langs->trans("ConfirmValidateCheckReceipt"), 'confirm_validate', '', '', 1); } /* * Confirm check rejection */ if ($action == 'reject_check') { $formquestion = array( array('type' => 'hidden', 'name' => 'bankid', 'value' => GETPOST('lineid', 'int')), array('type' => 'date', 'name' => 'rejectdate_', 'label' => $langs->trans("RejectCheckDate"), 'value' => dol_now()) ); print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("RejectCheck"), $langs->trans("ConfirmRejectCheck"), 'confirm_reject_check', $formquestion, '', 1); } } $accounts = array(); if ($action == 'new') { $paymentstatic = new Paiement($db); $accountlinestatic = new AccountLine($db); $lines = array(); $now = dol_now(); print ''.$langs->trans("SelectChequeTransactionAndGenerate").'

'."\n"; print '
'; print ''; print ''; print dol_get_fiche_head(); print ''; //print ''; // Filter print ''; print ''; print '
'.$langs->trans('Date').''.dol_print_date($now,'day').'
'.$langs->trans("DateChequeReceived").''; print $form->selectDate($filterdate, 'fd', 0, 0, 1, '', 1, 1); print '
'.$langs->trans("BankAccount").''; $form->select_comptes($filteraccountid, 'accountid', 0, 'courant <> 2', 1); print '
'; print dol_get_fiche_end(); print '
'; print ''; if ($filterdate || $filteraccountid > 0) { print '   '; print ''; } print '
'; print '
'; print '
'; $sql = "SELECT ba.rowid as bid, ba.label,"; $sql .= " b.rowid as transactionid, b.label as transactionlabel, b.datec as datec, b.dateo as date, "; $sql .= " b.amount, b.emetteur, b.num_chq, b.banque,"; $sql .= " p.rowid as paymentid, p.ref as paymentref"; $sql .= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement as p ON p.fk_bank = b.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON (b.fk_account = ba.rowid)"; $sql .= " WHERE b.fk_type = 'CHQ'"; $sql .= " AND ba.entity IN (".getEntity('bank_account').")"; $sql .= " AND b.fk_bordereau = 0"; $sql .= " AND b.amount > 0"; if ($filterdate) { $sql .= " AND b.dateo = '".$db->idate($filterdate)."'"; } if ($filteraccountid > 0) { $sql .= " AND ba.rowid = ".((int) $filteraccountid); } $sql .= $db->order("b.dateo,b.rowid", "ASC"); $resql = $db->query($sql); if ($resql) { $i = 0; while ($obj = $db->fetch_object($resql)) { $accounts[$obj->bid] = $obj->label; $lines[$obj->bid][$i]["date"] = $db->jdate($obj->datec); $lines[$obj->bid][$i]["amount"] = $obj->amount; $lines[$obj->bid][$i]["emetteur"] = $obj->emetteur; $lines[$obj->bid][$i]["numero"] = $obj->num_chq; $lines[$obj->bid][$i]["banque"] = $obj->banque; $lines[$obj->bid][$i]["id"] = $obj->transactionid; $lines[$obj->bid][$i]["ref"] = $obj->transactionid; $lines[$obj->bid][$i]["label"] = $obj->transactionlabel; $lines[$obj->bid][$i]["paymentid"] = $obj->paymentid; $lines[$obj->bid][$i]["paymentref"] = $obj->paymentref; $lines[$obj->bid][$i]["paymentdate"] = $db->jdate($obj->date); $i++; } if ($i == 0) { print '
'.$langs->trans("NoWaitingChecks").'

'; } } foreach ($accounts as $bid => $account_label) { print ' '; $num = $db->num_rows($resql); print '
'; print ''; print ''; print ''; $moreforfilter = ''; print '
'; print ''."\n"; print ''; print ''."\n"; print '\n"; print '\n"; print '\n"; print '\n"; print '\n"; print '\n"; print ''; print "\n"; if (count($lines[$bid])) { foreach ($lines[$bid] as $lid => $value) { //$account_id = $bid; FIXME not used // FIXME $accounts[$bid] is a label ! /*if (! isset($accounts[$bid])) $accounts[$bid]=0; $accounts[$bid] += 1;*/ print ''; print ''; print '\n"; print '\n"; print '\n"; print ''; // Link to payment print ''; // Link to bank transaction print ''; print ''; print ''; $i++; } } print "
'.$langs->trans("DateChequeReceived").''.$langs->trans("ChequeNumber")."'.$langs->trans("CheckTransmitter")."'.$langs->trans("Bank")."'.$langs->trans("Amount")."'.$langs->trans("Payment")."'.$langs->trans("LineRecord")."'.$langs->trans("Select")."
"; if ($conf->use_javascript_ajax) { print ''.$langs->trans("All").' / '.$langs->trans("None").''; } print '
'.dol_print_date($value["date"], 'day').''.$value["numero"]."'.$value["emetteur"]."'.$value["banque"]."'.price($value["amount"], 0, $langs, 1, -1, -1, $conf->currency).''; $paymentstatic->id = $value["paymentid"]; $paymentstatic->ref = $value["paymentref"]; $paymentstatic->date = $value["paymentdate"]; if ($paymentstatic->id) { print $paymentstatic->getNomUrl(1); } else { print ' '; } print ''; $accountlinestatic->id = $value["id"]; $accountlinestatic->ref = $value["ref"]; if ($accountlinestatic->id > 0) { print $accountlinestatic->getNomUrl(1); } else { print ' '; } print ''; print ''; print '
"; print '
'; print '
'; if ($user->rights->banque->cheque) { print ''; } else { print ''.$langs->trans('NewCheckDepositOn', $account_label).''; } print '

'; print '
'; } } else { $paymentstatic = new Paiement($db); $accountlinestatic = new AccountLine($db); $accountstatic = new Account($db); $accountstatic->fetch($object->account_id); $linkback = ''.$langs->trans("BackToList").''; $morehtmlref = ''; dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); print '
'; print '
'; print ''; print ''; print ''; // External ref /* Ext ref are not visible field on standard usage print ''; print ''; */ print ''; // Number of bank checks print ''; print ''; /*print '';*/ print '
'; print ''; if ($action != 'editdate') { print ''; } print '
'; print $langs->trans('Date'); print 'id.'">'.img_edit($langs->trans('SetDate'), 1).'
'; print '
'; if ($action == 'editdate') { print '
'; print ''; print ''; print $form->selectDate($object->date_bordereau, 'datecreate_', '', '', '', "setdate"); print ''; print '
'; } else { print $object->date_bordereau ? dol_print_date($object->date_bordereau, 'day') : ' '; } print '
'; print ''; if ($action != 'editrefext') print ''; print '
'; print $langs->trans('RefExt'); print 'id.'">'.img_edit($langs->trans('SetRefExt'),1).'
'; print '
'; if ($action == 'editrefext') { print '
'; print ''; print ''; print ''; print ''; print '
'; } else { print $object->ref_ext; } print '
'.$langs->trans('Account').''; print $accountstatic->getNomUrl(1); print '
'.$langs->trans('NbOfCheques').''; print $object->nbcheque; print '
'.$langs->trans('Total').''; print price($object->amount); print '
'.$langs->trans('Status').''; print $object->getLibStatut(4); print '

'; print '
'; // List of bank checks $sql = "SELECT b.rowid, b.rowid as ref, b.label, b.amount, b.num_chq, b.emetteur,"; $sql .= " b.dateo as date, b.datec as datec, b.banque,"; $sql .= " p.rowid as pid, p.ref as pref, ba.rowid as bid, p.statut"; $sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON (b.fk_account = ba.rowid)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement as p ON p.fk_bank = b.rowid"; $sql .= " WHERE ba.entity IN (".getEntity('bank_account').")"; $sql .= " AND b.fk_type= 'CHQ'"; $sql .= " AND b.fk_bordereau = ".((int) $object->id); $sql .= $db->order($sortfield, $sortorder); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); print '
'; print ''; $param = "&id=".$object->id; print ''; print_liste_field_titre("Cheques", '', '', '', '', 'width="30"'); print_liste_field_titre("DateChequeReceived", $_SERVER["PHP_SELF"], "b.dateo,b.rowid", "", $param, 'align="center"', $sortfield, $sortorder); print_liste_field_titre("Numero", $_SERVER["PHP_SELF"], "b.num_chq", "", $param, 'align="center"', $sortfield, $sortorder); print_liste_field_titre("CheckTransmitter", $_SERVER["PHP_SELF"], "b.emetteur", "", $param, "", $sortfield, $sortorder); print_liste_field_titre("Bank", $_SERVER["PHP_SELF"], "b.banque", "", $param, "", $sortfield, $sortorder); print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "b.amount", "", $param, 'class="right"', $sortfield, $sortorder); print_liste_field_titre("Payment", $_SERVER["PHP_SELF"], "p.rowid", "", $param, 'align="center"', $sortfield, $sortorder); print_liste_field_titre("LineRecord", $_SERVER["PHP_SELF"], "b.rowid", "", $param, 'align="center"', $sortfield, $sortorder); print_liste_field_titre(''); print "\n"; $i = 1; if ($num > 0) { while ($objp = $db->fetch_object($resql)) { print ''; print ''; print ''; // Operation date print ''; print ''; print ''; print ''; // Link to payment print ''; // Link to bank transaction print ''; // Action button print ''; print ''; $i++; } } else { print ''; } print "
'.$i.''.dol_print_date($db->jdate($objp->date), 'day').''.($objp->num_chq ? $objp->num_chq : ' ').''.dol_trunc($objp->emetteur, 24).''.dol_trunc($objp->banque, 24).''.price($objp->amount).''; $paymentstatic->id = $objp->pid; $paymentstatic->ref = $objp->pref; if ($paymentstatic->id) { print $paymentstatic->getNomUrl(1); } else { print ' '; } print ''; $accountlinestatic->id = $objp->rowid; $accountlinestatic->ref = $objp->ref; if ($accountlinestatic->id > 0) { print $accountlinestatic->getNomUrl(1); } else { print ' '; } print ''; if ($object->statut == 0) { print 'rowid.'">'.img_delete().''; } if ($object->statut == 1 && $objp->statut != 2) { print 'rowid.'">'.img_picto($langs->trans("RejectCheck"), 'disable').''; } if ($objp->statut == 2) { print '   '.img_picto($langs->trans('CheckRejected'), 'statut8').''; } print '
'; print $langs->trans("None"); print '
"; // Cheque denormalized data nbcheque is similar to real number of bank check if ($num > 0 && $i < ($object->nbcheque + 1)) { // Show warning that some records were removed. $langs->load("errors"); print info_admin($langs->trans("WarningSomeBankTransactionByChequeWereRemovedAfter"), 0, 0, 'warning'); // TODO Fix data ->nbcheque and ->amount } print "
"; } else { dol_print_error($db); } print dol_get_fiche_end(); } /* * Actions Buttons */ print '
'; if ($user->socid == 0 && !empty($object->id) && $object->statut == 0 && $user->rights->banque->cheque) { print ''.$langs->trans('Validate').''; } if ($user->socid == 0 && !empty($object->id) && $user->rights->banque->cheque) { print ''.$langs->trans('Delete').''; } print '
'; if ($action != 'new') { if ($object->statut == 1) { $filename = dol_sanitizeFileName($object->ref); $filedir = $dir.get_exdir($object->ref, 0, 1, 0, $object, 'checkdeposits'); $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; print $formfile->showdocuments('remisecheque', $filename, $filedir, $urlsource, 1, 1); print '
'; } } // End of page llxFooter(); $db->close();