dolibarr/htdocs/compta/prelevement/factures.php

303 lines
10 KiB
PHP
Raw Normal View History

2012-08-22 23:27:53 +02:00
<?php
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
2017-02-21 13:16:28 +01:00
* Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
2012-12-30 15:13:49 +01:00
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
2012-02-29 18:56:54 +01:00
* Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
2005-01-18 18:12: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-18 18:12: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-18 18:12:30 +01:00
*/
/**
2010-04-29 10:38:58 +02:00
* \file htdocs/compta/prelevement/factures.php
* \ingroup prelevement
* \brief Page liste des factures prelevees
*/
require('../../main.inc.php');
require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.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', 'companies', 'withdrawals', 'bills'));
2008-11-05 23:34:14 +01:00
// Securite acces client
2005-01-18 18:12:30 +01:00
if ($user->societe_id > 0) accessforbidden();
2011-05-06 15:49:34 +02:00
// Get supervariables
2012-02-27 22:26:22 +01:00
$prev_id = GETPOST('id','int');
$socid = GETPOST('socid','int');
$ref = GETPOST('ref', 'alpha');
2017-02-21 13:16:28 +01:00
2017-06-08 14:55:12 +02:00
$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
2017-02-21 13:16:28 +01:00
$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;
if (! $sortfield) $sortfield='p.ref';
if (! $sortorder) $sortorder='DESC';
$object = new BonPrelevement($db,"");
2017-02-21 13:16:28 +01:00
/*
* View
*/
$invoicetmp = new Facture($db);
$thirdpartytmp = new Societe($db);
2011-05-06 15:49:34 +02:00
2014-05-16 15:50:38 +02:00
llxHeader('',$langs->trans("WithdrawalsReceipts"));
2005-01-18 18:12:30 +01:00
if ($prev_id > 0 || $ref)
2005-01-18 18:12:30 +01:00
{
if ($object->fetch($prev_id, $ref) >= 0)
2005-01-18 18:12:30 +01:00
{
$head = prelevement_prepare_head($object);
dol_fiche_head($head, 'invoices', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
2005-01-18 18:12:30 +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>';
2010-11-18 18:10:31 +01:00
print '<table class="border" width="100%">';
//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>';
2011-01-05 10:57:55 +01:00
// Status
//print '<tr><td>'.$langs->trans('Status').'</td><td>'.$object->getLibStatut(1).'</td></tr>';
if($object->date_trans <> 0)
2011-01-05 10:57:55 +01:00
{
$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');
2011-01-08 09:18:29 +01:00
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];
2011-01-05 10:57:55 +01:00
print '</td></tr>';
}
if($object->date_credit <> 0)
2011-01-05 10:57:55 +01:00
{
2017-02-21 13:16:28 +01:00
print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
print dol_print_date($object->date_credit,'day');
2011-01-05 10:57:55 +01:00
print '</td></tr>';
}
print '</table>';
print '<br>';
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();
2005-01-18 18:12:30 +01:00
}
2010-11-18 18:10:31 +01:00
else
2005-01-18 18:12:30 +01:00
{
2010-11-18 18:10:31 +01:00
dol_print_error($db);
2005-01-18 18:12:30 +01:00
}
}
2017-02-21 13:16:28 +01:00
// List of invoices
2017-09-19 19:29:00 +02:00
$sql = "SELECT pf.rowid,";
$sql.= " f.rowid as facid, f.facnumber as ref, f.total_ttc,";
$sql.= " s.rowid as socid, s.nom as name, pl.statut, pl.amount as amount_requested";
$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";
$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";
$sql.= " AND pf.fk_facture = f.rowid";
$sql.= " AND f.entity = ".$conf->entity;
2011-05-06 15:49:34 +02:00
if ($prev_id) $sql.= " AND p.rowid=".$prev_id;
if ($socid) $sql.= " AND s.rowid = ".$socid;
2017-02-21 13:16:28 +01:00
$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;
}
2017-02-21 13:16:28 +01:00
}
$sql.= $db->plimit($limit + 1,$offset);
2005-03-01 14:26:20 +01:00
2017-02-21 13:16:28 +01:00
$result = $db->query($sql);
2005-01-18 18:12:30 +01:00
if ($result)
{
2010-11-18 18:10:31 +01:00
$num = $db->num_rows($result);
$i = 0;
2010-03-27 15:40:39 +01:00
2017-02-21 13:16:28 +01:00
$param = "&amp;id=".$prev_id;
// Lines of title fields
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
2017-05-21 02:43:51 +02:00
print '<input type="hidden" name="page" value="'.$page.'">';
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
2017-02-21 13:16:28 +01:00
print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
$massactionbutton='';
print_barre_liste($langs->trans("Invoices"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit);
2010-11-18 18:10:31 +01:00
print"\n<!-- debut table -->\n";
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
2010-11-18 18:10:31 +01:00
print '<table class="liste" width="100%">';
print '<tr class="liste_titre">';
print_liste_field_titre("Bill",$_SERVER["PHP_SELF"],"p.ref",'',$param,'',$sortfield,$sortorder);
print_liste_field_titre("ThirdParty",$_SERVER["PHP_SELF"],"s.nom",'',$param,'',$sortfield,$sortorder);
2017-09-19 19:29:00 +02:00
print_liste_field_titre("AmountInvoice",$_SERVER["PHP_SELF"],"f.total_ttc","",$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre("AmountRequested",$_SERVER["PHP_SELF"],"pl.amount","",$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre("StatusDebitCredit",$_SERVER["PHP_SELF"],"","",$param,'align="center"',$sortfield,$sortorder);
2015-06-26 06:23:29 +02:00
print_liste_field_titre('');
print "</tr>\n";
2005-01-18 18:12:30 +01:00
2017-09-19 19:29:00 +02:00
$totalinvoices = 0;
$totalamount_requested = 0;
2005-01-18 18:12:30 +01:00
2017-02-21 13:16:28 +01:00
while ($i < min($num, $limit))
2005-01-18 18:12:30 +01:00
{
2010-11-18 18:10:31 +01:00
$obj = $db->fetch_object($result);
2005-01-18 18:12:30 +01:00
2017-02-21 13:16:28 +01:00
$invoicetmp->id = $obj->facid;
$invoicetmp->ref = $obj->ref;
2017-02-21 13:16:28 +01:00
$thirdpartytmp->id = $obj->socid;
$thirdpartytmp->name = $obj->name;
print '<tr class="oddeven">';
2017-02-21 13:16:28 +01:00
print "<td>";
print $invoicetmp->getNomUrl(1);
print "</td>\n";
2005-01-18 18:12:30 +01:00
2017-02-21 13:16:28 +01:00
print '<td>';
print $thirdpartytmp->getNomUrl(1);
print "</td>\n";
2005-01-18 18:12:30 +01:00
2017-09-19 19:29:00 +02:00
// Amount of invoice
2017-02-21 13:16:28 +01:00
print '<td align="right">'.price($obj->total_ttc)."</td>\n";
2005-01-18 18:12:30 +01:00
2017-09-19 19:29:00 +02:00
// Amount requested
print '<td align="right">'.price($obj->amount_requested)."</td>\n";
2017-02-21 13:16:28 +01:00
// Status of requests
print '<td align="center">';
2005-01-24 09:34:00 +01:00
2010-11-18 18:10:31 +01:00
if ($obj->statut == 0)
{
print '-';
}
2011-01-30 00:09:36 +01:00
elseif ($obj->statut == 2)
2010-11-18 18:10:31 +01:00
{
2011-01-30 00:09:36 +01:00
print $langs->trans("StatusCredited");
2010-11-18 18:10:31 +01:00
}
2011-01-30 00:09:36 +01:00
elseif ($obj->statut == 3)
2010-11-18 18:10:31 +01:00
{
2011-01-30 00:09:36 +01:00
print '<b>'.$langs->trans("StatusRefused").'</b>';
2010-11-18 18:10:31 +01:00
}
2005-01-24 09:34:00 +01:00
2017-02-21 13:16:28 +01:00
print "</td>";
2017-02-21 13:16:28 +01:00
print "<td></td>";
2017-02-21 13:16:28 +01:00
print "</tr>\n";
2005-01-18 18:12:30 +01:00
2017-09-19 19:29:00 +02:00
$totalinvoices += $obj->total_ttc;
$totalamount_requested += $obj->amount_requested;
2010-11-18 18:10:31 +01:00
$i++;
2005-01-18 18:12:30 +01:00
}
2017-02-21 13:16:28 +01:00
if ($num > 0)
2005-01-18 18:12:30 +01:00
{
2017-02-21 13:16:28 +01:00
print '<tr class="liste_total">';
2011-01-30 00:09:36 +01:00
print '<td>'.$langs->trans("Total").'</td>';
2010-11-18 18:10:31 +01:00
print '<td>&nbsp;</td>';
print '<td align="right">';
2017-09-19 19:29:00 +02:00
//if ($totalinvoices != $object->amount) print img_warning("AmountOfFileDiffersFromSumOfInvoices"); // It is normal to have total that differs. For an amount of invoice of 100, request to pay may be 50 only.
if ($totalamount_requested != $object->amount) print img_warning("AmountOfFileDiffersFromSumOfInvoices");
print "</td>\n";
print '<td align="right">';
print price($totalamount_requested);
print "</td>\n";
2017-02-21 13:16:28 +01:00
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
2010-11-18 18:10:31 +01:00
print "</tr>\n";
2005-01-18 18:12:30 +01:00
}
2010-11-18 18:10:31 +01:00
print "</table>";
print '</div>';
2010-11-18 18:10:31 +01:00
$db->free($result);
2005-01-18 18:12:30 +01:00
}
2010-03-27 15:40:39 +01:00
else
2005-01-18 18:12:30 +01:00
{
2010-11-18 18:10:31 +01:00
dol_print_error($db);
2005-01-18 18:12:30 +01:00
}
llxFooter();
2014-11-05 16:21:17 +01:00
$db->close();