123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524 |
- <?php
- /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
- * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
- * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.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
- * 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 <https://www.gnu.org/licenses/>.
- */
- /**
- * \file htdocs/compta/prelevement/card.php
- * \ingroup prelevement
- * \brief Card of a direct debit
- */
- // Load Dolibarr environment
- require '../../main.inc.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
- require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.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', 'withdrawals'));
- // Get supervariables
- $action = GETPOST('action', 'aZ09');
- $id = GETPOST('id', 'int');
- $ref = GETPOST('ref', 'alpha');
- $socid = GETPOST('socid', 'int');
- $type = GETPOST('type', 'aZ09');
- // Load variable for pagination
- $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
- $sortfield = GETPOST('sortfield', 'aZ09comma');
- $sortorder = GETPOST('sortorder', 'aZ09comma');
- $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
- if (empty($page) || $page == -1) {
- $page = 0;
- } // If $page is not defined, or '' or -1
- $offset = $limit * $page;
- $pageprev = $page - 1;
- $pagenext = $page + 1;
- if (!$sortfield) {
- $sortfield = 'pl.rowid';
- }
- if (!$sortorder) {
- $sortorder = 'ASC';
- }
- $object = new BonPrelevement($db);
- // Load object
- include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
- $hookmanager->initHooks(array('directdebitprevcard', 'globalcard', 'directdebitprevlist'));
- $type = $object->type;
- if ($type == 'bank-transfer') {
- $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
- $permissiontoadd = $user->hasRight('paymentbybanktransfer', 'read');
- $permissiontosend = $user->hasRight('paymentbybanktransfer', 'send');
- $permissiontocreditdebit = $user->hasRight('paymentbybanktransfer', 'debit');
- $permissiontodelete = $user->hasRight('paymentbybanktransfer', 'read');
- } else {
- $result = restrictedArea($user, 'prelevement', '', '', 'bons');
- $permissiontoadd = $user->hasRight('prelevement', 'bons', 'read');
- $permissiontosend = $user->hasRight('prelevement', 'bons', 'send');
- $permissiontocreditdebit = $user->hasRight('prelevement', 'bons', 'credit');
- $permissiontodelete = $user->hasRight('prelevement', 'bons', 'read');
- }
- /*
- * Actions
- */
- $parameters = array('socid' => $socid);
- $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
- if ($reshook < 0) {
- setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
- }
- if (empty($reshook)) {
- if ($action == 'setbankaccount' && $permissiontoadd) {
- $object->oldcopy = dol_clone($object);
- $object->fk_bank_account = GETPOST('fk_bank_account', 'int');
- $object->update($user);
- }
- if ($action == 'infotrans' && $permissiontosend) {
- require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
- $dt = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
- /*
- if ($_FILES['userfile']['name'] && basename($_FILES['userfile']['name'],".ps") == $object->ref)
- {
- $dir = $conf->prelevement->dir_output.'/receipts';
- if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $dir . "/" . dol_unescapefile($_FILES['userfile']['name']),1) > 0)
- {
- $object->set_infotrans($user, $dt, GETPOST('methode','alpha'));
- }
- header("Location: card.php?id=".$id);
- exit;
- }
- else
- {
- dol_syslog("Fichier invalide",LOG_WARNING);
- $mesg='BadFile';
- }*/
- $error = $object->set_infotrans($user, $dt, GETPOST('methode', 'alpha'));
- if ($error) {
- header("Location: card.php?id=".$id."&error=$error");
- exit;
- }
- }
- // Set direct debit order to credited, create payment and close invoices
- if ($action == 'infocredit' && $permissiontocreditdebit) {
- $dt = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
- if (($object->type != 'bank-transfer' && $object->statut == BonPrelevement::STATUS_CREDITED) || ($object->type == 'bank-transfer' && $object->statut == BonPrelevement::STATUS_DEBITED)) {
- $error = 1;
- setEventMessages('WithdrawalCantBeCreditedTwice', array(), 'errors');
- } else {
- $error = $object->set_infocredit($user, $dt);
- }
- if ($error) {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- }
- if ($action == 'confirm_delete' && $permissiontodelete) {
- $savtype = $object->type;
- $res = $object->delete($user);
- if ($res > 0) {
- if ($savtype == 'bank-transfer') {
- header("Location: ".DOL_URL_ROOT.'/compta/paymentbybanktransfer/index.php');
- } else {
- header("Location: ".DOL_URL_ROOT.'/compta/prelevement/index.php');
- }
- exit;
- }
- }
- }
- /*
- * View
- */
- $form = new Form($db);
- llxHeader('', $langs->trans("WithdrawalsReceipts"));
- if ($id > 0 || $ref) {
- $head = prelevement_prepare_head($object);
- print dol_get_fiche_head($head, 'prelevement', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
- if (GETPOST('error', 'alpha') != '') {
- print '<div class="error">'.$object->getErrorString(GETPOST('error', 'alpha')).'</div>';
- }
- $linkback = '<a href="'.DOL_URL_ROOT.'/compta/prelevement/orders_list.php?restore_lastsearch_values=1'.($object->type != 'bank-transfer' ? '' : '&type=bank-transfer').'">'.$langs->trans("BackToList").'</a>';
- dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
- print '<div class="fichecenter">';
- print '<div class="underbanner clearboth"></div>';
- print '<table class="border centpercent tableforfield">';
- print '<tr><td class="titlefieldcreate">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
- print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($object->amount).'</span></td></tr>';
- if (!empty($object->date_trans)) {
- $muser = new User($db);
- $muser->fetch($object->user_trans);
- print '<tr><td>'.$langs->trans("TransData").'</td><td>';
- print dol_print_date($object->date_trans, 'day');
- print ' <span class="opacitymedium">'.$langs->trans("By").'</span> '.$muser->getNomUrl(-1).'</td></tr>';
- print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
- print $object->methodes_trans[$object->method_trans];
- print '</td></tr>';
- }
- if (!empty($object->date_credit)) {
- print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
- print dol_print_date($object->date_credit, 'day');
- print '</td></tr>';
- }
- print '</table>';
- print '<br>';
- print '<div class="underbanner clearboth"></div>';
- print '<table class="border centpercent tableforfield">';
- // Get bank account for the payment
- $acc = new Account($db);
- $fk_bank_account = $object->fk_bank_account;
- if (empty($fk_bank_account)) {
- $fk_bank_account = ($object->type == 'bank-transfer' ? getDolGlobalInt('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') : getDolGlobalInt('PRELEVEMENT_ID_BANKACCOUNT'));
- }
- if ($fk_bank_account > 0) {
- $result = $acc->fetch($fk_bank_account);
- }
- // Bank account
- $labelofbankfield = "BankToReceiveWithdraw";
- if ($object->type == 'bank-transfer') {
- $labelofbankfield = 'BankToPayCreditTransfer';
- }
- //print $langs->trans($labelofbankfield);
- $caneditbank = $permissiontoadd;
- if ($object->status != $object::STATUS_DRAFT) {
- $caneditbank = 0;
- }
- /*
- print '<tr><td class="titlefieldcreate">';
- print $form->editfieldkey($langs->trans($labelofbankfield), 'fk_bank_account', $acc->id, $object, $caneditbank);
- print '</td>';
- print '<td>';
- print $form->editfieldval($langs->trans($labelofbankfield), 'fk_bank_account', $acc->id, $acc, $caneditbank, 'string', '', null, null, '', 1, 'getNomUrl');
- print '</td>';
- print '</tr>';
- */
- print '<tr><td class="titlefieldcreate">';
- print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
- print $form->textwithpicto($langs->trans("BankAccount"), $langs->trans($labelofbankfield));
- print '<td>';
- if (($action != 'editbankaccount') && $caneditbank) {
- print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editfkbankaccount&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
- }
- print '</tr></table>';
- print '</td><td>';
- if ($action == 'editfkbankaccount') {
- $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $fk_bank_account, 'fk_bank_account', 0);
- } else {
- $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $fk_bank_account, 'none');
- }
- print "</td>";
- print '</tr>';
- // Donwload file
- print '<tr><td class="titlefieldcreate">';
- $labelfororderfield = 'WithdrawalFile';
- if ($object->type == 'bank-transfer') {
- $labelfororderfield = 'CreditTransferFile';
- }
- print $langs->trans($labelfororderfield).'</td><td>';
- $relativepath = 'receipts/'.$object->ref.'.xml';
- $modulepart = 'prelevement';
- if ($object->type == 'bank-transfer') {
- $modulepart = 'paymentbybanktransfer';
- }
- print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&modulepart='.$modulepart.'&file='.urlencode($relativepath).'">'.$relativepath;
- print img_picto('', 'download', 'class="paddingleft"');
- print '</a>';
- print '</td></tr>';
- // Other attributes
- $parameters = array();
- $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
- print $hookmanager->resPrint;
- print '</table>';
- print '</div>';
- print dol_get_fiche_end();
- $formconfirm = '';
- // Confirmation to delete
- if ($action == 'delete') {
- $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Delete'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
- }
- // Call Hook formConfirm
- /*$parameters = array('formConfirm' => $formconfirm);
- $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
- if (empty($reshook)) $formconfirm.=$hookmanager->resPrint;
- elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint;*/
- // Print form confirm
- print $formconfirm;
- if (empty($object->date_trans) && (($user->rights->prelevement->bons->send && $object->type != 'bank-transfer') || ($user->rights->paymentbybanktransfer->send && $object->type == 'bank-transfer')) && $action == 'settransmitted') {
- print '<form method="post" name="userfile" action="card.php?id='.$object->id.'" enctype="multipart/form-data">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="infotrans">';
- print '<table class="noborder centpercent">';
- print '<tr class="liste_titre">';
- print '<td colspan="3">'.$langs->trans("NotifyTransmision").'</td></tr>';
- print '<tr class="oddeven"><td>'.$langs->trans("TransData").'</td><td>';
- print $form->selectDate('', '', '', '', '', "userfile", 1, 1);
- print '</td></tr>';
- print '<tr class="oddeven"><td>'.$langs->trans("TransMetod").'</td><td>';
- print $form->selectarray("methode", $object->methodes_trans);
- print '</td></tr>';
- print '</table>';
- print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("SetToStatusSent")).'"></div>';
- print '</form>';
- print '<br>';
- }
- if (!empty($object->date_trans) && empty($object->date_credit) && (($user->rights->prelevement->bons->credit && $object->type != 'bank-transfer') || ($user->rights->paymentbybanktransfer->debit && $object->type == 'bank-transfer')) && $action == 'setcredited') {
- $btnLabel = ($object->type == 'bank-transfer') ? $langs->trans("ClassDebited") : $langs->trans("ClassCredited");
- print '<form name="infocredit" method="post" action="card.php?id='.$object->id.'">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="infocredit">';
- print '<table class="noborder centpercent">';
- print '<tr class="liste_titre">';
- print '<td colspan="3">'.$langs->trans("NotifyCredit").'</td></tr>';
- print '<tr class="oddeven"><td>'.$langs->trans('CreditDate').'</td><td>';
- print $form->selectDate(-1, '', '', '', '', "infocredit", 1, 1);
- print '</td></tr>';
- print '</table>';
- print '<br><div class="center"><span class="opacitymedium">'.$langs->trans("ThisWillAlsoAddPaymentOnInvoice").'</span></div>';
- print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($btnLabel).'"></div>';
- print '</form>';
- print '<br>';
- }
- // Actions
- if ($action != 'settransmitted' && $action != 'setcredited') {
- print "\n".'<div class="tabsAction">'."\n";
- $parameters = array();
- $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
- if (empty($reshook)) {
- if (empty($object->date_trans)) {
- if ($object->type == 'bank-transfer') print dolGetButtonAction($langs->trans("SetToStatusSent"), '', 'default', 'card.php?action=settransmitted&token='.newToken().'&id='.$object->id, '', $user->rights->paymentbybanktransfer->send);
- else print dolGetButtonAction($langs->trans("SetToStatusSent"), '', 'default', 'card.php?action=settransmitted&token='.newToken().'&id='.$object->id, '', $user->rights->prelevement->bons->send);
- }
- if (!empty($object->date_trans) && empty($object->date_credit)) {
- if ($object->type == 'bank-transfer') print dolGetButtonAction($langs->trans("ClassDebited"), '', 'default', 'card.php?action=setcredited&token='.newToken().'&id='.$object->id, '', $user->rights->paymentbybanktransfer->debit);
- else print dolGetButtonAction($langs->trans("ClassCredited"), '', 'default', 'card.php?action=setcredited&token='.newToken().'&id='.$object->id, '', $user->rights->prelevement->bons->credit);
- }
- if ($object->type == 'bank-transfer') print dolGetButtonAction($langs->trans("Delete"), '', 'delete', 'card.php?action=delete&token='.newToken().'&id='.$object->id, '', $user->rights->paymentbybanktransfer->create);
- else print dolGetButtonAction($langs->trans("Delete"), '', 'delete', 'card.php?action=delete&token='.newToken().'&id='.$object->id, '', $user->rights->prelevement->bons->creer);
- }
- print '</div>';
- }
- $ligne = new LignePrelevement($db);
- /*
- * Lines into withdraw request
- */
- $sql = "SELECT pl.rowid, pl.statut, pl.amount,";
- $sql .= " s.rowid as socid, s.nom as name";
- $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
- $sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
- $sql .= ", ".MAIN_DB_PREFIX."societe as s";
- $sql .= " WHERE pl.fk_prelevement_bons = ".((int) $id);
- $sql .= " AND pl.fk_prelevement_bons = pb.rowid";
- $sql .= " AND pb.entity = ".((int) $conf->entity); // No sharing of entity here
- $sql .= " AND pl.fk_soc = s.rowid";
- if ($socid) {
- $sql .= " AND s.rowid = ".((int) $socid);
- }
- $sql .= $db->order($sortfield, $sortorder);
- // Count total nb of records
- $nbtotalofrecords = '';
- if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
- $result = $db->query($sql);
- $nbtotalofrecords = $db->num_rows($result);
- if (($page * $limit) > $nbtotalofrecords) {
- // if total resultset is smaller then paging size (filtering), goto and load page 0
- $page = 0;
- $offset = 0;
- }
- }
- $sql .= $db->plimit($limit + 1, $offset);
- $result = $db->query($sql);
- if ($result) {
- $num = $db->num_rows($result);
- $i = 0;
- $urladd = "&id=".urlencode($id);
- if ($limit > 0 && $limit != $conf->liste_limit) {
- $urladd .= '&limit='.((int) $limit);
- }
- print '<form method="POST" action="'.$_SERVER ['PHP_SELF'].'" name="search_form">'."\n";
- print '<input type="hidden" name="token" value="'.newToken().'"/>';
- print '<input type="hidden" name="id" value="'.$id.'"/>';
- print '<input type="hidden" name="socid" value="'.$socid.'"/>';
- if (!empty($page)) {
- print '<input type="hidden" name="page" value="'.$page.'"/>';
- }
- if (!empty($limit)) {
- print '<input type="hidden" name="limit" value="'.$limit.'"/>';
- }
- if (!empty($sortfield)) {
- print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
- }
- if (!empty($sortorder)) {
- print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
- }
- print_barre_liste($langs->trans("Lines"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit);
- print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
- print '<table class="noborder liste" width="100%" cellpadding="4">';
- print '<tr class="liste_titre">';
- print_liste_field_titre("Lines", $_SERVER["PHP_SELF"], "pl.rowid", '', $urladd, '', $sortfield, $sortorder);
- print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "s.nom", '', $urladd, '', $sortfield, $sortorder);
- print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "pl.amount", "", $urladd, 'class="right"', $sortfield, $sortorder);
- print_liste_field_titre('');
- print "</tr>\n";
- $total = 0;
- while ($i < min($num, $limit)) {
- $obj = $db->fetch_object($result);
- print '<tr class="oddeven">';
- // Status of line
- print "<td>";
- print '<a class="valignmiddle" href="'.DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$obj->rowid.'&type='.$object->type.'&token='.newToken().'">';
- print $ligne->LibStatut($obj->statut, 2);
- print '<span class="paddingleft">'.$obj->rowid.'</span>';
- print '</a></td>';
- $thirdparty = new Societe($db);
- $thirdparty->fetch($obj->socid);
- print '<td>';
- print $thirdparty->getNomUrl(1);
- print "</td>\n";
- print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
- print '<td class="right">';
- if ($obj->statut == 3) {
- print '<b>'.$langs->trans("StatusRefused").'</b>';
- } else {
- if ($object->statut == BonPrelevement::STATUS_CREDITED) {
- if ($obj->statut == 2) {
- if ($user->rights->prelevement->bons->credit) {
- //print '<a class="butActionDelete" href="line.php?action=rejet&id='.$obj->rowid.'">'.$langs->trans("StandingOrderReject").'</a>';
- print '<a href="line.php?action=rejet&type='.$object->type.'&id='.$obj->rowid.'&token='.newToken().'">'.$langs->trans("StandingOrderReject").'</a>';
- } else {
- //print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("StandingOrderReject").'</a>';
- }
- }
- } else {
- //print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotPossibleForThisStatusOfWithdrawReceiptORLine").'">'.$langs->trans("StandingOrderReject").'</a>';
- }
- }
- print '</td></tr>';
- $total += $obj->amount;
- $i++;
- }
- if ($num > 0) {
- $total = price2num($total, 'MT');
- print '<tr class="liste_total">';
- print '<td>'.$langs->trans("Total").'</td>';
- print '<td> </td>';
- print '<td class="right">';
- if (empty($offset) && $num <= $limit) {
- // If we have all record on same page, then the following test/warning can be done
- if ($total != $object->amount) {
- print img_warning($langs->trans("TotalAmountOfdirectDebitOrderDiffersFromSumOfLines"));
- }
- }
- print price($total);
- print "</td>\n";
- print '<td> </td>';
- print "</tr>\n";
- }
- print "</table>";
- print '</div>';
- print '</form>';
- $db->free($result);
- } else {
- dol_print_error($db);
- }
- }
- // End of page
- llxFooter();
- $db->close();
|