dolibarr  9.0.0
treso.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
3  * Copyright (C) 2008-2009 Laurent Destailleur (Eldy) <eldy@users.sourceforge.net>
4  * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
5  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com
6  * Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
20  */
21 
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array('banks', 'categories', 'bills', 'companies'));
38 
39 // Security check
40 if (isset($_GET["account"]) || isset($_GET["ref"]))
41 {
42  $id = isset($_GET["account"])?$_GET["account"]:(isset($_GET["ref"])?$_GET["ref"]:'');
43 }
44 $fieldid = isset($_GET["ref"])?'ref':'rowid';
45 if ($user->societe_id) $socid=$user->societe_id;
46 $result=restrictedArea($user,'banque',$id,'bank_account&bank_account','','',$fieldid);
47 
48 
49 $vline=isset($_GET["vline"])?$_GET["vline"]:$_POST["vline"];
50 $page=isset($_GET["page"])?$_GET["page"]:0;
51 
52 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
53 $hookmanager->initHooks(array('banktreso','globalcard'));
54 
55 /*
56  * View
57  */
58 
59 $title = $langs->trans("FinancialAccount").' - '.$langs->trans("PlannedTransactions");
60 $helpurl = "";
61 llxHeader('',$title,$helpurl);
62 
63 $societestatic = new Societe($db);
64 $facturestatic=new Facture($db);
65 $facturefournstatic=new FactureFournisseur($db);
66 $socialcontribstatic=new ChargeSociales($db);
67 
68 $form = new Form($db);
69 
70 if ($_REQUEST["account"] || $_REQUEST["ref"])
71 {
72  if ($vline)
73  {
74  $viewline = $vline;
75  }
76  else
77  {
78  $viewline = 20;
79  }
80 
81  $object = new Account($db);
82  if ($_GET["account"])
83  {
84  $result=$object->fetch($_GET["account"]);
85  }
86  if ($_GET["ref"])
87  {
88  $result=$object->fetch(0,$_GET["ref"]);
89  $_GET["account"]=$object->id;
90  }
91 
92 
93  // Onglets
94  $head=bank_prepare_head($object);
95  dol_fiche_head($head, 'cash', $langs->trans("FinancialAccount"), 0, 'account');
96 
97  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
98 
99  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
100 
101  dol_fiche_end();
102 
103  print '<br>';
104 
105  $solde = $object->solde(0);
106 
107  // Show next coming entries
108  print '<div class="div-table-responsive">';
109  print '<table class="noborder centpercent">';
110 
111  // Ligne de titre tableau des ecritures
112  print '<tr class="liste_titre">';
113  print '<td>'.$langs->trans("DateDue").'</td>';
114  print '<td>'.$langs->trans("Description").'</td>';
115  print '<td>'.$langs->trans("ThirdParty").'</td>';
116  print '<td align="right">'.$langs->trans("Debit").'</td>';
117  print '<td align="right">'.$langs->trans("Credit").'</td>';
118  print '<td align="right">'.$langs->trans("BankBalance").'</td>';
119  print '</tr>';
120 
121  // Current balance
122  print '<tr class="liste_total">';
123  print '<td align="left" colspan="5">'.$langs->trans("CurrentBalance").'</td>';
124  print '<td align="right" class="nowrap">'.price($solde).'</td>';
125  print '</tr>';
126 
127 
128  print '<tr class="liste_titre">';
129  print '<td align="left" colspan="5">'.$langs->trans("RemainderToPay").'</td>';
130  print '<td align="right" class="nowrap">&nbsp;</td>';
131  print '</tr>';
132 
133 
134  // Remainder to pay in future
135  $sqls = array();
136 
137  // Customer invoices
138  $sql = "SELECT 'invoice' as family, f.rowid as objid, f.facnumber as ref, f.total_ttc, f.type, f.date_lim_reglement as dlr,";
139  $sql.= " s.rowid as socid, s.nom as name, s.fournisseur";
140  $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
141  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
142  $sql.= " WHERE f.entity = ".$conf->entity;
143  $sql.= " AND f.paye = 0 AND f.fk_statut = 1"; // Not paid
144  $sql.= " AND (f.fk_account IN (0, ".$object->id.") OR f.fk_account IS NULL)"; // Id bank account of invoice
145  $sql.= " ORDER BY dlr ASC";
146  $sqls[] = $sql;
147 
148  // Supplier invoices
149  $sql = " SELECT 'invoice_supplier' as family, ff.rowid as objid, ff.ref as ref, ff.ref_supplier as ref_supplier, (-1*ff.total_ttc) as total_ttc, ff.type, ff.date_lim_reglement as dlr,";
150  $sql.= " s.rowid as socid, s.nom as name, s.fournisseur";
151  $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as ff";
152  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON ff.fk_soc = s.rowid";
153  $sql.= " WHERE ff.entity = ".$conf->entity;
154  $sql.= " AND ff.paye = 0 AND fk_statut = 1"; // Not paid
155  $sql.= " AND (ff.fk_account IN (0, ".$object->id.") OR ff.fk_account IS NULL)"; // Id bank account of supplier invoice
156  $sql.= " ORDER BY dlr ASC";
157  $sqls[] = $sql;
158 
159  // Social contributions
160  $sql = " SELECT 'social_contribution' as family, cs.rowid as objid, cs.libelle as ref, (-1*cs.amount) as total_ttc, ccs.libelle as type, cs.date_ech as dlr";
161  $sql.= ", cs.fk_account";
162  $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as cs";
163  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as ccs ON cs.fk_type = ccs.id";
164  $sql.= " WHERE cs.entity = ".$conf->entity;
165  $sql.= " AND cs.paye = 0"; // Not paid
166  $sql.= " AND (cs.fk_account IN (0, ".$object->id.") OR cs.fk_account IS NULL)"; // Id bank account of social contribution
167  $sql.= " ORDER BY dlr ASC";
168  $sqls[] = $sql;
169 
170  // others sql
171  $parameters = array();
172  $reshook = $hookmanager->executeHooks('addMoreSQL', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
173  if(empty($reshook) and isset($hookmanager->resArray['sql'])){
174  $sqls[] = $hookmanager->resArray['sql'];
175  }
176 
177  $error=0;
178  $tab_sqlobjOrder=array();
179  $tab_sqlobj=array();
180 
181  foreach($sqls as $sql){
182  $resql = $db->query($sql);
183  if($resql){
184  while($sqlobj = $db->fetch_object($resql)){
185  $tab_sqlobj[] = $sqlobj;
186  $tab_sqlobjOrder[]= $db->jdate($sqlobj->dlr);
187  }
188  $db->free($resql);
189  }else{
190  $error++;
191  }
192  }
193 
194  // Sort array
195  if (! $error)
196  {
197  array_multisort($tab_sqlobjOrder,$tab_sqlobj);
198 
199  // Apply distinct filter
200  foreach ($tab_sqlobj as $key=>$value) {
201  $tab_sqlobj[$key] = "'" . serialize($value) . "'";
202  }
203  $tab_sqlobj = array_unique($tab_sqlobj);
204  foreach ($tab_sqlobj as $key=>$value) {
205  $tab_sqlobj[$key] = unserialize(trim($value, "'"));
206  }
207 
208  $num = count($tab_sqlobj);
209 
210  $i = 0;
211  while ($i < $num)
212  {
213  $paiement = '';
214  $ref = '';
215  $refcomp = '';
216 
217  $obj = array_shift($tab_sqlobj);
218 
219  if ($obj->family == 'invoice_supplier')
220  {
221  $showline=1;
222  // Uncomment this line to avoid to count suppliers credit note (ff.type = 2)
223  //$showline=(($obj->total_ttc < 0 && $obj->type != 2) || ($obj->total_ttc > 0 && $obj->type == 2))
224  if ($showline)
225  {
226  $ref=$obj->ref;
227  $facturefournstatic->ref=$ref;
228  $facturefournstatic->id=$obj->objid;
229  $facturefournstatic->type=$obj->type;
230  $ref = $facturefournstatic->getNomUrl(1,'');
231 
232  $societestatic->id = $obj->socid;
233  $societestatic->name = $obj->name;
234  $refcomp=$societestatic->getNomUrl(1,'',24);
235 
236  $paiement = -1*$facturefournstatic->getSommePaiement(); // Payment already done
237  }
238  }
239  if ($obj->family == 'invoice')
240  {
241  $facturestatic->ref=$obj->ref;
242  $facturestatic->id=$obj->objid;
243  $facturestatic->type=$obj->type;
244  $ref = $facturestatic->getNomUrl(1,'');
245 
246  $societestatic->id = $obj->socid;
247  $societestatic->name = $obj->name;
248  $refcomp=$societestatic->getNomUrl(1,'',24);
249 
250  $paiement = $facturestatic->getSommePaiement(); // Payment already done
251  $paiement+= $facturestatic->getSumDepositsUsed();
252  $paiement+= $facturestatic->getSumCreditNotesUsed();
253  }
254  if ($obj->family == 'social_contribution')
255  {
256  $socialcontribstatic->ref=$obj->ref;
257  $socialcontribstatic->id=$obj->objid;
258  $socialcontribstatic->lib=$obj->type;
259  $ref = $socialcontribstatic->getNomUrl(1,24);
260 
261  $paiement = -1*$socialcontribstatic->getSommePaiement(); // Payment already done
262  }
263 
264  $parameters = array('obj' => $obj);
265  $reshook = $hookmanager->executeHooks('moreFamily', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
266  if(empty($reshook)){
267  $ref = isset($hookmanager->resArray['ref']) ? $hookmanager->resArray['ref'] : '';
268  $refcomp = isset($hookmanager->resArray['refcomp']) ? $hookmanager->resArray['refcomp'] : '';
269  $paiement = isset($hookmanager->resArray['paiement']) ? $hookmanager->resArray['paiement'] : 0;
270  }
271 
272  $total_ttc = $obj->total_ttc;
273  if ($paiement) $total_ttc = $obj->total_ttc - $paiement;
274  $solde += $total_ttc;
275 
276  // We discard lines with a remainder to pay to 0
277  if (price2num($total_ttc) != 0)
278  {
279  // Show line
280  print '<tr class="oddeven">';
281  print '<td>';
282  if ($obj->dlr) print dol_print_date($db->jdate($obj->dlr),"day");
283  else print $langs->trans("NotDefined");
284  print "</td>";
285  print "<td>".$ref."</td>";
286  print "<td>".$refcomp."</td>";
287  if ($obj->total_ttc < 0) { print "<td align=\"right\">".price(abs($total_ttc))."</td><td>&nbsp;</td>"; };
288  if ($obj->total_ttc >= 0) { print "<td>&nbsp;</td><td align=\"right\">".price($total_ttc)."</td>"; };
289  print '<td align="right">'.price($solde).'</td>';
290  print "</tr>";
291  }
292 
293  $i++;
294  }
295  }
296  else
297  {
298  dol_print_error($db);
299  }
300 
301  // Other lines
302  $parameters = array('solde' => $solde);
303  $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
304  if(empty($reshook)){
305  print $hookmanager->resPrint;
306  $solde = isset($hookmanager->resArray['solde']) ? $hookmanager->resArray['solde'] : $solde;
307  }
308 
309  // solde
310  print '<tr class="liste_total">';
311  print '<td align="left" colspan="5">'.$langs->trans("FutureBalance").' ('.$object->currency_code.')</td>';
312  print '<td align="right" class="nowrap">'.price($solde, 0, $langs, 0, 0, -1, $object->currency_code).'</td>';
313  print '</tr>';
314 
315  print "</table>";
316  print "</div>";
317 }
318 else
319 {
320  print $langs->trans("ErrorBankAccountNotFound");
321 }
322 
323 // End of page
324 llxFooter();
325 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
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
bank_prepare_head(Account $object)
Prepare array with list of tabs.
Definition: bank.lib.php:34
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.
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 bank accounts.
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
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
Class to manage invoices.
Classe permettant la gestion des paiements des charges La tva collectee n&#39;est calculee que sur les fa...
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.