dolibarr  16.0.5
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 <https://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 (GETPOSTISSET("account") || GETPOSTISSET("ref")) {
41  $id = GETPOSTISSET("account") ? GETPOST("account") : (GETPOSTISSET("ref") ? GETPOST("ref") : '');
42 }
43 $fieldid = GETPOSTISSET("ref") ? 'ref' : 'rowid';
44 if ($user->socid) {
45  $socid = $user->socid;
46 }
47 $result = restrictedArea($user, 'banque', $id, 'bank_account&bank_account', '', '', $fieldid);
48 
49 
50 $vline = GETPOST('vline');
51 $page = GETPOSTISSET("page") ? GETPOST("page") : 0;
52 
53 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
54 $hookmanager->initHooks(array('banktreso', 'globalcard'));
55 
56 
57 /*
58  * View
59  */
60 
61 $title = $langs->trans("FinancialAccount").' - '.$langs->trans("PlannedTransactions");
62 $helpurl = "";
63 llxHeader('', $title, $helpurl);
64 
65 $societestatic = new Societe($db);
66 $facturestatic = new Facture($db);
67 $facturefournstatic = new FactureFournisseur($db);
68 $socialcontribstatic = new ChargeSociales($db);
69 
70 $form = new Form($db);
71 
72 if (GETPOST("account") || GETPOST("ref")) {
73  if ($vline) {
74  $viewline = $vline;
75  } else {
76  $viewline = 20;
77  }
78 
79  $object = new Account($db);
80  if (GETPOST("account", 'int')) {
81  $result = $object->fetch(GETPOST("account", 'int'));
82  }
83  if (GETPOST("ref")) {
84  $result = $object->fetch(0, GETPOST("ref"));
85  $_GET["account"] = $object->id;
86  }
87 
88 
89  // Onglets
90  $head = bank_prepare_head($object);
91  print dol_get_fiche_head($head, 'cash', $langs->trans("FinancialAccount"), 0, 'account');
92 
93  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
94 
95  $morehtmlref = '';
96 
97  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
98 
99  print dol_get_fiche_end();
100 
101 
102  // Remainder to pay in future
103  $sqls = array();
104 
105  // Customer invoices
106  $sql = "SELECT 'invoice' as family, f.rowid as objid, f.ref as ref, f.total_ttc, f.type, f.date_lim_reglement as dlr,";
107  $sql .= " s.rowid as socid, s.nom as name, s.fournisseur";
108  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
109  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
110  $sql .= " WHERE f.entity IN (".getEntity('invoice').")";
111  $sql .= " AND f.paye = 0 AND f.fk_statut = 1"; // Not paid
112  $sql .= " AND (f.fk_account IN (0, ".$object->id.") OR f.fk_account IS NULL)"; // Id bank account of invoice
113  $sql .= " ORDER BY dlr ASC";
114  $sqls[] = $sql;
115 
116  // Supplier invoices
117  $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,";
118  $sql .= " s.rowid as socid, s.nom as name, s.fournisseur";
119  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as ff";
120  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON ff.fk_soc = s.rowid";
121  $sql .= " WHERE ff.entity = ".$conf->entity;
122  $sql .= " AND ff.paye = 0 AND fk_statut = 1"; // Not paid
123  $sql .= " AND (ff.fk_account IN (0, ".$object->id.") OR ff.fk_account IS NULL)"; // Id bank account of supplier invoice
124  $sql .= " ORDER BY dlr ASC";
125  $sqls[] = $sql;
126 
127  // Social contributions
128  $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,";
129  $sql .= " 0 as socid, 'noname' as name, 0 as fournisseur";
130  $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as cs";
131  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as ccs ON cs.fk_type = ccs.id";
132  $sql .= " WHERE cs.entity = ".$conf->entity;
133  $sql .= " AND cs.paye = 0"; // Not paid
134  $sql .= " AND (cs.fk_account IN (0, ".$object->id.") OR cs.fk_account IS NULL)"; // Id bank account of social contribution
135  $sql .= " ORDER BY dlr ASC";
136  $sqls[] = $sql;
137 
138  // others sql
139  $parameters = array();
140  $reshook = $hookmanager->executeHooks('addMoreSQL', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
141  if (empty($reshook) and isset($hookmanager->resArray['sql'])) {
142  $sqls[] = $hookmanager->resArray['sql'];
143  }
144 
145  $error = 0;
146  $tab_sqlobjOrder = array();
147  $tab_sqlobj = array();
148  $nbtotalofrecords = 0;
149 
150  foreach ($sqls as $sql) {
151  $resql = $db->query($sql);
152  if ($resql) {
153  $nbtotalofrecords += $db->num_rows($resql);
154  while ($sqlobj = $db->fetch_object($resql)) {
155  $tmpobj = new stdClass();
156  $tmpobj->family = $sqlobj->family;
157  $tmpobj->objid = $sqlobj->objid;
158  $tmpobj->ref = $sqlobj->ref;
159  $tmpobj->total_ttc = $sqlobj->total_ttc;
160  $tmpobj->type = $sqlobj->type;
161  $tmpobj->dlr = $db->jdate($sqlobj->dlr);
162  $tmpobj->socid = $sqlobj->socid;
163  $tmpobj->name = $sqlobj->name;
164  $tmpobj->fournisseur = $sqlobj->fournisseur;
165 
166  $tab_sqlobj[] = $tmpobj;
167  $tab_sqlobjOrder[] = $db->jdate($sqlobj->dlr);
168  }
169  $db->free($resql);
170  } else {
171  $error++;
172  }
173  }
174 
175  $param = '';
176  $sortfield = '';
177  $sortorder = '';
178  $massactionbutton = '';
179  $num = 0;
180  $picto = '';
181  $morehtml = '';
182  $limit = 0;
183 
184  print_barre_liste($langs->trans("RemainderToPay"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $morehtml, '', $limit, 0, 0, 1);
185 
186 
187  $solde = $object->solde(0);
188  if (getDolGlobalInt('MULTICOMPANY_INVOICE_SHARING_ENABLED')) {
189  $colspan = 6;
190  } else {
191  $colspan = 5;
192  }
193 
194  // Show next coming entries
195  print '<div class="div-table-responsive">';
196  print '<table class="noborder centpercent">';
197 
198  // Ligne de titre tableau des ecritures
199  print '<tr class="liste_titre">';
200  print '<td>'.$langs->trans("DateDue").'</td>';
201  print '<td>'.$langs->trans("Description").'</td>';
202  if (getDolGlobalInt('MULTICOMPANY_INVOICE_SHARING_ENABLED')) {
203  print '<td>'.$langs->trans("Entity").'</td>';
204  }
205  print '<td>'.$langs->trans("ThirdParty").'</td>';
206  print '<td class="right">'.$langs->trans("Debit").'</td>';
207  print '<td class="right">'.$langs->trans("Credit").'</td>';
208  print '<td class="right" width="80">'.$langs->trans("BankBalance").'</td>';
209  print '</tr>';
210 
211  // Current balance
212  print '<tr class="liste_total">';
213  print '<td class="left" colspan="5">'.$langs->trans("CurrentBalance").'</td>';
214  print '<td class="nowrap right">'.price($solde).'</td>';
215  print '</tr>';
216 
217  // Sort array
218  if (!$error) {
219  array_multisort($tab_sqlobjOrder, $tab_sqlobj);
220 
221  $num = count($tab_sqlobj);
222 
223  $i = 0;
224  while ($i < $num) {
225  $ref = '';
226  $refcomp = '';
227  $totalpayment = '';
228 
229  $tmpobj = array_shift($tab_sqlobj);
230 
231  if ($tmpobj->family == 'invoice_supplier') {
232  $showline = 1;
233  // Uncomment this line to avoid to count suppliers credit note (ff.type = 2)
234  //$showline=(($tmpobj->total_ttc < 0 && $tmpobj->type != 2) || ($tmpobj->total_ttc > 0 && $tmpobj->type == 2))
235  if ($showline) {
236  $ref = $tmpobj->ref;
237  $facturefournstatic->ref = $ref;
238  $facturefournstatic->id = $tmpobj->objid;
239  $facturefournstatic->type = $tmpobj->type;
240  $ref = $facturefournstatic->getNomUrl(1, '');
241 
242  $societestatic->id = $tmpobj->socid;
243  $societestatic->name = $tmpobj->name;
244  $refcomp = $societestatic->getNomUrl(1, '', 24);
245 
246  $totalpayment = -1 * $facturefournstatic->getSommePaiement(); // Payment already done
247  }
248  }
249  if ($tmpobj->family == 'invoice') {
250  $facturestatic->ref = $tmpobj->ref;
251  $facturestatic->id = $tmpobj->objid;
252  $facturestatic->type = $tmpobj->type;
253  $ref = $facturestatic->getNomUrl(1, '');
254 
255  $societestatic->id = $tmpobj->socid;
256  $societestatic->name = $tmpobj->name;
257  $refcomp = $societestatic->getNomUrl(1, '', 24);
258 
259  $totalpayment = $facturestatic->getSommePaiement(); // Payment already done
260  $totalpayment += $facturestatic->getSumDepositsUsed();
261  $totalpayment += $facturestatic->getSumCreditNotesUsed();
262  }
263  if ($tmpobj->family == 'social_contribution') {
264  $socialcontribstatic->ref = $tmpobj->ref;
265  $socialcontribstatic->id = $tmpobj->objid;
266  $socialcontribstatic->label = $tmpobj->type;
267  $ref = $socialcontribstatic->getNomUrl(1, 24);
268 
269  $totalpayment = -1 * $socialcontribstatic->getSommePaiement(); // Payment already done
270  }
271 
272  $parameters = array('obj' => $tmpobj, 'ref' => $ref, 'refcomp' => $refcomp, 'totalpayment' => $totalpayment);
273  $reshook = $hookmanager->executeHooks('moreFamily', $parameters, $tmpobject, $action); // Note that $action and $tmpobject may have been modified by hook
274  if (empty($reshook)) {
275  $ref = isset($hookmanager->resArray['ref']) ? $hookmanager->resArray['ref'] : $ref;
276  $refcomp = isset($hookmanager->resArray['refcomp']) ? $hookmanager->resArray['refcomp'] : $refcomp;
277  $totalpayment = isset($hookmanager->resArray['totalpayment']) ? $hookmanager->resArray['totalpayment'] : $totalpayment;
278  }
279 
280  $total_ttc = $tmpobj->total_ttc;
281  if ($totalpayment) {
282  $total_ttc = $tmpobj->total_ttc - $totalpayment;
283  }
284  $solde += $total_ttc;
285 
286  // We discard lines with a remainder to pay to 0
287  if (price2num($total_ttc) != 0) {
288  // Show line
289  print '<tr class="oddeven">';
290  print '<td>';
291  if ($tmpobj->dlr) {
292  print dol_print_date($tmpobj->dlr, "day");
293  } else {
294  print $langs->trans("NotDefined");
295  }
296  print "</td>";
297  print "<td>".$ref."</td>";
298  if ($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED) {
299  if ($tmpobj->family == 'invoice') {
300  $mc->getInfo($tmpobj->entity);
301  print "<td>".$mc->label."</td>";
302  } else {
303  print "<td></td>";
304  }
305  }
306  print "<td>".$refcomp."</td>";
307  if ($tmpobj->total_ttc < 0) {
308  print '<td class="nowrap right">'.price(abs($total_ttc))."</td><td>&nbsp;</td>";
309  };
310  if ($tmpobj->total_ttc >= 0) {
311  print '<td>&nbsp;</td><td class="nowrap right">'.price($total_ttc)."</td>";
312  };
313  print '<td class="nowrap right">'.price($solde).'</td>';
314  print "</tr>";
315  }
316 
317  $i++;
318  }
319  } else {
320  dol_print_error($db);
321  }
322 
323  // Other lines
324  $parameters = array('solde' => $solde);
325  $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
326  if (empty($reshook)) {
327  print $hookmanager->resPrint;
328  $solde = isset($hookmanager->resArray['solde']) ? $hookmanager->resArray['solde'] : $solde;
329  }
330 
331  // solde
332  print '<tr class="liste_total">';
333  print '<td class="left" colspan="'.$colspan.'">'.$langs->trans("FutureBalance").' ('.$object->currency_code.')</td>';
334  print '<td class="nowrap right">'.price($solde, 0, $langs, 0, 0, -1, $object->currency_code).'</td>';
335  print '</tr>';
336 
337  print "</table>";
338  print "</div>";
339 } else {
340  print $langs->trans("ErrorBankAccountNotFound");
341 }
342 
343 // End of page
344 llxFooter();
345 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
ChargeSociales
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
Definition: chargesociales.class.php:34
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
Facture
Class to manage invoices.
Definition: facture.class.php:60
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
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
bank_prepare_head
bank_prepare_head(Account $object)
Prepare array with list of tabs.
Definition: bank.lib.php:37
print_barre_liste
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
Definition: functions.lib.php:5257
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
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$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
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:93
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
Account
Class to manage bank accounts.
Definition: account.class.php:38