* Copyright (C) 2005-2010 Laurent Destailleur * Copyright (C) 2010-2016 Juanjo Menent * 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/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', '', '', ''); } else { $result = restrictedArea($user, 'prelevement', '', '', 'bons'); } /* * 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 == 'confirm_delete') { $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; } } if ($action == 'infotrans' && (($user->rights->prelevement->bons->send && $object->type != 'bank-transfer') || ($user->rights->paymentbybanktransfer->send && $object->type == 'bank-transfer'))) { 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' && (($user->rights->prelevement->bons->credit && $object->type != 'bank-transfer') || ($user->rights->paymentbybanktransfer->debit && $object->type == 'bank-transfer'))) { $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'); } } } /* * 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 '
'.$object->getErrorString(GETPOST('error', 'alpha')).'
'; } $linkback = ''.$langs->trans("BackToList").''; dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref'); print '
'; print '
'; print ''; print ''; print ''; // Status /* print ''; print ''; print ''; */ if (!empty($object->date_trans)) { $muser = new User($db); $muser->fetch($object->user_trans); print ''; print ''; } if (!empty($object->date_credit)) { print ''; } print '
'.$langs->trans("Date").''.dol_print_date($object->datec, 'day').'
'.$langs->trans("Amount").''.price($object->amount).'
'.$langs->trans('Status').''.$object->getLibStatut(1).'
'.$langs->trans("TransData").''; print dol_print_date($object->date_trans, 'day'); print '   '.$langs->trans("By").' '.$muser->getNomUrl(-1).'
'.$langs->trans("TransMetod").''; print $object->methodes_trans[$object->method_trans]; print '
'.$langs->trans('CreditDate').''; print dol_print_date($object->date_credit, 'day'); print '
'; print '
'; print '
'; print ''; $acc = new Account($db); $result = $acc->fetch(($object->type == 'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT)); print ''; print ''; print ''; print ''; // 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 '
'; $labelofbankfield = "BankToReceiveWithdraw"; if ($object->type == 'bank-transfer') { $labelofbankfield = 'BankToPayCreditTransfer'; } print $langs->trans($labelofbankfield); print ''; if ($acc->id > 0) { print $acc->getNomUrl(1); } print '
'; $labelfororderfield = 'WithdrawalFile'; if ($object->type == 'bank-transfer') { $labelfororderfield = 'CreditTransferFile'; } print $langs->trans($labelfororderfield).''; $relativepath = 'receipts/'.$object->ref.'.xml'; $modulepart = 'prelevement'; if ($object->type == 'bank-transfer') { $modulepart = 'paymentbybanktransfer'; } print ''.$relativepath; print img_picto('', 'download', 'class="paddingleft"'); print ''; print '
'; print '
'; 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 '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("NotifyTransmision").'
'.$langs->trans("TransData").''; print $form->selectDate('', '', '', '', '', "userfile", 1, 1); print '
'.$langs->trans("TransMetod").''; print $form->selectarray("methode", $object->methodes_trans); print '
'; print '
'; print '
'; print '
'; } 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 '
'; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("NotifyCredit").'
'.$langs->trans('CreditDate').''; print $form->selectDate(-1, '', '', '', '', "infocredit", 1, 1); print '
'; print '
'.$langs->trans("ThisWillAlsoAddPaymentOnInvoice").'
'; print '
'; print '
'; print '
'; } // Actions if ($action != 'settransmitted' && $action != 'setcredited') { print "\n".'
'."\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 '
'; } $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 (empty($conf->global->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='.urlencode($limit); } print '
'."\n"; print ''; print ''; print ''; if (!empty($page)) { print ''; } if (!empty($limit)) { print ''; } if (!empty($sortfield)) { print ''; } if (!empty($sortorder)) { print ''; } print_barre_liste($langs->trans("Lines"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit); print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print ''; print ''; 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 "\n"; $total = 0; while ($i < min($num, $limit)) { $obj = $db->fetch_object($result); print ''; // Status of line print "'; $thirdparty = new Societe($db); $thirdparty->fetch($obj->socid); print '\n"; print '\n"; print ''; $total += $obj->amount; $i++; } if ($num > 0) { $total = price2num($total, 'MT'); print ''; print ''; print ''; print '\n"; print ''; print "\n"; } print "
"; print ''; print $ligne->LibStatut($obj->statut, 2); print ''.$obj->rowid.''; print ''; print $thirdparty->getNomUrl(1); print "'.price($obj->amount)."'; if ($obj->statut == 3) { print ''.$langs->trans("StatusRefused").''; } else { if ($object->statut == BonPrelevement::STATUS_CREDITED) { if ($obj->statut == 2) { if ($user->rights->prelevement->bons->credit) { //print ''.$langs->trans("StandingOrderReject").''; print ''.$langs->trans("StandingOrderReject").''; } else { //print ''.$langs->trans("StandingOrderReject").''; } } } else { //print ''.$langs->trans("StandingOrderReject").''; } } print '
'.$langs->trans("Total").' '; 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 " 
"; print '
'; print '
'; $db->free($result); } else { dol_print_error($db); } } // End of page llxFooter(); $db->close();