dolibarr  19.0.0-dev
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2005-2020 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
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 
29 // Load Dolibarr environment
30 require '../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array('banks', 'categories', 'withdrawals'));
39 
40 // Security check
41 $socid = GETPOST('socid', 'int');
42 if ($user->socid) {
43  $socid = $user->socid;
44 }
45 $result = restrictedArea($user, 'paymentbybanktransfer', '', '');
46 
47 $usercancreate = $user->rights->paymentbybanktransfer->create;
48 
49 
50 /*
51  * Actions
52  */
53 
54 // None
55 
56 
57 /*
58  * View
59  */
60 
61 llxHeader('', $langs->trans("SuppliersStandingOrdersArea"));
62 
63 if (prelevement_check_config('bank-transfer') < 0) {
64  $langs->load("errors");
65  setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("PaymentByBankTransfer")), null, 'errors');
66 }
67 
68 $newcardbutton = '';
69 if ($usercancreate) {
70  $newcardbutton .= dolGetButtonTitle($langs->trans('NewPaymentByBankTransfer'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type=bank-transfer');
71 }
72 
73 print load_fiche_titre($langs->trans("SuppliersStandingOrdersArea"), $newcardbutton);
74 
75 
76 print '<div class="fichecenter"><div class="fichethirdleft">';
77 
78 
79 $thirdpartystatic = new Societe($db);
80 $invoicestatic = new FactureFournisseur($db);
81 $bprev = new BonPrelevement($db);
82 
83 print '<div class="div-table-responsive-no-min">';
84 print '<table class="noborder centpercent">';
85 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
86 
87 print '<tr class="oddeven"><td>'.$langs->trans("NbOfInvoiceToPayByBankTransfer").'</td>';
88 print '<td class="right">';
89 print '<a class="badge badge-info" href="'.DOL_URL_ROOT.'/compta/prelevement/demandes.php?status=0&type=bank-transfer">';
90 print $bprev->nbOfInvoiceToPay('bank-transfer');
91 print '</a>';
92 print '</td></tr>';
93 
94 print '<tr class="oddeven"><td>'.$langs->trans("AmountToTransfer").'</td>';
95 print '<td class="right"><span class="amount nowraponall">';
96 print price($bprev->SommeAPrelever('bank-transfer'), '', '', 1, -1, -1, 'auto');
97 print '</span></td></tr></table></div><br>';
98 
99 
100 
101 /*
102  * Invoices waiting for withdraw
103  */
104 $sql = "SELECT f.ref, f.rowid, f.total_ttc, f.fk_statut, f.paye, f.type, f.datef, f.date_lim_reglement,";
105 $sql .= " pfd.date_demande, pfd.amount,";
106 $sql .= " s.nom as name, s.email, s.rowid as socid, s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6";
107 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
108 $sql .= " ".MAIN_DB_PREFIX."societe as s";
109 if (empty($user->rights->societe->client->voir) && !$socid) {
110  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
111 }
112 $sql .= ", ".MAIN_DB_PREFIX."prelevement_demande as pfd";
113 $sql .= " WHERE s.rowid = f.fk_soc";
114 $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
115 $sql .= " AND f.total_ttc > 0";
116 if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
117  $sql .= " AND f.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
118 }
119 $sql .= " AND pfd.traite = 0";
120 $sql .= " AND pfd.ext_payment_id IS NULL";
121 $sql .= " AND pfd.fk_facture_fourn = f.rowid";
122 if (empty($user->rights->societe->client->voir) && !$socid) {
123  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
124 }
125 if ($socid) {
126  $sql .= " AND f.fk_soc = ".((int) $socid);
127 }
128 
129 $resql = $db->query($sql);
130 if ($resql) {
131  $num = $db->num_rows($resql);
132  $i = 0;
133 
134  print '<div class="div-table-responsive-no-min">';
135  print '<table class="noborder centpercent">';
136  print '<tr class="liste_titre">';
137  print '<th colspan="5">'.$langs->trans("SupplierInvoiceWaitingWithdraw").' <span class="opacitymedium">('.$num.')</span></th></tr>';
138  if ($num) {
139  while ($i < $num && $i < 20) {
140  $obj = $db->fetch_object($resql);
141 
142  $invoicestatic->id = $obj->rowid;
143  $invoicestatic->ref = $obj->ref;
144  $invoicestatic->status = $obj->fk_statut;
145  $invoicestatic->statut = $obj->fk_statut; // For backward comaptibility
146  $invoicestatic->paye = $obj->paye;
147  $invoicestatic->type = $obj->type;
148  $invoicestatic->date = $db->jdate($obj->datef);
149  $invoicestatic->date_echeance = $db->jdate($obj->date_lim_reglement);
150  $invoicestatic->total_ttc = $obj->total_ttc;
151  $alreadypayed = $invoicestatic->getSommePaiement();
152 
153  $thirdpartystatic->id = $obj->socid;
154  $thirdpartystatic->name = $obj->name;
155  $thirdpartystatic->email = $obj->email;
156  $thirdpartystatic->tva_intra = $obj->tva_intra;
157  $thirdpartystatic->siren = $obj->idprof1;
158  $thirdpartystatic->siret = $obj->idprof2;
159  $thirdpartystatic->ape = $obj->idprof3;
160  $thirdpartystatic->idprof1 = $obj->idprof1;
161  $thirdpartystatic->idprof2 = $obj->idprof2;
162  $thirdpartystatic->idprof3 = $obj->idprof3;
163  $thirdpartystatic->idprof4 = $obj->idprof4;
164  $thirdpartystatic->idprof5 = $obj->idprof5;
165  $thirdpartystatic->idprof6 = $obj->idprof6;
166 
167  print '<tr class="oddeven"><td class="nowraponall">';
168  print $invoicestatic->getNomUrl(1, 'withdraw');
169  print '</td>';
170 
171  print '<td class="tdoverflowmax150">';
172  print $thirdpartystatic->getNomUrl(1, 'supplier');
173  print '</td>';
174 
175  print '<td class="right">';
176  print '<span class="amount">'.price($obj->amount).'</span>';
177  print '</td>';
178 
179  print '<td class="right">';
180  print dol_print_date($db->jdate($obj->date_demande), 'day');
181  print '</td>';
182 
183  print '<td class="right">';
184  print $invoicestatic->getLibStatut(3, $alreadypayed);
185  print '</td>';
186  print '</tr>';
187  $i++;
188  }
189  } else {
190  $titlefortab = $langs->transnoentitiesnoconv("BankTransfer");
191  print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("NoSupplierInvoiceToWithdraw", $titlefortab, $titlefortab).'</span></td></tr>';
192  }
193  print "</table></div><br>";
194 } else {
195  dol_print_error($db);
196 }
197 
198 
199 print '</div><div class="fichetwothirdright">';
200 
201 
202 /*
203  * Withdraw receipts
204  */
205 
206 $limit = 5;
207 $sql = "SELECT p.rowid, p.ref, p.amount, p.datec, p.statut";
208 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
209 $sql .= " WHERE p.type = 'bank-transfer'";
210 $sql .= " AND p.entity IN (".getEntity('invoice').")";
211 $sql .= " ORDER BY datec DESC";
212 $sql .= $db->plimit($limit);
213 
214 $result = $db->query($sql);
215 if ($result) {
216  $num = $db->num_rows($result);
217  $i = 0;
218 
219  print"\n<!-- debut table -->\n";
220  print '<div class="div-table-responsive-no-min">';
221  print '<table class="noborder centpercent">';
222  print '<tr class="liste_titre">';
223  print '<th>'.$langs->trans("LatestBankTransferReceipts", $limit).'</th>';
224  print '<th>'.$langs->trans("Date").'</th>';
225  print '<th class="right">'.$langs->trans("Amount").'</th>';
226  print '<th class="right">'.$langs->trans("Status").'</th>';
227  print '</tr>';
228 
229  if ($num > 0) {
230  while ($i < min($num, $limit)) {
231  $obj = $db->fetch_object($result);
232 
233  print '<tr class="oddeven">';
234 
235  print '<td class="nowraponall">';
236  $bprev->id = $obj->rowid;
237  $bprev->ref = $obj->ref;
238  $bprev->statut = $obj->statut;
239  print $bprev->getNomUrl(1);
240  print "</td>\n";
241  print '<td>'.dol_print_date($db->jdate($obj->datec), "dayhour")."</td>\n";
242  print '<td class="right nowraponall"><span class="amount">'.price($obj->amount)."</span></td>\n";
243  print '<td class="right"><span class="amount">'.$bprev->getLibStatut(3)."</span></td>\n";
244 
245  print "</tr>\n";
246  $i++;
247  }
248  } else {
249  print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
250  }
251 
252  print "</table></div><br>";
253  $db->free($result);
254 } else {
255  dol_print_error($db);
256 }
257 
258 
259 print '</div></div>';
260 
261 // End of page
262 llxFooter();
263 $db->close();
Class to manage withdrawal receipts.
Class to manage suppliers invoices.
Class to manage third parties objects (customers, suppliers, prospects...)
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
prelevement_check_config($type='direct-debit')
Check need data to create standigns orders receipt file.
llxFooter()
Footer empty.
Definition: index.php:71
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
restrictedArea(User $user, $features, $object=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.