dolibarr  13.0.2
create.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2010-2020 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
7  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
8  * Copyright (C) 2019 Markus Welters <markus@welters.de>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
30 require '../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
38 
39 // Load translation files required by the page
40 $langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies', 'bills'));
41 
42 // Security check
43 if ($user->socid) $socid = $user->socid;
44 $result = restrictedArea($user, 'prelevement', '', '', 'bons');
45 
46 $type = GETPOST('type', 'aZ09');
47 
48 // Get supervariables
49 $action = GETPOST('action', 'aZ09');
50 $mode = GETPOST('mode', 'alpha') ?GETPOST('mode', 'alpha') : 'real';
51 $format = GETPOST('format', 'aZ09');
52 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
53 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
54 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
55 $offset = $limit * $page;
56 
57 $hookmanager->initHooks(array('directdebitcreatecard', 'globalcard'));
58 
59 
60 /*
61  * Actions
62  */
63 
64 $parameters = array('mode' => $mode, 'format' => $format, 'limit' => $limit, 'page' => $page, 'offset' => $offset);
65 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
66 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
67 
68 if (empty($reshook))
69 {
70  // Change customer bank information to withdraw
71  if ($action == 'modify')
72  {
73  for ($i = 1; $i < 9; $i++)
74  {
75  dolibarr_set_const($db, GETPOST("nom$i"), GETPOST("value$i"), 'chaine', 0, '', $conf->entity);
76  }
77  }
78  if ($action == 'create')
79  {
80  $delayindays = 0;
81  if ($type != 'bank-transfer') {
82  $conf->global->PRELEVEMENT_ADDDAYS;
83  } else {
84  $conf->global->PAYMENTBYBANKTRANSFER_ADDDAYS;
85  }
86  $bprev = new BonPrelevement($db);
87  $executiondate = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), (GETPOST('reday', 'int') + $delayindays), GETPOST('reyear', 'int'));
88 
89  // $conf->global->PRELEVEMENT_CODE_BANQUE and $conf->global->PRELEVEMENT_CODE_GUICHET should be empty (we don't use them anymore)
90  $result = $bprev->create($conf->global->PRELEVEMENT_CODE_BANQUE, $conf->global->PRELEVEMENT_CODE_GUICHET, $mode, $format, $executiondate, 0, $type);
91  if ($result < 0) {
92  setEventMessages($bprev->error, $bprev->errors, 'errors');
93  } elseif ($result == 0) {
94  $mesg = $langs->trans("NoInvoiceCouldBeWithdrawed", $format);
95  setEventMessages($mesg, null, 'errors');
96  $mesg .= '<br>'."\n";
97  foreach ($bprev->invoice_in_error as $key => $val)
98  {
99  $mesg .= '<span class="warning">'.$val."</span><br>\n";
100  }
101  } else {
102  if ($type != 'bank-transfer') {
103  setEventMessages($langs->trans("DirectDebitOrderCreated", $bprev->getNomUrl(1)), null);
104  } else {
105  setEventMessages($langs->trans("CreditTransferOrderCreated", $bprev->getNomUrl(1)), null);
106  }
107 
108  header("Location: ".DOL_URL_ROOT.'/compta/prelevement/card.php?id='.$bprev->id);
109  exit;
110  }
111  }
112 }
113 
114 
115 /*
116  * View
117  */
118 
119 $form = new Form($db);
120 
121 $thirdpartystatic = new Societe($db);
122 if ($type != 'bank-transfer') {
123  $invoicestatic = new Facture($db);
124 } else {
125  $invoicestatic = new FactureFournisseur($db);
126 }
127 $bprev = new BonPrelevement($db);
128 
129 llxHeader('', $langs->trans("NewStandingOrder"));
130 
131 if (prelevement_check_config() < 0)
132 {
133  $langs->load("errors");
134  setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Withdraw")), null, 'errors');
135 }
136 
137 /*$h=0;
138 $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/create.php';
139 $head[$h][1] = $langs->trans("NewStandingOrder");
140 $head[$h][2] = 'payment';
141 $hselected = 'payment';
142 $h++;
143 
144 print dol_get_fiche_head($head, $hselected, $langs->trans("StandingOrders"), 0, 'payment');
145 */
146 
147 $title = $langs->trans("NewStandingOrder");
148 if ($type == 'bank-transfer') {
149  $title = $langs->trans("NewPaymentByBankTransfer");
150 }
151 
152 print load_fiche_titre($title);
153 
155 
156 $nb = $bprev->nbOfInvoiceToPay($type);
157 $pricetowithdraw = $bprev->SommeAPrelever($type);
158 if ($nb < 0)
159 {
160  dol_print_error($bprev->error);
161 }
162 print '<table class="border centpercent tableforfield">';
163 
164 $title = $langs->trans("NbOfInvoiceToWithdraw");
165 if ($type == 'bank-transfer') {
166  $title = $langs->trans("NbOfInvoiceToPayByBankTransfer");
167 }
168 
169 print '<tr><td class="titlefieldcreate">'.$title.'</td>';
170 print '<td>';
171 print $nb;
172 print '</td></tr>';
173 
174 print '<tr><td>'.$langs->trans("AmountTotal").'</td>';
175 print '<td>';
176 print price($pricetowithdraw);
177 print '</td>';
178 print '</tr>';
179 
180 print '</table>';
181 print '</div>';
182 
183 if ($mesg) print $mesg;
184 
185 print '<div class="tabsAction">'."\n";
186 
187 print '<form action="'.$_SERVER['PHP_SELF'].'?action=create" method="POST">';
188 print '<input type="hidden" name="token" value="'.newToken().'">';
189 print '<input type="hidden" name="type" value="'.$type.'">';
190 if ($nb) {
191  if ($pricetowithdraw) {
192  print $langs->trans('ExecutionDate').' ';
193  $datere = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
194  print $form->selectDate($datere, 're');
195 
196  if ($mysoc->isInEEC()) {
197  $title = $langs->trans("CreateForSepa");
198  if ($type == 'bank-transfer') {
199  $title = $langs->trans("CreateSepaFileForPaymentByBankTransfer");
200  }
201 
202  if ($type != 'bank-transfer') {
203  print '<select name="format">';
204  print '<option value="FRST"'.(GETPOST('format', 'aZ09') == 'FRST' ? ' selected="selected"' : '').'>'.$langs->trans('SEPAFRST').'</option>';
205  print '<option value="RCUR"'.(GETPOST('format', 'aZ09') == 'RCUR' ? ' selected="selected"' : '').'>'.$langs->trans('SEPARCUR').'</option>';
206  print '</select>';
207  }
208  print '<input class="butAction" type="submit" value="'.$title.'"/>';
209  } else {
210  $title = $langs->trans("CreateAll");
211  if ($type == 'bank-transfer') {
212  $title = $langs->trans("CreateFileForPaymentByBankTransfer");
213  }
214  print '<a class="butAction" type="submit" href="create.php?action=create&format=ALL&type='.$type.'">'.$title."</a>\n";
215  }
216  } else {
217  if ($mysoc->isInEEC())
218  {
219  $title = $langs->trans("CreateForSepaFRST");
220  if ($type == 'bank-transfer') {
221  $title = $langs->trans("CreateSepaFileForPaymentByBankTransfer");
222  }
223  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("AmountMustBePositive").'">'.$title."</a>\n";
224 
225  if ($type != 'bank-transfer') {
226  $title = $langs->trans("CreateForSepaRCUR");
227  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("AmountMustBePositive").'">'.$title."</a>\n";
228  }
229  } else {
230  $title = $langs->trans("CreateAll");
231  if ($type == 'bank-transfer') {
232  $title = $langs->trans("CreateFileForPaymentByBankTransfer");
233  }
234  print '<a class="butActionRefused classfortooltip" href="#">'.$title."</a>\n";
235  }
236  }
237 } else {
238  $titlefortab = $langs->transnoentitiesnoconv("StandingOrders");
239  $title = $langs->trans("CreateAll");
240  if ($type == 'bank-transfer') {
241  $titlefortab = $langs->transnoentitiesnoconv("PaymentByBankTransfers");
242  $title = $langs->trans("CreateFileForPaymentByBankTransfer");
243  }
244  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NoInvoiceToWithdraw", $titlefortab, $titlefortab)).'">'.$title."</a>\n";
245 }
246 
247 print "</form>\n";
248 
249 print "</div>\n";
250 print '</form>';
251 print '<br>';
252 
253 
254 /*
255  * Invoices waiting for withdraw
256  */
257 
258 $sql = "SELECT f.ref, f.rowid, f.total_ttc, s.nom as name, s.rowid as socid,";
259 $sql .= " pfd.date_demande, pfd.amount";
260 if ($type == 'bank-transfer') {
261  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
262 } else {
263  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
264 }
265 $sql .= " ".MAIN_DB_PREFIX."societe as s,";
266 $sql .= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
267 $sql .= " WHERE s.rowid = f.fk_soc";
268 $sql .= " AND f.entity IN (".getEntity('invoice').")";
269 if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS))
270 {
271  $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
272 }
273 //$sql .= " AND pfd.amount > 0";
274 $sql .= " AND f.total_ttc > 0"; // Avoid credit notes
275 $sql .= " AND pfd.traite = 0";
276 $sql .= " AND pfd.ext_payment_id IS NULL";
277 if ($type == 'bank-transfer') {
278  $sql .= " AND pfd.fk_facture_fourn = f.rowid";
279 } else {
280  $sql .= " AND pfd.fk_facture = f.rowid";
281 }
282 if ($socid > 0) $sql .= " AND f.fk_soc = ".$socid;
283 
284 $nbtotalofrecords = '';
285 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
286 {
287  $result = $db->query($sql);
288  $nbtotalofrecords = $db->num_rows($result);
289  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
290  {
291  $page = 0;
292  $offset = 0;
293  }
294 }
295 
296 $sql .= $db->plimit($limit + 1, $offset);
297 
298 $resql = $db->query($sql);
299 if ($resql)
300 {
301  $num = $db->num_rows($resql);
302  $i = 0;
303 
304  $param = '';
305  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
306  if ($socid) $param .= '&socid='.urlencode($socid);
307  if ($option) $param .= "&option=".urlencode($option);
308 
309  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
310  print '<input type="hidden" name="token" value="'.newToken().'">';
311  print '<input type="hidden" name="page" value="'.$page.'">';
312  if (!empty($limit)) {
313  print '<input type="hidden" name="limit" value="'.$limit.'"/>';
314  }
315 
316  $title = $langs->trans("InvoiceWaitingWithdraw");
317  if ($type == 'bank-transfer') {
318  $title = $langs->trans("InvoiceWaitingPaymentByBankTransfer");
319  }
320  print_barre_liste($title, $page, $_SERVER['PHP_SELF'], $param, '', '', '', $num, $nbtotalofrecords, 'bill', 0, '', '', $limit);
321 
322  $tradinvoice = "Invoice";
323  if ($type == 'bank-transfer') {
324  $tradinvoice = "SupplierInvoice";
325  }
326 
327  print '<table class="noborder centpercent">';
328  print '<tr class="liste_titre">';
329  print '<td>'.$langs->trans($tradinvoice).'</td>';
330  print '<td>'.$langs->trans("ThirdParty").'</td>';
331  print '<td>'.$langs->trans("RIB").'</td>';
332  print '<td>'.$langs->trans("RUM").'</td>';
333  print '<td class="right">'.$langs->trans("AmountTTC").'</td>';
334  print '<td class="right">'.$langs->trans("DateRequest").'</td>';
335  print '</tr>';
336 
337  if ($num)
338  {
339  require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
340  $bac = new CompanyBankAccount($db);
341 
342  while ($i < $num && $i < $limit)
343  {
344  $obj = $db->fetch_object($resql);
345 
346  $bac->fetch(0, $obj->socid);
347 
348  print '<tr class="oddeven">';
349 
350  // Ref invoice
351  print '<td>';
352  $invoicestatic->id = $obj->rowid;
353  $invoicestatic->ref = $obj->ref;
354  print $invoicestatic->getNomUrl(1, 'withdraw');
355  print '</td>';
356 
357  // Thirdparty
358  print '<td>';
359  $thirdpartystatic->fetch($obj->socid);
360  print $thirdpartystatic->getNomUrl(1, 'ban');
361  print '</td>';
362 
363  // RIB
364  print '<td>';
365  print $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
366  if ($bac->verif() <= 0) print img_warning('Error on default bank number for IBAN : '.$bac->error_message);
367  print '</td>';
368 
369  // RUM
370  print '<td>';
371  $rumtoshow = $thirdpartystatic->display_rib('rum');
372  if ($rumtoshow) {
373  print $rumtoshow;
374  $format = $thirdpartystatic->display_rib('format');
375  if ($type != 'bank-transfer') {
376  if ($format) print ' ('.$format.')';
377  }
378  } else {
379  print img_warning($langs->trans("NoBankAccount"));
380  }
381  print '</td>';
382  // Amount
383  print '<td class="right">';
384  print price($obj->amount, 0, $langs, 0, 0, -1, $conf->currency);
385  print '</td>';
386  // Date
387  print '<td class="right">';
388  print dol_print_date($db->jdate($obj->date_demande), 'day');
389  print '</td>';
390  print '</tr>';
391  $i++;
392  }
393  } else {
394  print '<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
395  }
396  print "</table>";
397  print "</form>";
398  print "<br>\n";
399 } else {
400  dol_print_error($db);
401 }
402 
403 
404 /*
405  * List of latest withdraws
406  */
407 /*
408 $limit=5;
409 
410 print load_fiche_titre($langs->trans("LastWithdrawalReceipts",$limit),'','');
411 
412 $sql = "SELECT p.rowid, p.ref, p.amount, p.statut";
413 $sql.= ", p.datec";
414 $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
415 $sql.= " WHERE p.entity IN (".getEntity('invoice').")";
416 $sql.= " ORDER BY datec DESC";
417 $sql.=$db->plimit($limit);
418 
419 $result = $db->query($sql);
420 if ($result)
421 {
422  $num = $db->num_rows($result);
423  $i = 0;
424 
425  print"\n<!-- debut table -->\n";
426  print '<table class="noborder centpercent">';
427  print '<tr class="liste_titre"><td>'.$langs->trans("Ref").'</td>';
428  print '<td class="center">'.$langs->trans("Date").'</td><td class="right">'.$langs->trans("Amount").'</td>';
429  print '</tr>';
430 
431  while ($i < min($num,$limit))
432  {
433  $obj = $db->fetch_object($result);
434 
435 
436  print '<tr class="oddeven">';
437 
438  print "<td>";
439  $bprev->id=$obj->rowid;
440  $bprev->ref=$obj->ref;
441  print $bprev->getNomUrl(1);
442  print "</td>\n";
443 
444  print '<td class="center">'.dol_print_date($db->jdate($obj->datec),'day')."</td>\n";
445 
446  print '<td class="right">'.price($obj->amount,0,$langs,0,0,-1,$conf->currency)."</td>\n";
447 
448  print "</tr>\n";
449  $i++;
450  }
451  print "</table><br>";
452  $db->free($result);
453 }
454 else
455 {
456  dol_print_error($db);
457 }
458 */
459 
460 // End of page
461 llxFooter();
462 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
prelevement_check_config()
Check need data to create standigns orders receipt file.
dolibarr_set_const($db, $name, $value, $type= 'chaine', $visible=0, $note= '', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:575
Class to manage bank accounts description of third parties.
Class to manage suppliers invoices.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
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.
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.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
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 $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
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...
Class to manage invoices.
llxFooter()
Empty footer.
Definition: wrapper.php:59