dolibarr  9.0.0
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 <http://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->societe_id > 0)
36 {
37  $action = '';
38  $socid = $user->societe_id;
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 
52 llxHeader();
53 
54 if ($socid > 0)
55 {
56  $societe = new Societe($db);
57  $societe->fetch($socid);
58 
59  /*
60  * Affichage onglets
61  */
62  $head = societe_prepare_head($societe);
63 
64  dol_fiche_head($head, 'supplier', $langs->trans("ThirdParty"), 0, 'company');
65  dol_banner_tab($societe, 'socid', '', ($user->societe_id?0:1), 'rowid', 'nom');
66  dol_fiche_end();
67 
68  if (! empty($conf->fournisseur->enabled) && $user->rights->facture->lire)
69  {
70  // Invoice list
71  print load_fiche_titre($langs->trans("SupplierPreview"));
72 
73  print '<table class="noborder tagtable liste" width="100%">';
74 
75  $sql = "SELECT s.nom, s.rowid as socid, f.ref_supplier, f.amount, f.datef as df,";
76  $sql.= " f.paye as paye, f.fk_statut as statut, f.rowid as facid,";
77  $sql.= " u.login, u.rowid as userid";
78  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f,".MAIN_DB_PREFIX."user as u";
79  $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$societe->id;
80  $sql.= " AND f.entity IN (".getEntity("facture_fourn").")"; // Reconaissance de l'entité attribuée à cette facture pour Multicompany
81  $sql.= " AND f.fk_user_valid = u.rowid";
82  $sql.= " ORDER BY f.datef DESC";
83 
84  $resql=$db->query($sql);
85  if ($resql)
86  {
87  $num = $db->num_rows($resql);
88 
89  print '<tr class="liste_titre">';
90  print '<td width="100" align="center">'.$langs->trans("Date").'</td>';
91  print '<td>&nbsp;</td>';
92  print '<td>'.$langs->trans("Status").'</td>';
93  print '<td align="right">'.$langs->trans("Debit").'</td>';
94  print '<td align="right">'.$langs->trans("Credit").'</td>';
95  print '<td align="right">'.$langs->trans("Balance").'</td>';
96  print '<td>&nbsp;</td>';
97  print '</tr>';
98 
99  if (! $num > 0)
100  {
101  print '<tr><td colspan="7">'.$langs->trans("NoInvoice").'</td></tr>';
102  }
103 
104  $solde = 0;
105 
106  // Boucle sur chaque facture
107  for ($i = 0 ; $i < $num ; $i++)
108  {
109  $objf = $db->fetch_object($resql);
110 
111  $fac = new FactureFournisseur($db);
112  $ret=$fac->fetch($objf->facid);
113  if ($ret < 0)
114  {
115  print $fac->error."<br>";
116  continue;
117  }
118  $totalpaye = $fac->getSommePaiement();
119 
120  print '<tr class="oddeven">';
121 
122  print "<td align=\"center\">".dol_print_date($fac->date)."</td>\n";
123  print "<td><a href=\"facture/card.php?facid=$fac->id\">".img_object($langs->trans("ShowBill"),"bill")." ".$fac->ref."</a></td>\n";
124 
125  print '<td aling="left">'.$fac->getLibStatut(2,$totalpaye).'</td>';
126  print '<td align="right">'.price($fac->total_ttc)."</td>\n";
127  $solde = $solde + $fac->total_ttc;
128 
129  print '<td align="right">&nbsp;</td>';
130  print '<td align="right">'.price($solde)."</td>\n";
131 
132  // Author
133  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>';
134 
135  print "</tr>\n";
136 
137  // Payments
138  $sql = "SELECT p.rowid, p.datep as dp, pf.amount, p.statut,";
139  $sql.= " p.fk_user_author, u.login, u.rowid as userid";
140  $sql.= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf,";
141  $sql.= " ".MAIN_DB_PREFIX."paiementfourn as p";
142  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON p.fk_user_author = u.rowid";
143  $sql.= " WHERE pf.fk_paiementfourn = p.rowid";
144  $sql.= " AND pf.fk_facturefourn = ".$fac->id;
145 
146  $resqlp = $db->query($sql);
147  if ($resqlp)
148  {
149  $nump = $db->num_rows($resqlp);
150  $j = 0;
151 
152  while ($j < $nump)
153  {
154  $objp = $db->fetch_object($resqlp);
155  //
156  print '<tr class="oddeven">';
157  print '<td align="center">'.dol_print_date($db->jdate($objp->dp))."</td>\n";
158  print '<td>';
159  print '&nbsp; &nbsp; &nbsp; '; // Decalage
160  print '<a href="paiement/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("ShowPayment"),"payment").' '.$langs->trans("Payment").' '.$objp->rowid.'</td>';
161  print "<td>&nbsp;</td>\n";
162  print "<td>&nbsp;</td>\n";
163  print '<td align="right">'.price($objp->amount).'</td>';
164  $solde = $solde - $objp->amount;
165  print '<td align="right">'.price($solde)."</td>\n";
166 
167  // Auteur
168  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>';
169 
170  print '</tr>';
171 
172  $j++;
173  }
174 
175  $db->free($resqlp);
176  }
177  else
178  {
179  dol_print_error($db);
180  }
181  }
182  }
183  else
184  {
185  dol_print_error($db);
186  }
187 
188  print "</table>";
189  }
190 }
191 else
192 {
193  dol_print_error($db);
194 }
195 
196 // End of page
197 llxFooter();
198 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
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.
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
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...)
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:42
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)