dolibarr/htdocs/compta/prelevement/line.php

356 lines
11 KiB
PHP
Raw Normal View History

2012-08-22 23:27:53 +02:00
<?php
2018-09-09 09:36:12 +02:00
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
2018-10-27 14:43:12 +02:00
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
2018-09-09 09:36:12 +02:00
* Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
2005-03-01 14:27:29 +01:00
*
* 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
2005-03-01 14:27:29 +01:00
* (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
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2005-03-01 14:27:29 +01:00
*/
2009-03-28 20:59:12 +01:00
/**
2019-07-19 23:19:06 +02:00
* \file htdocs/compta/prelevement/line.php
2009-03-28 20:59:12 +01:00
* \ingroup prelevement
* \brief card of withdraw line
*/
2018-07-26 11:57:25 +02:00
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
2013-06-05 16:24:32 +02:00
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
2018-05-27 09:27:09 +02:00
// Load translation files required by the page
$langs->loadlangs(array('banks', 'categories', 'bills', 'withdrawals'));
2005-03-01 14:27:29 +01:00
2011-05-12 17:57:38 +02:00
// Get supervariables
2020-09-16 19:39:50 +02:00
$action = GETPOST('action', 'aZ09');
$id = GETPOST('id', 'int');
$socid = GETPOST('socid', 'int');
$type = GETPOST('type', 'aZ09');
2020-04-20 15:06:27 +02:00
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
2020-09-17 14:31:25 +02:00
$sortorder = GETPOST('sortorder', 'aZ09comma');
2020-09-18 17:13:01 +02:00
$sortfield = GETPOST('sortfield', 'aZ09comma');
2020-04-20 15:06:27 +02:00
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
2021-06-10 00:00:49 +02:00
if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
// If $page is not defined, or '' or -1 or if we click on clear filters
2021-02-23 21:09:01 +01:00
$page = 0;
}
2020-04-20 15:06:27 +02:00
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
2021-02-23 21:09:01 +01:00
if ($sortorder == "") {
$sortorder = "DESC";
}
if ($sortfield == "") {
$sortfield = "pl.fk_soc";
}
2020-04-20 15:06:27 +02:00
if ($type == 'bank-transfer') {
$result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
} else {
$result = restrictedArea($user, 'prelevement', '', '', 'bons');
}
2020-04-20 15:06:27 +02:00
/*
* Actions
*/
2011-05-12 17:57:38 +02:00
2021-02-23 21:09:01 +01:00
if ($action == 'confirm_rejet') {
if (GETPOST("confirm") == 'yes') {
if (GETPOST('remonth', 'int')) {
$daterej = mktime(2, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
2013-05-13 16:30:52 +02:00
}
2005-03-01 17:06:16 +01:00
2021-02-23 21:09:01 +01:00
if (empty($daterej)) {
2013-05-11 18:36:44 +02:00
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
2021-02-23 21:09:01 +01:00
} elseif ($daterej > dol_now()) {
2013-05-13 16:30:52 +02:00
$error++;
$langs->load("error");
2015-11-15 07:47:35 +01:00
setEventMessages($langs->transnoentities("ErrorDateMustBeBeforeToday"), null, 'errors');
2013-05-13 16:30:52 +02:00
}
2021-02-23 21:09:01 +01:00
if (GETPOST('motif', 'alpha') == 0) {
2013-05-11 18:36:44 +02:00
$error++;
2015-10-17 16:18:33 +02:00
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("RefusedReason")), null, 'errors');
2013-05-11 18:36:44 +02:00
}
2021-02-23 21:09:01 +01:00
if (!$error) {
2020-05-07 12:14:45 +02:00
$lipre = new LignePrelevement($db);
2021-02-23 21:09:01 +01:00
if ($lipre->fetch($id) == 0) {
2020-10-22 21:32:12 +02:00
$rej = new RejetPrelevement($db, $user, $type);
$rej->create($user, $id, GETPOST('motif', 'alpha'), $daterej, $lipre->bon_rowid, GETPOST('facturer', 'int'));
2009-03-28 20:59:12 +01:00
2020-10-23 03:55:18 +02:00
header("Location: line.php?id=".urlencode($id).'&type='.urlencode($type));
2009-03-28 20:59:12 +01:00
exit;
}
2020-05-21 15:05:19 +02:00
} else {
$action = "rejet";
2009-03-28 20:59:12 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-10-23 03:55:18 +02:00
header("Location: line.php?id=".urlencode($id).'&type='.urlencode($type));
2009-03-28 20:59:12 +01:00
exit;
2005-03-01 14:27:29 +01:00
}
}
2014-11-05 17:32:42 +01:00
2009-03-28 20:59:12 +01:00
/*
* View
*/
2005-03-01 14:27:29 +01:00
if ($type == 'bank-transfer') {
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
$invoicestatic = new FactureFournisseur($db);
} else {
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
$invoicestatic = new Facture($db);
}
2014-11-05 17:32:42 +01:00
2020-06-08 11:43:20 +02:00
$title = $langs->trans("WithdrawalsLine");
if ($type == 'bank-transfer') {
$title = $langs->trans("CreditTransferLine");
}
llxHeader('', $title);
$head = array();
2005-03-01 14:27:29 +01:00
$h = 0;
2020-10-20 12:15:06 +02:00
$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$id.'&type='.$type;
2020-06-08 11:43:20 +02:00
$head[$h][1] = $title;
2005-03-01 14:27:29 +01:00
$hselected = $h;
2009-03-28 20:59:12 +01:00
$h++;
2005-03-01 14:27:29 +01:00
2021-02-23 21:09:01 +01:00
if ($id) {
2020-05-07 12:14:45 +02:00
$lipre = new LignePrelevement($db);
2010-07-27 00:03:50 +02:00
2021-02-23 21:09:01 +01:00
if ($lipre->fetch($id) >= 0) {
2009-03-28 20:59:12 +01:00
$bon = new BonPrelevement($db);
$bon->fetch($lipre->bon_rowid);
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head($head, $hselected, $title);
2009-03-28 20:59:12 +01:00
2020-06-08 11:43:20 +02:00
print '<table class="border centpercent tableforfield">';
2009-03-28 20:59:12 +01:00
2020-06-08 11:43:20 +02:00
print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>';
print $id.'</td></tr>';
2009-03-28 20:59:12 +01:00
2020-06-08 11:43:20 +02:00
print '<tr><td class="titlefield">'.$langs->trans("WithdrawalsReceipts").'</td><td>';
print $bon->getNomUrl(1).'</td></tr>';
2020-06-08 11:43:20 +02:00
print '<tr><td>'.$langs->trans("Date").'</td><td>'.dol_print_date($bon->datec, 'day').'</td></tr>';
2021-09-28 00:21:54 +02:00
print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($lipre->amount).'</span></td></tr>';
2020-06-08 11:43:20 +02:00
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$lipre->LibStatut($lipre->statut, 1).'</td></tr>';
2012-08-05 14:37:45 +02:00
2021-02-23 21:09:01 +01:00
if ($lipre->statut == 3) {
2020-10-22 21:29:33 +02:00
$rej = new RejetPrelevement($db, $user, $type);
2009-03-28 20:59:12 +01:00
$resf = $rej->fetch($lipre->id);
2021-02-23 21:09:01 +01:00
if ($resf == 0) {
2020-06-08 11:43:20 +02:00
print '<tr><td>'.$langs->trans("RefusedReason").'</td><td>'.$rej->motif.'</td></tr>';
2021-09-28 00:21:54 +02:00
2020-06-08 11:43:20 +02:00
print '<tr><td>'.$langs->trans("RefusedData").'</td><td>';
2021-02-23 21:09:01 +01:00
if ($rej->date_rejet == 0) {
2009-03-28 20:59:12 +01:00
/* Historique pour certaines install */
print $langs->trans("Unknown");
2020-05-21 15:05:19 +02:00
} else {
print dol_print_date($rej->date_rejet, 'day');
2009-03-28 20:59:12 +01:00
}
print '</td></tr>';
2021-09-28 00:21:54 +02:00
2020-06-08 11:43:20 +02:00
print '<tr><td>'.$langs->trans("RefusedInvoicing").'</td><td>'.$rej->invoicing.'</td></tr>';
2020-05-21 15:05:19 +02:00
} else {
2020-06-08 11:43:20 +02:00
print '<tr><td>'.$resf.'</td></tr>';
2009-03-28 20:59:12 +01:00
}
}
2009-03-28 20:59:12 +01:00
2011-01-09 00:18:13 +01:00
print '</table>';
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end();
2020-05-21 15:05:19 +02:00
} else {
2011-01-09 00:18:13 +01:00
dol_print_error($db);
2005-03-02 14:31:36 +01:00
}
2021-02-23 21:09:01 +01:00
if ($action == 'rejet' && $user->rights->prelevement->bons->credit) {
$form = new Form($db);
2009-03-28 20:59:12 +01:00
$soc = new Societe($db);
$soc->fetch($lipre->socid);
2020-10-22 15:59:04 +02:00
$rej = new RejetPrelevement($db, $user, $type);
2010-07-27 00:03:50 +02:00
2019-07-19 23:19:06 +02:00
print '<form name="confirm_rejet" method="post" action="line.php?id='.$id.'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
2009-03-28 20:59:12 +01:00
print '<input type="hidden" name="action" value="confirm_rejet">';
print '<input type="hidden" name="type" value="'.$type.'">';
2020-06-08 11:43:20 +02:00
print '<table class="noborder centpercent">';
2011-01-09 00:18:13 +01:00
print '<tr class="liste_titre">';
print '<td colspan="3">'.$langs->trans("WithdrawalRefused").'</td></tr>';
2012-08-05 14:37:45 +02:00
2011-01-09 00:18:13 +01:00
//Select yes/no
print '<tr><td class="valid">'.$langs->trans("WithdrawalRefusedConfirm").' '.$soc->name.' ?</td>';
2009-03-28 20:59:12 +01:00
print '<td colspan="2" class="valid">';
print $form->selectyesno("confirm", 1, 0);
2009-03-28 20:59:12 +01:00
print '</td></tr>';
2012-08-05 14:37:45 +02:00
2011-01-09 00:18:13 +01:00
//Date
print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedData").'</td>';
2009-03-28 20:59:12 +01:00
print '<td colspan="2" class="valid">';
2018-09-09 09:36:12 +02:00
print $form->selectDate('', '', '', '', '', "confirm_rejet");
2009-03-28 20:59:12 +01:00
print '</td></tr>';
2012-08-05 14:37:45 +02:00
2011-01-09 00:18:13 +01:00
//Reason
print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedReason").'</td>';
2009-03-28 20:59:12 +01:00
print '<td class="valid">';
2020-06-08 11:43:20 +02:00
print $form->selectarray("motif", $rej->motifs, GETPOSTISSET('motif') ? GETPOST('motif', 'int') : '');
2011-01-09 00:18:13 +01:00
print '</td></tr>';
2012-08-05 14:37:45 +02:00
2011-01-09 00:18:13 +01:00
//Facturer
print '<tr><td class="valid">'.$langs->trans("RefusedInvoicing").'</td>';
print '<td class="valid" colspan="2">';
2020-06-08 11:43:20 +02:00
print $form->selectarray("facturer", $rej->facturer, GETPOSTISSET('facturer') ? GETPOST('facturer', 'int') : '');
2011-01-09 00:18:13 +01:00
print '</td></tr>';
print '</table><br>';
2012-08-05 14:37:45 +02:00
2011-01-09 00:18:13 +01:00
//Confirm Button
print '<div class="center"><input type="submit" class="button button-save" value='.$langs->trans("Confirm").'></div>';
2011-01-09 00:18:13 +01:00
print '</form>';
}
2012-08-05 14:37:45 +02:00
2021-03-16 04:22:55 +01:00
/*
* Action bar
*/
2021-09-28 00:21:54 +02:00
print '<div class="tabsAction">';
2009-03-28 20:59:12 +01:00
2021-02-23 21:09:01 +01:00
if ($action == '') {
if ($bon->statut == BonPrelevement::STATUS_CREDITED) {
2020-06-08 11:43:20 +02:00
if ($lipre->statut == 2) {
2021-02-23 21:09:01 +01:00
if ($user->rights->prelevement->bons->credit) {
2020-10-20 12:15:06 +02:00
print '<a class="butActionDelete" href="line.php?action=rejet&type='.$type.'&id='.$lipre->id.'">'.$langs->trans("StandingOrderReject").'</a>';
} else {
2020-06-08 11:43:20 +02:00
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("StandingOrderReject").'</a>';
}
2014-11-05 17:32:42 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-06-08 11:43:20 +02:00
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotPossibleForThisStatusOfWithdrawReceiptORLine").'">'.$langs->trans("StandingOrderReject").'</a>';
}
2005-03-01 17:06:16 +01:00
}
2009-03-28 20:59:12 +01:00
2021-09-28 00:21:54 +02:00
print '</div>';
2011-01-09 00:18:13 +01:00
2009-03-28 20:59:12 +01:00
/*
2015-11-15 07:47:35 +01:00
* List of invoices
2009-03-28 20:59:12 +01:00
*/
$sql = "SELECT pf.rowid";
$sql .= " ,f.rowid as facid, f.ref as ref, f.total_ttc, f.paye, f.fk_statut";
$sql .= " , s.rowid as socid, s.nom as name";
$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
$sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
$sql .= " , ".MAIN_DB_PREFIX."prelevement_facture as pf";
if ($type == 'bank-transfer') {
$sql .= " , ".MAIN_DB_PREFIX."facture_fourn as f";
} else {
$sql .= " , ".MAIN_DB_PREFIX."facture as f";
}
$sql .= " , ".MAIN_DB_PREFIX."societe as s";
$sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid";
$sql .= " AND pl.fk_prelevement_bons = p.rowid";
$sql .= " AND f.fk_soc = s.rowid";
if ($type == 'bank-transfer') {
$sql .= " AND pf.fk_facture_fourn = f.rowid";
} else {
$sql .= " AND pf.fk_facture = f.rowid";
}
$sql .= " AND f.entity IN (".getEntity('invoice').")";
2021-03-22 13:31:06 +01:00
$sql .= " AND pl.rowid = ".((int) $id);
2021-02-23 21:09:01 +01:00
if ($socid) {
2021-03-22 13:31:06 +01:00
$sql .= " AND s.rowid = ".((int) $socid);
2021-02-23 21:09:01 +01:00
}
2021-09-28 00:21:54 +02:00
$sql .= $db->order($sortfield, $sortorder);
$sql .= $db->plimit($conf->liste_limit + 1, $offset);
2005-03-01 14:27:29 +01:00
2009-03-28 20:59:12 +01:00
$result = $db->query($sql);
2005-03-01 14:27:29 +01:00
2021-02-23 21:09:01 +01:00
if ($result) {
2009-03-28 20:59:12 +01:00
$num = $db->num_rows($result);
$i = 0;
2005-03-01 14:27:29 +01:00
2021-04-25 15:55:36 +02:00
$urladd = "&id=".urlencode($id);
2005-03-01 14:27:29 +01:00
2010-06-09 18:51:11 +02:00
print_barre_liste($langs->trans("Bills"), $page, "factures.php", $urladd, $sortfield, $sortorder, '', $num, 0, '');
2005-03-01 14:27:29 +01:00
2009-03-28 20:59:12 +01:00
print"\n<!-- debut table -->\n";
2021-04-30 15:22:17 +02:00
print '<table class="noborder" width="100%" cellpadding="4">';
2009-03-28 20:59:12 +01:00
print '<tr class="liste_titre">';
2019-02-10 16:08:03 +01:00
print '<td>'.$langs->trans("Invoice").'</td><td>'.$langs->trans("ThirdParty").'</td><td class="right">'.$langs->trans("Amount").'</td><td class="right">'.$langs->trans("Status").'</td>';
2009-03-28 20:59:12 +01:00
print '</tr>';
2005-03-01 14:27:29 +01:00
2009-03-28 20:59:12 +01:00
$total = 0;
2021-02-23 21:09:01 +01:00
while ($i < min($num, $conf->liste_limit)) {
2009-03-28 20:59:12 +01:00
$obj = $db->fetch_object($result);
2017-05-10 16:41:19 +02:00
print '<tr class="oddeven"><td>';
2009-03-28 20:59:12 +01:00
print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">';
print img_object($langs->trans("ShowBill"), "bill");
2009-03-28 20:59:12 +01:00
print '</a>&nbsp;';
2005-03-01 14:27:29 +01:00
if ($type == 'bank-transfer') {
print '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
} else {
print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
}
2005-03-01 14:27:29 +01:00
if ($type == 'bank-transfer') {
print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">';
} else {
print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">';
}
print img_object($langs->trans("ShowCompany"), "company").' '.$obj->name."</a></td>\n";
2005-03-01 14:27:29 +01:00
2021-03-29 13:00:17 +02:00
print '<td class="right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
2005-03-01 14:27:29 +01:00
2019-02-10 16:08:03 +01:00
print '<td class="right">';
2014-11-05 17:32:42 +01:00
$invoicestatic->fetch($obj->facid);
print $invoicestatic->getLibStatut(5);
print "</td>\n";
2009-03-28 20:59:12 +01:00
print "</tr>\n";
2005-03-01 14:27:29 +01:00
2009-03-28 20:59:12 +01:00
$i++;
}
print "</table>";
2005-03-01 14:27:29 +01:00
2009-03-28 20:59:12 +01:00
$db->free($result);
2020-05-21 15:05:19 +02:00
} else {
2009-03-28 20:59:12 +01:00
dol_print_error($db);
}
2005-03-01 14:27:29 +01:00
}
2018-08-08 12:29:36 +02:00
// End of page
llxFooter();
2013-05-11 18:36:44 +02:00
$db->close();