dolibarr 21.0.0-alpha
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-2012 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
30require '../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
32require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
33require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
35require_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 = GETPOSTINT('socid');
42if ($user->socid) {
43 $socid = $user->socid;
44}
45$result = restrictedArea($user, 'prelevement', '', 'bons');
46
47$usercancreate = $user->hasRight('prelevement', 'bons', 'creer');
48
49
50/*
51 * Actions
52 */
53
54// None
55
56
57/*
58 * View
59 */
60
61llxHeader('', $langs->trans("CustomersStandingOrdersArea"));
62
63if (prelevement_check_config() < 0) {
64 $langs->load("errors");
65 setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("PaymentByDirectDebit")), null, 'errors');
66}
67
68$newcardbutton = '';
69if ($usercancreate) {
70 $newcardbutton .= dolGetButtonTitle($langs->trans('NewStandingOrder'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type=');
71}
72
73print load_fiche_titre($langs->trans("CustomersStandingOrdersArea"), $newcardbutton);
74
75
76print '<div class="fichecenter"><div class="fichethirdleft">';
77
78
79$thirdpartystatic = new Societe($db);
80$invoicestatic = new Facture($db);
81$bprev = new BonPrelevement($db);
82
83print '<div class="div-table-responsive-no-min">';
84print '<table class="noborder centpercent">';
85print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
86
87print '<tr class="oddeven"><td>'.$langs->trans("NbOfInvoiceToWithdraw").'</td>';
88print '<td class="right">';
89print '<a class="badge badge-info" href="'.DOL_URL_ROOT.'/compta/prelevement/demandes.php?status=0">';
90print $bprev->nbOfInvoiceToPay('direct-debit');
91print '</a>';
92print '</td></tr>';
93
94print '<tr class="oddeven"><td>'.$langs->trans("AmountToWithdraw").'</td>';
95print '<td class="right"><span class="amount">';
96print price($bprev->SommeAPrelever('direct-debit'), 0, '', 1, -1, -1, 'auto');
97print '</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,";
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 as f,";
108$sql .= " ".MAIN_DB_PREFIX."societe as s";
109if (!$user->hasRight('societe', 'client', 'voir')) {
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('invoice').")";
115$sql .= " AND f.total_ttc > 0";
116if (!getDolGlobalString('WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS')) {
117 $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
118}
119$sql .= " AND pfd.traite = 0";
120$sql .= " AND pfd.ext_payment_id IS NULL";
121$sql .= " AND pfd.fk_facture = f.rowid";
122if (!$user->hasRight('societe', 'client', 'voir')) {
123 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
124}
125if ($socid) {
126 $sql .= " AND f.fk_soc = ".((int) $socid);
127}
128
129$resql = $db->query($sql);
130if ($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("InvoiceWaitingWithdraw").' ('.$num.')</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->statut = $obj->fk_statut;
145 $invoicestatic->paye = $obj->paye;
146 $invoicestatic->type = $obj->type;
147 $alreadypayed = $invoicestatic->getSommePaiement();
148
149 $thirdpartystatic->id = $obj->socid;
150 $thirdpartystatic->name = $obj->name;
151 $thirdpartystatic->email = $obj->email;
152 $thirdpartystatic->tva_intra = $obj->tva_intra;
153 $thirdpartystatic->siren = $obj->idprof1;
154 $thirdpartystatic->siret = $obj->idprof2;
155 $thirdpartystatic->ape = $obj->idprof3;
156 $thirdpartystatic->idprof1 = $obj->idprof1;
157 $thirdpartystatic->idprof2 = $obj->idprof2;
158 $thirdpartystatic->idprof3 = $obj->idprof3;
159 $thirdpartystatic->idprof4 = $obj->idprof4;
160 $thirdpartystatic->idprof5 = $obj->idprof5;
161 $thirdpartystatic->idprof6 = $obj->idprof6;
162
163 print '<tr class="oddeven"><td class="nowraponall">';
164 print $invoicestatic->getNomUrl(1, 'withdraw');
165 print '</td>';
166
167 print '<td class="tdoverflowmax150">';
168 print $thirdpartystatic->getNomUrl(1, 'customer');
169 print '</td>';
170
171 print '<td class="right">';
172 print '<span class="amount">'.price($obj->amount).'</span>';
173 print '</td>';
174
175 print '<td class="right">';
176 print dol_print_date($db->jdate($obj->date_demande), 'day');
177 print '</td>';
178
179 print '<td class="right">';
180 print $invoicestatic->getLibStatut(3, $alreadypayed);
181 print '</td>';
182 print '</tr>';
183 $i++;
184 }
185 } else {
186 $titlefortab = $langs->transnoentitiesnoconv("StandingOrders");
187 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("NoInvoiceToWithdraw", $titlefortab, $titlefortab).'</span></td></tr>';
188 }
189 print "</table></div><br>";
190} else {
191 dol_print_error($db);
192}
193
194
195print '</div><div class="fichetwothirdright">';
196
197
198/*
199 * Direct debit orders
200 */
201
202$limit = 5;
203$sql = "SELECT p.rowid, p.ref, p.amount, p.datec, p.statut";
204$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
205$sql .= " WHERE p.type = 'debit-order'";
206$sql .= " AND entity IN (".getEntity('prelevement').")";
207$sql .= " ORDER BY datec DESC";
208$sql .= $db->plimit($limit);
209
210$result = $db->query($sql);
211if ($result) {
212 $num = $db->num_rows($result);
213 $i = 0;
214
215 print"\n<!-- debut table -->\n";
216 print '<div class="div-table-responsive-no-min">';
217 print '<table class="noborder centpercent">';
218 print '<tr class="liste_titre">';
219 print '<th>'.$langs->trans("LastWithdrawalReceipt", $limit).'</th>';
220 print '<th>'.$langs->trans("Date").'</th>';
221 print '<th class="right">'.$langs->trans("Amount").'</th>';
222 print '<th class="right">'.$langs->trans("Status").'</th>';
223 print '</tr>';
224
225 if ($num > 0) {
226 while ($i < min($num, $limit)) {
227 $obj = $db->fetch_object($result);
228
229 $bprev->id = $obj->rowid;
230 $bprev->ref = $obj->ref;
231 $bprev->statut = $obj->statut;
232
233 print '<tr class="oddeven">';
234
235 print '<td class="nowraponall">';
236 print $bprev->getNomUrl(1);
237 print "</td>\n";
238 print '<td>'.dol_print_date($db->jdate($obj->datec), "dayhour")."</td>\n";
239 print '<td class="right nowraponall"><span class="amount">'.price($obj->amount)."</span></td>\n";
240 print '<td class="right">'.$bprev->getLibStatut(3)."</td>\n";
241
242 print "</tr>\n";
243 $i++;
244 }
245 } else {
246 print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
247 }
248
249 print "</table></div><br>";
250 $db->free($result);
251} else {
252 dol_print_error($db);
253}
254
255
256print '</div></div>';
257
258// End of page
259llxFooter();
260$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
Class to manage withdrawal receipts.
Class to manage invoices.
Class to manage third parties objects (customers, suppliers, prospects...)
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
prelevement_check_config($type='direct-debit')
Check need data to create standigns orders receipt file.
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.