dolibarr  9.0.0
create.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2010-2015 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  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
37 
38 // Load translation files required by the page
39 $langs->loadLangs(array('banks', 'categories', 'widthdrawals', 'companies', 'bills'));
40 
41 // Security check
42 if ($user->societe_id) $socid=$user->societe_id;
43 $result = restrictedArea($user, 'prelevement', '', '', 'bons');
44 
45 // Get supervariables
46 $action = GETPOST('action','alpha');
47 $mode = GETPOST('mode','alpha')?GETPOST('mode','alpha'):'real';
48 $format = GETPOST('format','aZ09');
49 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
50 $page = GETPOST("page",'int');
51 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
52 $offset = $limit * $page;
53 
54 /*
55  * Actions
56  */
57 
58 // Change customer bank information to withdraw
59 if ($action == 'modify')
60 {
61  for ($i = 1 ; $i < 9 ; $i++)
62  {
63  dolibarr_set_const($db, GETPOST("nom$i"), GETPOST("value$i"),'chaine',0,'',$conf->entity);
64  }
65 }
66 if ($action == 'create')
67 {
68  // $conf->global->PRELEVEMENT_CODE_BANQUE and $conf->global->PRELEVEMENT_CODE_GUICHET should be empty
69  $bprev = new BonPrelevement($db);
70  $executiondate = dol_mktime(0, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
71 
72  $result = $bprev->create($conf->global->PRELEVEMENT_CODE_BANQUE, $conf->global->PRELEVEMENT_CODE_GUICHET, $mode, $format,$executiondate);
73  if ($result < 0)
74  {
75  setEventMessages($bprev->error, $bprev->errors, 'errors');
76  }
77  elseif ($result == 0)
78  {
79  $mesg=$langs->trans("NoInvoiceCouldBeWithdrawed", $format);
80  setEventMessages($mesg, null, 'errors');
81  $mesg.='<br>'."\n";
82  foreach($bprev->invoice_in_error as $key => $val)
83  {
84  $mesg.='<span class="warning">'.$val."</span><br>\n";
85  }
86  }
87  else
88  {
89  setEventMessages($langs->trans("DirectDebitOrderCreated", $bprev->getNomUrl(1)), null);
90  }
91 }
92 
93 
94 /*
95  * View
96  */
97 $form = new Form($db);
98 
99 $thirdpartystatic=new Societe($db);
100 $invoicestatic=new Facture($db);
101 $bprev = new BonPrelevement($db);
102 
103 llxHeader('', $langs->trans("NewStandingOrder"));
104 
105 if (prelevement_check_config() < 0)
106 {
107  $langs->load("errors");
108  setEventMessages($langs->trans("ErrorModuleSetupNotComplete"), null, 'errors');
109 }
110 
111 /*$h=0;
112 $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/create.php';
113 $head[$h][1] = $langs->trans("NewStandingOrder");
114 $head[$h][2] = 'payment';
115 $hselected = 'payment';
116 $h++;
117 
118 dol_fiche_head($head, $hselected, $langs->trans("StandingOrders"), 0, 'payment');
119 */
120 
121 print load_fiche_titre($langs->trans("NewStandingOrder"));
122 
124 
125 $nb=$bprev->NbFactureAPrelever();
126 $nb1=$bprev->NbFactureAPrelever(1);
127 $nb11=$bprev->NbFactureAPrelever(1,1);
128 $pricetowithdraw=$bprev->SommeAPrelever();
129 if ($nb < 0 || $nb1 < 0 || $nb11 < 0)
130 {
131  dol_print_error($bprev->error);
132 }
133 print '<table class="border" width="100%">';
134 
135 print '<tr><td class="titlefield">'.$langs->trans("NbOfInvoiceToWithdraw").'</td>';
136 print '<td>';
137 print $nb;
138 print '</td></tr>';
139 
140 print '<tr><td>'.$langs->trans("AmountToWithdraw").'</td>';
141 print '<td>';
142 print price($pricetowithdraw);
143 print '</td>';
144 print '</tr>';
145 
146 print '</table>';
147 print '</div>';
148 
149 if ($mesg) print $mesg;
150 
151 print "<div class=\"tabsAction\">\n";
152 print '<form action="' . $_SERVER['PHP_SELF'] . '?action=create" method="POST">';
153 print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
154 if ($nb) {
155  if ($pricetowithdraw) {
156  print $langs->trans('ExecutionDate').' ';
157  print $form->selectDate();
158  if ($mysoc->isInEEC()) {
159  print '<select name="format"><option value="FRST">'.$langs->trans('SEPAFRST').'</option><option value="RCUR">'.$langs->trans('SEPARCUR').'</option></select>';
160  print '<input class="butAction" type="submit" value="' . $langs->trans("CreateForSepa") . '"/>';
161  } else {
162  print '<a class="butAction" type="submit" href="create.php?action=create&format=ALL">' . $langs->trans("CreateAll") . "</a>\n";
163  }
164  }
165  else
166  {
167  if ($mysoc->isInEEC())
168  {
169  print '<a class="butActionRefused" href="#">'.$langs->trans("CreateForSepaFRST")."</a>\n";
170  print '<a class="butActionRefused" href="#">'.$langs->trans("CreateForSepaRCUR")."</a>\n";
171  }
172  else
173  {
174  print '<a class="butActionRefused" href="#">'.$langs->trans("CreateAll")."</a>\n";
175  }
176  }
177 }
178 else
179 {
180  print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NoInvoiceToWithdraw", $langs->transnoentitiesnoconv("StandingOrders"))).'">'.$langs->trans("CreateAll")."</a>\n";
181 }
182 
183 print "</div>\n";
184 print '<br>';
185 
186 
187 /*
188  * Invoices waiting for withdraw
189  */
190 
191 $sql = "SELECT f.facnumber, f.rowid, f.total_ttc, s.nom as name, s.rowid as socid,";
192 $sql.= " pfd.date_demande, pfd.amount";
193 $sql.= " FROM ".MAIN_DB_PREFIX."facture as f,";
194 $sql.= " ".MAIN_DB_PREFIX."societe as s,";
195 $sql.= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
196 $sql.= " WHERE s.rowid = f.fk_soc";
197 $sql.= " AND f.entity = ".$conf->entity;
198 $sql.= " AND pfd.traite = 0";
199 $sql.= " AND pfd.fk_facture = f.rowid";
200 if ($socid) $sql.= " AND f.fk_soc = ".$socid;
201 
202 $nbtotalofrecords = '';
203 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
204 {
205  $result = $db->query($sql);
206  $nbtotalofrecords = $db->num_rows($result);
207 }
208 
209 $sql.= $db->plimit($limit+1,$offset);
210 
211 $resql=$db->query($sql);
212 if ($resql)
213 {
214  $num = $db->num_rows($resql);
215  $i = 0;
216 
217  $param='';
218  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
219  if($socid) $param .= '&socid='.urlencode($socid);
220  if($option) $param .= "&option=".urlencode($option);
221 
222  if(! empty($page) && $num <= $nbtotalofrecords) $page = 0;
223 
224  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
225  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
226  print '<input type="hidden" name="page" value="'.$page.'">';
227 
228  print_barre_liste($langs->trans("InvoiceWaitingWithdraw"),$page,$_SERVER['PHP_SELF'],$param,'','','',$num,$nbtotalofrecords,'title_accountancy.png',0,'','', $limit);
229 
230  print '<table class="noborder" width="100%">';
231  print '<tr class="liste_titre">';
232  print '<td>'.$langs->trans("Invoice").'</td>';
233  print '<td>'.$langs->trans("ThirdParty").'</td>';
234  print '<td>'.$langs->trans("RIB").'</td>';
235  print '<td>'.$langs->trans("RUM").'</td>';
236  print '<td align="right">'.$langs->trans("AmountTTC").'</td>';
237  print '<td align="right">'.$langs->trans("DateRequest").'</td>';
238  print '</tr>';
239 
240  if ($num)
241  {
242  require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
243  $bac = new CompanyBankAccount($db);
244 
245  while ($i < $num && $i < $limit)
246  {
247  $obj = $db->fetch_object($resql);
248 
249  print '<tr class="oddeven">';
250  print '<td>';
251  $invoicestatic->id=$obj->rowid;
252  $invoicestatic->ref=$obj->facnumber;
253  print $invoicestatic->getNomUrl(1,'withdraw');
254  print '</td>';
255  // Thirdparty
256  print '<td>';
257  $thirdpartystatic->fetch($obj->socid);
258  print $thirdpartystatic->getNomUrl(1,'ban');
259  print '</td>';
260  // RIB
261  print '<td>';
262  print $thirdpartystatic->display_rib();
263  $bac->fetch(0, $obj->socid);
264  if ($bac->verif() <= 0) print img_warning('Error on default bank number for IBAN : '.$bac->error_message);
265  print '</td>';
266  // RUM
267  print '<td>';
268  print $thirdpartystatic->display_rib('rum');
269  $format = $thirdpartystatic->display_rib('format');
270  if ($format) print ' ('.$format.')';
271  print '</td>';
272  // Amount
273  print '<td align="right">';
274  print price($obj->amount,0,$langs,0,0,-1,$conf->currency);
275  print '</td>';
276  // Date
277  print '<td align="right">';
278  print dol_print_date($db->jdate($obj->date_demande),'day');
279  print '</td>';
280  print '</tr>';
281  $i++;
282  }
283  }
284  else print '<tr '.$bc[0].'><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
285  print "</table>";
286  print "</form>";
287  print "<br>\n";
288 }
289 else
290 {
291  dol_print_error($db);
292 }
293 
294 
295 /*
296  * List of latest withdraws
297  */
298 /*
299 $limit=5;
300 
301 print load_fiche_titre($langs->trans("LastWithdrawalReceipts",$limit),'','');
302 
303 $sql = "SELECT p.rowid, p.ref, p.amount, p.statut";
304 $sql.= ", p.datec";
305 $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
306 $sql.= " WHERE p.entity IN (".getEntity('facture').")";
307 $sql.= " ORDER BY datec DESC";
308 $sql.=$db->plimit($limit);
309 
310 $result = $db->query($sql);
311 if ($result)
312 {
313  $num = $db->num_rows($result);
314  $i = 0;
315 
316  print"\n<!-- debut table -->\n";
317  print '<table class="noborder" width="100%">';
318  print '<tr class="liste_titre"><td>'.$langs->trans("Ref").'</td>';
319  print '<td align="center">'.$langs->trans("Date").'</td><td align="right">'.$langs->trans("Amount").'</td>';
320  print '</tr>';
321 
322  while ($i < min($num,$limit))
323  {
324  $obj = $db->fetch_object($result);
325 
326 
327  print '<tr class="oddeven">';
328 
329  print "<td>";
330  $bprev->id=$obj->rowid;
331  $bprev->ref=$obj->ref;
332  print $bprev->getNomUrl(1);
333  print "</td>\n";
334 
335  print '<td align="center">'.dol_print_date($db->jdate($obj->datec),'day')."</td>\n";
336 
337  print '<td align="right">'.price($obj->amount,0,$langs,0,0,-1,$conf->currency)."</td>\n";
338 
339  print "</tr>\n";
340  $i++;
341  }
342  print "</table><br>";
343  $db->free($result);
344 }
345 else
346 {
347  dol_print_error($db);
348 }
349 */
350 
351 // End of page
352 llxFooter();
353 $db->close();
img_warning($titlealt='default', $moreatt='')
Show warning logo.
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
prelevement_check_config()
Check need data to create standigns orders receipt file.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
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:510
Class to manage bank accounts description of third parties.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage generation of HTML components Only common components must be here.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage withdrawal receipts.
llxHeader()
Empty header.
Definition: wrapper.php:44
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='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.
Class to manage invoices.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.