dolibarr/htdocs/compta/prelevement/card.php

425 lines
13 KiB
PHP
Raw Normal View History

2012-08-22 23:27:53 +02:00
<?php
2008-12-15 23:13:55 +01:00
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
2016-04-15 17:20:37 +02:00
* Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
2005-01-07 16:26:30 +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-01-07 16:26:30 +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
2011-08-01 00:21:57 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2005-01-07 16:26:30 +01:00
*/
2009-03-28 20:59:12 +01:00
2005-01-21 23:59:48 +01:00
/**
* \file htdocs/compta/prelevement/card.php
2009-03-28 20:59:12 +01:00
* \ingroup prelevement
* \brief Card of a direct debit
2009-03-28 20:59:12 +01:00
*/
2005-01-21 23:59:48 +01:00
require('../../main.inc.php');
require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
2015-06-21 17:05:49 +02:00
require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.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'));
2005-01-07 16:26:30 +01:00
2005-08-03 18:05:00 +02:00
if (!$user->rights->prelevement->bons->lire)
2009-03-28 20:59:12 +01:00
accessforbidden();
2005-08-03 18:05:00 +02:00
2005-01-21 23:59:48 +01:00
$langs->load("bills");
2008-11-05 23:34:14 +01:00
$langs->load("withdrawals");
2005-01-21 23:59:48 +01:00
2009-03-28 20:59:12 +01:00
// Security check
if ($user->societe_id > 0) accessforbidden();
2011-05-06 15:49:34 +02:00
// Get supervariables
2012-02-29 18:56:54 +01:00
$action = GETPOST('action','alpha');
2012-02-27 22:26:22 +01:00
$id = GETPOST('id','int');
$ref = GETPOST('ref', 'alpha');
2015-06-21 17:05:49 +02:00
$socid = GETPOST('socid','int');
2017-02-21 13:16:28 +01:00
// Load variable for pagination
2017-06-08 14:55:12 +02:00
$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
$sortfield = GETPOST('sortfield','alpha');
$sortorder = GETPOST('sortorder','alpha');
$page = GETPOST('page','int');
2017-06-06 10:53:53 +02:00
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
2017-02-21 13:16:28 +01:00
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
2017-02-21 13:16:28 +01:00
if (! $sortfield) $sortfield='pl.fk_soc';
if (! $sortorder) $sortorder='DESC';
2015-06-21 17:05:49 +02:00
$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
2008-11-05 23:34:14 +01:00
/*
* Actions
*/
2017-02-21 13:16:28 +01:00
if ( $action == 'confirm_delete' )
{
$res=$object->delete($user);
if ($res > 0)
{
header("Location: index.php");
exit;
}
}
2008-11-05 23:34:14 +01:00
// Seems to no be used and replaced with $action == 'infocredit
2012-02-29 18:56:54 +01:00
if ( $action == 'confirm_credite' && GETPOST('confirm','alpha') == 'yes')
2005-01-07 16:26:30 +01:00
{
$res=$object->set_credite();
2017-02-21 13:16:28 +01:00
if ($res >= 0)
{
header("Location: card.php?id=".$id);
exit;
2017-02-21 13:16:28 +01:00
}
2005-01-07 16:26:30 +01:00
}
2011-05-06 15:49:34 +02:00
if ($action == 'infotrans' && $user->rights->prelevement->bons->send)
{
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)
2009-03-28 20:59:12 +01:00
{
$dir = $conf->prelevement->dir_output.'/receipts';
2005-04-05 16:23:45 +02:00
if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $dir . "/" . dol_unescapefile($_FILES['userfile']['name']),1) > 0)
2009-03-28 20:59:12 +01:00
{
$object->set_infotrans($user, $dt, GETPOST('methode','alpha'));
2009-03-28 20:59:12 +01:00
}
header("Location: card.php?id=".$id);
exit;
2009-03-28 20:59:12 +01:00
}
else
2005-04-05 16:23:45 +02:00
{
2009-03-28 20:59:12 +01:00
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;
2005-04-05 16:23:45 +02:00
}
}
// Set direct debit order to credited, create payment and close invoices
2011-05-06 15:49:34 +02:00
if ($action == 'infocredit' && $user->rights->prelevement->bons->credit)
{
2012-02-29 18:56:54 +01:00
$dt = dol_mktime(12,0,0,GETPOST('remonth','int'),GETPOST('reday','int'),GETPOST('reyear','int'));
2009-03-28 20:59:12 +01:00
$error = $object->set_infocredit($user, $dt);
2009-03-28 20:59:12 +01:00
if ($error)
2009-03-28 20:59:12 +01:00
{
header("Location: card.php?id=".$id."&error=$error");
exit;
2009-03-28 20:59:12 +01:00
}
}
2009-03-28 20:59:12 +01:00
/*
* View
*/
$form = new Form($db);
llxHeader('',$langs->trans("WithdrawalsReceipts"));
if ($id > 0 || $ref)
2005-01-11 15:40:08 +01:00
{
$head = prelevement_prepare_head($object);
dol_fiche_head($head, 'prelevement', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
if (GETPOST('error','alpha')!='')
2005-08-03 17:17:53 +02:00
{
print '<div class="error">'.$object->getErrorString(GETPOST('error','alpha')).'</div>';
}
2009-03-28 20:59:12 +01:00
/*if ($action == 'credite')
{
print $form->formconfirm("card.php?id=".$object->id,$langs->trans("ClassCredited"),$langs->trans("ClassCreditedConfirm"),"confirm_credite",'',1,1);
}*/
2009-03-28 20:59:12 +01:00
2017-12-15 17:24:36 +01:00
$linkback = '<a href="'.DOL_URL_ROOT.'/compta/prelevement/bons.php">'.$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" width="100%">';
2009-03-28 20:59:12 +01:00
//print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>'.$object->getNomUrl(1).'</td></tr>';
print '<tr><td class="titlefield">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec,'day').'</td></tr>';
print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
// Status
/*
2017-02-21 13:16:28 +01:00
print '<tr><td>'.$langs->trans('Status').'</td>';
print '<td>'.$object->getLibStatut(1).'</td>';
print '</tr>';
*/
if($object->date_trans <> 0)
{
$muser = new User($db);
$muser->fetch($object->user_trans);
2017-02-21 13:16:28 +01:00
print '<tr><td>'.$langs->trans("TransData").'</td><td>';
print dol_print_date($object->date_trans,'day');
print ' '.$langs->trans("By").' '.$muser->getFullName($langs).'</td></tr>';
2017-02-21 13:16:28 +01:00
print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
print $object->methodes_trans[$object->method_trans];
print '</td></tr>';
}
if($object->date_credit <> 0)
{
2017-02-21 13:16:28 +01:00
print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
print dol_print_date($object->date_credit,'day');
print '</td></tr>';
}
2009-03-28 20:59:12 +01:00
print '</table>';
2009-03-28 20:59:12 +01:00
print '<br>';
2009-03-28 20:59:12 +01:00
print '<div class="underbanner clearboth"></div>';
print '<table class="border" width="100%">';
$acc = new Account($db);
$result=$acc->fetch($conf->global->PRELEVEMENT_ID_BANKACCOUNT);
print '<tr><td class="titlefield">';
print $langs->trans("BankToReceiveWithdraw");
print '</td>';
print '<td>';
if ($acc->id > 0)
print $acc->getNomUrl(1);
print '</td>';
print '</tr>';
print '<tr><td class="titlefield">';
print $langs->trans("WithdrawalFile").'</td><td>';
$relativepath = 'receipts/'.$object->ref.'.xml';
2013-04-20 20:30:18 +02:00
print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart=prelevement&amp;file='.urlencode($relativepath).'">'.$relativepath.'</a>';
print '</td></tr></table>';
print '</div>';
dol_fiche_end();
2009-03-28 20:59:12 +01:00
if (empty($object->date_trans) && $user->rights->prelevement->bons->send && $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="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="infotrans">';
2018-01-18 18:40:01 +01:00
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td colspan="3">'.$langs->trans("NotifyTransmision").'</td></tr>';
2018-01-18 18:40:01 +01:00
print '<tr class="oddeven"><td>'.$langs->trans("TransData").'</td><td>';
print $form->select_date('','','','','',"userfile",1,1);
print '</td></tr>';
2018-01-18 18:40:01 +01:00
print '<tr class="oddeven"><td>'.$langs->trans("TransMetod").'</td><td>';
print $form->selectarray("methode",$object->methodes_trans);
print '</td></tr>';
/* print '<tr><td width="20%">'.$langs->trans("File").'</td><td>';
print '<input type="hidden" name="max_file_size" value="'.$conf->maxfilesize.'">';
print '<input class="flat" type="file" name="userfile"><br>';
print '</td></tr>';*/
print '</table><br>';
2014-11-25 20:13:43 +01:00
print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("SetToStatusSent")).'"></div>';
print '</form>';
2018-01-18 18:40:01 +01:00
print '<br>';
}
if (! empty($object->date_trans) && $object->date_credit == 0 && $user->rights->prelevement->bons->credit && $action=='setcredited')
{
print '<form name="infocredit" method="post" action="card.php?id='.$object->id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="infocredit">';
2018-01-18 18:40:01 +01:00
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td colspan="3">'.$langs->trans("NotifyCredit").'</td></tr>';
2018-01-18 18:40:01 +01:00
print '<tr class="oddeven"><td>'.$langs->trans('CreditDate').'</td><td>';
print $form->select_date('','','','','',"infocredit",1,1);
print '</td></tr>';
print '</table>';
print '<br>'.$langs->trans("ThisWillAlsoAddPaymentOnInvoice");
2014-11-25 20:13:43 +01:00
print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("ClassCredited")).'"></div>';
print '</form>';
2018-01-18 18:40:01 +01:00
print '<br>';
}
2009-03-28 20:59:12 +01:00
// Actions
if ($action != 'settransmitted' && $action != 'setcredited')
{
print "\n<div class=\"tabsAction\">\n";
if (empty($object->date_trans) && $user->rights->prelevement->bons->send)
2009-03-28 20:59:12 +01:00
{
print "<a class=\"butAction\" href=\"card.php?action=settransmitted&id=".$object->id."\">".$langs->trans("SetToStatusSent")."</a>";
2009-03-28 20:59:12 +01:00
}
if (! empty($object->date_trans) && $object->date_credit == 0)
2009-03-28 20:59:12 +01:00
{
print "<a class=\"butAction\" href=\"card.php?action=setcredited&id=".$object->id."\">".$langs->trans("ClassCredited")."</a>";
2009-03-28 20:59:12 +01:00
}
2005-01-11 15:40:08 +01:00
print "<a class=\"butActionDelete\" href=\"card.php?action=confirm_delete&id=".$object->id."\">".$langs->trans("Delete")."</a>";
2005-01-11 15:40:08 +01:00
print "</div>";
}
2015-06-21 17:05:49 +02:00
$ligne=new LignePrelevement($db,$user);
/*
* Lines into withdraw request
*/
2017-02-21 13:16:28 +01:00
$sql = "SELECT pl.rowid, pl.statut, pl.amount,";
$sql.= " s.rowid as socid, s.nom as name";
2015-06-21 17:05:49 +02:00
$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 = ".$id;
$sql.= " AND pl.fk_prelevement_bons = pb.rowid";
$sql.= " AND pb.entity = ".$conf->entity;
$sql.= " AND pl.fk_soc = s.rowid";
if ($socid) $sql.= " AND s.rowid = ".$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);
2015-06-21 17:05:49 +02:00
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows($result);
$i = 0;
2016-04-15 17:20:37 +02:00
$urladd = "&amp;id=".$id;
2015-06-21 17:05:49 +02:00
print_barre_liste($langs->trans("Lines"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');
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
2015-06-21 17:05:49 +02:00
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
print '<tr class="liste_titre">';
print_liste_field_titre("Lines",$_SERVER["PHP_SELF"],"pl.rowid",'',$urladd);
print_liste_field_titre("ThirdParty",$_SERVER["PHP_SELF"],"s.nom",'',$urladd);
print_liste_field_titre("Amount",$_SERVER["PHP_SELF"],"pl.amount","",$urladd,'align="right"');
2015-06-21 17:05:49 +02:00
print_liste_field_titre('');
2015-06-27 02:31:26 +02:00
print "</tr>\n";
2015-06-21 17:05:49 +02:00
$var=false;
$total = 0;
while ($i < min($num,$conf->liste_limit))
{
$obj = $db->fetch_object($result);
print '<tr class="oddeven">';
2015-06-21 17:05:49 +02:00
2017-02-21 13:16:28 +01:00
// Status of line
2015-06-21 17:05:49 +02:00
print "<td>";
print $ligne->LibStatut($obj->statut,2);
print "&nbsp;";
print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/ligne.php?id='.$obj->rowid.'">';
2017-02-21 13:16:28 +01:00
print sprintf("%06s",$obj->rowid);
2015-06-21 17:05:49 +02:00
print '</a></td>';
$thirdparty=new Societe($db);
$thirdparty->fetch($obj->socid);
print '<td>';
print $thirdparty->getNomUrl(1);
print "</td>\n";
2017-02-21 13:16:28 +01:00
print '<td align="right">'.price($obj->amount)."</td>\n";
2015-06-21 17:05:49 +02:00
print '<td>';
if ($obj->statut == 3)
{
print '<b>'.$langs->trans("StatusRefused").'</b>';
}
else
{
print "&nbsp;";
}
print '</td></tr>';
2017-02-21 13:16:28 +01:00
$total += $obj->amount;
2015-06-21 17:05:49 +02:00
$i++;
}
2017-02-21 13:16:28 +01:00
if ($num > 0)
2015-06-21 17:05:49 +02:00
{
2017-02-21 13:16:28 +01:00
print '<tr class="liste_total">';
2015-06-21 17:05:49 +02:00
print '<td>'.$langs->trans("Total").'</td>';
print '<td>&nbsp;</td>';
print '<td align="right">';
if ($total != $object->amount) print img_warning("AmountOfFileDiffersFromSumOfInvoices");
print price($total);
print "</td>\n";
2015-06-21 17:05:49 +02:00
print '<td>&nbsp;</td>';
print "</tr>\n";
}
print "</table>";
print '</div>';
2015-06-21 17:05:49 +02:00
$db->free($result);
}
else
{
dol_print_error($db);
}
}
2005-01-07 16:26:30 +01:00
llxFooter();
$db->close();