dolibarr  16.0.5
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 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
29 
30 // Load translation files required by the page
31 $langs->loadLangs(array('bills', 'companies'));
32 
33 // Security check
34 $socid = GETPOST("socid", 'int');
35 if ($user->socid > 0) {
36  $action = '';
37  $socid = $user->socid;
38 }
39 
40 
41 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
42 $hookmanager->initHooks(array('supplierbalencelist', 'globalcard'));
43 
44 /*
45  * View
46  */
47 
48 $form = new Form($db);
49 $userstatic = new User($db);
50 
51 llxHeader();
52 
53 if ($socid > 0) {
54  $societe = new Societe($db);
55  $societe->fetch($socid);
56 
57  /*
58  * Affichage onglets
59  */
60  $head = societe_prepare_head($societe);
61 
62  print dol_get_fiche_head($head, 'supplier', $langs->trans("ThirdParty"), 0, 'company');
63  dol_banner_tab($societe, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
64  print dol_get_fiche_end();
65 
66  if ((!empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (!empty($conf->supplier_invoice->enabled) && $user->rights->supplier_invoice->lire)) {
67  // Invoice list
68  print load_fiche_titre($langs->trans("SupplierPreview"));
69 
70  print '<table class="noborder tagtable liste centpercent">';
71 
72  $sql = "SELECT s.nom, s.rowid as socid, f.ref_supplier, f.datef as df,";
73  $sql .= " f.paye as paye, f.fk_statut as statut, f.rowid as facid,";
74  $sql .= " u.login, u.rowid as userid";
75  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f,".MAIN_DB_PREFIX."user as u";
76  $sql .= " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $societe->id);
77  $sql .= " AND f.entity IN (".getEntity("facture_fourn").")"; // Recognition of the entity attributed to this invoice for Multicompany
78  $sql .= " AND f.fk_user_valid = u.rowid";
79  $sql .= " ORDER BY f.datef DESC";
80 
81  $resql = $db->query($sql);
82  if ($resql) {
83  $num = $db->num_rows($resql);
84 
85  print '<tr class="liste_titre">';
86  print '<td width="100" class="center">'.$langs->trans("Date").'</td>';
87  print '<td>&nbsp;</td>';
88  print '<td>'.$langs->trans("Status").'</td>';
89  print '<td class="right">'.$langs->trans("Debit").'</td>';
90  print '<td class="right">'.$langs->trans("Credit").'</td>';
91  print '<td class="right">'.$langs->trans("Balance").'</td>';
92  print '<td>&nbsp;</td>';
93  print '</tr>';
94 
95  if ($num <= 0) {
96  print '<tr><td colspan="7"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
97  }
98 
99  $solde = 0;
100 
101  // Boucle sur chaque facture
102  for ($i = 0; $i < $num; $i++) {
103  $objf = $db->fetch_object($resql);
104 
105  $fac = new FactureFournisseur($db);
106  $ret = $fac->fetch($objf->facid);
107  if ($ret < 0) {
108  print $fac->error."<br>";
109  continue;
110  }
111  $totalpaid = $fac->getSommePaiement();
112 
113  print '<tr class="oddeven">';
114 
115  print '<td class="center">'.dol_print_date($fac->date)."</td>\n";
116  print "<td><a href=\"facture/card.php?facid=$fac->id\">".img_object($langs->trans("ShowBill"), "bill")." ".$fac->ref."</a></td>\n";
117 
118  print '<td class="left">'.$fac->getLibStatut(2, $totalpaid).'</td>';
119  print '<td class="right">'.price($fac->total_ttc)."</td>\n";
120  $solde = $solde + $fac->total_ttc;
121 
122  print '<td class="right">&nbsp;</td>';
123  print '<td class="right">'.price($solde)."</td>\n";
124 
125  // Author
126  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>';
127 
128  print "</tr>\n";
129 
130  // Payments
131  $sql = "SELECT p.rowid, p.datep as dp, pf.amount, p.statut,";
132  $sql .= " p.fk_user_author, u.login, u.rowid as userid";
133  $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf,";
134  $sql .= " ".MAIN_DB_PREFIX."paiementfourn as p";
135  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON p.fk_user_author = u.rowid";
136  $sql .= " WHERE pf.fk_paiementfourn = p.rowid";
137  $sql .= " AND pf.fk_facturefourn = ".((int) $fac->id);
138 
139  $resqlp = $db->query($sql);
140  if ($resqlp) {
141  $nump = $db->num_rows($resqlp);
142  $j = 0;
143 
144  while ($j < $nump) {
145  $objp = $db->fetch_object($resqlp);
146  //
147  print '<tr class="oddeven">';
148  print '<td class="center">'.dol_print_date($db->jdate($objp->dp))."</td>\n";
149  print '<td>';
150  print '&nbsp; &nbsp; &nbsp; '; // Decalage
151  print '<a href="paiement/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("ShowPayment"), "payment").' '.$langs->trans("Payment").' '.$objp->rowid.'</td>';
152  print "<td>&nbsp;</td>\n";
153  print "<td>&nbsp;</td>\n";
154  print '<td class="right">'.price($objp->amount).'</td>';
155  $solde = $solde - $objp->amount;
156  print '<td class="right">'.price($solde)."</td>\n";
157 
158  // Auteur
159  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>';
160 
161  print '</tr>';
162 
163  $j++;
164  }
165 
166  $db->free($resqlp);
167  } else {
168  dol_print_error($db);
169  }
170  }
171  } else {
172  dol_print_error($db);
173  }
174 
175  print "</table>";
176  }
177 } else {
178  dol_print_error($db);
179 }
180 
181 // End of page
182 llxFooter();
183 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
FactureFournisseur
Class to manage suppliers invoices.
Definition: fournisseur.facture.class.php:53
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_banner_tab
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.
Definition: functions.lib.php:2046
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
societe_prepare_head
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:42
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59