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