dolibarr 19.0.3
recap-fourn.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2019 Pierre Ardoin <mapiolca@me.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
30
31// Load translation files required by the page
32$langs->loadLangs(array('bills', 'companies'));
33
34// Security check
35$socid = GETPOST("socid", 'int');
36if ($user->socid > 0) {
37 $action = '';
38 $socid = $user->socid;
39}
40
41
42// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
43$hookmanager->initHooks(array('supplierbalencelist', 'globalcard'));
44
45/*
46 * View
47 */
48
49$form = new Form($db);
50$userstatic = new User($db);
51
52llxHeader();
53
54if ($socid > 0) {
55 $societe = new Societe($db);
56 $societe->fetch($socid);
57
58 /*
59 * Affichage onglets
60 */
61 $head = societe_prepare_head($societe);
62
63 print dol_get_fiche_head($head, 'supplier', $langs->trans("ThirdParty"), 0, 'company');
64 dol_banner_tab($societe, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
65 print dol_get_fiche_end();
66
67 if ((isModEnabled("fournisseur") && $user->hasRight("fournisseur", "facture", "lire") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_invoice") && $user->hasRight("supplier_invoice", "lire"))) {
68 // Invoice list
69 print load_fiche_titre($langs->trans("SupplierPreview"));
70
71 print '<table class="noborder tagtable liste centpercent">';
72
73 $sql = "SELECT s.nom, s.rowid as socid, f.ref_supplier, f.datef as df,";
74 $sql .= " f.paye as paye, f.fk_statut as statut, f.rowid as facid,";
75 $sql .= " u.login, u.rowid as userid";
76 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f,".MAIN_DB_PREFIX."user as u";
77 $sql .= " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $societe->id);
78 $sql .= " AND f.entity IN (".getEntity("facture_fourn").")"; // Recognition of the entity attributed to this invoice for Multicompany
79 $sql .= " AND f.fk_user_valid = u.rowid";
80 $sql .= " ORDER BY f.datef DESC";
81
82 $resql = $db->query($sql);
83 if ($resql) {
84 $num = $db->num_rows($resql);
85
86 print '<tr class="liste_titre">';
87 print '<td width="100" class="center">'.$langs->trans("Date").'</td>';
88 print '<td>&nbsp;</td>';
89 print '<td>'.$langs->trans("Status").'</td>';
90 print '<td class="right">'.$langs->trans("Debit").'</td>';
91 print '<td class="right">'.$langs->trans("Credit").'</td>';
92 print '<td class="right">'.$langs->trans("Balance").'</td>';
93 print '<td>&nbsp;</td>';
94 print '</tr>';
95
96 if ($num <= 0) {
97 print '<tr><td colspan="7"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
98 }
99
100 $solde = 0;
101
102 // Boucle sur chaque facture
103 for ($i = 0; $i < $num; $i++) {
104 $objf = $db->fetch_object($resql);
105
106 $fac = new FactureFournisseur($db);
107 $ret = $fac->fetch($objf->facid);
108 if ($ret < 0) {
109 print $fac->error."<br>";
110 continue;
111 }
112 $totalpaid = $fac->getSommePaiement();
113
114 print '<tr class="oddeven">';
115
116 print '<td class="center">'.dol_print_date($fac->date)."</td>\n";
117 print "<td><a href=\"facture/card.php?facid=$fac->id\">".img_object($langs->trans("ShowBill"), "bill")." ".$fac->ref."</a></td>\n";
118
119 print '<td class="left">'.$fac->getLibStatut(2, $totalpaid).'</td>';
120 print '<td class="right">'.price($fac->total_ttc)."</td>\n";
121 $solde = $solde + $fac->total_ttc;
122
123 print '<td class="right">&nbsp;</td>';
124 print '<td class="right">'.price($solde)."</td>\n";
125
126 // Author
127 print '<td class="nowrap" width="50"><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$objf->userid.'">'.img_object($langs->trans("ShowUser"), 'user').' '.$objf->login.'</a></td>';
128
129 print "</tr>\n";
130
131 // Payments
132 $sql = "SELECT p.rowid, p.datep as dp, pf.amount, p.statut,";
133 $sql .= " p.fk_user_author, u.login, u.rowid as userid";
134 $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf,";
135 $sql .= " ".MAIN_DB_PREFIX."paiementfourn as p";
136 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON p.fk_user_author = u.rowid";
137 $sql .= " WHERE pf.fk_paiementfourn = p.rowid";
138 $sql .= " AND pf.fk_facturefourn = ".((int) $fac->id);
139
140 $resqlp = $db->query($sql);
141 if ($resqlp) {
142 $nump = $db->num_rows($resqlp);
143 $j = 0;
144
145 while ($j < $nump) {
146 $objp = $db->fetch_object($resqlp);
147 //
148 print '<tr class="oddeven">';
149 print '<td class="center">'.dol_print_date($db->jdate($objp->dp))."</td>\n";
150 print '<td>';
151 print '&nbsp; &nbsp; &nbsp; '; // Decalage
152 print '<a href="paiement/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("ShowPayment"), "payment").' '.$langs->trans("Payment").' '.$objp->rowid.'</td>';
153 print "<td>&nbsp;</td>\n";
154 print "<td>&nbsp;</td>\n";
155 print '<td class="right">'.price($objp->amount).'</td>';
156 $solde = $solde - $objp->amount;
157 print '<td class="right">'.price($solde)."</td>\n";
158
159 // Auteur
160 print '<td class="nowrap" width="50"><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$objp->userid.'">'.img_object($langs->trans("ShowUser"), 'user').' '.$objp->login.'</a></td>';
161
162 print '</tr>';
163
164 $j++;
165 }
166
167 $db->free($resqlp);
168 } else {
169 dol_print_error($db);
170 }
171 }
172 } else {
173 dol_print_error($db);
174 }
175
176 print "</table>";
177 }
178} else {
179 dol_print_error($db);
180}
181
182// End of page
183llxFooter();
184$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage suppliers invoices.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.