dolibarr  16.0.5
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 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.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', 'withdrawals'));
38 
39 // Security check
40 $socid = GETPOST('socid', 'int');
41 if ($user->socid) {
42  $socid = $user->socid;
43 }
44 $result = restrictedArea($user, 'paymentbybanktransfer', '', '');
45 
46 $usercancreate = $user->rights->paymentbybanktransfer->create;
47 
48 
49 /*
50  * Actions
51  */
52 
53 // None
54 
55 
56 /*
57  * View
58  */
59 
60 llxHeader('', $langs->trans("SuppliersStandingOrdersArea"));
61 
62 if (prelevement_check_config('bank-transfer') < 0) {
63  $langs->load("errors");
64  setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("PaymentByBankTransfer")), null, 'errors');
65 }
66 
67 $newcardbutton = '';
68 if ($usercancreate) {
69  $newcardbutton .= dolGetButtonTitle($langs->trans('NewPaymentByBankTransfer'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type=bank-transfer');
70 }
71 
72 print load_fiche_titre($langs->trans("SuppliersStandingOrdersArea"), $newcardbutton);
73 
74 
75 print '<div class="fichecenter"><div class="fichethirdleft">';
76 
77 
78 $thirdpartystatic = new Societe($db);
79 $invoicestatic = new FactureFournisseur($db);
80 $bprev = new BonPrelevement($db);
81 
82 print '<div class="div-table-responsive-no-min">';
83 print '<table class="noborder centpercent">';
84 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
85 
86 print '<tr class="oddeven"><td>'.$langs->trans("NbOfInvoiceToPayByBankTransfer").'</td>';
87 print '<td class="right">';
88 print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/demandes.php?status=0&type=bank-transfer">';
89 print $bprev->nbOfInvoiceToPay('bank-transfer');
90 print '</a>';
91 print '</td></tr>';
92 
93 print '<tr class="oddeven"><td>'.$langs->trans("AmountToTransfer").'</td>';
94 print '<td class="right"><span class="amount">';
95 print price($bprev->SommeAPrelever('bank-transfer'), '', '', 1, -1, -1, 'auto');
96 print '</span></td></tr></table></div><br>';
97 
98 
99 
100 /*
101  * Invoices waiting for withdraw
102  */
103 $sql = "SELECT f.ref, f.rowid, f.total_ttc, f.fk_statut, f.paye, f.type,";
104 $sql .= " pfd.date_demande, pfd.amount,";
105 $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";
106 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
107 $sql .= " ".MAIN_DB_PREFIX."societe as s";
108 if (empty($user->rights->societe->client->voir) && !$socid) {
109  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
110 }
111 $sql .= ", ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
112 $sql .= " WHERE s.rowid = f.fk_soc";
113 $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
114 $sql .= " AND f.total_ttc > 0";
115 if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
116  $sql .= " AND f.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
117 }
118 $sql .= " AND pfd.traite = 0";
119 $sql .= " AND pfd.ext_payment_id IS NULL";
120 $sql .= " AND pfd.fk_facture_fourn = f.rowid";
121 if (empty($user->rights->societe->client->voir) && !$socid) {
122  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
123 }
124 if ($socid) {
125  $sql .= " AND f.fk_soc = ".((int) $socid);
126 }
127 
128 $resql = $db->query($sql);
129 if ($resql) {
130  $num = $db->num_rows($resql);
131  $i = 0;
132 
133  print '<div class="div-table-responsive-no-min">';
134  print '<table class="noborder centpercent">';
135  print '<tr class="liste_titre">';
136  print '<th colspan="5">'.$langs->trans("SupplierInvoiceWaitingWithdraw").' ('.$num.')</th></tr>';
137  if ($num) {
138  while ($i < $num && $i < 20) {
139  $obj = $db->fetch_object($resql);
140 
141  $invoicestatic->id = $obj->rowid;
142  $invoicestatic->ref = $obj->ref;
143  $invoicestatic->statut = $obj->fk_statut;
144  $invoicestatic->paye = $obj->paye;
145  $invoicestatic->type = $obj->type;
146  $alreadypayed = $invoicestatic->getSommePaiement();
147 
148  $thirdpartystatic->id = $obj->socid;
149  $thirdpartystatic->name = $obj->name;
150  $thirdpartystatic->email = $obj->email;
151  $thirdpartystatic->tva_intra = $obj->tva_intra;
152  $thirdpartystatic->siren = $obj->idprof1;
153  $thirdpartystatic->siret = $obj->idprof2;
154  $thirdpartystatic->ape = $obj->idprof3;
155  $thirdpartystatic->idprof1 = $obj->idprof1;
156  $thirdpartystatic->idprof2 = $obj->idprof2;
157  $thirdpartystatic->idprof3 = $obj->idprof3;
158  $thirdpartystatic->idprof4 = $obj->idprof4;
159  $thirdpartystatic->idprof5 = $obj->idprof5;
160  $thirdpartystatic->idprof6 = $obj->idprof6;
161 
162  print '<tr class="oddeven"><td class="nowraponall">';
163  print $invoicestatic->getNomUrl(1, 'withdraw');
164  print '</td>';
165 
166  print '<td class="tdoverflowmax150">';
167  print $thirdpartystatic->getNomUrl(1, 'supplier');
168  print '</td>';
169 
170  print '<td class="right">';
171  print '<span class="amount">'.price($obj->amount).'</span>';
172  print '</td>';
173 
174  print '<td class="right">';
175  print dol_print_date($db->jdate($obj->date_demande), 'day');
176  print '</td>';
177 
178  print '<td class="right">';
179  print $invoicestatic->getLibStatut(3, $alreadypayed);
180  print '</td>';
181  print '</tr>';
182  $i++;
183  }
184  } else {
185  print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("NoSupplierInvoiceToWithdraw", $langs->transnoentitiesnoconv("BankTransfer")).'</span></td></tr>';
186  }
187  print "</table></div><br>";
188 } else {
189  dol_print_error($db);
190 }
191 
192 
193 print '</div><div class="fichetwothirdright">';
194 
195 
196 /*
197  * Withdraw receipts
198  */
199 
200 $limit = 5;
201 $sql = "SELECT p.rowid, p.ref, p.amount, p.datec, p.statut";
202 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
203 $sql .= " WHERE p.type = 'bank-transfer'";
204 $sql .= " AND p.entity IN (".getEntity('invoice').")";
205 $sql .= " ORDER BY datec DESC";
206 $sql .= $db->plimit($limit);
207 
208 $result = $db->query($sql);
209 if ($result) {
210  $num = $db->num_rows($result);
211  $i = 0;
212 
213  print"\n<!-- debut table -->\n";
214  print '<div class="div-table-responsive-no-min">';
215  print '<table class="noborder centpercent">';
216  print '<tr class="liste_titre">';
217  print '<th>'.$langs->trans("LatestBankTransferReceipts", $limit).'</th>';
218  print '<th>'.$langs->trans("Date").'</th>';
219  print '<th class="right">'.$langs->trans("Amount").'</th>';
220  print '<th class="right">'.$langs->trans("Status").'</th>';
221  print '</tr>';
222 
223  if ($num > 0) {
224  while ($i < min($num, $limit)) {
225  $obj = $db->fetch_object($result);
226 
227  print '<tr class="oddeven">';
228 
229  print '<td class="nowraponall">';
230  $bprev->id = $obj->rowid;
231  $bprev->ref = $obj->ref;
232  $bprev->statut = $obj->statut;
233  print $bprev->getNomUrl(1);
234  print "</td>\n";
235  print '<td>'.dol_print_date($db->jdate($obj->datec), "dayhour")."</td>\n";
236  print '<td class="right nowraponall"><span class="amount">'.price($obj->amount)."</span></td>\n";
237  print '<td class="right"><span class="amount">'.$bprev->getLibStatut(3)."</span></td>\n";
238 
239  print "</tr>\n";
240  $i++;
241  }
242  } else {
243  print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
244  }
245 
246  print "</table></div><br>";
247  $db->free($result);
248 } else {
249  dol_print_error($db);
250 }
251 
252 
253 print '</div></div>';
254 
255 // End of page
256 llxFooter();
257 $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
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
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
BonPrelevement
Class to manage withdrawal receipts.
Definition: bonprelevement.class.php:43
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
dolGetButtonTitle
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.
Definition: functions.lib.php:10605
llxHeader
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
$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
price
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.
Definition: functions.lib.php:5541
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
prelevement_check_config
prelevement_check_config($type='direct-debit')
Check need data to create standigns orders receipt file.
Definition: prelevement.lib.php:85