dolibarr  9.0.0
card.php
1 <?php
2 /* Copyright (C) 2017 Alexandre Spangaro <aspangaro@zendsi.com>
3  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
25 require '../../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
33 if (! empty($conf->projet->enabled))
34 {
35  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
36  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
37 }
38 
39 // Load translation files required by the page
40 $langs->loadLangs(array("compta", "banks", "bills", "users", "accountancy"));
41 
42 // Get parameters
43 $id = GETPOST('id', 'int');
44 $action = GETPOST('action', 'alpha');
45 $cancel = GETPOST('cancel', 'aZ09');
46 $backtopage = GETPOST('backtopage', 'alpha');
47 
48 $accountid=GETPOST("accountid") > 0 ? GETPOST("accountid","int") : 0;
49 $label=GETPOST("label","alpha");
50 $sens=GETPOST("sens","int");
51 $amount=GETPOST("amount");
52 $paymenttype=GETPOST("paymenttype");
53 $accountancy_code=GETPOST("accountancy_code","int");
54 $projectid = (GETPOST('projectid','int') ? GETPOST('projectid', 'int') : GETPOST('fk_project','int'));
55 
56 // Security check
57 $socid = GETPOST("socid","int");
58 if ($user->societe_id) $socid=$user->societe_id;
59 $result = restrictedArea($user, 'banque', '', '', '');
60 
61 $object = new PaymentVarious($db);
62 
63 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
64 $hookmanager->initHooks(array('variouscard','globalcard'));
65 
66 
67 
72 $parameters=array();
73 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
74 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
75 
76 if (empty($reshook))
77 {
78  // Link to a project
79  if ($action == 'classin' && $user->rights->banque->modifier)
80  {
81  $object->fetch($id);
82  $object->setProject(GETPOST('projectid'));
83  }
84 
85  if ($cancel)
86  {
87  if ($action != 'addlink')
88  {
89  $urltogo=$backtopage?$backtopage:dol_buildpath('/compta/bank/various_payment/list.php',1);
90  header("Location: ".$urltogo);
91  exit;
92  }
93  if ($id > 0 || ! empty($ref)) $ret = $object->fetch($id,$ref);
94  $action='';
95  }
96 
97  if ($action == 'add')
98  {
99  $error=0;
100 
101  $datep=dol_mktime(12,0,0, GETPOST("datepmonth",'int'), GETPOST("datepday",'int'), GETPOST("datepyear",'int'));
102  $datev=dol_mktime(12,0,0, GETPOST("datevmonth",'int'), GETPOST("datevday",'int'), GETPOST("datevyear",'int'));
103  if (empty($datev)) $datev=$datep;
104 
105  $object->ref=''; // TODO
106  $object->accountid=GETPOST("accountid",'int') > 0 ? GETPOST("accountid","int") : 0;
107  $object->datev=$datev;
108  $object->datep=$datep;
109  $object->amount=price2num(GETPOST("amount",'alpha'));
110  $object->label=GETPOST("label",'none');
111  $object->note=GETPOST("note",'none');
112  $object->type_payment=GETPOST("paymenttype",'int') > 0 ? GETPOST("paymenttype", "int") : 0;
113  $object->num_payment=GETPOST("num_payment",'alpha');
114  $object->fk_user_author=$user->id;
115  $object->accountancy_code=GETPOST("accountancy_code") > 0 ? GETPOST("accountancy_code","int") : "";
116  $object->sens=GETPOST('sens');
117  $object->fk_project= GETPOST('fk_project','int');
118 
119  if (empty($datep) || empty($datev))
120  {
121  $langs->load('errors');
122  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
123  $error++;
124  }
125  if (empty($object->type_payment) || $object->type_payment < 0)
126  {
127  $langs->load('errors');
128  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
129  $error++;
130  }
131  if (empty($object->amount))
132  {
133  $langs->load('errors');
134  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
135  $error++;
136  }
137  if (! empty($conf->banque->enabled) && ! $object->accountid > 0)
138  {
139  $langs->load('errors');
140  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors');
141  $error++;
142  }
143  if (! empty($conf->accounting->enabled) && ! $object->accountancy_code)
144  {
145  $langs->load('errors');
146  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountAccounting")), null, 'errors');
147  $error++;
148  }
149 
150  if (! $error)
151  {
152  $db->begin();
153 
154  $ret=$object->create($user);
155  if ($ret > 0)
156  {
157  $db->commit();
158  $urltogo=($backtopage ? $backtopage : DOL_URL_ROOT.'/compta/bank/various_payment/list.php');
159  header("Location: ".$urltogo);
160  exit;
161  }
162  else
163  {
164  $db->rollback();
165  setEventMessages($object->error, $object->errors, 'errors');
166  $action="create";
167  }
168  }
169 
170  $action='create';
171  }
172 
173  if ($action == 'delete')
174  {
175  $result=$object->fetch($id);
176 
177  if ($object->rappro == 0)
178  {
179  $db->begin();
180 
181  $ret=$object->delete($user);
182  if ($ret > 0)
183  {
184  if ($object->fk_bank)
185  {
186  $accountline=new AccountLine($db);
187  $result=$accountline->fetch($object->fk_bank);
188  if ($result > 0) $result=$accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
189  }
190 
191  if ($result >= 0)
192  {
193  $db->commit();
194  header("Location: ".DOL_URL_ROOT.'/compta/bank/various_payment/list.php');
195  exit;
196  }
197  else
198  {
199  $object->error=$accountline->error;
200  $db->rollback();
201  setEventMessages($object->error, $object->errors, 'errors');
202  }
203  }
204  else
205  {
206  $db->rollback();
207  setEventMessages($object->error, $object->errors, 'errors');
208  }
209  }
210  else
211  {
212  setEventMessages('Error try do delete a line linked to a conciliated bank transaction', null, 'errors');
213  }
214  }
215 }
216 
217 
218 /*
219  * View
220  */
221 
222 llxHeader("",$langs->trans("VariousPayment"));
223 
224 $form = new Form($db);
225 if (! empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db);
226 if (! empty($conf->projet->enabled)) $formproject = new FormProjets($db);
227 
228 if ($id)
229 {
230  $object = new PaymentVarious($db);
231  $result = $object->fetch($id);
232  if ($result <= 0)
233  {
234  dol_print_error($db);
235  exit;
236  }
237 }
238 
239 /* ************************************************************************** */
240 /* */
241 /* Create mode */
242 /* */
243 /* ************************************************************************** */
244 if ($action == 'create')
245 {
246  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
247  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
248  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
249  print '<input type="hidden" name="action" value="add">';
250 
251  print load_fiche_titre($langs->trans("NewVariousPayment"),'', 'title_accountancy.png');
252 
253  dol_fiche_head('', '');
254 
255  print '<table class="border" width="100%">';
256 
257  // Date payment
258  print '<tr><td>';
259  print fieldLabel('DatePayment','datep',1).'</td><td>';
260  print $form->selectDate((empty($datep)?-1:$datep),"datep",'','','','add',1,1);
261  print '</td></tr>';
262 
263  // Date value for bank
264  print '<tr><td>';
265  print fieldLabel('DateValue','datev',0).'</td><td>';
266  print $form->selectDate((empty($datev)?-1:$datev),"datev",'','','','add',1,1);
267  print '</td></tr>';
268 
269  // Label
270  print '<tr><td>';
271  print fieldLabel('Label','label',1).'</td><td>';
272  print '<input name="label" id="label" class="minwidth300" value="'.($label?$label:$langs->trans("VariousPayment")).'">';
273  print '</td></tr>';
274 
275  // Sens
276  print '<tr><td>';
277  print fieldLabel('Sens','sens',1).'</td><td>';
278  $sensarray=array( '0' => $langs->trans("Debit"), '1' => $langs->trans("Credit"));
279  print $form->selectarray('sens',$sensarray,$sens);
280  print '</td></tr>';
281 
282  // Amount
283  print '<tr><td>';
284  print fieldLabel('Amount','amount',1).'</td><td>';
285  print '<input name="amount" id="amount" class="minwidth100" value="'.$amount.'">';
286  print '</td></tr>';
287 
288  // Bank
289  if (! empty($conf->banque->enabled))
290  {
291  print '<tr><td>';
292  print fieldLabel('BankAccount','selectaccountid',1).'</td><td>';
293  $form->select_comptes($accountid,"accountid",0,'',1); // Affiche liste des comptes courant
294  print '</td></tr>';
295  }
296 
297  // Type payment
298  print '<tr><td>';
299  print fieldLabel('PaymentMode','selectpaymenttype',1).'</td><td>';
300  $form->select_types_paiements($paymenttype, "paymenttype");
301  print '</td></tr>';
302 
303  // Number
304  if (! empty($conf->banque->enabled))
305  {
306  // Number
307  print '<tr><td><label for="num_payment">'.$langs->trans('Numero');
308  print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
309  print '</label></td>';
310  print '<td><input name="num_payment" id="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
311  }
312 
313  // Accountancy account
314  if (! empty($conf->accounting->enabled))
315  {
316  print '<tr><td class="fieldrequired">'.$langs->trans("AccountAccounting").'</td>';
317  print '<td>';
318  print $formaccounting->select_account($accountancy_code, 'accountancy_code', 1, null, 1, 1, '');
319  print '</td></tr>';
320  }
321  else // For external software
322  {
323  print '<tr><td>'.$langs->trans("AccountAccounting").'</td>';
324  print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code" value="'.$accountancy_code.'">';
325  print '</td></tr>';
326  }
327 
328  // Project
329  if (! empty($conf->projet->enabled))
330  {
331  $formproject=new FormProjets($db);
332 
333  // Associated project
334  $langs->load("projects");
335 
336  print '<tr><td>'.$langs->trans("Project").'</td><td>';
337 
338  $numproject=$formproject->select_projects(-1, $projectid,'fk_project',0,0,1,1);
339 
340  print '</td></tr>';
341  }
342 
343  // Other attributes
344  $parameters=array();
345  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
346  print $hookmanager->resPrint;
347 
348  print '</table>';
349 
350  dol_fiche_end();
351 
352  print '<div class="center">';
353  print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
354  print ' &nbsp; ';
355  print '<input type="button" class="button" value="'.$langs->trans("Cancel").'" onclick="javascript:history.go(-1)">';
356  print '</div>';
357 
358  print '</form>';
359 }
360 
361 
362 /* ************************************************************************** */
363 /* */
364 /* View mode */
365 /* */
366 /* ************************************************************************** */
367 
368 if ($id)
369 {
370  $head=various_payment_prepare_head($object);
371 
372  dol_fiche_head($head, 'card', $langs->trans("VariousPayment"), -1, 'payment');
373 
374  $morehtmlref='<div class="refidno">';
375  // Project
376  if (! empty($conf->projet->enabled))
377  {
378  $langs->load("projects");
379  $morehtmlref.=$langs->trans('Project') . ' ';
380  if ($user->rights->banque->modifier)
381  {
382  if ($action != 'classify')
383  $morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
384  if ($action == 'classify') {
385  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
386  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
387  $morehtmlref.='<input type="hidden" name="action" value="classin">';
388  $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
389  $morehtmlref.=$formproject->select_projects(0, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
390  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
391  $morehtmlref.='</form>';
392  } else {
393  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
394  }
395  } else {
396  if (! empty($object->fk_project)) {
397  $proj = new Project($db);
398  $proj->fetch($object->fk_project);
399  $morehtmlref.=$proj->getNomUrl(1);
400  } else {
401  $morehtmlref.='';
402  }
403  }
404  }
405  $morehtmlref.='</div>';
406  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/various_payment/list.php?restore_lastsearch_values=1'.(! empty($socid)?'&socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
407 
408  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
409 
410  print '<div class="fichecenter">';
411  print '<div class="underbanner clearboth"></div>';
412 
413  print '<table class="border" width="100%">';
414 
415  // Label
416  print '<tr><td class="titlefield">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
417 
418  // Payment date
419  print "<tr>";
420  print '<td>'.$langs->trans("DatePayment").'</td><td>';
421  print dol_print_date($object->datep,'day');
422  print '</td></tr>';
423 
424  // Value date
425  print '<tr><td>'.$langs->trans("DateValue").'</td><td>';
426  print dol_print_date($object->datev,'day');
427  print '</td></tr>';
428 
429  // Debit / Credit
430  if ($object->sens == '1') $sens = $langs->trans("Credit"); else $sens = $langs->trans("Debit");
431  print '<tr><td>'.$langs->trans("Sens").'</td><td>'.$sens.'</td></tr>';
432 
433  print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
434 
435  // Accountancy code
436  print '<tr><td class="nowrap">';
437  print $langs->trans("AccountAccounting");
438  print '</td><td>';
439  if (! empty($conf->accounting->enabled))
440  {
441  $accountingaccount = new AccountingAccount($db);
442  $accountingaccount->fetch('',$object->accountancy_code, 1);
443 
444  print $accountingaccount->getNomUrl(0,1,1,'',1);
445  } else {
446  print $object->accountancy_code;
447  }
448  print '</td></tr>';
449 
450  if (! empty($conf->banque->enabled))
451  {
452  if ($object->fk_account > 0)
453  {
454  $bankline=new AccountLine($db);
455  $bankline->fetch($object->fk_bank);
456 
457  print '<tr>';
458  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
459  print '<td colspan="3">';
460  print $bankline->getNomUrl(1,0,'showall');
461  print '</td>';
462  print '</tr>';
463  }
464  }
465 
466  // Other attributes
467  $parameters=array('socid'=>$object->id);
468  include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
469 
470  print '</table>';
471 
472  print '</div>';
473  print '</div>';
474 
475  print '<div class="clearboth"></div>';
476 
477  dol_fiche_end();
478 
479 
480  /*
481  * Action buttons
482  */
483  print '<div class="tabsAction">'."\n";
484  if ($object->rappro == 0)
485  {
486  if (! empty($user->rights->banque->modifier))
487  {
488  print '<a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete">'.$langs->trans("Delete").'</a>';
489  }
490  else
491  {
492  print '<a class="butActionRefused" href="#" title="'.(dol_escape_htmltag($langs->trans("NotAllowed"))).'">'.$langs->trans("Delete").'</a>';
493  }
494  }
495  else
496  {
497  print '<a class="butActionRefused" href="#" title="'.$langs->trans("LinkedToAConciliatedTransaction").'">'.$langs->trans("Delete").'</a>';
498  }
499  print "</div>";
500 }
501 
502 // End of page
503 llxFooter();
504 $db->close();
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.
Class to manage various payments.
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...
img_edit($titlealt='default', $float=0, $other='class="pictoedit"')
Show logo editer/modifier fiche.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
various_payment_prepare_head($object)
Prepare array with list of tabs.
Definition: bank.lib.php:164
Class to manage bank transaction lines.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
Class to manage building of HTML components.
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
if($_POST["cancel"]==$langs->trans("Cancel") &&! $id) if($action=='add' && $_POST["cancel"]<> $langs->trans("Cancel")) if($action=='delete') if($id) $form
Actions.
Definition: card.php:153
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).
Class to manage generation of HTML components for accounting management.
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 accounting accounts.
fieldLabel($langkey, $fieldkey, $fieldrequired=0)
Show a string with the label tag dedicated to the HTML edit field.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
$parameters
Actions.
Definition: card.php:114