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