dolibarr 21.0.0-beta
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
32
41// Load translation files required by the page
42$langs->loadLangs(array('bills', 'companies'));
43
44// Security check
45$socid = GETPOSTINT("socid");
46if ($user->socid > 0) {
47 $action = '';
48 $socid = $user->socid;
49}
50
51
52// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
53$hookmanager->initHooks(array('supplierbalencelist', 'globalcard'));
54
55/*
56 * View
57 */
58
59$form = new Form($db);
60$userstatic = new User($db);
61
62llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-fourn page-recap-fourn');
63
64if ($socid > 0) {
65 $societe = new Societe($db);
66 $societe->fetch($socid);
67
68 /*
69 * Show tabs
70 */
71 $head = societe_prepare_head($societe);
72
73 print dol_get_fiche_head($head, 'supplier', $langs->trans("ThirdParty"), 0, 'company');
74 dol_banner_tab($societe, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
75 print dol_get_fiche_end();
76
77 if ((isModEnabled("fournisseur") && $user->hasRight("fournisseur", "facture", "lire") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_invoice") && $user->hasRight("supplier_invoice", "lire"))) {
78 // Invoice list
79 print load_fiche_titre($langs->trans("SupplierPreview"));
80
81 print '<table class="noborder tagtable liste centpercent">';
82
83 $sql = "SELECT s.nom, s.rowid as socid, f.ref_supplier, f.datef as df,";
84 $sql .= " f.paye as paye, f.fk_statut as statut, f.rowid as facid,";
85 $sql .= " u.login, u.rowid as userid";
86 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f,".MAIN_DB_PREFIX."user as u";
87 $sql .= " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $societe->id);
88 $sql .= " AND f.entity IN (".getEntity("facture_fourn").")"; // Recognition of the entity attributed to this invoice for Multicompany
89 $sql .= " AND f.fk_user_valid = u.rowid";
90 $sql .= " ORDER BY f.datef DESC";
91
92 $resql = $db->query($sql);
93 if ($resql) {
94 $num = $db->num_rows($resql);
95
96 print '<tr class="liste_titre">';
97 print '<td width="100" class="center">'.$langs->trans("Date").'</td>';
98 print '<td>&nbsp;</td>';
99 print '<td>'.$langs->trans("Status").'</td>';
100 print '<td class="right">'.$langs->trans("Debit").'</td>';
101 print '<td class="right">'.$langs->trans("Credit").'</td>';
102 print '<td class="right">'.$langs->trans("Balance").'</td>';
103 print '<td>&nbsp;</td>';
104 print '</tr>';
105
106 if ($num <= 0) {
107 print '<tr><td colspan="7"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
108 }
109
110 $solde = 0;
111
112 // Boucle sur chaque facture
113 for ($i = 0; $i < $num; $i++) {
114 $objf = $db->fetch_object($resql);
115
116 $fac = new FactureFournisseur($db);
117 $ret = $fac->fetch($objf->facid);
118 if ($ret < 0) {
119 print $fac->error."<br>";
120 continue;
121 }
122 $totalpaid = $fac->getSommePaiement();
123
124 print '<tr class="oddeven">';
125
126 print '<td class="center">'.dol_print_date($fac->date)."</td>\n";
127 print "<td><a href=\"facture/card.php?facid=$fac->id\">".img_object($langs->trans("ShowBill"), "bill")." ".$fac->ref."</a></td>\n";
128
129 print '<td class="left">'.$fac->getLibStatut(2, $totalpaid).'</td>';
130 print '<td class="right">'.price($fac->total_ttc)."</td>\n";
131 $solde += $fac->total_ttc;
132
133 print '<td class="right">&nbsp;</td>';
134 print '<td class="right">'.price($solde)."</td>\n";
135
136 // Author
137 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>';
138
139 print "</tr>\n";
140
141 // Payments
142 $sql = "SELECT p.rowid, p.datep as dp, pf.amount, p.statut,";
143 $sql .= " p.fk_user_author, u.login, u.rowid as userid";
144 $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf,";
145 $sql .= " ".MAIN_DB_PREFIX."paiementfourn as p";
146 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON p.fk_user_author = u.rowid";
147 $sql .= " WHERE pf.fk_paiementfourn = p.rowid";
148 $sql .= " AND pf.fk_facturefourn = ".((int) $fac->id);
149
150 $resqlp = $db->query($sql);
151 if ($resqlp) {
152 $nump = $db->num_rows($resqlp);
153 $j = 0;
154
155 while ($j < $nump) {
156 $objp = $db->fetch_object($resqlp);
157 //
158 print '<tr class="oddeven">';
159 print '<td class="center">'.dol_print_date($db->jdate($objp->dp))."</td>\n";
160 print '<td>';
161 print '&nbsp; &nbsp; &nbsp; '; // Decalage
162 print '<a href="paiement/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("ShowPayment"), "payment").' '.$langs->trans("Payment").' '.$objp->rowid.'</td>';
163 print "<td>&nbsp;</td>\n";
164 print "<td>&nbsp;</td>\n";
165 print '<td class="right">'.price($objp->amount).'</td>';
166 $solde -= $objp->amount;
167 print '<td class="right">'.price($solde)."</td>\n";
168
169 // Auteur
170 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>';
171
172 print '</tr>';
173
174 $j++;
175 }
176
177 $db->free($resqlp);
178 } else {
179 dol_print_error($db);
180 }
181 }
182 } else {
183 dol_print_error($db);
184 }
185
186 print "</table>";
187 }
188} else {
189 dol_print_error($db);
190}
191
192// End of page
193llxFooter();
194$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
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.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.