dolibarr/htdocs/compta/recap-compta.php

228 lines
6.3 KiB
PHP
Raw Normal View History

2005-02-28 16:19:57 +01:00
<?php
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
2012-09-25 21:30:55 +02:00
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
2005-02-28 16:19:57 +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-02-28 16:19:57 +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-03 02:45:22 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2005-02-28 16:19:57 +01:00
*/
/**
* \file htdocs/compta/recap-compta.php
* \ingroup compta
* \brief Page de fiche recap compta
*/
2005-02-28 16:19:57 +01:00
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
2005-02-28 16:19:57 +01:00
$langs->load("companies");
2012-09-15 10:01:35 +02:00
if (! empty($conf->facture->enabled)) $langs->load("bills");
2005-02-28 16:19:57 +01:00
// Security check
2005-02-28 16:19:57 +01:00
$socid = $_GET["socid"];
if ($user->societe_id > 0)
{
$action = '';
$socid = $user->societe_id;
}
2005-02-28 16:19:57 +01:00
/*
* View
2005-02-28 16:19:57 +01:00
*/
2013-03-22 17:10:17 +01:00
$userstatic=new User($db);
llxHeader();
2005-02-28 16:19:57 +01:00
if ($socid > 0)
{
2012-02-01 18:29:06 +01:00
$societe = new Societe($db);
$societe->fetch($socid);
2012-02-01 18:29:06 +01:00
/*
* Affichage onglets
*/
2006-04-22 01:49:12 +02:00
$head = societe_prepare_head($societe);
2012-02-01 18:29:06 +01:00
dol_fiche_head($head, 'customer', $langs->trans("ThirdParty"), 0, 'company');
2012-02-01 18:29:06 +01:00
print "<table width=\"100%\">\n";
print '<tr><td valign="top" width="50%">';
2012-02-01 18:29:06 +01:00
print '<table class="border" width="100%">';
2012-02-01 18:29:06 +01:00
// Nom
print '<tr><td width="20%">'.$langs->trans("Name").'</td><td width="80%" colspan="3">'.$societe->nom.'</td></tr>';
2012-02-01 18:29:06 +01:00
// Prefix
if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
{
print '<tr><td>'.$langs->trans("Prefix").'</td><td colspan="3">';
print ($societe->prefix_comm?$societe->prefix_comm:'&nbsp;');
print '</td></tr>';
}
2012-02-01 18:29:06 +01:00
print "</table>";
2012-02-01 18:29:06 +01:00
print "</td></tr></table>\n";
2012-02-01 18:29:06 +01:00
print '</div>';
2012-09-15 11:21:22 +02:00
if (! empty($conf->facture->enabled) && $user->rights->facture->lire)
2012-02-01 18:29:06 +01:00
{
// Factures
print_fiche_titre($langs->trans("CustomerPreview"));
2012-02-01 18:29:06 +01:00
print '<table class="noborder" width="100%">';
2012-02-01 18:29:06 +01:00
$sql = "SELECT s.nom, s.rowid as socid, f.facnumber, f.amount, f.datef as df,";
$sql.= " f.paye as paye, f.fk_statut as statut, f.rowid as facid,";
$sql.= " u.login, u.rowid as userid";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."user as u";
$sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$societe->id;
$sql.= " AND f.entity = ".$conf->entity;
$sql.= " AND f.fk_user_valid = u.rowid";
$sql.= " ORDER BY f.datef DESC";
2012-02-01 18:29:06 +01:00
$resql=$db->query($sql);
if ($resql)
{
$var=true;
$num = $db->num_rows($resql);
2012-02-01 18:29:06 +01:00
print '<tr class="liste_titre">';
print '<td width="100" align="center">'.$langs->trans("Date").'</td>';
print '<td>&nbsp;</td>';
print '<td>'.$langs->trans("Status").'</td>';
print '<td align="right">'.$langs->trans("Debit").'</td>';
print '<td align="right">'.$langs->trans("Credit").'</td>';
print '<td align="right">'.$langs->trans("Balance").'</td>';
print '<td>&nbsp;</td>';
print '</tr>';
if (! $num > 0)
2012-02-01 18:29:06 +01:00
{
print '<tr><td colspan="7">'.$langs->trans("NoInvoice").'</td></tr>';
}
2012-02-01 18:29:06 +01:00
$solde = 0;
2012-02-01 18:29:06 +01:00
// Boucle sur chaque facture
for ($i = 0 ; $i < $num ; $i++)
{
$objf = $db->fetch_object($resql);
2012-02-01 18:29:06 +01:00
$fac = new Facture($db);
$ret=$fac->fetch($objf->facid);
if ($ret < 0)
{
print $fac->error."<br>";
continue;
}
$totalpaye = $fac->getSommePaiement();
2012-02-01 18:29:06 +01:00
$var=!$var;
2012-09-25 21:30:55 +02:00
print "<tr ".$bc[$var].">";
2013-03-22 17:10:17 +01:00
print "<td align=\"center\">".dol_print_date($fac->date,'day')."</td>\n";
print '<td><a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id.'">'.img_object($langs->trans("ShowBill"),"bill")." ".$fac->ref."</a></td>\n";
2012-02-01 18:29:06 +01:00
print '<td aling="left">'.$fac->getLibStatut(2,$totalpaye).'</td>';
print '<td align="right">'.price($fac->total_ttc)."</td>\n";
2012-09-30 21:26:58 +02:00
if (($fac->statut == 3 ) || ($fac->statut == 2 && ! $fact->close_code) ) $solde = $solde = $solde + $totalpaye;
2012-09-25 21:30:55 +02:00
else $solde = $solde + $fac->total_ttc;
2012-02-01 18:29:06 +01:00
print '<td align="right">&nbsp;</td>';
print '<td align="right">'.price($solde)."</td>\n";
2013-03-22 17:10:17 +01:00
// Author
$userstatic->id=$objf->userid;
$userstatic->login=$objf->login;
print '<td class="nowrap" align="right">';
2013-03-22 17:10:17 +01:00
print $userstatic->getLoginUrl(1);
print '</td>';
2012-02-01 18:29:06 +01:00
print "</tr>\n";
2012-02-01 18:29:06 +01:00
// Paiements
$sql = "SELECT p.rowid, p.datep as dp, pf.amount, p.statut,";
$sql.= " p.fk_user_creat, u.login, u.rowid as userid";
$sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf,";
$sql.= " ".MAIN_DB_PREFIX."paiement as p";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON p.fk_user_creat = u.rowid";
$sql.= " WHERE pf.fk_paiement = p.rowid";
$sql.= " AND p.entity = ".$conf->entity;
$sql.= " AND pf.fk_facture = ".$fac->id;
2012-02-01 18:29:06 +01:00
$resqlp = $db->query($sql);
if ($resqlp)
{
$nump = $db->num_rows($resqlp);
$j = 0;
2012-02-01 18:29:06 +01:00
while ($j < $nump)
{
$objp = $db->fetch_object($resqlp);
//$var=!$var;
2013-06-20 09:18:12 +02:00
print "<tr ".$bc[$var].">";
2013-03-22 17:10:17 +01:00
print '<td align="center">'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
2012-02-01 18:29:06 +01:00
print '<td>';
print '&nbsp; &nbsp; &nbsp; '; // Decalage
print '<a href="paiement/fiche.php?id='.$objp->rowid.'">'.img_object($langs->trans("ShowPayment"),"payment").' '.$langs->trans("Payment").' '.$objp->rowid.'</td>';
print "<td>&nbsp;</td>\n";
print "<td>&nbsp;</td>\n";
print '<td align="right">'.price($objp->amount).'</td>';
$solde = $solde - $objp->amount;
print '<td align="right">'.price($solde)."</td>\n";
2013-03-22 17:10:17 +01:00
// Author
$userstatic->id=$objp->userid;
$userstatic->login=$objp->login;
print '<td class="nowrap" align="right">';
2013-03-22 17:10:17 +01:00
print $userstatic->getLoginUrl(1);
print '</td>';
2012-02-01 18:29:06 +01:00
print '</tr>';
2012-02-01 18:29:06 +01:00
$j++;
}
2012-02-01 18:29:06 +01:00
$db->free($resqlp);
}
else
{
dol_print_error($db);
}
}
}
else
{
dol_print_error($db);
}
print "</table>";
print "<br>";
}
2005-02-28 16:19:57 +01:00
}
else
{
2012-02-01 18:29:06 +01:00
dol_print_error($db);
2005-02-28 16:19:57 +01:00
}
2005-07-15 02:26:54 +02:00
2012-02-01 18:29:06 +01:00
llxFooter();
2005-07-15 02:26:54 +02:00
2005-02-28 16:19:57 +01:00
$db->close();
?>