dolibarr  7.0.0-beta
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2015-2017 Alexandre Spangaro <aspangaro@zendsi.com>
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/tva/class/tva.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/vat.lib.php';
31 
32 $langs->load("compta");
33 $langs->load("banks");
34 $langs->load("bills");
35 
36 $id=GETPOST("id",'int');
37 $action=GETPOST("action","alpha");
38 $refund=GETPOST("refund","int");
39 if (empty($refund)) $refund=0;
40 
41 // Security check
42 $socid = GETPOST('socid','int');
43 if ($user->societe_id) $socid=$user->societe_id;
44 $result = restrictedArea($user, 'tax', '', '', 'charges');
45 
46 $object = new Tva($db);
47 
48 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
49 $hookmanager->initHooks(array('taxvatcard','globalcard'));
50 
51 
56 if ($_POST["cancel"] == $langs->trans("Cancel") && ! $id)
57 {
58  header("Location: reglement.php");
59  exit;
60 }
61 
62 if ($action == 'setdatev' && $user->rights->tax->charges->creer)
63 {
64  $object->fetch($id);
65  $object->datev=dol_mktime(12,0,0,$_POST['datevmonth'],$_POST['datevday'],$_POST['datevyear']);
66  $result=$object->update($user);
67  if ($result < 0) dol_print_error($db,$object->error);
68 
69  $action='';
70 }
71 
72 if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
73 {
74  $error=0;
75 
76  $datev=dol_mktime(12,0,0, $_POST["datevmonth"], $_POST["datevday"], $_POST["datevyear"]);
77  $datep=dol_mktime(12,0,0, $_POST["datepmonth"], $_POST["datepday"], $_POST["datepyear"]);
78 
79  $object->accountid=GETPOST("accountid");
80  $object->type_payment=GETPOST("type_payment");
81  $object->num_payment=GETPOST("num_payment");
82  $object->datev=$datev;
83  $object->datep=$datep;
84 
85  $amount = price2num(GETPOST("amount",'alpha'));
86  if ($refund == 1) {
87  $amount= -$amount;
88  }
89  $object->amount= $amount;
90  $object->label=GETPOST("label",'alpha');
91  $object->note=GETPOST("note",'none');
92 
93  if (empty($object->datev))
94  {
95  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateValue")), null, 'errors');
96  $error++;
97  }
98  if (empty($object->datep))
99  {
100  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment")), null, 'errors');
101  $error++;
102  }
103  if (empty($object->type_payment) || $object->type_payment < 0)
104  {
105  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
106  $error++;
107  }
108  if (empty($object->amount))
109  {
110  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
111  $error++;
112  }
113 
114  if (! $error)
115  {
116  $db->begin();
117 
118  $ret=$object->addPayment($user);
119  if ($ret > 0)
120  {
121  $db->commit();
122  header("Location: reglement.php");
123  exit;
124  }
125  else
126  {
127  $db->rollback();
128  setEventMessages($object->error, $object->errors, 'errors');
129  $action="create";
130  }
131  }
132 
133  $action='create';
134 }
135 
136 if ($action == 'delete')
137 {
138  $result=$object->fetch($id);
139 
140  if ($object->rappro == 0)
141  {
142  $db->begin();
143 
144  $ret=$object->delete($user);
145  if ($ret > 0)
146  {
147  if ($object->fk_bank)
148  {
149  $accountline=new AccountLine($db);
150  $result=$accountline->fetch($object->fk_bank);
151  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)
152  }
153 
154  if ($result >= 0)
155  {
156  $db->commit();
157  header("Location: ".DOL_URL_ROOT.'/compta/tva/reglement.php');
158  exit;
159  }
160  else
161  {
162  $object->error=$accountline->error;
163  $db->rollback();
164  setEventMessages($object->error, $object->errors, 'errors');
165  }
166  }
167  else
168  {
169  $db->rollback();
170  setEventMessages($object->error, $object->errors, 'errors');
171  }
172  }
173  else
174  {
175  setEventMessages('Error try do delete a line linked to a conciliated bank transaction', null, 'errors');
176  }
177 }
178 
179 
180 /*
181  * View
182  */
183 $title=$langs->trans("VAT") . " - " . $langs->trans("Card");
184 $help_url='';
185 llxHeader("",$title,$helpurl);
186 
187 $form = new Form($db);
188 
189 if ($id)
190 {
191  $result = $object->fetch($id);
192  if ($result <= 0)
193  {
194  dol_print_error($db);
195  exit;
196  }
197 }
198 
199 // Formulaire saisie tva
200 if ($action == 'create')
201 {
202  print load_fiche_titre($langs->trans("VAT") . ' - ' . $langs->trans("New"));
203 
204  if (! empty($conf->use_javascript_ajax))
205  {
206  print "\n".'<script type="text/javascript" language="javascript">';
207  print '$(document).ready(function () {
208  $("#radiopayment").click(function() {
209  $("#label").val($(this).data("label"));
210 
211  });
212  $("#radiorefund").click(function() {
213  $("#label").val($(this).data("label"));
214 
215  });
216  });';
217  print '</script>'."\n";
218  }
219 
220  print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formvat" method="post">';
221  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
222  print '<input type="hidden" name="action" value="add">';
223 
224  print '<div id="selectmethod">';
225  print '<div class="hideonsmartphone float">';
226  print $langs->trans("Type").':&nbsp;&nbsp;&nbsp;';
227  print '</div>';
228  print '<label for="radiopayment">';
229  print '<input type="radio" id="radiopayment" data-label="'.$langs->trans('VATPayment').'" class="flat" name="refund" value="0"'.($refund?'':' checked="checked"').'>';
230  print '&nbsp;';
231  print $langs->trans("Payment");
232  print '</label>';
233  print '&nbsp;&nbsp;&nbsp;';
234  print '<label for="radiorefund">';
235  print '<input type="radio" id="radiorefund" data-label="'.$langs->trans('VATRefund').'" class="flat" name="refund" value="1"'.($refund?' checked="checked"':'').'>';
236  print '&nbsp;';
237  print $langs->trans("Refund");
238  print '</label>';
239  print '</div>';
240  print "<br>\n";
241 
242  dol_fiche_head();
243 
244  print '<table class="border" width="100%">';
245 
246  print "<tr>";
247  print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
248  print $form->select_date($datep,"datep",'','','','add',1,1);
249  print '</td></tr>';
250 
251  print '<tr><td class="fieldrequired">'.$langs->trans("DateValue").'</td><td>';
252  print $form->select_date($datev,"datev",'','','','add',1,1);
253  print '</td></tr>';
254 
255  // Label
256  if ($refund == 1) {
257  $label = $langs->trans("VATRefund");
258  } else {
259  $label = $langs->trans("VATPayment");
260  }
261  print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input class="minwidth300" name="label" id="label" value="'.($_POST["label"]?GETPOST("label",'',2):$label).'"></td></tr>';
262 
263  // Amount
264  print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value="'.GETPOST("amount").'"></td></tr>';
265 
266  if (! empty($conf->banque->enabled))
267  {
268  print '<tr><td class="fieldrequired">'.$langs->trans("BankAccount").'</td><td>';
269  $form->select_comptes($_POST["accountid"],"accountid",0,"courant=1",1); // Affiche liste des comptes courant
270  print '</td></tr>';
271  }
272 
273  // Type payment
274  print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
275  $form->select_types_paiements(GETPOST("type_payment"), "type_payment");
276  print "</td>\n";
277  print "</tr>";
278 
279  // Number
280  print '<tr><td>'.$langs->trans('Numero');
281  print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
282  print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
283 
284  // Other attributes
285  $parameters=array();
286  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
287  print $hookmanager->resPrint;
288 
289  print '</table>';
290 
291  dol_fiche_end();
292 
293  print '<div class="center">';
294  print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
295  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
296  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
297  print '</div>';
298 
299  print '</form>';
300 }
301 
302 // View mode
303 if ($id)
304 {
305  $head=vat_prepare_head($object);
306 
307  dol_fiche_head($head, 'card', $langs->trans("VATPayment"), -1, 'payment');
308 
309  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/tva/reglement.php">'.$langs->trans("BackToList").'</a>';
310 
311  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
312 
313  print '<div class="fichecenter">';
314  print '<div class="underbanner clearboth"></div>';
315 
316  print '<table class="border" width="100%">';
317 
318  // Label
319  print '<tr><td class="titlefield">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
320 
321  print "<tr>";
322  print '<td>'.$langs->trans("DatePayment").'</td><td>';
323  print dol_print_date($object->datep,'day');
324  print '</td></tr>';
325 
326 
327  print '<tr><td>';
328  print $form->editfieldkey("DateValue", 'datev', $object->datev, $object, $user->rights->tax->charges->creer, 'day');
329  print '</td><td>';
330  print $form->editfieldval("DateValue", 'datev', $object->datev, $object, $user->rights->tax->charges->creer, 'day');
331  //print dol_print_date($object->datev,'day');
332  print '</td></tr>';
333 
334  print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
335 
336  if (! empty($conf->banque->enabled))
337  {
338  if ($object->fk_account > 0)
339  {
340  $bankline=new AccountLine($db);
341  $bankline->fetch($object->fk_bank);
342 
343  print '<tr>';
344  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
345  print '<td>';
346  print $bankline->getNomUrl(1,0,'showall');
347  print '</td>';
348  print '</tr>';
349  }
350  }
351 
352  // Other attributes
353  $parameters=array();
354  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
355  print $hookmanager->resPrint;
356 
357  print '</table>';
358 
359  print '</div>';
360 
361  dol_fiche_end();
362 
363  /*
364  * Action buttons
365  */
366  print "<div class=\"tabsAction\">\n";
367  if ($object->rappro == 0)
368  {
369  if (! empty($user->rights->tax->charges->supprimer))
370  {
371  print '<a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete">'.$langs->trans("Delete").'</a>';
372  }
373  else
374  {
375  print '<a class="butActionRefused" href="#" title="'.(dol_escape_htmltag($langs->trans("NotAllowed"))).'">'.$langs->trans("Delete").'</a>';
376  }
377  }
378  else
379  {
380  print '<a class="butActionRefused" href="#" title="'.$langs->trans("LinkedToAConciliatedTransaction").'">'.$langs->trans("Delete").'</a>';
381  }
382  print "</div>";
383 }
384 
385 llxFooter();
386 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
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...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
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.
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...
if(empty($reshook)) $form
View.
Definition: perms.php:103
Put here description of your class.
Definition: tva.class.php:33
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 generation of HTML components Only common components must be here.
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
dol_fiche_end($notab=0)
Show tab footer of a card.
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
vat_prepare_head($object)
Prepare array with list of tabs.
Definition: vat.lib.php:31
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
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.
$parameters
Actions.
Definition: card.php:112