dolibarr  13.0.2
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) $socid = $user->socid;
42 $result = restrictedArea($user, 'paymentbybanktransfer', '', '');
43 
44 
45 /*
46  * Actions
47  */
48 
49 
50 
51 
52 /*
53  * View
54  */
55 
56 llxHeader('', $langs->trans("SuppliersStandingOrdersArea"));
57 
58 if (prelevement_check_config() < 0)
59 {
60  $langs->load("errors");
61  setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Withdraw")), null, 'errors');
62 }
63 
64 print load_fiche_titre($langs->trans("SuppliersStandingOrdersArea"));
65 
66 
67 print '<div class="fichecenter"><div class="fichethirdleft">';
68 
69 
70 $thirdpartystatic = new Societe($db);
71 $invoicestatic = new FactureFournisseur($db);
72 $bprev = new BonPrelevement($db);
73 
74 print '<div class="div-table-responsive-no-min">';
75 print '<table class="noborder centpercent">';
76 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
77 
78 print '<tr class="oddeven"><td>'.$langs->trans("NbOfInvoiceToPayByBankTransfer").'</td>';
79 print '<td class="right">';
80 print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/demandes.php?status=0&type=bank-transfer">';
81 print $bprev->nbOfInvoiceToPay('bank-transfer');
82 print '</a>';
83 print '</td></tr>';
84 
85 print '<tr class="oddeven"><td>'.$langs->trans("AmountToWithdraw").'</td>';
86 print '<td class="right">';
87 print price($bprev->SommeAPrelever('bank-transfer'), '', '', 1, -1, -1, 'auto');
88 print '</td></tr></table></div><br>';
89 
90 
91 
92 /*
93  * Invoices waiting for withdraw
94  */
95 $sql = "SELECT f.ref, f.rowid, f.total_ttc, f.fk_statut, f.paye, f.type,";
96 $sql .= " pfd.date_demande, pfd.amount,";
97 $sql .= " s.nom as name, s.email, s.rowid as socid, s.tva_intra";
98 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
99 $sql .= " ".MAIN_DB_PREFIX."societe as s";
100 if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
101 $sql .= ", ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
102 $sql .= " WHERE s.rowid = f.fk_soc";
103 $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
104 $sql .= " AND f.total_ttc > 0";
105 if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS))
106 {
107  $sql .= " AND f.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
108 }
109 $sql .= " AND pfd.traite = 0";
110 $sql .= " AND pfd.ext_payment_id IS NULL";
111 $sql .= " AND pfd.fk_facture_fourn = f.rowid";
112 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
113 if ($socid) $sql .= " AND f.fk_soc = ".$socid;
114 
115 $resql = $db->query($sql);
116 if ($resql)
117 {
118  $num = $db->num_rows($resql);
119  $i = 0;
120 
121  print '<div class="div-table-responsive-no-min">';
122  print '<table class="noborder centpercent">';
123  print '<tr class="liste_titre">';
124  print '<th colspan="5">'.$langs->trans("SupplierInvoiceWaitingWithdraw").' ('.$num.')</th></tr>';
125  if ($num)
126  {
127  while ($i < $num && $i < 20)
128  {
129  $obj = $db->fetch_object($resql);
130 
131  $invoicestatic->id = $obj->rowid;
132  $invoicestatic->ref = $obj->ref;
133  $invoicestatic->statut = $obj->fk_statut;
134  $invoicestatic->paye = $obj->paye;
135  $invoicestatic->type = $obj->type;
136  $alreadypayed = $invoicestatic->getSommePaiement();
137 
138  $thirdpartystatic->id = $obj->socid;
139  $thirdpartystatic->name = $obj->name;
140  $thirdpartystatic->email = $obj->email;
141  $thirdpartystatic->tva_intra = $obj->tva_intra;
142 
143  print '<tr class="oddeven"><td>';
144  print $invoicestatic->getNomUrl(1, 'withdraw');
145  print '</td>';
146 
147  print '<td>';
148  print $thirdpartystatic->getNomUrl(1, 'supplier');
149  print '</td>';
150 
151  print '<td class="right">';
152  print price($obj->amount);
153  print '</td>';
154 
155  print '<td class="right">';
156  print dol_print_date($db->jdate($obj->date_demande), 'day');
157  print '</td>';
158 
159  print '<td class="right">';
160  print $invoicestatic->getLibStatut(3, $alreadypayed);
161  print '</td>';
162  print '</tr>';
163  $i++;
164  }
165  } else {
166  print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("NoSupplierInvoiceToWithdraw", $langs->transnoentitiesnoconv("BankTransfer")).'</td></tr>';
167  }
168  print "</table></div><br>";
169 } else {
170  dol_print_error($db);
171 }
172 
173 
174 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
175 
176 
177 /*
178  * Withdraw receipts
179  */
180 
181 $limit = 5;
182 $sql = "SELECT p.rowid, p.ref, p.amount, p.datec, p.statut";
183 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
184 $sql .= " WHERE p.type = 'bank-transfer'";
185 $sql .= " ORDER BY datec DESC";
186 $sql .= $db->plimit($limit);
187 
188 $result = $db->query($sql);
189 if ($result)
190 {
191  $num = $db->num_rows($result);
192  $i = 0;
193 
194  print"\n<!-- debut table -->\n";
195  print '<div class="div-table-responsive-no-min">';
196  print '<table class="noborder centpercent">';
197  print '<tr class="liste_titre">';
198  print '<th>'.$langs->trans("LatestBankTransferReceipts", $limit).'</th>';
199  print '<th>'.$langs->trans("Date").'</th>';
200  print '<th class="right">'.$langs->trans("Amount").'</th>';
201  print '<th class="right">'.$langs->trans("Status").'</th>';
202  print '</tr>';
203 
204  if ($num > 0) {
205  while ($i < min($num, $limit))
206  {
207  $obj = $db->fetch_object($result);
208 
209  print '<tr class="oddeven">';
210 
211  print "<td>";
212  $bprev->id = $obj->rowid;
213  $bprev->ref = $obj->ref;
214  $bprev->statut = $obj->statut;
215  print $bprev->getNomUrl(1);
216  print "</td>\n";
217  print '<td>'.dol_print_date($db->jdate($obj->datec), "dayhour")."</td>\n";
218  print '<td class="right">'.price($obj->amount)."</td>\n";
219  print '<td class="right">'.$bprev->getLibStatut(3)."</td>\n";
220 
221  print "</tr>\n";
222  $i++;
223  }
224  } else {
225  print '<tr><td class="opacitymedium" colspan="4">'.$langs->trans("None").'</td></tr>';
226  }
227 
228  print "</table></div><br>";
229  $db->free($result);
230 } else {
231  dol_print_error($db);
232 }
233 
234 
235 print '</div></div></div>';
236 
237 // End of page
238 llxFooter();
239 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
prelevement_check_config()
Check need data to create standigns orders receipt file.
Class to manage suppliers invoices.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage third parties objects (customers, suppliers, prospects...)
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
Class to manage withdrawal receipts.
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.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59